Skip to content

[910] SchemaMigrator/SchemaValidator support for MySQL and MariaDB #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ org.gradle.java.installations.auto-download=false
#enableJBossSnapshotsRep = true

# Enable the maven local repository (for local development when needed) when present (value ignored)
#enableMavenLocalRepo = true
enableMavenLocalRepo = true

# Override default Hibernate ORM version
#hibernateOrmVersion = 5.5.2.Final
hibernateOrmVersion = 5.5.6-SNAPSHOT

# If set to true, skip Hibernate ORM version parsing (default is true, if set to null)
# this is required when using intervals or weird versions or the build will fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,55 +74,55 @@ public boolean wasNull() {

@Override
public String getString(int columnIndex) {
String string = row.getString(columnIndex);
String string = row.getString( columnIndex - 1 );
return (wasNull=string==null) ? null : string;
}

@Override
public boolean getBoolean(int columnIndex) {
Boolean bool = row.getBoolean(columnIndex);
Boolean bool = row.getBoolean(columnIndex - 1);
wasNull = bool == null;
return !wasNull && bool;
}

@Override
public byte getByte(int columnIndex) {
Integer integer = row.getInteger( columnIndex );
Integer integer = row.getInteger( columnIndex - 1 );
wasNull = integer == null;
return wasNull ? 0 : integer.byteValue();
}

@Override
public short getShort(int columnIndex) {
Short aShort = row.getShort( columnIndex );
Short aShort = row.getShort( columnIndex - 1 );
wasNull = aShort == null;
return wasNull ? 0 : aShort;
}

@Override
public int getInt(int columnIndex) {
Integer integer = row.getInteger( columnIndex );
Integer integer = row.getInteger( columnIndex - 1 );
wasNull = integer == null;
return wasNull ? 0 : integer;
}

@Override
public long getLong(int columnIndex) {
Long aLong = row.getLong(columnIndex);
Long aLong = row.getLong( columnIndex - 1 );
wasNull = aLong == null;
return wasNull ? 0 : aLong;
}

@Override
public float getFloat(int columnIndex) {
Float real = row.getFloat( columnIndex );
Float real = row.getFloat( columnIndex - 1 );
wasNull = real == null;
return wasNull ? 0 : real;
}

