KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.hibernate.dialect;
2
3 import java.sql.Types JavaDoc;
4
5 import org.hibernate.Hibernate;
6 import org.hibernate.cfg.Environment;
7 import org.hibernate.dialect.function.NoArgSQLFunction;
8 import org.hibernate.dialect.function.StandardSQLFunction;
9 import org.hibernate.sql.JoinFragment;
10 import org.hibernate.sql.OracleJoinFragment;
11
12 /**
13  * A SQL dialect for TimesTen 5.1.
14  *
15  * Known limitations:
16  * joined-subclass support because of no CASE support in TimesTen
17  * No support for subqueries that includes aggregation
18  * - size() in HQL not supported
19  * - user queries that does subqueries with aggregation
20  * No CLOB/BLOB support
21  * No cascade delete support.
22  * No Calendar support
23  * No support for updating primary keys.
24  *
25  * @author Sherry Listgarten and Max Andersen
26  */

27 public class TimesTenDialect extends Dialect {
28     
29     public TimesTenDialect() {
30         super();
31         registerColumnType( Types.BIT, "TINYINT" );
32         registerColumnType( Types.BIGINT, "BIGINT" );
33         registerColumnType( Types.SMALLINT, "SMALLINT" );
34         registerColumnType( Types.TINYINT, "TINYINT" );
35         registerColumnType( Types.INTEGER, "INTEGER" );
36         registerColumnType( Types.CHAR, "CHAR(1)" );
37         registerColumnType( Types.VARCHAR, "VARCHAR($l)" );
38         registerColumnType( Types.FLOAT, "FLOAT" );
39         registerColumnType( Types.DOUBLE, "DOUBLE" );
40         registerColumnType( Types.DATE, "DATE" );
41         registerColumnType( Types.TIME, "TIME" );
42         registerColumnType( Types.TIMESTAMP, "TIMESTAMP" );
43         registerColumnType( Types.VARBINARY, "VARBINARY($l)" );
44         registerColumnType( Types.NUMERIC, "DECIMAL($p, $s)" );
45         // TimesTen has no BLOB/CLOB support, but these types may be suitable
46
// for some applications. The length is limited to 4 million bytes.
47
registerColumnType( Types.BLOB, "VARBINARY(4000000)" );
48         registerColumnType( Types.CLOB, "VARCHAR(4000000)" );
49     
50         getDefaultProperties().setProperty(Environment.USE_STREAMS_FOR_BINARY, "true");
51         getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
52         registerFunction( "lower", new StandardSQLFunction("lower") );
53         registerFunction( "upper", new StandardSQLFunction("upper") );
54         registerFunction( "rtrim", new StandardSQLFunction("rtrim") );
55         registerFunction( "concat", new StandardSQLFunction("concat", Hibernate.STRING) );
56         registerFunction( "mod", new StandardSQLFunction("mod") );
57         registerFunction( "to_char", new StandardSQLFunction("to_char",Hibernate.STRING) );
58         registerFunction( "to_date", new StandardSQLFunction("to_date",Hibernate.TIMESTAMP) );
59         registerFunction( "sysdate", new NoArgSQLFunction("sysdate", Hibernate.DATE, false) );
60         registerFunction( "getdate", new NoArgSQLFunction("getdate", Hibernate.DATE, false) );
61         registerFunction( "nvl", new StandardSQLFunction("nvl") );
62
63     }
64     
65     public boolean dropConstraints() {
66             return true;
67     }
68     
69     public boolean qualifyIndexName() {
70             return false;
71     }
72
73     public boolean supportsUnique() {
74         return false;
75     }
76     
77     public boolean supportsUniqueConstraintInCreateAlterTable() {
78         return false;
79     }
80     
81     public String JavaDoc getAddColumnString() {
82             return "add";
83     }
84
85     public boolean supportsSequences() {
86         return true;
87     }
88
89     public String JavaDoc getSequenceNextValString(String JavaDoc sequenceName) {
90         return "select first 1 " + sequenceName + ".nextval from sys.tables";
91     }
92
93     public String JavaDoc getCreateSequenceString(String JavaDoc sequenceName) {
94         return "create sequence " + sequenceName;
95     }
96
97     public String JavaDoc getDropSequenceString(String JavaDoc sequenceName) {
98         return "drop sequence " + sequenceName;
99     }
100
101     public String JavaDoc getQuerySequencesString() {
102         return "select NAME from sys.sequences";
103     }
104
105     public JoinFragment createOuterJoinFragment() {
106         return new OracleJoinFragment();
107     }
108
109     // new methods in dialect3
110
/*public boolean supportsForUpdateNowait() {
111         return false;
112     }*/

113     
114     public String JavaDoc getForUpdateString() {
115         return "";
116     }
117     
118     public boolean supportsColumnCheck() {
119         return false;
120     }
121
122     public boolean supportsTableCheck() {
123         return false;
124     }
125     
126     public boolean supportsLimitOffset() {
127         return false;
128     }
129
130     public boolean supportsVariableLimit() {
131         return false;
132     }
133
134     public boolean supportsLimit() {
135         return true;
136     }
137
138     public boolean useMaxForLimit() {
139         return true;
140     }
141
142     private static int getAfterSelectInsertPoint(String JavaDoc sql) {
143         return 6; //sql.startsWith("select distinct") ? 15 : 6;
144
}
145
146     public String JavaDoc getLimitString(String JavaDoc querySelect, int offset, int limit) {
147         if (offset>0) throw new UnsupportedOperationException JavaDoc("sql server has no offset");
148         return new StringBuffer JavaDoc( querySelect.length()+8 )
149             .append(querySelect)
150             .insert( getAfterSelectInsertPoint(querySelect), " first " + limit )
151             .toString();
152     }
153 }
154
155
156
157
158
159
160
161
Popular Tags