Skip to content

Commit 902dcf6

Browse files
committed
code cleanups in sql.results.jdbc.internal
mostly just lots of var
1 parent de66ab3 commit 902dcf6

11 files changed

+117
-125
lines changed

hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/AbstractJdbcValues.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ public final boolean next(RowProcessingState rowProcessingState) {
2121

2222
@Override
2323
public boolean previous(RowProcessingState rowProcessingState) {
24-
// NOTE : we do not even bother interacting with the query-cache put manager because
25-
// this method is implicitly related to scrolling and caching of scrolled results
26-
// is not supported
24+
// NOTE: we do not even bother interacting with the query-cache put manager because
25+
// this method is implicitly related to scrolling and caching of scrolled results
26+
// is not supported
2727
return processPrevious( rowProcessingState );
2828
}
2929

3030
protected abstract boolean processPrevious(RowProcessingState rowProcessingState);
3131

3232
@Override
3333
public boolean scroll(int numberOfRows, RowProcessingState rowProcessingState) {
34-
// NOTE : we do not even bother interacting with the query-cache put manager because
35-
// this method is implicitly related to scrolling and caching of scrolled results
36-
// is not supported
34+
// NOTE: we do not even bother interacting with the query-cache put manager because
35+
// this method is implicitly related to scrolling and caching of scrolled results
36+
// is not supported
3737
return processScroll( numberOfRows, rowProcessingState );
3838
}
3939

4040
protected abstract boolean processScroll(int numberOfRows, RowProcessingState rowProcessingState);
4141

4242
@Override
4343
public boolean position(int position, RowProcessingState rowProcessingState) {
44-
// NOTE : we do not even bother interacting with the query-cache put manager because
45-
// this method is implicitly related to scrolling and caching of scrolled results
46-
// is not supported
44+
// NOTE: we do not even bother interacting with the query-cache put manager because
45+
// this method is implicitly related to scrolling and caching of scrolled results
46+
// is not supported
4747
return processPosition( position, rowProcessingState );
4848
}
4949

hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/AbstractResultSetAccess.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.hibernate.type.descriptor.java.JavaType;
1818
import org.hibernate.type.descriptor.jdbc.JdbcType;
1919
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
20-
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
2120
import org.hibernate.type.spi.TypeConfiguration;
2221

2322
/**
@@ -108,18 +107,18 @@ public int getResultCountEstimate() {
108107
@Override
109108
public <J> BasicType<J> resolveType(int position, JavaType<J> explicitJavaType, TypeConfiguration typeConfiguration) {
110109
try {
111-
final ResultSetMetaData metaData = getResultSetMetaData();
112-
final JdbcTypeRegistry registry = typeConfiguration.getJdbcTypeRegistry();
110+
final var metaData = getResultSetMetaData();
111+
final var registry = typeConfiguration.getJdbcTypeRegistry();
113112
final String columnTypeName = metaData.getColumnTypeName( position );
114113
final int columnType = metaData.getColumnType( position );
115114
final int scale = metaData.getScale( position );
116115
final int precision = metaData.getPrecision( position );
117116
final int displaySize = metaData.getColumnDisplaySize( position );
118-
final Dialect dialect = getDialect();
117+
final var dialect = getDialect();
119118
final int length = dialect.resolveSqlTypeLength( columnTypeName, columnType, precision, scale, displaySize );
120-
final JdbcType resolvedJdbcType =
119+
final var resolvedJdbcType =
121120
dialect.resolveSqlTypeDescriptor( columnTypeName, columnType, length, scale, registry );
122-
final JdbcType jdbcType =
121+
final var jdbcType =
123122
explicitJavaType == null
124123
? resolvedJdbcType
125124
: jdbcType( explicitJavaType, resolvedJdbcType, length, precision, scale, typeConfiguration );

hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/CachedJdbcValuesMetadata.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
import java.io.Serializable;
88

9-
import org.hibernate.internal.util.collections.ArrayHelper;
109
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
1110
import org.hibernate.type.BasicType;
1211
import org.hibernate.type.descriptor.java.JavaType;
1312
import org.hibernate.type.spi.TypeConfiguration;
1413

14+
import static org.hibernate.internal.util.collections.ArrayHelper.indexOf;
15+
1516
public final class CachedJdbcValuesMetadata implements JdbcValuesMetadata, Serializable {
1617
private final String[] columnNames;
1718
private final BasicType<?>[] types;
@@ -28,7 +29,7 @@ public int getColumnCount() {
2829

2930
@Override
3031
public int resolveColumnPosition(String columnName) {
31-
final int position = ArrayHelper.indexOf( columnNames, columnName ) + 1;
32+
final int position = indexOf( columnNames, columnName ) + 1;
3233
if ( position == 0 ) {
3334
throw new IllegalStateException( "Unexpected resolving of unavailable column: " + columnName );
3435
}
@@ -49,7 +50,7 @@ public <J> BasicType<J> resolveType(
4950
int position,
5051
JavaType<J> explicitJavaType,
5152
TypeConfiguration typeConfiguration) {
52-
final BasicType<?> type = types[position - 1];
53+
final var type = types[position - 1];
5354
if ( type == null ) {
5455
throw new IllegalStateException( "Unexpected resolving of unavailable column at position: " + position );
5556
}
@@ -58,10 +59,8 @@ public <J> BasicType<J> resolveType(
5859
return (BasicType<J>) type;
5960
}
6061
else {
61-
return typeConfiguration.getBasicTypeRegistry().resolve(
62-
explicitJavaType,
63-
type.getJdbcType()
64-
);
62+
return typeConfiguration.getBasicTypeRegistry()
63+
.resolve( explicitJavaType, type.getJdbcType() );
6564
}
6665
}
6766

hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/DeferredResultSetAccess.java

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
import org.hibernate.dialect.Dialect;
1010
import org.hibernate.dialect.pagination.LimitHandler;
1111
import org.hibernate.dialect.pagination.NoopLimitHandler;
12-
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
1312
import org.hibernate.engine.jdbc.spi.JdbcServices;
1413
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
1514
import org.hibernate.engine.spi.SessionEventListenerManager;
1615
import org.hibernate.engine.spi.SessionFactoryImplementor;
17-
import org.hibernate.engine.spi.SharedSessionContractImplementor;
18-
import org.hibernate.event.monitor.spi.DiagnosticEvent;
19-
import org.hibernate.event.monitor.spi.EventMonitor;
2016
import org.hibernate.query.spi.Limit;
2117
import org.hibernate.query.spi.QueryOptions;
2218
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
@@ -62,7 +58,7 @@ public DeferredResultSetAccess(
6258
JdbcSelectExecutor.StatementCreator statementCreator,
6359
int resultCountEstimate) {
6460
super( executionContext.getSession() );
65-
final JdbcServices jdbcServices = executionContext.getSession().getJdbcServices();
61+
final var jdbcServices = executionContext.getSession().getJdbcServices();
6662

6763
this.jdbcParameterBindings = jdbcParameterBindings;
6864
this.executionContext = executionContext;
@@ -71,7 +67,7 @@ public DeferredResultSetAccess(
7167
this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
7268
this.resultCountEstimate = resultCountEstimate;
7369

74-
final QueryOptions queryOptions = executionContext.getQueryOptions();
70+
final var queryOptions = executionContext.getQueryOptions();
7571
if ( queryOptions == null ) {
7672
finalSql = jdbcSelect.getSqlString();
7773
limit = null;
@@ -80,41 +76,54 @@ public DeferredResultSetAccess(
8076
else {
8177
// Note that limit and lock aren't set for SQM as that is applied during SQL rendering
8278
// But for native queries, we have to adapt the SQL string
83-
final Dialect dialect = jdbcServices.getDialect();
79+
final var dialect = jdbcServices.getDialect();
8480

8581
final String sql = jdbcSelect.getSqlString();
8682

8783
limit = queryOptions.getLimit();
8884
final boolean needsLimitHandler = needsLimitHandler( jdbcSelect );
8985
limitHandler = needsLimitHandler ? dialect.getLimitHandler() : NoopLimitHandler.NO_LIMIT;
90-
final String sqlWithLimit = !needsLimitHandler ? sql : limitHandler.processSql(
91-
sql,
92-
jdbcParameterBindings.getBindings().size(),
93-
jdbcServices.getParameterMarkerStrategy(),
94-
queryOptions
95-
);
86+
final String sqlWithLimit =
87+
needsLimitHandler
88+
? sqlWithLimit( jdbcParameterBindings, sql, jdbcServices, queryOptions )
89+
: sql;
90+
91+
final String sqlWithLocking =
92+
sqlWithLocking( jdbcSelect.getLockStrategy(), sqlWithLimit, queryOptions, dialect );
93+
94+
finalSql =
95+
dialect.addSqlHintOrComment( sqlWithLocking, queryOptions,
96+
executionContext.getSession().getFactory()
97+
.getSessionFactoryOptions().isCommentsEnabled() );
98+
}
99+
}
96100

97-
final var lockOptions = queryOptions.getLockOptions();
98-
final var jdbcLockStrategy = jdbcSelect.getLockStrategy();
99-
final String sqlWithLocking;
100-
if ( hasLocking( jdbcLockStrategy, lockOptions ) ) {
101-
final boolean usesFollowOnLocking = useFollowOnLocking( jdbcLockStrategy, sqlWithLimit, queryOptions, lockOptions, dialect );
102-
if ( usesFollowOnLocking ) {
103-
sqlWithLocking = sqlWithLimit;
104-
}
105-
else {
106-
sqlWithLocking = dialect.applyLocksToSql( sqlWithLimit, lockOptions, emptyMap() );
107-
}
108-
}
109-
else {
110-
sqlWithLocking = sqlWithLimit;
111-
}
101+
private String sqlWithLimit(
102+
JdbcParameterBindings jdbcParameterBindings,
103+
String sql,
104+
JdbcServices jdbcServices,
105+
QueryOptions queryOptions) {
106+
return limitHandler.processSql(
107+
sql,
108+
jdbcParameterBindings.getBindings().size(),
109+
jdbcServices.getParameterMarkerStrategy(),
110+
queryOptions
111+
);
112+
}
112113

113-
final boolean commentsEnabled = executionContext.getSession()
114-
.getFactory()
115-
.getSessionFactoryOptions()
116-
.isCommentsEnabled();
117-
finalSql = dialect.addSqlHintOrComment( sqlWithLocking, queryOptions, commentsEnabled );
114+
private static String sqlWithLocking(
115+
JdbcLockStrategy jdbcLockStrategy,
116+
String sqlWithLimit,
117+
QueryOptions queryOptions,
118+
Dialect dialect) {
119+
final var lockOptions = queryOptions.getLockOptions();
120+
if ( hasLocking( jdbcLockStrategy, lockOptions ) ) {
121+
return useFollowOnLocking( jdbcLockStrategy, sqlWithLimit, queryOptions, lockOptions, dialect )
122+
? sqlWithLimit
123+
: dialect.applyLocksToSql( sqlWithLimit, lockOptions, emptyMap() );
124+
}
125+
else {
126+
return sqlWithLimit;
118127
}
119128
}
120129

@@ -221,7 +230,7 @@ protected void bindParameters(PreparedStatement preparedStatement) throws SQLExc
221230
}
222231

223232
private void setQueryOptions(PreparedStatement preparedStatement) throws SQLException {
224-
final QueryOptions queryOptions = executionContext.getQueryOptions();
233+
final var queryOptions = executionContext.getQueryOptions();
225234
// set options
226235
if ( queryOptions != null ) {
227236
final Integer fetchSize = queryOptions.getFetchSize();
@@ -238,10 +247,10 @@ private void setQueryOptions(PreparedStatement preparedStatement) throws SQLExce
238247
}
239248

240249
private void executeQuery() {
241-
final LogicalConnectionImplementor logicalConnection =
250+
final var logicalConnection =
242251
getPersistenceContext().getJdbcCoordinator().getLogicalConnection();
243252

244-
final SharedSessionContractImplementor session = executionContext.getSession();
253+
final var session = executionContext.getSession();
245254
try {
246255
CORE_LOGGER.tracef( "Executing query to retrieve ResultSet: %s", finalSql );
247256
// prepare the query
@@ -254,8 +263,8 @@ private void executeQuery() {
254263
if ( sqlStatementLogger.getLogSlowQuery() > 0 ) {
255264
executeStartNanos = System.nanoTime();
256265
}
257-
final EventMonitor eventMonitor = session.getEventMonitor();
258-
final DiagnosticEvent jdbcPreparedStatementExecutionEvent =
266+
final var eventMonitor = session.getEventMonitor();
267+
final var jdbcPreparedStatementExecutionEvent =
259268
eventMonitor.beginJdbcPreparedStatementExecutionEvent();
260269
try {
261270
eventListenerManager.jdbcExecuteStatementStart();
@@ -326,8 +335,7 @@ protected LockMode determineFollowOnLockMode(LockOptions lockOptions) {
326335

327336
@Override
328337
public void release() {
329-
final JdbcCoordinator jdbcCoordinator =
330-
getPersistenceContext().getJdbcCoordinator();
338+
final var jdbcCoordinator = getPersistenceContext().getJdbcCoordinator();
331339
final LogicalConnectionImplementor logicalConnection = jdbcCoordinator.getLogicalConnection();
332340
if ( resultSet != null ) {
333341
logicalConnection.getResourceRegistry().release( resultSet, preparedStatement );

hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/DirectResultSetAccess.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public DirectResultSetAccess(
2525
this.resultSetSource = resultSetSource;
2626
this.resultSet = resultSet;
2727

28-
persistenceContext.getJdbcCoordinator().getLogicalConnection().getResourceRegistry()
28+
persistenceContext.getJdbcCoordinator()
29+
.getLogicalConnection()
30+
.getResourceRegistry()
2931
.register( resultSet, resultSetSource );
3032
}
3133

hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesCacheHit.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public JdbcValuesCacheHit(List<?> cachedResults, JdbcValuesMapping resolvedMappi
3636

3737
@Override
3838
protected boolean processNext(RowProcessingState rowProcessingState) {
39-
// NOTE : explicitly skipping limit handling because the cached state ought
40-
// already be the limited size since the cache key includes limits
39+
// NOTE: explicitly skipping limit handling because the cached state ought
40+
// already be the limited size since the cache key includes limits
4141

4242
position++;
4343

@@ -51,8 +51,8 @@ protected boolean processNext(RowProcessingState rowProcessingState) {
5151

5252
@Override
5353
protected boolean processPrevious(RowProcessingState rowProcessingState) {
54-
// NOTE : explicitly skipping limit handling because the cached state ought
55-
// already be the limited size since the cache key includes limits
54+
// NOTE: explicitly skipping limit handling because the cached state ought
55+
// already be the limited size since the cache key includes limits
5656

5757
position--;
5858

@@ -86,8 +86,8 @@ public int getPosition() {
8686

8787
@Override
8888
protected boolean processPosition(int position, RowProcessingState rowProcessingState) {
89-
// NOTE : explicitly skipping limit handling because the cached state should
90-
// already be the limited size since the cache key includes limits
89+
// NOTE: explicitly skipping limit handling because the cached state should
90+
// already be the limited size since the cache key includes limits
9191

9292
if ( position < 0 ) {
9393
// we need to subtract it from `numberOfRows`

hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesMappingProducerStandard.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public JdbcValuesMapping resolve(
5050
final List<SqlSelection> sqlSelections = resolvedMapping.getSqlSelections();
5151
List<SqlSelection> resolvedSelections = null;
5252
for ( int i = 0; i < sqlSelections.size(); i++ ) {
53-
final SqlSelection sqlSelection = sqlSelections.get( i );
54-
final SqlSelection resolvedSelection = sqlSelection.resolve( jdbcResultsMetadata, sessionFactory );
53+
final var sqlSelection = sqlSelections.get( i );
54+
final var resolvedSelection = sqlSelection.resolve( jdbcResultsMetadata, sessionFactory );
5555
if ( resolvedSelection != sqlSelection ) {
5656
if ( resolvedSelections == null ) {
5757
resolvedSelections = new ArrayList<>( sqlSelections );

hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesMappingResolutionImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public JdbcValuesMappingResolutionImpl(
2222
DomainResultAssembler<?>[] domainResultAssemblers,
2323
boolean hasCollectionInitializers,
2424
InitializersList initializersList) {
25-
this( domainResultAssemblers, getResultInitializers( domainResultAssemblers ), hasCollectionInitializers, initializersList );
25+
this( domainResultAssemblers,
26+
getResultInitializers( domainResultAssemblers ),
27+
hasCollectionInitializers,
28+
initializersList );
2629
}
2730

2831
private JdbcValuesMappingResolutionImpl(
@@ -38,7 +41,7 @@ private JdbcValuesMappingResolutionImpl(
3841

3942
private static Initializer<?>[] getResultInitializers(DomainResultAssembler<?>[] resultAssemblers) {
4043
final LinkedHashSet<Initializer<?>> initializers = new LinkedHashSet<>( resultAssemblers.length );
41-
for ( DomainResultAssembler<?> resultAssembler : resultAssemblers ) {
44+
for ( var resultAssembler : resultAssemblers ) {
4245
resultAssembler.forEachResultAssembler( (initializer, list) -> list.add( initializer ), initializers );
4346
}
4447
return initializers.toArray(Initializer.EMPTY_ARRAY);

0 commit comments

Comments
 (0)