HHH-7298 regression, org.hibernate.ejb.test.lock.LockTest

This commit is contained in:
Strong Liu 2012-05-31 18:58:00 +08:00
parent bf69f8a382
commit c0b4b7a577
7 changed files with 65 additions and 31 deletions

View File

@ -157,13 +157,9 @@ abstract class AbstractTransactSQLDialect extends Dialect {
return insertSQL + "\nselect @@identity";
}
public String appendLockHint(LockMode mode, String tableName) {
if ( mode.greaterThan( LockMode.READ ) ) {
return tableName + " holdlock";
}
else {
return tableName;
}
@Override
public String appendLockHint(LockOptions lockOptions, String tableName) {
return lockOptions.getLockMode().greaterThan( LockMode.READ ) ? tableName + " holdlock" : tableName;
}
public String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map keyColumnNames) {

View File

@ -1281,8 +1281,23 @@ public abstract class Dialect implements ConversionContext {
* @param mode The lock mode to apply
* @param tableName The name of the table to which to apply the lock hint.
* @return The table with any required lock hints.
* @deprecated use {@code appendLockHint(LockOptions,String)} instead
*/
@Deprecated
public String appendLockHint(LockMode mode, String tableName) {
return appendLockHint( new LockOptions( mode ), tableName );
}
/**
* Some dialects support an alternative means to <tt>SELECT FOR UPDATE</tt>,
* whereby a "lock hint" is appends to the table name in the from clause.
* <p/>
* contributed by <a href="http://sourceforge.net/users/heschulz">Helge Schulz</a>
*
* @param lockOptions The lock options to apply
* @param tableName The name of the table to which to apply the lock hint.
* @return The table with any required lock hints.
*/
public String appendLockHint(LockOptions lockOptions, String tableName){
return tableName;
}

View File

@ -30,6 +30,7 @@ import java.util.regex.Pattern;
import org.hibernate.JDBCException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.QueryTimeoutException;
import org.hibernate.dialect.function.NoArgSQLFunction;
import org.hibernate.exception.LockTimeoutException;
@ -213,11 +214,25 @@ public class SQLServer2005Dialect extends SQLServerDialect {
}
@Override // since SQLServer2005 the nowait hint is supported
public String appendLockHint(LockMode mode, String tableName) {
if ( mode == LockMode.UPGRADE_NOWAIT ) {
public String appendLockHint(LockOptions lockOptions, String tableName) {
if ( lockOptions.getLockMode() == LockMode.UPGRADE_NOWAIT ) {
return tableName + " with (updlock, rowlock, nowait)";
}
return super.appendLockHint( mode, tableName );
LockMode mode = lockOptions.getLockMode();
boolean isNoWait = lockOptions.getTimeOut() == LockOptions.NO_WAIT;
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;
}
}
/**
@ -270,13 +285,18 @@ public class SQLServer2005Dialect extends SQLServerDialect {
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
if( "HY008".equals( sqlState )){
throw new QueryTimeoutException( message, sqlException, sql );
}
if (1222 == errorCode ) {
throw new LockTimeoutException( message, sqlException, sql );
}
return null;
}
};
}
}

View File

@ -25,6 +25,7 @@ package org.hibernate.dialect;
import java.sql.Types;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.dialect.function.AnsiTrimEmulationFunction;
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.dialect.function.StandardSQLFunction;
@ -120,18 +121,18 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
}
@Override
public String appendLockHint(LockMode mode, String tableName) {
if ( ( mode == LockMode.UPGRADE ) ||
( mode == LockMode.UPGRADE_NOWAIT ) ||
( mode == LockMode.PESSIMISTIC_WRITE ) ||
( mode == LockMode.WRITE ) ) {
return tableName + " with (updlock, rowlock)";
}
else if ( mode == LockMode.PESSIMISTIC_READ ) {
return tableName + " with (holdlock, rowlock)";
}
else {
return tableName;
public String appendLockHint(LockOptions lockOptions, String tableName) {
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)";
default:
return tableName;
}
}

View File

@ -72,31 +72,33 @@ public class SybaseASE157Dialect extends SybaseASE15Dialect {
}
// support Lob Locator
@Override
public boolean supportsExpectedLobUsagePattern() {
return true;
}
@Override
public boolean supportsLobValueChangePropogation() {
return false;
}
// support 'select ... for update [of columns]'
@Override
public boolean forUpdateOfColumns() {
return true;
}
@Override
public String getForUpdateString() {
return " for update";
}
@Override
public String getForUpdateString(String aliases) {
return getForUpdateString() + " of " + aliases;
}
public String appendLockHint(LockMode mode, String tableName) {
@Override
public String appendLockHint(LockOptions mode, String tableName) {
return tableName;
}
@Override
public String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map keyColumnNames) {
return sql + new ForUpdateFragment( this, aliasedLockOptions, keyColumnNames ).toFragmentString();
}

View File

@ -128,7 +128,7 @@ public abstract class AbstractEntityJoinWalker extends JoinWalker {
projection
)
.setFromClause(
getDialect().appendLockHint( lockOptions.getLockMode(), persister.fromTableFragment( alias ) ) +
getDialect().appendLockHint( lockOptions, persister.fromTableFragment( alias ) ) +
persister.fromJoinFragment( alias, true, true )
)
.setWhereClause( condition )

View File

@ -177,7 +177,7 @@ public class SimpleSelect {
}
buf.append(" from ")
.append( dialect.appendLockHint(lockOptions.getLockMode(), tableName) );
.append( dialect.appendLockHint(lockOptions, tableName) );
if ( whereTokens.size() > 0 ) {
buf.append(" where ")