예제 #1
0
 /**
  * Generate the next increment in the optimistic locking value according the {@link VersionType}
  * contract for the version property.
  *
  * @param version The current version
  * @param versionType The version type
  * @param session The originating session
  * @return The incremented optimistic locking value.
  */
 @SuppressWarnings("unchecked")
 public static Object increment(
     Object version, VersionType versionType, SharedSessionContractImplementor session) {
   final Object next = versionType.next(version, session);
   if (LOG.isTraceEnabled()) {
     LOG.tracef(
         "Incrementing: %s to %s",
         versionType.toLoggableString(version, session.getFactory()),
         versionType.toLoggableString(next, session.getFactory()));
   }
   return next;
 }
 /**
  * Build a loggable representation of the paths tracked here at the moment.
  *
  * @param session The session (used to resolve entity names)
  * @return The loggable representation
  */
 public String toLoggableString(SharedSessionContractImplementor session) {
   final StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('[');
   if (propertyPathsByTransientEntity != null) {
     for (Map.Entry<Object, Set<String>> entry : propertyPathsByTransientEntity.entrySet()) {
       sb.append("transientEntityName=").append(session.bestGuessEntityName(entry.getKey()));
       sb.append(" requiredBy=").append(entry.getValue());
     }
   }
   sb.append(']');
   return sb.toString();
 }
 @Override
 public void lock(
     Serializable id,
     Object version,
     Object object,
     int timeout,
     SharedSessionContractImplementor session) {
   if (!lockable.isVersioned()) {
     throw new HibernateException(
         "["
             + lockMode
             + "] not supported for non-versioned entities ["
             + lockable.getEntityName()
             + "]");
   }
   final EntityEntry entry = session.getPersistenceContext().getEntry(object);
   // Register the EntityIncrementVersionProcess action to run just prior to transaction commit.
   ((EventSource) session)
       .getActionQueue()
       .registerProcess(new EntityIncrementVersionProcess(object, entry));
 }