FileDocCategorySizeDatePackage
HSQLDialect.javaAPI DocHibernate 3.2.512616Thu Mar 15 04:33:16 GMT 2007org.hibernate.dialect

HSQLDialect

public class HSQLDialect extends Dialect
An SQL dialect compatible with HSQLDB (Hypersonic SQL).

Note this version supports HSQLDB version 1.8 and higher, only.

author
Christoph Sturm, Phillip Baird

Fields Summary
private static final Log
log
private boolean
schemaSupport
private static org.hibernate.exception.ViolatedConstraintNameExtracter
EXTRACTER
Constructors Summary
public HSQLDialect()


	  
		super();
		registerColumnType( Types.BIGINT, "bigint" );
		registerColumnType( Types.BINARY, "binary" );
		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" );
		registerColumnType( Types.LONGVARCHAR, "longvarchar" );
		registerColumnType( Types.SMALLINT, "smallint" );
		registerColumnType( Types.TINYINT, "tinyint" );
		registerColumnType( Types.TIME, "time" );
		registerColumnType( Types.TIMESTAMP, "timestamp" );
		registerColumnType( Types.VARCHAR, "varchar($l)" );
		registerColumnType( Types.VARBINARY, "varbinary($l)" );
		registerColumnType( Types.NUMERIC, "numeric" );
		//HSQL has no Blob/Clob support .... but just put these here for now!
		registerColumnType( Types.BLOB, "longvarbinary" );
		registerColumnType( Types.CLOB, "longvarchar" );

		registerFunction( "ascii", new StandardSQLFunction( "ascii", Hibernate.INTEGER ) );
		registerFunction( "char", new StandardSQLFunction( "char", Hibernate.CHARACTER ) );
		registerFunction( "length", new StandardSQLFunction( "length", Hibernate.LONG ) );
		registerFunction( "lower", new StandardSQLFunction( "lower" ) );
		registerFunction( "upper", new StandardSQLFunction( "upper" ) );
		registerFunction( "lcase", new StandardSQLFunction( "lcase" ) );
		registerFunction( "ucase", new StandardSQLFunction( "ucase" ) );
		registerFunction( "soundex", new StandardSQLFunction( "soundex", Hibernate.STRING ) );
		registerFunction( "ltrim", new StandardSQLFunction( "ltrim" ) );
		registerFunction( "rtrim", new StandardSQLFunction( "rtrim" ) );
		registerFunction( "reverse", new StandardSQLFunction( "reverse" ) );
		registerFunction( "space", new StandardSQLFunction( "space", Hibernate.STRING ) );
		registerFunction( "rawtohex", new StandardSQLFunction( "rawtohex" ) );
		registerFunction( "hextoraw", new StandardSQLFunction( "hextoraw" ) );

		registerFunction( "user", new NoArgSQLFunction( "user", Hibernate.STRING ) );
		registerFunction( "database", new NoArgSQLFunction( "database", Hibernate.STRING ) );

		registerFunction( "current_date", new NoArgSQLFunction( "current_date", Hibernate.DATE, false ) );
		registerFunction( "curdate", new NoArgSQLFunction( "curdate", Hibernate.DATE ) );
		registerFunction( "current_timestamp", new NoArgSQLFunction( "current_timestamp", Hibernate.TIMESTAMP, false ) );
		registerFunction( "now", new NoArgSQLFunction( "now", Hibernate.TIMESTAMP ) );
		registerFunction( "current_time", new NoArgSQLFunction( "current_time", Hibernate.TIME, false ) );
		registerFunction( "curtime", new NoArgSQLFunction( "curtime", Hibernate.TIME ) );
		registerFunction( "day", new StandardSQLFunction( "day", Hibernate.INTEGER ) );
		registerFunction( "dayofweek", new StandardSQLFunction( "dayofweek", Hibernate.INTEGER ) );
		registerFunction( "dayofyear", new StandardSQLFunction( "dayofyear", Hibernate.INTEGER ) );
		registerFunction( "dayofmonth", new StandardSQLFunction( "dayofmonth", Hibernate.INTEGER ) );
		registerFunction( "month", new StandardSQLFunction( "month", Hibernate.INTEGER ) );
		registerFunction( "year", new StandardSQLFunction( "year", Hibernate.INTEGER ) );
		registerFunction( "week", new StandardSQLFunction( "week", Hibernate.INTEGER ) );
		registerFunction( "quater", new StandardSQLFunction( "quater", Hibernate.INTEGER ) );
		registerFunction( "hour", new StandardSQLFunction( "hour", Hibernate.INTEGER ) );
		registerFunction( "minute", new StandardSQLFunction( "minute", Hibernate.INTEGER ) );
		registerFunction( "second", new StandardSQLFunction( "second", Hibernate.INTEGER ) );
		registerFunction( "dayname", new StandardSQLFunction( "dayname", Hibernate.STRING ) );
		registerFunction( "monthname", new StandardSQLFunction( "monthname", Hibernate.STRING ) );

		registerFunction( "abs", new StandardSQLFunction( "abs" ) );
		registerFunction( "sign", new StandardSQLFunction( "sign", Hibernate.INTEGER ) );

		registerFunction( "acos", new StandardSQLFunction( "acos", Hibernate.DOUBLE ) );
		registerFunction( "asin", new StandardSQLFunction( "asin", Hibernate.DOUBLE ) );
		registerFunction( "atan", new StandardSQLFunction( "atan", Hibernate.DOUBLE ) );
		registerFunction( "cos", new StandardSQLFunction( "cos", Hibernate.DOUBLE ) );
		registerFunction( "cot", new StandardSQLFunction( "cot", Hibernate.DOUBLE ) );
		registerFunction( "exp", new StandardSQLFunction( "exp", Hibernate.DOUBLE ) );
		registerFunction( "log", new StandardSQLFunction( "log", Hibernate.DOUBLE ) );
		registerFunction( "log10", new StandardSQLFunction( "log10", Hibernate.DOUBLE ) );
		registerFunction( "sin", new StandardSQLFunction( "sin", Hibernate.DOUBLE ) );
		registerFunction( "sqrt", new StandardSQLFunction( "sqrt", Hibernate.DOUBLE ) );
		registerFunction( "tan", new StandardSQLFunction( "tan", Hibernate.DOUBLE ) );
		registerFunction( "pi", new NoArgSQLFunction( "pi", Hibernate.DOUBLE ) );
		registerFunction( "rand", new StandardSQLFunction( "rand", Hibernate.FLOAT ) );

		registerFunction( "radians", new StandardSQLFunction( "radians", Hibernate.DOUBLE ) );
		registerFunction( "degrees", new StandardSQLFunction( "degrees", Hibernate.DOUBLE ) );
		registerFunction( "roundmagic", new StandardSQLFunction( "roundmagic" ) );

		registerFunction( "ceiling", new StandardSQLFunction( "ceiling" ) );
		registerFunction( "floor", new StandardSQLFunction( "floor" ) );

		// Multi-param dialect functions...
		registerFunction( "mod", new StandardSQLFunction( "mod", Hibernate.INTEGER ) );

		// function templates
		registerFunction( "concat", new VarArgsSQLFunction( Hibernate.STRING, "(", "||", ")" ) );

		getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );

		try {
			// Does present HSQLDB Database class support schemas?
			// yuck! Perhaps we should think about a new dialect?  Especially
			// if more things are going to break back-compat moving forward
			ReflectHelper.classForName( "org.hsqldb.Database" ).getDeclaredField( "schemaManager" );
			schemaSupport = true;
		}
		catch (Throwable t) {
			schemaSupport = false;
		}
	
