1 16 package org.pentaho.repository; 17 18 import java.sql.Types ; 19 import org.hibernate.Hibernate; 20 import org.hibernate.cfg.Environment; 21 import org.hibernate.dialect.Dialect; 22 import org.hibernate.dialect.function.NoArgSQLFunction; 23 import org.hibernate.dialect.function.StandardSQLFunction; 24 import org.hibernate.util.StringHelper; 25 26 public class MySQL5Dialect extends Dialect { 27 28 static final String DEFAULT_BATCH_SIZE = "15"; 30 public MySQL5Dialect() { 31 super(); 32 registerColumnType(Types.BIT, "bit"); registerColumnType(Types.BIGINT, "bigint"); registerColumnType(Types.SMALLINT, "smallint"); registerColumnType(Types.TINYINT, "tinyint"); registerColumnType(Types.INTEGER, "integer"); registerColumnType(Types.CHAR, "char(1)"); registerColumnType(Types.VARCHAR, "longtext"); registerColumnType(Types.VARCHAR, 16777215, "mediumtext"); registerColumnType(Types.VARCHAR, 65535, "varchar($l)"); registerColumnType(Types.FLOAT, "float"); registerColumnType(Types.DOUBLE, "double precision"); registerColumnType(Types.DATE, "date"); registerColumnType(Types.TIME, "time"); registerColumnType(Types.TIMESTAMP, "datetime"); registerColumnType(Types.VARBINARY, "longblob"); registerColumnType(Types.VARBINARY, 16777215, "mediumblob"); registerColumnType(Types.VARBINARY, 65535, "blob"); registerColumnType(Types.VARBINARY, 255, "tinyblob"); registerColumnType(Types.NUMERIC, "numeric($p,$s)"); registerColumnType(Types.BLOB, "longblob"); registerColumnType(Types.BLOB, 16777215, "mediumblob"); registerColumnType(Types.BLOB, 65535, "blob"); registerColumnType(Types.CLOB, "longtext"); registerColumnType(Types.CLOB, 16777215, "mediumtext"); registerColumnType(Types.CLOB, 65535, "text"); 58 registerFunction("ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER)); registerFunction("bin", new StandardSQLFunction("bin", Hibernate.STRING)); registerFunction("char_length", new StandardSQLFunction("char_length", Hibernate.LONG)); registerFunction("character_length", new StandardSQLFunction("character_length", Hibernate.LONG)); registerFunction("lcase", new StandardSQLFunction("lcase")); registerFunction("lower", new StandardSQLFunction("lower")); registerFunction("length", new StandardSQLFunction("length", Hibernate.LONG)); registerFunction("ltrim", new StandardSQLFunction("ltrim")); registerFunction("ord", new StandardSQLFunction("ord", Hibernate.INTEGER)); registerFunction("quote", new StandardSQLFunction("quote")); registerFunction("reverse", new StandardSQLFunction("reverse")); registerFunction("rtrim", new StandardSQLFunction("rtrim")); registerFunction("soundex", new StandardSQLFunction("soundex")); registerFunction("space", new StandardSQLFunction("space", Hibernate.STRING)); registerFunction("ucase", new StandardSQLFunction("ucase")); registerFunction("upper", new StandardSQLFunction("upper")); registerFunction("unhex", new StandardSQLFunction("unhex", Hibernate.STRING)); 76 registerFunction("abs", new StandardSQLFunction("abs")); registerFunction("sign", new StandardSQLFunction("sign", Hibernate.INTEGER)); 79 registerFunction("acos", new StandardSQLFunction("acos", Hibernate.DOUBLE)); registerFunction("asin", new StandardSQLFunction("asin", Hibernate.DOUBLE)); registerFunction("atan", new StandardSQLFunction("atan", Hibernate.DOUBLE)); registerFunction("cos", new StandardSQLFunction("cos", Hibernate.DOUBLE)); registerFunction("cot", new StandardSQLFunction("cot", Hibernate.DOUBLE)); registerFunction("crc32", new StandardSQLFunction("crc32", Hibernate.LONG)); registerFunction("exp", new StandardSQLFunction("exp", Hibernate.DOUBLE)); registerFunction("ln", new StandardSQLFunction("ln", Hibernate.DOUBLE)); registerFunction("log", new StandardSQLFunction("log", Hibernate.DOUBLE)); registerFunction("log2", new StandardSQLFunction("log2", Hibernate.DOUBLE)); registerFunction("log10", new StandardSQLFunction("log10", Hibernate.DOUBLE)); registerFunction("pi", new NoArgSQLFunction("pi", Hibernate.DOUBLE)); registerFunction("rand", new NoArgSQLFunction("rand", Hibernate.DOUBLE)); registerFunction("sin", new StandardSQLFunction("sin", Hibernate.DOUBLE)); registerFunction("sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE)); registerFunction("tan", new StandardSQLFunction("tan", Hibernate.DOUBLE)); 96 registerFunction("radians", new StandardSQLFunction("radians", Hibernate.DOUBLE)); registerFunction("degrees", new StandardSQLFunction("degrees", Hibernate.DOUBLE)); 99 registerFunction("ceiling", new StandardSQLFunction("ceiling", Hibernate.INTEGER)); registerFunction("ceil", new StandardSQLFunction("ceil", Hibernate.INTEGER)); registerFunction("floor", new StandardSQLFunction("floor", Hibernate.INTEGER)); registerFunction("round", new StandardSQLFunction("round", Hibernate.INTEGER)); 104 registerFunction("curdate", new NoArgSQLFunction("curdate", Hibernate.DATE)); registerFunction("curtime", new NoArgSQLFunction("curtime", Hibernate.TIME)); registerFunction("current_date", new NoArgSQLFunction("current_date", Hibernate.DATE, false)); registerFunction("current_time", new NoArgSQLFunction("current_time", Hibernate.TIME, false)); registerFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP, false)); registerFunction("date", new StandardSQLFunction("date", Hibernate.DATE)); registerFunction("day", new StandardSQLFunction("day", Hibernate.INTEGER)); registerFunction("dayofmonth", new StandardSQLFunction("dayofmonth", Hibernate.INTEGER)); registerFunction("dayname", new StandardSQLFunction("dayname", Hibernate.STRING)); registerFunction("dayofweek", new StandardSQLFunction("dayofweek", Hibernate.INTEGER)); registerFunction("dayofyear", new StandardSQLFunction("dayofyear", Hibernate.INTEGER)); registerFunction("from_days", new StandardSQLFunction("from_days", Hibernate.DATE)); registerFunction("from_unixtime", new StandardSQLFunction("from_unixtime", Hibernate.TIMESTAMP)); registerFunction("hour", new StandardSQLFunction("hour", Hibernate.INTEGER)); registerFunction("last_day", new StandardSQLFunction("last_day", Hibernate.DATE)); registerFunction("localtime", new NoArgSQLFunction("localtime", Hibernate.TIMESTAMP)); registerFunction("localtimestamp", new NoArgSQLFunction("localtimestamp", Hibernate.TIMESTAMP)); registerFunction("microseconds", new StandardSQLFunction("microseconds", Hibernate.INTEGER)); registerFunction("minute", new StandardSQLFunction("minute", Hibernate.INTEGER)); registerFunction("month", new StandardSQLFunction("month", Hibernate.INTEGER)); registerFunction("monthname", new StandardSQLFunction("monthname", Hibernate.STRING)); registerFunction("now", new NoArgSQLFunction("now", Hibernate.TIMESTAMP)); registerFunction("quarter", new StandardSQLFunction("quarter", Hibernate.INTEGER)); registerFunction("second", new StandardSQLFunction("second", Hibernate.INTEGER)); registerFunction("sec_to_time", new StandardSQLFunction("sec_to_time", Hibernate.TIME)); registerFunction("sysdate", new NoArgSQLFunction("sysdate", Hibernate.TIMESTAMP)); registerFunction("time", new StandardSQLFunction("time", Hibernate.TIME)); registerFunction("timestamp", new StandardSQLFunction("timestamp", Hibernate.TIMESTAMP)); registerFunction("time_to_sec", new StandardSQLFunction("time_to_sec", Hibernate.INTEGER)); registerFunction("to_days", new StandardSQLFunction("to_days", Hibernate.LONG)); registerFunction("unix_timestamp", new StandardSQLFunction("unix_timestamp", Hibernate.LONG)); registerFunction("utc_date", new NoArgSQLFunction("utc_date", Hibernate.STRING)); registerFunction("utc_time", new NoArgSQLFunction("utc_time", Hibernate.STRING)); registerFunction("utc_timestamp", new NoArgSQLFunction("utc_timestamp", Hibernate.STRING)); registerFunction("week", new StandardSQLFunction("week", Hibernate.INTEGER)); registerFunction("weekday", new StandardSQLFunction("weekday", Hibernate.INTEGER)); registerFunction("weekofyear", new StandardSQLFunction("weekofyear", Hibernate.INTEGER)); registerFunction("year", new StandardSQLFunction("year", Hibernate.INTEGER)); registerFunction("yearweek", new StandardSQLFunction("yearweek", Hibernate.INTEGER)); 144 registerFunction("hex", new StandardSQLFunction("hex", Hibernate.STRING)); registerFunction("oct", new StandardSQLFunction("oct", Hibernate.STRING)); 147 registerFunction("octet_length", new StandardSQLFunction("octet_length", Hibernate.LONG)); registerFunction("bit_length", new StandardSQLFunction("bit_length", Hibernate.LONG)); 150 registerFunction("bit_count", new StandardSQLFunction("bit_count", Hibernate.LONG)); registerFunction("encrypt", new StandardSQLFunction("encrypt", Hibernate.STRING)); registerFunction("md5", new StandardSQLFunction("md5", Hibernate.STRING)); registerFunction("sha1", new StandardSQLFunction("sha1", Hibernate.STRING)); registerFunction("sha", new StandardSQLFunction("sha", Hibernate.STRING)); 156 registerFunction("concat", new StandardSQLFunction("concat", Hibernate.STRING)); 158 getDefaultProperties().setProperty(Environment.MAX_FETCH_DEPTH, "2"); getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE); 160 } 161 162 public String getAddColumnString() { 163 return "add column"; } 165 166 public boolean qualifyIndexName() { 167 return false; 168 } 169 170 public boolean supportsIdentityColumns() { 171 return true; 172 } 173 174 public String getIdentitySelectString() { 175 return "select last_insert_id()"; } 177 178 public String getIdentityColumnString() { 179 return "not null auto_increment"; } 181 182 public String getAddForeignKeyConstraintString(String constraintName, String foreignKey[], String referencedTable, String primaryKey[], boolean referencesPrimaryKey) { 183 String cols = StringHelper.join(", ", foreignKey); return (new StringBuffer (30)) 185 .append(" add index ").append(constraintName).append(" (").append(cols).append("), add constraint ").append(constraintName).append(" foreign key (").append(cols).append(") references ").append(referencedTable).append(" (").append(StringHelper.join(", ", primaryKey)).append(')').toString(); } 187 188 public boolean supportsLimit() { 189 return true; 190 } 191 192 public String getDropForeignKeyString() { 193 return " drop foreign key "; } 195 196 public String getLimitString(String sql, boolean hasOffset) { 197 return (new StringBuffer (sql.length() + 20)).append(sql).append(hasOffset ? " limit ?, ?" : " limit ?").toString(); } 199 200 public char closeQuote() { 201 return '`'; 202 } 203 204 public char openQuote() { 205 return '`'; 206 } 207 208 public boolean supportsIfExistsBeforeTableName() { 209 return true; 210 } 211 212 public char getSchemaSeparator() { 213 return '_'; 214 } 215 216 public String getSelectGUIDString() { 217 return "select uuid()"; } 219 220 public boolean supportsCascadeDelete() { 221 return false; 222 } 223 224 public String getTableComment(String comment) { 225 return " comment='" + comment + "'"; } 227 228 public String getColumnComment(String comment) { 229 return " comment '" + comment + "'"; } 231 232 public boolean supportsTemporaryTables() { 233 return true; 234 } 235 236 public String getTemporaryTableCreationCommand() { 237 return "create temporary table if not exists"; } 239 240 public String getCastTypeName(int code) { 241 if (code == 4) 242 return "signed"; else 244 return super.getCastTypeName(code); 245 } 246 247 public boolean supportsCurrentTimestampSelection() { 248 return true; 249 } 250 251 public boolean isCurrentTimestampSelectStringCallable() { 252 return false; 253 } 254 255 public String getCurrentTimestampSelectString() { 256 return "select now()"; } 258 } 259 | Popular Tags |