Skip to content
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

Code cleanups #9634

Merged
merged 5 commits into from
Jan 17, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public interface ScrollableResults<R> extends AutoCloseable {
*/
void close();

/**
* @return {@code true} if {@link #close()} was already called
*/
boolean isClosed();

/**
* Advance to the next result.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,20 @@ else if ( supportsSchemas ) {
/**
* @deprecated currently used by Hibernate Reactive
* This version of the constructor should handle the case in which we do actually have
* the option to access the DatabaseMetaData, but since Hibernate Reactive is currently
* not making use of it we take a shortcut.
* the option to access the {@link DatabaseMetaData}, but since Hibernate Reactive is
* currently not making use of it we take a shortcut.
*/
@Deprecated
public JdbcEnvironmentImpl(
ServiceRegistryImplementor serviceRegistry,
Dialect dialect,
DatabaseMetaData databaseMetaData
/*JdbcConnectionAccess jdbcConnectionAccess*/) throws SQLException {
this(serviceRegistry, dialect);
DatabaseMetaData databaseMetaData) {
this( serviceRegistry, dialect );
}

/**
* The main constructor form. Builds a JdbcEnvironment using the available DatabaseMetaData
* The main constructor form.
* Builds a {@code JdbcEnvironment} using the available {@link DatabaseMetaData}.
*
* @param serviceRegistry The service registry
* @param dialect The resolved dialect
Expand Down Expand Up @@ -336,38 +336,33 @@ private String determineCurrentSchemaName(
DatabaseMetaData databaseMetaData,
ServiceRegistry serviceRegistry,
Dialect dialect) {
final Object setting =
serviceRegistry.requireService( ConfigurationService.class )
.getSettings().get( SCHEMA_NAME_RESOLVER );
final SchemaNameResolver schemaNameResolver;
if ( setting == null ) {
schemaNameResolver = dialect.getSchemaNameResolver();
}
else {
schemaNameResolver =
serviceRegistry.requireService( StrategySelector.class )
.resolveDefaultableStrategy(
SchemaNameResolver.class,
setting,
dialect.getSchemaNameResolver()
);
}

final SchemaNameResolver resolver = getSchemaNameResolver( serviceRegistry, dialect );
try {
return schemaNameResolver.resolveSchemaName( databaseMetaData.getConnection(), dialect );
return resolver.resolveSchemaName( databaseMetaData.getConnection(), dialect );
}
catch (Exception e) {
log.debug( "Unable to resolve connection default schema", e );
return null;
}
}

private SqlExceptionHelper buildSqlExceptionHelper(Dialect dialect, boolean logWarnings) {
SQLExceptionConversionDelegate dialectDelegate = dialect.buildSQLExceptionConversionDelegate();
SQLExceptionConversionDelegate[] delegates = dialectDelegate == null
private static SchemaNameResolver getSchemaNameResolver(ServiceRegistry serviceRegistry, Dialect dialect) {
final Object setting =
serviceRegistry.requireService( ConfigurationService.class )
.getSettings().get( SCHEMA_NAME_RESOLVER );
return setting == null
? dialect.getSchemaNameResolver()
: serviceRegistry.requireService( StrategySelector.class )
.resolveDefaultableStrategy( SchemaNameResolver.class, setting,
dialect.getSchemaNameResolver() );
}

private static SqlExceptionHelper buildSqlExceptionHelper(Dialect dialect, boolean logWarnings) {
final SQLExceptionConversionDelegate dialectDelegate = dialect.buildSQLExceptionConversionDelegate();
final SQLExceptionConversionDelegate[] delegates = dialectDelegate == null
? new SQLExceptionConversionDelegate[] { new SQLExceptionTypeDelegate( dialect ), new SQLStateConversionDelegate( dialect ) }
: new SQLExceptionConversionDelegate[] { dialectDelegate, new SQLExceptionTypeDelegate( dialect ), new SQLStateConversionDelegate( dialect ) };
return new SqlExceptionHelper( new StandardSQLExceptionConverter(delegates), logWarnings );
return new SqlExceptionHelper( new StandardSQLExceptionConverter( delegates ), logWarnings );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public AbstractScrollableResults(
this.persistenceContext = persistenceContext;
}


@Override
public final R get() throws HibernateException {
if ( closed ) {
Expand Down Expand Up @@ -85,26 +84,22 @@ protected void afterScrollOperation() {

@Override
public void setFetchSize(int fetchSize) {
getJdbcValues().setFetchSize(fetchSize);
getJdbcValues().setFetchSize( fetchSize );
}

@Override
public final void close() {
if ( this.closed ) {
// noop if already closed
return;
if ( !closed ) {
rowReader.finishUp( rowProcessingState );
jdbcValues.finishUp( persistenceContext );
getPersistenceContext().getJdbcCoordinator().afterStatementExecution();
closed = true;
}

rowReader.finishUp( rowProcessingState );
jdbcValues.finishUp( persistenceContext );

getPersistenceContext().getJdbcCoordinator().afterStatementExecution();

this.closed = true;
// noop if already closed
}

@Override
public boolean isClosed() {
return this.closed;
return closed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
*/
package org.hibernate.internal;

import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.query.spi.ScrollableResultsImplementor;

/**
* @author Andrea Boriero
*/
public class EmptyScrollableResults implements ScrollableResultsImplementor {
public class EmptyScrollableResults<R> implements ScrollableResultsImplementor<R> {

public static final ScrollableResultsImplementor INSTANCE = new EmptyScrollableResults();
@SuppressWarnings("rawtypes")
private static final ScrollableResultsImplementor INSTANCE = new EmptyScrollableResults();

@SuppressWarnings("unchecked")
public static <R> EmptyScrollableResults<R> instance() {
return (EmptyScrollableResults<R>) INSTANCE;
}

@Override
public boolean isClosed() {
return true;
}

// @Override
// public int getNumberOfTypes() {
// return 0;
// }

@Override
public void close() {

}

@Override
Expand Down Expand Up @@ -61,12 +60,10 @@ public boolean first() {

@Override
public void beforeFirst() {

}

@Override
public void afterLast() {

}

@Override
Expand All @@ -93,112 +90,7 @@ public boolean setRowNumber(int rowNumber) {
public void setFetchSize(int fetchSize) {}

@Override
public Object[] get() {
return ArrayHelper.EMPTY_OBJECT_ARRAY;
}

// @Override
// public Object get(int i) {
// return null;
// }
//
// @Override
// public Type getType(int i) {
// return null;
// }
//
// @Override
// public Integer getInteger(int col) {
// return null;
// }
//
// @Override
// public Long getLong(int col) {
// return null;
// }
//
// @Override
// public Float getFloat(int col) {
// return null;
// }
//
// @Override
// public Boolean getBoolean(int col) {
// return null;
// }
//
// @Override
// public Double getDouble(int col) {
// return null;
// }
//
// @Override
// public Short getShort(int col) {
// return null;
// }
//
// @Override
// public Byte getByte(int col) {
// return null;
// }
//
// @Override
// public Character getCharacter(int col) {
// return null;
// }
//
// @Override
// public byte[] getBinary(int col) {
// return new byte[0];
// }
//
// @Override
// public String getText(int col) {
// return null;
// }
//
// @Override
// public Blob getBlob(int col) {
// return null;
// }
//
// @Override
// public Clob getClob(int col) {
// return null;
// }
//
// @Override
// public String getString(int col) {
// return null;
// }
//
// @Override
// public BigDecimal getBigDecimal(int col) {
// return null;
// }
//
// @Override
// public BigInteger getBigInteger(int col) {
// return null;
// }
//
// @Override
// public Date getDate(int col) {
// return null;
// }
//
// @Override
// public Locale getLocale(int col) {
// return null;
// }
//
// @Override
// public Calendar getCalendar(int col) {
// return null;
// }
//
// @Override
// public TimeZone getTimeZone(int col) {
// return null;
// }
public R get() {
throw new UnsupportedOperationException( "Empty result set" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ else if ( beforeFirst ) {
}
}

boolean last = prepareCurrentRow();
final boolean last = prepareCurrentRow();

beforeFirst = false;
currentPosition++;
Expand Down Expand Up @@ -130,15 +130,12 @@ else if ( currentPosition == 1 ) {
// we are interested in processing
boolean firstPass = true;
final EntityKey lastKey = getEntityKey();

while ( getRowProcessingState().previous() ) {
EntityKey checkKey = getEntityKey();

final EntityKey checkKey = getEntityKey();
if ( firstPass ) {
firstPass = false;
keyToRead = checkKey;
}

if ( !lastKey.equals( checkKey ) ) {
break;
}
Expand All @@ -148,8 +145,7 @@ else if ( currentPosition == 1 ) {
// Read backwards until we read past the first physical sequential
// row with the key we are interested in loading
while ( getRowProcessingState().previous() ) {
EntityKey checkKey = getEntityKey();

final EntityKey checkKey = getEntityKey();
if ( !keyToRead.equals( checkKey ) ) {
break;
}
Expand Down Expand Up @@ -223,7 +219,6 @@ public boolean last() {
}
}
else {
final RowProcessingStateStandardImpl rowProcessingState = getRowProcessingState();
if ( isResultSetEmpty() || afterLast ) {
// should not be able to reach last without maxPosition being set
// unless there are no results
Expand All @@ -243,10 +238,8 @@ public boolean last() {
@Override
public boolean first() {
beforeFirst();
boolean more = next();

final boolean more = next();
afterScrollOperation();

return more;
}

Expand Down
Loading
Loading