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.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.TimeZone;
@ -639,12 +638,9 @@ public class CockroachLegacyDialect extends Dialect {
*/
if ( aliases.isEmpty() ) {
LockMode lockMode = lockOptions.getLockMode();
final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator();
while ( itr.hasNext() ) {
for ( Map.Entry<String, LockMode> entry : lockOptions.getAliasSpecificLocks() ) {
// seek the highest lock mode
final Map.Entry<String, LockMode> entry = itr.next();
final LockMode lm = entry.getValue();
if ( lm.greaterThan( lockMode ) ) {
if ( entry.getValue().greaterThan(lockMode) ) {
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).
*/
@SuppressWarnings("deprecation")
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.
*
* @return Iterator for accessing the Map.Entry's
* @deprecated use {@link #getAliasSpecificLocks()}
*/
@Deprecated
public Iterator<Map.Entry<String,LockMode>> getAliasLockIterator() {
return getAliasSpecificLocks().iterator();
}

View File

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

View File

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

View File

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

View File

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

View File

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