Java Code Examples for org.hibernate.LockOptions#setLockMode()
The following examples show how to use
org.hibernate.LockOptions#setLockMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CascadingActions.java From lams with GNU General Public License v2.0 | 6 votes |
@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() ); lr.setFollowOnLocking( lockOptions.getFollowOnLocking() ); if ( lockOptions.getScope() ) { lockMode = lockOptions.getLockMode(); } } lr.setLockMode( lockMode ); session.buildLockRequest( lr ).lock( entityName, child ); }
Example 2
Source File: Dialect.java From lams with GNU General Public License v2.0 | 6 votes |
/** * 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 ); }
Example 3
Source File: SessionImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public LockOptions getLockRequest(LockModeType lockModeType, Map<String, Object> properties) { LockOptions lockOptions = new LockOptions(); LockOptions.copy( this.lockOptions, lockOptions ); lockOptions.setLockMode( LockModeTypeHelper.getLockMode( lockModeType ) ); if ( properties != null ) { setLockOptions( properties, lockOptions ); } return lockOptions; }
Example 4
Source File: AbstractHANADialect.java From lams with GNU General Public License v2.0 | 5 votes |
@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() ); }
Example 5
Source File: LoadEvent.java From lams with GNU General Public License v2.0 | 5 votes |
private LoadEvent( Serializable entityId, String entityClassName, Object instanceToLoad, LockOptions lockOptions, boolean isAssociationFetch, EventSource source) { super(source); if ( entityId == null ) { throw new IllegalArgumentException("id to load is required for loading"); } if ( lockOptions.getLockMode() == LockMode.WRITE ) { throw new IllegalArgumentException("Invalid lock mode for loading"); } else if ( lockOptions.getLockMode() == null ) { lockOptions.setLockMode(DEFAULT_LOCK_MODE); } this.entityId = entityId; this.entityClassName = entityClassName; this.instanceToLoad = instanceToLoad; this.lockOptions = lockOptions; this.isAssociationFetch = isAssociationFetch; this.postLoadEvent = new PostLoadEvent( source ); }
Example 6
Source File: ResolveNaturalIdEvent.java From lams with GNU General Public License v2.0 | 4 votes |
public ResolveNaturalIdEvent( Map<String, Object> naturalIdValues, EntityPersister entityPersister, LockOptions lockOptions, EventSource source) { super( source ); if ( entityPersister == null ) { throw new IllegalArgumentException( "EntityPersister is required for loading" ); } if ( ! entityPersister.hasNaturalIdentifier() ) { throw new HibernateException( "Entity did not define a natural-id" ); } if ( naturalIdValues == null || naturalIdValues.isEmpty() ) { throw new IllegalArgumentException( "natural-id to load is required" ); } if ( entityPersister.getNaturalIdentifierProperties().length != naturalIdValues.size() ) { throw new HibernateException( String.format( "Entity [%s] defines its natural-id with %d properties but only %d were specified", entityPersister.getEntityName(), entityPersister.getNaturalIdentifierProperties().length, naturalIdValues.size() ) ); } if ( lockOptions.getLockMode() == LockMode.WRITE ) { throw new IllegalArgumentException( "Invalid lock mode for loading" ); } else if ( lockOptions.getLockMode() == null ) { lockOptions.setLockMode( DEFAULT_LOCK_MODE ); } this.entityPersister = entityPersister; this.naturalIdValues = naturalIdValues; this.lockOptions = lockOptions; int[] naturalIdPropertyPositions = entityPersister.getNaturalIdentifierProperties(); orderedNaturalIdValues = new Object[naturalIdPropertyPositions.length]; int i = 0; for ( int position : naturalIdPropertyPositions ) { final String propertyName = entityPersister.getPropertyNames()[position]; if ( ! naturalIdValues.containsKey( propertyName ) ) { throw new HibernateException( String.format( "No value specified for natural-id property %s#%s", getEntityName(), propertyName ) ); } orderedNaturalIdValues[i++] = naturalIdValues.get( entityPersister.getPropertyNames()[position] ); } }