Java Code Examples for org.hibernate.engine.spi.SessionFactoryImplementor.getDialect()

The following are Jave code examples for showing how to use getDialect() of the org.hibernate.engine.spi.SessionFactoryImplementor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: UpdateLockingStrategy.java   View Source Code Vote up 5 votes
protected String generateLockString() {
	final SessionFactoryImplementor factory = lockable.getFactory();
	final Update update = new Update( factory.getDialect() );
	update.setTableName( lockable.getRootTableName() );
	update.addPrimaryKeyColumns( lockable.getRootTableIdentifierColumnNames() );
	update.setVersionColumnName( lockable.getVersionColumnName() );
	update.addColumn( lockable.getVersionColumnName() );
	if ( factory.getSettings().isCommentsEnabled() ) {
		update.setComment( lockMode + " lock " + lockable.getEntityName() );
	}
	return update.toStatementString();
}
 
Example 2
Project: lams   File: PessimisticWriteUpdateLockingStrategy.java   View Source Code Vote up 5 votes
protected String generateLockString() {
	final SessionFactoryImplementor factory = lockable.getFactory();
	final Update update = new Update( factory.getDialect() );
	update.setTableName( lockable.getRootTableName() );
	update.addPrimaryKeyColumns( lockable.getRootTableIdentifierColumnNames() );
	update.setVersionColumnName( lockable.getVersionColumnName() );
	update.addColumn( lockable.getVersionColumnName() );
	if ( factory.getSettings().isCommentsEnabled() ) {
		update.setComment( lockMode + " lock " + lockable.getEntityName() );
	}
	return update.toStatementString();
}
 
Example 3
Project: lams   File: PessimisticReadUpdateLockingStrategy.java   View Source Code Vote up 5 votes
protected String generateLockString() {
	final SessionFactoryImplementor factory = lockable.getFactory();
	final Update update = new Update( factory.getDialect() );
	update.setTableName( lockable.getRootTableName() );
	update.addPrimaryKeyColumns( lockable.getRootTableIdentifierColumnNames() );
	update.setVersionColumnName( lockable.getVersionColumnName() );
	update.addColumn( lockable.getVersionColumnName() );
	if ( factory.getSettings().isCommentsEnabled() ) {
		update.setComment( lockMode + " lock " + lockable.getEntityName() );
	}
	return update.toStatementString();
}
 
Example 4
Project: unitimes   File: HibernateUtil.java   View Source Code Vote up 5 votes
public static void addBitwiseOperationsToDialect() {
	SessionFactoryImplementor hibSessionFactory = (SessionFactoryImplementor)new _RootDAO().getSession().getSessionFactory();
	Dialect dialect = hibSessionFactory.getDialect();
	if (!dialect.getFunctions().containsKey("bit_and")) {
		if (isOracle())
			dialect.getFunctions().put("bit_and", new StandardSQLFunction("bitand", IntegerType.INSTANCE));  
		else
			dialect.getFunctions().put("bit_and", new SQLFunctionTemplate(IntegerType.INSTANCE, "?1 & ?2"));
	}
}
 
Example 5
Project: lams   File: DeleteExecutor.java   View Source Code Vote up 4 votes
public DeleteExecutor(HqlSqlWalker walker, Queryable persister) {
	super( walker, persister );
	
	final SessionFactoryImplementor factory = walker.getSessionFactoryHelper().getFactory();
	final Dialect dialect = factory.getDialect();
	
	try {
		final DeleteStatement deleteStatement = (DeleteStatement) walker.getAST();
		
		final String idSubselectWhere;
		if ( deleteStatement.hasWhereClause() ) {
			final AST whereClause = deleteStatement.getWhereClause();
			final SqlGenerator gen = new SqlGenerator( factory );
			gen.whereClause( whereClause );
			parameterSpecifications = gen.getCollectedParameters();
			idSubselectWhere = gen.getSQL().length() > 7 ? gen.getSQL() : "";
		}
		else {
			parameterSpecifications = new ArrayList<ParameterSpecification>();
			idSubselectWhere = "";
		}
		
		// If many-to-many, delete the FK row in the collection table.
		for ( Type type : persister.getPropertyTypes() ) {
			if ( type.isCollectionType() ) {
				final CollectionType cType = (CollectionType) type;
				final AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory
						.getCollectionPersister( cType.getRole() );
				if ( cPersister.isManyToMany() ) {
					if ( persister.getIdentifierColumnNames().length > 1
							&& !dialect.supportsTuplesInSubqueries() ) {
						LOG.warn(
								"This dialect is unable to cascade the delete into the many-to-many join table" +
								" when the entity has multiple primary keys.  Either properly setup cascading on" +
								" the constraints or manually clear the associations prior to deleting the entities."
						);
					}
					else {
						final String idSubselect = "(select "
								+ StringHelper.join( ", ", persister.getIdentifierColumnNames() ) + " from "
								+ persister.getTableName() + idSubselectWhere + ")";
						final String where = "(" + StringHelper.join( ", ", cPersister.getKeyColumnNames() )
								+ ") in " + idSubselect;
						final Delete delete = new Delete().setTableName( cPersister.getTableName() ).setWhere( where );
						if ( factory.getSettings().isCommentsEnabled() ) {
							delete.setComment( "delete FKs in join table" );
						}
						deletes.add( delete.toStatementString() );
					}
				}
			}
		}
	}
	catch (RecognitionException e) {
		throw new HibernateException( "Unable to delete the FKs in the join table!", e );
	}
}