HHH-5275 - Criteria.setLockMode does not work correctly
This commit is contained in:
parent
cc15ba3f58
commit
e69104cd23
|
@ -1,11 +1,10 @@
|
||||||
// $Id:$
|
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
|
* Copyright (c) 2009-2012, Red Hat Inc. or third-party contributors as
|
||||||
* third-party contributors as indicated by either @author tags or express
|
* indicated by the @author tags or express copyright attribution
|
||||||
* copyright attribution statements applied by the authors. All
|
* statements applied by the authors. All third-party contributions are
|
||||||
* third-party contributions are distributed under license by Red Hat Inc.
|
* distributed under license by Red Hat Inc.
|
||||||
*
|
*
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
* 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
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
@ -23,13 +22,13 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate;
|
package org.hibernate;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains locking details (LockMode, Timeout and Scope).
|
* Contains locking details (LockMode, Timeout and Scope).
|
||||||
*
|
*
|
||||||
|
|
|
@ -34,6 +34,7 @@ import java.sql.SQLException;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -1231,10 +1232,20 @@ public abstract class Dialect {
|
||||||
* @param lockOptions the lock options to apply
|
* @param lockOptions the lock options to apply
|
||||||
* @return The appropriate <tt>FOR UPDATE OF column_list</tt> clause string.
|
* @return The appropriate <tt>FOR UPDATE OF column_list</tt> clause string.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings( {"unchecked"})
|
||||||
public String getForUpdateString(String aliases, LockOptions lockOptions) {
|
public String getForUpdateString(String aliases, LockOptions lockOptions) {
|
||||||
// by default we simply return the getForUpdateString() result since
|
LockMode lockMode = lockOptions.getLockMode();
|
||||||
// the default is to say no support for "FOR UPDATE OF ..."
|
Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator();
|
||||||
return getForUpdateString(lockOptions);
|
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1252,7 +1263,7 @@ public abstract class Dialect {
|
||||||
* for this dialect given the aliases of the columns to be write locked.
|
* for this dialect given the aliases of the columns to be write locked.
|
||||||
*
|
*
|
||||||
* @param aliases The columns to be write locked.
|
* @param aliases The columns to be write locked.
|
||||||
* @return The appropriate <tt>FOR UPDATE colunm_list NOWAIT</tt> clause string.
|
* @return The appropriate <tt>FOR UPDATE OF colunm_list NOWAIT</tt> clause string.
|
||||||
*/
|
*/
|
||||||
public String getForUpdateNowaitString(String aliases) {
|
public String getForUpdateNowaitString(String aliases) {
|
||||||
return getForUpdateString( aliases );
|
return getForUpdateString( aliases );
|
||||||
|
|
|
@ -75,7 +75,6 @@ public class LockModeTest extends BaseCoreFunctionalTestCase {
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test( timeout = 6000 )
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"deprecation"})
|
@SuppressWarnings( {"deprecation"})
|
||||||
public void testLoading() {
|
public void testLoading() {
|
||||||
|
@ -98,7 +97,6 @@ public class LockModeTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected( jiraKey = "HHH-5275" )
|
|
||||||
public void testLegacyCriteria() {
|
public void testLegacyCriteria() {
|
||||||
// open a session, begin a transaction and lock row
|
// open a session, begin a transaction and lock row
|
||||||
Session s1 = sessionFactory().openSession();
|
Session s1 = sessionFactory().openSession();
|
||||||
|
@ -121,7 +119,6 @@ public class LockModeTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected( jiraKey = "HHH-5275" )
|
|
||||||
public void testLegacyCriteriaAliasSpecific() {
|
public void testLegacyCriteriaAliasSpecific() {
|
||||||
// open a session, begin a transaction and lock row
|
// open a session, begin a transaction and lock row
|
||||||
Session s1 = sessionFactory().openSession();
|
Session s1 = sessionFactory().openSession();
|
||||||
|
@ -144,7 +141,6 @@ public class LockModeTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected( jiraKey = "HHH-5275" )
|
|
||||||
public void testQuery() {
|
public void testQuery() {
|
||||||
// open a session, begin a transaction and lock row
|
// open a session, begin a transaction and lock row
|
||||||
Session s1 = sessionFactory().openSession();
|
Session s1 = sessionFactory().openSession();
|
||||||
|
|
Loading…
Reference in New Issue