HHH-5654 PostgreSQL Dialect will now correctly apply "for update of" for any necessary table aliases. Added test.
Signed-off-by: Bradley Plies <pliesb@yahoo.com>
This commit is contained in:
parent
e70832d9dd
commit
51c7bd1523
|
@ -256,6 +256,14 @@ public class PostgreSQL81Dialect extends Dialect {
|
||||||
public String getForUpdateString(String aliases) {
|
public String getForUpdateString(String aliases) {
|
||||||
return getForUpdateString() + " of " + aliases;
|
return getForUpdateString() + " of " + aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getForUpdateString(String aliases, LockOptions lockOptions) {
|
||||||
|
/*
|
||||||
|
* Parent's implementation for (aliases, lockOptions) ignores aliases.
|
||||||
|
*/
|
||||||
|
return getForUpdateString(aliases);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdentitySelectString(String table, String column, int type) {
|
public String getIdentitySelectString(String table, String column, int type) {
|
||||||
|
|
|
@ -23,19 +23,20 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.dialect;
|
package org.hibernate.dialect;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.hibernate.JDBCException;
|
import org.hibernate.JDBCException;
|
||||||
|
import org.hibernate.LockMode;
|
||||||
|
import org.hibernate.LockOptions;
|
||||||
import org.hibernate.PessimisticLockException;
|
import org.hibernate.PessimisticLockException;
|
||||||
import org.hibernate.exception.LockAcquisitionException;
|
import org.hibernate.exception.LockAcquisitionException;
|
||||||
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
|
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,4 +66,22 @@ public class PostgreSQL81DialectTestCase extends BaseUnitTestCase {
|
||||||
JDBCException exception = delegate.convert(new SQLException("Lock Not Available", "55P03"), "", "");
|
JDBCException exception = delegate.convert(new SQLException("Lock Not Available", "55P03"), "", "");
|
||||||
assertTrue(exception instanceof PessimisticLockException);
|
assertTrue(exception instanceof PessimisticLockException);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that getForUpdateString(String aliases, LockOptions lockOptions) will return a String
|
||||||
|
* that will effect the SELECT ... FOR UPDATE OF tableAlias1, ..., tableAliasN
|
||||||
|
*/
|
||||||
|
@TestForIssue( jiraKey = "HHH-5654" )
|
||||||
|
public void testGetForUpdateStringWithAliasesAndLockOptions() {
|
||||||
|
PostgreSQL81Dialect dialect = new PostgreSQL81Dialect();
|
||||||
|
LockOptions lockOptions = new LockOptions();
|
||||||
|
lockOptions.setAliasSpecificLockMode("tableAlias1", LockMode.PESSIMISTIC_WRITE);
|
||||||
|
|
||||||
|
String forUpdateClause = dialect.getForUpdateString("tableAlias1", lockOptions);
|
||||||
|
assertTrue("for update of tableAlias1".equals(forUpdateClause));
|
||||||
|
|
||||||
|
lockOptions.setAliasSpecificLockMode("tableAlias2", LockMode.PESSIMISTIC_WRITE);
|
||||||
|
forUpdateClause = dialect.getForUpdateString("tableAlias1,tableAlias2", lockOptions);
|
||||||
|
assertTrue("for update of tableAlias1,tableAlias2".equals(forUpdateClause));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue