use of org.hibernate.LockMode in project hibernate-orm by hibernate.
the class PostgreSQL81Dialect method getForUpdateString.
@Override
public String getForUpdateString(String aliases, LockOptions lockOptions) {
/*
* Parent's implementation for (aliases, lockOptions) ignores aliases.
*/
if ("".equals(aliases)) {
LockMode lockMode = lockOptions.getLockMode();
final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator();
while (itr.hasNext()) {
// seek the highest lock mode
final Map.Entry<String, LockMode> entry = itr.next();
final LockMode lm = entry.getValue();
if (lm.greaterThan(lockMode)) {
aliases = entry.getKey();
}
}
}
LockMode lockMode = lockOptions.getAliasSpecificLockMode(aliases);
if (lockMode == null) {
lockMode = lockOptions.getLockMode();
}
switch(lockMode) {
case UPGRADE:
return getForUpdateString(aliases);
case PESSIMISTIC_READ:
return getReadLockString(aliases, lockOptions.getTimeOut());
case PESSIMISTIC_WRITE:
return getWriteLockString(aliases, lockOptions.getTimeOut());
case UPGRADE_NOWAIT:
case FORCE:
case PESSIMISTIC_FORCE_INCREMENT:
return getForUpdateNowaitString(aliases);
case UPGRADE_SKIPLOCKED:
return getForUpdateSkipLockedString(aliases);
default:
return "";
}
}
use of org.hibernate.LockMode in project hibernate-orm by hibernate.
the class Dialect method getForUpdateString.
/**
* Get the <tt>FOR UPDATE OF column_list</tt> fragment appropriate for this
* dialect given the aliases of the columns to be write locked.
*
* @param aliases The columns to be write locked.
* @param lockOptions the lock options to apply
* @return The appropriate <tt>FOR UPDATE OF column_list</tt> clause string.
*/
@SuppressWarnings({ "unchecked", "UnusedParameters" })
public String getForUpdateString(String aliases, LockOptions lockOptions) {
LockMode lockMode = lockOptions.getLockMode();
final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator();
while (itr.hasNext()) {
// seek the highest lock mode
final Map.Entry<String, LockMode> entry = itr.next();
final LockMode lm = entry.getValue();
if (lm.greaterThan(lockMode)) {
lockMode = lm;
}
}
lockOptions.setLockMode(lockMode);
return getForUpdateString(lockOptions);
}
use of org.hibernate.LockMode in project hibernate-orm by hibernate.
the class AbstractHANADialect method getForUpdateString.
@Override
public String getForUpdateString(final String aliases, final LockOptions lockOptions) {
LockMode lockMode = lockOptions.findGreatestLockMode();
lockOptions.setLockMode(lockMode);
// not sure why this is sometimes empty
if (aliases == null || aliases.isEmpty()) {
return getForUpdateString(lockOptions);
}
return getForUpdateString(aliases, lockMode, lockOptions.getTimeOut());
}
use of org.hibernate.LockMode in project hibernate-orm by hibernate.
the class SQLServer2005Dialect method appendLockHint.
@Override
public String appendLockHint(LockOptions lockOptions, String tableName) {
LockMode lockMode = lockOptions.getAliasSpecificLockMode(tableName);
if (lockMode == null) {
lockMode = lockOptions.getLockMode();
}
final String writeLockStr = lockOptions.getTimeOut() == LockOptions.SKIP_LOCKED ? "updlock" : "updlock, holdlock";
final String readLockStr = lockOptions.getTimeOut() == LockOptions.SKIP_LOCKED ? "updlock" : "holdlock";
final String noWaitStr = lockOptions.getTimeOut() == LockOptions.NO_WAIT ? ", nowait" : "";
final String skipLockStr = lockOptions.getTimeOut() == LockOptions.SKIP_LOCKED ? ", readpast" : "";
switch(lockMode) {
case UPGRADE:
case PESSIMISTIC_WRITE:
case WRITE:
{
return tableName + " with (" + writeLockStr + ", rowlock" + noWaitStr + skipLockStr + ")";
}
case PESSIMISTIC_READ:
{
return tableName + " with (" + readLockStr + ", rowlock" + noWaitStr + skipLockStr + ")";
}
case UPGRADE_SKIPLOCKED:
return tableName + " with (updlock, rowlock, readpast" + noWaitStr + ")";
case UPGRADE_NOWAIT:
return tableName + " with (updlock, holdlock, rowlock, nowait)";
default:
{
return tableName;
}
}
}
use of org.hibernate.LockMode in project hibernate-orm by hibernate.
the class Loader method instanceNotYetLoaded.
/**
* The entity instance is not in the session cache
*/
private Object instanceNotYetLoaded(final ResultSet rs, final int i, final Loadable persister, final String rowIdAlias, final EntityKey key, final LockMode lockMode, final EntityKey optionalObjectKey, final Object optionalObject, final List hydratedObjects, final SharedSessionContractImplementor session) throws HibernateException, SQLException {
final String instanceClass = getInstanceClass(rs, i, persister, key.getIdentifier(), session);
// see if the entity defines reference caching, and if so use the cached reference (if one).
if (session.getCacheMode().isGetEnabled() && persister.canUseReferenceCacheEntries()) {
final EntityDataAccess cache = persister.getCacheAccessStrategy();
final Object ck = cache.generateCacheKey(key.getIdentifier(), persister, session.getFactory(), session.getTenantIdentifier());
final Object cachedEntry = CacheHelper.fromSharedCache(session, ck, cache);
if (cachedEntry != null) {
CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure().destructure(cachedEntry, factory);
return ((ReferenceCacheEntryImpl) entry).getReference();
}
}
final Object object;
if (optionalObjectKey != null && key.equals(optionalObjectKey)) {
// its the given optional object
object = optionalObject;
} else {
// instantiate a new instance
object = session.instantiate(instanceClass, key.getIdentifier());
}
// need to hydrate it.
// grab its state from the ResultSet and keep it in the Session
// (but don't yet initialize the object itself)
// note that we acquire LockMode.READ even if it was not requested
LockMode acquiredLockMode = lockMode == LockMode.NONE ? LockMode.READ : lockMode;
loadFromResultSet(rs, i, object, instanceClass, key, rowIdAlias, acquiredLockMode, persister, session);
// materialize associations (and initialize the object) later
hydratedObjects.add(object);
return object;
}
Aggregations