Java Code Examples for org.hibernate.sql.Update#setVersionColumnName()

The following examples show how to use org.hibernate.sql.Update#setVersionColumnName() . 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
Source File: ReactiveAbstractEntityPersister.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
default String generateUpdateLockString(LockOptions lockOptions) {
	final SessionFactoryImplementor factory = getFactory();
	Dialect dialect = factory.getJdbcServices().getDialect();
	final Update update = new Update(dialect);
	update.setTableName( getRootTableName() );
	update.addPrimaryKeyColumns( getRootTableIdentifierColumnNames() );
	update.setVersionColumnName( getVersionColumnName() );
	update.addColumn( getVersionColumnName() );
	if ( factory.getSessionFactoryOptions().isCommentsEnabled() ) {
		update.setComment( lockOptions.getLockMode() + " lock " + getEntityName() );
	}
	return update.toStatementString();
}
 
Example 2
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String generateVersionIncrementUpdateString() {
	Update update = new Update( getFactory().getDialect() );
	update.setTableName( getTableName( 0 ) );
	if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
		update.setComment( "forced version increment" );
	}
	update.addColumn( getVersionColumnName() );
	update.addPrimaryKeyColumns( rootTableKeyColumnNames );
	update.setVersionColumnName( getVersionColumnName() );
	return update.toStatementString();
}
 
Example 3
Source File: UpdateLockingStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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.getSessionFactoryOptions().isCommentsEnabled() ) {
		update.setComment( lockMode + " lock " + lockable.getEntityName() );
	}
	return update.toStatementString();
}
 
Example 4
Source File: PessimisticWriteUpdateLockingStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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.getSessionFactoryOptions().isCommentsEnabled() ) {
		update.setComment( lockMode + " lock " + lockable.getEntityName() );
	}
	return update.toStatementString();
}
 
Example 5
Source File: PessimisticReadUpdateLockingStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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.getSessionFactoryOptions().isCommentsEnabled() ) {
		update.setComment( lockMode + " lock " + lockable.getEntityName() );
	}
	return update.toStatementString();
}
 
Example 6
Source File: AbstractEntityPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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();
}
 
Example 7
Source File: UpdateLockingStrategy.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected String generateLockString() {
	SessionFactoryImplementor factory = lockable.getFactory();
	Update update = new Update( factory.getDialect() );
	update.setTableName( lockable.getRootTableName() );
	update.setPrimaryKeyColumnNames( lockable.getRootTableIdentifierColumnNames() );
	update.setVersionColumnName( lockable.getVersionColumnName() );
	update.addColumn( lockable.getVersionColumnName() );
	if ( factory.getSettings().isCommentsEnabled() ) {
		update.setComment( lockMode + " lock " + lockable.getEntityName() );
	}
	return update.toStatementString();
}
 
Example 8
Source File: AbstractEntityPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Generate the SQL that updates a row by id (and version)
 */
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;
}