mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Compare commits
65
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c6d17c9a5 | ||
|
|
885ba0fdd2 | ||
|
|
f3b0e34b67 | ||
|
|
4109fab0d8 | ||
|
|
0688061f5c | ||
|
|
82c12b1565 | ||
|
|
ebc0fabbdb | ||
|
|
587b2e3075 | ||
|
|
ec82dd3da9 | ||
|
|
3e190b34f5 | ||
|
|
e059ad9172 | ||
|
|
1297324fa9 | ||
|
|
e2b7434d98 | ||
|
|
ada8df5755 | ||
|
|
843b90cbba | ||
|
|
6b263919d5 | ||
|
|
965c1e803f | ||
|
|
a13bc481b8 | ||
|
|
fc7379aabc | ||
|
|
a17683c549 | ||
|
|
eeacad0fb9 | ||
|
|
c51140b59a | ||
|
|
f1817a0dbb | ||
|
|
5b05510bb9 | ||
|
|
b676476cd2 | ||
|
|
709f8ed05f | ||
|
|
31282416d8 | ||
|
|
385c84ae6f | ||
|
|
2d24020202 | ||
|
|
1a2aba3f56 | ||
|
|
f50f0192d1 | ||
|
|
12b8b4b955 | ||
|
|
c267366578 | ||
|
|
18e49cc1ce | ||
|
|
1ce4b1a994 | ||
|
|
f3c87e488a | ||
|
|
f24c698cd5 | ||
|
|
144a3b54bb | ||
|
|
ec7c7048db | ||
|
|
fd2e542c0b | ||
|
|
11e8e3696f | ||
|
|
d08f7af1e0 | ||
|
|
60dfaab22c | ||
|
|
75fa7cb7fd | ||
|
|
e47b1737a8 | ||
|
|
e1ad210bb0 | ||
|
|
ac3edbedf4 | ||
|
|
2dc48cf08d | ||
|
|
ede1ad0a4c | ||
|
|
3e8f76cd6d | ||
|
|
cd6df2be39 | ||
|
|
7091e972fc | ||
|
|
c8ae3c5ef6 | ||
|
|
54e8c4df8a | ||
|
|
e18c190905 | ||
|
|
181dc73d39 | ||
|
|
7ed2de9178 | ||
|
|
8c101fd0a4 | ||
|
|
43213ead05 | ||
|
|
0ef5c65c94 | ||
|
|
c610f95b2d | ||
|
|
c4484c758e | ||
|
|
60ef87b269 | ||
|
|
7e265f7bde | ||
|
|
bd7499a505 |
@@ -1,9 +1,3 @@
|
||||
|
||||
GITHUB ISSUES ARE STRICTLY CONTROLLED FOR THIS PROJECT.
|
||||
|
||||
Refer to http://ebean-orm.github.io/support for the policies controlling the use of github issues.
|
||||
Please post issues to the Ebean group https://groups.google.com/forum/#!forum/ebean first.
|
||||
|
||||
## Expected behavior
|
||||
|
||||
## Actual behavior
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</parent>
|
||||
|
||||
<name>ebean api</name>
|
||||
|
||||
@@ -16,18 +16,15 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
* <p>
|
||||
* This uses either DatabaseConfig or properties in the application.properties file to
|
||||
* configure and create a Database instance.
|
||||
* </p>
|
||||
* <p>
|
||||
* The Database instance can either be registered with the DB singleton or
|
||||
* not. The DB singleton effectively holds a map of Database by a name.
|
||||
* If the Database is registered with the DB singleton you can retrieve it
|
||||
* later via {@link DB#byName(String)}.
|
||||
* </p>
|
||||
* <p>
|
||||
* One Database can be nominated as the 'default/primary' Database. Many
|
||||
* methods on the DB singleton such as {@link DB#find(Class)} are just a
|
||||
* convenient way of using the 'default/primary' Database.
|
||||
* </p>
|
||||
*/
|
||||
public class DatabaseFactory {
|
||||
|
||||
@@ -48,7 +45,7 @@ public class DatabaseFactory {
|
||||
public static void initialiseContainer(ContainerConfig containerConfig) {
|
||||
lock.lock();
|
||||
try {
|
||||
getContainer(containerConfig);
|
||||
container(containerConfig);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
@@ -60,7 +57,7 @@ public class DatabaseFactory {
|
||||
public static Database create(String name) {
|
||||
lock.lock();
|
||||
try {
|
||||
return getContainer(null).createServer(name);
|
||||
return container(null).createServer(name);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
@@ -68,6 +65,16 @@ public class DatabaseFactory {
|
||||
|
||||
/**
|
||||
* Create using the DatabaseConfig object to configure the database.
|
||||
*
|
||||
* <pre>{@code
|
||||
*
|
||||
* DatabaseConfig config = new DatabaseConfig();
|
||||
* config.setName("db");
|
||||
* config.loadProperties();
|
||||
*
|
||||
* Database database = DatabaseFactory.create(config);
|
||||
*
|
||||
* }</pre>
|
||||
*/
|
||||
public static Database create(DatabaseConfig config) {
|
||||
lock.lock();
|
||||
@@ -115,7 +122,6 @@ public class DatabaseFactory {
|
||||
* Shutdown gracefully all Database instances cleaning up any resources as required.
|
||||
* <p>
|
||||
* This is typically invoked via JVM shutdown hook and not explicitly called.
|
||||
* </p>
|
||||
*/
|
||||
public static void shutdown() {
|
||||
lock.lock();
|
||||
@@ -127,15 +133,15 @@ public class DatabaseFactory {
|
||||
}
|
||||
|
||||
private static Database createInternal(DatabaseConfig config) {
|
||||
return getContainer(config.getContainerConfig()).createServer(config);
|
||||
return container(config.getContainerConfig()).createServer(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the EbeanContainer initialising it if necessary.
|
||||
* Return the SpiContainer initialising it if necessary.
|
||||
*
|
||||
* @param containerConfig the configuration controlling clustering communication
|
||||
*/
|
||||
private static SpiContainer getContainer(ContainerConfig containerConfig) {
|
||||
private static SpiContainer container(ContainerConfig containerConfig) {
|
||||
// thread safe in that all calling methods hold lock
|
||||
if (container != null) {
|
||||
return container;
|
||||
|
||||
@@ -45,14 +45,6 @@ public interface ProfileLocation {
|
||||
*/
|
||||
String label();
|
||||
|
||||
/**
|
||||
* Return a hash of the location that intentionally excludes the line number.
|
||||
* <p>
|
||||
* The hash is expected to be stable regardless of line number in the source file
|
||||
* so that is identifies the class and method location over a long time.
|
||||
*/
|
||||
long hash();
|
||||
|
||||
/**
|
||||
* Return the full location.
|
||||
*/
|
||||
|
||||
@@ -395,6 +395,15 @@ public final class EntityBeanIntercept implements Serializable {
|
||||
this.owner._ebean_setEmbeddedLoaded();
|
||||
this.lazyLoadProperty = -1;
|
||||
this.origValues = null;
|
||||
// after save, transfer the mutable next values back to mutable info
|
||||
if (mutableNext != null) {
|
||||
for (int i = 0; i < mutableNext.length; i++) {
|
||||
MutableValueNext next = mutableNext[i];
|
||||
if (next != null) {
|
||||
mutableInfo(i, next.info());
|
||||
}
|
||||
}
|
||||
}
|
||||
this.mutableNext = null;
|
||||
for (int i = 0; i < flags.length; i++) {
|
||||
flags[i] &= ~(FLAG_CHANGED_PROP | FLAG_ORIG_VALUE_SET);
|
||||
@@ -1223,9 +1232,7 @@ public final class EntityBeanIntercept implements Serializable {
|
||||
if (mutableNext == null) {
|
||||
return null;
|
||||
}
|
||||
final MutableValueNext next = mutableNext[propertyIndex];
|
||||
mutableInfo(propertyIndex, next.info());
|
||||
return next.content();
|
||||
return mutableNext[propertyIndex].content();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -319,6 +319,8 @@ public class DatabaseConfig {
|
||||
*/
|
||||
private ExternalTransactionManager externalTransactionManager;
|
||||
|
||||
private boolean skipDataSourceCheck;
|
||||
|
||||
/**
|
||||
* The data source (if programmatically provided).
|
||||
*/
|
||||
@@ -1651,6 +1653,20 @@ public class DatabaseConfig {
|
||||
this.autoTuneConfig = autoTuneConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the startup DataSource check should be skipped.
|
||||
*/
|
||||
public boolean skipDataSourceCheck() {
|
||||
return skipDataSourceCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true to skip the startup DataSource check.
|
||||
*/
|
||||
public void setSkipDataSourceCheck(boolean skipDataSourceCheck) {
|
||||
this.skipDataSourceCheck = skipDataSourceCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DataSource.
|
||||
*/
|
||||
@@ -2932,6 +2948,7 @@ public class DatabaseConfig {
|
||||
jsonDate = p.getEnum(JsonConfig.Date.class, "jsonDate", jsonDate);
|
||||
jsonMutationDetection = p.getEnum(MutationDetection.class, "jsonMutationDetection", jsonMutationDetection);
|
||||
|
||||
skipDataSourceCheck = p.getBoolean("skipDataSourceCheck", skipDataSourceCheck);
|
||||
runMigration = p.getBoolean("migration.run", runMigration);
|
||||
ddlGenerate = p.getBoolean("ddl.generate", ddlGenerate);
|
||||
ddlRun = p.getBoolean("ddl.run", ddlRun);
|
||||
|
||||
@@ -14,10 +14,9 @@ import java.util.List;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* Manages the shutdown of the JVM Runtime.
|
||||
* Manages the shutdown of Ebean.
|
||||
* <p>
|
||||
* Makes sure all the resources are shutdown properly and in order.
|
||||
* </p>
|
||||
*/
|
||||
public final class ShutdownManager {
|
||||
|
||||
@@ -44,6 +43,9 @@ public final class ShutdownManager {
|
||||
private ShutdownManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the container (potentially with cluster management).
|
||||
*/
|
||||
public static void registerContainer(SpiContainer ebeanContainer) {
|
||||
container = ebeanContainer;
|
||||
}
|
||||
@@ -94,7 +96,7 @@ public final class ShutdownManager {
|
||||
/**
|
||||
* Register the shutdown hook with the Runtime.
|
||||
*/
|
||||
protected static void registerShutdownHook() {
|
||||
private static void registerShutdownHook() {
|
||||
lock.lock();
|
||||
try {
|
||||
String value = System.getProperty("ebean.registerShutdownHook");
|
||||
@@ -123,13 +125,10 @@ public final class ShutdownManager {
|
||||
// Already run shutdown...
|
||||
return;
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Shutting down");
|
||||
}
|
||||
|
||||
stopping = true;
|
||||
|
||||
deregisterShutdownHook();
|
||||
|
||||
String shutdownRunner = System.getProperty("ebean.shutdown.runnable");
|
||||
@@ -147,7 +146,6 @@ public final class ShutdownManager {
|
||||
// shutdown cluster networking if active
|
||||
container.shutdown();
|
||||
}
|
||||
|
||||
// shutdown any registered servers that have not
|
||||
// already been shutdown manually
|
||||
for (Database server : databases) {
|
||||
@@ -158,7 +156,6 @@ public final class ShutdownManager {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if ("true".equalsIgnoreCase(System.getProperty("ebean.datasource.deregisterAllDrivers", "false"))) {
|
||||
deregisterAllJdbcDrivers();
|
||||
}
|
||||
@@ -168,15 +165,15 @@ public final class ShutdownManager {
|
||||
}
|
||||
|
||||
private static void deregisterAllJdbcDrivers() {
|
||||
// This manually deregisters all JDBC drivers
|
||||
// This manually de-registers all JDBC drivers
|
||||
Enumeration<Driver> drivers = DriverManager.getDrivers();
|
||||
while (drivers.hasMoreElements()) {
|
||||
Driver driver = drivers.nextElement();
|
||||
try {
|
||||
logger.info("Deregistering jdbc driver: " + driver);
|
||||
logger.info("De-registering jdbc driver: " + driver);
|
||||
DriverManager.deregisterDriver(driver);
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error deregistering driver " + driver, e);
|
||||
logger.error("Error de-registering driver " + driver, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,6 +206,9 @@ public final class ShutdownManager {
|
||||
}
|
||||
|
||||
private static class ShutdownHook extends Thread {
|
||||
private ShutdownHook() {
|
||||
super("EbeanHook");
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
ShutdownManager.shutdown();
|
||||
|
||||
@@ -45,15 +45,8 @@ public interface MetaQueryMetric extends MetaTimedMetric {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the hash of the sql.
|
||||
* Return the hash of the plan.
|
||||
*/
|
||||
long sqlHash();
|
||||
String hash();
|
||||
|
||||
/**
|
||||
* Migrate to sqlHash().
|
||||
*/
|
||||
@Deprecated
|
||||
default long getSqlHash() {
|
||||
return sqlHash();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface MetaQueryPlan {
|
||||
/**
|
||||
* Return the hash of the plan.
|
||||
*/
|
||||
long sqlHash();
|
||||
String hash();
|
||||
|
||||
/**
|
||||
* Return a description of the bind values.
|
||||
|
||||
@@ -6,14 +6,6 @@ package io.ebean.meta;
|
||||
*/
|
||||
public interface MetaTimedMetric extends MetaMetric {
|
||||
|
||||
/**
|
||||
* Return the metric location hash if defined.
|
||||
* <p>
|
||||
* This hash excludes line number with the intention of being stable over time
|
||||
* as code changes move the source line (but the method is the same).
|
||||
*/
|
||||
long locationHash();
|
||||
|
||||
/**
|
||||
* Return the metric location if defined.
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,7 @@ package io.ebean.meta;
|
||||
public class MetricData {
|
||||
|
||||
private String name;
|
||||
private long sqlHash;
|
||||
private String hash;
|
||||
private String loc;
|
||||
private String sql;
|
||||
|
||||
@@ -14,7 +14,6 @@ public class MetricData {
|
||||
private Long mean;
|
||||
private Long max;
|
||||
private Long total;
|
||||
private long locHash;
|
||||
|
||||
public MetricData(String name) {
|
||||
this.name = name;
|
||||
@@ -31,20 +30,12 @@ public class MetricData {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getSqlHash() {
|
||||
return sqlHash;
|
||||
public String getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public void setSqlHash(long sqlHash) {
|
||||
this.sqlHash = sqlHash;
|
||||
}
|
||||
|
||||
public void setLocHash(long locHash) {
|
||||
this.locHash = locHash;
|
||||
}
|
||||
|
||||
public long getLocHash() {
|
||||
return locHash;
|
||||
public void setHash(String hash) {
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
public String getLoc() {
|
||||
|
||||
@@ -10,7 +10,7 @@ public class QueryPlanInit {
|
||||
|
||||
private boolean all;
|
||||
|
||||
private Set<Long> hashes = new HashSet<>();
|
||||
private Set<String> hashes = new HashSet<>();
|
||||
|
||||
private long thresholdMicros;
|
||||
|
||||
@@ -47,21 +47,21 @@ public class QueryPlanInit {
|
||||
/**
|
||||
* Return true if the query plan should be initiated based on it's hash.
|
||||
*/
|
||||
public boolean includeHash(long sqlHash) {
|
||||
return all || hashes.contains(sqlHash);
|
||||
public boolean includeHash(String hash) {
|
||||
return all || hashes.contains(hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the specific hashes that we want to collect query plans on.
|
||||
*/
|
||||
public Set<Long> sqlHashes() {
|
||||
public Set<String> hashes() {
|
||||
return hashes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the specific hashes that we want to collect query plans on.
|
||||
*/
|
||||
public void sqlHashes(Set<Long> hashes) {
|
||||
public void hashes(Set<String> hashes) {
|
||||
this.hashes = hashes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,6 @@ public interface TimedMetricStats extends MetaTimedMetric {
|
||||
*/
|
||||
void setLocation(String location);
|
||||
|
||||
/**
|
||||
* Additionally set the location hash.
|
||||
*/
|
||||
void setLocationHash(long locationHash);
|
||||
|
||||
/**
|
||||
* Override the name based on profile location.
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</parent>
|
||||
<!-- <parent>-->
|
||||
<!-- <groupId>org.avaje</groupId>-->
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:git@github.com:ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-parent-12.11.0</tag>
|
||||
<tag>ebean-parent-12.11.1</tag>
|
||||
</scm>
|
||||
|
||||
<name>ebean autotune</name>
|
||||
@@ -26,7 +26,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
+2
-1
@@ -146,7 +146,8 @@ public class BaseQueryTuner {
|
||||
case ID_LIST:
|
||||
case UPDATE:
|
||||
case DELETE:
|
||||
case SUBQUERY:
|
||||
case SQ_EXISTS:
|
||||
case SQ_IN:
|
||||
return false;
|
||||
default:
|
||||
// not using autoTune when explicitly loading the l2 bean cache
|
||||
|
||||
+15
-15
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</parent>
|
||||
|
||||
<name>ebean bom</name>
|
||||
@@ -81,88 +81,88 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-api</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core-type</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-ddl-generator</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-externalmapping-api</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-externalmapping-xml</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-autotune</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-querybean</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>querybean-generator</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>kotlin-querybean-generator</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-test</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-postgis</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-redis</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ebean-core-type</artifactId>
|
||||
@@ -16,7 +16,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-api</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
+10
-19
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ebean-core</artifactId>
|
||||
@@ -15,27 +15,18 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:git@github.com:ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-parent-12.11.0</tag>
|
||||
<tag>ebean-parent-12.11.1</tag>
|
||||
</scm>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<!-- Note: to use this profile, you need to download manually the db2jcc4 driver.
|
||||
After that, install it into your local maven repository:
|
||||
|
||||
mvn install:install-file \
|
||||
-Dfile=db2jcc4.jar \
|
||||
-DgroupId=com.ibm.jdbc \
|
||||
-DartifactId=db2jcc4 \
|
||||
-Dversion=4.23.42 \
|
||||
-Dpackaging=jar
|
||||
-->
|
||||
<id>db2</id>
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/com.ibm.db2/jcc -->
|
||||
<dependency>
|
||||
<groupId>com.ibm.jdbc</groupId>
|
||||
<artifactId>db2jcc4</artifactId>
|
||||
<version>4.23.42</version>
|
||||
<groupId>com.ibm.db2</groupId>
|
||||
<artifactId>jcc</artifactId>
|
||||
<version>11.5.5.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -72,7 +63,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-ddl-generator</artifactId>
|
||||
<version>12.9.4-RC1</version>
|
||||
<version>12.11.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -87,19 +78,19 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-api</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core-type</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-externalmapping-api</artifactId>
|
||||
<version>12.11.0</version>
|
||||
<version>12.11.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -4,11 +4,7 @@ import io.ebeaninternal.server.persist.MultiValueWrapper;
|
||||
import io.ebeaninternal.server.querydefn.NaturalKeyBindParam;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
@@ -54,12 +50,11 @@ public class BindParams implements Serializable {
|
||||
positionedParameters.clear();
|
||||
}
|
||||
|
||||
public int queryBindHash() {
|
||||
int hc = namedParameters.hashCode();
|
||||
for (Param positionedParameter : positionedParameters) {
|
||||
hc = hc * 92821 + positionedParameter.hashCode();
|
||||
public void queryBindHash(BindValuesKey key) {
|
||||
key.add(positionedParameters.size());
|
||||
for (Param param : positionedParameters) {
|
||||
param.queryBindHash(key);
|
||||
}
|
||||
return hc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,7 +419,14 @@ public class BindParams implements Serializable {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o != null && (o == this || (o instanceof Param) && hashCode() == o.hashCode());
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Param param = (Param) o;
|
||||
return isInParam == param.isInParam && isOutParam == param.isOutParam && type == param.type && Objects.equals(inValue, param.inValue);
|
||||
}
|
||||
|
||||
void queryBindHash(BindValuesKey key) {
|
||||
key.add(isInParam).add(isOutParam).add(type).add(inValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package io.ebeaninternal.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* BindValues used for L2 query cache key matching.
|
||||
* <p>
|
||||
* The equals/hashCode implementation must meet the requirement that the query bind values
|
||||
* match for L2 query cache hit (given the query plan hash is already a match).
|
||||
*/
|
||||
public class BindValuesKey {
|
||||
|
||||
private final List<Object> values = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Add a bind value.
|
||||
*/
|
||||
public BindValuesKey add(Object value) {
|
||||
values.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof BindValuesKey && ((BindValuesKey) obj).values.equals(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return values.hashCode();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package io.ebeaninternal.api;
|
||||
|
||||
import io.ebean.annotation.Platform;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Helper to indicate that an EbeanServer should come up offline
|
||||
@@ -10,8 +8,6 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class DbOffline {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DbOffline.class);
|
||||
|
||||
private static final String KEY = "ebean.dboffline";
|
||||
|
||||
private static boolean generateMigration;
|
||||
@@ -73,7 +69,6 @@ public class DbOffline {
|
||||
public static void reset() {
|
||||
generateMigration = false;
|
||||
System.clearProperty(KEY);
|
||||
logger.debug("reset");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,15 +6,14 @@ package io.ebeaninternal.api;
|
||||
public class HashQuery {
|
||||
|
||||
private final CQueryPlanKey planHash;
|
||||
|
||||
private final int bindHash;
|
||||
private final BindValuesKey bindValuesKey;
|
||||
|
||||
/**
|
||||
* Create the HashQuery.
|
||||
*/
|
||||
public HashQuery(CQueryPlanKey planHash, int bindHash) {
|
||||
public HashQuery(CQueryPlanKey planHash, BindValuesKey bindValuesKey) {
|
||||
this.planHash = planHash;
|
||||
this.bindHash = bindHash;
|
||||
this.bindValuesKey = bindValuesKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,7 +24,7 @@ public class HashQuery {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hc = 92821 * planHash.hashCode();
|
||||
hc = 92821 * hc + bindHash;
|
||||
hc = 92821 * hc + bindValuesKey.hashCode();
|
||||
return hc;
|
||||
}
|
||||
|
||||
@@ -37,8 +36,7 @@ public class HashQuery {
|
||||
if (!(obj instanceof HashQuery)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HashQuery e = (HashQuery) obj;
|
||||
return e.bindHash == bindHash && e.planHash.equals(planHash);
|
||||
return e.bindValuesKey.equals(bindValuesKey) && e.planHash.equals(planHash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,9 +92,7 @@ public class LoadBeanRequest extends LoadRequest {
|
||||
* Return the list of Id values for the beans in the lazy load buffer.
|
||||
*/
|
||||
public List<Object> getIdList() {
|
||||
|
||||
List<Object> idList = new ArrayList<>();
|
||||
|
||||
BeanDescriptor<?> desc = loadBuffer.getBeanDescriptor();
|
||||
for (EntityBeanIntercept ebi : batch) {
|
||||
idList.add(desc.getId(ebi.getOwner()));
|
||||
@@ -106,10 +104,8 @@ public class LoadBeanRequest extends LoadRequest {
|
||||
* Configure the query for lazy loading execution.
|
||||
*/
|
||||
public void configureQuery(SpiQuery<?> query, List<Object> idList) {
|
||||
|
||||
query.setMode(SpiQuery.Mode.LAZYLOAD_BEAN);
|
||||
query.setPersistenceContext(loadBuffer.getPersistenceContext());
|
||||
|
||||
String mode = isLazy() ? "+lazy" : "+query";
|
||||
query.setLoadDescription(mode, getDescription());
|
||||
|
||||
@@ -117,9 +113,7 @@ public class LoadBeanRequest extends LoadRequest {
|
||||
// cascade the batch size (if set) for further lazy loading
|
||||
query.setLazyLoadBatchSize(getBatchSize());
|
||||
}
|
||||
|
||||
loadBuffer.configureQuery(query, lazyLoadProperty);
|
||||
|
||||
if (idList.size() == 1) {
|
||||
query.where().idEq(idList.get(0));
|
||||
} else {
|
||||
@@ -131,19 +125,16 @@ public class LoadBeanRequest extends LoadRequest {
|
||||
* Load the beans into the L2 cache if that is requested and check for load failures due to deletes.
|
||||
*/
|
||||
public void postLoad(List<?> list) {
|
||||
|
||||
Set<Object> loadedIds = new HashSet<>();
|
||||
|
||||
BeanDescriptor<?> desc = loadBuffer.getBeanDescriptor();
|
||||
// collect Ids and maybe load bean cache
|
||||
for (Object aList : list) {
|
||||
EntityBean loadedBean = (EntityBean) aList;
|
||||
for (Object bean : list) {
|
||||
EntityBean loadedBean = (EntityBean) bean;
|
||||
loadedIds.add(desc.getId(loadedBean));
|
||||
}
|
||||
if (isLoadCache()) {
|
||||
desc.cacheBeanPutAll(list);
|
||||
}
|
||||
|
||||
if (lazyLoadProperty != null) {
|
||||
for (EntityBeanIntercept ebi : batch) {
|
||||
// check if the underlying row in DB was deleted. Mark the bean as 'failed' if
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.event.readaudit.ReadAuditLogger;
|
||||
import io.ebean.event.readaudit.ReadAuditPrepare;
|
||||
import io.ebean.meta.MetricVisitor;
|
||||
import io.ebeaninternal.api.SpiQuery.Type;
|
||||
import io.ebeaninternal.server.core.SpiResultSet;
|
||||
import io.ebeaninternal.server.core.timezone.DataTimeZone;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
@@ -149,7 +150,7 @@ public interface SpiEbeanServer extends ExtendedServer, EbeanServer, BeanCollect
|
||||
/**
|
||||
* Compile a query.
|
||||
*/
|
||||
<T> CQuery<T> compileQuery(Query<T> query, Transaction t);
|
||||
<T> CQuery<T> compileQuery(Type type, Query<T> query, Transaction t);
|
||||
|
||||
/**
|
||||
* Execute the findId's query but without copying the query.
|
||||
|
||||
@@ -54,9 +54,9 @@ public interface SpiExpression extends Expression {
|
||||
void queryPlanHash(StringBuilder builder);
|
||||
|
||||
/**
|
||||
* Return the hash value for the values that will be bound.
|
||||
* Build the key for bind values of the query.
|
||||
*/
|
||||
int queryBindHash();
|
||||
void queryBindKey(BindValuesKey key);
|
||||
|
||||
/**
|
||||
* Return true if the expression is the same with respect to bind values.
|
||||
|
||||
@@ -84,7 +84,7 @@ public interface SpiQuery<T> extends Query<T>, SpiQueryFetch, TxnProfileEventCod
|
||||
/**
|
||||
* Find single attribute.
|
||||
*/
|
||||
ATTRIBUTE(FIND_ATTRIBUTE, "findAttribute"),
|
||||
ATTRIBUTE(FIND_ATTRIBUTE, "findAttribute", false, false),
|
||||
|
||||
/**
|
||||
* Find rowCount.
|
||||
@@ -92,9 +92,14 @@ public interface SpiQuery<T> extends Query<T>, SpiQueryFetch, TxnProfileEventCod
|
||||
COUNT(FIND_COUNT, "findCount"),
|
||||
|
||||
/**
|
||||
* A subquery used as part of a where clause.
|
||||
* A subquery used as part of an exists where clause.
|
||||
*/
|
||||
SUBQUERY(FIND_SUBQUERY, "subquery"),
|
||||
SQ_EXISTS(FIND_SUBQUERY, "sqExists", false, false),
|
||||
|
||||
/**
|
||||
* A subquery used as part of an in where clause.
|
||||
*/
|
||||
SQ_IN(FIND_SUBQUERY, "sqIn", false, false),
|
||||
|
||||
/**
|
||||
* Delete query.
|
||||
@@ -107,17 +112,21 @@ public interface SpiQuery<T> extends Query<T>, SpiQueryFetch, TxnProfileEventCod
|
||||
UPDATE(FIND_UPDATE, "update", true);
|
||||
|
||||
private final boolean update;
|
||||
private final boolean defaultSelect;
|
||||
private final String profileEventId;
|
||||
private final String label;
|
||||
|
||||
Type(String profileEventId, String label) {
|
||||
this(profileEventId, label, false);
|
||||
this(profileEventId, label, false, true);
|
||||
}
|
||||
|
||||
Type(String profileEventId, String label, boolean update) {
|
||||
this(profileEventId, label, update, true);
|
||||
}
|
||||
Type(String profileEventId, String label, boolean update, boolean defaultSelect) {
|
||||
this.profileEventId = profileEventId;
|
||||
this.label = label;
|
||||
this.update = update;
|
||||
this.defaultSelect = defaultSelect;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,6 +136,13 @@ public interface SpiQuery<T> extends Query<T>, SpiQueryFetch, TxnProfileEventCod
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this allows default select clause.
|
||||
*/
|
||||
public boolean defaultSelect() {
|
||||
return defaultSelect;
|
||||
}
|
||||
|
||||
public String profileEventId() {
|
||||
return profileEventId;
|
||||
}
|
||||
@@ -629,13 +645,11 @@ public interface SpiQuery<T> extends Query<T>, SpiQueryFetch, TxnProfileEventCod
|
||||
CQueryPlanKey prepare(SpiOrmQueryRequest<T> request);
|
||||
|
||||
/**
|
||||
* Calculate a hash based on the bind values used in the query.
|
||||
* Build the key for the bind values used in the query (for l2 query cache).
|
||||
* <p>
|
||||
* Combined with queryPlanHash() to return getQueryHash (a unique hash for a
|
||||
* query).
|
||||
* </p>
|
||||
* Combined with queryPlanHash() to return queryHash (a unique key for a query).
|
||||
*/
|
||||
int queryBindHash();
|
||||
void queryBindKey(BindValuesKey key);
|
||||
|
||||
/**
|
||||
* Identifies queries that are exactly the same including bind variables.
|
||||
|
||||
@@ -20,7 +20,7 @@ public interface SpiQueryPlan {
|
||||
/**
|
||||
* The hash of the sql.
|
||||
*/
|
||||
long getSqlHash();
|
||||
String getHash();
|
||||
|
||||
/**
|
||||
* The SQL for the query plan.
|
||||
|
||||
+26
-19
@@ -11,6 +11,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
@@ -37,7 +38,7 @@ public class DefaultServerCache implements ServerCache {
|
||||
/**
|
||||
* The underlying map (ConcurrentHashMap or similar)
|
||||
*/
|
||||
protected final Map<Object, CacheEntry> map;
|
||||
protected final Map<Object, SoftReference<CacheEntry>> map;
|
||||
|
||||
protected final CountMetric hitCount;
|
||||
protected final CountMetric missCount;
|
||||
@@ -199,7 +200,8 @@ public class DefaultServerCache implements ServerCache {
|
||||
* Get the cache entry - override for query cache to validate dependent tables.
|
||||
*/
|
||||
protected CacheEntry getCacheEntry(Object id) {
|
||||
return map.get(key(id));
|
||||
final SoftReference<CacheEntry> ref = map.get(key(id));
|
||||
return ref != null ? ref.get() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -213,7 +215,7 @@ public class DefaultServerCache implements ServerCache {
|
||||
@Override
|
||||
public void put(Object id, Object value) {
|
||||
Object key = key(id);
|
||||
map.put(key, new CacheEntry(key, value));
|
||||
map.put(key, new SoftReference<>(new CacheEntry(key, value)));
|
||||
putCount.increment();
|
||||
}
|
||||
|
||||
@@ -222,8 +224,8 @@ public class DefaultServerCache implements ServerCache {
|
||||
*/
|
||||
@Override
|
||||
public void remove(Object id) {
|
||||
CacheEntry entry = map.remove(key(id));
|
||||
if (entry != null) {
|
||||
SoftReference<CacheEntry> entry = map.remove(key(id));
|
||||
if (entry != null && entry.get() != null) {
|
||||
removeCount.increment();
|
||||
}
|
||||
}
|
||||
@@ -266,6 +268,7 @@ public class DefaultServerCache implements ServerCache {
|
||||
long startNanos = System.nanoTime();
|
||||
|
||||
long trimmedByIdle = 0;
|
||||
long trimmedByGC = 0;
|
||||
long trimmedByTTL = 0;
|
||||
long trimmedByLRU = 0;
|
||||
|
||||
@@ -274,10 +277,14 @@ public class DefaultServerCache implements ServerCache {
|
||||
long idleExpireNano = startNanos - TimeUnit.SECONDS.toNanos(maxIdleSecs);
|
||||
long ttlExpireNano = startNanos - TimeUnit.SECONDS.toNanos(maxSecsToLive);
|
||||
|
||||
Iterator<CacheEntry> it = map.values().iterator();
|
||||
Iterator<SoftReference<CacheEntry>> it = map.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
CacheEntry cacheEntry = it.next();
|
||||
if (maxIdleSecs > 0 && idleExpireNano > cacheEntry.getLastAccessTime()) {
|
||||
SoftReference<CacheEntry> ref = it.next();
|
||||
final CacheEntry cacheEntry = ref.get();
|
||||
if (cacheEntry == null) {
|
||||
it.remove();
|
||||
trimmedByGC++;
|
||||
} else if (maxIdleSecs > 0 && idleExpireNano > cacheEntry.getLastAccessTime()) {
|
||||
it.remove();
|
||||
trimmedByIdle++;
|
||||
|
||||
@@ -290,27 +297,27 @@ public class DefaultServerCache implements ServerCache {
|
||||
}
|
||||
}
|
||||
|
||||
if (trimForMaxSize > 0) {
|
||||
trimmedByLRU = activeList.size() - maxSize;
|
||||
if (trimmedByLRU > 0) {
|
||||
// sort into last access time ascending
|
||||
activeList.sort(BY_LAST_ACCESS);
|
||||
int trimSize = getTrimSize();
|
||||
for (int i = trimSize; i < activeList.size(); i++) {
|
||||
// remove if still in the cache
|
||||
map.remove(activeList.get(i).getKey());
|
||||
if (trimForMaxSize > 0 && activeList.size() > maxSize) {
|
||||
// sort into last access time ascending
|
||||
activeList.sort(BY_LAST_ACCESS);
|
||||
int trimSize = getTrimSize();
|
||||
for (int i = trimSize; i < activeList.size(); i++) {
|
||||
// remove if still in the cache
|
||||
if (map.remove(activeList.get(i).getKey()) != null) {
|
||||
trimmedByLRU++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
evictCount.add(trimmedByIdle);
|
||||
evictCount.add(trimmedByGC);
|
||||
evictCount.add(trimmedByTTL);
|
||||
evictCount.add(trimmedByLRU);
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
long exeMicros = TimeUnit.MICROSECONDS.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS);
|
||||
logger.trace("Executed trim of cache {} in [{}]millis idle[{}] timeToLive[{}] accessTime[{}]"
|
||||
, name, exeMicros, trimmedByIdle, trimmedByTTL, trimmedByLRU);
|
||||
logger.trace("Executed trim of cache {} in [{}]millis idle[{}] timeToLive[{}] accessTime[{}] gc[{}]",
|
||||
name, exeMicros, trimmedByIdle, trimmedByTTL, trimmedByLRU, trimmedByGC);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -4,7 +4,9 @@ import io.ebean.cache.QueryCacheEntryValidate;
|
||||
import io.ebean.cache.ServerCacheConfig;
|
||||
import io.ebean.cache.ServerCacheOptions;
|
||||
import io.ebean.config.CurrentTenantProvider;
|
||||
import io.ebeaninternal.server.cache.DefaultServerCache.CacheEntry;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -17,13 +19,13 @@ public class DefaultServerCacheConfig {
|
||||
private int maxSecsToLive;
|
||||
private int trimFrequency;
|
||||
|
||||
private Map<Object, DefaultServerCache.CacheEntry> map;
|
||||
private Map<Object, SoftReference<CacheEntry>> map;
|
||||
|
||||
public DefaultServerCacheConfig(ServerCacheConfig config) {
|
||||
this(config, new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
public DefaultServerCacheConfig(ServerCacheConfig config, Map<Object, DefaultServerCache.CacheEntry> map) {
|
||||
public DefaultServerCacheConfig(ServerCacheConfig config, Map<Object, SoftReference<CacheEntry>> map) {
|
||||
this.config = config;
|
||||
this.map = map;
|
||||
|
||||
@@ -50,7 +52,7 @@ public class DefaultServerCacheConfig {
|
||||
return config.getShortName();
|
||||
}
|
||||
|
||||
public Map<Object, DefaultServerCache.CacheEntry> getMap() {
|
||||
public Map<Object, SoftReference<CacheEntry>> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -3,6 +3,8 @@ package io.ebeaninternal.server.cache;
|
||||
import io.ebean.cache.QueryCacheEntry;
|
||||
import io.ebean.cache.QueryCacheEntryValidate;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
|
||||
/**
|
||||
* Server cache for query caching.
|
||||
* <p>
|
||||
@@ -27,7 +29,8 @@ public class DefaultServerQueryCache extends DefaultServerCache {
|
||||
@Override
|
||||
protected CacheEntry getCacheEntry(Object id) {
|
||||
Object key = key(id);
|
||||
CacheEntry entry = map.get(key);
|
||||
final SoftReference<CacheEntry> ref = map.get(key);
|
||||
CacheEntry entry = ref != null ? ref.get() : null;
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -23,25 +23,16 @@ import javax.persistence.PersistenceException;
|
||||
public abstract class AbstractSqlQueryRequest implements CancelableQuery {
|
||||
|
||||
protected final SpiSqlBinding query;
|
||||
|
||||
protected final SpiEbeanServer server;
|
||||
|
||||
protected SpiTransaction transaction;
|
||||
|
||||
private boolean createdTransaction;
|
||||
|
||||
protected String sql;
|
||||
|
||||
protected ResultSet resultSet;
|
||||
|
||||
protected String bindLog = "";
|
||||
|
||||
protected PreparedStatement pstmt;
|
||||
|
||||
protected long startNano;
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
|
||||
/**
|
||||
* Create the BeanFindRequest.
|
||||
*/
|
||||
@@ -161,7 +152,8 @@ public abstract class AbstractSqlQueryRequest implements CancelableQuery {
|
||||
this.bindLog = binder.bind(bindParams, pstmt, conn);
|
||||
}
|
||||
if (isLogSql()) {
|
||||
transaction.logSql(Str.add(TrimLogSql.trim(sql), "; --bind(", bindLog, ")"));
|
||||
long micros = (System.nanoTime() - startNano) / 1000L;
|
||||
transaction.logSql(Str.add(TrimLogSql.trim(sql), "; --bind(", bindLog, ") --micros(", micros + ")"));
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
|
||||
@@ -33,7 +33,7 @@ public final class BindPadding {
|
||||
* Extra padding on binding id's in order to get better hit ratio on DB prepared statements / query plans.
|
||||
*/
|
||||
static int padding(int size) {
|
||||
if (size == 1) {
|
||||
if (size <= 1) {
|
||||
return 0;
|
||||
}
|
||||
if (size <= 5) {
|
||||
|
||||
@@ -36,9 +36,8 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* Create a DatabasePlatform from the configuration.
|
||||
* <p>
|
||||
* Will used platform name or use the meta data from the JDBC driver to
|
||||
* Will used platform name or use the metadata from the JDBC driver to
|
||||
* determine the platform automatically.
|
||||
* </p>
|
||||
*/
|
||||
public class DatabasePlatformFactory {
|
||||
|
||||
@@ -54,14 +53,12 @@ public class DatabasePlatformFactory {
|
||||
logger.info("offline platform [{}]", offlinePlatform);
|
||||
return byDatabaseName(offlinePlatform);
|
||||
}
|
||||
|
||||
if (config.getDatabasePlatformName() != null) {
|
||||
// choose based on dbName
|
||||
return byDatabaseName(config.getDatabasePlatformName());
|
||||
}
|
||||
|
||||
if (config.getDataSourceConfig().isOffline()) {
|
||||
throw new PersistenceException("You must specify a DatabasePlatformName when you are offline");
|
||||
throw new PersistenceException("DatabasePlatformName must be specified with offline mode");
|
||||
}
|
||||
// guess using meta data from driver
|
||||
return byDataSource(config.getDataSource());
|
||||
@@ -142,10 +139,10 @@ public class DatabasePlatformFactory {
|
||||
* Find the platform by the metaData.getDatabaseProductName().
|
||||
*/
|
||||
private DatabasePlatform byDatabaseMeta(DatabaseMetaData metaData, Connection connection) throws SQLException {
|
||||
|
||||
String dbProductName = metaData.getDatabaseProductName().toLowerCase();
|
||||
final int majorVersion = metaData.getDatabaseMajorVersion();
|
||||
final int minorVersion = metaData.getDatabaseMinorVersion();
|
||||
logger.debug("platform for productName[{}] version[{}.{}]", dbProductName, majorVersion, minorVersion);
|
||||
|
||||
if (dbProductName.contains("oracle")) {
|
||||
return oracleVersion(majorVersion);
|
||||
@@ -206,7 +203,6 @@ public class DatabasePlatformFactory {
|
||||
} catch (SQLException e) {
|
||||
logger.warn("Error running detection query on Postgres", e);
|
||||
}
|
||||
|
||||
if (majorVersion <= 9) {
|
||||
return new Postgres9Platform();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
*/
|
||||
public class DefaultContainer implements SpiContainer {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("io.ebean.internal.DefaultContainer");
|
||||
private static final Logger logger = LoggerFactory.getLogger("io.ebean.DB");
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final ClusterManager clusterManager;
|
||||
@@ -77,9 +77,10 @@ public class DefaultContainer implements SpiContainer {
|
||||
public SpiEbeanServer createServer(DatabaseConfig config) {
|
||||
lock.lock();
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
applyConfigServices(config);
|
||||
setNamingConvention(config);
|
||||
BootupClasses bootupClasses = getBootupClasses(config);
|
||||
BootupClasses bootupClasses = bootupClasses(config);
|
||||
|
||||
boolean online = true;
|
||||
if (config.isDocStoreOnly()) {
|
||||
@@ -101,22 +102,18 @@ public class DefaultContainer implements SpiContainer {
|
||||
// use a configured DbEncrypt rather than the platform default
|
||||
config.getDatabasePlatform().setDbEncrypt(config.getDbEncrypt());
|
||||
}
|
||||
|
||||
// inform the NamingConvention of the associated DatabasePlatform
|
||||
config.getNamingConvention().setDatabasePlatform(config.getDatabasePlatform());
|
||||
|
||||
// executor and l2 caching service setup early (used during server construction)
|
||||
SpiBackgroundExecutor executor = createBackgroundExecutor(config);
|
||||
InternalConfiguration c = new InternalConfiguration(online, clusterManager, executor, config, bootupClasses);
|
||||
|
||||
DefaultServer server = new DefaultServer(c, c.cacheManager());
|
||||
|
||||
// generate and run DDL if required
|
||||
// if there are any other tasks requiring action in their plugins, do them as well
|
||||
// generate and run DDL if required plus other plugins
|
||||
if (!DbOffline.isGenerateMigration()) {
|
||||
startServer(online, server);
|
||||
}
|
||||
DbOffline.reset();
|
||||
logger.info("started database[{}] platform[{}] in {}ms", config.getName(), config.getDatabasePlatform().getPlatform(), System.currentTimeMillis() - start);
|
||||
return server;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
@@ -161,9 +158,8 @@ public class DefaultContainer implements SpiContainer {
|
||||
* Get the entities, scalarTypes, Listeners etc combining the class registered
|
||||
* ones with the already created instances.
|
||||
*/
|
||||
private BootupClasses getBootupClasses(DatabaseConfig config) {
|
||||
|
||||
BootupClasses bootup = getBootupClasses1(config);
|
||||
private BootupClasses bootupClasses(DatabaseConfig config) {
|
||||
BootupClasses bootup = bootupClasses1(config);
|
||||
bootup.addIdGenerators(config.getIdGenerators());
|
||||
bootup.addPersistControllers(config.getPersistControllers());
|
||||
bootup.addPostLoaders(config.getPostLoaders());
|
||||
@@ -173,7 +169,6 @@ public class DefaultContainer implements SpiContainer {
|
||||
bootup.addQueryAdapters(config.getQueryAdapters());
|
||||
bootup.addServerConfigStartup(config.getServerConfigStartupListeners());
|
||||
bootup.addChangeLogInstances(config);
|
||||
|
||||
bootup.runServerConfigStartup(config);
|
||||
return bootup;
|
||||
}
|
||||
@@ -181,14 +176,12 @@ public class DefaultContainer implements SpiContainer {
|
||||
/**
|
||||
* Get the class based entities, scalarTypes, Listeners etc.
|
||||
*/
|
||||
private BootupClasses getBootupClasses1(DatabaseConfig config) {
|
||||
|
||||
private BootupClasses bootupClasses1(DatabaseConfig config) {
|
||||
List<Class<?>> entityClasses = config.getClasses();
|
||||
if (config.isDisableClasspathSearch() || (entityClasses != null && !entityClasses.isEmpty())) {
|
||||
// use classes we explicitly added via configuration
|
||||
return new BootupClasses(entityClasses);
|
||||
}
|
||||
|
||||
return BootupClassPathSearch.search(config);
|
||||
}
|
||||
|
||||
@@ -205,7 +198,6 @@ public class DefaultContainer implements SpiContainer {
|
||||
* Set the DatabasePlatform if it has not already been set.
|
||||
*/
|
||||
private void setDatabasePlatform(DatabaseConfig config) {
|
||||
|
||||
DatabasePlatform platform = config.getDatabasePlatform();
|
||||
if (platform == null) {
|
||||
if (config.getTenantMode().isDynamicDataSource()) {
|
||||
@@ -215,7 +207,6 @@ public class DefaultContainer implements SpiContainer {
|
||||
platform = new DatabasePlatformFactory().create(config);
|
||||
config.setDatabasePlatform(platform);
|
||||
}
|
||||
logger.info("DatabasePlatform name:{} platform:{}", config.getName(), platform.getName());
|
||||
platform.configure(config.getPlatformConfig());
|
||||
}
|
||||
|
||||
@@ -255,6 +246,9 @@ public class DefaultContainer implements SpiContainer {
|
||||
}
|
||||
throw new RuntimeException("DataSource not set?");
|
||||
}
|
||||
if (config.skipDataSourceCheck()) {
|
||||
return true;
|
||||
}
|
||||
try (Connection connection = config.getDataSource().getConnection()) {
|
||||
if (connection.getAutoCommit()) {
|
||||
logger.warn("DataSource [{}] has autoCommit defaulting to true!", config.getName());
|
||||
|
||||
@@ -490,6 +490,11 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Database{" + serverName + "}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the server name.
|
||||
*/
|
||||
@@ -526,8 +531,8 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
* Compile a query. Only valid for ORM queries.
|
||||
*/
|
||||
@Override
|
||||
public <T> CQuery<T> compileQuery(Query<T> query, Transaction t) {
|
||||
SpiOrmQueryRequest<T> qr = createQueryRequest(Type.SUBQUERY, query, t);
|
||||
public <T> CQuery<T> compileQuery(Type type, Query<T> query, Transaction t) {
|
||||
SpiOrmQueryRequest<T> qr = createQueryRequest(type, query, t);
|
||||
OrmQueryRequest<T> orm = (OrmQueryRequest<T>) qr;
|
||||
return cqueryEngine.buildQuery(orm);
|
||||
}
|
||||
@@ -2055,17 +2060,15 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
public void register(BeanPersistController c) {
|
||||
List<BeanDescriptor<?>> list = beanDescriptorManager.getBeanDescriptorList();
|
||||
for (BeanDescriptor<?> aList : list) {
|
||||
aList.register(c);
|
||||
public void register(BeanPersistController controller) {
|
||||
for (BeanDescriptor<?> desc : beanDescriptorManager.getBeanDescriptorList()) {
|
||||
desc.register(controller);
|
||||
}
|
||||
}
|
||||
|
||||
public void deregister(BeanPersistController c) {
|
||||
List<BeanDescriptor<?>> list = beanDescriptorManager.getBeanDescriptorList();
|
||||
for (BeanDescriptor<?> aList : list) {
|
||||
aList.deregister(c);
|
||||
for (BeanDescriptor<?> desc : beanDescriptorManager.getBeanDescriptorList()) {
|
||||
desc.deregister(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,8 @@ public final class DtoQueryRequest<T> extends AbstractSqlQueryRequest {
|
||||
private static final String ENC_PREFIX_UPPER = EncryptAlias.PREFIX.toUpperCase();
|
||||
|
||||
private final SpiDtoQuery<T> query;
|
||||
|
||||
private final DtoQueryEngine queryEngine;
|
||||
|
||||
private DtoQueryPlan plan;
|
||||
|
||||
private DataReader dataReader;
|
||||
|
||||
DtoQueryRequest(SpiEbeanServer server, DtoQueryEngine engine, SpiDtoQuery<T> query) {
|
||||
|
||||
@@ -120,7 +120,7 @@ class DumpMetrics {
|
||||
appendQueryName(metric, sb);
|
||||
appendCounters(metric, sb);
|
||||
if (dumpHash) {
|
||||
sb.append("\n sqlHash:").append(metric.sqlHash());
|
||||
sb.append("\n hash:").append(metric.hash());
|
||||
}
|
||||
appendProfileAndSql(metric, sb);
|
||||
out(sb.toString());
|
||||
@@ -134,7 +134,6 @@ class DumpMetrics {
|
||||
String location = metric.location();
|
||||
if (dumpLoc && location != null) {
|
||||
sb.append("\n loc:").append(location);
|
||||
sb.append("\n locHash:").append(metric.locationHash());
|
||||
}
|
||||
if (dumpSql) {
|
||||
sb.append(" \n\n sql:").append(metric.sql()).append("\n\n");
|
||||
|
||||
@@ -56,7 +56,6 @@ class DumpMetricsData {
|
||||
final MetricData data = create(metric);
|
||||
appendCounters(data, metric);
|
||||
data.setLoc(metric.location());
|
||||
data.setLocHash(metric.locationHash());
|
||||
}
|
||||
|
||||
private void addCount(MetaCountMetric metric) {
|
||||
@@ -68,11 +67,10 @@ class DumpMetricsData {
|
||||
final MetricData data = create(metric);
|
||||
appendCounters(data, metric);
|
||||
appendLocationAndSql(data, metric);
|
||||
data.setSqlHash(metric.sqlHash());
|
||||
data.setHash(metric.hash());
|
||||
}
|
||||
|
||||
private void appendLocationAndSql(MetricData data, MetaQueryMetric metric) {
|
||||
data.setLocHash(metric.locationHash());
|
||||
data.setLoc(metric.location());
|
||||
data.setSql(metric.sql());
|
||||
}
|
||||
|
||||
@@ -188,8 +188,7 @@ class DumpMetricsJson implements ServerMetricsAsJson {
|
||||
metricStart(metric);
|
||||
appendTiming(metric);
|
||||
if (isIncludeDetail(metric)) {
|
||||
keyVal("locHash", metric.locationHash());
|
||||
appendExtra("loc", metric.location());
|
||||
append("loc", metric.location());
|
||||
}
|
||||
metricEnd();
|
||||
}
|
||||
@@ -198,12 +197,11 @@ class DumpMetricsJson implements ServerMetricsAsJson {
|
||||
metricStart(metric);
|
||||
appendTiming(metric);
|
||||
if (withHash) {
|
||||
keyVal("sqlHash", metric.sqlHash());
|
||||
keyVal("locHash", metric.locationHash());
|
||||
append("hash", metric.hash());
|
||||
}
|
||||
if (isIncludeDetail(metric)) {
|
||||
appendExtra("loc", metric.location());
|
||||
appendExtra("sql", metric.sql());
|
||||
append("loc", metric.location());
|
||||
append("sql", metric.sql());
|
||||
}
|
||||
metricEnd();
|
||||
}
|
||||
@@ -212,7 +210,7 @@ class DumpMetricsJson implements ServerMetricsAsJson {
|
||||
return includeExtraAttributes == 2 || includeExtraAttributes == 1 && metric.initialCollection();
|
||||
}
|
||||
|
||||
private void appendExtra(String key, String val) throws IOException {
|
||||
private void append(String key, String val) throws IOException {
|
||||
if (val != null) {
|
||||
key(key);
|
||||
val(val);
|
||||
@@ -220,13 +218,13 @@ class DumpMetricsJson implements ServerMetricsAsJson {
|
||||
}
|
||||
|
||||
private void appendTiming(MetaTimedMetric timedMetric) throws IOException {
|
||||
keyVal("count", timedMetric.count());
|
||||
keyVal("total", timedMetric.total());
|
||||
keyVal("mean", timedMetric.mean());
|
||||
keyVal("max", timedMetric.max());
|
||||
append("count", timedMetric.count());
|
||||
append("total", timedMetric.total());
|
||||
append("mean", timedMetric.mean());
|
||||
append("max", timedMetric.max());
|
||||
}
|
||||
|
||||
private void keyVal(String key, long value) throws IOException {
|
||||
private void append(String key, long value) throws IOException {
|
||||
key(key);
|
||||
val(value);
|
||||
}
|
||||
|
||||
@@ -18,11 +18,8 @@ import java.util.function.Predicate;
|
||||
public final class RelationalQueryRequest extends AbstractSqlQueryRequest {
|
||||
|
||||
private final RelationalQueryEngine queryEngine;
|
||||
|
||||
private String[] propertyNames;
|
||||
|
||||
private int estimateCapacity;
|
||||
|
||||
private int rows;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1558,7 +1558,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
|
||||
|
||||
void queryPlanInit(QueryPlanInit request, List<MetaQueryPlan> list) {
|
||||
for (CQueryPlan queryPlan : queryPlanCache.values()) {
|
||||
if (request.includeHash(queryPlan.getSqlHash())) {
|
||||
if (request.includeHash(queryPlan.getHash())) {
|
||||
queryPlan.queryPlanInit(request.thresholdMicros());
|
||||
list.add(queryPlan.createMeta(null, null));
|
||||
}
|
||||
@@ -2519,7 +2519,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
|
||||
if (propName.indexOf('(') > -1) {
|
||||
return findSqlTreeFormula(propName, path);
|
||||
}
|
||||
return _findBeanProperty(propName);
|
||||
return findProperty(propName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+15
-1
@@ -5,6 +5,7 @@ import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.EntityBeanIntercept;
|
||||
import io.ebean.bean.MutableValueInfo;
|
||||
import io.ebean.bean.MutableValueNext;
|
||||
import io.ebean.bean.PersistenceContext;
|
||||
import io.ebean.core.type.DataReader;
|
||||
import io.ebean.core.type.ScalarType;
|
||||
import io.ebean.text.TextException;
|
||||
@@ -18,7 +19,7 @@ import java.util.Objects;
|
||||
/**
|
||||
* Handle json property with MutationDetection of SOURCE or HASH only.
|
||||
*/
|
||||
public class BeanPropertyJsonMapper extends BeanPropertyJsonBasic {
|
||||
public final class BeanPropertyJsonMapper extends BeanPropertyJsonBasic {
|
||||
|
||||
private final boolean sourceDetection;
|
||||
|
||||
@@ -105,6 +106,19 @@ public class BeanPropertyJsonMapper extends BeanPropertyJsonBasic {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCacheDataValue(EntityBean bean, Object cacheData, PersistenceContext context) {
|
||||
if (cacheData instanceof String) {
|
||||
// parse back from string to support optimisation of java object serialisation
|
||||
final String jsonContent = (String) cacheData;
|
||||
final MutableValueInfo hash = createMutableInfo(jsonContent);
|
||||
bean._ebean_getIntercept().mutableInfo(propertyIndex, hash);
|
||||
cacheData = scalarType.parse(jsonContent);
|
||||
}
|
||||
setValue(bean, cacheData);
|
||||
}
|
||||
|
||||
|
||||
private static final class NextPair implements MutableValueNext {
|
||||
|
||||
private final String json;
|
||||
|
||||
+2
-4
@@ -702,13 +702,11 @@ public class DeployBeanDescriptor<T> {
|
||||
}
|
||||
|
||||
public void sortProperties() {
|
||||
|
||||
ArrayList<DeployBeanProperty> list = new ArrayList<>(propMap.values());
|
||||
list.sort(PROP_ORDER);
|
||||
|
||||
propMap = new LinkedHashMap<>(list.size());
|
||||
for (DeployBeanProperty aList : list) {
|
||||
addBeanProperty(aList);
|
||||
for (DeployBeanProperty property : list) {
|
||||
addBeanProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
@@ -37,9 +38,9 @@ public abstract class AbstractTextExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return 0;
|
||||
}
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
// do nothing, only execute against document store
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean isSameByBind(SpiExpression other) {
|
||||
|
||||
+4
-6
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -122,14 +123,11 @@ class AllEqualsExpression extends NonPrepareExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
|
||||
int hc = 92821;
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(propMap.size());
|
||||
for (Object value : propMap.values()) {
|
||||
hc = hc * 92821 + (value == null ? 0 : value.hashCode());
|
||||
key.add(value);
|
||||
}
|
||||
|
||||
return hc;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-5
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
@@ -49,12 +50,11 @@ public class ArrayContainsExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = values[0].hashCode();
|
||||
for (int i = 1; i < values.length; i++) {
|
||||
hc = hc * 92821 + values[i].hashCode();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(values.length);
|
||||
for (Object value : values) {
|
||||
key.add(value);
|
||||
}
|
||||
return hc;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
@@ -33,8 +34,8 @@ public class ArrayIsEmptyExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return empty ? 0 : 92821;
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
@@ -49,10 +50,8 @@ class BetweenExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = low().hashCode();
|
||||
hc = hc * 92821 + high().hashCode();
|
||||
return hc;
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(low()).add(high());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.util.SplitName;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -95,8 +96,8 @@ class BetweenPropertyExpression extends NonPrepareExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return val().hashCode();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
@@ -39,8 +40,8 @@ class BitwiseExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return Long.hashCode(flags);
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(flags).add(match);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.el.ElPropertyValue;
|
||||
@@ -69,8 +70,8 @@ class CaseInsensitiveEqualExpression extends AbstractValueExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return val().hashCode();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+11
-18
@@ -5,6 +5,7 @@ import io.ebean.LikeType;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebean.util.SplitName;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
@@ -136,10 +137,8 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
|
||||
@Override
|
||||
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins whereManyJoins) {
|
||||
list = buildExpressions(desc);
|
||||
if (list != null) {
|
||||
for (SpiExpression aList : list) {
|
||||
aList.containsMany(desc, whereManyJoins);
|
||||
}
|
||||
for (SpiExpression expr : list) {
|
||||
expr.containsMany(desc, whereManyJoins);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +185,8 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
|
||||
|
||||
@Override
|
||||
public void validate(SpiExpressionValidation validation) {
|
||||
for (SpiExpression aList : list) {
|
||||
aList.validate(validation);
|
||||
for (SpiExpression expr : list) {
|
||||
expr.validate(validation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,25 +227,20 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
|
||||
*/
|
||||
@Override
|
||||
public void queryPlanHash(StringBuilder builder) {
|
||||
|
||||
builder.append("Example[");
|
||||
for (SpiExpression aList : list) {
|
||||
aList.queryPlanHash(builder);
|
||||
for (SpiExpression expr : list) {
|
||||
expr.queryPlanHash(builder);
|
||||
builder.append(",");
|
||||
}
|
||||
builder.append("]");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a hash for the actual bind values used.
|
||||
*/
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = DefaultExampleExpression.class.getName().hashCode();
|
||||
for (SpiExpression aList : list) {
|
||||
hc = hc * 92821 + aList.queryBindHash();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(list.size());
|
||||
for (SpiExpression expr : list) {
|
||||
expr.queryBindKey(key);
|
||||
}
|
||||
return hc;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -267,7 +261,6 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
|
||||
* Build the List of expressions.
|
||||
*/
|
||||
private ArrayList<SpiExpression> buildExpressions(BeanDescriptor<?> beanDescriptor) {
|
||||
|
||||
ArrayList<SpiExpression> list = new ArrayList<>();
|
||||
addExpressions(list, beanDescriptor, entity, null);
|
||||
return list;
|
||||
|
||||
+21
-30
@@ -26,6 +26,7 @@ import io.ebean.search.MultiMatch;
|
||||
import io.ebean.search.TextCommonTerms;
|
||||
import io.ebean.search.TextQueryString;
|
||||
import io.ebean.search.TextSimple;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
@@ -109,10 +110,8 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
* @return A single SpiExpression that has the nestedPath set
|
||||
*/
|
||||
SpiExpression wrap(List<SpiExpression> list, String nestedPath, Junction.Type type) {
|
||||
|
||||
DefaultExpressionList<T> wrapper = new DefaultExpressionList<>(query, expr, null, list, false);
|
||||
wrapper.setAllDocNested(nestedPath);
|
||||
|
||||
if (type != null) {
|
||||
return new JunctionExpression<>(type, wrapper);
|
||||
} else {
|
||||
@@ -121,15 +120,15 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
}
|
||||
|
||||
void simplifyEntries() {
|
||||
for (SpiExpression element : list) {
|
||||
element.simplify();
|
||||
for (SpiExpression expr : list) {
|
||||
expr.simplify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prefixProperty(String path) {
|
||||
for (SpiExpression exp : list) {
|
||||
exp.prefixProperty(path);
|
||||
for (SpiExpression expr : list) {
|
||||
expr.prefixProperty(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +173,6 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
context.startNested(allDocNestedPath);
|
||||
}
|
||||
int size = list.size();
|
||||
|
||||
SpiExpression first = list.get(0);
|
||||
boolean explicitBool = first instanceof SpiJunction<?>;
|
||||
boolean implicitBool = !explicitBool && size > 1;
|
||||
@@ -210,7 +208,6 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
|
||||
@Override
|
||||
public void writeDocQuery(DocQueryContext context, SpiExpression idEquals) throws IOException {
|
||||
|
||||
if (allDocNestedPath != null) {
|
||||
context.startNested(allDocNestedPath);
|
||||
}
|
||||
@@ -227,8 +224,8 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
if (idEquals != null) {
|
||||
idEquals.writeDocQuery(context);
|
||||
}
|
||||
for (SpiExpression aList : list) {
|
||||
aList.writeDocQuery(context);
|
||||
for (SpiExpression expr : list) {
|
||||
expr.writeDocQuery(context);
|
||||
}
|
||||
context.endBool();
|
||||
}
|
||||
@@ -278,16 +275,15 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
*/
|
||||
@Override
|
||||
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins whereManyJoins) {
|
||||
|
||||
for (SpiExpression aList : list) {
|
||||
aList.containsMany(desc, whereManyJoins);
|
||||
for (SpiExpression expr : list) {
|
||||
expr.containsMany(desc, whereManyJoins);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(SpiExpressionValidation validation) {
|
||||
for (SpiExpression aList : list) {
|
||||
aList.validate(validation);
|
||||
for (SpiExpression expr : list) {
|
||||
expr.validate(validation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,7 +626,6 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
SpiExpression expression = list.get(i);
|
||||
if (i > 0) {
|
||||
@@ -642,15 +637,15 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
for (SpiExpression aList : list) {
|
||||
aList.addBindValues(request);
|
||||
for (SpiExpression expr : list) {
|
||||
expr.addBindValues(request);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareExpression(BeanQueryRequest<?> request) {
|
||||
for (SpiExpression aList : list) {
|
||||
aList.prepareExpression(request);
|
||||
for (SpiExpression expr : list) {
|
||||
expr.prepareExpression(request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -667,23 +662,19 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
if (allDocNestedPath != null) {
|
||||
builder.append("path:").append(allDocNestedPath).append(" ");
|
||||
}
|
||||
for (SpiExpression aList : list) {
|
||||
aList.queryPlanHash(builder);
|
||||
for (SpiExpression expr : list) {
|
||||
expr.queryPlanHash(builder);
|
||||
builder.append(",");
|
||||
}
|
||||
builder.append("]");
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a hash based on the expressions.
|
||||
*/
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hash = DefaultExpressionList.class.getName().hashCode();
|
||||
for (SpiExpression aList : list) {
|
||||
hash = hash * 92821 + aList.queryBindHash();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(list.size());
|
||||
for (SpiExpression expr : list) {
|
||||
expr.queryBindKey(key);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-3
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
@@ -8,6 +9,7 @@ import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.api.SpiExpressionValidation;
|
||||
import io.ebeaninternal.api.SpiQuery;
|
||||
import io.ebeaninternal.api.SpiQuery.Type;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.query.CQuery;
|
||||
|
||||
@@ -81,7 +83,7 @@ class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpress
|
||||
*/
|
||||
protected CQuery<?> compileSubQuery(BeanQueryRequest<?> queryRequest) {
|
||||
SpiEbeanServer ebeanServer = (SpiEbeanServer) queryRequest.getEbeanServer();
|
||||
return ebeanServer.compileQuery(subQuery, queryRequest.getTransaction());
|
||||
return ebeanServer.compileQuery(Type.SQ_EXISTS, subQuery, queryRequest.getTransaction());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,8 +93,8 @@ class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpress
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return subQuery.queryBindHash();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
subQuery.queryBindKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -77,8 +78,8 @@ class IdExpression extends NonPrepareExpression implements SpiExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return value.hashCode();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -133,8 +134,11 @@ public class IdInExpression extends NonPrepareExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return idCollection.hashCode();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(idCollection.size());
|
||||
for (Object elem : idCollection) {
|
||||
key.add(elem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -176,12 +177,11 @@ class InExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = 92821;
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(bindValues.size());
|
||||
for (Object bindValue : bindValues) {
|
||||
hc = 92821 * hc + bindValue.hashCode();
|
||||
key.add(bindValue);
|
||||
}
|
||||
return hc;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.ebeaninternal.server.expression;
|
||||
import io.ebean.Pairs;
|
||||
import io.ebean.Pairs.Entry;
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -124,12 +125,11 @@ class InPairsExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = 92821;
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(entries.size());
|
||||
for (Pairs.Entry entry : entries) {
|
||||
hc = 92821 * hc + entry.hashCode();
|
||||
key.add(entry.getA()).add(entry.getB());
|
||||
}
|
||||
return hc;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.api.SpiQuery;
|
||||
import io.ebeaninternal.api.SpiQuery.Type;
|
||||
import io.ebeaninternal.server.query.CQuery;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -68,12 +70,12 @@ class InQueryExpression extends AbstractExpression implements UnsupportedDocStor
|
||||
private CQuery<?> compileSubQuery(BeanQueryRequest<?> queryRequest) {
|
||||
|
||||
SpiEbeanServer ebeanServer = (SpiEbeanServer) queryRequest.getEbeanServer();
|
||||
return ebeanServer.compileQuery(subQuery, queryRequest.getTransaction());
|
||||
return ebeanServer.compileQuery(Type.SQ_IN, subQuery, queryRequest.getTransaction());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return subQuery.queryBindHash();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
subQuery.queryBindKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
@@ -47,10 +48,8 @@ class InRangeExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = low().hashCode();
|
||||
hc = hc * 92821 + high().hashCode();
|
||||
return hc;
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(low()).add(high());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -103,8 +104,8 @@ class IsEmptyExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return 1;
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
// no bind values
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
@@ -83,10 +84,8 @@ class JsonPathExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = (value == null) ? 0 : value.hashCode();
|
||||
hc = (upperValue == null) ? hc : hc * 92821 + upperValue.hashCode();
|
||||
return hc;
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(value).add(upperValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+16
-31
@@ -25,6 +25,7 @@ import io.ebean.search.MultiMatch;
|
||||
import io.ebean.search.TextCommonTerms;
|
||||
import io.ebean.search.TextQueryString;
|
||||
import io.ebean.search.TextSimple;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
@@ -113,9 +114,8 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
@Override
|
||||
public void writeDocQuery(DocQueryContext context) throws IOException {
|
||||
context.startBool(type);
|
||||
List<SpiExpression> list = exprList.internalList();
|
||||
for (SpiExpression aList : list) {
|
||||
aList.writeDocQuery(context);
|
||||
for (SpiExpression expr : exprList.internalList()) {
|
||||
expr.writeDocQuery(context);
|
||||
}
|
||||
context.endBool();
|
||||
}
|
||||
@@ -123,9 +123,8 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
@Override
|
||||
public void writeDocQueryJunction(DocQueryContext context) throws IOException {
|
||||
context.startBoolGroupList(type);
|
||||
List<SpiExpression> list = exprList.internalList();
|
||||
for (SpiExpression aList : list) {
|
||||
aList.writeDocQuery(context);
|
||||
for (SpiExpression expr : exprList.internalList()) {
|
||||
expr.writeDocQuery(context);
|
||||
}
|
||||
context.endBoolGroupList();
|
||||
}
|
||||
@@ -138,18 +137,15 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
|
||||
@Override
|
||||
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins manyWhereJoin) {
|
||||
|
||||
List<SpiExpression> list = exprList.internalList();
|
||||
|
||||
// get the current state for 'require outer joins'
|
||||
boolean parentOuterJoins = manyWhereJoin.isRequireOuterJoins();
|
||||
if (type == Type.OR) {
|
||||
// turn on outer joins required for disjunction expressions
|
||||
manyWhereJoin.setRequireOuterJoins(true);
|
||||
}
|
||||
|
||||
for (SpiExpression aList : list) {
|
||||
aList.containsMany(desc, manyWhereJoin);
|
||||
for (SpiExpression expr : list) {
|
||||
expr.containsMany(desc, manyWhereJoin);
|
||||
}
|
||||
if (type == Type.OR && !parentOuterJoins) {
|
||||
// restore state to not forcing outer joins
|
||||
@@ -176,18 +172,14 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
|
||||
List<SpiExpression> list = exprList.internalList();
|
||||
for (SpiExpression aList : list) {
|
||||
aList.addBindValues(request);
|
||||
for (SpiExpression expr : exprList.internalList()) {
|
||||
expr.addBindValues(request);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
|
||||
List<SpiExpression> list = exprList.internalList();
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
request.append(type.prefix());
|
||||
request.append("(");
|
||||
@@ -204,9 +196,8 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
|
||||
@Override
|
||||
public void prepareExpression(BeanQueryRequest<?> request) {
|
||||
List<SpiExpression> list = exprList.internalList();
|
||||
for (SpiExpression aList : list) {
|
||||
aList.prepareExpression(request);
|
||||
for (SpiExpression expr : exprList.internalList()) {
|
||||
expr.prepareExpression(request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,22 +207,18 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
@Override
|
||||
public void queryPlanHash(StringBuilder builder) {
|
||||
builder.append(type).append("[");
|
||||
List<SpiExpression> list = exprList.internalList();
|
||||
for (SpiExpression aList : list) {
|
||||
aList.queryPlanHash(builder);
|
||||
for (SpiExpression expr : exprList.internalList()) {
|
||||
expr.queryPlanHash(builder);
|
||||
builder.append(",");
|
||||
}
|
||||
builder.append("]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = JunctionExpression.class.getName().hashCode();
|
||||
List<SpiExpression> list = exprList.internalList();
|
||||
for (SpiExpression aList : list) {
|
||||
hc = hc * 92821 + aList.queryBindHash();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
for (SpiExpression expr : exprList.internalList()) {
|
||||
expr.queryBindKey(key);
|
||||
}
|
||||
return hc;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -275,7 +262,6 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
return exprList.textCommonTerms(search, options);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ExpressionList<T> allEq(Map<String, Object> propertyMap) {
|
||||
return exprList.allEq(propertyMap);
|
||||
@@ -1025,7 +1011,6 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
|
||||
@Override
|
||||
public String nestedPath(BeanDescriptor<?> desc) {
|
||||
|
||||
PrepareDocNested.prepare(exprList, desc, type);
|
||||
String nestedPath = exprList.allDocNestedPath;
|
||||
if (nestedPath != null) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.LikeType;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.el.ElPropertyValue;
|
||||
@@ -70,8 +71,8 @@ class LikeExpression extends AbstractValueExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return strValue().hashCode();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(strValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.ebeaninternal.server.expression;
|
||||
import io.ebean.Expression;
|
||||
import io.ebean.Junction;
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
@@ -168,10 +169,8 @@ abstract class LogicExpression implements SpiExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = expOne.queryBindHash();
|
||||
hc = hc * 92821 + expTwo.queryBindHash();
|
||||
return hc;
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(expOne).add(expTwo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.LikeType;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.el.ElPropertyValue;
|
||||
@@ -54,8 +55,8 @@ class NativeILikeExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return val.hashCode();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(val);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -79,8 +80,8 @@ class NestedPathWrapperExpression implements SpiExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return delegate.queryBindHash();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
delegate.queryBindKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
@@ -74,9 +75,8 @@ class NoopExpression implements SpiExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
// no bind values
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.Expression;
|
||||
import io.ebean.event.BeanQueryRequest;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
@@ -99,8 +100,8 @@ final class NotExpression implements SpiExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return exp.queryBindHash();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
exp.queryBindKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebean.util.SplitName;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -94,7 +95,7 @@ class NullExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return (notNull ? 1 : 0);
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(notNull);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -73,12 +74,11 @@ class RawExpression extends NonPrepareExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = sql.hashCode();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(values.length);
|
||||
for (Object value : values) {
|
||||
hc = hc * 92821 + value.hashCode();
|
||||
key.add(value);
|
||||
}
|
||||
return hc;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.ebean.plugin.ExpressionPath;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.el.ElPropertyValue;
|
||||
import io.ebeaninternal.api.BindValuesKey;
|
||||
import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -121,8 +122,8 @@ public class SimpleExpression extends AbstractValueExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return value().hashCode();
|
||||
public void queryBindKey(BindValuesKey key) {
|
||||
key.add(value());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Comparator;
|
||||
* keys from inserts. These values are required to persist the 'detail' beans.
|
||||
* </p>
|
||||
*/
|
||||
class BatchDepthComparator implements Comparator<BatchedBeanHolder>, Serializable {
|
||||
final class BatchDepthComparator implements Comparator<BatchedBeanHolder>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 264611821665757991L;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Helper to determine batch execution order for BatchedBeanHolders.
|
||||
*/
|
||||
class BatchDepthOrder {
|
||||
final class BatchDepthOrder {
|
||||
|
||||
private final Map<Integer, Counter> map = new HashMap<>();
|
||||
|
||||
@@ -22,7 +22,7 @@ class BatchDepthOrder {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
private static class Counter {
|
||||
private static final class Counter {
|
||||
|
||||
int count;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.ArrayList;
|
||||
* executed. The lowest depth is executed first.
|
||||
* </p>
|
||||
*/
|
||||
class BatchedBeanHolder {
|
||||
final class BatchedBeanHolder {
|
||||
|
||||
/**
|
||||
* The owning queue.
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
* This can hold CallableStatements as well.
|
||||
* </p>
|
||||
*/
|
||||
public class BatchedPstmt implements SpiProfileTransactionEvent {
|
||||
public final class BatchedPstmt implements SpiProfileTransactionEvent {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BatchedPstmt.class);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.Map;
|
||||
* statements of a single 'depth' at any given time.
|
||||
* </p>
|
||||
*/
|
||||
public class BatchedPstmtHolder {
|
||||
public final class BatchedPstmtHolder {
|
||||
|
||||
/**
|
||||
* A Map of the statements using a String key. This is used so that the same
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
package io.ebeaninternal.server.persist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Holds a list of bind values for binding to a PreparedStatement.
|
||||
*/
|
||||
class BindValues {
|
||||
|
||||
private final ArrayList<Value> list = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Create with a Binder.
|
||||
*/
|
||||
public BindValues() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a bind value with its JDBC datatype.
|
||||
*
|
||||
* @param value the bind value
|
||||
* @param dbType the type as per java.sql.Types
|
||||
*/
|
||||
public void add(Object value, int dbType, String name) {
|
||||
list.add(new Value(value, dbType, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* List of bind values.
|
||||
*/
|
||||
public ArrayList<Value> values() {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Value has additionally the JDBC data type.
|
||||
*/
|
||||
public static class Value {
|
||||
|
||||
private final Object value;
|
||||
|
||||
private final int dbType;
|
||||
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Create the value.
|
||||
*/
|
||||
Value(Object value, int dbType, String name) {
|
||||
this.value = value;
|
||||
this.dbType = dbType;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type as per java.sql.Types.
|
||||
*/
|
||||
public int getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value.
|
||||
*/
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the property name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ import java.util.List;
|
||||
/**
|
||||
* Binds bean values to a PreparedStatement.
|
||||
*/
|
||||
public class Binder {
|
||||
public final class Binder {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Binder.class);
|
||||
|
||||
@@ -77,33 +77,6 @@ public class Binder {
|
||||
return asOfStandardsBased;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the values to the Prepared Statement.
|
||||
*/
|
||||
public void bind(BindValues bindValues, DataBind dataBind, StringBuilder bindBuf) throws SQLException {
|
||||
String logPrefix = "";
|
||||
ArrayList<BindValues.Value> list = bindValues.values();
|
||||
for (BindValues.Value bindValue : list) {
|
||||
Object val = bindValue.getValue();
|
||||
int dt = bindValue.getDbType();
|
||||
bindObject(dataBind, val, dt);
|
||||
|
||||
if (bindBuf != null) {
|
||||
bindBuf.append(logPrefix);
|
||||
if (logPrefix.isEmpty()) {
|
||||
logPrefix = ", ";
|
||||
}
|
||||
bindBuf.append(bindValue.getName());
|
||||
bindBuf.append("=");
|
||||
if (isLob(dt)) {
|
||||
bindBuf.append("[LOB]");
|
||||
} else {
|
||||
bindBuf.append(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the parameters to the preparedStatement returning the bind log.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@ import io.ebean.Transaction;
|
||||
import io.ebean.event.BeanDeleteIdRequest;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
|
||||
class DeleteIdRequest implements BeanDeleteIdRequest {
|
||||
final class DeleteIdRequest implements BeanDeleteIdRequest {
|
||||
|
||||
private final EbeanServer server;
|
||||
private final Transaction transaction;
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
* helps fetch the foreign keys and delete the appropriate rows.
|
||||
* </p>
|
||||
*/
|
||||
class DeleteUnloadedForeignKeys {
|
||||
final class DeleteUnloadedForeignKeys {
|
||||
|
||||
private final List<BeanPropertyAssocOne<?>> propList = new ArrayList<>(4);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ package io.ebeaninternal.server.persist;
|
||||
/**
|
||||
* Utility object with helper methods for DML.
|
||||
*/
|
||||
public class DmlUtil {
|
||||
public final class DmlUtil {
|
||||
|
||||
/**
|
||||
* Return true if the value is null or a Numeric 0 (for primitive int's and long's) or Option empty.
|
||||
|
||||
@@ -13,10 +13,9 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* Handles the execution of CallableSql requests.
|
||||
*/
|
||||
class ExeCallableSql {
|
||||
final class ExeCallableSql {
|
||||
|
||||
private final Binder binder;
|
||||
|
||||
private final PstmtFactory pstmtFactory;
|
||||
|
||||
ExeCallableSql(Binder binder) {
|
||||
@@ -28,9 +27,7 @@ class ExeCallableSql {
|
||||
* execute the CallableSql requests.
|
||||
*/
|
||||
public int execute(PersistRequestCallableSql request) {
|
||||
|
||||
boolean batchThisRequest = request.isBatchThisRequest();
|
||||
|
||||
CallableStatement cstmt = null;
|
||||
try {
|
||||
cstmt = bindStmt(request, batchThisRequest);
|
||||
@@ -58,18 +55,15 @@ class ExeCallableSql {
|
||||
|
||||
|
||||
private CallableStatement bindStmt(PersistRequestCallableSql request, boolean batchThisRequest) throws SQLException {
|
||||
|
||||
request.startBind(batchThisRequest);
|
||||
SpiCallableSql callableSql = request.getCallableSql();
|
||||
SpiTransaction t = request.getTransaction();
|
||||
|
||||
String sql = callableSql.getSql();
|
||||
|
||||
BindParams bindParams = callableSql.getBindParams();
|
||||
|
||||
// process named parameters if required
|
||||
sql = BindParamsParser.parse(bindParams, sql);
|
||||
|
||||
boolean logSql = request.isLogSql();
|
||||
|
||||
CallableStatement cstmt;
|
||||
@@ -90,9 +84,7 @@ class ExeCallableSql {
|
||||
if (!bindParams.isEmpty()) {
|
||||
bindLog = binder.bind(bindParams, cstmt, t.getInternalConnection());
|
||||
}
|
||||
|
||||
request.setBindLog(bindLog);
|
||||
|
||||
// required to read OUT params later
|
||||
request.setBound(bindParams, cstmt);
|
||||
return cstmt;
|
||||
|
||||
@@ -15,15 +15,11 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* Executes the UpdateSql requests.
|
||||
*/
|
||||
class ExeOrmUpdate {
|
||||
final class ExeOrmUpdate {
|
||||
|
||||
private final Binder binder;
|
||||
|
||||
private final PstmtFactory pstmtFactory;
|
||||
|
||||
/**
|
||||
* Create with a given binder.
|
||||
*/
|
||||
ExeOrmUpdate(Binder binder) {
|
||||
this.pstmtFactory = new PstmtFactory();
|
||||
this.binder = binder;
|
||||
@@ -33,9 +29,7 @@ class ExeOrmUpdate {
|
||||
* Execute the orm update request.
|
||||
*/
|
||||
public int execute(PersistRequestOrmUpdate request) {
|
||||
|
||||
boolean batchThisRequest = request.isBatchThisRequest();
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
pstmt = bindStmt(request, batchThisRequest);
|
||||
@@ -68,13 +62,11 @@ class ExeOrmUpdate {
|
||||
* Convert bean and property names to db table and columns.
|
||||
*/
|
||||
private String translate(PersistRequestOrmUpdate request, String sql) {
|
||||
|
||||
BeanDescriptor<?> descriptor = request.getBeanDescriptor();
|
||||
return descriptor.convertOrmUpdateToSql(sql);
|
||||
}
|
||||
|
||||
private PreparedStatement bindStmt(PersistRequestOrmUpdate request, boolean batchThisRequest) throws SQLException {
|
||||
|
||||
request.startBind(batchThisRequest);
|
||||
SpiUpdate<?> ormUpdate = request.getOrmUpdate();
|
||||
SpiTransaction t = request.getTransaction();
|
||||
|
||||
@@ -16,15 +16,11 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* Executes the UpdateSql requests.
|
||||
*/
|
||||
class ExeUpdateSql {
|
||||
final class ExeUpdateSql {
|
||||
|
||||
private final Binder binder;
|
||||
|
||||
private final PstmtFactory pstmtFactory;
|
||||
|
||||
/**
|
||||
* Create with a given binder.
|
||||
*/
|
||||
ExeUpdateSql(Binder binder) {
|
||||
this.binder = binder;
|
||||
this.pstmtFactory = new PstmtFactory();
|
||||
@@ -34,14 +30,10 @@ class ExeUpdateSql {
|
||||
* Execute the UpdateSql request.
|
||||
*/
|
||||
public int execute(PersistRequestUpdateSql request) {
|
||||
|
||||
boolean batchThisRequest = request.isBatchThisRequest();
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
|
||||
pstmt = bindStmt(request, batchThisRequest);
|
||||
|
||||
if (batchThisRequest) {
|
||||
pstmt.addBatch();
|
||||
// return -1 to indicate batch mode
|
||||
@@ -66,7 +58,6 @@ class ExeUpdateSql {
|
||||
}
|
||||
|
||||
private void readGeneratedKeys(PreparedStatement stmt, PersistRequestUpdateSql request) {
|
||||
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
resultSet = stmt.getGeneratedKeys();
|
||||
@@ -82,7 +73,6 @@ class ExeUpdateSql {
|
||||
}
|
||||
|
||||
private PreparedStatement bindStmt(PersistRequestUpdateSql request, boolean batchThisRequest) throws SQLException {
|
||||
|
||||
request.startBind(batchThisRequest);
|
||||
SpiSqlUpdate updateSql = request.getUpdateSql();
|
||||
SpiTransaction t = request.getTransaction();
|
||||
@@ -121,7 +111,6 @@ class ExeUpdateSql {
|
||||
|
||||
|
||||
private void determineType(String word1, String word2, String word3, PersistRequestUpdateSql request) {
|
||||
|
||||
if (word1.equalsIgnoreCase("UPDATE")) {
|
||||
request.setType(SqlType.SQL_UPDATE, word2);
|
||||
|
||||
@@ -137,7 +126,6 @@ class ExeUpdateSql {
|
||||
}
|
||||
|
||||
private void parseUpdate(String sql, PersistRequestUpdateSql request) {
|
||||
|
||||
int[] pos = new int[3];
|
||||
int spaceCount = 0;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
/**
|
||||
* Context used for merge processing.
|
||||
*/
|
||||
class MergeContext {
|
||||
final class MergeContext {
|
||||
|
||||
private final SpiEbeanServer server;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* Drives the merge processing.
|
||||
*/
|
||||
class MergeHandler {
|
||||
final class MergeHandler {
|
||||
|
||||
private static final Pattern PATH_SPLIT = Pattern.compile("\\.");
|
||||
|
||||
@@ -33,10 +33,8 @@ class MergeHandler {
|
||||
private final EntityBean bean;
|
||||
private final MergeOptions options;
|
||||
private final SpiTransaction transaction;
|
||||
|
||||
private final Map<String, MergeNode> nodes = new LinkedHashMap<>();
|
||||
|
||||
|
||||
MergeHandler(SpiEbeanServer server, BeanDescriptor<?> desc, EntityBean bean, MergeOptions options, SpiTransaction transaction) {
|
||||
this.server = server;
|
||||
this.desc = desc;
|
||||
@@ -49,7 +47,6 @@ class MergeHandler {
|
||||
* Fetch the Ids for the graph and use them to determine inserts, updates and deletes for the merge paths.
|
||||
*/
|
||||
List<EntityBean> merge() {
|
||||
|
||||
Set<String> paths = options.paths();
|
||||
if (desc.isIdGeneratedValue() && paths.isEmpty() && !options.isClientGeneratedIds()) {
|
||||
// just do a single insert or update based on Id value present
|
||||
@@ -76,7 +73,6 @@ class MergeHandler {
|
||||
for (MergeNode value : nodes.values()) {
|
||||
value.merge(request);
|
||||
}
|
||||
|
||||
return context.getDeletedBeans();
|
||||
}
|
||||
|
||||
@@ -86,9 +82,7 @@ class MergeHandler {
|
||||
* We use the Id values to determine what are inserts, updates and deletes as part of the merge.
|
||||
*/
|
||||
private EntityBean fetchOutline(Set<String> paths) {
|
||||
|
||||
Query<?> query = server.find(desc.getBeanType());
|
||||
|
||||
query.setBeanCacheMode(CacheMode.OFF);
|
||||
query.setPersistenceContextScope(PersistenceContextScope.QUERY);
|
||||
query.setId(desc.getId(bean));
|
||||
@@ -126,14 +120,12 @@ class MergeHandler {
|
||||
}
|
||||
|
||||
private MergeNode addRootLevelNode(String rootPath) {
|
||||
|
||||
MergeNode node = createMergeNode(rootPath, desc, rootPath);
|
||||
nodes.put(rootPath, node);
|
||||
return node;
|
||||
}
|
||||
|
||||
static MergeNode createMergeNode(String fullPath, BeanDescriptor<?> targetDesc, String path) {
|
||||
|
||||
BeanProperty prop = targetDesc.getBeanProperty(path);
|
||||
if (!(prop instanceof BeanPropertyAssoc)) {
|
||||
throw new PersistenceException("merge path [" + path + "] is not a ToMany or ToOne property of " + targetDesc.getFullName());
|
||||
|
||||
@@ -33,7 +33,7 @@ abstract class MergeNode {
|
||||
/**
|
||||
* Add a child node given the fullPath and relative path.
|
||||
*/
|
||||
MergeNode addChild(String fullPath, String path) {
|
||||
final MergeNode addChild(String fullPath, String path) {
|
||||
MergeNode childNode = MergeHandler.createMergeNode(fullPath, targetDescriptor, path);
|
||||
if (children == null) {
|
||||
children = new LinkedHashMap<>();
|
||||
@@ -45,7 +45,7 @@ abstract class MergeNode {
|
||||
/**
|
||||
* Return the node given the relative path.
|
||||
*/
|
||||
MergeNode get(String path) {
|
||||
final MergeNode get(String path) {
|
||||
if (children != null) {
|
||||
return children.get(path);
|
||||
}
|
||||
@@ -55,8 +55,7 @@ abstract class MergeNode {
|
||||
/**
|
||||
* Return the outline beans as a map keyed by Id values.
|
||||
*/
|
||||
Map<Object, EntityBean> toMap(Collection outlines) {
|
||||
|
||||
final Map<Object, EntityBean> toMap(Collection outlines) {
|
||||
Map<Object, EntityBean> outlineMap = new HashMap<>();
|
||||
if (outlines != null) {
|
||||
for (Object out : outlines) {
|
||||
@@ -71,8 +70,7 @@ abstract class MergeNode {
|
||||
/**
|
||||
* Add to the query to fetch the Ids values for the foreign keys basically.
|
||||
*/
|
||||
void addSelectId(Query<?> query) {
|
||||
|
||||
final void addSelectId(Query<?> query) {
|
||||
BeanProperty idProperty = targetDescriptor.getIdProperty();
|
||||
query.fetch(fullPath, idProperty.getName());
|
||||
}
|
||||
@@ -80,8 +78,7 @@ abstract class MergeNode {
|
||||
/**
|
||||
* Cascade the merge processing if this has child nodes.
|
||||
*/
|
||||
void cascade(EntityBean entityBean, EntityBean outlineBean, MergeRequest request) {
|
||||
|
||||
final void cascade(EntityBean entityBean, EntityBean outlineBean, MergeRequest request) {
|
||||
if (children != null && !children.isEmpty()) {
|
||||
MergeRequest sub = request.sub(entityBean, outlineBean);
|
||||
for (MergeNode node : children.values()) {
|
||||
|
||||
+1
-7
@@ -15,7 +15,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Node for processing merge on ManyToMany properties.
|
||||
*/
|
||||
class MergeNodeAssocManyToMany extends MergeNode {
|
||||
final class MergeNodeAssocManyToMany extends MergeNode {
|
||||
|
||||
private final BeanPropertyAssocMany<?> many;
|
||||
|
||||
@@ -26,14 +26,11 @@ class MergeNodeAssocManyToMany extends MergeNode {
|
||||
|
||||
@Override
|
||||
public void merge(MergeRequest request) {
|
||||
|
||||
EntityBean parentBean = request.getBean();
|
||||
|
||||
Collection beans = many.getRawCollection(parentBean);
|
||||
Collection outlines = many.getRawCollection(request.getOutline());
|
||||
|
||||
Map<Object, EntityBean> outlineIds = toMap(outlines);
|
||||
|
||||
List<EntityBean> additions = new ArrayList<>();
|
||||
if (beans != null) {
|
||||
for (Object bean : beans) {
|
||||
@@ -57,7 +54,6 @@ class MergeNodeAssocManyToMany extends MergeNode {
|
||||
|
||||
if (!deletions.isEmpty()) {
|
||||
transaction.flush();
|
||||
|
||||
SqlUpdate delete = intersectionTable.delete(server, false);
|
||||
for (EntityBean deletion : deletions) {
|
||||
many.intersectionBind(delete, parentBean, deletion);
|
||||
@@ -68,7 +64,6 @@ class MergeNodeAssocManyToMany extends MergeNode {
|
||||
|
||||
if (!additions.isEmpty()) {
|
||||
transaction.flush();
|
||||
|
||||
SqlUpdate insert = intersectionTable.insert(server, false);
|
||||
for (EntityBean addition : additions) {
|
||||
many.intersectionBind(insert, parentBean, addition);
|
||||
@@ -76,7 +71,6 @@ class MergeNodeAssocManyToMany extends MergeNode {
|
||||
}
|
||||
insert.execute();
|
||||
}
|
||||
|
||||
many.resetMany(parentBean);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.Objects;
|
||||
/**
|
||||
* Node for processing merge on ToOne properties.
|
||||
*/
|
||||
class MergeNodeAssocOne extends MergeNode {
|
||||
final class MergeNodeAssocOne extends MergeNode {
|
||||
|
||||
private final BeanPropertyAssocOne<?> one;
|
||||
|
||||
@@ -19,7 +19,6 @@ class MergeNodeAssocOne extends MergeNode {
|
||||
|
||||
@Override
|
||||
public void merge(MergeRequest request) {
|
||||
|
||||
EntityBean entityBean = getEntityBean(request.getBean());
|
||||
if (entityBean == null) {
|
||||
checkOrphanRemoval(request);
|
||||
|
||||
+1
-4
@@ -9,7 +9,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Node for processing merge on ToMany properties.
|
||||
*/
|
||||
class MergeNodeAssocOneToMany extends MergeNode {
|
||||
final class MergeNodeAssocOneToMany extends MergeNode {
|
||||
|
||||
private final BeanPropertyAssocMany<?> many;
|
||||
|
||||
@@ -20,12 +20,10 @@ class MergeNodeAssocOneToMany extends MergeNode {
|
||||
|
||||
@Override
|
||||
public void merge(MergeRequest request) {
|
||||
|
||||
Collection beans = many.getRawCollection(request.getBean());
|
||||
Collection outlines = many.getRawCollection(request.getOutline());
|
||||
|
||||
Map<Object, EntityBean> outlineIds = toMap(outlines);
|
||||
|
||||
if (beans != null) {
|
||||
for (Object bean : beans) {
|
||||
EntityBean entityBean = (EntityBean) bean;
|
||||
@@ -40,7 +38,6 @@ class MergeNodeAssocOneToMany extends MergeNode {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// any remaining are considered deletes
|
||||
for (EntityBean outlineBean : outlineIds.values()) {
|
||||
request.addDelete(outlineBean);
|
||||
|
||||
@@ -7,11 +7,10 @@ import io.ebeaninternal.api.SpiTransaction;
|
||||
/**
|
||||
* Request object used for processing the merge.
|
||||
*/
|
||||
class MergeRequest {
|
||||
final class MergeRequest {
|
||||
|
||||
private final EntityBean bean;
|
||||
private final EntityBean outline;
|
||||
|
||||
private final MergeContext context;
|
||||
|
||||
MergeRequest(MergeContext context, EntityBean bean, EntityBean outline) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Collection;
|
||||
* Wraps the multi values that are used for "property in (...)" queries
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*/
|
||||
public class MultiValueWrapper {
|
||||
public final class MultiValueWrapper {
|
||||
private final Collection<?> values;
|
||||
private final Class<?> type;
|
||||
|
||||
|
||||
@@ -15,10 +15,7 @@ import java.sql.Statement;
|
||||
* getGeneratedKeys.
|
||||
* </p>
|
||||
*/
|
||||
class PstmtFactory {
|
||||
|
||||
PstmtFactory() {
|
||||
}
|
||||
final class PstmtFactory {
|
||||
|
||||
/**
|
||||
* Get a callable statement without any batching.
|
||||
@@ -56,7 +53,6 @@ class PstmtFactory {
|
||||
if (t.isLogSql()) {
|
||||
t.logSql(TrimLogSql.trim(sql));
|
||||
}
|
||||
|
||||
Connection conn = t.getInternalConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
BatchedPstmt bs = new BatchedPstmt(stmt, false, sql, t);
|
||||
@@ -68,10 +64,8 @@ class PstmtFactory {
|
||||
* Return a callable statement taking into account batch requirements.
|
||||
*/
|
||||
CallableStatement getCstmtBatch(SpiTransaction t, boolean logSql, String sql, BatchPostExecute batchExe) throws SQLException {
|
||||
|
||||
BatchedPstmtHolder batch = t.getBatchControl().getPstmtHolder();
|
||||
CallableStatement stmt = (CallableStatement) batch.getStmt(sql, batchExe);
|
||||
|
||||
if (stmt != null) {
|
||||
return stmt;
|
||||
}
|
||||
@@ -79,10 +73,8 @@ class PstmtFactory {
|
||||
if (logSql) {
|
||||
t.logSql(sql);
|
||||
}
|
||||
|
||||
Connection conn = t.getInternalConnection();
|
||||
stmt = conn.prepareCall(sql);
|
||||
|
||||
BatchedPstmt bs = new BatchedPstmt(stmt, false, sql, t);
|
||||
batch.addStmt(bs, batchExe);
|
||||
return stmt;
|
||||
|
||||
@@ -46,20 +46,20 @@ abstract class SaveManyBase implements SaveMany {
|
||||
*/
|
||||
abstract void save();
|
||||
|
||||
void preElementCollectionUpdate() {
|
||||
final void preElementCollectionUpdate() {
|
||||
if (!insertedParent) {
|
||||
request.preElementCollectionUpdate();
|
||||
persister.addToFlushQueue(many.deleteByParentId(request.getBeanId(), null), transaction, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void resetModifyState() {
|
||||
final void resetModifyState() {
|
||||
if (value instanceof BeanCollection<?>) {
|
||||
modifyListenReset((BeanCollection<?>) value);
|
||||
}
|
||||
}
|
||||
|
||||
void modifyListenReset(BeanCollection<?> c) {
|
||||
final void modifyListenReset(BeanCollection<?> c) {
|
||||
if (insertedParent) {
|
||||
// after insert set the modify listening mode for private owned etc
|
||||
c.setModifyListening(many.getModifyListenMode());
|
||||
@@ -67,7 +67,7 @@ abstract class SaveManyBase implements SaveMany {
|
||||
c.modifyReset();
|
||||
}
|
||||
|
||||
void postElementCollectionUpdate() {
|
||||
final void postElementCollectionUpdate() {
|
||||
if (!insertedParent) {
|
||||
if (request.isNotifyCache()) {
|
||||
try {
|
||||
|
||||
@@ -26,7 +26,7 @@ import static io.ebeaninternal.server.persist.DmlUtil.isNullOrZero;
|
||||
/**
|
||||
* Saves the details for a OneToMany or ManyToMany relationship (entity beans).
|
||||
*/
|
||||
public class SaveManyBeans extends SaveManyBase {
|
||||
public final class SaveManyBeans extends SaveManyBase {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SaveManyBeans.class);
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.Collection;
|
||||
/**
|
||||
* Save details for a simple scalar element collection.
|
||||
*/
|
||||
class SaveManyElementCollection extends SaveManyBase {
|
||||
final class SaveManyElementCollection extends SaveManyBase {
|
||||
|
||||
private Collection<?> collection;
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Save details for a simple scalar map element collection.
|
||||
*/
|
||||
class SaveManyElementCollectionMap extends SaveManyBase {
|
||||
final class SaveManyElementCollectionMap extends SaveManyBase {
|
||||
|
||||
private Set<Map.Entry<?, ?>> entries;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.persist;
|
||||
/**
|
||||
* Utility to improve logging of raw SQL that contains new line characters.
|
||||
*/
|
||||
public class TrimLogSql {
|
||||
public final class TrimLogSql {
|
||||
|
||||
/**
|
||||
* Replace new line chars for nicer logging of multi-line sql strings.
|
||||
|
||||
@@ -16,19 +16,17 @@ class BaseMeta {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
String appendWhere(GenerateDmlRequest request, ConcurrencyMode conMode) {
|
||||
final String appendWhere(GenerateDmlRequest request, ConcurrencyMode conMode) {
|
||||
request.setWhereIdMode();
|
||||
id.dmlAppend(request);
|
||||
if (tenantId != null) {
|
||||
tenantId.dmlAppend(request);
|
||||
}
|
||||
|
||||
if (ConcurrencyMode.VERSION == conMode) {
|
||||
if (version != null) {
|
||||
version.dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
return request.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user