HHH-16271 Fix generated keys issues with Sybase JConn and insert-select statements

This commit is contained in:
Christian Beikov 2023-04-25 14:08:54 +02:00
parent 0170db7c9d
commit 279b6ad31f
58 changed files with 213 additions and 46 deletions

View File

@ -371,7 +371,7 @@ public class CUBRIDDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new CUBRIDIdentityColumnSupport();
return CUBRIDIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -295,7 +295,7 @@ public class CacheDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new CacheIdentityColumnSupport();
return CacheIdentityColumnSupport.INSTANCE;
}
// SEQUENCE support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -103,7 +103,6 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
public class CockroachLegacyDialect extends Dialect {
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, CockroachLegacyDialect.class.getName() );
private static final CockroachDBIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new CockroachDBIdentityColumnSupport();
// KNOWN LIMITATIONS:
// * no support for java.sql.Clob
@ -513,7 +512,7 @@ public class CockroachLegacyDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return IDENTITY_COLUMN_SUPPORT;
return CockroachDBIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -65,6 +65,6 @@ public class DB2390Dialect extends DB2LegacyDialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new DB2zIdentityColumnSupport();
return DB2zIdentityColumnSupport.INSTANCE;
}
}

View File

@ -934,7 +934,7 @@ public class DB2LegacyDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new DB2IdentityColumnSupport();
return DB2IdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -128,8 +128,8 @@ public class DB2iLegacyDialect extends DB2LegacyDialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return getVersion().isSameOrAfter(7, 3)
? new DB2IdentityColumnSupport()
: new DB2390IdentityColumnSupport();
? DB2IdentityColumnSupport.INSTANCE
: DB2390IdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -146,7 +146,7 @@ public class DB2zLegacyDialect extends DB2LegacyDialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new DB2390IdentityColumnSupport();
return DB2390IdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -589,7 +589,7 @@ public class DerbyLegacyDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new DB2IdentityColumnSupport();
return DB2IdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -625,7 +625,7 @@ public class FirebirdDialect extends Dialect {
public IdentityColumnSupport getIdentityColumnSupport() {
return getVersion().isBefore( 3, 0 )
? super.getIdentityColumnSupport()
: new FirebirdIdentityColumnSupport();
: FirebirdIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -100,9 +100,11 @@ public class HSQLLegacyDialect extends Dialect {
org.hibernate.community.dialect.HSQLLegacyDialect.class.getName()
);
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate( this );
private final HSQLIdentityColumnSupport identityColumnSupport;
public HSQLLegacyDialect(DialectResolutionInfo info) {
super( info );
this.identityColumnSupport = new HSQLIdentityColumnSupport( getVersion() );
}
public HSQLLegacyDialect() {
@ -111,6 +113,7 @@ public class HSQLLegacyDialect extends Dialect {
public HSQLLegacyDialect(DatabaseVersion version) {
super( version.isSame( 1, 8 ) ? reflectedVersion( version ) : version );
this.identityColumnSupport = new HSQLIdentityColumnSupport( getVersion() );
}
@Override
@ -770,7 +773,7 @@ public class HSQLLegacyDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new HSQLIdentityColumnSupport( this.getVersion() );
return identityColumnSupport;
}
@Override

View File

@ -518,7 +518,7 @@ public class InformixDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new InformixIdentityColumnSupport();
return InformixIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -399,10 +399,10 @@ public class IngresDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
if ( getVersion().isSameOrAfter( 10 ) ) {
return new Ingres10IdentityColumnSupport();
return Ingres10IdentityColumnSupport.INSTANCE;
}
else if ( getVersion().isSameOrAfter( 9, 3 ) ) {
return new Ingres9IdentityColumnSupport();
return Ingres9IdentityColumnSupport.INSTANCE;
}
else {
return super.getIdentityColumnSupport();

View File

@ -328,6 +328,6 @@ public class MimerSQLDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new MimerSQLIdentityColumnSupport();
return MimerSQLIdentityColumnSupport.INSTANCE;
}
}

View File

@ -1117,7 +1117,7 @@ public class MySQLLegacyDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new MySQLIdentityColumnSupport();
return MySQLIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -840,7 +840,7 @@ public class OracleLegacyDialect extends Dialect {
public IdentityColumnSupport getIdentityColumnSupport() {
return getVersion().isBefore( 12 )
? super.getIdentityColumnSupport()
: new Oracle12cIdentityColumnSupport();
: Oracle12cIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -148,8 +148,6 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
*/
public class PostgreSQLLegacyDialect extends Dialect {
private static final PostgreSQLIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new PostgreSQLIdentityColumnSupport();
protected final PostgreSQLDriverKind driverKind;
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate(this);
@ -1007,7 +1005,7 @@ public class PostgreSQLLegacyDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return IDENTITY_COLUMN_SUPPORT;
return PostgreSQLIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -623,7 +623,7 @@ public class SQLServerLegacyDialect extends AbstractTransactSQLDialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new SQLServerIdentityColumnSupport();
return SQLServerIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -94,8 +94,6 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
*/
public class SQLiteDialect extends Dialect {
private static final SQLiteIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new SQLiteIdentityColumnSupport();
private final UniqueDelegate uniqueDelegate;
public SQLiteDialect(DialectResolutionInfo info) {
@ -545,7 +543,7 @@ public class SQLiteDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return IDENTITY_COLUMN_SUPPORT;
return SQLiteIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -173,7 +173,7 @@ public class SybaseAnywhereDialect extends SybaseDialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new SybaseAnywhereIdentityColumnSupport();
return SybaseAnywhereIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -618,7 +618,7 @@ public class TeradataDialect extends Dialect {
public IdentityColumnSupport getIdentityColumnSupport() {
return getVersion().isBefore( 14 )
? super.getIdentityColumnSupport()
: new Teradata14IdentityColumnSupport();
: Teradata14IdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -12,6 +12,9 @@ import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
* @author Andrea Boriero
*/
public class CUBRIDIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final CUBRIDIdentityColumnSupport INSTANCE = new CUBRIDIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -13,6 +13,9 @@ import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
* @author Andrea Boriero
*/
public class CacheIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final CacheIdentityColumnSupport INSTANCE = new CacheIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -13,6 +13,8 @@ import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
*/
public class FirebirdIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final FirebirdIdentityColumnSupport INSTANCE = new FirebirdIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -15,6 +15,9 @@ import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
* @author Andrea Boriero
*/
public class InformixIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final InformixIdentityColumnSupport INSTANCE = new InformixIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -10,6 +10,9 @@ package org.hibernate.community.dialect.identity;
* @author Andrea Boriero
*/
public class Ingres10IdentityColumnSupport extends Ingres9IdentityColumnSupport {
public static final Ingres10IdentityColumnSupport INSTANCE = new Ingres10IdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -12,6 +12,9 @@ import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
* @author Andrea Boriero
*/
public class Ingres9IdentityColumnSupport extends IdentityColumnSupportImpl {
public static final Ingres9IdentityColumnSupport INSTANCE = new Ingres9IdentityColumnSupport();
@Override
public String getIdentitySelectString(String table, String column, int type) {
return "select last_identity()";

View File

@ -12,6 +12,9 @@ import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
* @author Andrea Boriero
*/
public class MimerSQLIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final MimerSQLIdentityColumnSupport INSTANCE = new MimerSQLIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return false;

View File

@ -16,6 +16,8 @@ import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
*/
public class SQLiteIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final SQLiteIdentityColumnSupport INSTANCE = new SQLiteIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -12,6 +12,9 @@ import org.hibernate.dialect.identity.AbstractTransactSQLIdentityColumnSupport;
* @author Andrea Boriero
*/
public class SybaseAnywhereIdentityColumnSupport extends AbstractTransactSQLIdentityColumnSupport {
public static final SybaseAnywhereIdentityColumnSupport INSTANCE = new SybaseAnywhereIdentityColumnSupport();
@Override
public boolean supportsInsertSelectIdentity() {
return false;

View File

@ -12,6 +12,9 @@ import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
* @author Andrea Boriero
*/
public class Teradata14IdentityColumnSupport extends IdentityColumnSupportImpl {
public static Teradata14IdentityColumnSupport INSTANCE = new Teradata14IdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -1075,7 +1075,7 @@ public abstract class AbstractHANADialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new HANAIdentityColumnSupport();
return HANAIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -375,7 +375,7 @@ public abstract class AbstractTransactSQLDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new AbstractTransactSQLIdentityColumnSupport();
return AbstractTransactSQLIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -118,7 +118,6 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
public class CockroachDialect extends Dialect {
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, CockroachDialect.class.getName() );
private static final CockroachDBIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new CockroachDBIdentityColumnSupport();
// KNOWN LIMITATIONS:
// * no support for java.sql.Clob
@ -516,7 +515,7 @@ public class CockroachDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return IDENTITY_COLUMN_SUPPORT;
return CockroachDBIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -48,6 +48,6 @@ public class DB2400Dialect extends DB2Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new DB2zIdentityColumnSupport();
return DB2zIdentityColumnSupport.INSTANCE;
}
}

View File

@ -50,6 +50,6 @@ public class DB2400V7R3Dialect extends DB2400Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new DB2IdentityColumnSupport();
return DB2IdentityColumnSupport.INSTANCE;
}
}

View File

@ -1010,7 +1010,7 @@ public class DB2Dialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new DB2IdentityColumnSupport();
return DB2IdentityColumnSupport.INSTANCE;
}
/**

View File

@ -122,8 +122,8 @@ public class DB2iDialect extends DB2Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return getVersion().isSameOrAfter(7, 3)
? new DB2IdentityColumnSupport()
: new DB2zIdentityColumnSupport();
? DB2IdentityColumnSupport.INSTANCE
: DB2zIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -135,7 +135,7 @@ public class DB2zDialect extends DB2Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new DB2zIdentityColumnSupport();
return DB2zIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -563,7 +563,7 @@ public class DerbyDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new DB2IdentityColumnSupport();
return DB2IdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -1784,8 +1784,8 @@ public abstract class Dialect implements ConversionContext, TypeContributor, Fun
* @return the IdentityColumnSupport
* @since 5.1
*/
public IdentityColumnSupport getIdentityColumnSupport(){
return new IdentityColumnSupportImpl();
public IdentityColumnSupport getIdentityColumnSupport() {
return IdentityColumnSupportImpl.INSTANCE;
}
// SEQUENCE support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -70,9 +70,11 @@ public class HSQLDialect extends Dialect {
private static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 2, 6, 1 );
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate(this);
private final HSQLIdentityColumnSupport identityColumnSupport;
public HSQLDialect(DialectResolutionInfo info) {
super( info );
this.identityColumnSupport = new HSQLIdentityColumnSupport( getVersion() );
}
public HSQLDialect() {
@ -81,6 +83,7 @@ public class HSQLDialect extends Dialect {
public HSQLDialect(DatabaseVersion version) {
super( version );
this.identityColumnSupport = new HSQLIdentityColumnSupport( getVersion() );
}
@Override
@ -589,7 +592,7 @@ public class HSQLDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new HSQLIdentityColumnSupport( this.getVersion() );
return identityColumnSupport;
}
@Override

View File

@ -1202,7 +1202,7 @@ public class MySQLDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new MySQLIdentityColumnSupport();
return MySQLIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -857,7 +857,7 @@ public class OracleDialect extends Dialect {
public IdentityColumnSupport getIdentityColumnSupport() {
return getVersion().isBefore( 12 )
? super.getIdentityColumnSupport()
: new Oracle12cIdentityColumnSupport();
: Oracle12cIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -138,7 +138,6 @@ import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithM
public class PostgreSQLDialect extends Dialect {
protected final static DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 10 );
private static final PostgreSQLIdentityColumnSupport IDENTITY_COLUMN_SUPPORT = new PostgreSQLIdentityColumnSupport();
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate(this);
protected final PostgreSQLDriverKind driverKind;
@ -1009,7 +1008,7 @@ public class PostgreSQLDialect extends Dialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return IDENTITY_COLUMN_SUPPORT;
return PostgreSQLIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -610,7 +610,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new SQLServerIdentityColumnSupport();
return SQLServerIdentityColumnSupport.INSTANCE;
}
@Override

View File

@ -16,6 +16,9 @@ import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.function.CountFunction;
import org.hibernate.dialect.function.IntegralTimestampaddFunction;
import org.hibernate.dialect.function.SybaseTruncFunction;
import org.hibernate.dialect.identity.AbstractTransactSQLIdentityColumnSupport;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.identity.SybaseJconnIdentityColumnSupport;
import org.hibernate.dialect.unique.SkipNullableUniqueDelegate;
import org.hibernate.dialect.unique.UniqueDelegate;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
@ -387,4 +390,11 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
public boolean supportsAlterColumnType() {
return true;
}
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return jtdsDriver
? AbstractTransactSQLIdentityColumnSupport.INSTANCE
: SybaseJconnIdentityColumnSupport.INSTANCE;
}
}

View File

@ -12,6 +12,8 @@ import org.hibernate.MappingException;
* @author Andrea Boriero
*/
public class AbstractTransactSQLIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final AbstractTransactSQLIdentityColumnSupport INSTANCE = new AbstractTransactSQLIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -11,6 +11,9 @@ import java.sql.Types;
import org.hibernate.MappingException;
public class CockroachDBIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final CockroachDBIdentityColumnSupport INSTANCE = new CockroachDBIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
// Full support requires setting the sql.defaults.serial_normalization=sql_sequence in CockroachDB.

View File

@ -10,6 +10,9 @@ package org.hibernate.dialect.identity;
* @author Andrea Boriero
*/
public class DB2IdentityColumnSupport extends IdentityColumnSupportImpl {
public static final DB2IdentityColumnSupport INSTANCE = new DB2IdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -10,6 +10,9 @@ package org.hibernate.dialect.identity;
* @author Andrea Boriero
*/
public class DB2zIdentityColumnSupport extends DB2IdentityColumnSupport {
public static final DB2zIdentityColumnSupport INSTANCE = new DB2zIdentityColumnSupport();
@Override
public String getIdentitySelectString(String table, String column, int type) {
return "select identity_val_local() from sysibm.sysdummy1";

View File

@ -10,6 +10,8 @@ import org.hibernate.MappingException;
public class HANAIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final HANAIdentityColumnSupport INSTANCE = new HANAIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -16,6 +16,8 @@ import org.hibernate.id.insert.GetGeneratedKeysDelegate;
*/
public class IdentityColumnSupportImpl implements IdentityColumnSupport {
public static final IdentityColumnSupportImpl INSTANCE = new IdentityColumnSupportImpl();
@Override
public boolean supportsIdentityColumns() {
return false;

View File

@ -10,6 +10,9 @@ package org.hibernate.dialect.identity;
* @author Andrea Boriero
*/
public class MySQLIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final MySQLIdentityColumnSupport INSTANCE = new MySQLIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -14,6 +14,9 @@ import org.hibernate.id.insert.GetGeneratedKeysDelegate;
* @author Andrea Boriero
*/
public class Oracle12cIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final Oracle12cIdentityColumnSupport INSTANCE = new Oracle12cIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -16,6 +16,8 @@ import static org.hibernate.internal.util.StringHelper.unquote;
* @author Andrea Boriero
*/
public class PostgreSQLIdentityColumnSupport extends IdentityColumnSupportImpl {
public static final PostgreSQLIdentityColumnSupport INSTANCE = new PostgreSQLIdentityColumnSupport();
@Override
public boolean supportsIdentityColumns() {
return true;

View File

@ -10,6 +10,9 @@ package org.hibernate.dialect.identity;
* @author Andrea Boriero
*/
public class SQLServerIdentityColumnSupport extends AbstractTransactSQLIdentityColumnSupport {
public static final SQLServerIdentityColumnSupport INSTANCE = new SQLServerIdentityColumnSupport();
/**
* Use {@code insert table(...) values(...) select SCOPE_IDENTITY()}
* <p>

View File

@ -0,0 +1,23 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.dialect.identity;
import org.hibernate.dialect.Dialect;
import org.hibernate.id.PostInsertIdentityPersister;
import org.hibernate.id.insert.GetGeneratedKeysDelegate;
import org.hibernate.id.insert.SybaseJConnGetGeneratedKeysDelegate;
public class SybaseJconnIdentityColumnSupport extends AbstractTransactSQLIdentityColumnSupport {
public static final SybaseJconnIdentityColumnSupport INSTANCE = new SybaseJconnIdentityColumnSupport();
@Override
public GetGeneratedKeysDelegate buildGetGeneratedKeysDelegate(
PostInsertIdentityPersister persister,
Dialect dialect) {
return new SybaseJConnGetGeneratedKeysDelegate( persister, dialect );
}
}

View File

@ -0,0 +1,81 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.id.insert;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.hibernate.MappingException;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.mutation.JdbcValueBindings;
import org.hibernate.engine.jdbc.mutation.group.PreparedStatementDetails;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.jdbc.spi.StatementPreparer;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.id.PostInsertIdentityPersister;
import org.hibernate.internal.CoreLogging;
import org.hibernate.jdbc.Expectation;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.sql.model.ast.builder.TableInsertBuilder;
import org.hibernate.sql.model.ast.builder.TableInsertBuilderStandard;
import static java.sql.Statement.NO_GENERATED_KEYS;
import static org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity;
/**
* Specialized {@link IdentifierGeneratingInsert} which appends the database
* specific clause which signifies to return generated {@code IDENTITY} values
* to the end of the insert statement.
*
* @author Christian Beikov
*/
public class SybaseJConnGetGeneratedKeysDelegate extends GetGeneratedKeysDelegate {
private final PostInsertIdentityPersister persister;
private final Dialect dialect;
public SybaseJConnGetGeneratedKeysDelegate(PostInsertIdentityPersister persister, Dialect dialect) {
super( persister, dialect, true );
this.persister = persister;
this.dialect = dialect;
}
@Override
public String prepareIdentifierGeneratingInsert(String insertSQL) {
return dialect.getIdentityColumnSupport().appendIdentitySelectToInsert( insertSQL );
}
@Override
public Object executeAndExtract(
String insertSql,
PreparedStatement insertStatement,
SharedSessionContractImplementor session) {
JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
final JdbcServices jdbcServices = session.getJdbcServices();
ResultSet resultSet = jdbcCoordinator.getResultSetReturn().execute( insertStatement, insertSql );
try {
return getGeneratedIdentity( persister.getNavigableRole().getFullPath(), resultSet, persister, session );
}
catch (SQLException e) {
throw jdbcServices.getSqlExceptionHelper().convert(
e,
"Unable to extract generated-keys ResultSet",
insertSql
);
}
finally {
jdbcCoordinator.getLogicalConnection().getResourceRegistry().release( resultSet, insertStatement );
jdbcCoordinator.afterStatementExecution();
}
}
}