public void forceLocked(Object entity, Object nextVersion) { version = nextVersion; loadedState[persister.getVersionProperty()] = version; //noinspection deprecation setLockMode(LockMode.FORCE); // TODO: use LockMode.PESSIMISTIC_FORCE_INCREMENT persister.setPropertyValue(entity, getPersister().getVersionProperty(), nextVersion); }
/** * Perform any property value substitution that is necessary (interceptor callback, version * initialization...) * * @param entity The entity * @param id The entity identifier * @param values The snapshot entity state * @param persister The entity persister * @param source The originating session * @return True if the snapshot state changed such that reinjection of the values into the entity * is required. */ protected boolean substituteValuesIfNecessary( Object entity, Serializable id, Object[] values, EntityPersister persister, SessionImplementor source) { boolean substitute = source .getInterceptor() .onSave(entity, id, values, persister.getPropertyNames(), persister.getPropertyTypes()); // keep the existing version number in the case of replicate! if (persister.isVersioned()) { substitute = Versioning.seedVersion( values, persister.getVersionProperty(), persister.getVersionType(), source) || substitute; } return substitute; }
/** * Extract the optimistic locking value out of the entity state snapshot. * * @param fields The state snapshot * @param persister The entity persister * @return The extracted optimistic locking value */ public static Object getVersion(Object[] fields, EntityPersister persister) { if (!persister.isVersioned()) { return null; } return fields[persister.getVersionProperty()]; }
/** * Inject the optimistic locking value into the entity state snapshot. * * @param fields The state snapshot * @param version The optimistic locking value * @param persister The entity persister */ public static void setVersion(Object[] fields, Object version, EntityPersister persister) { if (!persister.isVersioned()) { return; } fields[persister.getVersionProperty()] = version; }
/** Get the version number of the given instance state snapshot */ public static Object getVersion(Object[] fields, EntityPersister persister) throws HibernateException { return persister.isVersioned() ? getVersion(fields, persister.getVersionProperty()) : null; }
/** Set the version number of the given instance state snapshot */ public static void setVersion(Object[] fields, Object version, EntityPersister persister) { setVersion(fields, version, persister.getVersionProperty()); }