Class Cache71Dialect

  • All Implemented Interfaces:
    ConversionContext

    public class Cache71Dialect
    extends Dialect
    Caché 2007.1 dialect. This class is required in order to use Hibernate with InterSystems Caché SQL. Compatible with Caché 2007.1.

    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. 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.
    3. In the file, hibernate.properties (or hibernate.cfg.xml), specify the Caché dialect and the Caché version URL settings.

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

    Property Name Property Value
    hibernate.dialect org.hibernate.dialect.Cache71Dialect
    hibernate.connection.driver_class com.intersys.jdbc.CacheDriver
    hibernate.connection.username (see note 1)
    hibernate.connection.password (see note 1)
    hibernate.connection.url jdbc:Cache://127.0.0.1:1972/USER

    NOTE: 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)

    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. src\org\hibernate\dialect\function\ConditionalParenthesisFunction.java
    3. src\org\hibernate\dialect\function\ConvertFunction.java
    4. src\org\hibernate\exception\CacheSQLStateConverter.java
    5. src\org\hibernate\sql\CacheJoinFragment.java
    Cache71Dialect ships with Hibernate 3.2. All other dialects are distributed by InterSystems and subclass Cache71Dialect.
    • Constructor Detail

      • Cache71Dialect

        public Cache71Dialect()
        Creates new Cache71Dialect instance. Sets up the JDBC / Caché type mappings.
    • Method Detail

      • commonRegistration

        protected final void commonRegistration()
      • register71Functions

        protected final void register71Functions()
      • hasAlterTable

        public boolean hasAlterTable()
        Description copied from class: Dialect
        Does this dialect support the ALTER TABLE syntax?
        Overrides:
        hasAlterTable in class Dialect
        Returns:
        True if we support altering of tables; false otherwise.
      • qualifyIndexName

        public boolean qualifyIndexName()
        Description copied from class: Dialect
        Do we need to qualify index names with the schema name?
        Overrides:
        qualifyIndexName in class Dialect
        Returns:
        boolean
      • getAddForeignKeyConstraintString

        public String getAddForeignKeyConstraintString​(String constraintName,
                                                       String[] foreignKey,
                                                       String referencedTable,
                                                       String[] primaryKey,
                                                       boolean referencesPrimaryKey)
        Description copied from class: Dialect
        The syntax used to add a foreign key constraint to a table.
        Overrides:
        getAddForeignKeyConstraintString in class Dialect
        Parameters:
        constraintName - The FK constraint name.
        foreignKey - The names of the columns comprising the FK
        referencedTable - The table referenced by the FK
        primaryKey - The explicit columns in the referencedTable referenced by this FK.
        referencesPrimaryKey - if false, constraint should be explicit about which column names the constraint refers to
        Returns:
        the "add FK" fragment
      • supportsCheck

        public boolean supportsCheck()
        Does this dialect support check constraints?
        Returns:
        false (Cache does not support check constraints)
      • getAddColumnString

        public String getAddColumnString()
        Description copied from class: Dialect
        The syntax used to add a column to a table (optional).
        Overrides:
        getAddColumnString in class Dialect
        Returns:
        The "add column" fragment.
      • dropConstraints

        public boolean dropConstraints()
        Description copied from class: Dialect
        Do we need to drop constraints before dropping tables in this dialect?
        Overrides:
        dropConstraints in class Dialect
        Returns:
        True if constraints must be dropped prior to dropping the table; false otherwise.
      • supportsCascadeDelete

        public boolean supportsCascadeDelete()
        Description copied from class: Dialect
        Does this dialect support cascaded delete on foreign key definitions?
        Overrides:
        supportsCascadeDelete in class Dialect
        Returns:
        true indicates that the dialect does support cascaded delete on foreign keys.
      • hasSelfReferentialForeignKeyBug

        public boolean hasSelfReferentialForeignKeyBug()
        Description copied from class: Dialect
        Does the database/driver have bug in deleting rows that refer to other rows being deleted in the same query?
        Overrides:
        hasSelfReferentialForeignKeyBug in class Dialect
        Returns:
        true if the database/driver has this bug
      • getNativeIdentifierGeneratorStrategy

        public String getNativeIdentifierGeneratorStrategy()
        Description copied from class: Dialect
        Resolves the native generation strategy associated to this dialect.

        Comes into play whenever the user specifies the native generator.

        Overrides:
        getNativeIdentifierGeneratorStrategy in class Dialect
        Returns:
        The native generator strategy.
      • supportsSequences

        public boolean supportsSequences()
        Description copied from class: Dialect
        Does this dialect support sequences?
        Overrides:
        supportsSequences in class Dialect
        Returns:
        True if sequences supported; false otherwise.
      • supportsOuterJoinForUpdate

        public boolean supportsOuterJoinForUpdate()
        Description copied from class: Dialect
        Does this dialect support FOR UPDATE in conjunction with outer joined rows?
        Overrides:
        supportsOuterJoinForUpdate in class Dialect
        Returns:
        True if outer joined rows can be locked via FOR UPDATE.
      • getLockingStrategy

        public LockingStrategy getLockingStrategy​(Lockable lockable,
                                                  LockMode lockMode)
        Description copied from class: Dialect
        Get a strategy instance which knows how to acquire a database-level lock of the specified mode for this dialect.
        Overrides:
        getLockingStrategy in class Dialect
        Parameters:
        lockable - The persister for the entity to be locked.
        lockMode - The type of lock to be acquired.
        Returns:
        The appropriate locking strategy.
      • getLimitHandler

        public LimitHandler getLimitHandler()
        Description copied from class: Dialect
        Returns the delegate managing LIMIT clause.
        Overrides:
        getLimitHandler in class Dialect
        Returns:
        LIMIT clause delegate.
      • supportsLimit

        public boolean supportsLimit()
        Description copied from class: Dialect
        Does this dialect support some form of limiting query results via a SQL clause?
        Overrides:
        supportsLimit in class Dialect
        Returns:
        True if this dialect supports some form of LIMIT.
      • supportsLimitOffset

        public boolean supportsLimitOffset()
        Description copied from class: Dialect
        Does this dialect's LIMIT support (if any) additionally support specifying an offset?
        Overrides:
        supportsLimitOffset in class Dialect
        Returns:
        True if the dialect supports an offset within the limit support.
      • supportsVariableLimit

        public boolean supportsVariableLimit()
        Description copied from class: Dialect
        Does this dialect support bind variables (i.e., prepared statement parameters) for its limit/offset?
        Overrides:
        supportsVariableLimit in class Dialect
        Returns:
        True if bind variables can be used; false otherwise.
      • bindLimitParametersFirst

        public boolean bindLimitParametersFirst()
        Description copied from class: Dialect
        Does the LIMIT clause come at the start of the SELECT statement, rather than at the end?
        Overrides:
        bindLimitParametersFirst in class Dialect
        Returns:
        true if limit parameters should come before other parameters
      • useMaxForLimit

        public boolean useMaxForLimit()
        Description copied from class: Dialect
        Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows?

        This is easiest understood via an example. Consider you have a table with 20 rows, but you only want to retrieve rows number 11 through 20. Generally, a limit with offset would say that the offset = 11 and the limit = 10 (we only want 10 rows at a time); this is specifying the total number of returned rows. Some dialects require that we instead specify offset = 11 and limit = 20, where 20 is the "last" row we want relative to offset (i.e. total number of rows = 20 - 11 = 9)

        So essentially, is limit relative from offset? Or is limit absolute?

        Overrides:
        useMaxForLimit in class Dialect
        Returns:
        True if limit is relative from offset; false otherwise.
      • getLimitString

        public String getLimitString​(String sql,
                                     boolean hasOffset)
        Description copied from class: Dialect
        Apply s limit clause to the query.

        Typically dialects utilize variable limit clauses when they support limits. Thus, when building the select command we do not actually need to know the limit or the offest since we will just be using placeholders.

        Here we do still pass along whether or not an offset was specified so that dialects not supporting offsets can generate proper exceptions. In general, dialects will override one or the other of this method and Dialect.getLimitString(String, int, int).

        Overrides:
        getLimitString in class Dialect
        Parameters:
        sql - The query to which to apply the limit.
        hasOffset - Is the query requesting an offset?
        Returns:
        the modified SQL
      • registerResultSetOutParameter

        public int registerResultSetOutParameter​(CallableStatement statement,
                                                 int col)
                                          throws SQLException
        Description copied from class: Dialect
        Registers a parameter (either OUT, or the new REF_CURSOR param type available in Java 8) capable of returning ResultSet *by position*. Pre-Java 8, registering such ResultSet-returning parameters varied greatly across database and drivers; hence its inclusion as part of the Dialect contract.
        Overrides:
        registerResultSetOutParameter in class Dialect
        Parameters:
        statement - The callable statement.
        col - The bind position at which to register the output param.
        Returns:
        The number of (contiguous) bind positions used.
        Throws:
        SQLException - Indicates problems registering the param.
      • getLowercaseFunction

        public String getLowercaseFunction()
        Description copied from class: Dialect
        The name of the SQL function that transforms a string to lowercase
        Overrides:
        getLowercaseFunction in class Dialect
        Returns:
        The dialect-specific lowercase function.
      • getNullColumnString

        public String getNullColumnString()
        Description copied from class: Dialect
        The keyword used to specify a nullable column.
        Overrides:
        getNullColumnString in class Dialect
        Returns:
        String
      • getNoColumnsInsertString

        public String getNoColumnsInsertString()
        Description copied from class: Dialect
        The fragment used to insert a row without specifying any column values. This is not possible on some databases.
        Overrides:
        getNoColumnsInsertString in class Dialect
        Returns:
        The appropriate empty values clause.
      • buildSQLExceptionConversionDelegate

        public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate()
        Description copied from class: Dialect
        Build an instance of a SQLExceptionConversionDelegate for interpreting dialect-specific error or SQLState codes.

        When Dialect.buildSQLExceptionConverter() returns null, the default SQLExceptionConverter is used to interpret SQLState and error codes. If this method is overridden to return a non-null value, the default SQLExceptionConverter will use the returned SQLExceptionConversionDelegate in addition to the following standard delegates:

        1. a "static" delegate based on the JDBC 4 defined SQLException hierarchy;
        2. a delegate that interprets SQLState codes for either X/Open or SQL-2003 codes, depending on java.sql.DatabaseMetaData#getSQLStateType

        It is strongly recommended that specific Dialect implementations override this method, since interpretation of a SQL error is much more accurate when based on the a vendor-specific ErrorCode rather than the SQLState.

        Specific Dialects may override to return whatever is most appropriate for that vendor.

        Overrides:
        buildSQLExceptionConversionDelegate in class Dialect
        Returns:
        The SQLExceptionConversionDelegate for this dialect
      • supportsEmptyInList

        public boolean supportsEmptyInList()
        Description copied from class: Dialect
        Does this dialect support empty IN lists?

        For example, is [where XYZ in ()] a supported construct?

        Overrides:
        supportsEmptyInList in class Dialect
        Returns:
        True if empty in lists are supported; false otherwise.
      • areStringComparisonsCaseInsensitive

        public boolean areStringComparisonsCaseInsensitive()
        Description copied from class: Dialect
        Are string comparisons implicitly case insensitive.

        In other words, does [where 'XYZ' = 'xyz'] resolve to true?

        Overrides:
        areStringComparisonsCaseInsensitive in class Dialect
        Returns:
        True if comparisons are case insensitive.