package org.hibernate.dialect;
import java.sql.Types;
import java.util.Locale;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.sql.CaseFragment;
import org.hibernate.sql.DecodeCaseFragment;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.OracleJoinFragment;
import org.jboss.logging.Logger;
@SuppressWarnings("deprecation")
@Deprecated
public class OracleDialect extends Oracle9Dialect {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class,
OracleDialect.class.getName()
);
public OracleDialect() {
super();
LOG.deprecatedOracleDialect();
registerColumnType( Types.TIMESTAMP, "date" );
registerColumnType( Types.CHAR, "char(1)" );
registerColumnType( Types.VARCHAR, 4000, "varchar2($l)" );
}
@Override
public JoinFragment createOuterJoinFragment() {
return new OracleJoinFragment();
}
@Override
public CaseFragment createCaseFragment() {
return new DecodeCaseFragment();
}
@Override
public String getLimitString(String sql, boolean hasOffset) {
sql = sql.trim();
boolean isForUpdate = false;
if ( sql.toLowerCase(Locale.ROOT).endsWith( " for update" ) ) {
sql = sql.substring( 0, sql.length()-11 );
isForUpdate = true;
}
final StringBuilder pagingSelect = new StringBuilder( 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();
}
@Override
public String getSelectClauseNullString(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)";
}
}
@Override
public String getCurrentTimestampSelectString() {
return "select sysdate from dual";
}
@Override
public String getCurrentTimestampSQLFunctionName() {
return "sysdate";
}
}