1 package org.hibernate.dialect; 3 4 import java.sql.Types ; 5 6 import org.hibernate.Hibernate; 7 import org.hibernate.LockMode; 8 import org.hibernate.dialect.function.SQLFunctionTemplate; 9 10 14 public class SQLServerDialect extends SybaseDialect { 15 16 public SQLServerDialect() { 17 registerColumnType( Types.VARBINARY, "image" ); 18 registerColumnType( Types.VARBINARY, 8000, "varbinary($l)" ); 19 20 registerFunction( "second", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(second, ?1)") ); 21 registerFunction( "minute", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(minute, ?1)") ); 22 registerFunction( "hour", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(hour, ?1)") ); 23 } 24 25 public String getNoColumnsInsertString() { 26 return "default values"; 27 } 28 29 static int getAfterSelectInsertPoint(String sql) { 30 int selectIndex = sql.toLowerCase().indexOf( "select" ); 31 final int selectDistinctIndex = sql.toLowerCase().indexOf( "select distinct" ); 32 return selectIndex + ( selectDistinctIndex == selectIndex ? 15 : 6 ); 33 } 34 35 public String getLimitString(String querySelect, int offset, int limit) { 36 if (offset>0) throw new UnsupportedOperationException ("sql server has no offset"); 37 return new StringBuffer ( querySelect.length()+8 ) 38 .append(querySelect) 39 .insert( getAfterSelectInsertPoint(querySelect), " top " + limit ) 40 .toString(); 41 } 42 43 48 public String appendIdentitySelectToInsert(String insertSQL) { 49 return insertSQL + " select scope_identity()"; 50 } 51 52 public boolean supportsLimit() { 53 return true; 54 } 55 56 public boolean useMaxForLimit() { 57 return true; 58 } 59 60 public boolean supportsLimitOffset() { 61 return false; 62 } 63 64 public boolean supportsVariableLimit() { 65 return false; 66 } 67 68 public char closeQuote() { 69 return ']'; 70 } 71 72 public char openQuote() { 73 return '['; 74 } 75 76 public String appendLockHint(LockMode mode, String tableName) { 77 if ( mode.greaterThan(LockMode.READ) ) { 78 return tableName + " with (updlock, rowlock)"; 79 } 80 else { 81 return tableName; 82 } 83 } 84 85 public String getSelectGUIDString() { 86 return "select newid()"; 87 } 88 89 } 90 | Popular Tags |