📄 cache71dialect.java
字号:
registerFunction( "replicate", new VarArgsSQLFunction( Hibernate.STRING, "replicate(", ",", ")" ) );
registerFunction( "right", new StandardJDBCEscapeFunction( "right", Hibernate.STRING ) );
registerFunction( "round", new VarArgsSQLFunction( Hibernate.FLOAT, "round(", ",", ")" ) );
registerFunction( "rtrim", new StandardSQLFunction( "rtrim", Hibernate.STRING ) );
registerFunction( "second", new StandardJDBCEscapeFunction( "second", Hibernate.INTEGER ) );
registerFunction( "sign", new StandardSQLFunction( "sign", Hibernate.INTEGER ) );
registerFunction( "sin", new StandardJDBCEscapeFunction( "sin", Hibernate.DOUBLE ) );
registerFunction( "space", new StandardSQLFunction( "space", Hibernate.STRING ) );
registerFunction( "%sqlstring", new VarArgsSQLFunction( Hibernate.STRING, "%sqlstring(", ",", ")" ) );
registerFunction( "%sqlupper", new VarArgsSQLFunction( Hibernate.STRING, "%sqlupper(", ",", ")" ) );
registerFunction( "sqrt", new StandardJDBCEscapeFunction( "SQRT", Hibernate.DOUBLE ) );
registerFunction( "%startswith", new VarArgsSQLFunction( Hibernate.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( Hibernate.STRING, "cast(?1 as char varying)" ) );
registerFunction( "string", new VarArgsSQLFunction( Hibernate.STRING, "string(", ",", ")" ) );
// note that %string is deprecated
registerFunction( "%string", new VarArgsSQLFunction( Hibernate.STRING, "%string(", ",", ")" ) );
registerFunction( "substr", new VarArgsSQLFunction( Hibernate.STRING, "substr(", ",", ")" ) );
registerFunction( "substring", new VarArgsSQLFunction( Hibernate.STRING, "substring(", ",", ")" ) );
registerFunction( "sysdate", new NoArgSQLFunction( "sysdate", Hibernate.TIMESTAMP, false ) );
registerFunction( "tan", new StandardJDBCEscapeFunction( "tan", Hibernate.DOUBLE ) );
registerFunction( "timestampadd", new StandardJDBCEscapeFunction( "timestampadd", Hibernate.DOUBLE ) );
registerFunction( "timestampdiff", new StandardJDBCEscapeFunction( "timestampdiff", Hibernate.DOUBLE ) );
registerFunction( "tochar", new VarArgsSQLFunction( Hibernate.STRING, "tochar(", ",", ")" ) );
registerFunction( "to_char", new VarArgsSQLFunction( Hibernate.STRING, "to_char(", ",", ")" ) );
registerFunction( "todate", new VarArgsSQLFunction( Hibernate.STRING, "todate(", ",", ")" ) );
registerFunction( "to_date", new VarArgsSQLFunction( Hibernate.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(Hibernate.STRING, "trim(?1 ?2 from ?3)") );
registerFunction( "truncate", new StandardJDBCEscapeFunction( "truncate", Hibernate.STRING ) );
registerFunction( "ucase", new StandardJDBCEscapeFunction( "ucase", Hibernate.STRING ) );
registerFunction( "upper", new StandardSQLFunction( "upper" ) );
// %upper is deprecated
registerFunction( "%upper", new StandardSQLFunction( "%upper" ) );
registerFunction( "user", new StandardJDBCEscapeFunction( "user", Hibernate.STRING ) );
registerFunction( "week", new StandardJDBCEscapeFunction( "user", Hibernate.INTEGER ) );
registerFunction( "xmlconcat", new VarArgsSQLFunction( Hibernate.STRING, "xmlconcat(", ",", ")" ) );
registerFunction( "xmlelement", new VarArgsSQLFunction( Hibernate.STRING, "xmlelement(", ",", ")" ) );
// xmlforest requires a new kind of function constructor
registerFunction( "year", new StandardJDBCEscapeFunction( "year", Hibernate.INTEGER ) );
}
protected final void register71Functions() {
this.registerFunction( "str", new VarArgsSQLFunction( Hibernate.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.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( "An offset may not be specified to <TOP n> in Cache SQL" );
}
// 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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -