FileDocCategorySizeDatePackage
Oracle8iDialect.javaAPI DocHibernate 3.2.514986Fri Jun 08 12:52:20 BST 2007org.hibernate.dialect

Oracle8iDialect

public class Oracle8iDialect extends Dialect
A dialect for Oracle 8i.
author
Steve Ebersole

Fields Summary
private static org.hibernate.exception.ViolatedConstraintNameExtracter
EXTRACTER
int
oracletypes_cursor_value
Constructors Summary
public Oracle8iDialect()

		super();
		registerCharacterTypeMappings();
		registerNumericTypeMappings();
		registerDateTimeTypeMappings();
		registerLargeObjectTypeMappings();

		registerReverseHibernateTypeMappings();

		registerFunctions();

		registerDefaultProperties();
	
Methods Summary
public booleanbindLimitParametersInReverseOrder()

		return true;
	
public org.hibernate.sql.CaseFragmentcreateCaseFragment()
Map case support to the Oracle DECODE function. Oracle did not add support for CASE until 9i.

return
The oracle CASE -> DECODE fragment

		return new DecodeCaseFragment();
	
public org.hibernate.sql.JoinFragmentcreateOuterJoinFragment()
Support for the oracle proprietary join syntax...

return
The orqacle join fragment

		return new OracleJoinFragment();
	
public booleandropConstraints()

		return false;
	
public booleandropTemporaryTableAfterUse()

		return false;
	
public booleanforUpdateOfColumns()

		return true;
	
public java.lang.StringgenerateTemporaryTableName(java.lang.String baseTableName)

		String name = super.generateTemporaryTableName(baseTableName);
		return name.length() > 30 ? name.substring( 1, 30 ) : name;
	
public java.lang.StringgetAddColumnString()

		return "add";
	
