mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-22 05:02:10 +00:00
#2089 - Postgres - Use NO KEY with FOR UPDATE clauses with Postgres
Rename PlatformConfig.defaultLockWithKey to PlatformConfig.forUpdateNoKey
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -496,16 +496,31 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
return exprList.forUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> forUpdate(Query.LockType lockType) {
|
||||
return exprList.forUpdate(lockType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> forUpdateNoWait() {
|
||||
return exprList.forUpdateNoWait();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> forUpdateNoWait(Query.LockType lockType) {
|
||||
return exprList.forUpdateNoWait(lockType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> forUpdateSkipLocked() {
|
||||
return exprList.forUpdateSkipLocked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> forUpdateSkipLocked(Query.LockType lockType) {
|
||||
return exprList.forUpdateSkipLocked(lockType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Path exists - for the given path in a JSON document.
|
||||
*/
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ServerConfigTest {
|
||||
props.setProperty("caseSensitiveCollation", "false");
|
||||
props.setProperty("loadModuleInfo", "true");
|
||||
props.setProperty("collectQueryPlanThresholdMicros", "10000");
|
||||
props.setProperty("lockWithKey", "false");
|
||||
props.setProperty("forUpdateNoKey", "true");
|
||||
|
||||
serverConfig.loadFromProperties(props);
|
||||
|
||||
@@ -85,7 +85,7 @@ public class ServerConfigTest {
|
||||
|
||||
assertTrue(serverConfig.isIdGeneratorAutomatic());
|
||||
assertFalse(serverConfig.getPlatformConfig().isCaseSensitiveCollation());
|
||||
assertFalse(serverConfig.getPlatformConfig().isLockWithKey());
|
||||
assertTrue(serverConfig.getPlatformConfig().isForUpdateNoKey());
|
||||
|
||||
assertThat(serverConfig.getNamingConvention()).isInstanceOf(MatchingNamingConvention.class);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class PostgresPlatformTest {
|
||||
PlatformConfig config = new PlatformConfig();
|
||||
platform.configure(config);
|
||||
|
||||
assertThat(config.isLockWithKey()).isTrue();
|
||||
assertThat(config.isForUpdateNoKey()).isFalse();
|
||||
assertThat(platform.withForUpdate("X", Query.ForUpdate.SKIPLOCKED, Query.LockType.Default)).isEqualTo("X for update skip locked");
|
||||
assertThat(platform.withForUpdate("X", Query.ForUpdate.NOWAIT, Query.LockType.Default)).isEqualTo("X for update nowait");
|
||||
assertThat(platform.withForUpdate("X", Query.ForUpdate.BASE, Query.LockType.Default)).isEqualTo("X for update");
|
||||
@@ -56,10 +56,10 @@ public class PostgresPlatformTest {
|
||||
DatabasePlatform platform = new PostgresPlatform();
|
||||
|
||||
PlatformConfig config = new PlatformConfig();
|
||||
config.setLockWithKey(false);
|
||||
config.setForUpdateNoKey(true);
|
||||
platform.configure(config);
|
||||
|
||||
assertThat(config.isLockWithKey()).isFalse();
|
||||
assertThat(config.isForUpdateNoKey()).isTrue();
|
||||
assertThat(platform.withForUpdate("X", Query.ForUpdate.SKIPLOCKED, Query.LockType.Default)).isEqualTo("X for no key update skip locked");
|
||||
assertThat(platform.withForUpdate("X", Query.ForUpdate.NOWAIT, Query.LockType.Default)).isEqualTo("X for no key update nowait");
|
||||
assertThat(platform.withForUpdate("X", Query.ForUpdate.BASE, Query.LockType.Default)).isEqualTo("X for no key update");
|
||||
|
||||
Reference in New Issue
Block a user