private void checkOptimisticLockingState()

in core/src/main/java/org/hibernate/ogm/persister/impl/OgmEntityPersister.java [1627:1662]


	private void checkOptimisticLockingState(Serializable id, EntityKey key, Object object, Object[] loadedState, Object version,
			SharedSessionContractImplementor session, Tuple resultset) {
		int tableSpan = getTableSpan();
		EntityMetamodel entityMetamodel = getEntityMetamodel();

		boolean isImpliedOptimisticLocking = !entityMetamodel.isVersioned() && isAllOrDirtyOptLocking();

		// Compare all the columns against their current state in the datastore
		if ( isImpliedOptimisticLocking && loadedState != null ) {
			// we need to utilize dynamic delete statements
			for ( int j = tableSpan - 1; j >= 0; j-- ) {
				boolean[] versionability = getPropertyVersionability();

				//TODO do a diff on the properties value from resultset
				GridType[] types = gridPropertyTypes;

				for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) {
					boolean include = isPropertyOfTable( i, j ) && versionability[i];
					if ( include ) {
						final GridType type = types[i];
						final Object snapshotValue = type.nullSafeGet(
								resultset, getPropertyColumnNames( i ), session, object
						);
						//TODO support other entity modes
						if ( ! type.isEqual( loadedState[i], snapshotValue, getFactory() ) ) {
							raiseStaleObjectStateException( id );
						}
					}
				}
			}
		}
		// compare the version column only
		else if ( entityMetamodel.isVersioned() ) {
			checkVersionAndRaiseSOSE( id, version, session, resultset );
		}
	}