KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > dialect > OracleDialect


1 //$Id: OracleDialect.java,v 1.14 2005/07/20 05:00:18 oneovthafew Exp $
2
package org.hibernate.dialect;
3
4 import java.sql.Types JavaDoc;
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 /**
12  * An SQL dialect for Oracle, compatible with Oracle 8.
13  * @author Gavin King
14  */

15 public class OracleDialect extends Oracle9Dialect {
16
17     public OracleDialect() {
18         super();
19         // Oracle8 and previous define only a "DATE" type which
20
// is used to represent all aspects of date/time
21
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 JavaDoc getLimitString(String JavaDoc 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 JavaDoc pagingSelect = new StringBuffer JavaDoc( 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 JavaDoc 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