Skip to content
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 @@ -48,32 +48,28 @@ public int getJdbcBatchSize() {
return globalBatchSize;
}

private int batchSize(Integer explicitBatchSize) {
return explicitBatchSize == null
? globalBatchSize
: explicitBatchSize;
}

@Override
public Batch buildBatch(
BatchKey key,
Integer explicitBatchSize,
Supplier<PreparedStatementGroup> statementGroupSupplier,
JdbcCoordinator jdbcCoordinator) {
final int batchSize =
explicitBatchSize == null
? globalBatchSize
: explicitBatchSize;
final int batchSize = batchSize( explicitBatchSize );
assert batchSize > 1;
return new BatchImpl( key, statementGroupSupplier.get(), batchSize, jdbcCoordinator );
}


/**
* Intended for use from tests
*/
@Internal
public BatchImpl buildBatch(BatchKey batchKey, Integer sizeOverride, String table, SessionImplementor session, String sql) {
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();

final int batchSize = sizeOverride == null
? globalBatchSize
: sizeOverride;

return new BatchImpl(
batchKey,
new PreparedStatementGroupSingleTable(
Expand Down Expand Up @@ -137,8 +133,8 @@ public MutationDetails getDeleteDetails() {
),
session
),
batchSize,
jdbcCoordinator
batchSize( sizeOverride ),
session.getJdbcCoordinator()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public BatchBuilder initiateService(Map<String, Object> configurationValues, Ser

final String builderClassName = builder.toString();
try {
return (BatchBuilder) registry.requireService( ClassLoaderService.class )
.classForName( builderClassName )
.getConstructor()
.newInstance();
return (BatchBuilder)
registry.requireService( ClassLoaderService.class )
.classForName( builderClassName )
.getConstructor()
.newInstance();
}
catch (Exception e) {
throw new ServiceException( "Could not build explicit BatchBuilder [" + builderClassName + "]", e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package org.hibernate.engine.jdbc.batch.internal;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.LinkedHashSet;

Expand All @@ -21,10 +20,6 @@
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
import org.hibernate.event.monitor.spi.EventMonitor;
import org.hibernate.event.monitor.spi.DiagnosticEvent;
import org.hibernate.resource.jdbc.spi.JdbcEventHandler;
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;

import static java.util.Objects.requireNonNull;
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;
Expand Down Expand Up @@ -131,7 +126,7 @@ public void addToBatch(JdbcValueBindings jdbcValueBindings, TableInclusionChecke
}
else {
//noinspection resource
final PreparedStatement statement = statementDetails.resolveStatement();
final var statement = statementDetails.resolveStatement();
final String sqlString = statementDetails.getSqlString();
sqlStatementLogger.logStatement( sqlString );
jdbcValueBindings.beforeStatement( statementDetails );
Expand Down Expand Up @@ -169,7 +164,7 @@ protected void releaseStatements() {
}

protected void clearBatch(PreparedStatementDetails statementDetails) {
final PreparedStatement statement = statementDetails.getStatement();
final var statement = statementDetails.getStatement();
assert statement != null;

try {
Expand All @@ -192,7 +187,7 @@ protected void clearBatch(PreparedStatementDetails statementDetails) {
* Convenience method to notify registered observers of an explicit execution of this batch.
*/
protected final void notifyObserversExplicitExecution() {
for ( BatchObserver observer : observers ) {
for ( var observer : observers ) {
observer.batchExplicitlyExecuted();
}
}
Expand All @@ -201,7 +196,7 @@ protected final void notifyObserversExplicitExecution() {
* Convenience method to notify registered observers of an implicit execution of this batch.
*/
protected final void notifyObserversImplicitExecution() {
for ( BatchObserver observer : observers ) {
for ( var observer : observers ) {
observer.batchImplicitlyExecuted();
}
}
Expand Down Expand Up @@ -247,18 +242,18 @@ protected void performExecution() {
);
}

final JdbcSessionOwner jdbcSessionOwner = jdbcCoordinator.getJdbcSessionOwner();
final JdbcEventHandler eventHandler = jdbcSessionOwner.getJdbcSessionContext().getEventHandler();
final var jdbcSessionOwner = jdbcCoordinator.getJdbcSessionOwner();
final var eventHandler = jdbcSessionOwner.getJdbcSessionContext().getEventHandler();
try {
getStatementGroup().forEachStatement( (tableName, statementDetails) -> {
final String sql = statementDetails.getSqlString();
final PreparedStatement statement = statementDetails.getStatement();
final var statement = statementDetails.getStatement();
if ( statement != null ) {
try {
if ( statementDetails.getMutatingTableDetails().isIdentifierTable() ) {
final var eventMonitor = jdbcSessionOwner.getEventMonitor();
final var executionEvent = eventMonitor.beginJdbcBatchExecutionEvent();
final int[] rowCounts;
final EventMonitor eventMonitor = jdbcSessionOwner.getEventMonitor();
final DiagnosticEvent executionEvent = eventMonitor.beginJdbcBatchExecutionEvent();
try {
eventHandler.jdbcExecuteBatchStart();
rowCounts = statement.executeBatch();
Expand Down Expand Up @@ -319,7 +314,7 @@ private void checkRowCounts(int[] rowCounts, PreparedStatementDetails statementD
@Override
public void release() {
if ( BATCH_MESSAGE_LOGGER.isInfoEnabled() ) {
final PreparedStatementGroup statementGroup = getStatementGroup();
final var statementGroup = getStatementGroup();
if ( statementGroup.getNumberOfStatements() != 0
&& statementGroup.hasMatching( statementDetails -> statementDetails.getStatement() != null ) ) {
BATCH_MESSAGE_LOGGER.batchContainedStatementsOnRelease();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
*/
package org.hibernate.engine.jdbc.env.internal;

import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.EnumSet;
import java.util.Map;

import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;
import org.hibernate.internal.util.config.ConfigurationHelper;

import static org.hibernate.engine.jdbc.env.internal.LobCreationLogging.LOB_LOGGER;
import static org.hibernate.engine.jdbc.env.internal.LobCreationLogging.LOB_MESSAGE_LOGGER;
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;

/**
* Utilities for LOB creation
Expand All @@ -37,7 +35,7 @@ public class LobCreationHelper {
* @param jdbcConnection The connection which can be used in level-of-support testing.
*/
public static EnumSet<LobTypes> getSupportedContextualLobTypes(Dialect dialect, Map<String,Object> configValues, Connection jdbcConnection) {
if ( ConfigurationHelper.getBoolean( Environment.NON_CONTEXTUAL_LOB_CREATION, configValues ) ) {
if ( getBoolean( Environment.NON_CONTEXTUAL_LOB_CREATION, configValues ) ) {
LOB_MESSAGE_LOGGER.disablingContextualLOBCreation( Environment.NON_CONTEXTUAL_LOB_CREATION );
return NONE;
}
Expand All @@ -48,14 +46,14 @@ public static EnumSet<LobTypes> getSupportedContextualLobTypes(Dialect dialect,
}

try {
final DatabaseMetaData meta = jdbcConnection.getMetaData();
final var databaseMetaData = jdbcConnection.getMetaData();
// if the jdbc driver version is less than 4, it shouldn't have createClob
if ( meta.getJDBCMajorVersion() < 4 ) {
LOB_MESSAGE_LOGGER.nonContextualLobCreationJdbcVersion( meta.getJDBCMajorVersion() );
if ( databaseMetaData.getJDBCMajorVersion() < 4 ) {
LOB_MESSAGE_LOGGER.nonContextualLobCreationJdbcVersion( databaseMetaData.getJDBCMajorVersion() );
return NONE;
}

if ( !dialect.supportsJdbcConnectionLobCreation( meta ) ) {
if ( !dialect.supportsJdbcConnectionLobCreation( databaseMetaData ) ) {
LOB_MESSAGE_LOGGER.nonContextualLobCreationDialect();
return NONE;
}
Expand All @@ -64,25 +62,23 @@ public static EnumSet<LobTypes> getSupportedContextualLobTypes(Dialect dialect,
// ignore exception and continue
}

// NOTE : for the time being we assume that the ability to call
// `createClob` implies the ability to call `#createBlob`
// NOTE: for the time being, we assume that the ability to call
// createClob() implies the ability to call createBlob()
if ( canCreateClob( jdbcConnection ) ) {
if ( canCreateNClob( jdbcConnection ) ) {
return EnumSet.of( LobTypes.BLOB, LobTypes.CLOB, LobTypes.NCLOB );
}
else {
return EnumSet.of( LobTypes.BLOB, LobTypes.CLOB );
}
return canCreateNClob( jdbcConnection )
? EnumSet.of( LobTypes.BLOB, LobTypes.CLOB, LobTypes.NCLOB )
: EnumSet.of( LobTypes.BLOB, LobTypes.CLOB );
}

return NONE;
}

private static boolean canCreateClob(Connection jdbcConnection) {
try {
// we just want to see if the driver can create one. we can immediately free it.
final Clob clob = jdbcConnection.createClob();
// We just want to see if the driver can create one
final var clob = jdbcConnection.createClob();
try {
// We can immediately free it
clob.free();
}
catch (Throwable e) {
Expand All @@ -98,9 +94,10 @@ private static boolean canCreateClob(Connection jdbcConnection) {

private static boolean canCreateNClob(Connection jdbcConnection) {
try {
// we just want to see if the driver can create one. we can immediately free it.
final Clob clob = jdbcConnection.createNClob();
// We just want to see if the driver can create one
final var clob = jdbcConnection.createNClob();
try {
// We can immediately free it
clob.free();
}
catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,9 @@ public LobCreator buildLobCreator(LobCreationContext lobCreationContext) {
}
else if ( supportedContextualLobTypes.contains( LobTypes.BLOB )
&& supportedContextualLobTypes.contains( LobTypes.CLOB ) ){
if ( !supportedContextualLobTypes.contains( LobTypes.NCLOB ) ) {
return new BlobAndClobCreator( lobCreationContext, useConnectionToCreateLob );
}
else {
return new StandardLobCreator( lobCreationContext, useConnectionToCreateLob );
}
return !supportedContextualLobTypes.contains( LobTypes.NCLOB )
? new BlobAndClobCreator( lobCreationContext, useConnectionToCreateLob )
: new StandardLobCreator( lobCreationContext, useConnectionToCreateLob );
}
else {
LOB_LOGGER.debug( "Unexpected condition resolving type of LobCreator to use. Falling back to NonContextualLobCreator" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ else if ( mustQuote( identifier ) ) {
}

private boolean mustQuote(Identifier identifier) {
final String identifierText = identifier.getText();
return globallyQuoteIdentifiers
|| autoQuoteKeywords && isReservedWord( identifier.getText() )
|| autoQuoteInitialUnderscore && identifier.getText().startsWith( "_" )
|| autoQuoteDollar && identifier.getText().contains( "$" );
|| autoQuoteKeywords && isReservedWord( identifierText )
|| autoQuoteInitialUnderscore && identifierText.startsWith( "_" )
|| autoQuoteDollar && identifierText.contains( "$" );
}

@Override
Expand Down Expand Up @@ -107,15 +108,13 @@ public String toMetaDataCatalogName(Identifier identifier) {
// null is used to tell DatabaseMetaData to not limit results based on catalog.
return null;
}

if ( identifier == null ) {
if ( jdbcEnvironment.getCurrentCatalog() == null ) {
return "";
}
identifier = jdbcEnvironment.getCurrentCatalog();
else {
final var id =
identifier == null
? jdbcEnvironment.getCurrentCatalog()
: identifier;
return id == null ? "" : toMetaDataText( id );
}

return toMetaDataText( identifier );
}

private String toMetaDataText(Identifier identifier) {
Expand Down Expand Up @@ -149,15 +148,14 @@ public String toMetaDataSchemaName(Identifier identifier) {
// null is used to tell DatabaseMetaData to not limit results based on schema.
return null;
}

if ( identifier == null ) {
if ( jdbcEnvironment.getCurrentSchema() == null ) {
return "";
}
identifier = jdbcEnvironment.getCurrentSchema();
else {
final var id =
identifier == null
? jdbcEnvironment.getCurrentSchema()
: identifier;
return id == null ? "" : toMetaDataText( id );
}

return toMetaDataText( identifier );
}

@Override
Expand Down
Loading
Loading