HHH-4765 Enhance Dialect support for JPA-2 locking. MySQL pessimistic locking and Dialect.getForUpdateString(String aliases, LockOptions lockOptions)

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18782 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Scott Marlow 2010-02-11 15:51:25 +00:00
parent dafa28812a
commit 19de9d4ed9
4 changed files with 37 additions and 7 deletions

View File

@ -170,6 +170,7 @@ abstract class AbstractTransactSQLDialect extends Dialect {
}
public String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map keyColumnNames) {
// TODO: merge additional lockoptions support in Dialect.applyLocksToSql
Iterator itr = aliasedLockOptions.getAliasLockIterator();
StringBuffer buffer = new StringBuffer( sql );
int correction = 0;

View File

@ -1094,6 +1094,20 @@ public abstract class Dialect {
return getForUpdateString();
}
/**
* 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
* @return The appropriate <tt>FOR UPDATE OF column_list</tt> clause string.
*/
public String getForUpdateString(String aliases, LockOptions lockOptions) {
// by default we simply return the getForUpdateString() result since
// the default is to say no support for "FOR UPDATE OF ..."
return getForUpdateString(lockOptions);
}
/**
* Retrieves the <tt>FOR UPDATE NOWAIT</tt> syntax specific to this dialect.
*

View File

@ -30,6 +30,7 @@ import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.Hibernate;
import org.hibernate.LockOptions;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.NoArgSQLFunction;
import org.hibernate.dialect.function.StandardSQLFunction;
@ -334,6 +335,21 @@ public class MySQLDialect extends Dialect {
}
// locking support
public String getForUpdateString() {
return " for update";
}
public String getWriteLockString(int timeout) {
return " for update";
}
public String getReadLockString(int timeout) {
return " lock in share mode";
}
// Overridden informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public boolean supportsEmptyInList() {

View File

@ -101,13 +101,12 @@ public class ForUpdateFragment {
}
public String toFragmentString() {
if ( aliases.length() == 0) {
if ( lockOptions != null ) {
return dialect.getForUpdateString(lockOptions);
}
else if ( lockMode != null ) {
return dialect.getForUpdateString(lockMode);
if ( lockOptions!= null ) {
return dialect.getForUpdateString( aliases.toString(), lockOptions );
}
else if ( aliases.length() == 0) {
if ( lockMode != null ) {
return dialect.getForUpdateString( lockMode );
}
return "";
}