Package org.hibernate.sql

Examples of org.hibernate.sql.Update


      final String revEndColumnName = rootAuditedEntityQueryable.toColumns( auditCfg.getAuditEntCfg().getRevisionEndFieldName() )[0];

      final boolean isRevisionEndTimestampEnabled = auditCfg.getAuditEntCfg().isRevisionEndTimestampEnabled();

      // update audit_ent set REVEND = ? [, REVEND_TSTMP = ?] where (prod_ent_id) = ? and REV <> ? and REVEND is null
      final Update update = new Update( dialect ).setTableName( updateTableName );
      // set REVEND = ?
      update.addColumn( revEndColumnName );
      // set [, REVEND_TSTMP = ?]
      if ( isRevisionEndTimestampEnabled ) {
        update.addColumn(
            rootAuditedEntityQueryable.toColumns(
                auditCfg.getAuditEntCfg().getRevisionEndTimestampFieldName()
            )[0]
        );
      }

      // where (prod_ent_id) = ?
      update.addPrimaryKeyColumns( rootProductionEntityQueryable.getIdentifierColumnNames() );
      // where REV <> ?
      update.addWhereColumn(
          rootAuditedEntityQueryable.toColumns(
              auditCfg.getAuditEntCfg().getRevisionNumberPath()
          )[0],
          "<> ?"
      );
      // where REVEND is null
      update.addWhereColumn( revEndColumnName, " is null" );

      // Now lets execute the sql...
      final String updateSql = update.toStatementString();

      int rowCount = session.doReturningWork(
          new ReturningWork<Integer>() {
            @Override
            public Integer execute(Connection connection) throws SQLException {
View Full Code Here


    }
  }

  protected String generateLockString() {
    SessionFactoryImplementor factory = lockable.getFactory();
    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();
  }
View Full Code Here

    }
  }

  protected String generateLockString() {
    SessionFactoryImplementor factory = lockable.getFactory();
    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();
  }
View Full Code Here

    return nextVersion;
  }

  private String generateVersionIncrementUpdateString() {
    Update update = new Update( getFactory().getDialect() );
    update.setTableName( getTableName( 0 ) );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      update.setComment( "forced version increment" );
    }
    update.addColumn( getVersionColumnName() );
    update.setPrimaryKeyColumnNames( getIdentifierColumnNames() );
    update.setVersionColumnName( getVersionColumnName() );
    return update.toStatementString();
  }
View Full Code Here

  protected String generateUpdateString(final boolean[] includeProperty,
                      final int j,
                      final Object[] oldFields,
                      final boolean useRowId) {

    Update update = new Update( getFactory().getDialect() ).setTableName( getTableName( j ) );

    // select the correct row by either pk or rowid
    if ( useRowId ) {
      update.setPrimaryKeyColumnNames( new String[]{rowIdName} ); //TODO: eventually, rowIdName[j]
    }
    else {
      update.setPrimaryKeyColumnNames( getKeyColumns( j ) );
    }

    boolean hasColumns = false;
    for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) {
      if ( includeProperty[i] && isPropertyOfTable( i, j ) ) {
        // this is a property of the table, which we are updating
        update.addColumns( getPropertyColumnNames(i), propertyColumnUpdateable[i] );
        hasColumns = hasColumns || getPropertyColumnSpan( i ) > 0;
      }
    }

    if ( j == 0 && isVersioned() && entityMetamodel.getOptimisticLockMode() == Versioning.OPTIMISTIC_LOCK_VERSION ) {
      // this is the root (versioned) table, and we are using version-based
      // optimistic locking;  if we are not updating the version, also don't
      // check it (unless this is a "generated" version column)!
      if ( checkVersion( includeProperty ) ) {
        update.setVersionColumnName( getVersionColumnName() );
        hasColumns = true;
      }
    }
    else if ( entityMetamodel.getOptimisticLockMode() > Versioning.OPTIMISTIC_LOCK_VERSION && oldFields != null ) {
      // we are using "all" or "dirty" property-based optimistic locking

      boolean[] includeInWhere = entityMetamodel.getOptimisticLockMode() == Versioning.OPTIMISTIC_LOCK_ALL ?
          getPropertyUpdateability() : //optimistic-lock="all", include all updatable properties
          includeProperty; //optimistic-lock="dirty", include all properties we are updating this time

      boolean[] versionability = getPropertyVersionability();
      Type[] types = getPropertyTypes();
      for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) {
        boolean include = includeInWhere[i] &&
            isPropertyOfTable( i, j ) &&
            versionability[i];
        if ( include ) {
          // this property belongs to the table, and it is not specifically
          // excluded from optimistic locking by optimistic-lock="false"
          String[] propertyColumnNames = getPropertyColumnNames( i );
          boolean[] propertyNullness = types[i].toColumnNullness( oldFields[i], getFactory() );
          for ( int k=0; k<propertyNullness.length; k++ ) {
            if ( propertyNullness[k] ) {
              update.addWhereColumn( propertyColumnNames[k] );
            }
            else {
              update.addWhereColumn( propertyColumnNames[k], " is null" );
            }
          }
        }
      }

    }

    if ( getFactory().getSettings().isCommentsEnabled() ) {
      update.setComment( "update " + getEntityName() );
    }

    return hasColumns ? update.toStatementString() : null;
  }
