#2089 - Postgres - Use NO KEY with FOR UPDATE clauses with Postgres

Rename PlatformConfig.defaultLockWithKey to PlatformConfig.forUpdateNoKey
This commit is contained in:
rob bygrave
2020-11-24 23:58:58 +13:00
parent 92a4bfb38e
commit 20fc74219a
5 changed files with 33 additions and 18 deletions
@@ -18,9 +18,9 @@ public class PlatformConfig {
private boolean allQuotedIdentifiers;
/**
* Set this to true for Postgres FOR UPDATE to include the primary key (not use NO KEY).
* Set this to true for Postgres FOR UPDATE to use NO KEY option.
*/
private boolean lockWithKey = true;
private boolean forUpdateNoKey;
private DbConstraintNaming constraintNaming;
@@ -82,7 +82,7 @@ public class PlatformConfig {
* Construct based on given config - typically for DbMigration generation with many platforms.
*/
public PlatformConfig(PlatformConfig platformConfig) {
this.lockWithKey = platformConfig.lockWithKey;
this.forUpdateNoKey = platformConfig.forUpdateNoKey;
this.databaseBooleanFalse = platformConfig.databaseBooleanFalse;
this.databaseBooleanTrue = platformConfig.databaseBooleanTrue;
this.databaseSequenceBatchSize = platformConfig.databaseSequenceBatchSize;
@@ -140,17 +140,17 @@ public class PlatformConfig {
}
/**
* Return true if Postgres FOR UPDATE should include the primary key (or use NO KEY).
* Return true if Postgres FOR UPDATE should use the NO KEY option.
*/
public boolean isLockWithKey() {
return lockWithKey;
public boolean isForUpdateNoKey() {
return forUpdateNoKey;
}
/**
* Set to true such that Postgres FOR UPDATE should include the primary key (not use NO KEY option).
* Set to true such that Postgres FOR UPDATE should use the NO KEY option.
*/
public void setLockWithKey(boolean lockWithKey) {
this.lockWithKey = lockWithKey;
public void setForUpdateNoKey(boolean forUpdateNoKey) {
this.forUpdateNoKey = forUpdateNoKey;
}
/**
@@ -308,7 +308,7 @@ public class PlatformConfig {
public void loadSettings(PropertiesWrapper p) {
idType = p.getEnum(IdType.class, "idType", idType);
lockWithKey = p.getBoolean("lockWithKey", lockWithKey);
forUpdateNoKey = p.getBoolean("forUpdateNoKey", forUpdateNoKey);
databaseSequenceBatchSize = p.getInt("databaseSequenceBatchSize", databaseSequenceBatchSize);
databaseBooleanTrue = p.get("databaseBooleanTrue", databaseBooleanTrue);
databaseBooleanFalse = p.get("databaseBooleanFalse", databaseBooleanFalse);
@@ -33,7 +33,7 @@ public class PostgresPlatform extends DatabasePlatform {
private static final String FOR_SHARE = " for share";
private static final String FOR_KEY_SHARE = " for key share";
private boolean defaultLockWithKey = true;
private boolean forUpdateNoKey;
public PostgresPlatform() {
super();
@@ -94,7 +94,7 @@ public class PostgresPlatform extends DatabasePlatform {
@Override
public void configure(PlatformConfig config) {
super.configure(config);
defaultLockWithKey = config.isLockWithKey();
forUpdateNoKey = config.isForUpdateNoKey();
}
@Override
@@ -145,7 +145,7 @@ public class PostgresPlatform extends DatabasePlatform {
case NoKeyUpdate: return FOR_NO_KEY_UPDATE;
case Share: return FOR_SHARE;
case KeyShare: return FOR_KEY_SHARE;
case Default: return defaultLockWithKey ? FOR_UPDATE : FOR_NO_KEY_UPDATE;
case Default: return forUpdateNoKey ? FOR_NO_KEY_UPDATE : FOR_UPDATE;
}
return FOR_UPDATE;
}