From 199201482dcb5396e38f12f562a3bac2bf756da9 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Tue, 25 Apr 2023 14:08:54 +0200 Subject: [PATCH] HHH-16271 Fix generated keys issues with Sybase JConn and insert-select statements --- .../community/dialect/CUBRIDDialect.java | 2 +- .../community/dialect/CacheDialect.java | 2 +- .../dialect/CockroachLegacyDialect.java | 3 +- .../community/dialect/DB2390Dialect.java | 2 +- .../community/dialect/DB2LegacyDialect.java | 2 +- .../community/dialect/DB2iLegacyDialect.java | 4 +- .../community/dialect/DB2zLegacyDialect.java | 2 +- .../community/dialect/DerbyLegacyDialect.java | 2 +- .../community/dialect/FirebirdDialect.java | 2 +- .../community/dialect/HSQLLegacyDialect.java | 5 +- .../community/dialect/InformixDialect.java | 2 +- .../community/dialect/IngresDialect.java | 4 +- .../community/dialect/MimerSQLDialect.java | 2 +- .../community/dialect/MySQLLegacyDialect.java | 2 +- .../dialect/OracleLegacyDialect.java | 2 +- .../dialect/PostgreSQLLegacyDialect.java | 4 +- .../dialect/SQLServerLegacyDialect.java | 2 +- .../community/dialect/SQLiteDialect.java | 4 +- .../dialect/SybaseAnywhereDialect.java | 2 +- .../community/dialect/TeradataDialect.java | 2 +- .../identity/CUBRIDIdentityColumnSupport.java | 3 + .../identity/CacheIdentityColumnSupport.java | 3 + .../FirebirdIdentityColumnSupport.java | 2 + .../InformixIdentityColumnSupport.java | 3 + .../Ingres10IdentityColumnSupport.java | 3 + .../Ingres9IdentityColumnSupport.java | 3 + .../MimerSQLIdentityColumnSupport.java | 3 + .../identity/SQLiteIdentityColumnSupport.java | 2 + .../SybaseAnywhereIdentityColumnSupport.java | 3 + .../Teradata14IdentityColumnSupport.java | 3 + .../dialect/AbstractHANADialect.java | 2 +- .../dialect/AbstractTransactSQLDialect.java | 2 +- .../hibernate/dialect/CockroachDialect.java | 3 +- .../org/hibernate/dialect/DB2400Dialect.java | 2 +- .../hibernate/dialect/DB2400V7R3Dialect.java | 2 +- .../org/hibernate/dialect/DB2Dialect.java | 2 +- .../org/hibernate/dialect/DB2iDialect.java | 4 +- .../org/hibernate/dialect/DB2zDialect.java | 2 +- .../org/hibernate/dialect/DerbyDialect.java | 2 +- .../java/org/hibernate/dialect/Dialect.java | 4 +- .../org/hibernate/dialect/HSQLDialect.java | 5 +- .../org/hibernate/dialect/MySQLDialect.java | 2 +- .../org/hibernate/dialect/OracleDialect.java | 2 +- .../hibernate/dialect/PostgreSQLDialect.java | 3 +- .../hibernate/dialect/SQLServerDialect.java | 2 +- .../org/hibernate/dialect/SybaseDialect.java | 10 +++ ...tractTransactSQLIdentityColumnSupport.java | 2 + .../CockroachDBIdentityColumnSupport.java | 3 + .../identity/DB2IdentityColumnSupport.java | 3 + .../identity/DB2zIdentityColumnSupport.java | 3 + .../identity/HANAIdentityColumnSupport.java | 2 + .../identity/IdentityColumnSupportImpl.java | 2 + .../identity/MySQLIdentityColumnSupport.java | 3 + .../Oracle12cIdentityColumnSupport.java | 3 + .../PostgreSQLIdentityColumnSupport.java | 2 + .../SQLServerIdentityColumnSupport.java | 3 + .../SybaseJconnIdentityColumnSupport.java | 23 ++++++ .../SybaseJConnGetGeneratedKeysDelegate.java | 81 +++++++++++++++++++ 58 files changed, 213 insertions(+), 46 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/identity/SybaseJconnIdentityColumnSupport.java create mode 100644 hibernate-core/src/main/java/org/hibernate/id/insert/SybaseJConnGetGeneratedKeysDelegate.java diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java index 3fbf29131c..13ca6a723e 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CUBRIDDialect.java @@ -371,7 +371,7 @@ public class CUBRIDDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new CUBRIDIdentityColumnSupport(); + return CUBRIDIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java index f4d6e8f0cb..5db647eaec 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CacheDialect.java @@ -295,7 +295,7 @@ public class CacheDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new CacheIdentityColumnSupport(); + return CacheIdentityColumnSupport.INSTANCE; } // SEQUENCE support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CockroachLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CockroachLegacyDialect.java index 1de07631e4..510c19611f 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CockroachLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CockroachLegacyDialect.java @@ -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 diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2390Dialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2390Dialect.java index 238ab1d697..5db5fd6f96 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2390Dialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2390Dialect.java @@ -65,6 +65,6 @@ public class DB2390Dialect extends DB2LegacyDialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new DB2zIdentityColumnSupport(); + return DB2zIdentityColumnSupport.INSTANCE; } } diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java index 97a56512ba..beaa8b5827 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2LegacyDialect.java @@ -934,7 +934,7 @@ public class DB2LegacyDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new DB2IdentityColumnSupport(); + return DB2IdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2iLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2iLegacyDialect.java index 3e1f867ea4..0c28f59b75 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2iLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2iLegacyDialect.java @@ -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 diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2zLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2zLegacyDialect.java index 8adadb9aba..a88260900f 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2zLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DB2zLegacyDialect.java @@ -146,7 +146,7 @@ public class DB2zLegacyDialect extends DB2LegacyDialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new DB2390IdentityColumnSupport(); + return DB2390IdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java index 034b7f1be9..48ea03c1e4 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/DerbyLegacyDialect.java @@ -589,7 +589,7 @@ public class DerbyLegacyDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new DB2IdentityColumnSupport(); + return DB2IdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java index eec4b49a84..c476aa5ac9 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/FirebirdDialect.java @@ -625,7 +625,7 @@ public class FirebirdDialect extends Dialect { public IdentityColumnSupport getIdentityColumnSupport() { return getVersion().isBefore( 3, 0 ) ? super.getIdentityColumnSupport() - : new FirebirdIdentityColumnSupport(); + : FirebirdIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/HSQLLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/HSQLLegacyDialect.java index ad9d0ba407..055797ab33 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/HSQLLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/HSQLLegacyDialect.java @@ -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 diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java index dc614f4a7f..888c09af46 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java @@ -518,7 +518,7 @@ public class InformixDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new InformixIdentityColumnSupport(); + return InformixIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java index 3648387642..de5b0cbae6 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/IngresDialect.java @@ -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(); diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java index 49238051e9..44ce68c3c5 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MimerSQLDialect.java @@ -328,6 +328,6 @@ public class MimerSQLDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new MimerSQLIdentityColumnSupport(); + return MimerSQLIdentityColumnSupport.INSTANCE; } } diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java index 183c02dd3a..8ec8999494 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java @@ -1117,7 +1117,7 @@ public class MySQLLegacyDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new MySQLIdentityColumnSupport(); + return MySQLIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacyDialect.java index cdbe977fad..505a199571 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/OracleLegacyDialect.java @@ -840,7 +840,7 @@ public class OracleLegacyDialect extends Dialect { public IdentityColumnSupport getIdentityColumnSupport() { return getVersion().isBefore( 12 ) ? super.getIdentityColumnSupport() - : new Oracle12cIdentityColumnSupport(); + : Oracle12cIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java index 33a0e7122a..c9d608fbf6 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java @@ -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 diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java index 9f8c2607e7..8d85234801 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java @@ -623,7 +623,7 @@ public class SQLServerLegacyDialect extends AbstractTransactSQLDialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new SQLServerIdentityColumnSupport(); + return SQLServerIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java index f56d9e351f..f1d8c8f92c 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java @@ -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 diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java index cbb18d2305..41a2dd00b7 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java @@ -173,7 +173,7 @@ public class SybaseAnywhereDialect extends SybaseDialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new SybaseAnywhereIdentityColumnSupport(); + return SybaseAnywhereIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java index fe895548d4..deabc41ba7 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/TeradataDialect.java @@ -618,7 +618,7 @@ public class TeradataDialect extends Dialect { public IdentityColumnSupport getIdentityColumnSupport() { return getVersion().isBefore( 14 ) ? super.getIdentityColumnSupport() - : new Teradata14IdentityColumnSupport(); + : Teradata14IdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/CUBRIDIdentityColumnSupport.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/CUBRIDIdentityColumnSupport.java index 7f6e46ecdb..0a87e1b846 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/CUBRIDIdentityColumnSupport.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/CUBRIDIdentityColumnSupport.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/CacheIdentityColumnSupport.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/CacheIdentityColumnSupport.java index 182bea072e..de04c23f31 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/CacheIdentityColumnSupport.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/CacheIdentityColumnSupport.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/FirebirdIdentityColumnSupport.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/FirebirdIdentityColumnSupport.java index fb95e544b5..68f1ac657a 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/FirebirdIdentityColumnSupport.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/FirebirdIdentityColumnSupport.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/InformixIdentityColumnSupport.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/InformixIdentityColumnSupport.java index cf82523a54..bb61ed9d2f 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/InformixIdentityColumnSupport.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/InformixIdentityColumnSupport.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Ingres10IdentityColumnSupport.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Ingres10IdentityColumnSupport.java index b40ca3fb6a..dbbbba18f2 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Ingres10IdentityColumnSupport.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Ingres10IdentityColumnSupport.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Ingres9IdentityColumnSupport.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Ingres9IdentityColumnSupport.java index 733a03583b..91310d3f70 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Ingres9IdentityColumnSupport.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Ingres9IdentityColumnSupport.java @@ -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()"; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/MimerSQLIdentityColumnSupport.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/MimerSQLIdentityColumnSupport.java index ff01b15c01..b65c12b266 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/MimerSQLIdentityColumnSupport.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/MimerSQLIdentityColumnSupport.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/SQLiteIdentityColumnSupport.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/SQLiteIdentityColumnSupport.java index 0bdc00b97c..e301700238 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/SQLiteIdentityColumnSupport.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/SQLiteIdentityColumnSupport.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/SybaseAnywhereIdentityColumnSupport.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/SybaseAnywhereIdentityColumnSupport.java index bec0dc93c8..a06442a516 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/SybaseAnywhereIdentityColumnSupport.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/SybaseAnywhereIdentityColumnSupport.java @@ -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; diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Teradata14IdentityColumnSupport.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Teradata14IdentityColumnSupport.java index cd417f4aa3..252831dad0 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Teradata14IdentityColumnSupport.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/identity/Teradata14IdentityColumnSupport.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java index cb4b189edc..af15cd8e9c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java @@ -1075,7 +1075,7 @@ public abstract class AbstractHANADialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new HANAIdentityColumnSupport(); + return HANAIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java index 80220329f8..adcfa484f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractTransactSQLDialect.java @@ -375,7 +375,7 @@ public abstract class AbstractTransactSQLDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new AbstractTransactSQLIdentityColumnSupport(); + return AbstractTransactSQLIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java index e486c8f141..bc9c8adf38 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java @@ -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 diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2400Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2400Dialect.java index 6e349ed8c8..988aba2fe6 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2400Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2400Dialect.java @@ -48,6 +48,6 @@ public class DB2400Dialect extends DB2Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new DB2zIdentityColumnSupport(); + return DB2zIdentityColumnSupport.INSTANCE; } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2400V7R3Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2400V7R3Dialect.java index e0811023f5..e657b4248e 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2400V7R3Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2400V7R3Dialect.java @@ -50,6 +50,6 @@ public class DB2400V7R3Dialect extends DB2400Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new DB2IdentityColumnSupport(); + return DB2IdentityColumnSupport.INSTANCE; } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java index 4a860bca25..78f04360a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java @@ -1013,7 +1013,7 @@ public class DB2Dialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new DB2IdentityColumnSupport(); + return DB2IdentityColumnSupport.INSTANCE; } /** diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java index cb98096c80..9e3e971411 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2iDialect.java @@ -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 diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java index 747ea39e16..789c3512a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2zDialect.java @@ -135,7 +135,7 @@ public class DB2zDialect extends DB2Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new DB2zIdentityColumnSupport(); + return DB2zIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java index 75c7c92426..3af52c1b14 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java @@ -563,7 +563,7 @@ public class DerbyDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new DB2IdentityColumnSupport(); + return DB2IdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 2e62d0c2a5..a48eeb2c4b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -1761,8 +1761,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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java index 72cdfbe3ca..134a1afccf 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java @@ -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 diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java index e07ef69323..936367563c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java @@ -1200,7 +1200,7 @@ public class MySQLDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new MySQLIdentityColumnSupport(); + return MySQLIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java index 051e2f16e0..ba484f4823 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/OracleDialect.java @@ -875,7 +875,7 @@ public class OracleDialect extends Dialect { public IdentityColumnSupport getIdentityColumnSupport() { return getVersion().isBefore( 12 ) ? super.getIdentityColumnSupport() - : new Oracle12cIdentityColumnSupport(); + : Oracle12cIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java index b49b24af2e..4cdc5e9c70 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java @@ -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; @@ -1011,7 +1010,7 @@ public class PostgreSQLDialect extends Dialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return IDENTITY_COLUMN_SUPPORT; + return PostgreSQLIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java index ce0f5a6ef1..0662a2b8aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java @@ -610,7 +610,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect { @Override public IdentityColumnSupport getIdentityColumnSupport() { - return new SQLServerIdentityColumnSupport(); + return SQLServerIdentityColumnSupport.INSTANCE; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java index 4d071819aa..7312dc0eb9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java @@ -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; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/AbstractTransactSQLIdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/AbstractTransactSQLIdentityColumnSupport.java index 8245f08320..8b540f7cb1 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/AbstractTransactSQLIdentityColumnSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/AbstractTransactSQLIdentityColumnSupport.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/CockroachDBIdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/CockroachDBIdentityColumnSupport.java index 070c066112..169a7e5ad1 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/CockroachDBIdentityColumnSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/CockroachDBIdentityColumnSupport.java @@ -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. diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/DB2IdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/DB2IdentityColumnSupport.java index d3eb55b8ff..3966e2011f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/DB2IdentityColumnSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/DB2IdentityColumnSupport.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/DB2zIdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/DB2zIdentityColumnSupport.java index 2a6ed34e09..01623e371c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/DB2zIdentityColumnSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/DB2zIdentityColumnSupport.java @@ -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"; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/HANAIdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/HANAIdentityColumnSupport.java index 00cd124969..9722668c9a 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/HANAIdentityColumnSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/HANAIdentityColumnSupport.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/IdentityColumnSupportImpl.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/IdentityColumnSupportImpl.java index fe2e75b348..4ba4191282 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/IdentityColumnSupportImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/IdentityColumnSupportImpl.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/MySQLIdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/MySQLIdentityColumnSupport.java index 9ff2d2a351..66ad3a3c62 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/MySQLIdentityColumnSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/MySQLIdentityColumnSupport.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/Oracle12cIdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/Oracle12cIdentityColumnSupport.java index 1f4b4b8896..9c56db74d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/Oracle12cIdentityColumnSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/Oracle12cIdentityColumnSupport.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/PostgreSQLIdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/PostgreSQLIdentityColumnSupport.java index 874f0eca70..975aeb800c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/PostgreSQLIdentityColumnSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/PostgreSQLIdentityColumnSupport.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/SQLServerIdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/SQLServerIdentityColumnSupport.java index 673047be89..8cfc2b7d67 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/identity/SQLServerIdentityColumnSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/SQLServerIdentityColumnSupport.java @@ -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()} *

diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/identity/SybaseJconnIdentityColumnSupport.java b/hibernate-core/src/main/java/org/hibernate/dialect/identity/SybaseJconnIdentityColumnSupport.java new file mode 100644 index 0000000000..cabda1dce8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/identity/SybaseJconnIdentityColumnSupport.java @@ -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 . + */ +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 ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/SybaseJConnGetGeneratedKeysDelegate.java b/hibernate-core/src/main/java/org/hibernate/id/insert/SybaseJConnGetGeneratedKeysDelegate.java new file mode 100644 index 0000000000..904fd643e1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/SybaseJConnGetGeneratedKeysDelegate.java @@ -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 . + */ +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(); + } + } +}