/** * 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(); }
.append( toWhereClause() );
public SimpleSelect addCondition(String lhs, String condition) { and(); whereTokens.add( lhs + ' ' + condition ); return this; }
protected String generateDetectRowByElementString() { return new SimpleSelect( dialect ) .setTableName( getTableName() ) .addCondition( getKeyColumnNames(), "=?" ) .addCondition( getElementColumnNames(), "=?" ) .addCondition( elementFormulas, "=?" ) .addWhereToken( sqlWhereString ) .addColumn( "1" ) .toStatementString(); }
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(); } }
public SimpleSelect addColumns(String[] columns, String[] aliases, boolean[] ignore) { for ( int i = 0; i < ignore.length; i++ ) { if ( !ignore[i] && columns[i] != null ) { addColumn( columns[i], aliases[i] ); } } return this; }
public SimpleSelect addCondition(String[] lhs, String condition) { for ( String lh : lhs ) { if ( lh != null ) { addCondition( lh, condition ); } } return this; }
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(); } }
protected String generateDetectRowByIndexString() { if ( !hasIndex() ) { return null; } return new SimpleSelect( dialect ) .setTableName( getTableName() ) .addCondition( getKeyColumnNames(), "=?" ) .addCondition( getIndexColumnNames(), "=?" ) .addCondition( indexFormulas, "=?" ) .addWhereToken( sqlWhereString ) .addColumn( "1" ) .toStatementString(); }
public SimpleSelect addColumns(String[] columnNames) { for ( String columnName : columnNames ) { if ( columnName != null ) { addColumn( columnName ); } } return this; }
public SimpleSelect addCondition(String[] lhs, String op, String[] rhs) { for ( int i = 0; i < lhs.length; i++ ) { addCondition( lhs[i], op, rhs[i] ); } return this; }
SimpleSelect select = new SimpleSelect( getFactory().getDialect() ) .setLockMode( lockMode ) .setTableName( getTableName() ) .addColumns( getIdentifierColumnNames() ) .addColumns( getSubclassColumnClosure(), getSubclassColumnAliasClosure(), getSubclassColumnLazyiness() .addColumns( getSubclassFormulaClosure(), getSubclassFormulaAliasClosure(), select.addColumn( getDiscriminatorFormula(), getDiscriminatorAlias() ); select.addColumn( getDiscriminatorColumnName(), getDiscriminatorAlias() ); select.setComment( "load " + getEntityName() ); return select.addCondition( getIdentifierColumnNames(), "=?" ).toStatementString();
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(); } }
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(); }
public SimpleSelect addColumns(String[] columnNames, String[] columnAliases) { for ( int i = 0; i < columnNames.length; i++ ) { if ( columnNames[i] != null ) { addColumn( columnNames[i], columnAliases[i] ); } } return this; }
public SimpleSelect addCondition(String[] lhs, String op, String[] rhs) { for ( int i=0; i<lhs.length; i++ ) { addCondition( lhs[i], op, rhs[i] ); } return this; }
public SimpleSelect addCondition(String lhs, String op, String rhs) { and(); whereTokens.add( lhs + ' ' + op + ' ' + rhs ); return this; }
/** * Generate the SQL that pessimistic locks a row by id (and version) */ protected String generateLockString(LockMode lockMode) { SimpleSelect select = new SimpleSelect( getFactory().getDialect() ) .setLockMode( lockMode ) .setTableName( getVersionedTableName() ) .addColumn( rootTableKeyColumnNames[0] ) .addCondition( rootTableKeyColumnNames, "=?" ); if ( isVersioned() ) { select.addWhereToken( "and" ) .addCondition( getVersionColumnName(), "=?" ); } if ( getFactory().getSettings().isCommentsEnabled() ) { select.setComment( "lock " + getEntityName() ); } return select.toStatementString(); }
protected String generateLockString(int lockTimeout) { SessionFactoryImplementor factory = getLockable().getFactory(); LockOptions lockOptions = new LockOptions( getLockMode() ); lockOptions.setTimeOut( lockTimeout ); 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.getSettings().isCommentsEnabled() ) { select.setComment( getLockMode() + " lock " + getLockable().getEntityName() ); } return select.toStatementString(); } }