public java.lang.StringgetBasicSelectClauseNullString(int sqlType)
Allows access to the basic {@link Dialect#getSelectClauseNullString} implementation...

param
sqlType The {@link java.sql.Types} mapping type code
return
The appropriate select cluse fragment

		return super.getSelectClauseNullString( sqlType );
	
public java.lang.StringgetCascadeConstraintsString()

		return " cascade constraints";
	
public java.lang.StringgetCreateSequenceString(java.lang.String sequenceName)

		return "create sequence " + sequenceName; //starts with 1, implicitly
	
public java.lang.StringgetCreateTemporaryTablePostfix()

		return "on commit delete rows";
	
public java.lang.StringgetCreateTemporaryTableString()

		return "create global temporary table";
	
public java.lang.StringgetCurrentTimestampSQLFunctionName()

		return "sysdate";
	
public java.lang.StringgetCurrentTimestampSelectString()

		return "select sysdate from dual";
	
public java.lang.StringgetDropSequenceString(java.lang.String sequenceName)

		return "drop sequence " + sequenceName;
	
public java.lang.StringgetForUpdateNowaitString()

		return " for update nowait";
	
public java.lang.StringgetForUpdateNowaitString(java.lang.String aliases)

		return getForUpdateString() + " of " + aliases + " nowait";
	
public java.lang.StringgetForUpdateString(java.lang.String aliases)

		return getForUpdateString() + " of " + aliases;
	
public java.lang.StringgetLimitString(java.lang.String sql, boolean hasOffset)

		sql = sql.trim();
		boolean isForUpdate = false;
		if ( sql.toLowerCase().endsWith(" for update") ) {
			sql = sql.substring( 0, sql.length()-11 );
			isForUpdate = true;
		}

		StringBuffer pagingSelect = new StringBuffer( sql.length()+100 );
		if (hasOffset) {
			pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
		}
		else {
			pagingSelect.append("select * from ( ");
		}
		pagingSelect.append(sql);
		if (hasOffset) {
			pagingSelect.append(" ) row_ ) where rownum_ <= ? and rownum_ > ?");
		}
		else {
			pagingSelect.append(" ) where rownum <= ?");
		}

		if ( isForUpdate ) {
			pagingSelect.append( " for update" );
		}

		return pagingSelect.toString();
	
public java.lang.StringgetQuerySequencesString()

		return "select sequence_name from user_sequences";
	
public java.sql.ResultSetgetResultSet(java.sql.CallableStatement ps)

		ps.execute();
		return ( ResultSet ) ps.getObject( 1 );
	
public java.lang.StringgetSelectClauseNullString(int sqlType)

		switch(sqlType) {
			case Types.VARCHAR:
			case Types.CHAR:
				return "to_char(null)";
			case Types.DATE:
			case Types.TIMESTAMP:
			case Types.TIME:
				return "to_date(null)";
			default:
				return "to_number(null)";
		}
	
public java.lang.StringgetSelectGUIDString()

		return "select rawtohex(sys_guid()) from dual";
	
public java.lang.StringgetSelectSequenceNextValString(java.lang.String sequenceName)

		return sequenceName + ".nextval";
	
public java.lang.StringgetSequenceNextValString(java.lang.String sequenceName)

		return "select " + getSelectSequenceNextValString( sequenceName ) + " from dual";
	
public org.hibernate.exception.ViolatedConstraintNameExtractergetViolatedConstraintNameExtracter()

        return EXTRACTER;
	
public booleanisCurrentTimestampSelectStringCallable()

		return false;
	
protected voidregisterCharacterTypeMappings()

		registerColumnType( Types.CHAR, "char(1)" );
		registerColumnType( Types.VARCHAR, 4000, "varchar2($l)" );
		registerColumnType( Types.VARCHAR, "long" );
	
protected voidregisterDateTimeTypeMappings()

		registerColumnType( Types.TIMESTAMP, "date" );
	
protected voidregisterDefaultProperties()

		getDefaultProperties().setProperty( Environment.USE_STREAMS_FOR_BINARY, "true" );
		getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
		// Oracle driver reports to support getGeneratedKeys(), but they only
		// support the version taking an array of the names of the columns to
		// be returned (via its RETURNING clause).  No other driver seems to
		// support this overloaded version.
		getDefaultProperties().setProperty( Environment.USE_GET_GENERATED_KEYS, "false" );
	
protected voidregisterFunctions()

		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( "cosh", new StandardSQLFunction("cosh", Hibernate.DOUBLE) );
		registerFunction( "exp", new StandardSQLFunction("exp", Hibernate.DOUBLE) );
		registerFunction( "ln", new StandardSQLFunction("ln", Hibernate.DOUBLE) );
		registerFunction( "sin", new StandardSQLFunction("sin", Hibernate.DOUBLE) );
		registerFunction( "sinh", new StandardSQLFunction("sinh", Hibernate.DOUBLE) );
		registerFunction( "stddev", new StandardSQLFunction("stddev", Hibernate.DOUBLE) );
		registerFunction( "sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE) );
		registerFunction( "tan", new StandardSQLFunction("tan", Hibernate.DOUBLE) );
		registerFunction( "tanh", new StandardSQLFunction("tanh", Hibernate.DOUBLE) );
		registerFunction( "variance", new StandardSQLFunction("variance", Hibernate.DOUBLE) );

		registerFunction( "round", new StandardSQLFunction("round") );
		registerFunction( "trunc", new StandardSQLFunction("trunc") );
		registerFunction( "ceil", new StandardSQLFunction("ceil") );
		registerFunction( "floor", new StandardSQLFunction("floor") );

		registerFunction( "chr", new StandardSQLFunction("chr", Hibernate.CHARACTER) );
		registerFunction( "initcap", new StandardSQLFunction("initcap") );
		registerFunction( "lower", new StandardSQLFunction("lower") );
		registerFunction( "ltrim", new StandardSQLFunction("ltrim") );
		registerFunction( "rtrim", new StandardSQLFunction("rtrim") );
		registerFunction( "soundex", new StandardSQLFunction("soundex") );
		registerFunction( "upper", new StandardSQLFunction("upper") );
		registerFunction( "ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER) );
		registerFunction( "length", new StandardSQLFunction("length", Hibernate.LONG) );

		registerFunction( "to_char", new StandardSQLFunction("to_char", Hibernate.STRING) );
		registerFunction( "to_date", new StandardSQLFunction("to_date", Hibernate.TIMESTAMP) );

		registerFunction( "current_date", new NoArgSQLFunction("current_date", Hibernate.DATE, false) );
		registerFunction( "current_time", new NoArgSQLFunction("current_timestamp", Hibernate.TIME, false) );
		registerFunction( "current_timestamp", new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP, false) );

		registerFunction( "lastday", new StandardSQLFunction("lastday", Hibernate.DATE) );
		registerFunction( "sysdate", new NoArgSQLFunction("sysdate", Hibernate.DATE, false) );
		registerFunction( "systimestamp", new NoArgSQLFunction("systimestamp", Hibernate.TIMESTAMP, false) );
		registerFunction( "uid", new NoArgSQLFunction("uid", Hibernate.INTEGER, false) );
		registerFunction( "user", new NoArgSQLFunction("user", Hibernate.STRING, false) );

		registerFunction( "rowid", new NoArgSQLFunction("rowid", Hibernate.LONG, false) );
		registerFunction( "rownum", new NoArgSQLFunction("rownum", Hibernate.LONG, false) );

		// Multi-param string dialect functions...
		registerFunction( "concat", new VarArgsSQLFunction(Hibernate.STRING, "", "||", "") );
		registerFunction( "instr", new StandardSQLFunction("instr", Hibernate.INTEGER) );
		registerFunction( "instrb", new StandardSQLFunction("instrb", Hibernate.INTEGER) );
		registerFunction( "lpad", new StandardSQLFunction("lpad", Hibernate.STRING) );
		registerFunction( "replace", new StandardSQLFunction("replace", Hibernate.STRING) );
		registerFunction( "rpad", new StandardSQLFunction("rpad", Hibernate.STRING) );
		registerFunction( "substr", new StandardSQLFunction("substr", Hibernate.STRING) );
		registerFunction( "substrb", new StandardSQLFunction("substrb", Hibernate.STRING) );
		registerFunction( "translate", new StandardSQLFunction("translate", Hibernate.STRING) );

		registerFunction( "substring", new StandardSQLFunction( "substr", Hibernate.STRING ) );
		registerFunction( "locate", new SQLFunctionTemplate( Hibernate.INTEGER, "instr(?2,?1)" ) );
		registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "vsize(?1)*8" ) );
		registerFunction( "coalesce", new NvlFunction() );

		// Multi-param numeric dialect functions...
		registerFunction( "atan2", new StandardSQLFunction("atan2", Hibernate.FLOAT) );
		registerFunction( "log", new StandardSQLFunction("log", Hibernate.INTEGER) );
		registerFunction( "mod", new StandardSQLFunction("mod", Hibernate.INTEGER) );
		registerFunction( "nvl", new StandardSQLFunction("nvl") );
		registerFunction( "nvl2", new StandardSQLFunction("nvl2") );
		registerFunction( "power", new StandardSQLFunction("power", Hibernate.FLOAT) );

		// Multi-param date dialect functions...
		registerFunction( "add_months", new StandardSQLFunction("add_months", Hibernate.DATE) );
		registerFunction( "months_between", new StandardSQLFunction("months_between", Hibernate.FLOAT) );
		registerFunction( "next_day", new StandardSQLFunction("next_day", Hibernate.DATE) );

		registerFunction( "str", new StandardSQLFunction("to_char", Hibernate.STRING) );
	
