📄 cache71dialect.java
字号:
/*
* 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.dialect;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.Hibernate;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.NoArgSQLFunction;
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.dialect.function.StandardJDBCEscapeFunction;
import org.hibernate.dialect.function.ConvertFunction;
import org.hibernate.dialect.function.ConditionalParenthesisFunction;
import org.hibernate.dialect.lock.LockingStrategy;
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.persister.entity.Lockable;
import org.hibernate.sql.CacheJoinFragment;
import org.hibernate.sql.JoinFragment;
import org.hibernate.util.StringHelper;
/**
* Caché 2007.1 dialect. This class is required in order to use Hibernate with Intersystems Cach� SQL.<br>
* <br>
* Compatible with Cach� 2007.1.
* <br>
* <head>
* <title>Caché and Hibernate</title>
* </head>
* <body>
* <h1>Caché and Hibernate</h1>
* <h2>PREREQUISITES</h2>
* These setup instructions assume that both Caché and Hibernate are installed and operational.
* <br>
* <h2>HIBERNATE DIRECTORIES AND FILES</h2>
* JBoss distributes the InterSystems Cache' dialect for Hibernate 3.2.1
* For earlier versions of Hibernate please contact
* <a href="http://www.intersystems.com/support/cache-support.html">InterSystems Worldwide Response Center</A> (WRC)
* for the appropriate source files.
* <br>
* <h2>CACHÉ DOCUMENTATION</h2>
* Documentation for Caché is available online when Caché is running.
* It can also be obtained from the
* <a href="http://www.intersystems.com/cache/downloads/documentation.html">InterSystems</A> website.
* The book, "Object-oriented Application Development Using the Caché Post-relational Database:
* is also available from Springer-Verlag.
* <br>
* <h2>HIBERNATE DOCUMENTATION</h2>
* Hibernate comes with extensive electronic documentation.
* In addition, several books on Hibernate are available from
* <a href="http://www.manning.com">Manning Publications Co</a>.
* Three available titles are "Hibernate Quickly", "Hibernate in Action", and "Java Persistence with Hibernate".
* <br>
* <h2>TO SET UP HIBERNATE FOR USE WITH CACHÉ</h2>
* 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.
* <p/>
* If either product is installed in a different location, the pathnames that follow should be modified appropriately.
* <p/>
* 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é.
* <ol>
* <li>Copy C:\CacheSys\dev\java\lib\JDK15\CacheDB.jar to C:\Hibernate\lib\CacheDB.jar.</li>
* <p/>
* <li>Insert the following files into your Java classpath:
* <p/>
* <ul>
* <li>All jar files in the directory C:\Hibernate\lib</li>
* <li>The directory (or directories) where hibernate.properties and/or hibernate.cfg.xml are kept.</li>
* </ul>
* </li>
* <p/>
* <li>In the file, hibernate.properties (or hibernate.cfg.xml),
* specify the Caché dialect and the Caché version URL settings.</li>
* </ol>
* <p/>
* For example, in Hibernate 3.2, typical entries in hibernate.properties would have the following
* "name=value" pairs:
* <p/>
* <table cols=3 border cellpadding=5 cellspacing=0>
* <tr>
* <th>Property Name</th>
* <th>Property Value</th>
* </tr>
* <tr>
* <td>hibernate.dialect</td>
* <td>org.hibernate.dialect.Cache71Dialect</td>
* </tr>
* <tr>
* <td>hibernate.connection.driver_class</td>
* <td>com.intersys.jdbc.CacheDriver</td>
* </tr>
* <tr>
* <td>hibernate.connection.username</td>
* <td>(see note 1)</td>
* </tr>
* <tr>
* <td>hibernate.connection.password</td>
* <td>(see note 1)</td>
* </tr>
* <tr>
* <td>hibernate.connection.url</td>
* <td>jdbc:Cache://127.0.0.1:1972/USER</td>
* </tr>
* </table>
* <p/>
* <dl>
* <dt><b>Note 1</b></dt>
* <dd>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.</dd>
* </dl>
* <br>
* <h2>CACHÉ VERSION URL</h2>
* 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.
* <br>
* <h2>CACHÉ DIALECTS</h2>
* Choices for Dialect are:
* <br>
* <p/>
* <ol>
* <li>org.hibernate.dialect.Cache71Dialect (requires Caché
* 2007.1 or above)</li>
* <p/>
* </ol>
* <br>
* <h2>SUPPORT FOR IDENTITY COLUMNS</h2>
* Caché 2007.1 or later supports identity columns. For
* Hibernate to use identity columns, specify "native" as the
* generator.
* <br>
* <h2>SEQUENCE DIALECTS SUPPORT SEQUENCES</h2>
* <p/>
* To use Hibernate sequence support with Caché in a namespace, you must FIRST load the following file into that namespace:
* <pre>
* etc\CacheSequences.xml
* </pre>
* For example, at the COS terminal prompt in the namespace, run the
* following command:
* <p>
* d LoadFile^%apiOBJ("c:\hibernate\etc\CacheSequences.xml","ck")
* <p>
* In your Hibernate mapping you can specify sequence use.
* <p>
* For example, the following shows the use of a sequence generator in a Hibernate mapping:
* <pre>
* <id name="id" column="uid" type="long" unsaved-value="null">
* <generator class="sequence"/>
* </id>
* </pre>
* <br>
* <p/>
* 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" ).
* <br>
* <h2>HIBERNATE FILES ASSOCIATED WITH CACHÉ DIALECT</h2>
* The following files are associated with Caché dialect:
* <p/>
* <ol>
* <li>src\org\hibernate\dialect\Cache71Dialect.java</li>
* <li>src\org\hibernate\dialect\function\ConditionalParenthesisFunction.java</li>
* <li>src\org\hibernate\dialect\function\ConvertFunction.java</li>
* <li>src\org\hibernate\exception\CacheSQLStateConverter.java</li>
* <li>src\org\hibernate\sql\CacheJoinFragment.java</li>
* </ol>
* 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 <code>Cach�71Dialect</code> 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", Hibernate.DOUBLE ) );
registerFunction( "%alphaup", new StandardSQLFunction( "%alphaup", Hibernate.STRING ) );
registerFunction( "ascii", new StandardSQLFunction( "ascii", Hibernate.STRING ) );
registerFunction( "asin", new StandardJDBCEscapeFunction( "asin", Hibernate.DOUBLE ) );
registerFunction( "atan", new StandardJDBCEscapeFunction( "atan", Hibernate.DOUBLE ) );
registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "($length(?1)*8)" ) );
// hibernate impelemnts cast in Dialect.java
registerFunction( "ceiling", new StandardSQLFunction( "ceiling", Hibernate.INTEGER ) );
registerFunction( "char", new StandardJDBCEscapeFunction( "char", Hibernate.CHARACTER ) );
registerFunction( "character_length", new StandardSQLFunction( "character_length", Hibernate.INTEGER ) );
registerFunction( "char_length", new StandardSQLFunction( "char_length", Hibernate.INTEGER ) );
registerFunction( "cos", new StandardJDBCEscapeFunction( "cos", Hibernate.DOUBLE ) );
registerFunction( "cot", new StandardJDBCEscapeFunction( "cot", Hibernate.DOUBLE ) );
registerFunction( "coalesce", new VarArgsSQLFunction( "coalesce(", ",", ")" ) );
registerFunction( "concat", new VarArgsSQLFunction( Hibernate.STRING, "", "||", "" ) );
registerFunction( "convert", new ConvertFunction() );
registerFunction( "curdate", new StandardJDBCEscapeFunction( "curdate", Hibernate.DATE ) );
registerFunction( "current_date", new NoArgSQLFunction( "current_date", Hibernate.DATE, false ) );
registerFunction( "current_time", new NoArgSQLFunction( "current_time", Hibernate.TIME, false ) );
registerFunction(
"current_timestamp", new ConditionalParenthesisFunction( "current_timestamp", Hibernate.TIMESTAMP )
);
registerFunction( "curtime", new StandardJDBCEscapeFunction( "curtime", Hibernate.TIME ) );
registerFunction( "database", new StandardJDBCEscapeFunction( "database", Hibernate.STRING ) );
registerFunction( "dateadd", new VarArgsSQLFunction( Hibernate.TIMESTAMP, "dateadd(", ",", ")" ) );
registerFunction( "datediff", new VarArgsSQLFunction( Hibernate.INTEGER, "datediff(", ",", ")" ) );
registerFunction( "datename", new VarArgsSQLFunction( Hibernate.STRING, "datename(", ",", ")" ) );
registerFunction( "datepart", new VarArgsSQLFunction( Hibernate.INTEGER, "datepart(", ",", ")" ) );
registerFunction( "day", new StandardSQLFunction( "day", Hibernate.INTEGER ) );
registerFunction( "dayname", new StandardJDBCEscapeFunction( "dayname", Hibernate.STRING ) );
registerFunction( "dayofmonth", new StandardJDBCEscapeFunction( "dayofmonth", Hibernate.INTEGER ) );
registerFunction( "dayofweek", new StandardJDBCEscapeFunction( "dayofweek", Hibernate.INTEGER ) );
registerFunction( "dayofyear", new StandardJDBCEscapeFunction( "dayofyear", Hibernate.INTEGER ) );
// is it necessary to register %exact since it can only appear in a where clause?
registerFunction( "%exact", new StandardSQLFunction( "%exact", Hibernate.STRING ) );
registerFunction( "exp", new StandardJDBCEscapeFunction( "exp", Hibernate.DOUBLE ) );
registerFunction( "%external", new StandardSQLFunction( "%external", Hibernate.STRING ) );
registerFunction( "$extract", new VarArgsSQLFunction( Hibernate.INTEGER, "$extract(", ",", ")" ) );
registerFunction( "$find", new VarArgsSQLFunction( Hibernate.INTEGER, "$find(", ",", ")" ) );
registerFunction( "floor", new StandardSQLFunction( "floor", Hibernate.INTEGER ) );
registerFunction( "getdate", new StandardSQLFunction( "getdate", Hibernate.TIMESTAMP ) );
registerFunction( "hour", new StandardJDBCEscapeFunction( "hour", Hibernate.INTEGER ) );
registerFunction( "ifnull", new VarArgsSQLFunction( "ifnull(", ",", ")" ) );
registerFunction( "%internal", new StandardSQLFunction( "%internal" ) );
registerFunction( "isnull", new VarArgsSQLFunction( "isnull(", ",", ")" ) );
registerFunction( "isnumeric", new StandardSQLFunction( "isnumeric", Hibernate.INTEGER ) );
registerFunction( "lcase", new StandardJDBCEscapeFunction( "lcase", Hibernate.STRING ) );
registerFunction( "left", new StandardJDBCEscapeFunction( "left", Hibernate.STRING ) );
registerFunction( "len", new StandardSQLFunction( "len", Hibernate.INTEGER ) );
registerFunction( "length", new StandardSQLFunction( "length", Hibernate.INTEGER ) );
registerFunction( "$length", new VarArgsSQLFunction( "$length(", ",", ")" ) );
// aggregate functions shouldn't be registered, right?
//registerFunction( "list", new StandardSQLFunction("list",Hibernate.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", Hibernate.INTEGER ) );
registerFunction( "locate", new StandardSQLFunction( "$FIND", Hibernate.INTEGER ) );
registerFunction( "log", new StandardJDBCEscapeFunction( "log", Hibernate.DOUBLE ) );
registerFunction( "log10", new StandardJDBCEscapeFunction( "log", Hibernate.DOUBLE ) );
registerFunction( "lower", new StandardSQLFunction( "lower" ) );
registerFunction( "ltrim", new StandardSQLFunction( "ltrim" ) );
registerFunction( "minute", new StandardJDBCEscapeFunction( "minute", Hibernate.INTEGER ) );
registerFunction( "mod", new StandardJDBCEscapeFunction( "mod", Hibernate.DOUBLE ) );
registerFunction( "month", new StandardJDBCEscapeFunction( "month", Hibernate.INTEGER ) );
registerFunction( "monthname", new StandardJDBCEscapeFunction( "monthname", Hibernate.STRING ) );
registerFunction( "now", new StandardJDBCEscapeFunction( "monthname", Hibernate.TIMESTAMP ) );
registerFunction( "nullif", new VarArgsSQLFunction( "nullif(", ",", ")" ) );
registerFunction( "nvl", new NvlFunction() );
registerFunction( "%odbcin", new StandardSQLFunction( "%odbcin" ) );
registerFunction( "%odbcout", new StandardSQLFunction( "%odbcin" ) );
registerFunction( "%pattern", new VarArgsSQLFunction( Hibernate.STRING, "", "%pattern", "" ) );
registerFunction( "pi", new StandardJDBCEscapeFunction( "pi", Hibernate.DOUBLE ) );
registerFunction( "$piece", new VarArgsSQLFunction( Hibernate.STRING, "$piece(", ",", ")" ) );
registerFunction( "position", new VarArgsSQLFunction( Hibernate.INTEGER, "position(", " in ", ")" ) );
registerFunction( "power", new VarArgsSQLFunction( Hibernate.STRING, "power(", ",", ")" ) );
registerFunction( "quarter", new StandardJDBCEscapeFunction( "quarter", Hibernate.INTEGER ) );
registerFunction( "repeat", new VarArgsSQLFunction( Hibernate.STRING, "repeat(", ",", ")" ) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -