Skip to content

Commit b5e88aa

Browse files
gbadnergavinking
authored andcommitted
[536] SchemaMigrator support for PostgreSQL
[536] Correct order of arguments to TestContext#assertEquals [536] : Change SQL keywords to lowercase [536] Encapsulate extraction methods into ReactiveExtractionTool [536] : Added Javodoc, made minor changes to sych up with ORM, changed more SQL keywords that were upper-case to lower-case [536] : Use org.hibernate.reactive.pool.impl.Parameters#process for dialect-specific parameter placeholders [536] : Add a method for non-standard information_schema.columns column name used by PostgreSQL [536] Change `ResultSetAdapter#getLong(String)` to be convert String to Long [536] Change `ResultSetAdapter#getLong(String)` to throw the original exception if the value is neither a long nor a String that can be parsed as a long. [913] SchemaMigrator/SchemaValidator support for CockroachDB [536] [913] Comment out settings in gradle.properties [910] SchemaMigrator/SchemaValidator support for MySQL [910] Fix off-by-one bug in ResultSetAdaptor#getXXX(int columnIndex) methods [910] SchemaMigrator/SchemaValidator support for MariaDB [910] Improve Javadoc; simplify MySqlReactiveInformationExtractorImpl methods [536] Disable SQL logging attempt to fix CI build
1 parent eec3a2e commit b5e88aa

21 files changed

+2408
-53
lines changed

.github/workflows/tracking-orm-5.build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
matrix:
2424
example: [ 'session-example', 'native-sql-example' ]
25-
orm-version: [ '[5.4,5.5)','[5.5,5.6)' ]
25+
orm-version: [ '5.6.0.Beta1' ]
2626
db: ['MySQL', 'PostgreSQL']
2727
exclude:
2828
# 'native-sql-example' doesn't run on MySQL because it has native queries
@@ -77,7 +77,7 @@ jobs:
7777
runs-on: ubuntu-latest
7878
strategy:
7979
matrix:
80-
orm-version: [ '[5.4,5.5)','[5.5,5.6)' ]
80+
orm-version: [ '5.6.0.Beta1' ]
8181
db: ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer']
8282
steps:
8383
- uses: actions/checkout@v2

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ org.gradle.java.installations.auto-download=false
3838
#enableMavenLocalRepo = true
3939

4040
# Override default Hibernate ORM version
41-
#hibernateOrmVersion = 5.5.2.Final
41+
#hibernateOrmVersion = 5.5.6-SNAPSHOT
4242

4343
# If set to true, skip Hibernate ORM version parsing (default is true, if set to null)
4444
# this is required when using intervals or weird versions or the build will fail

