HHH-100084 - Refactor Identity Column support methods into IdentityColumnSupport interface
This commit is contained in:
parent
7c17a0f444
commit
2731fe541a
|
@ -22,6 +22,8 @@ import org.hibernate.dialect.function.NoArgSQLFunction;
|
|||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||
import org.hibernate.dialect.identity.AbstractTransactSQLIdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.hql.spi.id.IdTableSupportStandardImpl;
|
||||
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
|
||||
import org.hibernate.hql.spi.id.local.AfterUseAction;
|
||||
|
@ -134,32 +136,6 @@ abstract class AbstractTransactSQLDialect extends Dialect {
|
|||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "select @@identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString() {
|
||||
//starts with 1, implicitly
|
||||
return "identity not null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsInsertSelectIdentity() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String appendIdentitySelectToInsert(String insertSQL) {
|
||||
return insertSQL + "\nselect @@identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String appendLockHint(LockOptions lockOptions, String tableName) {
|
||||
return lockOptions.getLockMode().greaterThan( LockMode.READ ) ? tableName + " holdlock" : tableName;
|
||||
|
@ -293,4 +269,10 @@ abstract class AbstractTransactSQLDialect extends Dialect {
|
|||
public boolean supportsTuplesInSubqueries() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new AbstractTransactSQLIdentityColumnSupport();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import org.hibernate.cfg.Environment;
|
|||
import org.hibernate.dialect.function.NoArgSQLFunction;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||
import org.hibernate.dialect.identity.CUBRIDIdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.CUBRIDLimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
@ -230,16 +232,6 @@ public class CUBRIDDialect extends Dialect {
|
|||
registerKeyword( "SEARCH" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColumnCheck() {
|
||||
return false;
|
||||
|
@ -250,17 +242,6 @@ public class CUBRIDDialect extends Dialect {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "select last_insert_id()";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getIdentityColumnString() {
|
||||
//starts with 1, implicitly
|
||||
return "not null auto_increment";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAddColumnString() {
|
||||
return "add";
|
||||
|
@ -360,4 +341,10 @@ public class CUBRIDDialect extends Dialect {
|
|||
public LimitHandler getLimitHandler() {
|
||||
return CUBRIDLimitHandler.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new CUBRIDIdentityColumnSupport();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
package org.hibernate.dialect;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.function.ConditionalParenthesisFunction;
|
||||
import org.hibernate.dialect.function.ConvertFunction;
|
||||
|
@ -17,6 +16,8 @@ import org.hibernate.dialect.function.SQLFunctionTemplate;
|
|||
import org.hibernate.dialect.function.StandardJDBCEscapeFunction;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||
import org.hibernate.dialect.identity.Chache71IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.lock.LockingStrategy;
|
||||
import org.hibernate.dialect.lock.OptimisticForceIncrementLockingStrategy;
|
||||
import org.hibernate.dialect.lock.OptimisticLockingStrategy;
|
||||
|
@ -464,34 +465,16 @@ public class Cache71Dialect extends Dialect {
|
|||
);
|
||||
}
|
||||
|
||||
// IDENTITY support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getNativeIdentifierGeneratorClass() {
|
||||
return IdentityGenerator.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDataTypeInIdentityColumn() {
|
||||
// Whether this dialect has an Identity clause added to the data type or a completely seperate identity
|
||||
// data type
|
||||
return true;
|
||||
}
|
||||
// IDENTITY support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString() throws MappingException {
|
||||
// The keyword used to specify an identity column, if identity column key generation is supported.
|
||||
return "identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "SELECT LAST_IDENTITY() FROM %TSQL_sys.snf";
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new Chache71IdentityColumnSupport();
|
||||
}
|
||||
|
||||
// SEQUENCE support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.dialect;
|
||||
|
||||
import org.hibernate.dialect.identity.DB2390IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.AbstractLimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHelper;
|
||||
|
@ -50,11 +52,6 @@ public class DB2390Dialect extends DB2Dialect {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "select identity_val_local() from sysibm.sysdummy1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsLimit() {
|
||||
return true;
|
||||
|
@ -92,4 +89,9 @@ public class DB2390Dialect extends DB2Dialect {
|
|||
return LIMIT_HANDLER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new DB2390IdentityColumnSupport();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.dialect;
|
||||
|
||||
import org.hibernate.dialect.identity.DB2390IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.AbstractLimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHelper;
|
||||
|
@ -49,11 +51,6 @@ public class DB2400Dialect extends DB2Dialect {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "select identity_val_local() from sysibm.sysdummy1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsLimit() {
|
||||
return true;
|
||||
|
@ -95,4 +92,9 @@ public class DB2400Dialect extends DB2Dialect {
|
|||
public String getForUpdateString() {
|
||||
return " for update with rs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new DB2390IdentityColumnSupport();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ import org.hibernate.dialect.function.NoArgSQLFunction;
|
|||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||
import org.hibernate.dialect.identity.DB2IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.AbstractLimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHelper;
|
||||
|
@ -225,26 +227,6 @@ public class DB2Dialect extends Dialect {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "values identity_val_local()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString() {
|
||||
return "generated by default as identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return "default";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSequenceNextValString(String sequenceName) {
|
||||
return "values nextval for " + sequenceName;
|
||||
|
@ -566,4 +548,9 @@ public class DB2Dialect extends Dialect {
|
|||
order
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new DB2IdentityColumnSupport();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
|
@ -40,6 +42,8 @@ import org.hibernate.dialect.function.SQLFunction;
|
|||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||
import org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
|
||||
import org.hibernate.dialect.lock.LockingStrategy;
|
||||
import org.hibernate.dialect.lock.OptimisticForceIncrementLockingStrategy;
|
||||
import org.hibernate.dialect.lock.OptimisticLockingStrategy;
|
||||
|
@ -67,7 +71,6 @@ import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
|
|||
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
|
||||
import org.hibernate.hql.spi.id.persistent.PersistentTableBulkIdStrategy;
|
||||
import org.hibernate.id.IdentityGenerator;
|
||||
import org.hibernate.id.SequenceGenerator;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
|
@ -102,8 +105,6 @@ import org.hibernate.type.StandardBasicTypes;
|
|||
import org.hibernate.type.descriptor.sql.ClobTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Represents a dialect of SQL implemented by a particular RDBMS. Subclasses implement Hibernate compatibility
|
||||
* with different systems. Subclasses should provide a public default constructor that register a set of type
|
||||
|
@ -728,7 +729,7 @@ public abstract class Dialect implements ConversionContext {
|
|||
* @return The native generator class.
|
||||
*/
|
||||
public Class getNativeIdentifierGeneratorClass() {
|
||||
if ( supportsIdentityColumns() ) {
|
||||
if ( getIdentityColumnSupport().supportsIdentityColumns() ) {
|
||||
return IdentityGenerator.class;
|
||||
}
|
||||
else {
|
||||
|
@ -739,13 +740,26 @@ public abstract class Dialect implements ConversionContext {
|
|||
|
||||
// IDENTITY support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
/**
|
||||
* Get the appropriate {@link IdentityColumnSupport}
|
||||
*
|
||||
* @return the IdentityColumnSupport
|
||||
* @since 5.1
|
||||
*/
|
||||
public IdentityColumnSupport getIdentityColumnSupport(){
|
||||
return new IdentityColumnSupportImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this dialect support identity column key generation?
|
||||
*
|
||||
* @return True if IDENTITY columns are supported; false otherwise.
|
||||
*
|
||||
* @deprecated use {@link IdentityColumnSupport} method instead
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean supportsIdentityColumns() {
|
||||
return false;
|
||||
return getIdentityColumnSupport().supportsIdentityColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -754,9 +768,12 @@ public abstract class Dialect implements ConversionContext {
|
|||
*
|
||||
* @return True if the dialect supports selecting the just
|
||||
* generated IDENTITY in the insert statement.
|
||||
*
|
||||
* @deprecated use {@link IdentityColumnSupport} method instead
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean supportsInsertSelectIdentity() {
|
||||
return false;
|
||||
return getIdentityColumnSupport().supportsInsertSelectIdentity();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -764,9 +781,12 @@ public abstract class Dialect implements ConversionContext {
|
|||
* completely separate identity data type
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @deprecated use {@link IdentityColumnSupport} method instead
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasDataTypeInIdentityColumn() {
|
||||
return true;
|
||||
return getIdentityColumnSupport().hasDataTypeInIdentityColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -779,9 +799,12 @@ public abstract class Dialect implements ConversionContext {
|
|||
* @param insertString The insert command
|
||||
* @return The insert command with any necessary identity select
|
||||
* clause attached.
|
||||
*
|
||||
* @deprecated use {@link IdentityColumnSupport} method instead
|
||||
*/
|
||||
@Deprecated
|
||||
public String appendIdentitySelectToInsert(String insertString) {
|
||||
return insertString;
|
||||
return getIdentityColumnSupport().appendIdentitySelectToInsert( insertString );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -793,23 +816,12 @@ public abstract class Dialect implements ConversionContext {
|
|||
* @param type The {@link java.sql.Types} type code.
|
||||
* @return The appropriate select command
|
||||
* @throws MappingException If IDENTITY generation is not supported.
|
||||
*/
|
||||
public String getIdentitySelectString(String table, String column, int type) throws MappingException {
|
||||
return getIdentitySelectString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the select command to use to retrieve the last generated IDENTITY
|
||||
* value.
|
||||
*
|
||||
* @return The appropriate select command
|
||||
* @throws MappingException If IDENTITY generation is not supported.
|
||||
*
|
||||
* @deprecated use {@link Dialect#getIdentitySelectString(String, String, int)} instead
|
||||
* @deprecated use {@link IdentityColumnSupport} method instead
|
||||
*/
|
||||
@Deprecated
|
||||
protected String getIdentitySelectString() throws MappingException {
|
||||
throw new MappingException( getClass().getName() + " does not support identity key generation" );
|
||||
public String getIdentitySelectString(String table, String column, int type) throws MappingException {
|
||||
return getIdentityColumnSupport().getIdentitySelectString( table, column, type );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -819,22 +831,12 @@ public abstract class Dialect implements ConversionContext {
|
|||
* @param type The {@link java.sql.Types} type code.
|
||||
* @return The appropriate DDL fragment.
|
||||
* @throws MappingException If IDENTITY generation is not supported.
|
||||
*/
|
||||
public String getIdentityColumnString(int type) throws MappingException {
|
||||
return getIdentityColumnString();
|
||||
}
|
||||
|
||||
/**
|
||||
* The syntax used during DDL to define a column as being an IDENTITY.
|
||||
*
|
||||
* @return The appropriate DDL fragment.
|
||||
* @throws MappingException If IDENTITY generation is not supported.
|
||||
*
|
||||
* @deprecated use {@link Dialect#getIdentityColumnString(int)} instead
|
||||
* @deprecated use {@link IdentityColumnSupport} method instead
|
||||
*/
|
||||
@Deprecated
|
||||
protected String getIdentityColumnString() throws MappingException {
|
||||
throw new MappingException( getClass().getName() + " does not support identity key generation" );
|
||||
public String getIdentityColumnString(int type) throws MappingException {
|
||||
return getIdentityColumnSupport().getIdentityColumnString( type );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -842,12 +844,14 @@ public abstract class Dialect implements ConversionContext {
|
|||
* Need if the dialect does not support inserts that specify no column values.
|
||||
*
|
||||
* @return The appropriate keyword.
|
||||
*
|
||||
* @deprecated use {@link IdentityColumnSupport} method instead
|
||||
*/
|
||||
@Deprecated
|
||||
public String getIdentityInsertString() {
|
||||
return null;
|
||||
return getIdentityColumnSupport().getIdentityInsertString();
|
||||
}
|
||||
|
||||
|
||||
// SEQUENCE support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,6 +14,8 @@ import org.hibernate.dialect.function.AvgWithArgumentCastFunction;
|
|||
import org.hibernate.dialect.function.NoArgSQLFunction;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||
import org.hibernate.dialect.identity.H2IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.AbstractLimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHelper;
|
||||
|
@ -221,27 +223,6 @@ public class H2Dialect extends Dialect {
|
|||
return "add column";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString() {
|
||||
// not null is implicit
|
||||
return "generated by default as identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "call identity()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForUpdateString() {
|
||||
return " for update";
|
||||
|
@ -452,5 +433,10 @@ public class H2Dialect extends Dialect {
|
|||
// We don't need to drop constraints before dropping tables, that just leads to error
|
||||
// messages about missing tables when we don't have a schema in the database
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new H2IdentityColumnSupport();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import org.hibernate.dialect.function.NoArgSQLFunction;
|
|||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||
import org.hibernate.dialect.identity.HSQLIdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.lock.LockingStrategy;
|
||||
import org.hibernate.dialect.lock.OptimisticForceIncrementLockingStrategy;
|
||||
import org.hibernate.dialect.lock.OptimisticLockingStrategy;
|
||||
|
@ -256,27 +258,6 @@ public class HSQLDialect extends Dialect {
|
|||
return "add column";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString() {
|
||||
//not null is implicit
|
||||
return "generated by default as identity (start with 1)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "call identity()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return hsqldbVersion < 20 ? "null" : "default";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsLockTimeouts() {
|
||||
return false;
|
||||
|
@ -672,4 +653,9 @@ public class HSQLDialect extends Dialect {
|
|||
public boolean supportsTupleDistinctCounts() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new HSQLIdentityColumnSupport( this.hsqldbVersion );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
*/
|
||||
package org.hibernate.dialect;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.InformixIdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.FirstLimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.unique.InformixUniqueDelegate;
|
||||
|
@ -80,31 +81,6 @@ public class InformixDialect extends Dialect {
|
|||
return "add";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type)
|
||||
throws MappingException {
|
||||
return type == Types.BIGINT
|
||||
? "select dbinfo('serial8') from informix.systables where tabid=1"
|
||||
: "select dbinfo('sqlca.sqlerrd1') from informix.systables where tabid=1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) throws MappingException {
|
||||
return type == Types.BIGINT ?
|
||||
"serial8 not null" :
|
||||
"serial not null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDataTypeInIdentityColumn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Informix constraint name must be at the end.
|
||||
* <p/>
|
||||
|
@ -296,4 +272,9 @@ public class InformixDialect extends Dialect {
|
|||
public UniqueDelegate getUniqueDelegate() {
|
||||
return uniqueDelegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new InformixIdentityColumnSupport();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import java.sql.Types;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.Ingres10IdentityColumnSupport;
|
||||
|
||||
/**
|
||||
* A SQL dialect for Ingres 10 and later versions.
|
||||
|
@ -59,27 +61,8 @@ public class Ingres10Dialect extends Ingres9Dialect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new Ingres10IdentityColumnSupport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDataTypeInIdentityColumn() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "select last_identity()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString() {
|
||||
return "not null generated by default as identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import java.sql.Types;
|
|||
|
||||
import org.hibernate.dialect.function.NoArgSQLFunction;
|
||||
import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.Ingres9IdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.AbstractLimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHelper;
|
||||
|
@ -109,11 +111,6 @@ public class Ingres9Dialect extends IngresDialect {
|
|||
|
||||
// SEQUENCE support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "select last_identity()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuerySequencesString() {
|
||||
return "select seq_name from iisequences";
|
||||
|
@ -201,4 +198,9 @@ public class Ingres9Dialect extends IngresDialect {
|
|||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new Ingres9IdentityColumnSupport();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ package org.hibernate.dialect;
|
|||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.JDataStoreIdentityColumnSupport;
|
||||
|
||||
/**
|
||||
* A Dialect for JDataStore.
|
||||
|
@ -58,22 +60,6 @@ public class JDataStoreDialect extends Dialect {
|
|||
return " cascade";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
// NOT_SUPPORTED_SHOULD_USE_JDBC3_PreparedStatement.getGeneratedKeys_method
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString() {
|
||||
return "autoincrement";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNoColumnsInsertString() {
|
||||
return "default values";
|
||||
|
@ -89,4 +75,9 @@ public class JDataStoreDialect extends Dialect {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new JDataStoreIdentityColumnSupport();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import java.sql.Types;
|
|||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.MimerSQLIdentityColumnSupport;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
/**
|
||||
|
@ -132,11 +134,6 @@ public class MimerSQLDialect extends Dialect {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsSequences() {
|
||||
return true;
|
||||
|
@ -181,4 +178,9 @@ public class MimerSQLDialect extends Dialect {
|
|||
public boolean supportsOuterJoinForUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new MimerSQLIdentityColumnSupport();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import org.hibernate.boot.TempTableDdlTransactionHandling;
|
|||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.function.NoArgSQLFunction;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.MySQLIdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.AbstractLimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHelper;
|
||||
|
@ -213,22 +215,6 @@ public class MySQLDialect extends Dialect {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString() {
|
||||
return "select last_insert_id()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString() {
|
||||
//starts with 1, implicitly
|
||||
return "not null auto_increment";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAddForeignKeyConstraintString(
|
||||
String constraintName,
|
||||
|
@ -531,4 +517,9 @@ public class MySQLDialect extends Dialect {
|
|||
public String getNotExpression(String expression) {
|
||||
return "not (" + expression + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new MySQLIdentityColumnSupport();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,24 +27,8 @@ public class Oracle12cDialect extends Oracle10gDialect {
|
|||
getDefaultProperties().setProperty( Environment.USE_GET_GENERATED_KEYS, "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsInsertSelectIdentity() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString() {
|
||||
return "generated as identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public LimitHandler getLimitHandler() {
|
||||
return SQL2008StandardLimitHandler.INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.hibernate.dialect.function.PositionSubstringFunction;
|
|||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.function.VarArgsSQLFunction;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.PostgreSQL81IdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.AbstractLimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHelper;
|
||||
|
@ -27,7 +29,6 @@ import org.hibernate.hql.spi.id.IdTableSupportStandardImpl;
|
|||
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
|
||||
import org.hibernate.hql.spi.id.local.AfterUseAction;
|
||||
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
|
||||
import org.hibernate.id.SequenceGenerator;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.internal.util.JdbcExceptionHelper;
|
||||
import org.hibernate.procedure.internal.PostgresCallableStatementSupport;
|
||||
|
@ -262,16 +263,11 @@ public class PostgreSQL81Dialect extends Dialect {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForUpdateString(String aliases) {
|
||||
return getForUpdateString() + " of " + aliases;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getForUpdateString(String aliases, LockOptions lockOptions) {
|
||||
/*
|
||||
|
@ -280,23 +276,6 @@ public class PostgreSQL81Dialect extends Dialect {
|
|||
return getForUpdateString(aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
return "select currval('" + table + '_' + column + "_seq')";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
return type==Types.BIGINT ?
|
||||
"bigserial not null" :
|
||||
"serial not null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDataTypeInIdentityColumn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNoColumnsInsertString() {
|
||||
return "default values";
|
||||
|
@ -562,4 +541,9 @@ public class PostgreSQL81Dialect extends Dialect {
|
|||
public boolean qualifyIndexName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new PostgreSQL81IdentityColumnSupport();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ import org.hibernate.LockOptions;
|
|||
import org.hibernate.dialect.function.AnsiTrimEmulationFunction;
|
||||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.SQLServerIdentityColumnSupport;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.TopLimitHandler;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
@ -79,16 +81,6 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
|
|||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use <tt>insert table(...) values(...) select SCOPE_IDENTITY()</tt>
|
||||
* <p/>
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String appendIdentitySelectToInsert(String insertSQL) {
|
||||
return insertSQL + " select scope_identity()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public LimitHandler getLimitHandler() {
|
||||
return limitHandler;
|
||||
|
@ -203,6 +195,10 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
|
|||
public int getInExpressionCountLimit() {
|
||||
return PARAM_LIST_SIZE_LIMIT;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new SQLServerIdentityColumnSupport();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
package org.hibernate.dialect;
|
||||
|
||||
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.SybaseAnywhereIdentityColumnSupport;
|
||||
|
||||
/**
|
||||
* SQL Dialect for Sybase Anywhere
|
||||
* extending Sybase (Enterprise) Dialect
|
||||
|
@ -38,8 +41,7 @@ public class SybaseAnywhereDialect extends SybaseDialect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsInsertSelectIdentity() {
|
||||
return false;
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new SybaseAnywhereIdentityColumnSupport();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import org.hibernate.boot.Metadata;
|
|||
import org.hibernate.boot.model.relational.QualifiedNameImpl;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.Teradata14IdentityColumnSupport;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter;
|
||||
import org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
|
||||
|
@ -94,16 +96,6 @@ public class Teradata14Dialect extends TeradataDialect {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString() {
|
||||
return "generated by default as identity not null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsExpectedLobUsagePattern() {
|
||||
return true;
|
||||
|
@ -274,6 +266,9 @@ public class Teradata14Dialect extends TeradataDialect {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new Teradata14IdentityColumnSupport();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.MappingException;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class AbstractTransactSQLIdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) throws MappingException {
|
||||
//starts with 1, implicitly
|
||||
return "identity not null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) throws MappingException {
|
||||
return "select @@identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsInsertSelectIdentity() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String appendIdentitySelectToInsert(String insertSQL) {
|
||||
return insertSQL + "\nselect @@identity";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class CUBRIDIdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
return "select last_insert_id()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
//starts with 1, implicitly
|
||||
return "not null auto_increment";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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.MappingException;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class Chache71IdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDataTypeInIdentityColumn() {
|
||||
// Whether this dialect has an Identity clause added to the data type or a completely seperate identity
|
||||
// data type
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) throws MappingException {
|
||||
// The keyword used to specify an identity column, if identity column key generation is supported.
|
||||
return "identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
return "SELECT LAST_IDENTITY() FROM %TSQL_sys.snf";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class DB2390IdentityColumnSupport extends DB2IdentityColumnSupport {
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
return "select identity_val_local() from sysibm.sysdummy1";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class DB2IdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
return "values identity_val_local()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
return "generated by default as identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return "default";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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 java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper;
|
||||
import org.hibernate.id.PostInsertIdentityPersister;
|
||||
import org.hibernate.id.insert.AbstractReturningDelegate;
|
||||
import org.hibernate.id.insert.IdentifierGeneratingInsert;
|
||||
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
|
||||
|
||||
/**
|
||||
* Delegate for dealing with IDENTITY columns using JDBC3 getGeneratedKeys
|
||||
*
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class GetGeneratedKeysDelegate
|
||||
extends AbstractReturningDelegate
|
||||
implements InsertGeneratedIdentifierDelegate {
|
||||
private final PostInsertIdentityPersister persister;
|
||||
private final Dialect dialect;
|
||||
|
||||
public GetGeneratedKeysDelegate(PostInsertIdentityPersister persister, Dialect dialect) {
|
||||
super( persister );
|
||||
this.persister = persister;
|
||||
this.dialect = dialect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert() {
|
||||
IdentifierGeneratingInsert insert = new IdentifierGeneratingInsert( dialect );
|
||||
insert.addIdentityColumn( persister.getRootTableKeyColumnNames()[0] );
|
||||
return insert;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PreparedStatement prepare(String insertSQL, SessionImplementor session) throws SQLException {
|
||||
return session
|
||||
.getJdbcCoordinator()
|
||||
.getStatementPreparer()
|
||||
.prepareStatement( insertSQL, PreparedStatement.RETURN_GENERATED_KEYS );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable executeAndExtract(PreparedStatement insert, SessionImplementor session)
|
||||
throws SQLException {
|
||||
session.getJdbcCoordinator().getResultSetReturn().executeUpdate( insert );
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
rs = insert.getGeneratedKeys();
|
||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||
rs,
|
||||
persister.getRootTableKeyColumnNames()[0],
|
||||
persister.getIdentifierType()
|
||||
);
|
||||
}
|
||||
finally {
|
||||
if ( rs != null ) {
|
||||
session.getJdbcCoordinator().getResourceRegistry().release( rs, insert );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class H2IdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
// not null is implicit
|
||||
return "generated by default as identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
return "call identity()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return "null";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class HSQLIdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
|
||||
final private int hsqldbVersion;
|
||||
|
||||
public HSQLIdentityColumnSupport(int hsqldbVersion) {
|
||||
|
||||
this.hsqldbVersion = hsqldbVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
//not null is implicit
|
||||
return "generated by default as identity (start with 1)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
return "call identity()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return hsqldbVersion < 20 ? "null" : "default";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* 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.MappingException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.id.PostInsertIdentityPersister;
|
||||
|
||||
/**
|
||||
* Represents a support for the Dialect identity key generation
|
||||
*
|
||||
* @author Andrea Boriero
|
||||
*
|
||||
* @since 5.1
|
||||
*/
|
||||
public interface IdentityColumnSupport {
|
||||
/**
|
||||
* Does this dialect support identity column key generation?
|
||||
*
|
||||
* @return True if IDENTITY columns are supported; false otherwise.
|
||||
*/
|
||||
public boolean supportsIdentityColumns();
|
||||
|
||||
/**
|
||||
* Does the dialect support some form of inserting and selecting
|
||||
* the generated IDENTITY value all in the same statement.
|
||||
*
|
||||
* @return True if the dialect supports selecting the just
|
||||
* generated IDENTITY in the insert statement.
|
||||
*/
|
||||
public boolean supportsInsertSelectIdentity();
|
||||
|
||||
/**
|
||||
* Whether this dialect have an Identity clause added to the data type or a
|
||||
* completely separate identity data type
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean hasDataTypeInIdentityColumn();
|
||||
|
||||
/**
|
||||
* Provided we {@link #supportsInsertSelectIdentity}, then attach the
|
||||
* "select identity" clause to the insert statement.
|
||||
* <p/>
|
||||
* Note, if {@link #supportsInsertSelectIdentity} == false then
|
||||
* the insert-string should be returned without modification.
|
||||
*
|
||||
* @param insertString The insert command
|
||||
*
|
||||
* @return The insert command with any necessary identity select
|
||||
* clause attached.
|
||||
*/
|
||||
public String appendIdentitySelectToInsert(String insertString);
|
||||
|
||||
/**
|
||||
* Get the select command to use to retrieve the last generated IDENTITY
|
||||
* value for a particular table
|
||||
*
|
||||
* @param table The table into which the insert was done
|
||||
* @param column The PK column.
|
||||
* @param type The {@link java.sql.Types} type code.
|
||||
*
|
||||
* @return The appropriate select command
|
||||
*
|
||||
* @throws MappingException If IDENTITY generation is not supported.
|
||||
*/
|
||||
public String getIdentitySelectString(String table, String column, int type) throws MappingException;
|
||||
|
||||
|
||||
/**
|
||||
* The syntax used during DDL to define a column as being an IDENTITY of
|
||||
* a particular type.
|
||||
*
|
||||
* @param type The {@link java.sql.Types} type code.
|
||||
*
|
||||
* @return The appropriate DDL fragment.
|
||||
*
|
||||
* @throws MappingException If IDENTITY generation is not supported.
|
||||
*/
|
||||
public String getIdentityColumnString(int type) throws MappingException;
|
||||
|
||||
|
||||
/**
|
||||
* The keyword used to insert a generated value into an identity column (or null).
|
||||
* Need if the dialect does not support inserts that specify no column values.
|
||||
*
|
||||
* @return The appropriate keyword.
|
||||
*/
|
||||
public String getIdentityInsertString();
|
||||
|
||||
/**
|
||||
* The Delegate for dealing with IDENTITY columns using JDBC3 getGeneratedKeys
|
||||
*
|
||||
* @param persister The persister
|
||||
* @param dialect The dialect against which to generate the delegate
|
||||
*
|
||||
* @return the dialect specific GetGeneratedKeys delegate
|
||||
*/
|
||||
public GetGeneratedKeysDelegate buildGetGeneratedKeysDelegate(
|
||||
PostInsertIdentityPersister persister,
|
||||
Dialect dialect);
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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.MappingException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.id.PostInsertIdentityPersister;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class IdentityColumnSupportImpl implements IdentityColumnSupport {
|
||||
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsInsertSelectIdentity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDataTypeInIdentityColumn() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String appendIdentitySelectToInsert(String insertString) {
|
||||
return insertString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) throws MappingException {
|
||||
throw new MappingException( getClass().getName() + " does not support identity key generation" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) throws MappingException {
|
||||
throw new MappingException( getClass().getName() + " does not support identity key generation" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetGeneratedKeysDelegate buildGetGeneratedKeysDelegate(
|
||||
PostInsertIdentityPersister persister,
|
||||
Dialect dialect) {
|
||||
return new GetGeneratedKeysDelegate( persister, dialect );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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 java.sql.Types;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class InformixIdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type)
|
||||
throws MappingException {
|
||||
return type == Types.BIGINT
|
||||
? "select dbinfo('serial8') from informix.systables where tabid=1"
|
||||
: "select dbinfo('sqlca.sqlerrd1') from informix.systables where tabid=1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) throws MappingException {
|
||||
return type == Types.BIGINT ?
|
||||
"serial8 not null" :
|
||||
"serial not null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDataTypeInIdentityColumn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class Ingres10IdentityColumnSupport extends Ingres9IdentityColumnSupport {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDataTypeInIdentityColumn() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
return "not null generated by default as identity";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return "default";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class Ingres9IdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
return "select last_identity()";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class JDataStoreIdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
// NOT_SUPPORTED_SHOULD_USE_JDBC3_PreparedStatement.getGeneratedKeys_method
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
return "autoincrement";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class MimerSQLIdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class MySQLIdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
return "select last_insert_id()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
//starts with 1, implicitly
|
||||
return "not null auto_increment";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class Oracle12cIdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsInsertSelectIdentity() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
return "generated as identity";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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 java.sql.Types;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class PostgreSQL81IdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public boolean supportsIdentityColumns() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentitySelectString(String table, String column, int type) {
|
||||
return "select currval('" + table + '_' + column + "_seq')";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
return type == Types.BIGINT ?
|
||||
"bigserial not null" :
|
||||
"serial not null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDataTypeInIdentityColumn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class SQLServerIdentityColumnSupport extends AbstractTransactSQLIdentityColumnSupport {
|
||||
/**
|
||||
* Use <tt>insert table(...) values(...) select SCOPE_IDENTITY()</tt>
|
||||
* <p/>
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String appendIdentitySelectToInsert(String insertSQL) {
|
||||
return insertSQL + " select scope_identity()";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class SybaseAnywhereIdentityColumnSupport extends AbstractTransactSQLIdentityColumnSupport {
|
||||
@Override
|
||||
public boolean supportsInsertSelectIdentity() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class Teradata14IdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||
@Override
|
||||
public String getIdentityColumnString(int type) {
|
||||
return "generated by default as identity not null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityInsertString() {
|
||||
return "null";
|
||||
}
|
||||
}
|
|
@ -38,9 +38,9 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
|||
Dialect dialect,
|
||||
boolean isGetGeneratedKeysEnabled) throws HibernateException {
|
||||
if ( isGetGeneratedKeysEnabled ) {
|
||||
return new GetGeneratedKeysDelegate( persister, dialect );
|
||||
return dialect.getIdentityColumnSupport().buildGetGeneratedKeysDelegate( persister, dialect );
|
||||
}
|
||||
else if ( dialect.supportsInsertSelectIdentity() ) {
|
||||
else if ( dialect.getIdentityColumnSupport().supportsInsertSelectIdentity() ) {
|
||||
return new InsertSelectDelegate( persister, dialect );
|
||||
}
|
||||
else {
|
||||
|
@ -48,56 +48,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate for dealing with IDENTITY columns using JDBC3 getGeneratedKeys
|
||||
*/
|
||||
public static class GetGeneratedKeysDelegate
|
||||
extends AbstractReturningDelegate
|
||||
implements InsertGeneratedIdentifierDelegate {
|
||||
private final PostInsertIdentityPersister persister;
|
||||
private final Dialect dialect;
|
||||
|
||||
public GetGeneratedKeysDelegate(PostInsertIdentityPersister persister, Dialect dialect) {
|
||||
super( persister );
|
||||
this.persister = persister;
|
||||
this.dialect = dialect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert() {
|
||||
IdentifierGeneratingInsert insert = new IdentifierGeneratingInsert( dialect );
|
||||
insert.addIdentityColumn( persister.getRootTableKeyColumnNames()[0] );
|
||||
return insert;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PreparedStatement prepare(String insertSQL, SessionImplementor session) throws SQLException {
|
||||
return session
|
||||
.getJdbcCoordinator()
|
||||
.getStatementPreparer()
|
||||
.prepareStatement( insertSQL, PreparedStatement.RETURN_GENERATED_KEYS );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable executeAndExtract(PreparedStatement insert, SessionImplementor session)
|
||||
throws SQLException {
|
||||
session.getJdbcCoordinator().getResultSetReturn().executeUpdate( insert );
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
rs = insert.getGeneratedKeys();
|
||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||
rs,
|
||||
persister.getRootTableKeyColumnNames()[0],
|
||||
persister.getIdentifierType()
|
||||
);
|
||||
}
|
||||
finally {
|
||||
if ( rs != null ) {
|
||||
session.getJdbcCoordinator().getResourceRegistry().release( rs, insert );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate for dealing with IDENTITY columns where the dialect supports returning
|
||||
|
|
|
@ -20,6 +20,6 @@ public class InsertSelectIdentityInsert extends IdentifierGeneratingInsert {
|
|||
}
|
||||
|
||||
public String toStatementString() {
|
||||
return getDialect().appendIdentitySelectToInsert( super.toStatementString() );
|
||||
return getDialect().getIdentityColumnSupport().appendIdentitySelectToInsert( super.toStatementString() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -508,11 +508,11 @@ public class Table implements RelationalModel, Serializable, Exportable {
|
|||
|
||||
if ( identityColumn && col.getQuotedName( dialect ).equals( pkname ) ) {
|
||||
// to support dialects that have their own identity data type
|
||||
if ( dialect.hasDataTypeInIdentityColumn() ) {
|
||||
if ( dialect.getIdentityColumnSupport().hasDataTypeInIdentityColumn() ) {
|
||||
buf.append( col.getSqlType( dialect, p ) );
|
||||
}
|
||||
buf.append( ' ' )
|
||||
.append( dialect.getIdentityColumnString( col.getSqlTypeCode( p ) ) );
|
||||
.append( dialect.getIdentityColumnSupport().getIdentityColumnString( col.getSqlTypeCode( p ) ) );
|
||||
}
|
||||
else {
|
||||
|
||||
|
|
|
@ -2434,7 +2434,7 @@ public abstract class AbstractEntityPersister
|
|||
|
||||
// append the SQL to return the generated identifier
|
||||
if ( j == 0 && identityInsert && useInsertSelectIdentity() ) { //TODO: suck into Insert
|
||||
result = getFactory().getDialect().appendIdentitySelectToInsert( result );
|
||||
result = getFactory().getDialect().getIdentityColumnSupport().appendIdentitySelectToInsert( result );
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -2686,7 +2686,7 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
|
||||
protected boolean useInsertSelectIdentity() {
|
||||
return !useGetGeneratedKeys() && getFactory().getDialect().supportsInsertSelectIdentity();
|
||||
return !useGetGeneratedKeys() && getFactory().getDialect().getIdentityColumnSupport().supportsInsertSelectIdentity();
|
||||
}
|
||||
|
||||
protected boolean useGetGeneratedKeys() {
|
||||
|
@ -2732,11 +2732,12 @@ public abstract class AbstractEntityPersister
|
|||
|
||||
public String getIdentitySelectString() {
|
||||
//TODO: cache this in an instvar
|
||||
return getFactory().getDialect().getIdentitySelectString(
|
||||
getTableName( 0 ),
|
||||
getKeyColumns( 0 )[0],
|
||||
getIdentifierType().sqlTypes( getFactory() )[0]
|
||||
);
|
||||
return getFactory().getDialect().getIdentityColumnSupport()
|
||||
.getIdentitySelectString(
|
||||
getTableName( 0 ),
|
||||
getKeyColumns( 0 )[0],
|
||||
getIdentifierType().sqlTypes( getFactory() )[0]
|
||||
);
|
||||
}
|
||||
|
||||
public String getSelectByUniqueKeyString(String propertyName) {
|
||||
|
|
|
@ -75,7 +75,7 @@ public class Insert {
|
|||
}
|
||||
|
||||
public Insert addIdentityColumn(String columnName) {
|
||||
String value = dialect.getIdentityInsertString();
|
||||
String value = dialect.getIdentityColumnSupport().getIdentityInsertString();
|
||||
if ( value != null ) {
|
||||
addColumn( columnName, value );
|
||||
}
|
||||
|
|
|
@ -84,11 +84,11 @@ public class StandardTableExporter implements Exporter<Table> {
|
|||
|
||||
if ( isPrimaryKeyIdentity && colName.equals( pkColName ) ) {
|
||||
// to support dialects that have their own identity data type
|
||||
if ( dialect.hasDataTypeInIdentityColumn() ) {
|
||||
if ( dialect.getIdentityColumnSupport().hasDataTypeInIdentityColumn() ) {
|
||||
buf.append( col.getSqlType( dialect, metadata ) );
|
||||
}
|
||||
buf.append( ' ' )
|
||||
.append( dialect.getIdentityColumnString( col.getSqlTypeCode( metadata ) ) );
|
||||
.append( dialect.getIdentityColumnSupport().getIdentityColumnString( col.getSqlTypeCode( metadata ) ) );
|
||||
}
|
||||
else {
|
||||
buf.append( col.getSqlType( dialect, metadata ) );
|
||||
|
|
|
@ -6,15 +6,17 @@
|
|||
*/
|
||||
package org.hibernate.test.annotations.lob;
|
||||
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupportImpl;
|
||||
import org.hibernate.dialect.Oracle10gDialect;
|
||||
import org.hibernate.id.SequenceIdentityGenerator;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
public class OracleSeqIdGenDialect extends Oracle10gDialect {
|
||||
|
||||
@Override
|
||||
public Class<?> getNativeIdentifierGeneratorClass() {
|
||||
return SequenceIdentityGenerator.class;
|
||||
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||
return new IdentityColumnSupportImpl();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ abstract public class DialectChecks {
|
|||
|
||||
public static class SupportsIdentityColumns implements DialectCheck {
|
||||
public boolean isMatch(Dialect dialect) {
|
||||
return dialect.supportsIdentityColumns();
|
||||
return dialect.getIdentityColumnSupport().supportsIdentityColumns();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue