congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
TimestampLockingPolicy
Code IndexAdd Tabnine to your IDE (free)

How to use
TimestampLockingPolicy
in
org.eclipse.persistence.descriptors

Best Java code snippets using org.eclipse.persistence.descriptors.TimestampLockingPolicy (Showing top 20 results out of 315)

origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * PUBLIC:
 * Set the locking policy to use timestamp version locking.
 * This updates the timestamp field on all updates, first comparing that the field has not changed to detect locking conflicts.
 * Note: many database have limited precision of timestamps which can be an issue is highly concurrent systems.
 *
 * The parameter 'shouldStoreInCache' configures the version lock value to be stored in the cache or in the object.
 * Note: if using a stateless model where the object can be passed to a client and then later updated in a different transaction context,
 * then the version lock value should not be stored in the cache, but in the object to ensure it is the correct value for that object.
 * @see VersionLockingPolicy
 */
public void useTimestampLocking(String writeLockFieldName, boolean shouldStoreInCache) {
  TimestampLockingPolicy policy = new TimestampLockingPolicy(writeLockFieldName);
  if (shouldStoreInCache) {
    policy.storeInCache();
  } else {
    policy.storeInObject();
  }
  setOptimisticLockingPolicy(policy);
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * INTERNAL:
 * Compares the value with the value from the object (or cache).
 * Will return true if the currentValue is newer than the domainObject.
 */
public boolean isNewerVersion(Object currentValue, Object domainObject, java.util.Vector primaryKey, AbstractSession session) {
  java.sql.Timestamp writeLockFieldValue;
  java.sql.Timestamp newWriteLockFieldValue = (java.sql.Timestamp)currentValue;
  if (isStoredInCache()) {
    writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessorInstance().getWriteLockValue(primaryKey, domainObject.getClass(), getDescriptor());
  } else {
    writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject);
  }
  return isNewerVersion(newWriteLockFieldValue, writeLockFieldValue);
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * INTERNAL:
 * Returns the new Timestamp value.
 */
public Object getNewLockValue(ModifyQuery query) {
  return getInitialWriteValue(query.getSession());
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * PUBLIC:
 * Set if policy uses server time.
 */
public void setUsesServerTime(boolean usesServerTime) {
  if (usesServerTime) {
    useServerTime();
  } else {
    useLocalTime();
  }
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * INTERNAL:
 * This method will return the optimistic lock value for the object
 */
public Object getWriteLockValue(Object domainObject, java.util.Vector primaryKey, AbstractSession session) {
  java.sql.Timestamp writeLockFieldValue = null;
  if (isStoredInCache()) {
    writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessorInstance().getWriteLockValue(primaryKey, domainObject.getClass(), getDescriptor());
  } else {
    //CR#2281 notStoredInCache prevent ClassCastException
    Object lockValue = lockValueFromObject(domainObject);
    if (lockValue != null) {
      if (lockValue instanceof java.sql.Timestamp) {
        writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject);
      } else {
        throw OptimisticLockException.needToMapJavaSqlTimestampWhenStoredInObject();
      }
    }
  }
  return writeLockFieldValue;
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * INTERNAL:
 * returns the initial locking value
 */
protected Object getInitialWriteValue(AbstractSession session) {
  if (usesLocalTime()) {
    return new Timestamp(System.currentTimeMillis());
  }
  if (usesServerTime()) {
    AbstractSession readSession = session.getSessionForClass(getDescriptor().getJavaClass());
    while (readSession.isUnitOfWork()) {
      readSession = ((UnitOfWorkImpl)readSession).getParent().getSessionForClass(getDescriptor().getJavaClass());
    }
    return readSession.getDatasourceLogin().getDatasourcePlatform().getTimestampFromServer(session, readSession.getName());
  }
  return null;
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * INTERNAL:
 * Return the value that should be stored in the identity map.  If the value
 * is stored in the object, then return a null.
 */
public Object getValueToPutInCache(AbstractRecord row, AbstractSession session) {
  if (isStoredInCache()) {
    return session.getDatasourcePlatform().convertObject(row.get(getWriteLockField()), ClassConstants.TIMESTAMP);
  } else {
    return null;
  }
}
origin: com.haulmont.thirdparty/eclipselink

  /**
   * INTERNAL:
   * Process a version accessor.
   */
  @Override
  public void process() {
    // This will initialize the m_field variable. Accessible through getField().
    super.process();
    
    // Process an @Version or version element if there is one.
    if (getDescriptor().usesOptimisticLocking()) {
      // Ignore the version locking if it is already set.
      getLogger().logConfigMessage(MetadataLogger.IGNORE_VERSION_LOCKING, this);
    } else {
      MetadataClass lockType = getRawClass();
      getDatabaseField().setTypeName(getJavaClassName(lockType));

      if (isValidVersionLockingType(lockType) || isValidTimestampVersionLockingType(lockType)) {
        for (MetadataDescriptor owningDescriptor : getOwningDescriptors()) {
          VersionLockingPolicy policy = isValidVersionLockingType(lockType) ? new VersionLockingPolicy(getDatabaseField()) : new TimestampLockingPolicy(getDatabaseField());  
          policy.storeInObject();
          policy.setIsCascaded(getDescriptor().usesCascadedOptimisticLocking());
          owningDescriptor.setOptimisticLockingPolicy(policy);
        }
      } else {
        throw ValidationException.invalidTypeForVersionAttribute(getAttributeName(), lockType, getJavaClass());
      }
    }
  }
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * INTERNAL:
 * This method will return the optimistic lock value for the object.
 */
@Override
public Object getWriteLockValue(Object domainObject, Object primaryKey, AbstractSession session) {
  java.sql.Timestamp writeLockFieldValue = null;
  if (isStoredInCache()) {
    writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessorInstance().getWriteLockValue(primaryKey, domainObject.getClass(), getDescriptor());
  } else {
    //CR#2281 notStoredInCache prevent ClassCastException
    Object lockValue = lockValueFromObject(domainObject);
    if (lockValue != null) {
      if (lockValue instanceof java.sql.Timestamp) {
        writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject);
      } else {
        throw OptimisticLockException.needToMapJavaSqlTimestampWhenStoredInObject();
      }
    }
  }
  return writeLockFieldValue;
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * INTERNAL:
 * returns the initial locking value
 */
protected Object getInitialWriteValue(AbstractSession session) {
  if (usesLocalTime()) {
    return new Timestamp(System.currentTimeMillis());
  }
  if (usesServerTime()) {
    AbstractSession readSession = session.getSessionForClass(getDescriptor().getJavaClass());
    while (readSession.isUnitOfWork()) {
      readSession = ((UnitOfWorkImpl)readSession).getParent().getSessionForClass(getDescriptor().getJavaClass());
    }
    return readSession.getDatasourceLogin().getDatasourcePlatform().getTimestampFromServer(session, readSession.getName());
  }
  return null;
}
origin: com.haulmont.thirdparty/eclipselink

/**
 * PUBLIC:
 * Set if policy uses server time.
 */
public void setUsesServerTime(boolean usesServerTime) {
  if (usesServerTime) {
    useServerTime();
  } else {
    useLocalTime();
  }
}
origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

/**
 * INTERNAL:
 * Return the value that should be stored in the identity map.  If the value
 * is stored in the object, then return a null.
 */
public Object getValueToPutInCache(AbstractRecord row, AbstractSession session) {
  if (isStoredInCache()) {
    return session.getDatasourcePlatform().convertObject(row.get(getWriteLockField()), ClassConstants.TIMESTAMP);
  } else {
    return null;
  }
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * INTERNAL:
 * Compares the value with the value from the object (or cache).
 * Will return true if the currentValue is newer than the domainObject.
 */
@Override
public boolean isNewerVersion(Object currentValue, Object domainObject, Object primaryKey, AbstractSession session) {
  java.sql.Timestamp writeLockFieldValue;
  java.sql.Timestamp newWriteLockFieldValue = (java.sql.Timestamp)currentValue;
  if (isStoredInCache()) {
    writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessorInstance().getWriteLockValue(primaryKey, domainObject.getClass(), getDescriptor());
  } else {
    writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject);
  }
  return isNewerVersion(newWriteLockFieldValue, writeLockFieldValue);
}
origin: com.haulmont.thirdparty/eclipselink

/**
 * INTERNAL:
 * This method will return the optimistic lock value for the object.
 */
@Override
public Object getWriteLockValue(Object domainObject, Object primaryKey, AbstractSession session) {
  java.sql.Timestamp writeLockFieldValue = null;
  if (isStoredInCache()) {
    writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessorInstance().getWriteLockValue(primaryKey, domainObject.getClass(), getDescriptor());
  } else {
    //CR#2281 notStoredInCache prevent ClassCastException
    Object lockValue = lockValueFromObject(domainObject);
    if (lockValue != null) {
      if (lockValue instanceof java.sql.Timestamp) {
        writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject);
      } else {
        throw OptimisticLockException.needToMapJavaSqlTimestampWhenStoredInObject();
      }
    }
  }
  return writeLockFieldValue;
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * PUBLIC:
 * Set the locking policy to use timestamp version locking.
 * This updates the timestamp field on all updates, first comparing that the field has not changed to detect locking conflicts.
 * Note: many database have limited precision of timestamps which can be an issue is highly concurrent systems.
 *
 * The parameter 'shouldStoreInCache' configures the version lock value to be stored in the cache or in the object.
 * Note: if using a stateless model where the object can be passed to a client and then later updated in a different transaction context,
 * then the version lock value should not be stored in the cache, but in the object to ensure it is the correct value for that object.
 * @see VersionLockingPolicy
 */
public void useTimestampLocking(String writeLockFieldName, boolean shouldStoreInCache) {
  TimestampLockingPolicy policy = new TimestampLockingPolicy(writeLockFieldName);
  if (shouldStoreInCache) {
    policy.storeInCache();
  } else {
    policy.storeInObject();
  }
  setOptimisticLockingPolicy(policy);
}
origin: com.haulmont.thirdparty/eclipselink

/**
 * INTERNAL:
 * returns the initial locking value
 */
protected Object getInitialWriteValue(AbstractSession session) {
  if (usesLocalTime()) {
    return new Timestamp(System.currentTimeMillis());
  }
  if (usesServerTime()) {
    AbstractSession readSession = session.getSessionForClass(getDescriptor().getJavaClass());
    while (readSession.isUnitOfWork()) {
      readSession = ((UnitOfWorkImpl)readSession).getParent().getSessionForClass(getDescriptor().getJavaClass());
    }
    return readSession.getDatasourceLogin().getDatasourcePlatform().getTimestampFromServer(session, readSession.getName());
  }
  return null;
}
origin: org.eclipse.persistence/org.eclipse.persistence.core

/**
 * PUBLIC:
 * Set if policy uses server time.
 */
public void setUsesServerTime(boolean usesServerTime) {
  if (usesServerTime) {
    useServerTime();
  } else {
    useLocalTime();
  }
}
origin: com.haulmont.thirdparty/eclipselink

/**
 * INTERNAL:
 * Return the value that should be stored in the identity map.  If the value
 * is stored in the object, then return a null.
 */
public Object getValueToPutInCache(AbstractRecord row, AbstractSession session) {
  if (isStoredInCache()) {
    return session.getDatasourcePlatform().convertObject(row.get(getWriteLockField()), ClassConstants.TIMESTAMP);
  } else {
    return null;
  }
}
origin: com.haulmont.thirdparty/eclipselink

/**
 * INTERNAL:
 * Returns the new Timestamp value.
 */
public Object getNewLockValue(ModifyQuery query) {
  return getInitialWriteValue(query.getSession());
}
origin: com.haulmont.thirdparty/eclipselink

/**
 * INTERNAL:
 * Compares the value with the value from the object (or cache).
 * Will return true if the currentValue is newer than the domainObject.
 */
@Override
public boolean isNewerVersion(Object currentValue, Object domainObject, Object primaryKey, AbstractSession session) {
  java.sql.Timestamp writeLockFieldValue;
  java.sql.Timestamp newWriteLockFieldValue = (java.sql.Timestamp)currentValue;
  if (isStoredInCache()) {
    writeLockFieldValue = (java.sql.Timestamp)session.getIdentityMapAccessorInstance().getWriteLockValue(primaryKey, domainObject.getClass(), getDescriptor());
  } else {
    writeLockFieldValue = (java.sql.Timestamp)lockValueFromObject(domainObject);
  }
  return isNewerVersion(newWriteLockFieldValue, writeLockFieldValue);
}
org.eclipse.persistence.descriptorsTimestampLockingPolicy

Javadoc

Purpose: Used to allow a single version timestamp to be used for optimistic locking.

Most used methods

  • <init>
    INTERNAL: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server.
  • getDescriptor
  • getInitialWriteValue
    INTERNAL: returns the initial locking value
  • getWriteLockField
  • isNewerVersion
    INTERNAL: Compares the value from the row and from the object (or cache). Will return true if the ro
  • isStoredInCache
  • lockValueFromObject
  • storeInCache
  • storeInObject
  • useLocalTime
    PUBLIC: set this policy to get the time from the local machine.
  • useServerTime
    PUBLIC: set this policy to get the time from the server.
  • usesLocalTime
    PUBLIC: Return true if policy uses local time.
  • useServerTime,
  • usesLocalTime,
  • usesServerTime

Popular in Java

  • Making http requests using okhttp
  • setContentView (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • setRequestProperty (URLConnection)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • 21 Best IntelliJ Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now