HHH-7716 Updated CUBRIDDialect.

Added supported SQL functions and data types. Removed limit related
methods in favor of CUBRIDLimitHandler. Improved the dialect by
correctly setting values (true/false) for certain dialect features.
This commit is contained in:
Esen Sagynov 2012-10-25 11:15:10 -04:00 committed by brmeyer
parent b7855e944b
commit f0ebd2f378
2 changed files with 243 additions and 119 deletions

View File

@ -39,94 +39,187 @@ import org.hibernate.type.StandardBasicTypes;
* @author Seok Jeong Il
*/
public class CUBRIDDialect extends Dialect {
@Override
protected String getIdentityColumnString() throws MappingException {
return "auto_increment"; //starts with 1, implicitly
}
@Override
public String getIdentitySelectString(String table, String column, int type)
throws MappingException {
// CUBRID 8.4.0 support last_insert_id()
// return "select last_insert_id()";
return "select current_val from db_serial where name = '" + ( table + "_ai_" + column ).toLowerCase() + "'";
}
public CUBRIDDialect() {
super();
registerColumnType( Types.BIT, "bit(8)" );
registerColumnType( Types.BIGINT, "numeric(19,0)" );
registerColumnType( Types.SMALLINT, "short" );
registerColumnType( Types.TINYINT, "short" );
registerColumnType( Types.INTEGER, "integer" );
registerColumnType( Types.CHAR, "char(1)" );
registerColumnType( Types.VARCHAR, 4000, "varchar($l)" );
registerColumnType( Types.FLOAT, "float" );
registerColumnType( Types.DOUBLE, "double" );
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.TIME, "time" );
registerColumnType( Types.BIGINT, "bigint" );
registerColumnType( Types.BIT, "bit(8)" );
registerColumnType( Types.BLOB, "bit varying(65535)" );
registerColumnType( Types.BOOLEAN, "bit(1)");
registerColumnType( Types.CHAR, "char(1)" );
registerColumnType( Types.CLOB, "string" );
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.DECIMAL, "decimal" );
registerColumnType( Types.DOUBLE, "double" );
registerColumnType( Types.FLOAT, "float" );
registerColumnType( Types.INTEGER, "int" );
registerColumnType( Types.NUMERIC, "numeric($p,$s)" );
registerColumnType( Types.REAL, "double" );
registerColumnType( Types.SMALLINT, "smallint" );
registerColumnType( Types.TIME, "time" );
registerColumnType( Types.TIMESTAMP, "timestamp" );
registerColumnType( Types.VARBINARY, 2000, "bit varying($l)" );
registerColumnType( Types.NUMERIC, "numeric($p,$s)" );
registerColumnType( Types.BLOB, "blob" );
registerColumnType( Types.CLOB, "string" );
registerColumnType( Types.TINYINT, "smallint" );
registerColumnType( Types.VARBINARY, 2000, "bit varying($l)" );
registerColumnType( Types.VARCHAR, 4000, "varchar($l)" );
getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "true" );
getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
getDefaultProperties().setProperty(Environment.USE_STREAMS_FOR_BINARY, "true");
getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
registerFunction( "substring", new StandardSQLFunction( "substr", StandardBasicTypes.STRING ) );
registerFunction( "trim", new StandardSQLFunction( "trim" ) );
registerFunction( "length", new StandardSQLFunction( "length", StandardBasicTypes.INTEGER ) );
registerFunction( "bit_length", new StandardSQLFunction( "bit_length", StandardBasicTypes.INTEGER ) );
registerFunction( "coalesce", new StandardSQLFunction( "coalesce" ) );
registerFunction( "nullif", new StandardSQLFunction( "nullif" ) );
registerFunction( "abs", new StandardSQLFunction( "abs" ) );
registerFunction( "mod", new StandardSQLFunction( "mod" ) );
registerFunction( "upper", new StandardSQLFunction( "upper" ) );
registerFunction( "lower", new StandardSQLFunction( "lower" ) );
registerFunction("ascii", new StandardSQLFunction("ascii", StandardBasicTypes.INTEGER) );
registerFunction("bin", new StandardSQLFunction("bin", StandardBasicTypes.STRING) );
registerFunction("char_length", new StandardSQLFunction("char_length", StandardBasicTypes.LONG) );
registerFunction("character_length", new StandardSQLFunction("character_length", StandardBasicTypes.LONG) );
registerFunction("lengthb", new StandardSQLFunction("lengthb", StandardBasicTypes.LONG) );
registerFunction("lengthh", new StandardSQLFunction("lengthh", StandardBasicTypes.LONG) );
registerFunction("lcase", new StandardSQLFunction("lcase") );
registerFunction("lower", new StandardSQLFunction("lower") );
registerFunction("ltrim", new StandardSQLFunction("ltrim") );
registerFunction("reverse", new StandardSQLFunction("reverse") );
registerFunction("rtrim", new StandardSQLFunction("rtrim") );
registerFunction("trim", new StandardSQLFunction("trim") );
registerFunction("space", new StandardSQLFunction("space", StandardBasicTypes.STRING) );
registerFunction("ucase", new StandardSQLFunction("ucase") );
registerFunction("upper", new StandardSQLFunction("upper") );
registerFunction( "power", new StandardSQLFunction( "power" ) );
registerFunction( "stddev", new StandardSQLFunction( "stddev" ) );
registerFunction( "variance", new StandardSQLFunction( "variance" ) );
registerFunction( "round", new StandardSQLFunction( "round" ) );
registerFunction( "trunc", new StandardSQLFunction( "trunc" ) );
registerFunction( "ceil", new StandardSQLFunction( "ceil" ) );
registerFunction( "floor", new StandardSQLFunction( "floor" ) );
registerFunction( "ltrim", new StandardSQLFunction( "ltrim" ) );
registerFunction( "rtrim", new StandardSQLFunction( "rtrim" ) );
registerFunction( "nvl", new StandardSQLFunction( "nvl" ) );
registerFunction( "nvl2", new StandardSQLFunction( "nvl2" ) );
registerFunction( "sign", new StandardSQLFunction( "sign", StandardBasicTypes.INTEGER ) );
registerFunction( "chr", new StandardSQLFunction( "chr", StandardBasicTypes.CHARACTER ) );
registerFunction( "to_char", new StandardSQLFunction( "to_char", StandardBasicTypes.STRING ) );
registerFunction( "to_date", new StandardSQLFunction( "to_date", StandardBasicTypes.TIMESTAMP ) );
registerFunction( "last_day", new StandardSQLFunction( "last_day", StandardBasicTypes.DATE ) );
registerFunction( "instr", new StandardSQLFunction( "instr", StandardBasicTypes.INTEGER ) );
registerFunction( "instrb", new StandardSQLFunction( "instrb", StandardBasicTypes.INTEGER ) );
registerFunction( "lpad", new StandardSQLFunction( "lpad", StandardBasicTypes.STRING ) );
registerFunction( "replace", new StandardSQLFunction( "replace", StandardBasicTypes.STRING ) );
registerFunction( "rpad", new StandardSQLFunction( "rpad", StandardBasicTypes.STRING ) );
registerFunction( "substr", new StandardSQLFunction( "substr", StandardBasicTypes.STRING ) );
registerFunction( "substrb", new StandardSQLFunction( "substrb", StandardBasicTypes.STRING ) );
registerFunction( "translate", new StandardSQLFunction( "translate", StandardBasicTypes.STRING ) );
registerFunction( "add_months", new StandardSQLFunction( "add_months", StandardBasicTypes.DATE ) );
registerFunction( "months_between", new StandardSQLFunction( "months_between", StandardBasicTypes.FLOAT ) );
registerFunction("abs", new StandardSQLFunction("abs") );
registerFunction("sign", new StandardSQLFunction("sign", StandardBasicTypes.INTEGER) );
registerFunction( "current_date", new NoArgSQLFunction( "current_date", StandardBasicTypes.DATE, false ) );
registerFunction( "current_time", new NoArgSQLFunction( "current_time", StandardBasicTypes.TIME, false ) );
registerFunction(
"current_timestamp",
new NoArgSQLFunction( "current_timestamp", StandardBasicTypes.TIMESTAMP, false )
);
registerFunction( "sysdate", new NoArgSQLFunction( "sysdate", StandardBasicTypes.DATE, false ) );
registerFunction( "systime", new NoArgSQLFunction( "systime", StandardBasicTypes.TIME, false ) );
registerFunction( "systimestamp", new NoArgSQLFunction( "systimestamp", StandardBasicTypes.TIMESTAMP, false ) );
registerFunction( "user", new NoArgSQLFunction( "user", StandardBasicTypes.STRING, false ) );
registerFunction( "rownum", new NoArgSQLFunction( "rownum", StandardBasicTypes.LONG, false ) );
registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "", "||", "" ) );
registerFunction("acos", new StandardSQLFunction("acos", StandardBasicTypes.DOUBLE) );
registerFunction("asin", new StandardSQLFunction("asin", StandardBasicTypes.DOUBLE) );
registerFunction("atan", new StandardSQLFunction("atan", StandardBasicTypes.DOUBLE) );
registerFunction("cos", new StandardSQLFunction("cos", StandardBasicTypes.DOUBLE) );
registerFunction("cot", new StandardSQLFunction("cot", StandardBasicTypes.DOUBLE) );
registerFunction("exp", new StandardSQLFunction("exp", StandardBasicTypes.DOUBLE) );
registerFunction("ln", new StandardSQLFunction("ln", StandardBasicTypes.DOUBLE) );
registerFunction("log2", new StandardSQLFunction("log2", StandardBasicTypes.DOUBLE) );
registerFunction("log10", new StandardSQLFunction("log10", StandardBasicTypes.DOUBLE) );
registerFunction("pi", new NoArgSQLFunction("pi", StandardBasicTypes.DOUBLE) );
registerFunction("rand", new NoArgSQLFunction("rand", StandardBasicTypes.DOUBLE) );
registerFunction("random", new NoArgSQLFunction("random", StandardBasicTypes.DOUBLE) );
registerFunction("sin", new StandardSQLFunction("sin", StandardBasicTypes.DOUBLE) );
registerFunction("sqrt", new StandardSQLFunction("sqrt", StandardBasicTypes.DOUBLE) );
registerFunction("tan", new StandardSQLFunction("tan", StandardBasicTypes.DOUBLE) );
registerFunction("radians", new StandardSQLFunction("radians", StandardBasicTypes.DOUBLE) );
registerFunction("degrees", new StandardSQLFunction("degrees", StandardBasicTypes.DOUBLE) );
registerFunction("ceil", new StandardSQLFunction("ceil", StandardBasicTypes.INTEGER) );
registerFunction("floor", new StandardSQLFunction("floor", StandardBasicTypes.INTEGER) );
registerFunction("round", new StandardSQLFunction("round") );
registerFunction("datediff", new StandardSQLFunction("datediff", StandardBasicTypes.INTEGER) );
registerFunction("timediff", new StandardSQLFunction("timediff", StandardBasicTypes.TIME) );
registerFunction("date", new StandardSQLFunction("date", StandardBasicTypes.DATE) );
registerFunction("curdate", new NoArgSQLFunction("curdate", StandardBasicTypes.DATE) );
registerFunction("current_date", new NoArgSQLFunction("current_date", StandardBasicTypes.DATE, false) );
registerFunction("sys_date", new NoArgSQLFunction("sys_date", StandardBasicTypes.DATE, false) );
registerFunction("sysdate", new NoArgSQLFunction("sysdate", StandardBasicTypes.DATE, false) );
registerFunction("time", new StandardSQLFunction("time", StandardBasicTypes.TIME) );
registerFunction("curtime", new NoArgSQLFunction("curtime", StandardBasicTypes.TIME) );
registerFunction("current_time", new NoArgSQLFunction("current_time", StandardBasicTypes.TIME, false) );
registerFunction("sys_time", new NoArgSQLFunction("sys_time", StandardBasicTypes.TIME, false) );
registerFunction("systime", new NoArgSQLFunction("systime", StandardBasicTypes.TIME, false) );
registerFunction("timestamp", new StandardSQLFunction("timestamp", StandardBasicTypes.TIMESTAMP) );
registerFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", StandardBasicTypes.TIMESTAMP, false) );
registerFunction("sys_timestamp", new NoArgSQLFunction("sys_timestamp", StandardBasicTypes.TIMESTAMP, false) );
registerFunction("systimestamp", new NoArgSQLFunction("systimestamp", StandardBasicTypes.TIMESTAMP, false) );
registerFunction("localtime", new NoArgSQLFunction("localtime", StandardBasicTypes.TIMESTAMP, false) );
registerFunction("localtimestamp", new NoArgSQLFunction("localtimestamp", StandardBasicTypes.TIMESTAMP, false) );
registerFunction("day", new StandardSQLFunction("day", StandardBasicTypes.INTEGER) );
registerFunction("dayofmonth", new StandardSQLFunction("dayofmonth", StandardBasicTypes.INTEGER) );
registerFunction("dayofweek", new StandardSQLFunction("dayofweek", StandardBasicTypes.INTEGER) );
registerFunction("dayofyear", new StandardSQLFunction("dayofyear", StandardBasicTypes.INTEGER) );
registerFunction("from_days", new StandardSQLFunction("from_days", StandardBasicTypes.DATE) );
registerFunction("from_unixtime", new StandardSQLFunction("from_unixtime", StandardBasicTypes.TIMESTAMP) );
registerFunction("last_day", new StandardSQLFunction("last_day", StandardBasicTypes.DATE) );
registerFunction("minute", new StandardSQLFunction("minute", StandardBasicTypes.INTEGER) );
registerFunction("month", new StandardSQLFunction("month", StandardBasicTypes.INTEGER) );
registerFunction("months_between", new StandardSQLFunction("months_between", StandardBasicTypes.DOUBLE) );
registerFunction("now", new NoArgSQLFunction("now", StandardBasicTypes.TIMESTAMP) );
registerFunction("quarter", new StandardSQLFunction("quarter", StandardBasicTypes.INTEGER) );
registerFunction("second", new StandardSQLFunction("second", StandardBasicTypes.INTEGER) );
registerFunction("sec_to_time", new StandardSQLFunction("sec_to_time", StandardBasicTypes.TIME) );
registerFunction("time_to_sec", new StandardSQLFunction("time_to_sec", StandardBasicTypes.INTEGER) );
registerFunction("to_days", new StandardSQLFunction("to_days", StandardBasicTypes.LONG) );
registerFunction("unix_timestamp", new StandardSQLFunction("unix_timestamp", StandardBasicTypes.LONG) );
registerFunction("utc_date", new NoArgSQLFunction("utc_date", StandardBasicTypes.STRING) );
registerFunction("utc_time", new NoArgSQLFunction("utc_time", StandardBasicTypes.STRING) );
registerFunction("week", new StandardSQLFunction("week", StandardBasicTypes.INTEGER) );
registerFunction("weekday", new StandardSQLFunction("weekday", StandardBasicTypes.INTEGER) );
registerFunction("year", new StandardSQLFunction("year", StandardBasicTypes.INTEGER) );
registerFunction("hex", new StandardSQLFunction("hex", StandardBasicTypes.STRING) );
registerFunction("octet_length", new StandardSQLFunction("octet_length", StandardBasicTypes.LONG) );
registerFunction("bit_length", new StandardSQLFunction("bit_length", StandardBasicTypes.LONG) );
registerFunction("bit_count", new StandardSQLFunction("bit_count", StandardBasicTypes.LONG) );
registerFunction("md5", new StandardSQLFunction("md5", StandardBasicTypes.STRING) );
registerFunction( "concat", new StandardSQLFunction( "concat", StandardBasicTypes.STRING ) );
registerFunction("substring", new StandardSQLFunction("substring", StandardBasicTypes.STRING) );
registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING) );
registerFunction("length", new StandardSQLFunction("length", StandardBasicTypes.INTEGER) );
registerFunction("bit_length",new StandardSQLFunction("bit_length", StandardBasicTypes.INTEGER) );
registerFunction("coalesce", new StandardSQLFunction("coalesce") );
registerFunction("nullif", new StandardSQLFunction("nullif") );
registerFunction("mod", new StandardSQLFunction("mod") );
registerFunction("power", new StandardSQLFunction("power") );
registerFunction("stddev", new StandardSQLFunction("stddev") );
registerFunction("variance", new StandardSQLFunction("variance") );
registerFunction("trunc", new StandardSQLFunction("trunc") );
registerFunction("nvl", new StandardSQLFunction("nvl") );
registerFunction("nvl2", new StandardSQLFunction("nvl2") );
registerFunction("chr", new StandardSQLFunction("chr", StandardBasicTypes.CHARACTER));
registerFunction("to_char", new StandardSQLFunction("to_char", StandardBasicTypes.STRING) );
registerFunction("to_date", new StandardSQLFunction("to_date", StandardBasicTypes.TIMESTAMP));
registerFunction("instr", new StandardSQLFunction("instr", StandardBasicTypes.INTEGER) );
registerFunction("instrb", new StandardSQLFunction("instrb", StandardBasicTypes.INTEGER) );
registerFunction("lpad", new StandardSQLFunction("lpad", StandardBasicTypes.STRING) );
registerFunction("replace", new StandardSQLFunction("replace", StandardBasicTypes.STRING) );
registerFunction("rpad", new StandardSQLFunction("rpad", StandardBasicTypes.STRING) );
registerFunction("translate", new StandardSQLFunction("translate", StandardBasicTypes.STRING) );
registerFunction("add_months", new StandardSQLFunction("add_months", StandardBasicTypes.DATE) );
registerFunction("user", new NoArgSQLFunction("user", StandardBasicTypes.STRING, false) );
registerFunction("rownum", new NoArgSQLFunction("rownum", StandardBasicTypes.LONG, false) );
registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", ""));
}
public boolean supportsIdentityColumns() {
return true;
}
public String getIdentityInsertString() {
return "NULL";
}
public boolean supportsColumnCheck() {
return false;
}
public boolean supportsPooledSequences() {
return true;
}
public String getIdentitySelectString() {
return "select last_insert_id()";
}
protected String getIdentityColumnString() {
return "not null auto_increment"; //starts with 1, implicitly
}
/*
* CUBRID supports "ADD [COLUMN | ATTRIBUTE]"
*/
public String getAddColumnString() {
return "add";
}
@ -143,50 +236,39 @@ public class CUBRIDDialect extends Dialect {
return "drop serial " + sequenceName;
}
public String getDropForeignKeyString() {
return " drop foreign key ";
}
public boolean qualifyIndexName() {
return false;
}
public boolean supportsSequences() {
return true;
}
public boolean supportsExistsInSelect() {
return false;
}
public String getQuerySequencesString() {
return "select name from db_serial";
}
public boolean dropConstraints() {
return false;
}
public boolean supportsLimit() {
return true;
}
public String getLimitString(String sql, boolean hasOffset) {
// CUBRID 8.3.0 support limit
return new StringBuilder( sql.length() + 20 ).append( sql )
.append( hasOffset ? " limit ?, ?" : " limit ?" ).toString();
}
public boolean bindLimitParametersInReverseOrder() {
return true;
}
public boolean useMaxForLimit() {
return true;
}
public boolean forUpdateOfColumns() {
return true;
}
public char closeQuote() {
return ']';
}
/**
* The character specific to this dialect used to close a quoted identifier.
* CUBRID supports square brackets (MSSQL style), backticks (MySQL style),
* as well as double quotes (Oracle style).
*
* @return The dialect's specific open quote character.
*/
public char openQuote() {
return '[';
}
public boolean hasAlterTable() {
return false;
public char closeQuote() {
return ']';
}
public String getForUpdateString() {
@ -197,23 +279,31 @@ public class CUBRIDDialect extends Dialect {
return true;
}
public boolean supportsCommentOn() {
return false;
}
public boolean supportsTemporaryTables() {
return false;
}
public boolean supportsCurrentTimestampSelection() {
return true;
}
public String getCurrentTimestampSelectString() {
return "select systimestamp from table({1}) as T(X)";
return "select now()";
}
public boolean isCurrentTimestampSelectStringCallable() {
return false;
}
public boolean supportsEmptyInList() {
return false;
}
public boolean supportsIfExistsBeforeTableName() {
return true;
}
public boolean supportsTupleDistinctCounts() {
return false;
}
public LimitHandler buildLimitHandler(String sql, RowSelection selection) {
return new CUBRIDLimitHandler( this, sql, selection );
}
}

View File

@ -0,0 +1,34 @@
package org.hibernate.dialect.pagination;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.RowSelection;
/**
* Limit handler that delegates all operations to the underlying dialect.
*
* @author Esen Sagynov (kadishmal at gmail dot com)
*/
public class CUBRIDLimitHandler extends AbstractLimitHandler {
private final Dialect dialect;
public CUBRIDLimitHandler(Dialect dialect, String sql, RowSelection selection) {
super( sql, selection );
this.dialect = dialect;
}
public boolean supportsLimit() {
return true;
}
public boolean useMaxForLimit() {
return true;
}
public String getProcessedSql() {
boolean useLimitOffset = supportsLimit() && supportsLimitOffset()
&& LimitHelper.hasFirstRow( selection ) && LimitHelper.hasMaxRows( selection );
return dialect.getLimitString(
sql, useLimitOffset ? LimitHelper.getFirstRow( selection ) : 0, getMaxOrLimit()
);
}
}