View Full Code Here

  /**
   * Generate the SQL UPDATE that updates all the foreign keys to null
   */
  protected String generateDeleteString() {
   
    Update update = new Update( getDialect() )
        .setTableName( qualifiedTableName )
        .addColumns( keyColumnNames, "null" )
        .setPrimaryKeyColumnNames( keyColumnNames );
   
    if ( hasIndex && !indexContainsFormula ) update.addColumns( indexColumnNames, "null" );
   
    if ( hasWhere ) update.setWhere( sqlWhereString );
   
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      update.setComment( "delete one-to-many " + getRole() );
    }
   
    return update.toStatementString();
  }
View Full Code Here

  /**
   * Generate the SQL UPDATE that updates a foreign key to a value
   */
  protected String generateInsertRowString() {
   
    Update update = new Update( getDialect() )
        .setTableName( qualifiedTableName )
        .addColumns( keyColumnNames );
   
    if ( hasIndex && !indexContainsFormula ) update.addColumns( indexColumnNames );
   
    //identifier collections not supported for 1-to-many
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      update.setComment( "create one-to-many row " + getRole() );
    }
   
    return update.setPrimaryKeyColumnNames( elementColumnNames )
        .toStatementString();
  }
View Full Code Here

   * Generate the SQL UPDATE that updates a particular row's foreign
   * key to null
   */
  protected String generateDeleteRowString() {
   
    Update update = new Update( getDialect() )
        .setTableName( qualifiedTableName )
        .addColumns( keyColumnNames, "null" );
   
    if ( hasIndex && !indexContainsFormula ) update.addColumns( indexColumnNames, "null" );
   
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      update.setComment( "delete one-to-many row " + getRole() );
    }
   
    //use a combination of foreign key columns and pk columns, since
    //the ordering of removal and addition is not guaranteed when
    //a child moves from one parent to another
    String[] rowSelectColumnNames = ArrayHelper.join(keyColumnNames, elementColumnNames);
    return update.setPrimaryKeyColumnNames( rowSelectColumnNames )
        .toStatementString();
  }
View Full Code Here

  /**
   * Generate the SQL UPDATE that updates a row
   */
  protected String generateUpdateRowString() {
   
    Update update = new Update( getDialect() )
      .setTableName( qualifiedTableName );
   
    //if ( !elementIsFormula ) {
      update.addColumns( elementColumnNames, elementColumnIsSettable );
    //}
   
    if ( hasIdentifier ) {
      update.setPrimaryKeyColumnNames( new String[]{ identifierColumnName } );
    }
    else if ( hasIndex && !indexContainsFormula ) {
      update.setPrimaryKeyColumnNames( ArrayHelper.join( keyColumnNames, indexColumnNames ) );
    }
    else {
      update.setPrimaryKeyColumnNames( ArrayHelper.join( keyColumnNames, elementColumnNames, elementColumnIsInPrimaryKey ) );
    }
   
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      update.setComment( "update collection row " + getRole() );
    }
   
    return update.toStatementString();
  }
View Full Code Here

    return nextVersion;
  }

  private String generateVersionIncrementUpdateString() {
    Update update = new Update( getFactory().getDialect() );
    update.setTableName( getTableName( 0 ) );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
      update.setComment( "forced version increment" );
    }
    update.addColumn( getVersionColumnName() );
    update.addPrimaryKeyColumns( getIdentifierColumnNames() );
    update.setVersionColumnName( getVersionColumnName() );
    return update.toStatementString();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.sql.Update

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.