Java Code Examples for org.hibernate.sql.SimpleSelect

The following examples show how to use org.hibernate.sql.SimpleSelect. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
default String generateSelectLockString(LockOptions lockOptions) {
	final SessionFactoryImplementor factory = getFactory();
	Dialect dialect = factory.getJdbcServices().getDialect();
	final SimpleSelect select = new SimpleSelect(dialect)
			.setLockOptions( lockOptions )
			.setTableName( getRootTableName() )
			.addColumn( getRootTableIdentifierColumnNames()[0] )
			.addCondition( getRootTableIdentifierColumnNames(), "=?" );
	if ( isVersioned() ) {
		select.addCondition( getVersionColumnName(), "=?" );
	}
	if ( factory.getSessionFactoryOptions().isCommentsEnabled() ) {
		select.setComment( lockOptions.getLockMode() + " lock " + getEntityName() );
	}
	return select.toStatementString();
}
 
Example 2
protected String generateLockString(int lockTimeout) {
	final SessionFactoryImplementor factory = getLockable().getFactory();
	final LockOptions lockOptions = new LockOptions( getLockMode() );
	lockOptions.setTimeOut( lockTimeout );
	final SimpleSelect select = new SimpleSelect( factory.getDialect() )
			.setLockOptions( lockOptions )
			.setTableName( getLockable().getRootTableName() )
			.addColumn( getLockable().getRootTableIdentifierColumnNames()[0] )
			.addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" );
	if ( getLockable().isVersioned() ) {
		select.addCondition( getLockable().getVersionColumnName(), "=?" );
	}
	if ( factory.getSessionFactoryOptions().isCommentsEnabled() ) {
		select.setComment( getLockMode() + " lock " + getLockable().getEntityName() );
	}
	return select.toStatementString();
}
 
Example 3
Source Project: lams   Source File: SelectLockingStrategy.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected String generateLockString(int timeout) {
	final SessionFactoryImplementor factory = getLockable().getFactory();
	final LockOptions lockOptions = new LockOptions( getLockMode() );
	lockOptions.setTimeOut( timeout );
	final SimpleSelect select = new SimpleSelect( factory.getDialect() )
			.setLockOptions( lockOptions )
			.setTableName( getLockable().getRootTableName() )
			.addColumn( getLockable().getRootTableIdentifierColumnNames()[0] )
			.addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" );
	if ( getLockable().isVersioned() ) {
		select.addCondition( getLockable().getVersionColumnName(), "=?" );
	}
	if ( factory.getSessionFactoryOptions().isCommentsEnabled() ) {
		select.setComment( getLockMode() + " lock " + getLockable().getEntityName() );
	}
	return select.toStatementString();
}
 
Example 4
protected String generateLockString(int lockTimeout) {
	final SessionFactoryImplementor factory = getLockable().getFactory();
	final LockOptions lockOptions = new LockOptions( getLockMode() );
	lockOptions.setTimeOut( lockTimeout );
	final SimpleSelect select = new SimpleSelect( factory.getDialect() )
			.setLockOptions( lockOptions )
			.setTableName( getLockable().getRootTableName() )
			.addColumn( getLockable().getRootTableIdentifierColumnNames()[0] )
			.addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" );
	if ( getLockable().isVersioned() ) {
		select.addCondition( getLockable().getVersionColumnName(), "=?" );
	}
	if ( factory.getSessionFactoryOptions().isCommentsEnabled() ) {
		select.setComment( getLockMode() + " lock " + getLockable().getEntityName() );
	}
	return select.toStatementString();
}
 
Example 5
Source Project: lams   Source File: AbstractEntityPersister.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate the SQL that selects the version number by id
 */
protected String generateSelectVersionString() {
	SimpleSelect select = new SimpleSelect( getFactory().getDialect() )
			.setTableName( getVersionedTableName() );
	if ( isVersioned() ) {
		select.addColumn( versionColumnName );
	}
	else {
		select.addColumns( rootTableKeyColumnNames );
	}
	if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
		select.setComment( "get version " + getEntityName() );
	}
	return select.addCondition( rootTableKeyColumnNames, "=?" ).toStatementString();
}
 
