1 package org.hibernate.dialect; 3 4 import java.sql.CallableStatement ; 5 import java.sql.ResultSet ; 6 import java.sql.SQLException ; 7 import java.sql.Types ; 8 9 import org.hibernate.Hibernate; 10 import org.hibernate.LockMode; 11 import org.hibernate.cfg.Environment; 12 import org.hibernate.dialect.function.NoArgSQLFunction; 13 import org.hibernate.dialect.function.StandardSQLFunction; 14 import org.hibernate.dialect.function.VarArgsSQLFunction; 15 16 20 21 public class SybaseDialect extends Dialect { 22 public SybaseDialect() { 23 super(); 24 registerColumnType( Types.BIT, "tinyint" ); registerColumnType( Types.BIGINT, "numeric(19,0)" ); 26 registerColumnType( Types.SMALLINT, "smallint" ); 27 registerColumnType( Types.TINYINT, "tinyint" ); 28 registerColumnType( Types.INTEGER, "int" ); 29 registerColumnType( Types.CHAR, "char(1)" ); 30 registerColumnType( Types.VARCHAR, "varchar($l)" ); 31 registerColumnType( Types.FLOAT, "float" ); 32 registerColumnType( Types.DOUBLE, "double precision" ); 33 registerColumnType( Types.DATE, "datetime" ); 34 registerColumnType( Types.TIME, "datetime" ); 35 registerColumnType( Types.TIMESTAMP, "datetime" ); 36 registerColumnType( Types.VARBINARY, "varbinary($l)" ); 37 registerColumnType( Types.NUMERIC, "numeric($p,$s)" ); 38 registerColumnType( Types.BLOB, "image" ); 39 registerColumnType( Types.CLOB, "text" ); 40 41 registerFunction( "ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER) ); 42 registerFunction( "char", new StandardSQLFunction("char", Hibernate.CHARACTER) ); 43 registerFunction( "len", new StandardSQLFunction("len", Hibernate.LONG) ); 44 registerFunction( "lower", new StandardSQLFunction("lower") ); 45 registerFunction( "upper", new StandardSQLFunction("upper") ); 46 registerFunction( "str", new StandardSQLFunction("str", Hibernate.STRING) ); 47 registerFunction( "ltrim", new StandardSQLFunction("ltrim") ); 48 registerFunction( "rtrim", new StandardSQLFunction("rtrim") ); 49 registerFunction( "reverse", new StandardSQLFunction("reverse") ); 50 registerFunction( "space", new StandardSQLFunction("space", Hibernate.STRING) ); 51 52 registerFunction( "user", new NoArgSQLFunction("user", Hibernate.STRING) ); 53 54 registerFunction( "current_timestamp", new NoArgSQLFunction("getdate", Hibernate.TIMESTAMP) ); 55 registerFunction( "current_time", new NoArgSQLFunction("getdate", Hibernate.TIME) ); 56 registerFunction( "current_date", new NoArgSQLFunction("getdate", Hibernate.DATE) ); 57 58 registerFunction( "getdate", new NoArgSQLFunction("getdate", Hibernate.TIMESTAMP) ); 59 registerFunction( "getutcdate", new NoArgSQLFunction("getutcdate", Hibernate.TIMESTAMP) ); 60 registerFunction( "day", new StandardSQLFunction("day", Hibernate.INTEGER) ); 61 registerFunction( "month", new StandardSQLFunction("month", Hibernate.INTEGER) ); 62 registerFunction( "year", new StandardSQLFunction("year", Hibernate.INTEGER) ); 63 registerFunction( "datename", new StandardSQLFunction("datename", Hibernate.STRING) ); 64 65 registerFunction( "abs", new StandardSQLFunction("abs") ); 66 registerFunction( "sign", new StandardSQLFunction("sign", Hibernate.INTEGER) ); 67 68 registerFunction( "acos", new StandardSQLFunction("acos", Hibernate.DOUBLE) ); 69 registerFunction( "asin", new StandardSQLFunction("asin", Hibernate.DOUBLE) ); 70 registerFunction( "atan", new StandardSQLFunction("atan", Hibernate.DOUBLE) ); 71 registerFunction( "cos", new StandardSQLFunction("cos", Hibernate.DOUBLE) ); 72 registerFunction( "cot", new StandardSQLFunction("cot", Hibernate.DOUBLE) ); 73 registerFunction( "exp", new StandardSQLFunction("exp", Hibernate.DOUBLE) ); 74 registerFunction( "log", new StandardSQLFunction( "log", Hibernate.DOUBLE) ); 75 registerFunction( "log10", new StandardSQLFunction("log10", Hibernate.DOUBLE) ); 76 registerFunction( "sin", new StandardSQLFunction("sin", Hibernate.DOUBLE) ); 77 registerFunction( "sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE) ); 78 registerFunction( "tan", new StandardSQLFunction("tan", Hibernate.DOUBLE) ); 79 registerFunction( "pi", new NoArgSQLFunction("pi", Hibernate.DOUBLE) ); 80 registerFunction( "square", new StandardSQLFunction("square") ); 81 registerFunction( "rand", new StandardSQLFunction("rand", Hibernate.FLOAT) ); 82 83 registerFunction("radians", new StandardSQLFunction("radians", Hibernate.DOUBLE) ); 84 registerFunction("degrees", new StandardSQLFunction("degrees", Hibernate.DOUBLE) ); 85 86 registerFunction( "round", new StandardSQLFunction("round") ); 87 registerFunction( "ceiling", new StandardSQLFunction("ceiling") ); 88 registerFunction( "floor", new StandardSQLFunction("floor") ); 89 90 registerFunction( "isnull", new StandardSQLFunction("isnull") ); 91 92 registerFunction( "concat", new VarArgsSQLFunction( Hibernate.STRING, "(","+",")" ) ); 93 94 registerFunction( "length", new StandardSQLFunction( "len", Hibernate.INTEGER ) ); 95 96 getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH); 97 } 98 99 public String getAddColumnString() { 100 return "add"; 101 } 102 public String getNullColumnString() { 103 return " null"; 104 } 105 public boolean qualifyIndexName() { 106 return false; 107 } 108 109 public String getForUpdateString() { 110 return ""; 111 } 112 113 public boolean supportsIdentityColumns() { 114 return true; 115 } 116 public String getIdentitySelectString() { 117 return "select @@identity"; 118 } 119 public String getIdentityColumnString() { 120 return "identity not null"; } 122 123 public boolean supportsInsertSelectIdentity() { 124 return true; 125 } 126 127 public String appendIdentitySelectToInsert(String insertSQL) { 128 return insertSQL + "\nselect @@identity"; 129 } 130 131 public String appendLockHint(LockMode mode, String tableName) { 132 if ( mode.greaterThan(LockMode.READ) ) { 133 return tableName + " holdlock"; 134 } 135 else { 136 return tableName; 137 } 138 } 139 140 public int registerResultSetOutParameter(CallableStatement statement, int col) throws SQLException { 141 return col; } 143 144 public ResultSet getResultSet(CallableStatement ps) throws SQLException { 145 boolean isResultSet = ps.execute(); 146 while (!isResultSet && ps.getUpdateCount() != -1) { 148 isResultSet = ps.getMoreResults(); 149 } 150 ResultSet rs = ps.getResultSet(); 151 return rs; 154 } 155 156 } 157 | Popular Tags |