@Override
public double getDouble(int columnIndex) {
Double real = row.getDouble( columnIndex );
Double real = row.getDouble( columnIndex - 1 );
wasNull = real == null;
return wasNull ? 0 : real;
}
Expand All @@ -134,32 +134,32 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) {

@Override
public byte[] getBytes(int columnIndex) {
Buffer buffer = row.getBuffer(columnIndex);
Buffer buffer = row.getBuffer( columnIndex - 1 );
wasNull = buffer == null;
return wasNull ? null : buffer.getBytes();
}

@Override
public Date getDate(int columnIndex) {
LocalDate localDate = row.getLocalDate(columnIndex);
LocalDate localDate = row.getLocalDate( columnIndex - 1 );
return (wasNull=localDate==null) ? null : java.sql.Date.valueOf(localDate);
}

@Override
public Time getTime(int columnIndex) {
LocalTime localTime = row.getLocalTime(columnIndex);
LocalTime localTime = row.getLocalTime( columnIndex - 1);
return (wasNull=localTime==null) ? null : Time.valueOf(localTime);
}

@Override
public Time getTime(int columnIndex, Calendar cal) {
LocalTime localTime = row.getLocalTime(columnIndex);
LocalTime localTime = row.getLocalTime( columnIndex - 1 );
return (wasNull=localTime==null) ? null : Time.valueOf(localTime);
}

@Override
public Timestamp getTimestamp(int columnIndex) {
LocalDateTime localDateTime = row.getLocalDateTime(columnIndex);
LocalDateTime localDateTime = row.getLocalDateTime( columnIndex - 1 );
return (wasNull=localDateTime==null) ? null : Timestamp.valueOf(localDateTime);
}

Expand Down Expand Up @@ -214,7 +214,28 @@ public int getInt(String columnLabel) {

@Override
public long getLong(String columnLabel) {
Long aLong = row.getLong( columnLabel );
// PostgreSQL stores sequence metadata in information_schema as Strings.
// First try to get the value as a Long; if that fails, try to get
// as a String and try to parse it as a Long.
Long aLong;
try {
aLong = row.getLong(columnLabel);
}
catch (ClassCastException ex) {
// Check if the value is a String that can be converted to a Long
final String aString = row.getString(columnLabel);
// aString won't be null; check just because...
try {
aLong = aString != null ? Long.parseLong( aString ) : null;
}
catch (ClassCastException exNotAString) {
// The value is neither a long nor a String that can be
// parsed as a long.
// Throw the original exception.
throw ex;
}
}

wasNull = aLong == null;
return wasNull ? 0 : aLong;
}
Expand Down Expand Up @@ -311,7 +332,7 @@ public boolean isClosed() {

@Override
public <T> T getObject(int columnIndex, Class<T> type) {
T object = row.get(type, columnIndex);
T object = row.get(type, columnIndex - 1);
return (wasNull=object==null) ? null : object;
}

Expand Down Expand Up @@ -430,6 +451,8 @@ public String getCatalogName(int column) {

@Override
public String getColumnTypeName(int column) {
// This information is in rows.columnDescriptors().get( column-1 ).dataType.name
// but does not appear to be accessible.
return null;
}

Expand Down Expand Up @@ -467,7 +490,7 @@ public boolean isWrapperFor(Class<?> iface) {

@Override
public Object getObject(int columnIndex) {
Object object = row.getValue( columnIndex );
Object object = row.getValue( columnIndex - 1 );
return (wasNull=object==null) ? null : object;
}

Expand All @@ -485,7 +508,7 @@ public int findColumn(String columnLabel) {

@Override
public BigDecimal getBigDecimal(int columnIndex) {
BigDecimal decimal = row.getBigDecimal(columnIndex);
BigDecimal decimal = row.getBigDecimal(columnIndex - 1);
return (wasNull=decimal==null) ? null : decimal;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public CompletionStage<ResultSet> selectJdbc(String sql, Object[] paramValues) {
delegate.selectJdbc(sql, paramValues);
}

@Override
public CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues) {
return delegate.selectJdbcOutsideTransaction( sql, paramValues );
}

public CompletionStage<Long> selectIdentifier(String sql, Object[] paramValues) {
// Do not want to execute the batch here
// because we want to be able to select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ interface Expectation {
CompletionStage<Result> select(String sql, Object[] paramValues);
CompletionStage<ResultSet> selectJdbc(String sql, Object[] paramValues);

/**
* This method is intended to be used only for queries returning
* a ResultSet that must be executed outside of any "current"
* transaction (i.e with autocommit=true).
* <p/>
* For example, it would be appropriate to use this method when
* performing queries on information_schema or system tables in
* order to obtain metadata information about catalogs, schemas,
* tables, etc.
*
* @param sql - the query to execute outside of a transaction
* @param paramValues - a non-null array of parameter values
* @return the CompletionStage<ResultSet> from executing the query.
*/
CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues);

CompletionStage<Long> insertAndSelectIdentifier(String sql, Object[] paramValues);
CompletionStage<Long> selectIdentifier(String sql, Object[] paramValues);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public CompletionStage<ResultSet> selectJdbc(String sql, Object[] paramValues) {
return withConnection( conn -> conn.selectJdbc( sql, paramValues ) );
}

@Override
public CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues) {
return withConnection( conn -> conn.selectJdbcOutsideTransaction( sql, paramValues ) );
}

@Override
public CompletionStage<Long> selectIdentifier(String sql, Object[] paramValues) {
return withConnection( conn -> conn.selectIdentifier( sql, paramValues ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public CompletionStage<ResultSet> selectJdbc(String sql, Object[] paramValues) {
return preparedQuery( sql, Tuple.wrap( paramValues ) ).thenApply(ResultSetAdaptor::new);
}

@Override
public CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues) {
return preparedQueryOutsideTransaction( sql, Tuple.wrap( paramValues ) ).thenApply(ResultSetAdaptor::new);
}

@Override
public CompletionStage<Void> execute(String sql) {
return preparedQuery( sql ).thenApply( ignore -> null );
Expand Down Expand Up @@ -194,6 +199,11 @@ public CompletionStage<RowSet<Row>> preparedQueryOutsideTransaction(String sql)
return pool.preparedQuery( sql ).execute().toCompletionStage();
}

public CompletionStage<RowSet<Row>> preparedQueryOutsideTransaction(String sql, Tuple parameters) {
feedback( sql );
return pool.preparedQuery( sql ).execute( parameters ).toCompletionStage();
}

private void feedback(String sql) {
Objects.requireNonNull(sql, "SQL query cannot be null");
// DDL already gets formatted by the client, so don't reformat it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.hibernate.reactive.provider.service.NoJdbcEnvironmentInitiator;
import org.hibernate.reactive.provider.service.NoJtaPlatformInitiator;
import org.hibernate.reactive.provider.service.ReactiveQueryTranslatorFactoryInitiator;
import org.hibernate.reactive.provider.service.ReactiveSchemaManagementToolInitiator;
import org.hibernate.reactive.provider.service.ReactiveSessionFactoryBuilderInitiator;
import org.hibernate.reactive.id.impl.ReactiveIdentifierGeneratorFactoryInitiator;
import org.hibernate.reactive.provider.service.ReactivePersisterClassResolverInitiator;
Expand All @@ -38,7 +39,6 @@
import org.hibernate.resource.transaction.internal.TransactionCoordinatorBuilderInitiator;
import org.hibernate.service.internal.SessionFactoryServiceRegistryFactoryInitiator;
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractorInitiator;
import org.hibernate.tool.schema.internal.SchemaManagementToolInitiator;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -83,7 +83,6 @@ private static List<StandardServiceInitiator> buildInitialServiceInitiatorList()
serviceInitiators.add( PropertyAccessStrategyResolverInitiator.INSTANCE );

serviceInitiators.add( ImportSqlCommandExtractorInitiator.INSTANCE );
serviceInitiators.add( SchemaManagementToolInitiator.INSTANCE );

//Custom for Hibernate Reactive:
serviceInitiators.add( NoJdbcEnvironmentInitiator.INSTANCE );
Expand All @@ -105,6 +104,9 @@ private static List<StandardServiceInitiator> buildInitialServiceInitiatorList()
serviceInitiators.add( JdbcServicesInitiator.INSTANCE );
serviceInitiators.add( RefCursorSupportInitiator.INSTANCE );

//Custom for Hibernate Reactive:
serviceInitiators.add( ReactiveSchemaManagementToolInitiator.INSTANCE );

//Custom for Hibernate Reactive:
serviceInitiators.add( ReactiveQueryTranslatorFactoryInitiator.INSTANCE );

Expand Down
Loading