hibernate-reactive-core/src/main/java/org/hibernate/reactive/adaptor/impl/ResultSetAdaptor.java

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,55 +74,55 @@ public boolean wasNull() {
7474

7575
@Override
7676
public String getString(int columnIndex) {
77-
String string = row.getString(columnIndex);
77+
String string = row.getString( columnIndex - 1 );
7878
return (wasNull=string==null) ? null : string;
7979
}
8080

8181
@Override
8282
public boolean getBoolean(int columnIndex) {
83-
Boolean bool = row.getBoolean(columnIndex);
83+
Boolean bool = row.getBoolean(columnIndex - 1);
8484
wasNull = bool == null;
8585
return !wasNull && bool;
8686
}
8787

8888
@Override
8989
public byte getByte(int columnIndex) {
90-
Integer integer = row.getInteger( columnIndex );
90+
Integer integer = row.getInteger( columnIndex - 1 );
9191
wasNull = integer == null;
9292
return wasNull ? 0 : integer.byteValue();
9393
}
9494

9595
@Override
9696
public short getShort(int columnIndex) {
97-
Short aShort = row.getShort( columnIndex );
97+
Short aShort = row.getShort( columnIndex - 1 );
9898
wasNull = aShort == null;
9999
return wasNull ? 0 : aShort;
100100
}
101101

102102
@Override
103103
public int getInt(int columnIndex) {
104-
Integer integer = row.getInteger( columnIndex );
104+
Integer integer = row.getInteger( columnIndex - 1 );
105105
wasNull = integer == null;
106106
return wasNull ? 0 : integer;
107107
}
108108

109109
@Override
110110
public long getLong(int columnIndex) {
111-
Long aLong = row.getLong(columnIndex);
111+
Long aLong = row.getLong( columnIndex - 1 );
112112
wasNull = aLong == null;
113113
return wasNull ? 0 : aLong;
114114
}
115115

116116
@Override
117117
public float getFloat(int columnIndex) {
118-
Float real = row.getFloat( columnIndex );
118+
Float real = row.getFloat( columnIndex - 1 );
119119
wasNull = real == null;
120120
return wasNull ? 0 : real;
121121
}
122122

123123
@Override
124124
public double getDouble(int columnIndex) {
125-
Double real = row.getDouble( columnIndex );
125+
Double real = row.getDouble( columnIndex - 1 );
126126
wasNull = real == null;
127127
return wasNull ? 0 : real;
128128
}
@@ -134,32 +134,32 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) {
134134

135135
@Override
136136
public byte[] getBytes(int columnIndex) {
137-
Buffer buffer = row.getBuffer(columnIndex);
137+
Buffer buffer = row.getBuffer( columnIndex - 1 );
138138
wasNull = buffer == null;
139139
return wasNull ? null : buffer.getBytes();
140140
}
141141

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

148148
@Override
149149
public Time getTime(int columnIndex) {
150-
LocalTime localTime = row.getLocalTime(columnIndex);
150+
LocalTime localTime = row.getLocalTime( columnIndex - 1);
151151
return (wasNull=localTime==null) ? null : Time.valueOf(localTime);
152152
}
153153

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

160160
@Override
161161
public Timestamp getTimestamp(int columnIndex) {
162-
LocalDateTime localDateTime = row.getLocalDateTime(columnIndex);
162+
LocalDateTime localDateTime = row.getLocalDateTime( columnIndex - 1 );
163163
return (wasNull=localDateTime==null) ? null : Timestamp.valueOf(localDateTime);
164164
}
165165

@@ -214,7 +214,28 @@ public int getInt(String columnLabel) {
214214

215215
@Override
216216
public long getLong(String columnLabel) {
217-
Long aLong = row.getLong( columnLabel );
217+
// PostgreSQL stores sequence metadata in information_schema as Strings.
218+
// First try to get the value as a Long; if that fails, try to get
219+
// as a String and try to parse it as a Long.
220+
Long aLong;
221+
try {
222+
aLong = row.getLong(columnLabel);
223+
}
224+
catch (ClassCastException ex) {
225+
// Check if the value is a String that can be converted to a Long
226+
final String aString = row.getString(columnLabel);
227+
// aString won't be null; check just because...
228+
try {
229+
aLong = aString != null ? Long.parseLong( aString ) : null;
230+
}
231+
catch (ClassCastException exNotAString) {
232+
// The value is neither a long nor a String that can be
233+
// parsed as a long.
234+
// Throw the original exception.
235+
throw ex;
236+
}
237+
}
238+
218239
wasNull = aLong == null;
219240
return wasNull ? 0 : aLong;
220241
}
@@ -311,7 +332,7 @@ public boolean isClosed() {
311332

312333
@Override
313334
public <T> T getObject(int columnIndex, Class<T> type) {
314-
T object = row.get(type, columnIndex);
335+
T object = row.get(type, columnIndex - 1);
315336
return (wasNull=object==null) ? null : object;
316337
}
317338

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

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

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

468491
@Override
469492
public Object getObject(int columnIndex) {
470-
Object object = row.getValue( columnIndex );
493+
Object object = row.getValue( columnIndex - 1 );
471494
return (wasNull=object==null) ? null : object;
472495
}
473496

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

486509
@Override
487510
public BigDecimal getBigDecimal(int columnIndex) {
488-
BigDecimal decimal = row.getBigDecimal(columnIndex);
511+
BigDecimal decimal = row.getBigDecimal(columnIndex - 1);
489512
return (wasNull=decimal==null) ? null : decimal;
490513
}
491514

hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/BatchingConnection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public CompletionStage<ResultSet> selectJdbc(String sql, Object[] paramValues) {
160160
delegate.selectJdbc(sql, paramValues);
161161
}
162162

163+
@Override
164+
public CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues) {
165+
return delegate.selectJdbcOutsideTransaction( sql, paramValues );
166+
}
167+
163168
public CompletionStage<Long> selectIdentifier(String sql, Object[] paramValues) {
164169
// Do not want to execute the batch here
165170
// because we want to be able to select

hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/ReactiveConnection.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ interface Expectation {
5151
CompletionStage<Result> select(String sql, Object[] paramValues);
5252
CompletionStage<ResultSet> selectJdbc(String sql, Object[] paramValues);
5353

54+
/**
55+
* This method is intended to be used only for queries returning
56+
* a ResultSet that must be executed outside of any "current"
57+
* transaction (i.e with autocommit=true).
58+
* <p/>
59+
* For example, it would be appropriate to use this method when
60+
* performing queries on information_schema or system tables in
61+
* order to obtain metadata information about catalogs, schemas,
62+
* tables, etc.
63+
*
64+
* @param sql - the query to execute outside of a transaction
65+
* @param paramValues - a non-null array of parameter values
66+
* @return the CompletionStage<ResultSet> from executing the query.
67+
*/
68+
CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues);
69+
5470
CompletionStage<Long> insertAndSelectIdentifier(String sql, Object[] paramValues);
5571
CompletionStage<Long> selectIdentifier(String sql, Object[] paramValues);
5672

hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/ProxyConnection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ public CompletionStage<ResultSet> selectJdbc(String sql, Object[] paramValues) {
129129
return withConnection( conn -> conn.selectJdbc( sql, paramValues ) );
130130
}
131131

132+
@Override
133+
public CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues) {
134+
return withConnection( conn -> conn.selectJdbcOutsideTransaction( sql, paramValues ) );
135+
}
136+
132137
@Override
133138
public CompletionStage<Long> selectIdentifier(String sql, Object[] paramValues) {
134139
return withConnection( conn -> conn.selectIdentifier( sql, paramValues ) );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/SqlClientConnection.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ public CompletionStage<ResultSet> selectJdbc(String sql, Object[] paramValues) {
114114
return preparedQuery( sql, Tuple.wrap( paramValues ) ).thenApply(ResultSetAdaptor::new);
115115
}
116116

117+
@Override
118+
public CompletionStage<ResultSet> selectJdbcOutsideTransaction(String sql, Object[] paramValues) {
119+
return preparedQueryOutsideTransaction( sql, Tuple.wrap( paramValues ) ).thenApply(ResultSetAdaptor::new);
120+
}
121+
117122
@Override
118123
public CompletionStage<Void> execute(String sql) {
119124
return preparedQuery( sql ).thenApply( ignore -> null );
@@ -192,6 +197,11 @@ public CompletionStage<RowSet<Row>> preparedQueryOutsideTransaction(String sql)
192197
return pool.preparedQuery( sql ).execute().toCompletionStage();
193198
}
194199

200+
public CompletionStage<RowSet<Row>> preparedQueryOutsideTransaction(String sql, Tuple parameters) {
201+
feedback( sql );
202+
return pool.preparedQuery( sql ).execute( parameters ).toCompletionStage();
203+
}
204+
195205
private void feedback(String sql) {
196206
Objects.requireNonNull(sql, "SQL query cannot be null");
197207
// DDL already gets formatted by the client, so don't reformat it

hibernate-reactive-core/src/main/java/org/hibernate/reactive/provider/impl/ReactiveServiceInitiators.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.hibernate.reactive.provider.service.NoJdbcEnvironmentInitiator;
3030
import org.hibernate.reactive.provider.service.NoJtaPlatformInitiator;
3131
import org.hibernate.reactive.provider.service.ReactiveQueryTranslatorFactoryInitiator;
32+
import org.hibernate.reactive.provider.service.ReactiveSchemaManagementToolInitiator;
3233
import org.hibernate.reactive.provider.service.ReactiveSessionFactoryBuilderInitiator;
3334
import org.hibernate.reactive.id.impl.ReactiveIdentifierGeneratorFactoryInitiator;
3435
import org.hibernate.reactive.provider.service.ReactivePersisterClassResolverInitiator;
@@ -38,7 +39,6 @@
3839
import org.hibernate.resource.transaction.internal.TransactionCoordinatorBuilderInitiator;
3940
import org.hibernate.service.internal.SessionFactoryServiceRegistryFactoryInitiator;
4041
import org.hibernate.tool.hbm2ddl.ImportSqlCommandExtractorInitiator;
41-
import org.hibernate.tool.schema.internal.SchemaManagementToolInitiator;
4242

4343
import java.util.ArrayList;
4444
import java.util.Collections;
@@ -83,7 +83,6 @@ private static List<StandardServiceInitiator> buildInitialServiceInitiatorList()
8383
serviceInitiators.add( PropertyAccessStrategyResolverInitiator.INSTANCE );
8484

8585
serviceInitiators.add( ImportSqlCommandExtractorInitiator.INSTANCE );
86-
serviceInitiators.add( SchemaManagementToolInitiator.INSTANCE );
8786

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

107+
//Custom for Hibernate Reactive:
108+
serviceInitiators.add( ReactiveSchemaManagementToolInitiator.INSTANCE );
109+
108110
//Custom for Hibernate Reactive:
109111
serviceInitiators.add( ReactiveQueryTranslatorFactoryInitiator.INSTANCE );
110112

0 commit comments

Comments
 (0)