FileDocCategorySizeDatePackage
SQLServerDialect.javaAPI DocHibernate 3.2.54236Mon Mar 19 16:06:46 GMT 2007org.hibernate.dialect

SQLServerDialect

public class SQLServerDialect extends SybaseDialect
A dialect for Microsoft SQL Server 2000 and 2005
author
Gavin King

Fields Summary
Constructors Summary
public SQLServerDialect()

		registerColumnType( Types.VARBINARY, "image" );
		registerColumnType( Types.VARBINARY, 8000, "varbinary($l)" );

		registerFunction( "second", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(second, ?1)") );
		registerFunction( "minute", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(minute, ?1)") );
		registerFunction( "hour", new SQLFunctionTemplate(Hibernate.INTEGER, "datepart(hour, ?1)") );
		registerFunction( "locate", new StandardSQLFunction("charindex", Hibernate.INTEGER) );

		registerFunction( "extract", new SQLFunctionTemplate( Hibernate.INTEGER, "datepart(?1, ?3)" ) );
		registerFunction( "mod", new SQLFunctionTemplate( Hibernate.INTEGER, "?1 % ?2" ) );
		registerFunction( "bit_length", new SQLFunctionTemplate( Hibernate.INTEGER, "datalength(?1) * 8" ) );

		registerFunction( "trim", new AnsiTrimEmulationFunction() );

		registerKeyword("top");
	
Methods Summary
public java.lang.StringappendIdentitySelectToInsert(java.lang.String insertSQL)
Use insert table(...) values(...) select SCOPE_IDENTITY()

		return insertSQL + " select scope_identity()";
	
public java.lang.StringappendLockHint(org.hibernate.LockMode mode, java.lang.String tableName)

		if ( mode.greaterThan( LockMode.READ ) ) {
			// does this need holdlock also? : return tableName + " with (updlock, rowlock, holdlock)";
			return tableName + " with (updlock, rowlock)";
		}
		else {
			return tableName;
		}
	
public booleanareStringComparisonsCaseInsensitive()

		return true;
	
public charcloseQuote()

		return ']";
	
public booleandoesReadCommittedCauseWritersToBlockReaders()

		return false; // here assume SQLServer2005 using snapshot isolation, which does not have this problem
	
public booleandoesRepeatableReadCauseReadersToBlockWriters()

		return false; // here assume SQLServer2005 using snapshot isolation, which does not have this problem
	
static intgetAfterSelectInsertPoint(java.lang.String sql)

		int selectIndex = sql.toLowerCase().indexOf( "select" );
		final int selectDistinctIndex = sql.toLowerCase().indexOf( "select distinct" );
		return selectIndex + ( selectDistinctIndex == selectIndex ? 15 : 6 );
	
public java.lang.StringgetCurrentTimestampSelectString()

		return "select current_timestamp";
	
public java.lang.StringgetLimitString(java.lang.String querySelect, int offset, int limit)

		if ( offset > 0 ) {
			throw new UnsupportedOperationException( "sql server has no offset" );
		}
		return new StringBuffer( querySelect.length()+8 )
			.append(querySelect)
			.insert( getAfterSelectInsertPoint(querySelect), " top " + limit )
			.toString();
	
public java.lang.StringgetNoColumnsInsertString()

		return "default values";
	
public java.lang.StringgetSelectGUIDString()

		return "select newid()";
	
public charopenQuote()

		return '[";
	
public booleansupportsCircularCascadeDeleteConstraints()

		// SQL Server (at least up through 2005) does not support defining
		// cascade delete constraints which can circel back to the mutating
		// table
		return false;
	
public booleansupportsLimit()

		return true;
	
public booleansupportsLimitOffset()

		return false;
	
public booleansupportsLobValueChangePropogation()

		// note: at least my local SQL Server 2005 Express shows this not working...
		return false;
	
public booleansupportsResultSetPositionQueryMethodsOnForwardOnlyCursor()

		return false;
	
public booleansupportsVariableLimit()

		return false;
	
public booleanuseMaxForLimit()

		return true;