Example 6
Source Project: lams   Source File: AbstractEntityPersister.java    License: GNU General Public License v2.0 5 votes vote down vote up
public String getSelectByUniqueKeyString(String propertyName) {
	return new SimpleSelect( getFactory().getDialect() )
			.setTableName( getTableName( 0 ) )
			.addColumns( getKeyColumns( 0 ) )
			.addCondition( getPropertyColumnNames( propertyName ), "=?" )
			.toStatementString();
}
 
Example 7
/**
 * Generate the SQL that selects a row by id
 */
protected String generateSelectString(LockMode lockMode) {
	SimpleSelect select = new SimpleSelect( getFactory().getDialect() )
			.setLockMode( lockMode )
			.setTableName( getTableName() )
			.addColumns( getIdentifierColumnNames() )
			.addColumns(
					getSubclassColumnClosure(),
					getSubclassColumnAliasClosure(),
					getSubclassColumnLazyiness()
			)
			.addColumns(
					getSubclassFormulaClosure(),
					getSubclassFormulaAliasClosure(),
					getSubclassFormulaLazyiness()
			);
	//TODO: include the rowids!!!!
	if ( hasSubclasses() ) {
		if ( isDiscriminatorFormula() ) {
			select.addColumn( getDiscriminatorFormula(), getDiscriminatorAlias() );
		}
		else {
			select.addColumn( getDiscriminatorColumnName(), getDiscriminatorAlias() );
		}
	}
	if ( getFactory().getSettings().isCommentsEnabled() ) {
		select.setComment( "load " + getEntityName() );
	}
	return select.addCondition( getIdentifierColumnNames(), "=?" ).toStatementString();
}
 
Example 8
protected String generateSelectSizeString(boolean isIntegerIndexed) {
	String selectValue = isIntegerIndexed ?
			"max(" + getIndexColumnNames()[0] + ") + 1" : // lists, arrays
			"count(" + getElementColumnNames()[0] + ")"; // sets, maps, bags
	return new SimpleSelect( dialect )
			.setTableName( getTableName() )
			.addCondition( getKeyColumnNames(), "=?" )
			.addWhereToken( sqlWhereString )
			.addColumn( selectValue )
			.toStatementString();
}
 
Example 9
protected String generateDetectRowByIndexString() {
	if ( !hasIndex() ) {
		return null;
	}
	return new SimpleSelect( dialect )
			.setTableName( getTableName() )
			.addCondition( getKeyColumnNames(), "=?" )
			.addCondition( getIndexColumnNames(), "=?" )
			.addCondition( indexFormulas, "=?" )
			.addWhereToken( sqlWhereString )
			.addColumn( "1" )
			.toStatementString();
}
 
Example 10
protected String generateSelectRowByIndexString() {
	if ( !hasIndex() ) {
		return null;
	}
	return new SimpleSelect( dialect )
			.setTableName( getTableName() )
			.addCondition( getKeyColumnNames(), "=?" )
			.addCondition( getIndexColumnNames(), "=?" )
			.addCondition( indexFormulas, "=?" )
			.addWhereToken( sqlWhereString )
			.addColumns( getElementColumnNames(), elementColumnAliases )
			.addColumns( indexFormulas, indexColumnAliases )
			.toStatementString();
}
 
Example 11
protected String generateDetectRowByElementString() {
	return new SimpleSelect( dialect )
			.setTableName( getTableName() )
			.addCondition( getKeyColumnNames(), "=?" )
			.addCondition( getElementColumnNames(), "=?" )
			.addCondition( elementFormulas, "=?" )
			.addWhereToken( sqlWhereString )
			.addColumn( "1" )
			.toStatementString();
}
 
Example 12
/**
 * Generate the SQL that selects the version number by id
 */
protected String generateSelectVersionString() {
	SimpleSelect select = new SimpleSelect( getFactory().getDialect() )
			.setTableName( getVersionedTableName() );
	if ( isVersioned() ) {
		select.addColumn( versionColumnName );
	}
	else {
		select.addColumns( rootTableKeyColumnNames );
	}
	if ( getFactory().getSettings().isCommentsEnabled() ) {
		select.setComment( "get version " + getEntityName() );
	}
	return select.addCondition( rootTableKeyColumnNames, "=?" ).toStatementString();
}
 