protected voidregisterLargeObjectTypeMappings()

		registerColumnType( Types.VARBINARY, 2000, "raw($l)" );
		registerColumnType( Types.VARBINARY, "long raw" );

		registerColumnType( Types.BLOB, "blob" );
		registerColumnType( Types.CLOB, "clob" );
	
protected voidregisterNumericTypeMappings()

		registerColumnType( Types.BIT, "number(1,0)" );
		registerColumnType( Types.BIGINT, "number(19,0)" );
		registerColumnType( Types.SMALLINT, "number(5,0)" );
		registerColumnType( Types.TINYINT, "number(3,0)" );
		registerColumnType( Types.INTEGER, "number(10,0)" );

		registerColumnType( Types.FLOAT, "float" );
		registerColumnType( Types.DOUBLE, "double precision" );
		registerColumnType( Types.NUMERIC, "number($p,$s)" );
		registerColumnType( Types.DECIMAL, "number($p,$s)" );
	
public intregisterResultSetOutParameter(java.sql.CallableStatement statement, int col)

	       
		if(oracletypes_cursor_value==0) {
			try {
				Class types = ReflectHelper.classForName("oracle.jdbc.driver.OracleTypes");
				oracletypes_cursor_value = types.getField("CURSOR").getInt(types.newInstance());
			} catch (Exception se) {
				throw new HibernateException("Problem while trying to load or access OracleTypes.CURSOR value",se);
			}
		}
		//	register the type of the out param - an Oracle specific type
		statement.registerOutParameter(col, oracletypes_cursor_value);
		col++;
		return col;
	
protected voidregisterReverseHibernateTypeMappings()

	
public booleansupportsCommentOn()

		return true;
	
public booleansupportsCurrentTimestampSelection()

		return true;
	
public booleansupportsEmptyInList()

		return false;
	
public booleansupportsExistsInSelect()

		return false;
	
public booleansupportsLimit()

		return true;
	
public booleansupportsPooledSequences()

		return true;
	
public booleansupportsSequences()

		return true;
	
public booleansupportsTemporaryTables()

		return true;
	
public booleansupportsUnionAll()

		return true;
	
public booleanuseMaxForLimit()

		return true;