From a806626a2765b270b68df16f43709d4022cc2b53 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 4 May 2011 18:33:12 -0500 Subject: [PATCH] HHH-6199 - Split org.hibernate.exception package into api/spi/internal --- .../org/hibernate/cfg/AvailableSettings.java | 2 +- .../org/hibernate/dialect/Cache71Dialect.java | 1386 ++++++++--------- .../java/org/hibernate/dialect/Dialect.java | 6 +- .../java/org/hibernate/dialect/H2Dialect.java | 5 +- .../org/hibernate/dialect/HSQLDialect.java | 4 +- .../hibernate/dialect/InformixDialect.java | 4 +- .../hibernate/dialect/Oracle8iDialect.java | 4 +- .../org/hibernate/dialect/Oracle9Dialect.java | 4 +- .../hibernate/dialect/PostgreSQLDialect.java | 4 +- .../resolver/BasicSQLExceptionConverter.java | 4 +- .../engine/jdbc/spi/SqlExceptionHelper.java | 6 +- .../engine/spi/SessionFactoryImplementor.java | 2 +- .../CacheSQLStateConverter.java | 239 +-- .../{ => internal}/SQLStateConverter.java | 16 +- .../exception/{ => spi}/Configurable.java | 11 +- .../{ => spi}/SQLExceptionConverter.java | 12 +- .../SQLExceptionConverterFactory.java | 19 +- ...platedViolatedConstraintNameExtracter.java | 8 +- .../ViolatedConstraintNameExtracter.java | 8 +- .../internal/SessionFactoryImpl.java | 2 +- .../AbstractCollectionPersister.java | 2 +- .../tool/hbm2ddl/DatabaseMetadata.java | 2 +- 22 files changed, 882 insertions(+), 868 deletions(-) rename hibernate-core/src/main/java/org/hibernate/exception/{ => internal}/CacheSQLStateConverter.java (89%) rename hibernate-core/src/main/java/org/hibernate/exception/{ => internal}/SQLStateConverter.java (89%) rename hibernate-core/src/main/java/org/hibernate/exception/{ => spi}/Configurable.java (83%) rename hibernate-core/src/main/java/org/hibernate/exception/{ => spi}/SQLExceptionConverter.java (82%) rename hibernate-core/src/main/java/org/hibernate/exception/{ => spi}/SQLExceptionConverterFactory.java (93%) rename hibernate-core/src/main/java/org/hibernate/exception/{ => spi}/TemplatedViolatedConstraintNameExtracter.java (92%) rename hibernate-core/src/main/java/org/hibernate/exception/{ => spi}/ViolatedConstraintNameExtracter.java (89%) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index 27e21e5188..d502a96ba0 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -383,7 +383,7 @@ public interface AvailableSettings { public static final String HBM2DDL_IMPORT_FILES = "hibernate.hbm2ddl.import_files"; /** - * The {@link org.hibernate.exception.SQLExceptionConverter} to use for converting SQLExceptions + * The {@link org.hibernate.exception.spi.SQLExceptionConverter} to use for converting SQLExceptions * to Hibernate's JDBCException hierarchy. The default is to use the configured * {@link org.hibernate.dialect.Dialect}'s preferred SQLExceptionConverter. */ diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java index edaac0cdfd..74601a3004 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java @@ -1,694 +1,694 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2010, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.dialect; -import java.sql.CallableStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -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; -import org.hibernate.dialect.function.NoArgSQLFunction; -import org.hibernate.dialect.function.NvlFunction; -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.lock.LockingStrategy; -import org.hibernate.dialect.lock.OptimisticForceIncrementLockingStrategy; -import org.hibernate.dialect.lock.OptimisticLockingStrategy; -import org.hibernate.dialect.lock.PessimisticForceIncrementLockingStrategy; -import org.hibernate.dialect.lock.PessimisticReadUpdateLockingStrategy; -import org.hibernate.dialect.lock.PessimisticWriteUpdateLockingStrategy; -import org.hibernate.dialect.lock.SelectLockingStrategy; -import org.hibernate.dialect.lock.UpdateLockingStrategy; -import org.hibernate.exception.CacheSQLStateConverter; -import org.hibernate.exception.SQLExceptionConverter; -import org.hibernate.exception.TemplatedViolatedConstraintNameExtracter; -import org.hibernate.exception.ViolatedConstraintNameExtracter; -import org.hibernate.id.IdentityGenerator; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.persister.entity.Lockable; -import org.hibernate.sql.CacheJoinFragment; -import org.hibernate.sql.JoinFragment; -import org.hibernate.type.StandardBasicTypes; - -/** - * Caché 2007.1 dialect. This class is required in order to use Hibernate with Intersystems Cach� SQL.
- *
- * Compatible with Cach� 2007.1. - *
- * - * Caché and Hibernate - * - * - *

Caché and Hibernate

- *

PREREQUISITES

- * These setup instructions assume that both Caché and Hibernate are installed and operational. - *
- *

HIBERNATE DIRECTORIES AND FILES

- * JBoss distributes the InterSystems Cache' dialect for Hibernate 3.2.1 - * For earlier versions of Hibernate please contact - * InterSystems Worldwide Response Center (WRC) - * for the appropriate source files. - *
- *

CACHÉ DOCUMENTATION

- * Documentation for Caché is available online when Caché is running. - * It can also be obtained from the - * InterSystems website. - * The book, "Object-oriented Application Development Using the Caché Post-relational Database: - * is also available from Springer-Verlag. - *
- *

HIBERNATE DOCUMENTATION

- * Hibernate comes with extensive electronic documentation. - * In addition, several books on Hibernate are available from - * Manning Publications Co. - * Three available titles are "Hibernate Quickly", "Hibernate in Action", and "Java Persistence with Hibernate". - *
- *

TO SET UP HIBERNATE FOR USE WITH CACHÉ

- * The following steps assume that the directory where Caché was installed is C:\CacheSys. - * This is the default installation directory for Caché. - * The default installation directory for Hibernate is assumed to be C:\Hibernate. - *

- * If either product is installed in a different location, the pathnames that follow should be modified appropriately. - *

- * Caché version 2007.1 and above is recommended for use with - * Hibernate. The next step depends on the location of your - * CacheDB.jar depending on your version of Caché. - *

    - *
  1. Copy C:\CacheSys\dev\java\lib\JDK15\CacheDB.jar to C:\Hibernate\lib\CacheDB.jar.
  2. - *

    - *

  3. Insert the following files into your Java classpath: - *

    - *

      - *
    • All jar files in the directory C:\Hibernate\lib
    • - *
    • The directory (or directories) where hibernate.properties and/or hibernate.cfg.xml are kept.
    • - *
    - *
  4. - *

    - *

  5. In the file, hibernate.properties (or hibernate.cfg.xml), - * specify the Caché dialect and the Caché version URL settings.
  6. - *
- *

- * For example, in Hibernate 3.2, typical entries in hibernate.properties would have the following - * "name=value" pairs: - *

- * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
Property NameProperty Value
hibernate.dialectorg.hibernate.dialect.Cache71Dialect
hibernate.connection.driver_classcom.intersys.jdbc.CacheDriver
hibernate.connection.username(see note 1)
hibernate.connection.password(see note 1)
hibernate.connection.urljdbc:Cache://127.0.0.1:1972/USER
- *

- *

- *
Note 1
- *
Please contact your administrator for the userid and password you should use when attempting access via JDBC. - * By default, these are chosen to be "_SYSTEM" and "SYS" respectively as noted in the SQL standard.
- *
- *
- *

CACHÉ VERSION URL

- * This is the standard URL for the JDBC driver. - * For a JDBC driver on the machine hosting Caché, use the IP "loopback" address, 127.0.0.1. - * For 1972, the default port, specify the super server port of your Caché instance. - * For USER, substitute the NAMESPACE which contains your Caché database data. - *
- *

CACHÉ DIALECTS

- * Choices for Dialect are: - *
- *

- *

    - *
  1. org.hibernate.dialect.Cache71Dialect (requires Caché - * 2007.1 or above)
  2. - *

    - *

- *
- *

SUPPORT FOR IDENTITY COLUMNS

- * Caché 2007.1 or later supports identity columns. For - * Hibernate to use identity columns, specify "native" as the - * generator. - *
- *

SEQUENCE DIALECTS SUPPORT SEQUENCES

- *

- * To use Hibernate sequence support with Caché in a namespace, you must FIRST load the following file into that namespace: - *

- *     etc\CacheSequences.xml
- * 
- * For example, at the COS terminal prompt in the namespace, run the - * following command: - *

- * d LoadFile^%apiOBJ("c:\hibernate\etc\CacheSequences.xml","ck") - *

- * In your Hibernate mapping you can specify sequence use. - *

- * For example, the following shows the use of a sequence generator in a Hibernate mapping: - *

- *     <id name="id" column="uid" type="long" unsaved-value="null">
- *         <generator class="sequence"/>
- *     </id>
- * 
- *
- *

- * Some versions of Hibernate under some circumstances call - * getSelectSequenceNextValString() in the dialect. If this happens - * you will receive the error message: new MappingException( "Dialect - * does not support sequences" ). - *
- *

HIBERNATE FILES ASSOCIATED WITH CACHÉ DIALECT

- * The following files are associated with Caché dialect: - *

- *

    - *
  1. src\org\hibernate\dialect\Cache71Dialect.java
  2. - *
  3. src\org\hibernate\dialect\function\ConditionalParenthesisFunction.java
  4. - *
  5. src\org\hibernate\dialect\function\ConvertFunction.java
  6. - *
  7. src\org\hibernate\exception\CacheSQLStateConverter.java
  8. - *
  9. src\org\hibernate\sql\CacheJoinFragment.java
  10. - *
- * Cache71Dialect ships with Hibernate 3.2. All other dialects are distributed by InterSystems and subclass Cache71Dialect. - * - * @author Jonathan Levinson - */ - -public class Cache71Dialect extends Dialect { - - /** - * Creates new Cach�71Dialect instance. Sets up the JDBC / - * Cach� type mappings. - */ - public Cache71Dialect() { - super(); - commonRegistration(); - register71Functions(); - } - - protected final void commonRegistration() { - // Note: For object <-> SQL datatype mappings see: - // Configuration Manager | Advanced | SQL | System DDL Datatype Mappings - // - // TBD registerColumnType(Types.BINARY, "binary($1)"); - // changed 08-11-2005, jsl - registerColumnType( Types.BINARY, "varbinary($1)" ); - registerColumnType( Types.BIGINT, "BigInt" ); - registerColumnType( Types.BIT, "bit" ); - registerColumnType( Types.CHAR, "char(1)" ); - registerColumnType( Types.DATE, "date" ); - registerColumnType( Types.DECIMAL, "decimal" ); - registerColumnType( Types.DOUBLE, "double" ); - registerColumnType( Types.FLOAT, "float" ); - registerColumnType( Types.INTEGER, "integer" ); - registerColumnType( Types.LONGVARBINARY, "longvarbinary" ); // binary %Stream - registerColumnType( Types.LONGVARCHAR, "longvarchar" ); // character %Stream - registerColumnType( Types.NUMERIC, "numeric($p,$s)" ); - registerColumnType( Types.REAL, "real" ); - registerColumnType( Types.SMALLINT, "smallint" ); - registerColumnType( Types.TIMESTAMP, "timestamp" ); - registerColumnType( Types.TIME, "time" ); - registerColumnType( Types.TINYINT, "tinyint" ); - // TBD should this be varbinary($1)? - // registerColumnType(Types.VARBINARY, "binary($1)"); - registerColumnType( Types.VARBINARY, "longvarbinary" ); - registerColumnType( Types.VARCHAR, "varchar($l)" ); - registerColumnType( Types.BLOB, "longvarbinary" ); - registerColumnType( Types.CLOB, "longvarchar" ); - - getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "false" ); - getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE ); - //getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH); - - getDefaultProperties().setProperty( Environment.USE_SQL_COMMENTS, "false" ); - - registerFunction( "abs", new StandardSQLFunction( "abs" ) ); - registerFunction( "acos", new StandardJDBCEscapeFunction( "acos", StandardBasicTypes.DOUBLE ) ); - registerFunction( "%alphaup", new StandardSQLFunction( "%alphaup", StandardBasicTypes.STRING ) ); - registerFunction( "ascii", new StandardSQLFunction( "ascii", StandardBasicTypes.STRING ) ); - registerFunction( "asin", new StandardJDBCEscapeFunction( "asin", StandardBasicTypes.DOUBLE ) ); - registerFunction( "atan", new StandardJDBCEscapeFunction( "atan", StandardBasicTypes.DOUBLE ) ); - registerFunction( "bit_length", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "($length(?1)*8)" ) ); - // hibernate impelemnts cast in Dialect.java - registerFunction( "ceiling", new StandardSQLFunction( "ceiling", StandardBasicTypes.INTEGER ) ); - registerFunction( "char", new StandardJDBCEscapeFunction( "char", StandardBasicTypes.CHARACTER ) ); - registerFunction( "character_length", new StandardSQLFunction( "character_length", StandardBasicTypes.INTEGER ) ); - registerFunction( "char_length", new StandardSQLFunction( "char_length", StandardBasicTypes.INTEGER ) ); - registerFunction( "cos", new StandardJDBCEscapeFunction( "cos", StandardBasicTypes.DOUBLE ) ); - registerFunction( "cot", new StandardJDBCEscapeFunction( "cot", StandardBasicTypes.DOUBLE ) ); - registerFunction( "coalesce", new VarArgsSQLFunction( "coalesce(", ",", ")" ) ); - registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "", "||", "" ) ); - registerFunction( "convert", new ConvertFunction() ); - registerFunction( "curdate", new StandardJDBCEscapeFunction( "curdate", StandardBasicTypes.DATE ) ); - registerFunction( "current_date", new NoArgSQLFunction( "current_date", StandardBasicTypes.DATE, false ) ); - registerFunction( "current_time", new NoArgSQLFunction( "current_time", StandardBasicTypes.TIME, false ) ); - registerFunction( - "current_timestamp", new ConditionalParenthesisFunction( "current_timestamp", StandardBasicTypes.TIMESTAMP ) - ); - registerFunction( "curtime", new StandardJDBCEscapeFunction( "curtime", StandardBasicTypes.TIME ) ); - registerFunction( "database", new StandardJDBCEscapeFunction( "database", StandardBasicTypes.STRING ) ); - registerFunction( "dateadd", new VarArgsSQLFunction( StandardBasicTypes.TIMESTAMP, "dateadd(", ",", ")" ) ); - registerFunction( "datediff", new VarArgsSQLFunction( StandardBasicTypes.INTEGER, "datediff(", ",", ")" ) ); - registerFunction( "datename", new VarArgsSQLFunction( StandardBasicTypes.STRING, "datename(", ",", ")" ) ); - registerFunction( "datepart", new VarArgsSQLFunction( StandardBasicTypes.INTEGER, "datepart(", ",", ")" ) ); - registerFunction( "day", new StandardSQLFunction( "day", StandardBasicTypes.INTEGER ) ); - registerFunction( "dayname", new StandardJDBCEscapeFunction( "dayname", StandardBasicTypes.STRING ) ); - registerFunction( "dayofmonth", new StandardJDBCEscapeFunction( "dayofmonth", StandardBasicTypes.INTEGER ) ); - registerFunction( "dayofweek", new StandardJDBCEscapeFunction( "dayofweek", StandardBasicTypes.INTEGER ) ); - registerFunction( "dayofyear", new StandardJDBCEscapeFunction( "dayofyear", StandardBasicTypes.INTEGER ) ); - // is it necessary to register %exact since it can only appear in a where clause? - registerFunction( "%exact", new StandardSQLFunction( "%exact", StandardBasicTypes.STRING ) ); - registerFunction( "exp", new StandardJDBCEscapeFunction( "exp", StandardBasicTypes.DOUBLE ) ); - registerFunction( "%external", new StandardSQLFunction( "%external", StandardBasicTypes.STRING ) ); - registerFunction( "$extract", new VarArgsSQLFunction( StandardBasicTypes.INTEGER, "$extract(", ",", ")" ) ); - registerFunction( "$find", new VarArgsSQLFunction( StandardBasicTypes.INTEGER, "$find(", ",", ")" ) ); - registerFunction( "floor", new StandardSQLFunction( "floor", StandardBasicTypes.INTEGER ) ); - registerFunction( "getdate", new StandardSQLFunction( "getdate", StandardBasicTypes.TIMESTAMP ) ); - registerFunction( "hour", new StandardJDBCEscapeFunction( "hour", StandardBasicTypes.INTEGER ) ); - registerFunction( "ifnull", new VarArgsSQLFunction( "ifnull(", ",", ")" ) ); - registerFunction( "%internal", new StandardSQLFunction( "%internal" ) ); - registerFunction( "isnull", new VarArgsSQLFunction( "isnull(", ",", ")" ) ); - registerFunction( "isnumeric", new StandardSQLFunction( "isnumeric", StandardBasicTypes.INTEGER ) ); - registerFunction( "lcase", new StandardJDBCEscapeFunction( "lcase", StandardBasicTypes.STRING ) ); - registerFunction( "left", new StandardJDBCEscapeFunction( "left", StandardBasicTypes.STRING ) ); - registerFunction( "len", new StandardSQLFunction( "len", StandardBasicTypes.INTEGER ) ); - registerFunction( "$length", new VarArgsSQLFunction( "$length(", ",", ")" ) ); - // aggregate functions shouldn't be registered, right? - //registerFunction( "list", new StandardSQLFunction("list",StandardBasicTypes.STRING) ); - // stopped on $list - registerFunction( "$list", new VarArgsSQLFunction( "$list(", ",", ")" ) ); - registerFunction( "$listdata", new VarArgsSQLFunction( "$listdata(", ",", ")" ) ); - registerFunction( "$listfind", new VarArgsSQLFunction( "$listfind(", ",", ")" ) ); - registerFunction( "$listget", new VarArgsSQLFunction( "$listget(", ",", ")" ) ); - registerFunction( "$listlength", new StandardSQLFunction( "$listlength", StandardBasicTypes.INTEGER ) ); - registerFunction( "locate", new StandardSQLFunction( "$FIND", StandardBasicTypes.INTEGER ) ); - registerFunction( "log", new StandardJDBCEscapeFunction( "log", StandardBasicTypes.DOUBLE ) ); - registerFunction( "log10", new StandardJDBCEscapeFunction( "log", StandardBasicTypes.DOUBLE ) ); - registerFunction( "lower", new StandardSQLFunction( "lower" ) ); - registerFunction( "ltrim", new StandardSQLFunction( "ltrim" ) ); - registerFunction( "minute", new StandardJDBCEscapeFunction( "minute", StandardBasicTypes.INTEGER ) ); - registerFunction( "mod", new StandardJDBCEscapeFunction( "mod", StandardBasicTypes.DOUBLE ) ); - registerFunction( "month", new StandardJDBCEscapeFunction( "month", StandardBasicTypes.INTEGER ) ); - registerFunction( "monthname", new StandardJDBCEscapeFunction( "monthname", StandardBasicTypes.STRING ) ); - registerFunction( "now", new StandardJDBCEscapeFunction( "monthname", StandardBasicTypes.TIMESTAMP ) ); - registerFunction( "nullif", new VarArgsSQLFunction( "nullif(", ",", ")" ) ); - registerFunction( "nvl", new NvlFunction() ); - registerFunction( "%odbcin", new StandardSQLFunction( "%odbcin" ) ); - registerFunction( "%odbcout", new StandardSQLFunction( "%odbcin" ) ); - registerFunction( "%pattern", new VarArgsSQLFunction( StandardBasicTypes.STRING, "", "%pattern", "" ) ); - registerFunction( "pi", new StandardJDBCEscapeFunction( "pi", StandardBasicTypes.DOUBLE ) ); - registerFunction( "$piece", new VarArgsSQLFunction( StandardBasicTypes.STRING, "$piece(", ",", ")" ) ); - registerFunction( "position", new VarArgsSQLFunction( StandardBasicTypes.INTEGER, "position(", " in ", ")" ) ); - registerFunction( "power", new VarArgsSQLFunction( StandardBasicTypes.STRING, "power(", ",", ")" ) ); - registerFunction( "quarter", new StandardJDBCEscapeFunction( "quarter", StandardBasicTypes.INTEGER ) ); - registerFunction( "repeat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "repeat(", ",", ")" ) ); - registerFunction( "replicate", new VarArgsSQLFunction( StandardBasicTypes.STRING, "replicate(", ",", ")" ) ); - registerFunction( "right", new StandardJDBCEscapeFunction( "right", StandardBasicTypes.STRING ) ); - registerFunction( "round", new VarArgsSQLFunction( StandardBasicTypes.FLOAT, "round(", ",", ")" ) ); - registerFunction( "rtrim", new StandardSQLFunction( "rtrim", StandardBasicTypes.STRING ) ); - registerFunction( "second", new StandardJDBCEscapeFunction( "second", StandardBasicTypes.INTEGER ) ); - registerFunction( "sign", new StandardSQLFunction( "sign", StandardBasicTypes.INTEGER ) ); - registerFunction( "sin", new StandardJDBCEscapeFunction( "sin", StandardBasicTypes.DOUBLE ) ); - registerFunction( "space", new StandardSQLFunction( "space", StandardBasicTypes.STRING ) ); - registerFunction( "%sqlstring", new VarArgsSQLFunction( StandardBasicTypes.STRING, "%sqlstring(", ",", ")" ) ); - registerFunction( "%sqlupper", new VarArgsSQLFunction( StandardBasicTypes.STRING, "%sqlupper(", ",", ")" ) ); - registerFunction( "sqrt", new StandardJDBCEscapeFunction( "SQRT", StandardBasicTypes.DOUBLE ) ); - registerFunction( "%startswith", new VarArgsSQLFunction( StandardBasicTypes.STRING, "", "%startswith", "" ) ); - // below is for Cache' that don't have str in 2007.1 there is str and we register str directly - registerFunction( "str", new SQLFunctionTemplate( StandardBasicTypes.STRING, "cast(?1 as char varying)" ) ); - registerFunction( "string", new VarArgsSQLFunction( StandardBasicTypes.STRING, "string(", ",", ")" ) ); - // note that %string is deprecated - registerFunction( "%string", new VarArgsSQLFunction( StandardBasicTypes.STRING, "%string(", ",", ")" ) ); - registerFunction( "substr", new VarArgsSQLFunction( StandardBasicTypes.STRING, "substr(", ",", ")" ) ); - registerFunction( "substring", new VarArgsSQLFunction( StandardBasicTypes.STRING, "substring(", ",", ")" ) ); - registerFunction( "sysdate", new NoArgSQLFunction( "sysdate", StandardBasicTypes.TIMESTAMP, false ) ); - registerFunction( "tan", new StandardJDBCEscapeFunction( "tan", StandardBasicTypes.DOUBLE ) ); - registerFunction( "timestampadd", new StandardJDBCEscapeFunction( "timestampadd", StandardBasicTypes.DOUBLE ) ); - registerFunction( "timestampdiff", new StandardJDBCEscapeFunction( "timestampdiff", StandardBasicTypes.DOUBLE ) ); - registerFunction( "tochar", new VarArgsSQLFunction( StandardBasicTypes.STRING, "tochar(", ",", ")" ) ); - registerFunction( "to_char", new VarArgsSQLFunction( StandardBasicTypes.STRING, "to_char(", ",", ")" ) ); - registerFunction( "todate", new VarArgsSQLFunction( StandardBasicTypes.STRING, "todate(", ",", ")" ) ); - registerFunction( "to_date", new VarArgsSQLFunction( StandardBasicTypes.STRING, "todate(", ",", ")" ) ); - registerFunction( "tonumber", new StandardSQLFunction( "tonumber" ) ); - registerFunction( "to_number", new StandardSQLFunction( "tonumber" ) ); - // TRIM(end_keyword string-expression-1 FROM string-expression-2) - // use Hibernate implementation "From" is one of the parameters they pass in position ?3 - //registerFunction( "trim", new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1 ?2 from ?3)") ); - registerFunction( "truncate", new StandardJDBCEscapeFunction( "truncate", StandardBasicTypes.STRING ) ); - registerFunction( "ucase", new StandardJDBCEscapeFunction( "ucase", StandardBasicTypes.STRING ) ); - registerFunction( "upper", new StandardSQLFunction( "upper" ) ); - // %upper is deprecated - registerFunction( "%upper", new StandardSQLFunction( "%upper" ) ); - registerFunction( "user", new StandardJDBCEscapeFunction( "user", StandardBasicTypes.STRING ) ); - registerFunction( "week", new StandardJDBCEscapeFunction( "user", StandardBasicTypes.INTEGER ) ); - registerFunction( "xmlconcat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "xmlconcat(", ",", ")" ) ); - registerFunction( "xmlelement", new VarArgsSQLFunction( StandardBasicTypes.STRING, "xmlelement(", ",", ")" ) ); - // xmlforest requires a new kind of function constructor - registerFunction( "year", new StandardJDBCEscapeFunction( "year", StandardBasicTypes.INTEGER ) ); - } - - protected final void register71Functions() { - this.registerFunction( "str", new VarArgsSQLFunction( StandardBasicTypes.STRING, "str(", ",", ")" ) ); - } - - // DDL support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - public boolean hasAlterTable() { - // Does this dialect support the ALTER TABLE syntax? - return true; - } - - public boolean qualifyIndexName() { - // Do we need to qualify index names with the schema name? - return false; - } - - public boolean supportsUnique() { - // Does this dialect support the UNIQUE column syntax? - return true; - } - - /** - * The syntax used to add a foreign key constraint to a table. - * - * @return String - */ - public String getAddForeignKeyConstraintString( - String constraintName, - String[] foreignKey, - String referencedTable, - String[] primaryKey, - boolean referencesPrimaryKey) { - // The syntax used to add a foreign key constraint to a table. - return new StringBuffer( 300 ) - .append( " ADD CONSTRAINT " ) - .append( constraintName ) - .append( " FOREIGN KEY " ) - .append( constraintName ) - .append( " (" ) - .append( StringHelper.join( ", ", foreignKey ) ) // identifier-commalist - .append( ") REFERENCES " ) - .append( referencedTable ) - .append( " (" ) - .append( StringHelper.join( ", ", primaryKey ) ) // identifier-commalist - .append( ") " ) - .toString(); - } - - public boolean supportsCheck() { - // Does this dialect support check constraints? - return false; - } - - public String getAddColumnString() { - // The syntax used to add a column to a table - return " add column"; - } - - public String getCascadeConstraintsString() { - // Completely optional cascading drop clause. - return ""; - } - - public boolean dropConstraints() { - // Do we need to drop constraints before dropping tables in this dialect? - return true; - } - - public boolean supportsCascadeDelete() { - return true; - } - - public boolean hasSelfReferentialForeignKeyBug() { - return true; - } - - // temporary table support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - public boolean supportsTemporaryTables() { - return true; - } - - public String generateTemporaryTableName(String baseTableName) { - String name = super.generateTemporaryTableName( baseTableName ); - return name.length() > 25 ? name.substring( 1, 25 ) : name; - } - - public String getCreateTemporaryTableString() { - return "create global temporary table"; - } - - public Boolean performTemporaryTableDDLInIsolation() { - return Boolean.FALSE; - } - - public String getCreateTemporaryTablePostfix() { - return ""; - } - - public boolean dropTemporaryTableAfterUse() { - return true; - } - - // IDENTITY support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - public boolean supportsIdentityColumns() { - return true; - } - - public Class getNativeIdentifierGeneratorClass() { - return IdentityGenerator.class; - } - - public boolean hasDataTypeInIdentityColumn() { - // Whether this dialect has an Identity clause added to the data type or a completely seperate identity - // data type - return true; - } - - public String getIdentityColumnString() throws MappingException { - // The keyword used to specify an identity column, if identity column key generation is supported. - return "identity"; - } - - public String getIdentitySelectString() { - return "SELECT LAST_IDENTITY() FROM %TSQL_sys.snf"; - } - - // SEQUENCE support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - public boolean supportsSequences() { - return false; - } - -// It really does support sequences, but InterSystems elects to suggest usage of IDENTITY instead :/ -// Anyway, below are the actual support overrides for users wanting to use this combo... -// -// public String getSequenceNextValString(String sequenceName) { -// return "select InterSystems.Sequences_GetNext('" + sequenceName + "') from InterSystems.Sequences where ucase(name)=ucase('" + sequenceName + "')"; -// } -// -// public String getSelectSequenceNextValString(String sequenceName) { -// return "(select InterSystems.Sequences_GetNext('" + sequenceName + "') from InterSystems.Sequences where ucase(name)=ucase('" + sequenceName + "'))"; -// } -// -// public String getCreateSequenceString(String sequenceName) { -// return "insert into InterSystems.Sequences(Name) values (ucase('" + sequenceName + "'))"; -// } -// -// public String getDropSequenceString(String sequenceName) { -// return "delete from InterSystems.Sequences where ucase(name)=ucase('" + sequenceName + "')"; -// } -// -// public String getQuerySequencesString() { -// return "select name from InterSystems.Sequences"; -// } - - // lock acquisition support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - public boolean supportsForUpdate() { - // Does this dialect support the FOR UPDATE syntax? - return false; - } - - public boolean supportsForUpdateOf() { - // Does this dialect support FOR UPDATE OF, allowing particular rows to be locked? - return false; - } - - public boolean supportsForUpdateNowait() { - // Does this dialect support the Oracle-style FOR UPDATE NOWAIT syntax? - return false; - } - - public boolean supportsOuterJoinForUpdate() { - return false; - } - - public LockingStrategy getLockingStrategy(Lockable lockable, LockMode lockMode) { - // InterSystems Cache' does not current support "SELECT ... FOR UPDATE" syntax... - // Set your transaction mode to READ_COMMITTED before using - if ( lockMode==LockMode.PESSIMISTIC_FORCE_INCREMENT) { - return new PessimisticForceIncrementLockingStrategy( lockable, lockMode); - } - else if ( lockMode==LockMode.PESSIMISTIC_WRITE) { - return new PessimisticWriteUpdateLockingStrategy( lockable, lockMode); - } - else if ( lockMode==LockMode.PESSIMISTIC_READ) { - return new PessimisticReadUpdateLockingStrategy( lockable, lockMode); - } - else if ( lockMode==LockMode.OPTIMISTIC) { - return new OptimisticLockingStrategy( lockable, lockMode); - } - else if ( lockMode==LockMode.OPTIMISTIC_FORCE_INCREMENT) { - return new OptimisticForceIncrementLockingStrategy( lockable, lockMode); - } - else if ( lockMode.greaterThan( LockMode.READ ) ) { - return new UpdateLockingStrategy( lockable, lockMode ); - } - else { - return new SelectLockingStrategy( lockable, lockMode ); - } - } - - // LIMIT support (ala TOP) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - public boolean supportsLimit() { - return true; - } - - public boolean supportsLimitOffset() { - return false; - } - - public boolean supportsVariableLimit() { - return true; - } - - public boolean bindLimitParametersFirst() { - // Does the LIMIT clause come at the start of the SELECT statement, rather than at the end? - return true; - } - - public boolean useMaxForLimit() { - // Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows? - return true; - } - - public String getLimitString(String sql, boolean hasOffset) { - if ( hasOffset ) { - throw new UnsupportedOperationException( "query result offset is not supported" ); - } - - // This does not support the Cache SQL 'DISTINCT BY (comma-list)' extensions, - // but this extension is not supported through Hibernate anyway. - int insertionPoint = sql.startsWith( "select distinct" ) ? 15 : 6; - - return new StringBuffer( sql.length() + 8 ) - .append( sql ) - .insert( insertionPoint, " TOP ? " ) - .toString(); - } - - // callable statement support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - public int registerResultSetOutParameter(CallableStatement statement, int col) throws SQLException { - return col; - } - - public ResultSet getResultSet(CallableStatement ps) throws SQLException { - ps.execute(); - return ( ResultSet ) ps.getObject( 1 ); - } - - // miscellaneous support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - public String getLowercaseFunction() { - // The name of the SQL function that transforms a string to lowercase - return "lower"; - } - - public String getNullColumnString() { - // The keyword used to specify a nullable column. - return " null"; - } - - public JoinFragment createOuterJoinFragment() { - // Create an OuterJoinGenerator for this dialect. - return new CacheJoinFragment(); - } - - public String getNoColumnsInsertString() { - // The keyword used to insert a row without specifying - // any column values - return " default values"; - } - - public SQLExceptionConverter buildSQLExceptionConverter() { - return new CacheSQLStateConverter( EXTRACTER ); - } - - public static final ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter() { - /** - * Extract the name of the violated constraint from the given SQLException. - * - * @param sqle The exception that was the result of the constraint violation. - * @return The extracted constraint name. - */ - public String extractConstraintName(SQLException sqle) { - return extractUsingTemplate( "constraint (", ") violated", sqle.getMessage() ); - } - }; - - - // Overridden informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - public boolean supportsEmptyInList() { - return false; - } - - public boolean areStringComparisonsCaseInsensitive() { - return true; - } - - public boolean supportsResultSetPositionQueryMethodsOnForwardOnlyCursor() { - return false; - } -} +import java.sql.CallableStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +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; +import org.hibernate.dialect.function.NoArgSQLFunction; +import org.hibernate.dialect.function.NvlFunction; +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.lock.LockingStrategy; +import org.hibernate.dialect.lock.OptimisticForceIncrementLockingStrategy; +import org.hibernate.dialect.lock.OptimisticLockingStrategy; +import org.hibernate.dialect.lock.PessimisticForceIncrementLockingStrategy; +import org.hibernate.dialect.lock.PessimisticReadUpdateLockingStrategy; +import org.hibernate.dialect.lock.PessimisticWriteUpdateLockingStrategy; +import org.hibernate.dialect.lock.SelectLockingStrategy; +import org.hibernate.dialect.lock.UpdateLockingStrategy; +import org.hibernate.exception.internal.CacheSQLStateConverter; +import org.hibernate.exception.spi.SQLExceptionConverter; +import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; +import org.hibernate.id.IdentityGenerator; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.persister.entity.Lockable; +import org.hibernate.sql.CacheJoinFragment; +import org.hibernate.sql.JoinFragment; +import org.hibernate.type.StandardBasicTypes; + +/** + * Caché 2007.1 dialect. This class is required in order to use Hibernate with Intersystems Cach� SQL.
+ *
+ * Compatible with Cach� 2007.1. + *
+ * + * Caché and Hibernate + * + * + *

Caché and Hibernate

+ *

PREREQUISITES

+ * These setup instructions assume that both Caché and Hibernate are installed and operational. + *
+ *

HIBERNATE DIRECTORIES AND FILES

+ * JBoss distributes the InterSystems Cache' dialect for Hibernate 3.2.1 + * For earlier versions of Hibernate please contact + * InterSystems Worldwide Response Center (WRC) + * for the appropriate source files. + *
+ *

CACHÉ DOCUMENTATION

+ * Documentation for Caché is available online when Caché is running. + * It can also be obtained from the + * InterSystems website. + * The book, "Object-oriented Application Development Using the Caché Post-relational Database: + * is also available from Springer-Verlag. + *
+ *

HIBERNATE DOCUMENTATION

+ * Hibernate comes with extensive electronic documentation. + * In addition, several books on Hibernate are available from + * Manning Publications Co. + * Three available titles are "Hibernate Quickly", "Hibernate in Action", and "Java Persistence with Hibernate". + *
+ *

TO SET UP HIBERNATE FOR USE WITH CACHÉ

+ * The following steps assume that the directory where Caché was installed is C:\CacheSys. + * This is the default installation directory for Caché. + * The default installation directory for Hibernate is assumed to be C:\Hibernate. + *

+ * If either product is installed in a different location, the pathnames that follow should be modified appropriately. + *

+ * Caché version 2007.1 and above is recommended for use with + * Hibernate. The next step depends on the location of your + * CacheDB.jar depending on your version of Caché. + *

    + *
  1. Copy C:\CacheSys\dev\java\lib\JDK15\CacheDB.jar to C:\Hibernate\lib\CacheDB.jar.
  2. + *

    + *

  3. Insert the following files into your Java classpath: + *

    + *

      + *
    • All jar files in the directory C:\Hibernate\lib
    • + *
    • The directory (or directories) where hibernate.properties and/or hibernate.cfg.xml are kept.
    • + *
    + *
  4. + *

    + *

  5. In the file, hibernate.properties (or hibernate.cfg.xml), + * specify the Caché dialect and the Caché version URL settings.
  6. + *
+ *

+ * For example, in Hibernate 3.2, typical entries in hibernate.properties would have the following + * "name=value" pairs: + *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Property NameProperty Value
hibernate.dialectorg.hibernate.dialect.Cache71Dialect
hibernate.connection.driver_classcom.intersys.jdbc.CacheDriver
hibernate.connection.username(see note 1)
hibernate.connection.password(see note 1)
hibernate.connection.urljdbc:Cache://127.0.0.1:1972/USER
+ *

+ *

+ *
Note 1
+ *
Please contact your administrator for the userid and password you should use when attempting access via JDBC. + * By default, these are chosen to be "_SYSTEM" and "SYS" respectively as noted in the SQL standard.
+ *
+ *
+ *

CACHÉ VERSION URL

+ * This is the standard URL for the JDBC driver. + * For a JDBC driver on the machine hosting Caché, use the IP "loopback" address, 127.0.0.1. + * For 1972, the default port, specify the super server port of your Caché instance. + * For USER, substitute the NAMESPACE which contains your Caché database data. + *
+ *

CACHÉ DIALECTS

+ * Choices for Dialect are: + *
+ *

+ *

    + *
  1. org.hibernate.dialect.Cache71Dialect (requires Caché + * 2007.1 or above)
  2. + *

    + *

+ *
+ *

SUPPORT FOR IDENTITY COLUMNS

+ * Caché 2007.1 or later supports identity columns. For + * Hibernate to use identity columns, specify "native" as the + * generator. + *
+ *

SEQUENCE DIALECTS SUPPORT SEQUENCES

+ *

+ * To use Hibernate sequence support with Caché in a namespace, you must FIRST load the following file into that namespace: + *

+ *     etc\CacheSequences.xml
+ * 
+ * For example, at the COS terminal prompt in the namespace, run the + * following command: + *

+ * d LoadFile^%apiOBJ("c:\hibernate\etc\CacheSequences.xml","ck") + *

+ * In your Hibernate mapping you can specify sequence use. + *

+ * For example, the following shows the use of a sequence generator in a Hibernate mapping: + *

+ *     <id name="id" column="uid" type="long" unsaved-value="null">
+ *         <generator class="sequence"/>
+ *     </id>
+ * 
+ *
+ *

+ * Some versions of Hibernate under some circumstances call + * getSelectSequenceNextValString() in the dialect. If this happens + * you will receive the error message: new MappingException( "Dialect + * does not support sequences" ). + *
+ *

HIBERNATE FILES ASSOCIATED WITH CACHÉ DIALECT

+ * The following files are associated with Caché dialect: + *

+ *

    + *
  1. src\org\hibernate\dialect\Cache71Dialect.java
  2. + *
  3. src\org\hibernate\dialect\function\ConditionalParenthesisFunction.java
  4. + *
  5. src\org\hibernate\dialect\function\ConvertFunction.java
  6. + *
  7. src\org\hibernate\exception\CacheSQLStateConverter.java
  8. + *
  9. src\org\hibernate\sql\CacheJoinFragment.java
  10. + *
+ * Cache71Dialect ships with Hibernate 3.2. All other dialects are distributed by InterSystems and subclass Cache71Dialect. + * + * @author Jonathan Levinson + */ + +public class Cache71Dialect extends Dialect { + + /** + * Creates new Cach�71Dialect instance. Sets up the JDBC / + * Cach� type mappings. + */ + public Cache71Dialect() { + super(); + commonRegistration(); + register71Functions(); + } + + protected final void commonRegistration() { + // Note: For object <-> SQL datatype mappings see: + // Configuration Manager | Advanced | SQL | System DDL Datatype Mappings + // + // TBD registerColumnType(Types.BINARY, "binary($1)"); + // changed 08-11-2005, jsl + registerColumnType( Types.BINARY, "varbinary($1)" ); + registerColumnType( Types.BIGINT, "BigInt" ); + registerColumnType( Types.BIT, "bit" ); + registerColumnType( Types.CHAR, "char(1)" ); + registerColumnType( Types.DATE, "date" ); + registerColumnType( Types.DECIMAL, "decimal" ); + registerColumnType( Types.DOUBLE, "double" ); + registerColumnType( Types.FLOAT, "float" ); + registerColumnType( Types.INTEGER, "integer" ); + registerColumnType( Types.LONGVARBINARY, "longvarbinary" ); // binary %Stream + registerColumnType( Types.LONGVARCHAR, "longvarchar" ); // character %Stream + registerColumnType( Types.NUMERIC, "numeric($p,$s)" ); + registerColumnType( Types.REAL, "real" ); + registerColumnType( Types.SMALLINT, "smallint" ); + registerColumnType( Types.TIMESTAMP, "timestamp" ); + registerColumnType( Types.TIME, "time" ); + registerColumnType( Types.TINYINT, "tinyint" ); + // TBD should this be varbinary($1)? + // registerColumnType(Types.VARBINARY, "binary($1)"); + registerColumnType( Types.VARBINARY, "longvarbinary" ); + registerColumnType( Types.VARCHAR, "varchar($l)" ); + registerColumnType( Types.BLOB, "longvarbinary" ); + registerColumnType( Types.CLOB, "longvarchar" ); + + getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "false" ); + getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE ); + //getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH); + + getDefaultProperties().setProperty( Environment.USE_SQL_COMMENTS, "false" ); + + registerFunction( "abs", new StandardSQLFunction( "abs" ) ); + registerFunction( "acos", new StandardJDBCEscapeFunction( "acos", StandardBasicTypes.DOUBLE ) ); + registerFunction( "%alphaup", new StandardSQLFunction( "%alphaup", StandardBasicTypes.STRING ) ); + registerFunction( "ascii", new StandardSQLFunction( "ascii", StandardBasicTypes.STRING ) ); + registerFunction( "asin", new StandardJDBCEscapeFunction( "asin", StandardBasicTypes.DOUBLE ) ); + registerFunction( "atan", new StandardJDBCEscapeFunction( "atan", StandardBasicTypes.DOUBLE ) ); + registerFunction( "bit_length", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "($length(?1)*8)" ) ); + // hibernate impelemnts cast in Dialect.java + registerFunction( "ceiling", new StandardSQLFunction( "ceiling", StandardBasicTypes.INTEGER ) ); + registerFunction( "char", new StandardJDBCEscapeFunction( "char", StandardBasicTypes.CHARACTER ) ); + registerFunction( "character_length", new StandardSQLFunction( "character_length", StandardBasicTypes.INTEGER ) ); + registerFunction( "char_length", new StandardSQLFunction( "char_length", StandardBasicTypes.INTEGER ) ); + registerFunction( "cos", new StandardJDBCEscapeFunction( "cos", StandardBasicTypes.DOUBLE ) ); + registerFunction( "cot", new StandardJDBCEscapeFunction( "cot", StandardBasicTypes.DOUBLE ) ); + registerFunction( "coalesce", new VarArgsSQLFunction( "coalesce(", ",", ")" ) ); + registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "", "||", "" ) ); + registerFunction( "convert", new ConvertFunction() ); + registerFunction( "curdate", new StandardJDBCEscapeFunction( "curdate", StandardBasicTypes.DATE ) ); + registerFunction( "current_date", new NoArgSQLFunction( "current_date", StandardBasicTypes.DATE, false ) ); + registerFunction( "current_time", new NoArgSQLFunction( "current_time", StandardBasicTypes.TIME, false ) ); + registerFunction( + "current_timestamp", new ConditionalParenthesisFunction( "current_timestamp", StandardBasicTypes.TIMESTAMP ) + ); + registerFunction( "curtime", new StandardJDBCEscapeFunction( "curtime", StandardBasicTypes.TIME ) ); + registerFunction( "database", new StandardJDBCEscapeFunction( "database", StandardBasicTypes.STRING ) ); + registerFunction( "dateadd", new VarArgsSQLFunction( StandardBasicTypes.TIMESTAMP, "dateadd(", ",", ")" ) ); + registerFunction( "datediff", new VarArgsSQLFunction( StandardBasicTypes.INTEGER, "datediff(", ",", ")" ) ); + registerFunction( "datename", new VarArgsSQLFunction( StandardBasicTypes.STRING, "datename(", ",", ")" ) ); + registerFunction( "datepart", new VarArgsSQLFunction( StandardBasicTypes.INTEGER, "datepart(", ",", ")" ) ); + registerFunction( "day", new StandardSQLFunction( "day", StandardBasicTypes.INTEGER ) ); + registerFunction( "dayname", new StandardJDBCEscapeFunction( "dayname", StandardBasicTypes.STRING ) ); + registerFunction( "dayofmonth", new StandardJDBCEscapeFunction( "dayofmonth", StandardBasicTypes.INTEGER ) ); + registerFunction( "dayofweek", new StandardJDBCEscapeFunction( "dayofweek", StandardBasicTypes.INTEGER ) ); + registerFunction( "dayofyear", new StandardJDBCEscapeFunction( "dayofyear", StandardBasicTypes.INTEGER ) ); + // is it necessary to register %exact since it can only appear in a where clause? + registerFunction( "%exact", new StandardSQLFunction( "%exact", StandardBasicTypes.STRING ) ); + registerFunction( "exp", new StandardJDBCEscapeFunction( "exp", StandardBasicTypes.DOUBLE ) ); + registerFunction( "%external", new StandardSQLFunction( "%external", StandardBasicTypes.STRING ) ); + registerFunction( "$extract", new VarArgsSQLFunction( StandardBasicTypes.INTEGER, "$extract(", ",", ")" ) ); + registerFunction( "$find", new VarArgsSQLFunction( StandardBasicTypes.INTEGER, "$find(", ",", ")" ) ); + registerFunction( "floor", new StandardSQLFunction( "floor", StandardBasicTypes.INTEGER ) ); + registerFunction( "getdate", new StandardSQLFunction( "getdate", StandardBasicTypes.TIMESTAMP ) ); + registerFunction( "hour", new StandardJDBCEscapeFunction( "hour", StandardBasicTypes.INTEGER ) ); + registerFunction( "ifnull", new VarArgsSQLFunction( "ifnull(", ",", ")" ) ); + registerFunction( "%internal", new StandardSQLFunction( "%internal" ) ); + registerFunction( "isnull", new VarArgsSQLFunction( "isnull(", ",", ")" ) ); + registerFunction( "isnumeric", new StandardSQLFunction( "isnumeric", StandardBasicTypes.INTEGER ) ); + registerFunction( "lcase", new StandardJDBCEscapeFunction( "lcase", StandardBasicTypes.STRING ) ); + registerFunction( "left", new StandardJDBCEscapeFunction( "left", StandardBasicTypes.STRING ) ); + registerFunction( "len", new StandardSQLFunction( "len", StandardBasicTypes.INTEGER ) ); + registerFunction( "$length", new VarArgsSQLFunction( "$length(", ",", ")" ) ); + // aggregate functions shouldn't be registered, right? + //registerFunction( "list", new StandardSQLFunction("list",StandardBasicTypes.STRING) ); + // stopped on $list + registerFunction( "$list", new VarArgsSQLFunction( "$list(", ",", ")" ) ); + registerFunction( "$listdata", new VarArgsSQLFunction( "$listdata(", ",", ")" ) ); + registerFunction( "$listfind", new VarArgsSQLFunction( "$listfind(", ",", ")" ) ); + registerFunction( "$listget", new VarArgsSQLFunction( "$listget(", ",", ")" ) ); + registerFunction( "$listlength", new StandardSQLFunction( "$listlength", StandardBasicTypes.INTEGER ) ); + registerFunction( "locate", new StandardSQLFunction( "$FIND", StandardBasicTypes.INTEGER ) ); + registerFunction( "log", new StandardJDBCEscapeFunction( "log", StandardBasicTypes.DOUBLE ) ); + registerFunction( "log10", new StandardJDBCEscapeFunction( "log", StandardBasicTypes.DOUBLE ) ); + registerFunction( "lower", new StandardSQLFunction( "lower" ) ); + registerFunction( "ltrim", new StandardSQLFunction( "ltrim" ) ); + registerFunction( "minute", new StandardJDBCEscapeFunction( "minute", StandardBasicTypes.INTEGER ) ); + registerFunction( "mod", new StandardJDBCEscapeFunction( "mod", StandardBasicTypes.DOUBLE ) ); + registerFunction( "month", new StandardJDBCEscapeFunction( "month", StandardBasicTypes.INTEGER ) ); + registerFunction( "monthname", new StandardJDBCEscapeFunction( "monthname", StandardBasicTypes.STRING ) ); + registerFunction( "now", new StandardJDBCEscapeFunction( "monthname", StandardBasicTypes.TIMESTAMP ) ); + registerFunction( "nullif", new VarArgsSQLFunction( "nullif(", ",", ")" ) ); + registerFunction( "nvl", new NvlFunction() ); + registerFunction( "%odbcin", new StandardSQLFunction( "%odbcin" ) ); + registerFunction( "%odbcout", new StandardSQLFunction( "%odbcin" ) ); + registerFunction( "%pattern", new VarArgsSQLFunction( StandardBasicTypes.STRING, "", "%pattern", "" ) ); + registerFunction( "pi", new StandardJDBCEscapeFunction( "pi", StandardBasicTypes.DOUBLE ) ); + registerFunction( "$piece", new VarArgsSQLFunction( StandardBasicTypes.STRING, "$piece(", ",", ")" ) ); + registerFunction( "position", new VarArgsSQLFunction( StandardBasicTypes.INTEGER, "position(", " in ", ")" ) ); + registerFunction( "power", new VarArgsSQLFunction( StandardBasicTypes.STRING, "power(", ",", ")" ) ); + registerFunction( "quarter", new StandardJDBCEscapeFunction( "quarter", StandardBasicTypes.INTEGER ) ); + registerFunction( "repeat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "repeat(", ",", ")" ) ); + registerFunction( "replicate", new VarArgsSQLFunction( StandardBasicTypes.STRING, "replicate(", ",", ")" ) ); + registerFunction( "right", new StandardJDBCEscapeFunction( "right", StandardBasicTypes.STRING ) ); + registerFunction( "round", new VarArgsSQLFunction( StandardBasicTypes.FLOAT, "round(", ",", ")" ) ); + registerFunction( "rtrim", new StandardSQLFunction( "rtrim", StandardBasicTypes.STRING ) ); + registerFunction( "second", new StandardJDBCEscapeFunction( "second", StandardBasicTypes.INTEGER ) ); + registerFunction( "sign", new StandardSQLFunction( "sign", StandardBasicTypes.INTEGER ) ); + registerFunction( "sin", new StandardJDBCEscapeFunction( "sin", StandardBasicTypes.DOUBLE ) ); + registerFunction( "space", new StandardSQLFunction( "space", StandardBasicTypes.STRING ) ); + registerFunction( "%sqlstring", new VarArgsSQLFunction( StandardBasicTypes.STRING, "%sqlstring(", ",", ")" ) ); + registerFunction( "%sqlupper", new VarArgsSQLFunction( StandardBasicTypes.STRING, "%sqlupper(", ",", ")" ) ); + registerFunction( "sqrt", new StandardJDBCEscapeFunction( "SQRT", StandardBasicTypes.DOUBLE ) ); + registerFunction( "%startswith", new VarArgsSQLFunction( StandardBasicTypes.STRING, "", "%startswith", "" ) ); + // below is for Cache' that don't have str in 2007.1 there is str and we register str directly + registerFunction( "str", new SQLFunctionTemplate( StandardBasicTypes.STRING, "cast(?1 as char varying)" ) ); + registerFunction( "string", new VarArgsSQLFunction( StandardBasicTypes.STRING, "string(", ",", ")" ) ); + // note that %string is deprecated + registerFunction( "%string", new VarArgsSQLFunction( StandardBasicTypes.STRING, "%string(", ",", ")" ) ); + registerFunction( "substr", new VarArgsSQLFunction( StandardBasicTypes.STRING, "substr(", ",", ")" ) ); + registerFunction( "substring", new VarArgsSQLFunction( StandardBasicTypes.STRING, "substring(", ",", ")" ) ); + registerFunction( "sysdate", new NoArgSQLFunction( "sysdate", StandardBasicTypes.TIMESTAMP, false ) ); + registerFunction( "tan", new StandardJDBCEscapeFunction( "tan", StandardBasicTypes.DOUBLE ) ); + registerFunction( "timestampadd", new StandardJDBCEscapeFunction( "timestampadd", StandardBasicTypes.DOUBLE ) ); + registerFunction( "timestampdiff", new StandardJDBCEscapeFunction( "timestampdiff", StandardBasicTypes.DOUBLE ) ); + registerFunction( "tochar", new VarArgsSQLFunction( StandardBasicTypes.STRING, "tochar(", ",", ")" ) ); + registerFunction( "to_char", new VarArgsSQLFunction( StandardBasicTypes.STRING, "to_char(", ",", ")" ) ); + registerFunction( "todate", new VarArgsSQLFunction( StandardBasicTypes.STRING, "todate(", ",", ")" ) ); + registerFunction( "to_date", new VarArgsSQLFunction( StandardBasicTypes.STRING, "todate(", ",", ")" ) ); + registerFunction( "tonumber", new StandardSQLFunction( "tonumber" ) ); + registerFunction( "to_number", new StandardSQLFunction( "tonumber" ) ); + // TRIM(end_keyword string-expression-1 FROM string-expression-2) + // use Hibernate implementation "From" is one of the parameters they pass in position ?3 + //registerFunction( "trim", new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1 ?2 from ?3)") ); + registerFunction( "truncate", new StandardJDBCEscapeFunction( "truncate", StandardBasicTypes.STRING ) ); + registerFunction( "ucase", new StandardJDBCEscapeFunction( "ucase", StandardBasicTypes.STRING ) ); + registerFunction( "upper", new StandardSQLFunction( "upper" ) ); + // %upper is deprecated + registerFunction( "%upper", new StandardSQLFunction( "%upper" ) ); + registerFunction( "user", new StandardJDBCEscapeFunction( "user", StandardBasicTypes.STRING ) ); + registerFunction( "week", new StandardJDBCEscapeFunction( "user", StandardBasicTypes.INTEGER ) ); + registerFunction( "xmlconcat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "xmlconcat(", ",", ")" ) ); + registerFunction( "xmlelement", new VarArgsSQLFunction( StandardBasicTypes.STRING, "xmlelement(", ",", ")" ) ); + // xmlforest requires a new kind of function constructor + registerFunction( "year", new StandardJDBCEscapeFunction( "year", StandardBasicTypes.INTEGER ) ); + } + + protected final void register71Functions() { + this.registerFunction( "str", new VarArgsSQLFunction( StandardBasicTypes.STRING, "str(", ",", ")" ) ); + } + + // DDL support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + public boolean hasAlterTable() { + // Does this dialect support the ALTER TABLE syntax? + return true; + } + + public boolean qualifyIndexName() { + // Do we need to qualify index names with the schema name? + return false; + } + + public boolean supportsUnique() { + // Does this dialect support the UNIQUE column syntax? + return true; + } + + /** + * The syntax used to add a foreign key constraint to a table. + * + * @return String + */ + public String getAddForeignKeyConstraintString( + String constraintName, + String[] foreignKey, + String referencedTable, + String[] primaryKey, + boolean referencesPrimaryKey) { + // The syntax used to add a foreign key constraint to a table. + return new StringBuffer( 300 ) + .append( " ADD CONSTRAINT " ) + .append( constraintName ) + .append( " FOREIGN KEY " ) + .append( constraintName ) + .append( " (" ) + .append( StringHelper.join( ", ", foreignKey ) ) // identifier-commalist + .append( ") REFERENCES " ) + .append( referencedTable ) + .append( " (" ) + .append( StringHelper.join( ", ", primaryKey ) ) // identifier-commalist + .append( ") " ) + .toString(); + } + + public boolean supportsCheck() { + // Does this dialect support check constraints? + return false; + } + + public String getAddColumnString() { + // The syntax used to add a column to a table + return " add column"; + } + + public String getCascadeConstraintsString() { + // Completely optional cascading drop clause. + return ""; + } + + public boolean dropConstraints() { + // Do we need to drop constraints before dropping tables in this dialect? + return true; + } + + public boolean supportsCascadeDelete() { + return true; + } + + public boolean hasSelfReferentialForeignKeyBug() { + return true; + } + + // temporary table support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + public boolean supportsTemporaryTables() { + return true; + } + + public String generateTemporaryTableName(String baseTableName) { + String name = super.generateTemporaryTableName( baseTableName ); + return name.length() > 25 ? name.substring( 1, 25 ) : name; + } + + public String getCreateTemporaryTableString() { + return "create global temporary table"; + } + + public Boolean performTemporaryTableDDLInIsolation() { + return Boolean.FALSE; + } + + public String getCreateTemporaryTablePostfix() { + return ""; + } + + public boolean dropTemporaryTableAfterUse() { + return true; + } + + // IDENTITY support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + public boolean supportsIdentityColumns() { + return true; + } + + public Class getNativeIdentifierGeneratorClass() { + return IdentityGenerator.class; + } + + public boolean hasDataTypeInIdentityColumn() { + // Whether this dialect has an Identity clause added to the data type or a completely seperate identity + // data type + return true; + } + + public String getIdentityColumnString() throws MappingException { + // The keyword used to specify an identity column, if identity column key generation is supported. + return "identity"; + } + + public String getIdentitySelectString() { + return "SELECT LAST_IDENTITY() FROM %TSQL_sys.snf"; + } + + // SEQUENCE support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + public boolean supportsSequences() { + return false; + } + +// It really does support sequences, but InterSystems elects to suggest usage of IDENTITY instead :/ +// Anyway, below are the actual support overrides for users wanting to use this combo... +// +// public String getSequenceNextValString(String sequenceName) { +// return "select InterSystems.Sequences_GetNext('" + sequenceName + "') from InterSystems.Sequences where ucase(name)=ucase('" + sequenceName + "')"; +// } +// +// public String getSelectSequenceNextValString(String sequenceName) { +// return "(select InterSystems.Sequences_GetNext('" + sequenceName + "') from InterSystems.Sequences where ucase(name)=ucase('" + sequenceName + "'))"; +// } +// +// public String getCreateSequenceString(String sequenceName) { +// return "insert into InterSystems.Sequences(Name) values (ucase('" + sequenceName + "'))"; +// } +// +// public String getDropSequenceString(String sequenceName) { +// return "delete from InterSystems.Sequences where ucase(name)=ucase('" + sequenceName + "')"; +// } +// +// public String getQuerySequencesString() { +// return "select name from InterSystems.Sequences"; +// } + + // lock acquisition support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + public boolean supportsForUpdate() { + // Does this dialect support the FOR UPDATE syntax? + return false; + } + + public boolean supportsForUpdateOf() { + // Does this dialect support FOR UPDATE OF, allowing particular rows to be locked? + return false; + } + + public boolean supportsForUpdateNowait() { + // Does this dialect support the Oracle-style FOR UPDATE NOWAIT syntax? + return false; + } + + public boolean supportsOuterJoinForUpdate() { + return false; + } + + public LockingStrategy getLockingStrategy(Lockable lockable, LockMode lockMode) { + // InterSystems Cache' does not current support "SELECT ... FOR UPDATE" syntax... + // Set your transaction mode to READ_COMMITTED before using + if ( lockMode==LockMode.PESSIMISTIC_FORCE_INCREMENT) { + return new PessimisticForceIncrementLockingStrategy( lockable, lockMode); + } + else if ( lockMode==LockMode.PESSIMISTIC_WRITE) { + return new PessimisticWriteUpdateLockingStrategy( lockable, lockMode); + } + else if ( lockMode==LockMode.PESSIMISTIC_READ) { + return new PessimisticReadUpdateLockingStrategy( lockable, lockMode); + } + else if ( lockMode==LockMode.OPTIMISTIC) { + return new OptimisticLockingStrategy( lockable, lockMode); + } + else if ( lockMode==LockMode.OPTIMISTIC_FORCE_INCREMENT) { + return new OptimisticForceIncrementLockingStrategy( lockable, lockMode); + } + else if ( lockMode.greaterThan( LockMode.READ ) ) { + return new UpdateLockingStrategy( lockable, lockMode ); + } + else { + return new SelectLockingStrategy( lockable, lockMode ); + } + } + + // LIMIT support (ala TOP) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + public boolean supportsLimit() { + return true; + } + + public boolean supportsLimitOffset() { + return false; + } + + public boolean supportsVariableLimit() { + return true; + } + + public boolean bindLimitParametersFirst() { + // Does the LIMIT clause come at the start of the SELECT statement, rather than at the end? + return true; + } + + public boolean useMaxForLimit() { + // Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows? + return true; + } + + public String getLimitString(String sql, boolean hasOffset) { + if ( hasOffset ) { + throw new UnsupportedOperationException( "query result offset is not supported" ); + } + + // This does not support the Cache SQL 'DISTINCT BY (comma-list)' extensions, + // but this extension is not supported through Hibernate anyway. + int insertionPoint = sql.startsWith( "select distinct" ) ? 15 : 6; + + return new StringBuffer( sql.length() + 8 ) + .append( sql ) + .insert( insertionPoint, " TOP ? " ) + .toString(); + } + + // callable statement support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + public int registerResultSetOutParameter(CallableStatement statement, int col) throws SQLException { + return col; + } + + public ResultSet getResultSet(CallableStatement ps) throws SQLException { + ps.execute(); + return ( ResultSet ) ps.getObject( 1 ); + } + + // miscellaneous support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + public String getLowercaseFunction() { + // The name of the SQL function that transforms a string to lowercase + return "lower"; + } + + public String getNullColumnString() { + // The keyword used to specify a nullable column. + return " null"; + } + + public JoinFragment createOuterJoinFragment() { + // Create an OuterJoinGenerator for this dialect. + return new CacheJoinFragment(); + } + + public String getNoColumnsInsertString() { + // The keyword used to insert a row without specifying + // any column values + return " default values"; + } + + public SQLExceptionConverter buildSQLExceptionConverter() { + return new CacheSQLStateConverter( EXTRACTER ); + } + + public static final ViolatedConstraintNameExtracter EXTRACTER = new TemplatedViolatedConstraintNameExtracter() { + /** + * Extract the name of the violated constraint from the given SQLException. + * + * @param sqle The exception that was the result of the constraint violation. + * @return The extracted constraint name. + */ + public String extractConstraintName(SQLException sqle) { + return extractUsingTemplate( "constraint (", ") violated", sqle.getMessage() ); + } + }; + + + // Overridden informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + public boolean supportsEmptyInList() { + return false; + } + + public boolean areStringComparisonsCaseInsensitive() { + return true; + } + + public boolean supportsResultSetPositionQueryMethodsOnForwardOnlyCursor() { + return false; + } +} 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 4ec5710f01..54a0a172f1 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -57,9 +57,9 @@ import org.hibernate.dialect.lock.PessimisticReadSelectLockingStrategy; import org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy; import org.hibernate.dialect.lock.SelectLockingStrategy; import org.hibernate.engine.jdbc.LobCreator; -import org.hibernate.exception.SQLExceptionConverter; -import org.hibernate.exception.SQLStateConverter; -import org.hibernate.exception.ViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.SQLExceptionConverter; +import org.hibernate.exception.internal.SQLStateConverter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.id.IdentityGenerator; import org.hibernate.id.SequenceGenerator; import org.hibernate.id.TableHiLoGenerator; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java index 048280e334..ba281ce6cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java @@ -25,14 +25,15 @@ package org.hibernate.dialect; import java.sql.SQLException; import java.sql.Types; + +import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.cfg.Environment; 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.exception.TemplatedViolatedConstraintNameExtracter; -import org.hibernate.exception.ViolatedConstraintNameExtracter; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.type.StandardBasicTypes; import org.jboss.logging.Logger; 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 ffaf04c383..8e1ab6031e 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java @@ -27,6 +27,8 @@ import java.io.Serializable; import java.sql.SQLException; import java.sql.Types; +import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.JDBCException; import org.hibernate.LockMode; @@ -45,8 +47,6 @@ import org.hibernate.dialect.lock.PessimisticReadSelectLockingStrategy; import org.hibernate.dialect.lock.PessimisticWriteSelectLockingStrategy; import org.hibernate.dialect.lock.SelectLockingStrategy; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.exception.TemplatedViolatedConstraintNameExtracter; -import org.hibernate.exception.ViolatedConstraintNameExtracter; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.persister.entity.Lockable; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java index b664bab1c7..567c4399bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java @@ -26,8 +26,8 @@ import java.sql.SQLException; import java.sql.Types; import org.hibernate.MappingException; import org.hibernate.dialect.function.VarArgsSQLFunction; -import org.hibernate.exception.TemplatedViolatedConstraintNameExtracter; -import org.hibernate.exception.ViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.StringHelper; import org.hibernate.type.StandardBasicTypes; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java index 53432d3591..e549ed576c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java @@ -34,8 +34,8 @@ import org.hibernate.dialect.function.NvlFunction; import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.dialect.function.StandardSQLFunction; import org.hibernate.dialect.function.VarArgsSQLFunction; -import org.hibernate.exception.TemplatedViolatedConstraintNameExtracter; -import org.hibernate.exception.ViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.sql.CaseFragment; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java index 8c6f6bc04d..ae37fc1fa4 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java @@ -28,6 +28,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import org.hibernate.HibernateException; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.cfg.Environment; import org.hibernate.dialect.function.NoArgSQLFunction; @@ -35,8 +36,7 @@ import org.hibernate.dialect.function.NvlFunction; import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.dialect.function.StandardSQLFunction; import org.hibernate.dialect.function.VarArgsSQLFunction; -import org.hibernate.exception.TemplatedViolatedConstraintNameExtracter; -import org.hibernate.exception.ViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.type.StandardBasicTypes; 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 d96aecd78f..99c8bb9fbe 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java @@ -35,8 +35,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.exception.TemplatedViolatedConstraintNameExtracter; -import org.hibernate.exception.ViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.id.SequenceGenerator; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.type.StandardBasicTypes; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/resolver/BasicSQLExceptionConverter.java b/hibernate-core/src/main/java/org/hibernate/dialect/resolver/BasicSQLExceptionConverter.java index 5cfada1f50..ce92b29ff7 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/resolver/BasicSQLExceptionConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/resolver/BasicSQLExceptionConverter.java @@ -24,10 +24,10 @@ package org.hibernate.dialect.resolver; import java.sql.SQLException; +import org.hibernate.exception.internal.SQLStateConverter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.JDBCException; -import org.hibernate.exception.SQLStateConverter; -import org.hibernate.exception.ViolatedConstraintNameExtracter; import org.jboss.logging.Logger; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlExceptionHelper.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlExceptionHelper.java index 4b5e1f7b09..d8e1570ddf 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlExceptionHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlExceptionHelper.java @@ -28,11 +28,11 @@ import java.sql.SQLException; import java.sql.SQLWarning; import java.sql.Statement; +import org.hibernate.exception.internal.SQLStateConverter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.JDBCException; -import org.hibernate.exception.SQLExceptionConverter; -import org.hibernate.exception.SQLStateConverter; -import org.hibernate.exception.ViolatedConstraintNameExtracter; +import org.hibernate.exception.spi.SQLExceptionConverter; import org.hibernate.internal.util.StringHelper; import org.jboss.logging.Logger; import org.jboss.logging.Logger.Level; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java index ae92327f0e..f4c1bdef0c 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java @@ -44,7 +44,7 @@ import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.SqlExceptionHelper; import org.hibernate.engine.profile.FetchProfile; import org.hibernate.engine.query.spi.QueryPlanCache; -import org.hibernate.exception.SQLExceptionConverter; +import org.hibernate.exception.spi.SQLExceptionConverter; import org.hibernate.id.IdentifierGenerator; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; diff --git a/hibernate-core/src/main/java/org/hibernate/exception/CacheSQLStateConverter.java b/hibernate-core/src/main/java/org/hibernate/exception/internal/CacheSQLStateConverter.java similarity index 89% rename from hibernate-core/src/main/java/org/hibernate/exception/CacheSQLStateConverter.java rename to hibernate-core/src/main/java/org/hibernate/exception/internal/CacheSQLStateConverter.java index 74607bba4d..c58025d381 100644 --- a/hibernate-core/src/main/java/org/hibernate/exception/CacheSQLStateConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/exception/internal/CacheSQLStateConverter.java @@ -1,116 +1,123 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - * - */ -package org.hibernate.exception; - -import java.sql.SQLException; -import java.util.HashSet; -import java.util.Set; -import org.hibernate.JDBCException; -import org.hibernate.internal.util.JdbcExceptionHelper; - -/** - * A SQLExceptionConverter implementation specific to Caché SQL, - * accounting for its custom integrity constraint violation error codes. - * - * @author Jonathan Levinson - */ -public class CacheSQLStateConverter implements SQLExceptionConverter { - - private ViolatedConstraintNameExtracter extracter; - - private static final Set SQL_GRAMMAR_CATEGORIES = new HashSet(); - private static final Set DATA_CATEGORIES = new HashSet(); - private static final Set INTEGRITY_VIOLATION_CATEGORIES = new HashSet(); - private static final Set CONNECTION_CATEGORIES = new HashSet(); - - static { - SQL_GRAMMAR_CATEGORIES.add( "07" ); - SQL_GRAMMAR_CATEGORIES.add( "37" ); - SQL_GRAMMAR_CATEGORIES.add( "42" ); - SQL_GRAMMAR_CATEGORIES.add( "65" ); - SQL_GRAMMAR_CATEGORIES.add( "S0" ); - SQL_GRAMMAR_CATEGORIES.add( "20" ); - - DATA_CATEGORIES.add( "22" ); - DATA_CATEGORIES.add( "21" ); - DATA_CATEGORIES.add( "02" ); - - INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 119 ) ); - INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 120 ) ); - INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 121 ) ); - INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 122 ) ); - INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 123 ) ); - INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 124 ) ); - INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 125 ) ); - INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 127 ) ); - - CONNECTION_CATEGORIES.add( "08" ); - } - - public CacheSQLStateConverter(ViolatedConstraintNameExtracter extracter) { - this.extracter = extracter; - } - - /** - * Convert the given SQLException into Hibernate's JDBCException hierarchy. - * - * @param sqlException The SQLException to be converted. - * @param message An optional error message. - * @param sql Optionally, the sql being performed when the exception occurred. - * @return The resulting JDBCException. - */ - public JDBCException convert(SQLException sqlException, String message, String sql) { - String sqlStateClassCode = JdbcExceptionHelper.extractSqlStateClassCode( sqlException ); - Integer errorCode = new Integer( JdbcExceptionHelper.extractErrorCode( sqlException ) ); - if ( sqlStateClassCode != null ) { - if ( SQL_GRAMMAR_CATEGORIES.contains( sqlStateClassCode ) ) { - return new SQLGrammarException( message, sqlException, sql ); - } - else if ( INTEGRITY_VIOLATION_CATEGORIES.contains( errorCode ) ) { - String constraintName = extracter.extractConstraintName( sqlException ); - return new ConstraintViolationException( message, sqlException, sql, constraintName ); - } - else if ( CONNECTION_CATEGORIES.contains( sqlStateClassCode ) ) { - return new JDBCConnectionException( message, sqlException, sql ); - } - else if ( DATA_CATEGORIES.contains( sqlStateClassCode ) ) { - return new DataException( message, sqlException, sql ); - } - } - return handledNonSpecificException( sqlException, message, sql ); - } - - /** - * Handle an exception not converted to a specific type based on the SQLState. - * - * @param sqlException The exception to be handled. - * @param message An optional message - * @param sql Optionally, the sql being performed when the exception occurred. - * @return The converted exception; should never be null. - */ - protected JDBCException handledNonSpecificException(SQLException sqlException, String message, String sql) { - return new GenericJDBCException( message, sqlException, sql ); - } -} +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.exception.internal; + +import java.sql.SQLException; +import java.util.HashSet; +import java.util.Set; + +import org.hibernate.JDBCException; +import org.hibernate.exception.ConstraintViolationException; +import org.hibernate.exception.DataException; +import org.hibernate.exception.GenericJDBCException; +import org.hibernate.exception.JDBCConnectionException; +import org.hibernate.exception.SQLGrammarException; +import org.hibernate.exception.spi.SQLExceptionConverter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; +import org.hibernate.internal.util.JdbcExceptionHelper; + +/** + * A SQLExceptionConverter implementation specific to Caché SQL, + * accounting for its custom integrity constraint violation error codes. + * + * @author Jonathan Levinson + */ +public class CacheSQLStateConverter implements SQLExceptionConverter { + + private ViolatedConstraintNameExtracter extracter; + + private static final Set SQL_GRAMMAR_CATEGORIES = new HashSet(); + private static final Set DATA_CATEGORIES = new HashSet(); + private static final Set INTEGRITY_VIOLATION_CATEGORIES = new HashSet(); + private static final Set CONNECTION_CATEGORIES = new HashSet(); + + static { + SQL_GRAMMAR_CATEGORIES.add( "07" ); + SQL_GRAMMAR_CATEGORIES.add( "37" ); + SQL_GRAMMAR_CATEGORIES.add( "42" ); + SQL_GRAMMAR_CATEGORIES.add( "65" ); + SQL_GRAMMAR_CATEGORIES.add( "S0" ); + SQL_GRAMMAR_CATEGORIES.add( "20" ); + + DATA_CATEGORIES.add( "22" ); + DATA_CATEGORIES.add( "21" ); + DATA_CATEGORIES.add( "02" ); + + INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 119 ) ); + INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 120 ) ); + INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 121 ) ); + INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 122 ) ); + INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 123 ) ); + INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 124 ) ); + INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 125 ) ); + INTEGRITY_VIOLATION_CATEGORIES.add( new Integer( 127 ) ); + + CONNECTION_CATEGORIES.add( "08" ); + } + + public CacheSQLStateConverter(ViolatedConstraintNameExtracter extracter) { + this.extracter = extracter; + } + + /** + * Convert the given SQLException into Hibernate's JDBCException hierarchy. + * + * @param sqlException The SQLException to be converted. + * @param message An optional error message. + * @param sql Optionally, the sql being performed when the exception occurred. + * @return The resulting JDBCException. + */ + public JDBCException convert(SQLException sqlException, String message, String sql) { + String sqlStateClassCode = JdbcExceptionHelper.extractSqlStateClassCode( sqlException ); + Integer errorCode = new Integer( JdbcExceptionHelper.extractErrorCode( sqlException ) ); + if ( sqlStateClassCode != null ) { + if ( SQL_GRAMMAR_CATEGORIES.contains( sqlStateClassCode ) ) { + return new SQLGrammarException( message, sqlException, sql ); + } + else if ( INTEGRITY_VIOLATION_CATEGORIES.contains( errorCode ) ) { + String constraintName = extracter.extractConstraintName( sqlException ); + return new ConstraintViolationException( message, sqlException, sql, constraintName ); + } + else if ( CONNECTION_CATEGORIES.contains( sqlStateClassCode ) ) { + return new JDBCConnectionException( message, sqlException, sql ); + } + else if ( DATA_CATEGORIES.contains( sqlStateClassCode ) ) { + return new DataException( message, sqlException, sql ); + } + } + return handledNonSpecificException( sqlException, message, sql ); + } + + /** + * Handle an exception not converted to a specific type based on the SQLState. + * + * @param sqlException The exception to be handled. + * @param message An optional message + * @param sql Optionally, the sql being performed when the exception occurred. + * @return The converted exception; should never be null. + */ + protected JDBCException handledNonSpecificException(SQLException sqlException, String message, String sql) { + return new GenericJDBCException( message, sqlException, sql ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/exception/SQLStateConverter.java b/hibernate-core/src/main/java/org/hibernate/exception/internal/SQLStateConverter.java similarity index 89% rename from hibernate-core/src/main/java/org/hibernate/exception/SQLStateConverter.java rename to hibernate-core/src/main/java/org/hibernate/exception/internal/SQLStateConverter.java index b8f57f6a41..2eda211532 100644 --- a/hibernate-core/src/main/java/org/hibernate/exception/SQLStateConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/exception/internal/SQLStateConverter.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2010, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,16 +20,24 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ -package org.hibernate.exception; +package org.hibernate.exception.internal; import java.sql.SQLException; import java.util.HashSet; import java.util.Set; + import org.hibernate.JDBCException; import org.hibernate.PessimisticLockException; import org.hibernate.QueryTimeoutException; +import org.hibernate.exception.ConstraintViolationException; +import org.hibernate.exception.DataException; +import org.hibernate.exception.GenericJDBCException; +import org.hibernate.exception.JDBCConnectionException; +import org.hibernate.exception.LockAcquisitionException; +import org.hibernate.exception.SQLGrammarException; +import org.hibernate.exception.spi.SQLExceptionConverter; +import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.internal.util.JdbcExceptionHelper; /** diff --git a/hibernate-core/src/main/java/org/hibernate/exception/Configurable.java b/hibernate-core/src/main/java/org/hibernate/exception/spi/Configurable.java similarity index 83% rename from hibernate-core/src/main/java/org/hibernate/exception/Configurable.java rename to hibernate-core/src/main/java/org/hibernate/exception/spi/Configurable.java index 70306305a0..6b86231ab2 100644 --- a/hibernate-core/src/main/java/org/hibernate/exception/Configurable.java +++ b/hibernate-core/src/main/java/org/hibernate/exception/spi/Configurable.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,10 +20,11 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ -package org.hibernate.exception; +package org.hibernate.exception.spi; + import java.util.Properties; + import org.hibernate.HibernateException; /** @@ -33,8 +34,6 @@ import org.hibernate.HibernateException; * @author Steve Ebersole */ public interface Configurable { - // todo: this might really even be moved into the cfg package and used as the basis for all things which are configurable. - /** * Configure the component, using the given settings and properties. * diff --git a/hibernate-core/src/main/java/org/hibernate/exception/SQLExceptionConverter.java b/hibernate-core/src/main/java/org/hibernate/exception/spi/SQLExceptionConverter.java similarity index 82% rename from hibernate-core/src/main/java/org/hibernate/exception/SQLExceptionConverter.java rename to hibernate-core/src/main/java/org/hibernate/exception/spi/SQLExceptionConverter.java index 143395f6ba..2da3dcea39 100644 --- a/hibernate-core/src/main/java/org/hibernate/exception/SQLExceptionConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/exception/spi/SQLExceptionConverter.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,12 +20,12 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ -package org.hibernate.exception; +package org.hibernate.exception.spi; import java.io.Serializable; import java.sql.SQLException; + import org.hibernate.JDBCException; /** @@ -36,7 +36,7 @@ import org.hibernate.JDBCException; * Implementations must have a constructor which takes a * {@link ViolatedConstraintNameExtracter} parameter. *

- * Implementations may implement {@link Configurable} if they need to perform + * Implementations may implement {@link org.hibernate.exception.spi.Configurable} if they need to perform * configuration steps prior to first use. * * @author Steve Ebersole @@ -49,7 +49,7 @@ public interface SQLExceptionConverter extends Serializable { * @param sqlException The SQLException to be converted. * @param message An optional error message. * @return The resulting JDBCException. - * @see ConstraintViolationException, JDBCConnectionException, SQLGrammarException, LockAcquisitionException + * @see org.hibernate.exception.ConstraintViolationException , JDBCConnectionException, SQLGrammarException, LockAcquisitionException */ public JDBCException convert(SQLException sqlException, String message, String sql); } diff --git a/hibernate-core/src/main/java/org/hibernate/exception/SQLExceptionConverterFactory.java b/hibernate-core/src/main/java/org/hibernate/exception/spi/SQLExceptionConverterFactory.java similarity index 93% rename from hibernate-core/src/main/java/org/hibernate/exception/SQLExceptionConverterFactory.java rename to hibernate-core/src/main/java/org/hibernate/exception/spi/SQLExceptionConverterFactory.java index 40e4b58265..ba967a548d 100644 --- a/hibernate-core/src/main/java/org/hibernate/exception/SQLExceptionConverterFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/exception/spi/SQLExceptionConverterFactory.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,23 +20,24 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ -package org.hibernate.exception; +package org.hibernate.exception.spi; import java.lang.reflect.Constructor; import java.sql.SQLException; import java.util.Properties; + +import org.jboss.logging.Logger; + import org.hibernate.HibernateException; -import org.hibernate.internal.CoreMessageLogger; import org.hibernate.JDBCException; import org.hibernate.cfg.Environment; import org.hibernate.dialect.Dialect; +import org.hibernate.exception.GenericJDBCException; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.StringHelper; -import org.jboss.logging.Logger; - /** * A factory for building SQLExceptionConverter instances. * @@ -79,7 +80,7 @@ public class SQLExceptionConverterFactory { if ( converter instanceof Configurable ) { try { - ( ( Configurable ) converter ).configure( properties ); + ( (Configurable) converter ).configure( properties ); } catch ( HibernateException e ) { LOG.unableToConfigureSqlExceptionConverter(e); @@ -92,7 +93,7 @@ public class SQLExceptionConverterFactory { /** * Builds a minimal converter. The instance returned here just always converts to - * {@link GenericJDBCException}. + * {@link org.hibernate.exception.GenericJDBCException}. * * @return The minimal converter. */ diff --git a/hibernate-core/src/main/java/org/hibernate/exception/TemplatedViolatedConstraintNameExtracter.java b/hibernate-core/src/main/java/org/hibernate/exception/spi/TemplatedViolatedConstraintNameExtracter.java similarity index 92% rename from hibernate-core/src/main/java/org/hibernate/exception/TemplatedViolatedConstraintNameExtracter.java rename to hibernate-core/src/main/java/org/hibernate/exception/spi/TemplatedViolatedConstraintNameExtracter.java index 31609eb162..303d2be611 100644 --- a/hibernate-core/src/main/java/org/hibernate/exception/TemplatedViolatedConstraintNameExtracter.java +++ b/hibernate-core/src/main/java/org/hibernate/exception/spi/TemplatedViolatedConstraintNameExtracter.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,10 +20,8 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ -package org.hibernate.exception; - +package org.hibernate.exception.spi; /** * Knows how to extract a violated constraint name from an error message based on the diff --git a/hibernate-core/src/main/java/org/hibernate/exception/ViolatedConstraintNameExtracter.java b/hibernate-core/src/main/java/org/hibernate/exception/spi/ViolatedConstraintNameExtracter.java similarity index 89% rename from hibernate-core/src/main/java/org/hibernate/exception/ViolatedConstraintNameExtracter.java rename to hibernate-core/src/main/java/org/hibernate/exception/spi/ViolatedConstraintNameExtracter.java index 6e733fcd71..c6e9060b61 100644 --- a/hibernate-core/src/main/java/org/hibernate/exception/ViolatedConstraintNameExtracter.java +++ b/hibernate-core/src/main/java/org/hibernate/exception/spi/ViolatedConstraintNameExtracter.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Middleware LLC. + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -20,9 +20,9 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - * */ -package org.hibernate.exception; +package org.hibernate.exception.spi; + import java.sql.SQLException; /** diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 6bcf97a6e4..1baa86829b 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -99,7 +99,7 @@ import org.hibernate.engine.profile.FetchProfile; import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification; import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl; import org.hibernate.engine.transaction.spi.TransactionEnvironment; -import org.hibernate.exception.SQLExceptionConverter; +import org.hibernate.exception.spi.SQLExceptionConverter; import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.UUIDGenerator; import org.hibernate.id.factory.IdentifierGeneratorFactory; diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index 3f804204d0..1e109d5f98 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -44,6 +44,7 @@ import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SubselectFetch; +import org.hibernate.exception.spi.SQLExceptionConverter; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.MappingException; import org.hibernate.QueryException; @@ -59,7 +60,6 @@ import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey; import org.hibernate.engine.jdbc.spi.SqlExceptionHelper; -import org.hibernate.exception.SQLExceptionConverter; import org.hibernate.id.IdentifierGenerator; import org.hibernate.internal.FilterHelper; import org.hibernate.internal.util.StringHelper; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java index 312b81bd23..787cb8ac40 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/DatabaseMetadata.java @@ -37,7 +37,7 @@ import org.hibernate.HibernateException; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.spi.SqlExceptionHelper; -import org.hibernate.exception.SQLExceptionConverter; +import org.hibernate.exception.spi.SQLExceptionConverter; import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.Table;