Example 13
public String getSelectByUniqueKeyString(String propertyName) {
	return new SimpleSelect( getFactory().getDialect() )
		.setTableName( getTableName(0) )
		.addColumns( getKeyColumns(0) )
		.addCondition( getPropertyColumnNames(propertyName), "=?" )
		.toStatementString();
}
 
Example 14
/**
 * Generate the SQL that selects a row by id
 */
protected String generateSelectString(LockMode lockMode) {
	SimpleSelect select = new SimpleSelect( getFactory().getDialect() )
		.setLockMode(lockMode)
		.setTableName( getTableName() )
		.addColumns( getIdentifierColumnNames() )
		.addColumns( 
				getSubclassColumnClosure(), 
				getSubclassColumnAliasClosure(),
				getSubclassColumnLazyiness()
		)
		.addColumns( 
				getSubclassFormulaClosure(), 
				getSubclassFormulaAliasClosure(),
				getSubclassFormulaLazyiness()
		);
	//TODO: include the rowids!!!!
	if ( hasSubclasses() ) {
		if ( isDiscriminatorFormula() ) {
			select.addColumn( getDiscriminatorFormula(), getDiscriminatorAlias() );
		}
		else {
			select.addColumn( getDiscriminatorColumnName(), getDiscriminatorAlias() );
		}
	}
	if ( getFactory().getSettings().isCommentsEnabled() ) {
		select.setComment( "load " + getEntityName() );
	}
	return select.addCondition( getIdentifierColumnNames(), "=?" ).toStatementString();
}
 
Example 15
protected String generateSelectSizeString(boolean isIntegerIndexed) {
	String selectValue = isIntegerIndexed ? 
		"max(" + getIndexColumnNames()[0] + ") + 1": //lists, arrays
		"count(" + getElementColumnNames()[0] + ")"; //sets, maps, bags
	return new SimpleSelect(dialect)
			.setTableName( getTableName() )
			.addCondition( getKeyColumnNames(), "=?" )
			.addColumn(selectValue)
			.toStatementString();
}
 
Example 16
protected String generateDetectRowByIndexString() {
	if ( !hasIndex() ) {
		return null;
	}
	return new SimpleSelect(dialect)
			.setTableName( getTableName() )
			.addCondition( getKeyColumnNames(), "=?" )
			.addCondition( getIndexColumnNames(), "=?" )
			.addCondition( indexFormulas, "=?" )
			.addColumn("1")
			.toStatementString();
}
 
Example 17
protected String generateSelectRowByIndexString() {
	if ( !hasIndex() ) {
		return null;
	}
	return new SimpleSelect(dialect)
			.setTableName( getTableName() )
			.addCondition( getKeyColumnNames(), "=?" )
			.addCondition( getIndexColumnNames(), "=?" )
			.addCondition( indexFormulas, "=?" )
			.addColumns( getElementColumnNames(), elementColumnAliases )
			.addColumns( indexFormulas, indexColumnAliases )
			.toStatementString();
}
 
Example 18
protected String generateDetectRowByElementString() {
	return new SimpleSelect(dialect)
			.setTableName( getTableName() )
			.addCondition( getKeyColumnNames(), "=?" )
			.addCondition( getElementColumnNames(), "=?" )
			.addCondition( elementFormulas, "=?" )
			.addColumn("1")
			.toStatementString();
}
 
Example 19
protected String generateLockString() {
	SessionFactoryImplementor factory = lockable.getFactory();
	SimpleSelect select = new SimpleSelect( factory.getDialect() )
			.setLockMode( lockMode )
			.setTableName( lockable.getRootTableName() )
			.addColumn( lockable.getRootTableIdentifierColumnNames()[0] )
			.addCondition( lockable.getRootTableIdentifierColumnNames(), "=?" );
	if ( lockable.isVersioned() ) {
		select.addCondition( lockable.getVersionColumnName(), "=?" );
	}
	if ( factory.getSettings().isCommentsEnabled() ) {
		select.setComment( lockMode + " lock " + lockable.getEntityName() );
	}
	return select.toStatementString();
}