clean up old code + deprecate LockOptions.getAliasLockIterator()

This commit is contained in:
Gavin King 2022-09-16 08:20:07 +02:00
parent cf51b92aeb
commit 7740121449
7 changed files with 35 additions and 55 deletions

View File

@ -12,7 +12,6 @@ import java.sql.Types;
import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAccessor;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
@ -639,12 +638,9 @@ public class CockroachLegacyDialect extends Dialect {
*/ */
if ( aliases.isEmpty() ) { if ( aliases.isEmpty() ) {
LockMode lockMode = lockOptions.getLockMode(); LockMode lockMode = lockOptions.getLockMode();
final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator(); for ( Map.Entry<String, LockMode> entry : lockOptions.getAliasSpecificLocks() ) {
while ( itr.hasNext() ) {
// seek the highest lock mode // seek the highest lock mode
final Map.Entry<String, LockMode> entry = itr.next(); if ( entry.getValue().greaterThan(lockMode) ) {
final LockMode lm = entry.getValue();
if ( lm.greaterThan( lockMode ) ) {
aliases = entry.getKey(); aliases = entry.getKey();
} }
} }

View File

@ -34,7 +34,6 @@ public class LockOptions implements Serializable {
/** /**
* Represents LockMode.UPGRADE (will wait forever for lock and scope of false meaning only entity is locked). * Represents LockMode.UPGRADE (will wait forever for lock and scope of false meaning only entity is locked).
*/ */
@SuppressWarnings("deprecation")
public static final LockOptions UPGRADE = new LockOptions(LockMode.PESSIMISTIC_WRITE); public static final LockOptions UPGRADE = new LockOptions(LockMode.PESSIMISTIC_WRITE);
/** /**
@ -198,7 +197,9 @@ public class LockOptions implements Serializable {
* Iterator for accessing Alias (key) and LockMode (value) as Map.Entry. * Iterator for accessing Alias (key) and LockMode (value) as Map.Entry.
* *
* @return Iterator for accessing the Map.Entry's * @return Iterator for accessing the Map.Entry's
* @deprecated use {@link #getAliasSpecificLocks()}
*/ */
@Deprecated
public Iterator<Map.Entry<String,LockMode>> getAliasLockIterator() { public Iterator<Map.Entry<String,LockMode>> getAliasLockIterator() {
return getAliasSpecificLocks().iterator(); return getAliasSpecificLocks().iterator();
} }

View File

@ -38,7 +38,6 @@ import java.sql.CallableStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import static org.hibernate.type.SqlTypes.*; import static org.hibernate.type.SqlTypes.*;
@ -219,14 +218,11 @@ public abstract class AbstractTransactSQLDialect extends Dialect {
@Override @Override
public String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map<String, String[]> keyColumnNames) { public String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map<String, String[]> keyColumnNames) {
// TODO: merge additional lock options support in Dialect.applyLocksToSql // TODO: merge additional lock options support in Dialect.applyLocksToSql
final Iterator itr = aliasedLockOptions.getAliasLockIterator();
final StringBuilder buffer = new StringBuilder( sql ); final StringBuilder buffer = new StringBuilder( sql );
for ( Map.Entry<String, LockMode> entry: aliasedLockOptions.getAliasSpecificLocks() ) {
while ( itr.hasNext() ) { final LockMode lockMode = entry.getValue();
final Map.Entry entry = (Map.Entry) itr.next();
final LockMode lockMode = (LockMode) entry.getValue();
if ( lockMode.greaterThan( LockMode.READ ) ) { if ( lockMode.greaterThan( LockMode.READ ) ) {
final String alias = (String) entry.getKey(); final String alias = entry.getKey();
int start = -1; int start = -1;
int end = -1; int end = -1;
if ( sql.endsWith( " " + alias ) ) { if ( sql.endsWith( " " + alias ) ) {

View File

@ -12,7 +12,6 @@ import java.sql.Types;
import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAccessor;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
@ -636,12 +635,9 @@ public class CockroachDialect extends Dialect {
*/ */
if ( aliases.isEmpty() ) { if ( aliases.isEmpty() ) {
LockMode lockMode = lockOptions.getLockMode(); LockMode lockMode = lockOptions.getLockMode();
final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator(); for ( Map.Entry<String, LockMode> entry : lockOptions.getAliasSpecificLocks() ) {
while ( itr.hasNext() ) {
// seek the highest lock mode // seek the highest lock mode
final Map.Entry<String, LockMode> entry = itr.next(); if ( entry.getValue().greaterThan(lockMode) ) {
final LockMode lm = entry.getValue();
if ( lm.greaterThan( lockMode ) ) {
aliases = entry.getKey(); aliases = entry.getKey();
} }
} }

View File

@ -1821,12 +1821,10 @@ public abstract class Dialect implements ConversionContext {
*/ */
public String getForUpdateString(String aliases, LockOptions lockOptions) { public String getForUpdateString(String aliases, LockOptions lockOptions) {
LockMode lockMode = lockOptions.getLockMode(); LockMode lockMode = lockOptions.getLockMode();
final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator(); for ( Map.Entry<String, LockMode> entry : lockOptions.getAliasSpecificLocks() ) {
while ( itr.hasNext() ) {
// seek the highest lock mode // seek the highest lock mode
final Map.Entry<String, LockMode>entry = itr.next();
final LockMode lm = entry.getValue(); final LockMode lm = entry.getValue();
if ( lm.greaterThan( lockMode ) ) { if ( lm.greaterThan(lockMode) ) {
lockMode = lm; lockMode = lm;
} }
} }

View File

@ -14,9 +14,7 @@ import java.sql.Types;
import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAccessor;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import jakarta.persistence.TemporalType; import jakarta.persistence.TemporalType;
@ -636,12 +634,9 @@ public class PostgreSQLDialect extends Dialect {
*/ */
if ( aliases.isEmpty() ) { if ( aliases.isEmpty() ) {
LockMode lockMode = lockOptions.getLockMode(); LockMode lockMode = lockOptions.getLockMode();
final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator(); for ( Map.Entry<String, LockMode> entry : lockOptions.getAliasSpecificLocks() ) {
while ( itr.hasNext() ) {
// seek the highest lock mode // seek the highest lock mode
final Map.Entry<String, LockMode> entry = itr.next(); if ( entry.getValue().greaterThan(lockMode) ) {
final LockMode lm = entry.getValue();
if ( lm.greaterThan( lockMode ) ) {
aliases = entry.getKey(); aliases = entry.getKey();
} }
} }

View File

@ -6,7 +6,6 @@
*/ */
package org.hibernate.sql; package org.hibernate.sql;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import org.hibernate.LockMode; import org.hibernate.LockMode;
@ -27,20 +26,18 @@ public class ForUpdateFragment {
public ForUpdateFragment(Dialect dialect, LockOptions lockOptions, Map<String, String[]> keyColumnNames) throws QueryException { public ForUpdateFragment(Dialect dialect, LockOptions lockOptions, Map<String, String[]> keyColumnNames) throws QueryException {
this.dialect = dialect; this.dialect = dialect;
LockMode upgradeType = null; LockMode upgradeType = null;
Iterator<Map.Entry<String, LockMode>> iter = lockOptions.getAliasLockIterator();
this.lockOptions = lockOptions; this.lockOptions = lockOptions;
if ( !iter.hasNext()) { // no tables referenced if ( !lockOptions.getAliasSpecificLocks().iterator().hasNext() ) { // no tables referenced
final LockMode lockMode = lockOptions.getLockMode(); final LockMode lockMode = lockOptions.getLockMode();
if ( LockMode.READ.lessThan( lockMode ) ) { if ( LockMode.READ.lessThan(lockMode) ) {
upgradeType = lockMode; upgradeType = lockMode;
} }
} }
else {
while ( iter.hasNext() ) { for ( Map.Entry<String, LockMode> me : lockOptions.getAliasSpecificLocks() ) {
final Map.Entry<String, LockMode> me = iter.next();
final LockMode lockMode = me.getValue(); final LockMode lockMode = me.getValue();
if ( LockMode.READ.lessThan( lockMode ) ) { if ( LockMode.READ.lessThan(lockMode) ) {
final String tableAlias = me.getKey(); final String tableAlias = me.getKey();
if ( dialect.getWriteRowLockStrategy() == RowLockStrategy.COLUMN ) { if ( dialect.getWriteRowLockStrategy() == RowLockStrategy.COLUMN ) {
String[] keyColumns = keyColumnNames.get( tableAlias ); //use the id column alias String[] keyColumns = keyColumnNames.get( tableAlias ); //use the id column alias
@ -62,6 +59,7 @@ public class ForUpdateFragment {
} }
} }
} }
}
public ForUpdateFragment addTableAlias(String alias) { public ForUpdateFragment addTableAlias(String alias) {
if ( aliases.length() > 0 ) { if ( aliases.length() > 0 ) {