本文整理汇总了Java中org.hibernate.LockOptions类的典型用法代码示例。如果您正苦于以下问题:Java LockOptions类的具体用法?Java LockOptions怎么用?Java LockOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LockOptions类属于org.hibernate包,在下文中一共展示了LockOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.hibernate.LockOptions; //导入依赖的package包/类
@Override
public Object get(final String entityName, final Serializable id, final LockMode lockMode)
throws DataAccessException {
return executeWithNativeSession(new HibernateCallback<Object>() {
@Override
public Object doInHibernate(Session session) throws HibernateException {
if (lockMode != null) {
return session.get(entityName, id, new LockOptions(lockMode));
}
else {
return session.get(entityName, id);
}
}
});
}
示例2: load
import org.hibernate.LockOptions; //导入依赖的package包/类
@Override
public <T> T load(final Class<T> entityClass, final Serializable id, final LockMode lockMode)
throws DataAccessException {
return executeWithNativeSession(new HibernateCallback<T>() {
@Override
@SuppressWarnings("unchecked")
public T doInHibernate(Session session) throws HibernateException {
if (lockMode != null) {
return (T) session.load(entityClass, id, new LockOptions(lockMode));
}
else {
return (T) session.load(entityClass, id);
}
}
});
}
示例3: delete
import org.hibernate.LockOptions; //导入依赖的package包/类
@Override
public void delete(final String entityName, final Object entity, final LockMode lockMode)
throws DataAccessException {
executeWithNativeSession(new HibernateCallback<Object>() {
@Override
public Object doInHibernate(Session session) throws HibernateException {
checkWriteOperationAllowed(session);
if (lockMode != null) {
session.buildLockRequest(new LockOptions(lockMode)).lock(entityName, entity);
}
session.delete(entityName, entity);
return null;
}
});
}
示例4: doBatchLoad
import org.hibernate.LockOptions; //导入依赖的package包/类
protected Object doBatchLoad(
Serializable id,
Loader loaderToUse,
SessionImplementor session,
Serializable[] ids,
Object optionalObject,
LockOptions lockOptions) {
if ( log.isDebugEnabled() ) {
log.debugf( "Batch loading entity: %s", MessageHelper.infoString( persister, ids, session.getFactory() ) );
}
QueryParameters qp = buildQueryParameters( id, ids, optionalObject, lockOptions );
try {
final List results = loaderToUse.doQueryAndInitializeNonLazyCollections( session, qp, false );
log.debug( "Done entity batch load" );
return getObjectFromList(results, id, session);
}
catch ( SQLException sqle ) {
throw session.getFactory().getSQLExceptionHelper().convert(
sqle,
"could not load an entity batch: " + MessageHelper.infoString( persister(), ids, session.getFactory() ),
loaderToUse.getSQLString()
);
}
}
示例5: EntityLoader
import org.hibernate.LockOptions; //导入依赖的package包/类
public EntityLoader(
OuterJoinLoadable persister,
int batchSize,
LockOptions lockOptions,
SessionFactoryImplementor factory,
LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
this(
persister,
persister.getIdentifierColumnNames(),
persister.getIdentifierType(),
batchSize,
lockOptions,
factory,
loadQueryInfluencers
);
}
示例6: generateLockString
import org.hibernate.LockOptions; //导入依赖的package包/类
protected String generateLockString(int lockTimeout) {
final SessionFactoryImplementor factory = getLockable().getFactory();
final LockOptions lockOptions = new LockOptions( getLockMode() );
lockOptions.setTimeOut( lockTimeout );
final SimpleSelect select = new SimpleSelect( factory.getDialect() )
.setLockOptions( lockOptions )
.setTableName( getLockable().getRootTableName() )
.addColumn( getLockable().getRootTableIdentifierColumnNames()[0] )
.addCondition( getLockable().getRootTableIdentifierColumnNames(), "=?" );
if ( getLockable().isVersioned() ) {
select.addCondition( getLockable().getVersionColumnName(), "=?" );
}
if ( factory.getSettings().isCommentsEnabled() ) {
select.setComment( getLockMode() + " lock " + getLockable().getEntityName() );
}
return select.toStatementString();
}
示例7: load
import org.hibernate.LockOptions; //导入依赖的package包/类
@Override
public Object load(
Serializable id,
Object optionalObject,
SessionImplementor session,
LockOptions lockOptions) {
final Serializable[] batch = session.getPersistenceContext()
.getBatchFetchQueue()
.getEntityBatch( persister(), id, maxBatchSize, persister().getEntityMode() );
final int numberOfIds = ArrayHelper.countNonNull( batch );
if ( numberOfIds <= 1 ) {
return singleKeyLoader.load( id, optionalObject, session );
}
final Serializable[] idsToLoad = new Serializable[numberOfIds];
System.arraycopy( batch, 0, idsToLoad, 0, numberOfIds );
if ( log.isDebugEnabled() ) {
log.debugf( "Batch loading entity: %s", MessageHelper.infoString( persister(), idsToLoad, session.getFactory() ) );
}
QueryParameters qp = buildQueryParameters( id, idsToLoad, optionalObject, lockOptions );
List results = dynamicLoader.doEntityBatchFetch( session, qp, idsToLoad );
return getObjectFromList( results, id, session );
}
示例8: cascade
import org.hibernate.LockOptions; //导入依赖的package包/类
@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 );
}
示例9: buildQueryParameters
import org.hibernate.LockOptions; //导入依赖的package包/类
protected QueryParameters buildQueryParameters(
Serializable id,
Serializable[] ids,
Object optionalObject,
LockOptions lockOptions) {
Type[] types = new Type[ids.length];
Arrays.fill( types, persister().getIdentifierType() );
QueryParameters qp = new QueryParameters();
qp.setPositionalParameterTypes( types );
qp.setPositionalParameterValues( ids );
qp.setOptionalObject( optionalObject );
qp.setOptionalEntityName( persister().getEntityName() );
qp.setOptionalId( id );
qp.setLockOptions( lockOptions );
return qp;
}
示例10: getForUpdateString
import org.hibernate.LockOptions; //导入依赖的package包/类
/**
* 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 );
}
示例11: getForUpdateString
import org.hibernate.LockOptions; //导入依赖的package包/类
@Override
public String getForUpdateString(final String aliases, final 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;
}
}
// not sure why this is sometimes empty
if ( aliases == null || "".equals( aliases ) ) {
return getForUpdateString( lockMode );
}
return getForUpdateString( lockMode ) + " of " + aliases;
}
示例12: appendLockHint
import org.hibernate.LockOptions; //导入依赖的package包/类
@Override
public String appendLockHint(LockOptions lockOptions, String tableName) {
// NOTE : since SQLServer2005 the nowait hint is supported
if ( lockOptions.getLockMode() == LockMode.UPGRADE_NOWAIT ) {
return tableName + " with (updlock, rowlock, nowait)";
}
final LockMode mode = lockOptions.getLockMode();
final boolean isNoWait = lockOptions.getTimeOut() == LockOptions.NO_WAIT;
final String noWaitStr = isNoWait ? ", nowait" : "";
switch ( mode ) {
case UPGRADE_NOWAIT:
return tableName + " with (updlock, rowlock, nowait)";
case UPGRADE:
case PESSIMISTIC_WRITE:
case WRITE:
return tableName + " with (updlock, rowlock" + noWaitStr + " )";
case PESSIMISTIC_READ:
return tableName + " with (holdlock, rowlock" + noWaitStr + " )";
default:
return tableName;
}
}
示例13: appendLockHint
import org.hibernate.LockOptions; //导入依赖的package包/类
@Override
public String appendLockHint(LockOptions lockOptions, String tableName) {
final LockMode mode = lockOptions.getLockMode();
switch ( mode ) {
case UPGRADE:
case UPGRADE_NOWAIT:
case PESSIMISTIC_WRITE:
case WRITE:
return tableName + " with (updlock, rowlock)";
case PESSIMISTIC_READ:
return tableName + " with (holdlock, rowlock)";
case UPGRADE_SKIPLOCKED:
return tableName + " with (updlock, rowlock, readpast)";
default:
return tableName;
}
}
示例14: byKey
import org.hibernate.LockOptions; //导入依赖的package包/类
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 ) ;
}
示例15: lock
import org.hibernate.LockOptions; //导入依赖的package包/类
@Override
public void lock(final String entityName, final Object entity, final LockMode lockMode)
throws DataAccessException {
executeWithNativeSession(new HibernateCallback<Object>() {
@Override
public Object doInHibernate(Session session) throws HibernateException {
session.buildLockRequest(new LockOptions(lockMode)).lock(entityName, entity);
return null;
}
});
}