1 package org.hibernate.dialect; 2 3 import java.sql.Types ; 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 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 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 getAddColumnString() { 82 return "add"; 83 } 84 85 public boolean supportsSequences() { 86 return true; 87 } 88 89 public String getSequenceNextValString(String sequenceName) { 90 return "select first 1 " + sequenceName + ".nextval from sys.tables"; 91 } 92 93 public String getCreateSequenceString(String sequenceName) { 94 return "create sequence " + sequenceName; 95 } 96 97 public String getDropSequenceString(String sequenceName) { 98 return "drop sequence " + sequenceName; 99 } 100 101 public String getQuerySequencesString() { 102 return "select NAME from sys.sequences"; 103 } 104 105 public JoinFragment createOuterJoinFragment() { 106 return new OracleJoinFragment(); 107 } 108 109 113 114 public String 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 sql) { 143 return 6; } 145 146 public String getLimitString(String querySelect, int offset, int limit) { 147 if (offset>0) throw new UnsupportedOperationException ("sql server has no offset"); 148 return new StringBuffer ( 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 |