HHH-6736 - Support for SELECT ... FOR UPDATE SKIP LOCKED / read past locking

This commit is contained in:
Steve Ebersole 2013-02-20 09:31:14 -06:00
parent e0cfc6bf2e
commit 4e126dcffc
4 changed files with 46 additions and 3 deletions

View File

@ -25,6 +25,8 @@ package org.hibernate.event.internal;
import java.io.Serializable;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.TransientObjectException;
@ -36,6 +38,7 @@ import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.LockEvent;
import org.hibernate.event.spi.LockEventListener;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.entity.EntityPersister;
/**
@ -46,7 +49,13 @@ import org.hibernate.persister.entity.EntityPersister;
*/
public class DefaultLockEventListener extends AbstractLockUpgradeEventListener implements LockEventListener {
/** Handle the given lock event.
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class,
DefaultLockEventListener.class.getName()
);
/**
* Handle the given lock event.
*
* @param event The lock event to be handled.
* @throws HibernateException
@ -61,6 +70,10 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i
throw new HibernateException( "Invalid lock mode for lock()" );
}
if ( event.getLockMode() == LockMode.UPGRADE_SKIPLOCKED ) {
LOG.explicitSkipLockedLockCombo();
}
SessionImplementor source = event.getSession();
Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );

View File

@ -1609,4 +1609,11 @@ public interface CoreMessageLogger extends BasicLogger {
)
void embedXmlAttributesNoLongerSupported();
@LogMessage(level = WARN)
@Message(
value = "Explicit use of UPGRADE_SKIPLOCKED in lock() calls is not recommended; use normal UPGRADE locking instead",
id = 447
)
void explicitSkipLockedLockCombo();
}

View File

@ -1,5 +1,28 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ Copyright (c) 2013, Red Hat Inc. or third-party contributors as
~ indicated by the @author tags or express copyright attribution
~ statements applied by the authors. All third-party contributions are
~ distributed under license by Red Hat Inc.
~
~ This copyrighted material is made available to anyone wishing to use, modify,
~ copy, or redistribute it subject to the terms and conditions of the GNU
~ Lesser General Public License, as published by the Free Software Foundation.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
~ for more details.
~
~ You should have received a copy of the GNU Lesser General Public License
~ along with this distribution; if not, write to:
~ Free Software Foundation, Inc.
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

View File

@ -2,7 +2,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.