Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //$Id: $
  package org.hibernate.dialect;
  
  import java.sql.ResultSet;
  import java.sql.Types;
  import java.util.Map;
  import java.util.Iterator;
 
An abstract base class for Sybase and MS SQL Server dialects.

Author(s):
Gavin King
 
 
 /* package-private */
 abstract class AbstractTransactSQLDialect extends Dialect {
 		super();
 		registerColumnType."tinyint" ); //Sybase BIT type does not support null values
 		registerColumnType."numeric(19,0)" );
 		registerColumnType."smallint" );
 		registerColumnType."tinyint" );
 		registerColumnType."char(1)" );
 		registerColumnType."varchar($l)" );
 		registerColumnType."float" );
 		registerColumnType."double precision" );
 		registerColumnType."datetime" );
 		registerColumnType."datetime" );
 		registerColumnType."datetime" );
 		registerColumnType."varbinary($l)" );
 		registerColumnType."numeric($p,$s)" );
 		registerColumnType."image" );
 		registerColumnType."text" );
 
 		registerFunction"ascii"new StandardSQLFunction("ascii".) );
 		registerFunction"len"new StandardSQLFunction("len".) );
 		registerFunction"lower"new StandardSQLFunction("lower") );
 		registerFunction"upper"new StandardSQLFunction("upper") );
 		registerFunction"ltrim"new StandardSQLFunction("ltrim") );
 		registerFunction"rtrim"new StandardSQLFunction("rtrim") );
 		registerFunction"reverse"new StandardSQLFunction("reverse") );
 		registerFunction"space"new StandardSQLFunction("space".) );
 
 		registerFunction"user"new NoArgSQLFunction("user".) );
 
 		registerFunction"current_timestamp"new NoArgSQLFunction("getdate".) );
 		registerFunction"current_time"new NoArgSQLFunction("getdate".) );
 		registerFunction"current_date"new NoArgSQLFunction("getdate".) );
 
 		registerFunction"getdate"new NoArgSQLFunction("getdate".) );
 		registerFunction"getutcdate"new NoArgSQLFunction("getutcdate".) );
 		registerFunction"month"new StandardSQLFunction("month".) );
 		registerFunction"year"new StandardSQLFunction("year".) );
 		registerFunction"datename"new StandardSQLFunction("datename".) );
 
 		registerFunction"abs"new StandardSQLFunction("abs") );
 		registerFunction"sign"new StandardSQLFunction("sign".) );
 
 		registerFunction"acos"new StandardSQLFunction("acos".) );
 		registerFunction"asin"new StandardSQLFunction("asin".) );
 		registerFunction"atan"new StandardSQLFunction("atan".) );
 		registerFunction"log"new StandardSQLFunction"log".) );
 		registerFunction"log10"new StandardSQLFunction("log10".) );
 		registerFunction"sqrt"new StandardSQLFunction("sqrt".) );
 		registerFunction"square"new StandardSQLFunction("square") );
 		registerFunction"rand"new StandardSQLFunction("rand".) );
 
 		registerFunction("radians"new StandardSQLFunction("radians".) );
 		registerFunction("degrees"new StandardSQLFunction("degrees".) );
 
 		registerFunction"round"new StandardSQLFunction("round") );
 		registerFunction"ceiling"new StandardSQLFunction("ceiling") );
 		registerFunction"floor"new StandardSQLFunction("floor") );
 
 		registerFunction"isnull"new StandardSQLFunction("isnull") );
 
 		registerFunction"concat"new VarArgsSQLFunction."(","+",")" ) );
 
 		registerFunction"length"new StandardSQLFunction"len". ) );
		registerFunction"trim"new SQLFunctionTemplate."ltrim(rtrim(?1))") );
		registerFunction"locate"new CharIndexFunction() );
	}
		return "add";
	}
		return " null";
	}
	public boolean qualifyIndexName() {
		return false;
	}
		return "";
	}
	public boolean supportsIdentityColumns() {
		return true;
	}
		return "select @@identity";
	}
		return "identity not null"//starts with 1, implicitly
	}
	public boolean supportsInsertSelectIdentity() {
		return true;
	}
		return insertSQL + "\nselect @@identity";
	}
	public String appendLockHint(LockMode modeString tableName) {
		if ( mode.greaterThan. ) ) {
			return tableName + " holdlock";
		}
		else {
			return tableName;
		}
	}
	public String applyLocksToSql(String sqlMap aliasedLockModesMap keyColumnNames) {
		Iterator itr = aliasedLockModes.entrySet().iterator();
		StringBuffer buffer = new StringBuffersql );
		int correction = 0;
		while ( itr.hasNext() ) {
			final Map.Entry entry = ( Map.Entry ) itr.next();
			final LockMode lockMode = ( LockMode ) entry.getValue();
			if ( lockMode.greaterThan. ) ) {
				final String alias = ( String ) entry.getKey();
				int start = -1, end = -1;
				if ( sql.endsWith" " + alias ) ) {
					start = ( sql.length() - alias.length() ) + correction;
					end = start + alias.length();
				}
				else {
					int position = sql.indexOf" " + alias + " " );
					if ( position <= -1 ) {
						position = sql.indexOf" " + alias + "," );
					}
					if ( position > -1 ) {
						start = position + correction + 1;
						end = start + alias.length();
					}
				}
				if ( start > -1 ) {
					final String lockHint = appendLockHintlockModealias );
					buffer.replacestartendlockHint );
					correction += ( lockHint.length() - alias.length() );
				}
			}
		}
		return buffer.toString();
	}
	public int registerResultSetOutParameter(CallableStatement statementint colthrows SQLException {
		return col// sql server just returns automatically
	}
		boolean isResultSet = ps.execute();
//		 This assumes you will want to ignore any update counts
		while ( !isResultSet && ps.getUpdateCount() != -1 ) {
			isResultSet = ps.getMoreResults();
		}
//		 You may still have other ResultSets or update counts left to process here
//		 but you can't do it now or the ResultSet you just got will be closed
		return ps.getResultSet();
	}
		return true;
	}
		return false;
	}
		return "select getdate()";
	}
	public boolean supportsTemporaryTables() {
		return true;
	}
	public String generateTemporaryTableName(String baseTableName) {
		return "#" + baseTableName;
	}
	public boolean dropTemporaryTableAfterUse() {
		return true;  // sql-server, at least needed this dropped after use; strange!
	}
	// Overridden informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	public boolean supportsEmptyInList() {
		return false;
	}
	public boolean supportsExistsInSelect() {
		return false;
	}
		return true;
	}
		return true;
	}
New to GrepCode? Check out our FAQ X