1 package org.hibernate.dialect; 3 4 import java.sql.Types ; 5 6 import org.hibernate.sql.CaseFragment; 7 import org.hibernate.sql.DecodeCaseFragment; 8 import org.hibernate.sql.JoinFragment; 9 import org.hibernate.sql.OracleJoinFragment; 10 11 15 public class OracleDialect extends Oracle9Dialect { 16 17 public OracleDialect() { 18 super(); 19 registerColumnType( Types.TIMESTAMP, "date" ); 22 } 23 24 public JoinFragment createOuterJoinFragment() { 25 return new OracleJoinFragment(); 26 } 27 public CaseFragment createCaseFragment() { 28 return new DecodeCaseFragment(); 29 } 30 31 public String getLimitString(String sql, boolean hasOffset) { 32 33 sql = sql.trim(); 34 boolean isForUpdate = false; 35 if ( sql.toLowerCase().endsWith(" for update") ) { 36 sql = sql.substring( 0, sql.length()-11 ); 37 isForUpdate = true; 38 } 39 40 StringBuffer pagingSelect = new StringBuffer ( sql.length()+100 ); 41 if (hasOffset) { 42 pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( "); 43 } 44 else { 45 pagingSelect.append("select * from ( "); 46 } 47 pagingSelect.append(sql); 48 if (hasOffset) { 49 pagingSelect.append(" ) row_ ) where rownum_ <= ? and rownum_ > ?"); 50 } 51 else { 52 pagingSelect.append(" ) where rownum <= ?"); 53 } 54 55 if (isForUpdate) pagingSelect.append(" for update"); 56 57 return pagingSelect.toString(); 58 } 59 60 public String getSelectClauseNullString(int sqlType) { 61 switch(sqlType) { 62 case Types.VARCHAR: 63 case Types.CHAR: 64 return "to_char(null)"; 65 case Types.DATE: 66 case Types.TIMESTAMP: 67 case Types.TIME: 68 return "to_date(null)"; 69 default: 70 return "to_number(null)"; 71 } 72 } 73 } 74 | Popular Tags |