Methods Summary
public booleanbindLimitParametersFirst()

		return true;
	
public java.lang.StringgetAddColumnString()

		return "add column";
	
public java.lang.String[]getCreateSequenceStrings(java.lang.String sequenceName)

		return getCreateSequenceStrings( sequenceName, 1, 1 );
	
public java.lang.String[]getCreateSequenceStrings(java.lang.String sequenceName, int initialValue, int incrementSize)

		return new String[] {
				"create table dual_" + sequenceName + " (zero integer)",
		        "insert into dual_" + sequenceName + " values (0)",
		        "create sequence " + sequenceName + " start with " + initialValue + " increment by " + incrementSize
		};
	
public java.lang.String[]getDropSequenceStrings(java.lang.String sequenceName)

		return new String[] {
				"drop table dual_" + sequenceName + " if exists",
		        "drop sequence " + sequenceName
		};
	
public java.lang.StringgetForUpdateString()

		return "";
	
public java.lang.StringgetIdentityColumnString()

		return "generated by default as identity (start with 1)"; //not null is implicit
	
public java.lang.StringgetIdentityInsertString()

		return "null";
	
public java.lang.StringgetIdentitySelectString()

		return "call identity()";
	
public java.lang.StringgetLimitString(java.lang.String sql, boolean hasOffset)

		return new StringBuffer( sql.length() + 10 )
				.append( sql )
				.insert( sql.toLowerCase().indexOf( "select" ) + 6, hasOffset ? " limit ? ?" : " top ?" )
				.toString();
	
public org.hibernate.dialect.lock.LockingStrategygetLockingStrategy(org.hibernate.persister.entity.Lockable lockable, org.hibernate.LockMode lockMode)

		// HSQLDB only supports READ_UNCOMMITTED transaction isolation
		return new ReadUncommittedLockingStrategy( lockable, lockMode );
	
public java.lang.StringgetQuerySequencesString()

		if ( schemaSupport ) {
			return "select sequence_name from information_schema.system_sequences";
		}
		else {
			return "select sequence_name from system_sequences";
		}
	
public java.lang.StringgetSelectSequenceNextValString(java.lang.String sequenceName)

		return "next value for " + sequenceName;
	
public java.lang.StringgetSequenceNextValString(java.lang.String sequenceName)

		return "select next value for " + sequenceName + " from dual_" + sequenceName;
	
public org.hibernate.exception.ViolatedConstraintNameExtractergetViolatedConstraintNameExtracter()

		return EXTRACTER;
	
public booleansupportsColumnCheck()

		return false;
	
public booleansupportsCurrentTimestampSelection()

		return false;
	
public booleansupportsEmptyInList()

		return false;
	
public booleansupportsIdentityColumns()

		return true;
	
public booleansupportsIfExistsAfterTableName()

		return true;
	
public booleansupportsLimit()

		return true;
	
public booleansupportsLobValueChangePropogation()

		return false;
	
public booleansupportsPooledSequences()

		return true;
	
public booleansupportsSequences()

		return true;
	
public booleansupportsTemporaryTables()
HSQL does not really support temp tables; just take advantage of the fact that it is a single user db...


	                    	 
	   
		return true;
	
public booleansupportsUnique()

		return false;