本文整理匯總了Java中org.hibernate.LockMode.NONE屬性的典型用法代碼示例。如果您正苦於以下問題:Java LockMode.NONE屬性的具體用法?Java LockMode.NONE怎麽用?Java LockMode.NONE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.hibernate.LockMode
的用法示例。
在下文中一共展示了LockMode.NONE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: byKey
public CollectionLoader byKey() {
final QueryBuildingParameters buildingParameters = new QueryBuildingParameters() {
@Override
public LoadQueryInfluencers getQueryInfluencers() {
return influencers;
}
@Override
public int getBatchSize() {
return batchSize;
}
@Override
public LockMode getLockMode() {
return LockMode.NONE;
}
@Override
public LockOptions getLockOptions() {
return null;
}
};
return new CollectionLoader( collectionPersister, buildingParameters ) ;
}
示例2: createUniqueKeyLoader
private EntityLoader createUniqueKeyLoader(
Type uniqueKeyType,
String[] columns,
LoadQueryInfluencers loadQueryInfluencers) {
if ( uniqueKeyType.isEntityType() ) {
String className = ( ( EntityType ) uniqueKeyType ).getAssociatedEntityName();
uniqueKeyType = getFactory().getEntityPersister( className ).getIdentifierType();
}
return new EntityLoader(
this,
columns,
uniqueKeyType,
1,
LockMode.NONE,
getFactory(),
loadQueryInfluencers
);
}
示例3: cascade
@Override
public void cascade(
EventSource session,
Object child,
String entityName,
Object anything,
boolean isCascadeDeleteEnabled) {
LOG.tracev( "Cascading to lock: {0}", entityName );
LockMode lockMode = LockMode.NONE;
LockOptions lr = new LockOptions();
if ( anything instanceof LockOptions ) {
LockOptions lockOptions = (LockOptions) anything;
lr.setTimeOut( lockOptions.getTimeOut() );
lr.setScope( lockOptions.getScope() );
if ( lockOptions.getScope() ) {
lockMode = lockOptions.getLockMode();
}
}
lr.setLockMode( lockMode );
session.buildLockRequest( lr ).lock( entityName, child );
}
示例4: getCurrentLockMode
@Override
public LockMode getCurrentLockMode(Object object) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
if ( object == null ) {
throw new NullPointerException( "null object passed to getCurrentLockMode()" );
}
if ( object instanceof HibernateProxy ) {
object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation(this);
if ( object == null ) {
return LockMode.NONE;
}
}
EntityEntry e = persistenceContext.getEntry(object);
if ( e == null ) {
throw new TransientObjectException( "Given object not associated with the session" );
}
if ( e.getStatus() != Status.MANAGED ) {
throw new ObjectDeletedException(
"The given object was deleted",
e.getId(),
e.getPersister().getEntityName()
);
}
return e.getLockMode();
}
示例5: convertToLockModeType
/**
* Convert from the Hibernate specific LockMode to the JPA defined LockModeType.
*
* @param lockMode The Hibernate LockMode.
*
* @return The JPA LockModeType
*/
public static LockModeType convertToLockModeType(LockMode lockMode) {
if ( lockMode == LockMode.NONE ) {
return LockModeType.NONE;
}
else if ( lockMode == LockMode.OPTIMISTIC || lockMode == LockMode.READ ) {
return LockModeType.OPTIMISTIC;
}
else if ( lockMode == LockMode.OPTIMISTIC_FORCE_INCREMENT || lockMode == LockMode.WRITE ) {
return LockModeType.OPTIMISTIC_FORCE_INCREMENT;
}
else if ( lockMode == LockMode.PESSIMISTIC_READ ) {
return LockModeType.PESSIMISTIC_READ;
}
else if ( lockMode == LockMode.PESSIMISTIC_WRITE
|| lockMode == LockMode.UPGRADE
|| lockMode == LockMode.UPGRADE_NOWAIT
|| lockMode == LockMode.UPGRADE_SKIPLOCKED) {
return LockModeType.PESSIMISTIC_WRITE;
}
else if ( lockMode == LockMode.PESSIMISTIC_FORCE_INCREMENT
|| lockMode == LockMode.FORCE ) {
return LockModeType.PESSIMISTIC_FORCE_INCREMENT;
}
throw new AssertionFailure( "unhandled lock mode " + lockMode );
}
示例6: CollectionElementLoader
public CollectionElementLoader(
QueryableCollection collectionPersister,
SessionFactoryImplementor factory,
LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
super( factory, loadQueryInfluencers );
this.keyType = collectionPersister.getKeyType();
this.indexType = collectionPersister.getIndexType();
this.persister = (OuterJoinLoadable) collectionPersister.getElementPersister();
this.entityName = persister.getEntityName();
JoinWalker walker = new EntityJoinWalker(
persister,
ArrayHelper.join(
collectionPersister.getKeyColumnNames(),
collectionPersister.toColumns("index")
),
1,
LockMode.NONE,
factory,
loadQueryInfluencers
);
initFromWalker( walker );
postInstantiate();
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Static select for entity %s: %s", entityName, getSQLString() );
}
}
示例7: applyLocks
@Override
protected String applyLocks(
String sql,
QueryParameters parameters,
Dialect dialect,
List<AfterLoadAction> afterLoadActions) throws QueryException {
final LockOptions lockOptions = parameters.getLockOptions();
if ( lockOptions == null ||
( lockOptions.getLockMode() == LockMode.NONE && lockOptions.getAliasLockCount() == 0 ) ) {
return sql;
}
// user is request locking, lets see if we can apply locking directly to the SQL...
// some dialects wont allow locking with paging...
afterLoadActions.add(
new AfterLoadAction() {
private final LockOptions originalLockOptions = lockOptions.makeCopy();
@Override
public void afterLoad(SessionImplementor session, Object entity, Loadable persister) {
( (Session) session ).buildLockRequest( originalLockOptions ).lock( persister.getEntityName(), entity );
}
}
);
parameters.getLockOptions().setLockMode( LockMode.READ );
return sql;
}
示例8: instanceAlreadyLoaded
/**
* The entity instance is already in the session cache
*/
private void instanceAlreadyLoaded(
final ResultSet rs,
final int i,
final Loadable persister,
final EntityKey key,
final Object object,
final LockMode requestedLockMode,
final SessionImplementor session)
throws HibernateException, SQLException {
if ( !persister.isInstance( object ) ) {
throw new WrongClassException(
"loaded object was of wrong class " + object.getClass(),
key.getIdentifier(),
persister.getEntityName()
);
}
if ( LockMode.NONE != requestedLockMode && upgradeLocks() ) { //no point doing this if NONE was requested
final EntityEntry entry = session.getPersistenceContext().getEntry( object );
if ( entry.getLockMode().lessThan( requestedLockMode ) ) {
//we only check the version when _upgrading_ lock modes
if ( persister.isVersioned() ) {
checkVersion( i, persister, key.getIdentifier(), object, rs, session );
}
//we need to upgrade the lock mode to the mode requested
entry.setLockMode( requestedLockMode );
}
}
}
示例9: getLockModes
/**
* @param lockOptions a collection of lock modes specified dynamically via the Query interface
*/
@Override
protected LockMode[] getLockModes(LockOptions lockOptions) {
if ( lockOptions == null ) {
return defaultLockModes;
}
if ( lockOptions.getAliasLockCount() == 0
&& ( lockOptions.getLockMode() == null || LockMode.NONE.equals( lockOptions.getLockMode() ) ) ) {
return defaultLockModes;
}
// unfortunately this stuff can't be cached because
// it is per-invocation, not constant for the
// QueryTranslator instance
LockMode[] lockModesArray = new LockMode[entityAliases.length];
for ( int i = 0; i < entityAliases.length; i++ ) {
LockMode lockMode = lockOptions.getEffectiveLockMode( entityAliases[i] );
if ( lockMode == null ) {
//NONE, because its the requested lock mode, not the actual!
lockMode = LockMode.NONE;
}
lockModesArray[i] = lockMode;
}
return lockModesArray;
}
示例10: checkVersion
private void checkVersion(
ResultSet resultSet,
ResultSetProcessingContext context,
EntityKey entityKey,
Object existing) {
final LockMode requestedLockMode = context.resolveLockMode( entityReference );
if ( requestedLockMode != LockMode.NONE ) {
final LockMode currentLockMode = context.getSession().getPersistenceContext().getEntry( existing ).getLockMode();
final boolean isVersionCheckNeeded = entityReference.getEntityPersister().isVersioned()
&& currentLockMode.lessThan( requestedLockMode );
// we don't need to worry about existing version being uninitialized because this block isn't called
// by a re-entrant load (re-entrant loads *always* have lock mode NONE)
if ( isVersionCheckNeeded ) {
//we only check the version when *upgrading* lock modes
checkVersion(
context.getSession(),
resultSet,
entityReference.getEntityPersister(),
entityReferenceAliases.getColumnAliases(),
entityKey,
existing
);
//we need to upgrade the lock mode to the mode requested
context.getSession().getPersistenceContext().getEntry( existing ).setLockMode( requestedLockMode );
}
}
}
示例11: convertToLockMode
/**
* Convert from JPA defined LockModeType to Hibernate specific LockMode.
*
* @param lockMode The JPA LockModeType
*
* @return The Hibernate LockMode.
*/
public static LockMode convertToLockMode(LockModeType lockMode) {
switch ( lockMode ) {
case READ:
case OPTIMISTIC: {
return LockMode.OPTIMISTIC;
}
case OPTIMISTIC_FORCE_INCREMENT:
case WRITE: {
return LockMode.OPTIMISTIC_FORCE_INCREMENT;
}
case PESSIMISTIC_READ: {
return LockMode.PESSIMISTIC_READ;
}
case PESSIMISTIC_WRITE: {
return LockMode.PESSIMISTIC_WRITE;
}
case PESSIMISTIC_FORCE_INCREMENT: {
return LockMode.PESSIMISTIC_FORCE_INCREMENT;
}
case NONE: {
return LockMode.NONE;
}
default: {
throw new AssertionFailure( "Unknown LockModeType: " + lockMode );
}
}
}
示例12: getLockMode
private static LockMode getLockMode(String lockMode) {
if ( lockMode == null || "read".equals( lockMode ) ) {
return LockMode.READ;
}
else if ( "none".equals( lockMode ) ) {
return LockMode.NONE;
}
else if ( "upgrade".equals( lockMode ) ) {
return LockMode.UPGRADE;
}
else if ( "upgrade-nowait".equals( lockMode ) ) {
return LockMode.UPGRADE_NOWAIT;
}
else if ( "upgrade-skiplocked".equals( lockMode )) {
return LockMode.UPGRADE_SKIPLOCKED;
}
else if ( "write".equals( lockMode ) ) {
return LockMode.WRITE;
}
else if ( "force".equals( lockMode ) ) {
return LockMode.FORCE;
}
else if ( "optimistic".equals( lockMode ) ) {
return LockMode.OPTIMISTIC;
}
else if ( "optimistic_force_increment".equals( lockMode ) ) {
return LockMode.OPTIMISTIC_FORCE_INCREMENT;
}
else if ( "pessimistic_read".equals( lockMode ) ) {
return LockMode.PESSIMISTIC_READ;
}
else if ( "pessimistic_write".equals( lockMode ) ) {
return LockMode.PESSIMISTIC_WRITE;
}
else if ( "pessimistic_force_increment".equals( lockMode ) ) {
return LockMode.PESSIMISTIC_FORCE_INCREMENT;
}
else {
throw new MappingException( "unknown lockmode" );
}
}
示例13: 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 SessionImplementor 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 Object cachedEntry = CacheHelper.fromSharedCache(
session,
session.generateCacheKey(
key.getIdentifier(),
persister.getEntityMetamodel().getEntityType(),
key.getEntityName()
),
persister.getCacheAccessStrategy()
);
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;
}
示例14: applyLocks
@Override
protected String applyLocks(
String sql,
QueryParameters parameters,
Dialect dialect,
List<AfterLoadAction> afterLoadActions) throws QueryException {
// can't cache this stuff either (per-invocation)
// we are given a map of user-alias -> lock mode
// create a new map of sql-alias -> lock mode
final LockOptions lockOptions = parameters.getLockOptions();
if ( lockOptions == null ||
( lockOptions.getLockMode() == LockMode.NONE && lockOptions.getAliasLockCount() == 0 ) ) {
return sql;
}
// user is request locking, lets see if we can apply locking directly to the SQL...
// some dialects wont allow locking with paging...
if ( shouldUseFollowOnLocking( parameters, dialect, afterLoadActions ) ) {
return sql;
}
// there are other conditions we might want to add here, such as checking the result types etc
// but those are better served after we have redone the SQL generation to use ASTs.
// we need both the set of locks and the columns to reference in locks
// as the ultimate output of this section...
final LockOptions locks = new LockOptions( lockOptions.getLockMode() );
final Map<String, String[]> keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap<String, String[]>() : null;
locks.setScope( lockOptions.getScope() );
locks.setTimeOut( lockOptions.getTimeOut() );
for ( Map.Entry<String, String> entry : sqlAliasByEntityAlias.entrySet() ) {
final String userAlias = entry.getKey();
final String drivingSqlAlias = entry.getValue();
if ( drivingSqlAlias == null ) {
throw new IllegalArgumentException( "could not locate alias to apply lock mode : " + userAlias );
}
// at this point we have (drivingSqlAlias) the SQL alias of the driving table
// corresponding to the given user alias. However, the driving table is not
// (necessarily) the table against which we want to apply locks. Mainly,
// the exception case here is joined-subclass hierarchies where we instead
// want to apply the lock against the root table (for all other strategies,
// it just happens that driving and root are the same).
final QueryNode select = (QueryNode) queryTranslator.getSqlAST();
final Lockable drivingPersister = (Lockable) select.getFromClause()
.findFromElementByUserOrSqlAlias( userAlias, drivingSqlAlias )
.getQueryable();
final String sqlAlias = drivingPersister.getRootTableAlias( drivingSqlAlias );
final LockMode effectiveLockMode = lockOptions.getEffectiveLockMode( userAlias );
locks.setAliasSpecificLockMode( sqlAlias, effectiveLockMode );
if ( keyColumnNames != null ) {
keyColumnNames.put( sqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
}
}
// apply the collected locks and columns
return dialect.applyLocksToSql( sql, locks, keyColumnNames );
}
示例15: toStatementString
/**
* Construct an SQL <tt>SELECT</tt> statement from the given clauses.
*
* @return the SQL <tt>SELECT</tt> statement.
*/
public String toStatementString() {
final StringBuilder buf = new StringBuilder( guesstimatedBufferSize );
if ( StringHelper.isNotEmpty( comment ) ) {
buf.append( "/* " ).append( comment ).append( " */ " );
}
buf.append( "select " )
.append( selectClause )
.append( " from " )
.append( fromClause );
if ( StringHelper.isNotEmpty( outerJoinsAfterFrom ) ) {
buf.append( outerJoinsAfterFrom );
}
if ( isNotEmpty( whereClause ) || isNotEmpty( outerJoinsAfterWhere ) ) {
buf.append( " where " );
// the outerJoinsAfterWhere needs to come before where clause to properly
// handle dynamic filters
if ( StringHelper.isNotEmpty( outerJoinsAfterWhere ) ) {
buf.append( outerJoinsAfterWhere );
if ( isNotEmpty( whereClause ) ) {
buf.append( " and " );
}
}
if ( isNotEmpty( whereClause ) ) {
buf.append( whereClause );
}
}
if ( orderByClause != null ) {
buf.append( " order by " ).append( orderByClause );
}
if ( lockOptions.getLockMode() != LockMode.NONE ) {
buf.append( dialect.getForUpdateString( lockOptions ) );
}
return dialect.transformSelectString( buf.toString() );
}