Compare commits

..
Author SHA1 Message Date
robin.bygrave 72ce587629 Add dbName() to MetaQueryPlan - easier to support multi-db query plan capture handling 2026-08-14 18:03:02 +12:00
robin.bygrave 77e98a3f54 Metrics - support both CUMULATIVE and DELTA metrics collection concurrently
ebean insight [and StatsD] work off DELTA metrics, where as OTEL
and Prometheus want CUMULATIVE. With this change we can have a metrics
collection for ebean insight using DELTA mode and have a second collection
use CUMULATIVE for reporting to OTEL - for the case of fan-out metrics
going to 2 places.

This isn't strictly needed when only one collection mode is used.
2026-08-14 16:31:28 +12:00
95 changed files with 326 additions and 1408 deletions
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-clickhouse</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-db2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-hana</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-mariadb</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-mysql</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+6 -6
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -22,13 +22,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -47,19 +47,19 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-net-postgis-types</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-nuodb</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-oracle</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+6 -6
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -22,13 +22,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -47,19 +47,19 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-pgvector-types</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
+6 -6
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -22,13 +22,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -47,19 +47,19 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-postgis-types</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlite</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlserver</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+6 -6
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -41,7 +41,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-jackson-mapper</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -60,13 +60,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-all</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+1 -1
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>composites</artifactId>
+1 -1
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<name>ebean api</name>
@@ -5,18 +5,13 @@ package io.ebean.meta;
*/
public abstract class AbstractMetricVisitor implements MetricVisitor {
private final Mode mode;
private final boolean reset;
private final boolean collectTransactionMetrics;
private final boolean collectQueryMetrics;
private final boolean collectL2Metrics;
public AbstractMetricVisitor(boolean reset, boolean collectTransactionMetrics, boolean collectQueryMetrics, boolean collectL2Metrics) {
this(reset ? Mode.RESET : Mode.CUMULATIVE,
collectTransactionMetrics, collectQueryMetrics, collectL2Metrics);
}
public AbstractMetricVisitor(Mode mode, boolean collectTransactionMetrics, boolean collectQueryMetrics, boolean collectL2Metrics) {
this.mode = mode;
this.reset = reset;
this.collectTransactionMetrics = collectTransactionMetrics;
this.collectQueryMetrics = collectQueryMetrics;
this.collectL2Metrics = collectL2Metrics;
@@ -24,12 +19,7 @@ public abstract class AbstractMetricVisitor implements MetricVisitor {
@Override
public boolean reset() {
return mode == Mode.RESET;
}
@Override
public Mode mode() {
return mode;
return reset;
}
@Override
@@ -57,3 +47,4 @@ public abstract class AbstractMetricVisitor implements MetricVisitor {
// do nothing by default
}
}
@@ -30,16 +30,7 @@ public class BasicMetricVisitor extends AbstractMetricVisitor implements ServerM
* Construct specifying reset and what to collect.
*/
public BasicMetricVisitor(String name, Function<String,String> naming, boolean reset, boolean collectTransactionMetrics, boolean collectQueryMetrics, boolean collectL2Metrics) {
this(name, naming, reset ? Mode.RESET : Mode.CUMULATIVE,
collectTransactionMetrics, collectQueryMetrics, collectL2Metrics);
}
/**
* Construct specifying the collection mode and what to collect.
*/
public BasicMetricVisitor(String name, Function<String,String> naming, Mode mode,
boolean collectTransactionMetrics, boolean collectQueryMetrics, boolean collectL2Metrics) {
super(mode, collectTransactionMetrics, collectQueryMetrics, collectL2Metrics);
super(reset, collectTransactionMetrics, collectQueryMetrics, collectL2Metrics);
this.name = name;
this.naming = naming;
}
@@ -7,12 +7,6 @@ import java.util.function.Function;
*/
public interface MetricVisitor {
enum Mode {
RESET,
CUMULATIVE,
DELTA
}
/**
* Return the naming convention that should be applied to the reported metric names.
*/
@@ -23,13 +17,6 @@ public interface MetricVisitor {
*/
boolean reset();
/**
* Return the metric collection mode.
*/
default Mode mode() {
return reset() ? Mode.RESET : Mode.CUMULATIVE;
}
/**
* Return true if we should visit the transaction metrics.
*/
@@ -37,16 +37,6 @@ public interface TimedMetric {
*/
TimedMetricStats collect(boolean reset);
/**
* Collect a snapshot using the given collection mode.
*
* <p>Implementations that do not support delta collection use cumulative
* collection for {@link MetricVisitor.Mode#DELTA}.</p>
*/
default TimedMetricStats collect(MetricVisitor.Mode mode) {
return collect(mode == MetricVisitor.Mode.RESET);
}
/**
* Visit non empty metrics.
*/
@@ -43,18 +43,4 @@ class MetaInfoManagerTest {
assertThat(manager.collectMetrics(false)).isSameAs(metrics);
}
@Test
void basicMetricVisitorSupportsExplicitCollectionModes() {
var reset = new BasicMetricVisitor("db", MetricNamingMatch.INSTANCE, MetricVisitor.Mode.RESET, true, true, true);
var cumulative = new BasicMetricVisitor("db", MetricNamingMatch.INSTANCE, MetricVisitor.Mode.CUMULATIVE, true, true, true);
var delta = new BasicMetricVisitor("db", MetricNamingMatch.INSTANCE, MetricVisitor.Mode.DELTA, true, true, true);
assertThat(reset.reset()).isTrue();
assertThat(reset.mode()).isEqualTo(MetricVisitor.Mode.RESET);
assertThat(cumulative.reset()).isFalse();
assertThat(cumulative.mode()).isEqualTo(MetricVisitor.Mode.CUMULATIVE);
assertThat(delta.reset()).isFalse();
assertThat(delta.mode()).isEqualTo(MetricVisitor.Mode.DELTA);
}
}
+5 -5
View File
@@ -3,7 +3,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -14,7 +14,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-type</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
@@ -41,14 +41,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
@@ -69,7 +69,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>ebean-bench</artifactId>
+29 -29
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<name>ebean bom</name>
@@ -89,25 +89,25 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-type</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -125,19 +125,19 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-jackson-mapper</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-avajejsonb-mapper</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -161,37 +161,37 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>querybean-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>kotlin-querybean-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-redis</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-spring-txn</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<!-- platforms -->
@@ -199,91 +199,91 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-clickhouse</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-db2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-h2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-hana</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-mariadb</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-mysql</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-nuodb</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-oracle</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-postgis</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-postgis-types</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-pgvector</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-pgvector-types</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-sqlite</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-sqlserver</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -3,7 +3,7 @@
<parent>
<groupId>io.ebean</groupId>
<artifactId>ebean-parent</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>ebean-core-json</artifactId>
<name>ebean-core-json</name>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>ebean-core-type</artifactId>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
+7 -7
View File
@@ -3,7 +3,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>ebean-core</artifactId>
@@ -22,13 +22,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-json</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -52,7 +52,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-type</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -157,21 +157,21 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlserver</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
@@ -81,13 +81,6 @@ public final class BatchControl {
*/
private int bufferMax;
/**
* True while the batched requests are being executed. A persist performed from a
* BeanPersistController callback must not flush the batch that is executing it, the same way
* executeNow() stops a query from doing so.
*/
private boolean executing;
private final Queue[] queues = new Queue[2];
static final int DELETE_QUEUE = 0;
@@ -146,9 +139,8 @@ public final class BatchControl {
* to the depth.
*/
public int executeStatementOrBatch(PersistRequest request, boolean batch, boolean addBatch) throws BatchedSqlException {
if (!executing && (!batch || (batchFlushOnMixed && !isBeansEmpty()))) {
// flush when mixing beans and updateSql, unless we are inside the execution of the batch
// itself : flushing then would issue the statements queued behind the current one early
if (!batch || (batchFlushOnMixed && !isBeansEmpty())) {
// flush when mixing beans and updateSql
flush();
}
if (!batch) {
@@ -171,9 +163,8 @@ public final class BatchControl {
* according to the depth (object graph depth).
*/
public int executeOrQueue(PersistRequestBean<?> request, boolean batch) throws BatchedSqlException {
if (!executing && (!batch || (batchFlushOnMixed && !pstmtHolder.isEmpty()))) {
// flush when mixing beans and updateSql, unless we are inside the execution of the batch
// itself : flushing then would issue the statements queued behind the current one early
if (!batch || (batchFlushOnMixed && !pstmtHolder.isEmpty())) {
// flush when mixing beans and updateSql
flush();
}
if (!batch) {
@@ -235,9 +226,7 @@ public final class BatchControl {
void executeNow(ArrayList<PersistRequest> list) throws BatchedSqlException {
boolean old = transaction.isFlushOnQuery();
transaction.setFlushOnQuery(false);
boolean oldExecuting = executing;
executing = true;
// disable flush on query and on persist due transaction callbacks
// disable flush on query due transaction callbacks
try {
for (int i = 0; i < list.size(); i++) {
if (i % batchSize == 0) {
@@ -248,7 +237,6 @@ public final class BatchControl {
}
flushPstmtHolder();
} finally {
executing = oldExecuting;
transaction.setFlushOnQuery(old);
}
}
@@ -17,6 +17,9 @@ final class DCountMetric implements CountMetric {
this.name = name;
}
/**
* Add a value. Usually the value is Time or Bytes etc.
*/
@Override
public void add(long value) {
count.add(value);
@@ -39,25 +42,12 @@ final class DCountMetric implements CountMetric {
@Override
public long get(boolean reset) {
return reset ? count.getAndReset() : count.cumulative();
return count.get(reset);
}
@Override
public void visit(MetricVisitor visitor) {
long val;
switch (visitor.mode()) {
case RESET:
val = count.getAndReset();
break;
case CUMULATIVE:
val = count.cumulative();
break;
case DELTA:
val = count.delta();
break;
default:
throw new IllegalStateException("Unknown metric collection mode");
}
long val = count.get(visitor.reset());
if (val > 0) {
final String name = reportName != null ? reportName : reportName(visitor);
visitor.visitCount(new DCountMetricStats(name, val));
@@ -20,7 +20,7 @@ final class DQueryPlanMetric implements QueryPlanMetric {
@Override
public void visit(MetricVisitor visitor) {
TimedMetricStats stats = metric.collect(visitor.mode());
TimedMetricStats stats = metric.collect(visitor.reset());
if (stats != null) {
String name = reportName != null ? reportName : reportName(visitor);
visitor.visitQuery(new Stats(name, meta, stats, collected));
@@ -3,6 +3,8 @@ package io.ebeaninternal.server.profile;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.TimedMetric;
import java.util.concurrent.atomic.LongAccumulator;
/**
* Used to collect timed execution statistics.
* <p>
@@ -14,17 +16,12 @@ final class DTimedMetric implements TimedMetric {
private final String name;
private final ValueAdder count = new ValueAdder();
private final ValueAdder total = new ValueAdder();
private final ValueMax max;
private final LongAccumulator max = new LongAccumulator(Math::max, 0);
private boolean collected;
private String reportName;
DTimedMetric(String name) {
this(name, new ValueMax());
}
DTimedMetric(String name, ValueMax max) {
this.name = name;
this.max = max;
}
@Override
@@ -34,7 +31,7 @@ final class DTimedMetric implements TimedMetric {
final long mean = totalMicros / batch;
count.add(batch);
total.add(totalMicros);
max.add(mean);
max.accumulate(mean);
}
}
@@ -47,7 +44,7 @@ final class DTimedMetric implements TimedMetric {
public void add(long value) {
count.add(1);
total.add(value);
max.add(value);
max.accumulate(value);
}
@Override
@@ -64,63 +61,31 @@ final class DTimedMetric implements TimedMetric {
@Override
public void visit(MetricVisitor visitor) {
final DTimeMetricStats stats = collect(visitor.mode());
if (stats != null) {
final boolean reset = visitor.reset();
final long countSum = count.get(reset);
if (countSum > 0) {
final String name = reportName != null ? reportName : reportName(visitor);
stats.setName(name);
visitor.visitTimed(stats);
visitor.visitTimed(stats(reset, name, countSum));
}
}
@Override
public DTimeMetricStats collect(boolean reset) {
return collect(reset ? MetricVisitor.Mode.RESET : MetricVisitor.Mode.CUMULATIVE);
}
@Override
public DTimeMetricStats collect(MetricVisitor.Mode mode) {
final long maxValue = max.collect();
final long countSum;
switch (mode) {
case RESET:
countSum = count.getAndReset();
break;
case CUMULATIVE:
countSum = count.cumulative();
break;
case DELTA:
countSum = count.delta();
break;
default:
throw new IllegalStateException("Unknown metric collection mode");
}
final long countSum = count.get(reset);
if (countSum == 0) {
return null;
} else {
return stats(mode, name, countSum, maxValue);
return stats(reset, name, countSum);
}
}
/**
* Return the current statistics resetting the internal values if reset is true.
*/
private DTimeMetricStats stats(MetricVisitor.Mode mode, String name, long countSum, long maxValue) {
private DTimeMetricStats stats(boolean reset, String name, long countSum) {
try {
final long totalSum;
switch (mode) {
case RESET:
totalSum = total.getAndReset();
break;
case CUMULATIVE:
totalSum = total.cumulative();
break;
case DELTA:
totalSum = total.delta();
break;
default:
throw new IllegalStateException("Unknown metric collection mode");
}
return new DTimeMetricStats(name, collected, countSum, totalSum, maxValue);
final long totalSum = total.get(reset);
return new DTimeMetricStats(name, collected, countSum, totalSum, max.getThenReset());
} finally {
collected = true;
}
@@ -46,7 +46,7 @@ final class DTimedProfileLocation extends DProfileLocation implements TimedProfi
@Override
public void visit(MetricVisitor visitor) {
TimedMetricStats collect = timedMetric.collect(visitor.mode());
TimedMetricStats collect = timedMetric.collect(visitor.reset());
if (collect != null) {
final String name = reportName != null ? reportName : reportName(visitor, collect.name());
collect.setName(name);
@@ -15,22 +15,16 @@ final class ValueAdder {
value.add(amount);
}
long cumulative() {
return value.sum();
}
long delta() {
long get(boolean reset) {
long currentValue = value.sum();
if (!reset) {
return currentValue;
}
long previous = previousValue.getAndSet(currentValue);
return currentValue >= previous ? currentValue - previous : currentValue;
}
long getAndReset() {
long currentValue = value.sumThenReset();
previousValue.set(0);
return currentValue;
}
void reset() {
value.reset();
previousValue.set(0);
@@ -1,48 +0,0 @@
package io.ebeaninternal.server.profile;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAccumulator;
import java.util.function.LongSupplier;
/**
* Accumulates a maximum value and publishes it in rolling 59-second windows.
*/
final class ValueMax {
private static final long WINDOW_NANOS = TimeUnit.SECONDS.toNanos(59);
private final LongSupplier nanoTime;
private final LongAccumulator value;
private volatile long published;
private long lastResetNanos;
ValueMax() {
this(System::nanoTime);
}
ValueMax(LongSupplier nanoTime) {
this.nanoTime = nanoTime;
this.value = new LongAccumulator(Math::max, 0);
this.lastResetNanos = nanoTime.getAsLong() - 2 * WINDOW_NANOS;
}
void add(long amount) {
value.accumulate(amount);
}
synchronized long collect() {
long now = nanoTime.getAsLong();
if (now - lastResetNanos >= WINDOW_NANOS) {
published = value.getThenReset();
lastResetNanos = now;
}
return published;
}
synchronized void reset() {
value.reset();
published = 0;
lastResetNanos = nanoTime.getAsLong() - 2 * WINDOW_NANOS;
}
}
@@ -285,9 +285,7 @@ public class TransactionManager implements SpiTransactionManager {
private SpiTransaction createTransaction(TxScope txScope) {
if (txScope.isReadonly()) {
// Honor isolation on read-only scopes (e.g. @Transactional(readOnly=true, isolation=...))
SpiTransaction transaction = createReadOnlyTransaction(null, false);
return transactionFactory.setIsolationLevel(transaction, txScope.getIsolationLevel());
return createReadOnlyTransaction(null, false);
} else {
return createTransaction(true, txScope.getIsolationLevel());
}
@@ -2,7 +2,6 @@ package io.ebeaninternal.server.profile;
import io.ebean.meta.BasicMetricVisitor;
import io.ebean.meta.MetaCountMetric;
import io.ebean.meta.MetricVisitor;
import org.junit.jupiter.api.Test;
import java.util.List;
@@ -52,50 +51,8 @@ class DCountMetricTest {
assertThat(counter.get(true)).isEqualTo(7);
counter.add(5);
assertThat(counter.get(false)).isEqualTo(5);
assertThat(counter.get(false)).isEqualTo(12);
assertThat(counter.get(true)).isEqualTo(5);
assertThat(counter.get(true)).isEqualTo(0);
}
@Test
void valueAdderSupportsExplicitCollectionOperations() {
var values = new ValueAdder();
values.add(7);
assertThat(values.cumulative()).isEqualTo(7);
assertThat(values.delta()).isEqualTo(7);
values.add(5);
assertThat(values.cumulative()).isEqualTo(12);
assertThat(values.delta()).isEqualTo(5);
assertThat(values.getAndReset()).isEqualTo(12);
assertThat(values.cumulative()).isEqualTo(0);
assertThat(values.delta()).isEqualTo(0);
}
@Test
void visitorCanCollectDeltaWithoutResettingCumulativeValue() {
var counter = new DCountMetric("org.hello");
counter.add(7);
var cumulative = new BasicMetricVisitor("db", naming, MetricVisitor.Mode.CUMULATIVE, true, true, true);
counter.visit(cumulative);
assertThat(cumulative.countMetrics()).hasSize(1);
assertThat(cumulative.countMetrics().get(0).count()).isEqualTo(7);
var delta = new BasicMetricVisitor("db", naming, MetricVisitor.Mode.DELTA, true, true, true);
counter.visit(delta);
assertThat(delta.countMetrics()).hasSize(1);
assertThat(delta.countMetrics().get(0).count()).isEqualTo(7);
counter.add(5);
delta = new BasicMetricVisitor("db", naming, MetricVisitor.Mode.DELTA, true, true, true);
counter.visit(delta);
assertThat(delta.countMetrics()).hasSize(1);
assertThat(delta.countMetrics().get(0).count()).isEqualTo(5);
cumulative = new BasicMetricVisitor("db", naming, MetricVisitor.Mode.CUMULATIVE, true, true, true);
counter.visit(cumulative);
assertThat(cumulative.countMetrics().get(0).count()).isEqualTo(12);
}
}
@@ -5,22 +5,19 @@ import io.ebean.meta.MetaQueryMetric;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import static org.assertj.core.api.Assertions.assertThat;
class DQueryPlanMetricTest {
private final AtomicLong nanoTime = new AtomicLong();
Function<String, String> naming = (String name) -> "prefix[" + name.replace('.', '-') + "]";
@Test
void visit() {
DQueryPlanMeta meta = new DQueryPlanMeta(Object.class, "dto.Object.lab", "lab", null, "sql", "hash");
DTimedMetric metric = new DTimedMetric("org.timed.plan", new ValueMax(nanoTime::get));
DTimedMetric metric = new DTimedMetric("org.timed.plan");
DQueryPlanMetric planMetric = new DQueryPlanMetric(meta, metric);
metric.add(560);
@@ -49,10 +46,10 @@ class DQueryPlanMetricTest {
}
@Test
void visitCumulativePublishesSharedMax() {
void visitCumulativeResetsMax() {
DQueryPlanMeta meta = new DQueryPlanMeta(Object.class, "dto.Object.lab", "lab", null, "sql", "hash");
DTimedMetric metric = new DTimedMetric("org.timed.plan", new ValueMax(nanoTime::get));
DTimedMetric metric = new DTimedMetric("org.timed.plan");
DQueryPlanMetric planMetric = new DQueryPlanMetric(meta, metric);
metric.add(560);
@@ -77,7 +74,7 @@ class DQueryPlanMetricTest {
assertThat(result.get(0).name()).isEqualTo("prefix[dto-Object-lab]");
assertThat(result.get(0).count()).isEqualTo(2);
assertThat(result.get(0).total()).isEqualTo(820);
assertThat(result.get(0).max()).isEqualTo(560);
assertThat(result.get(0).max()).isEqualTo(0);
}
metric.add(410);
@@ -90,14 +87,7 @@ class DQueryPlanMetricTest {
assertThat(result.get(0).name()).isEqualTo("prefix[dto-Object-lab]");
assertThat(result.get(0).count()).isEqualTo(3);
assertThat(result.get(0).total()).isEqualTo(1230);
assertThat(result.get(0).max()).isEqualTo(560);
assertThat(result.get(0).max()).isEqualTo(410);
}
nanoTime.addAndGet(TimeUnit.SECONDS.toNanos(59));
BasicMetricVisitor visitor = new BasicMetricVisitor("v", naming, false, true, true, true);
planMetric.visit(visitor);
List<MetaQueryMetric> result = visitor.queryMetrics();
assertThat(result).hasSize(1);
assertThat(result.get(0).max()).isEqualTo(410);
}
}
@@ -5,20 +5,16 @@ import io.ebean.meta.MetaTimedMetric;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import static org.assertj.core.api.Assertions.assertThat;
public class DTimedMetricTest {
private final AtomicLong nanoTime = new AtomicLong();
@Test
public void addSinceNanos() throws InterruptedException {
DTimedMetric metric = new DTimedMetric("addSinceNanos", new ValueMax(nanoTime::get));
DTimedMetric metric = new DTimedMetric("addSinceNanos");
long start = System.nanoTime();
Thread.sleep(11);
@@ -32,7 +28,6 @@ public class DTimedMetricTest {
metric.addSinceNanos(start);
nanoTime.addAndGet(TimeUnit.SECONDS.toNanos(59));
stats = metric.collect(true);
assertThat(stats.count()).isEqualTo(1);
assertThat(stats.total()).isGreaterThan(10);
@@ -42,7 +37,7 @@ public class DTimedMetricTest {
@Test
public void addBatchSince() throws InterruptedException {
DTimedMetric metric = new DTimedMetric("addSinceNanos", new ValueMax(nanoTime::get));
DTimedMetric metric = new DTimedMetric("addSinceNanos");
long start = System.nanoTime();
Thread.sleep(11);
@@ -57,7 +52,6 @@ public class DTimedMetricTest {
metric.addBatchSince(start, 2);
nanoTime.addAndGet(TimeUnit.SECONDS.toNanos(59));
stats = metric.collect(true);
assertThat(stats.count()).isEqualTo(2);
assertThat(stats.total()).isGreaterThan(10000);
@@ -98,8 +92,8 @@ public class DTimedMetricTest {
}
@Test
void collectCumulativePublishesSharedMax() {
DTimedMetric metric = new DTimedMetric("org.timed", new ValueMax(nanoTime::get));
void collectCumulativeResetsMax() {
DTimedMetric metric = new DTimedMetric("org.timed");
metric.add(560);
metric.add(500);
@@ -111,7 +105,7 @@ public class DTimedMetricTest {
stats = metric.collect(false);
assertThat(stats.count()).isEqualTo(2);
assertThat(stats.total()).isEqualTo(1060);
assertThat(stats.max()).isEqualTo(560);
assertThat(stats.max()).isEqualTo(0);
metric.add(160);
metric.add(100);
@@ -120,16 +114,12 @@ public class DTimedMetricTest {
stats = metric.collect(false);
assertThat(stats.count()).isEqualTo(5);
assertThat(stats.total()).isEqualTo(1470);
assertThat(stats.max()).isEqualTo(560);
nanoTime.addAndGet(TimeUnit.SECONDS.toNanos(59));
stats = metric.collect(false);
assertThat(stats.max()).isEqualTo(160);
}
@Test
void cumulativeAndDeltaAreIndependent() {
DTimedMetric metric = new DTimedMetric("org.timed", new ValueMax(nanoTime::get));
DTimedMetric metric = new DTimedMetric("org.timed");
metric.add(560);
metric.add(500);
@@ -142,9 +132,9 @@ public class DTimedMetricTest {
DTimeMetricStats delta = metric.collect(true);
assertThat(delta.count()).isEqualTo(3);
assertThat(delta.total()).isEqualTo(1220);
assertThat(delta.max()).isEqualTo(560);
cumulative = metric.collect(false);
assertThat(cumulative).isNull();
assertThat(cumulative.count()).isEqualTo(3);
assertThat(cumulative.total()).isEqualTo(1220);
}
}
+4 -4
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<name>ebean ddl generation</name>
@@ -28,14 +28,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-type</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
@@ -65,7 +65,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-all</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
+2 -2
View File
@@ -3,7 +3,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -15,7 +15,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-type</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
+4 -4
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<name>ebean net postgis types</name>
@@ -19,14 +19,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<!-- provided scope -->
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
@@ -54,7 +54,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>ebean-opentelemetry</artifactId>
@@ -28,7 +28,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
@@ -71,21 +71,21 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>querybean-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
+4 -4
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<name>ebean pgvector types</name>
@@ -19,14 +19,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<!-- provided scope -->
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
@@ -54,7 +54,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
+4 -4
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<name>ebean postgis types</name>
@@ -19,14 +19,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<!-- provided scope -->
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
@@ -62,7 +62,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<name>ebean querybean</name>
@@ -17,7 +17,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
@@ -59,14 +59,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
@@ -80,7 +80,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>querybean-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
+6 -6
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>ebean-redis</artifactId>
@@ -29,35 +29,35 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>querybean-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
+6 -6
View File
@@ -6,7 +6,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>ebean-redisson</artifactId>
@@ -29,35 +29,35 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>querybean-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
+3 -3
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>ebean-spring-txn</artifactId>
@@ -28,7 +28,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
@@ -77,7 +77,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
+7 -7
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<name>ebean test</name>
@@ -33,20 +33,20 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -149,14 +149,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-jackson-mapper</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-all</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
@@ -240,7 +240,7 @@
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.3.5</version>
<version>3.0.7</version>
<scope>test</scope>
</dependency>
@@ -1,95 +0,0 @@
package org.tests.delete;
import io.ebean.DB;
import io.ebean.Transaction;
import io.ebean.test.LoggedSql;
import io.ebean.xtest.BaseTestCase;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.tests.model.deleteorder.DcoAsset;
import org.tests.model.deleteorder.DcoLinkAdapter;
import org.tests.model.deleteorder.DcoParent;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
* A join entity owns the foreign key to the bean its delete cascades to, so the join row has to be
* deleted first. When a persist callback writes to the database it flushes the batch from inside the
* flush that is already running : the outer flush has taken the join rows out of their bean holder,
* so the inner flush only finds the assets and executes them first.
* <p>
* See <a href="https://github.com/ebean-orm/ebean/issues/1852">#1852</a>.
*/
class TestDeleteCascadeOrder extends BaseTestCase {
@AfterEach
void after() {
DcoLinkAdapter.reset();
}
@Test
void deleteLinkBeforeAsset() {
assertLinkDeletedBeforeAsset(deleteAllLinks(newParent(2)));
}
@Test
void deleteLinkBeforeAsset_whenCallbackWritesOnPreDelete() {
DcoLinkAdapter.writeOnPreDelete(true);
assertLinkDeletedBeforeAsset(deleteAllLinks(newParent(2)));
}
@Test
void deleteLinkBeforeAsset_whenCallbackWritesOnPostDelete() {
DcoLinkAdapter.writeOnPostDelete(true);
assertLinkDeletedBeforeAsset(deleteAllLinks(newParent(2)));
}
private Long newParent(int assetCount) {
DcoParent parent = new DcoParent("parent-" + assetCount);
for (int i = 0; i < assetCount; i++) {
parent.addAsset(new DcoAsset("asset-" + i));
}
DB.save(parent);
return parent.getId();
}
/**
* Remove every link of the parent, which cascades the delete to the assets behind them. The graph is
* fetched up front : a lazy load would flush the batch on its own and hide the ordering.
*/
private List<String> deleteAllLinks(Long parentId) {
try (Transaction txn = DB.beginTransaction()) {
txn.setBatchMode(true);
DcoParent parent = DB.find(DcoParent.class)
.fetch("links")
.fetch("links.asset")
.where().idEq(parentId)
.findOne();
parent.getLinks().clear();
LoggedSql.start();
DB.save(parent);
txn.commit();
return LoggedSql.stop();
}
}
private void assertLinkDeletedBeforeAsset(List<String> sql) {
assertThat(firstIndexOf(sql, "delete from dco_link"))
.as("the join row must be deleted before the asset it references, statements were :%n%s", String.join("\n", sql))
.isLessThan(firstIndexOf(sql, "delete from dco_asset"));
}
private int firstIndexOf(List<String> sql, String fragment) {
for (int i = 0; i < sql.size(); i++) {
if (sql.get(i).contains(fragment)) {
return i;
}
}
throw new AssertionError("no statement containing '" + fragment + "', statements were :\n" + String.join("\n", sql));
}
}
@@ -1,50 +0,0 @@
package org.tests.delete;
import io.ebean.DB;
import io.ebean.xtest.BaseTestCase;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.tests.model.deleteorder.DcoTree;
import org.tests.model.deleteorder.DcoTreeContainer;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The tree shape reported on <a href="https://github.com/ebean-orm/ebean/issues/1852">#1852</a> :
* deleting the container cascades down a self referencing tree, and the deletes have to reach the
* leaves before their parents.
*/
class TestDeleteTreeCascadeOrder extends BaseTestCase {
/**
* Still reproduces on 18.4.0. The tree is deleted level by level but not deepest first :
* <pre>
* delete from dco_tree where id in (?) -- the root, whose children are still there
* delete from dco_tree where id in (?,?,?)
* delete from dco_tree where id in (?,?)
* </pre>
* which fails with "Referential integrity constraint violation: FK_DCO_TREE_PARENT_ID". Disabled so
* that it does not break the build, remove the annotation to see the failure.
*/
@Disabled("reproduces #1852, not fixed yet")
@Test
void deleteContainerOfNestedTree() {
DcoTreeContainer container = new DcoTreeContainer();
DcoTree root = new DcoTree("root");
DcoTree child1 = root.addChild("child 1");
child1.addChild("child 1a").addChild("child 1a1");
DcoTree child2 = root.addChild("child 2");
child2.addChild("child 2a");
child2.addChild("child 2b");
container.getTrees().add(root);
DB.save(container);
DB.delete(container);
assertThat(DB.find(DcoTree.class).findCount()).isZero();
assertThat(DB.find(DcoTreeContainer.class).where().idEq(container.getId()).findCount()).isZero();
}
}
@@ -1,91 +0,0 @@
package org.tests.delete;
import io.ebean.DB;
import io.ebean.Transaction;
import io.ebean.test.LoggedSql;
import io.ebean.xtest.BaseTestCase;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.tests.model.deleteorder.DcoAsset;
import org.tests.model.deleteorder.DcoParent;
import org.tests.model.deleteorder.DcoParentAdapter;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Same defect as the cascaded delete one, on the insert side : a persist done from a BeanPersistController
* flushes the batch from inside the flush that is already running, and the statements queued behind the
* one being executed are issued out of order.
* <p>
* <a href="https://github.com/ebean-orm/ebean/pull/3148">#3148</a> fixed this for a flush triggered by a
* query (BatchControl.executeNow disables flushOnQuery), but a flush triggered by a write goes through
* BatchControl.executeOrQueue, which that guard does not cover.
*/
class TestInsertCascadeOrder extends BaseTestCase {
@AfterEach
void after() {
DcoParentAdapter.writeOnPreInsert(false);
DcoParentAdapter.sqlUpdateOnPreInsert(false);
}
@Test
void insertParentBeforeItsLinks_whenCallbackWritesDuringFlush() {
DcoParentAdapter.writeOnPreInsert(true);
List<String> sql = insertParents(3);
// every parent has to be inserted before the link that points at it
assertThat(lastIndexOf(sql, "insert into dco_parent"))
.as("a parent must be inserted before the links referencing it, statements were :%n%s", String.join("\n", sql))
.isLessThan(lastIndexOf(sql, "insert into dco_link"));
}
/**
* Same as above but the callback runs a SqlUpdate, which reaches BatchControl by
* executeStatementOrBatch rather than executeOrQueue.
*/
@Test
void insertParentBeforeItsLinks_whenCallbackRunsSqlUpdateDuringFlush() {
DcoParentAdapter.sqlUpdateOnPreInsert(true);
List<String> sql = insertParents(3);
assertThat(lastIndexOf(sql, "insert into dco_parent"))
.as("a parent must be inserted before the links referencing it, statements were :%n%s", String.join("\n", sql))
.isLessThan(lastIndexOf(sql, "insert into dco_link"));
}
private List<String> insertParents(int count) {
List<DcoParent> parents = new ArrayList<>();
for (int i = 0; i < count; i++) {
DcoParent parent = new DcoParent("batch-parent-" + i);
parent.addAsset(new DcoAsset("batch-asset-" + i));
parents.add(parent);
}
try (Transaction txn = DB.beginTransaction()) {
txn.setBatchMode(true);
txn.setBatchSize(50);
LoggedSql.start();
DB.saveAll(parents);
txn.commit();
List<String> sql = LoggedSql.stop();
System.out.println("---- insert order ----");
sql.stream().filter(s -> !s.contains("-- bind")).forEach(s -> System.out.println(" " + s));
return sql;
}
}
private int lastIndexOf(List<String> sql, String fragment) {
for (int i = sql.size() - 1; i >= 0; i--) {
if (sql.get(i).contains(fragment)) {
return i;
}
}
throw new AssertionError("no statement containing '" + fragment + "', statements were :\n" + String.join("\n", sql));
}
}
@@ -30,7 +30,6 @@ public class TestNatKeyCacheWithForeignKey extends BaseTestCase {
setupData();
clearAllL2Cache();
getStats();
final OCachedAppDetail found0 = findDetail(app0, "detail0");
assertThat(found0).isNotNull();
@@ -1,34 +0,0 @@
package org.tests.model.deleteorder;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Version;
/**
* Owned by a {@link DcoLink} through a cascading OneToOne, so deleting the link deletes the asset.
*/
@Entity
public class DcoAsset {
@Id
@GeneratedValue
Long id;
@Version
Long version;
String name;
public DcoAsset(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
}
@@ -1,30 +0,0 @@
package org.tests.model.deleteorder;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
/**
* Written from the delete callback of {@link DcoLink}, the way an audit or an outbox row is.
*/
@Entity
public class DcoAudit {
@Id
@GeneratedValue
Long id;
String message;
public DcoAudit(String message) {
this.message = message;
}
public Long getId() {
return id;
}
public String getMessage() {
return message;
}
}
@@ -1,46 +0,0 @@
package org.tests.model.deleteorder;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
/**
* Join entity between {@link DcoParent} and {@link DcoAsset}. It owns the foreign key to the asset,
* so the link row has to be deleted before the asset it points at.
* <p>
* A real entity (rather than a plain join table) so that its delete fires a persistence callback,
* see {@link DcoLinkAdapter}.
*/
@Entity
public class DcoLink {
@Id
@GeneratedValue
Long id;
@ManyToOne(optional = false)
DcoParent parent;
@OneToOne(optional = false, cascade = CascadeType.ALL, orphanRemoval = true)
DcoAsset asset;
public DcoLink(DcoParent parent, DcoAsset asset) {
this.parent = parent;
this.asset = asset;
}
public Long getId() {
return id;
}
public DcoParent getParent() {
return parent;
}
public DcoAsset getAsset() {
return asset;
}
}
@@ -1,54 +0,0 @@
package org.tests.model.deleteorder;
import io.ebean.event.BeanPersistAdapter;
import io.ebean.event.BeanPersistRequest;
/**
* Persists a bean from inside a delete callback of {@link DcoLink}, the way an audit or an outbox row
* is written. The BeanPersistController javadoc documents this as a supported use case.
* <p>
* Off by default so that the callbacks only fire for the tests that ask for them.
*/
public class DcoLinkAdapter extends BeanPersistAdapter {
private static boolean writeOnPreDelete;
private static boolean writeOnPostDelete;
public static void writeOnPreDelete(boolean enabled) {
writeOnPreDelete = enabled;
}
public static void writeOnPostDelete(boolean enabled) {
writeOnPostDelete = enabled;
}
public static void reset() {
writeOnPreDelete = false;
writeOnPostDelete = false;
}
@Override
public boolean isRegisterFor(Class<?> cls) {
return DcoLink.class.equals(cls);
}
@Override
public boolean preDelete(BeanPersistRequest<?> request) {
if (writeOnPreDelete) {
audit(request, "pre");
}
return true;
}
@Override
public void postDelete(BeanPersistRequest<?> request) {
if (writeOnPostDelete) {
audit(request, "post");
}
}
private void audit(BeanPersistRequest<?> request, String phase) {
DcoLink link = (DcoLink) request.bean();
request.database().save(new DcoAudit(phase + " delete of link " + link.getId()), request.transaction());
}
}
@@ -1,50 +0,0 @@
package org.tests.model.deleteorder;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
/**
* Parent of a join entity, see {@link DcoLink}.
*/
@Entity
public class DcoParent {
@Id
@GeneratedValue
Long id;
String name;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent", orphanRemoval = true)
List<DcoLink> links = new ArrayList<>();
public DcoParent(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<DcoLink> getLinks() {
return links;
}
public void addAsset(DcoAsset asset) {
links.add(new DcoLink(this, asset));
}
}
@@ -1,49 +0,0 @@
package org.tests.model.deleteorder;
import io.ebean.event.BeanPersistAdapter;
import io.ebean.event.BeanPersistRequest;
/**
* Persists a bean from inside the insert callback of {@link DcoParent}, the way an audit or an outbox
* row is written. The BeanPersistController javadoc documents this as a supported use case.
* <p>
* Off by default so that the callback only fires for the tests that ask for it.
*/
public class DcoParentAdapter extends BeanPersistAdapter {
private static boolean writeOnPreInsert;
private static boolean sqlUpdateOnPreInsert;
public static void writeOnPreInsert(boolean enabled) {
writeOnPreInsert = enabled;
}
/**
* Same as {@link #writeOnPreInsert(boolean)} but through SqlUpdate, which takes the
* BatchControl.executeStatementOrBatch path rather than executeOrQueue.
*/
public static void sqlUpdateOnPreInsert(boolean enabled) {
sqlUpdateOnPreInsert = enabled;
}
@Override
public boolean isRegisterFor(Class<?> cls) {
return DcoParent.class.equals(cls);
}
@Override
public boolean preInsert(BeanPersistRequest<?> request) {
DcoParent parent = (DcoParent) request.bean();
if (writeOnPreInsert) {
request.database().save(new DcoAudit("inserting " + parent.getName()), request.transaction());
}
if (sqlUpdateOnPreInsert) {
request.database().sqlUpdate("update dco_audit set message = ? where id = ?")
.setParameter(1, "inserting " + parent.getName())
.setParameter(2, -1L)
.usingTransaction(request.transaction())
.execute();
}
return true;
}
}
@@ -1,52 +0,0 @@
package org.tests.model.deleteorder;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
/**
* Self referencing tree, as reported on #1852.
*/
@Entity
public class DcoTree {
@Id
@GeneratedValue
Long id;
String name;
@ManyToOne
DcoTree parent;
@ManyToOne
DcoTreeContainer container;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
List<DcoTree> children = new ArrayList<>();
public DcoTree(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public List<DcoTree> getChildren() {
return children;
}
public DcoTree addChild(String name) {
DcoTree child = new DcoTree(name);
child.parent = this;
children.add(child);
return child;
}
}
@@ -1,32 +0,0 @@
package org.tests.model.deleteorder;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
/**
* Holds the roots of a {@link DcoTree}, as reported on #1852.
*/
@Entity
public class DcoTreeContainer {
@Id
@GeneratedValue
Long id;
@OneToMany(cascade = CascadeType.ALL)
List<DcoTree> trees = new ArrayList<>();
public Long getId() {
return id;
}
public List<DcoTree> getTrees() {
return trees;
}
}
@@ -1,17 +1,12 @@
package org.tests.transaction;
import io.ebean.DB;
import io.ebean.Transaction;
import io.ebean.TxScope;
import io.ebean.annotation.Transactional;
import io.ebean.annotation.TxIsolation;
import io.ebean.meta.MetaTimedMetric;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import io.ebean.annotation.Transactional;
import io.ebean.meta.MetaTimedMetric;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Optional;
@@ -43,33 +38,6 @@ public class TestTransactionalReadOnly extends BaseTestCase {
assertThat(metric(timedMetrics, "txn.readonly")).isEmpty();
}
/**
* #3407 read-only TxScope must honor isolation (previously dropped for createReadOnlyTransaction).
*/
@Test
public void test_readonly_honors_isolation() throws SQLException {
TxScope scope = TxScope.required()
.setReadOnly(true)
.setIsolation(TxIsolation.SERIALIZABLE);
DB.execute(scope, () -> {
Transaction txn = DB.currentTransaction();
assertThat(txn).isNotNull();
try {
assertThat(txn.connection().getTransactionIsolation())
.isEqualTo(Connection.TRANSACTION_SERIALIZABLE);
} catch (SQLException e) {
throw new RuntimeException(e);
}
DB.find(Customer.class).findCount();
});
}
@Test
public void test_readonly_annotation_honors_isolation() throws SQLException {
executeTransactionalReadOnlyWithIsolation();
}
private Optional<MetaTimedMetric> metric(List<MetaTimedMetric> timedMetrics, String name) {
return timedMetrics.stream()
.filter(metaTimedMetric -> metaTimedMetric.name().equals(name))
@@ -85,13 +53,4 @@ public class TestTransactionalReadOnly extends BaseTestCase {
private void executeTransactionalUsingMainDataSource() {
DB.find(Customer.class).findCount();
}
@Transactional(readOnly = true, isolation = TxIsolation.SERIALIZABLE)
private void executeTransactionalReadOnlyWithIsolation() throws SQLException {
Transaction txn = DB.currentTransaction();
assertThat(txn).isNotNull();
assertThat(txn.connection().getTransactionIsolation())
.isEqualTo(Connection.TRANSACTION_SERIALIZABLE);
DB.find(Customer.class).findCount();
}
}
+2 -2
View File
@@ -15,8 +15,8 @@ mvn -T 4 clean package
mvn -T 4 deploy -pl '!composites,!platforms' -Pcentral -DskipTests
## git commit, git tag, git push --tags
git commit -am 'Version 18.5.0'
git tag 18.5.0
git commit -am 'Version 18.4.0'
git tag 18.4.0
git push --tags
### convert to javax
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<name>kotlin querybean generator</name>
@@ -21,7 +21,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
@@ -35,7 +35,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
@@ -56,14 +56,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
+14 -14
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,67 +16,67 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-clickhouse</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-db2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-hana</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-hsqldb</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-mysql</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-mariadb</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-nuodb</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-oracle</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlanywhere</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlite</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlserver</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<!-- Provided scope so that the H2HistoryTrigger can live in Ebean core
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+3 -3
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,13 +16,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-mysql</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+1 -1
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>platforms</artifactId>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -1,11 +0,0 @@
[
{"name": "org.postgis.DriverWrapperLW", "allDeclaredConstructors": true},
{"name": "org.postgis.DriverWrapper", "allDeclaredConstructors": true},
{"name": "org.postgis.DriverWrapper$TypesAdder80", "allDeclaredConstructors": true},
{"name": "org.postgis.PGbox2d", "allDeclaredConstructors": true},
{"name": "org.postgis.PGbox3d", "allDeclaredConstructors": true},
{"name": "org.postgis.PGgeography", "allDeclaredConstructors": true},
{"name": "org.postgis.PGgeographyLW", "allDeclaredConstructors": true},
{"name": "org.postgis.PGgeometry", "allDeclaredConstructors": true},
{"name": "org.postgis.PGgeometryLW", "allDeclaredConstructors": true}
]
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
<relativePath>../..</relativePath>
</parent>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
</dependencies>
+4 -4
View File
@@ -9,7 +9,7 @@
<groupId>io.ebean</groupId>
<artifactId>ebean-parent</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<packaging>pom</packaging>
<name>ebean parent</name>
@@ -51,9 +51,9 @@
<ebean-migration-auto.version>1.2</ebean-migration-auto.version>
<ebean-migration.version>14.4.0</ebean-migration.version>
<ebean-test-containers.version>8.2</ebean-test-containers.version>
<ebean-datasource.version>10.12</ebean-datasource.version>
<ebean-agent.version>18.5.0</ebean-agent.version>
<ebean-maven-plugin.version>18.5.0</ebean-maven-plugin.version>
<ebean-datasource.version>10.10</ebean-datasource.version>
<ebean-agent.version>18.4.0</ebean-agent.version>
<ebean-maven-plugin.version>18.4.0</ebean-maven-plugin.version>
<surefire.useModulePath>false</surefire.useModulePath>
</properties>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<name>querybean generator</name>
@@ -45,7 +45,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -234,11 +234,9 @@ class DtoMapperWriter {
Set<String> nestedAssocPaths = new LinkedHashSet<>();
for (DtoPropertyMeta property : activeProperties) {
if ((property.kind() == DtoPropertyMeta.Kind.NESTED_ONE || property.kind() == DtoPropertyMeta.Kind.NESTED_MANY)
&& !property.isUnfetchable()
&& !property.hasComputedSegment()) {
nestedAssocPaths.add(property.sourcePropertyPath().get(0));
} else if (property.kind() == DtoPropertyMeta.Kind.SCALAR && property.isListTarget()
&& !property.isScalarCollection()
&& !property.hasComputedSegment() && property.sourcePropertyPath().size() == 1) {
// a single-segment SCALAR property whose DTO field is a List with no registered nested
// DTO mapping of its own (e.g. @DtoConvert reducing a ToMany association) - still fully
@@ -255,7 +253,7 @@ class DtoMapperWriter {
switch (property.kind()) {
case NESTED_ONE:
case NESTED_MANY:
if (property.hasComputedSegment() || property.isUnfetchable()) {
if (property.hasComputedSegment()) {
// a single-hop @DtoPath rename traversing a computed/derived getter (no backing
// field) that happens to target a nested DTO type - just as unfetchable via
// fetch(path, mapper.fetchGroup()) as the analogous SCALAR case, since "path" here
@@ -269,7 +267,7 @@ class DtoMapperWriter {
property.sourcePropertyPath().get(0), mapperFieldName(property)));
break;
case SCALAR:
if (property.hasComputedSegment() || property.isUnfetchable()) {
if (property.hasComputedSegment()) {
// the path traverses a computed/derived getter (no backing field) - its own segments
// past that point aren't real Ebean fetch paths, so don't add them to pathSelect/
// rootSelect at all; @DtoPath#requires() (plus the real prefix, if any) already names
@@ -279,7 +277,7 @@ class DtoMapperWriter {
}
List<String> path = property.sourcePropertyPath();
if (path.size() == 1) {
if (property.isListTarget() && !property.isScalarCollection()) {
if (property.isListTarget()) {
// a single-segment path whose DTO field type is a List, but with no registered
// nested DTO mapping of its own (e.g. a @DtoConvert-backed property reducing a
// ToMany association to a simpler element type) - the source side is still a real
@@ -819,37 +819,32 @@ class DtoMappingReader {
// straight into a NullPointerException. Default to the primitive's zero-equivalent value,
// or fail fast with a clear message instead when @DtoPath(failOnNull = true).
boolean isListTarget = listElementType(field.asType()) != null;
boolean scalarCollection = isListTarget && isScalarCollectionProperty(lastOwnerType, properties.get(properties.size() - 1));
DtoConverterMeta pathConverter = isListTarget ? converter
: autoTypeConverter(converter, lastOwnerType != null ? getterReturnTypeMirror(lastOwnerType, lastGetter) : null, field.asType());
return new DtoPropertyMeta(name, DtoPropertyMeta.Kind.SCALAR, getters, properties, null, pathConverter,
field.asType().getKind().isPrimitive(), pathPrism.failOnNull(), computedFrom >= 0, requiredFetchPaths,
isListTarget, scalarCollection, false);
isListTarget, false);
}
TypeMirror fieldType = field.asType();
TypeMirror listElementType = listElementType(fieldType);
boolean unfetchable = isUnfetchableProperty(meta.source(), name);
if (listElementType != null) {
DtoBeanMeta nested = lookupByTarget(listElementType);
if (nested != null) {
rejectConverterOnNested(field, converter, name, meta);
return new DtoPropertyMeta(name, DtoPropertyMeta.Kind.NESTED_MANY, List.of(getterName(meta.source(), name)), List.of(name), nested,
unfetchable, List.of());
return new DtoPropertyMeta(name, DtoPropertyMeta.Kind.NESTED_MANY, List.of(getterName(meta.source(), name)), List.of(name), nested);
}
} else {
DtoBeanMeta nested = lookupByTarget(fieldType);
if (nested != null) {
rejectConverterOnNested(field, converter, name, meta);
return new DtoPropertyMeta(name, DtoPropertyMeta.Kind.NESTED_ONE, List.of(getterName(meta.source(), name)), List.of(name), nested,
unfetchable, List.of());
return new DtoPropertyMeta(name, DtoPropertyMeta.Kind.NESTED_ONE, List.of(getterName(meta.source(), name)), List.of(name), nested);
}
}
String getter = getterName(meta.source(), name);
boolean scalarCollection = listElementType != null && isScalarCollectionProperty(meta.source(), name);
DtoConverterMeta scalarConverter = listElementType != null ? converter
: autoTypeConverter(converter, getterReturnTypeMirror(meta.source(), getter), fieldType);
return new DtoPropertyMeta(name, DtoPropertyMeta.Kind.SCALAR, List.of(getter), List.of(name), null, scalarConverter,
fieldType.getKind().isPrimitive(), false, false, List.of(), listElementType != null, scalarCollection, unfetchable, false);
fieldType.getKind().isPrimitive(), listElementType != null);
}
/**
@@ -1060,35 +1055,7 @@ class DtoMappingReader {
for (TypeElement current = type; current != null; current = superclassOf(current)) {
for (VariableElement f : ElementFilter.fieldsIn(current.getEnclosedElements())) {
if (f.getSimpleName().contentEquals(propertyName)) {
return !ctx.isTransientField(f);
}
}
}
return false;
}
private boolean isScalarCollectionProperty(TypeElement type, String propertyName) {
if (type == null) {
return false;
}
for (TypeElement current = type; current != null; current = superclassOf(current)) {
for (VariableElement field : ElementFilter.fieldsIn(current.getEnclosedElements())) {
if (field.getSimpleName().contentEquals(propertyName)) {
return ctx.isScalarCollectionField(field);
}
}
}
return false;
}
private boolean isUnfetchableProperty(TypeElement type, String propertyName) {
if (type == null) {
return false;
}
for (TypeElement current = type; current != null; current = superclassOf(current)) {
for (VariableElement field : ElementFilter.fieldsIn(current.getEnclosedElements())) {
if (field.getSimpleName().contentEquals(propertyName)) {
return ctx.isTransientField(field);
return true;
}
}
}
@@ -30,8 +30,6 @@ class DtoPropertyMeta {
private final boolean computedSegment;
private final List<String> requiredFetchPaths;
private final boolean listTarget;
private final boolean scalarCollection;
private final boolean unfetchable;
private final boolean ignored;
DtoPropertyMeta(String dtoFieldName, Kind kind, List<String> sourceGetterPath, List<String> sourcePropertyPath, DtoBeanMeta nested) {
@@ -46,7 +44,7 @@ class DtoPropertyMeta {
* before ever consulting them.
*/
static DtoPropertyMeta ignored(String dtoFieldName, boolean listTarget) {
return new DtoPropertyMeta(dtoFieldName, Kind.SCALAR, List.of(), List.of(), null, null, false, false, false, List.of(), listTarget, false, false, true);
return new DtoPropertyMeta(dtoFieldName, Kind.SCALAR, List.of(), List.of(), null, null, false, false, false, List.of(), listTarget, true);
}
/**
@@ -92,22 +90,6 @@ class DtoPropertyMeta {
DtoPropertyMeta(String dtoFieldName, Kind kind, List<String> sourceGetterPath, List<String> sourcePropertyPath,
DtoBeanMeta nested, DtoConverterMeta converter, boolean primitiveTarget, boolean failOnNull,
boolean computedSegment, List<String> requiredFetchPaths, boolean listTarget, boolean ignored) {
this(dtoFieldName, kind, sourceGetterPath, sourcePropertyPath, nested, converter, primitiveTarget, failOnNull,
computedSegment, requiredFetchPaths, listTarget, false, ignored);
}
DtoPropertyMeta(String dtoFieldName, Kind kind, List<String> sourceGetterPath, List<String> sourcePropertyPath,
DtoBeanMeta nested, DtoConverterMeta converter, boolean primitiveTarget, boolean failOnNull,
boolean computedSegment, List<String> requiredFetchPaths, boolean listTarget,
boolean scalarCollection, boolean ignored) {
this(dtoFieldName, kind, sourceGetterPath, sourcePropertyPath, nested, converter, primitiveTarget, failOnNull,
computedSegment, requiredFetchPaths, listTarget, scalarCollection, false, ignored);
}
DtoPropertyMeta(String dtoFieldName, Kind kind, List<String> sourceGetterPath, List<String> sourcePropertyPath,
DtoBeanMeta nested, DtoConverterMeta converter, boolean primitiveTarget, boolean failOnNull,
boolean computedSegment, List<String> requiredFetchPaths, boolean listTarget,
boolean scalarCollection, boolean unfetchable, boolean ignored) {
this.dtoFieldName = dtoFieldName;
this.kind = kind;
this.sourceGetterPath = sourceGetterPath;
@@ -119,8 +101,6 @@ class DtoPropertyMeta {
this.computedSegment = computedSegment;
this.requiredFetchPaths = requiredFetchPaths;
this.listTarget = listTarget;
this.scalarCollection = scalarCollection;
this.unfetchable = unfetchable;
this.ignored = ignored;
}
@@ -197,18 +177,6 @@ class DtoPropertyMeta {
return listTarget || kind == Kind.NESTED_MANY;
}
/**
* Return true when the source property is a scalar collection such as an Ebean {@code @DbArray},
* rather than a to-many association.
*/
boolean isScalarCollection() {
return scalarCollection;
}
boolean isUnfetchable() {
return unfetchable;
}
/**
* {@code true} when this property is marked {@code @DtoIgnore} - permanently excluded from
* every mapping (base and every named variant alike), always given its empty default rather
@@ -277,3 +245,4 @@ class DtoPropertyMeta {
sb.append(')');
}
}
@@ -223,15 +223,6 @@ class ProcessingContext implements Constants {
);
}
boolean isTransientField(Element field) {
if (field.getKind() != ElementKind.FIELD) {
return false;
}
VariableElement variable = (VariableElement) field;
return variable.getModifiers().contains(Modifier.TRANSIENT)
|| hasAnnotations(variable, "jakarta.persistence.Transient");
}
private static boolean hasAnnotations(Element element, String... annotations) {
return getAnnotation(element, annotations) != null;
}
@@ -277,21 +268,17 @@ class ProcessingContext implements Constants {
/**
* Return true if it is a DbJson field.
*/
boolean isDbJsonField(Element field) {
private static boolean dbJsonField(Element field) {
return hasAnnotations(field, DBJSON, DBJSONB);
}
/**
* Return true if it is a DbArray field.
*/
boolean isDbArrayField(Element field) {
private static boolean dbArrayField(Element field) {
return hasAnnotations(field, DBARRAY);
}
boolean isScalarCollectionField(Element field) {
return isDbArrayField(field) || isDbJsonField(field);
}
private static boolean dbToMany(Element field) {
return hasAnnotations(field, ONE_TO_MANY, MANY_TO_MANY);
}
@@ -430,10 +417,10 @@ class ProcessingContext implements Constants {
}
boolean toMany = dbToMany(field);
if (isDbJsonField(field)) {
if (dbJsonField(field)) {
return propertyTypeMap.getDbJsonType();
}
if (isDbArrayField(field)) {
if (dbArrayField(field)) {
// get generic parameter type
DeclaredType declaredType = (DeclaredType) field.asType();
TypeMirror arrayElementType = declaredType.getTypeArguments().get(0);
@@ -19,8 +19,6 @@ public class Processor extends AbstractProcessor implements Constants {
private ProcessingContext processingContext;
private DtoMappingReader dtoMappingReader;
private boolean wroteDtoMappers;
private SimpleModuleInfoWriter moduleWriter;
private boolean initModuleWriter;
private boolean wroteLookup;
@@ -61,7 +59,6 @@ public class Processor extends AbstractProcessor implements Constants {
final int loaded = processingContext.complete();
dtoMappingReader.collect(roundEnv);
if (!roundEnv.processingOver()) {
initModuleInfoBean();
writeDtoMappers();
}
if (roundEnv.processingOver()) {
@@ -112,33 +109,24 @@ public class Processor extends AbstractProcessor implements Constants {
}
}
private void initModuleInfoBean() {
if (initModuleWriter || !processingContext.hasAnyEntitiesOrOther()) {
return;
}
try {
moduleWriter = new SimpleModuleInfoWriter(processingContext);
} catch (FilerException e) {
processingContext.logWarn(null, "FilerException trying to write EntityClassRegister error: " + e);
} catch (Throwable e) {
processingContext.logError(null, "Failed to initialise EntityClassRegister error:" + e + " stack:" + Arrays.toString(e.getStackTrace()));
} finally {
initModuleWriter = true;
}
}
/**
* Write the {@code EbeanEntityRegister} at the end of processing. The source file is reserved
* during an earlier round by {@link #initModuleInfoBean()} so javac does not warn that it was
* created in the final round.
* Write the {@code EbeanEntityRegister} at the end of processing - deferred until there is
* something to actually register (rather than eagerly reserving/creating the source file up
* front), since a compilation unit with no {@code @Entity}/{@code @Embeddable}/{@code @Converter}
* /other classes at all - e.g. a test-source-only module that only declares
* {@code @DtoMapping} - has nothing meaningful to write and no factory package to derive a
* sensible location from.
*/
private void writeModuleInfoBean() {
if (moduleWriter == null) {
if (!processingContext.hasAnyEntitiesOrOther()) {
processingContext.logNote("EbeanEntityRegister skipped - no entities or other classes found");
return;
}
try {
SimpleModuleInfoWriter moduleWriter = new SimpleModuleInfoWriter(processingContext);
moduleWriter.write();
} catch (FilerException e) {
processingContext.logWarn(null, "FilerException trying to write EntityClassRegister error: " + e);
} catch (Throwable e) {
processingContext.logError(null, "Failed to write EntityClassRegister error:" + e + " stack:" + Arrays.toString(e.getStackTrace()));
}
@@ -1,124 +0,0 @@
package io.ebean.querybean.generator;
import org.junit.jupiter.api.Test;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertTrue;
class DtoMapperDbArrayTest {
@Test
void dbArrayList_isSelectedAsScalarColumn() throws IOException {
Path sourceDir = Files.createTempDirectory("dto-db-array-src");
Path outDir = Files.createTempDirectory("dto-db-array-out");
Path genSourceDir = Files.createTempDirectory("dto-db-array-gensrc");
writeSource(sourceDir, "org.tests.dbarray.ProcessLog",
"package org.tests.dbarray;\n"
+ "import io.ebean.annotation.DbArray;\n"
+ "import io.ebean.annotation.DbJson;\n"
+ "import io.ebean.annotation.DbJsonB;\n"
+ "import jakarta.persistence.Transient;\n"
+ "public class ProcessLog {\n"
+ " @DbArray private java.util.List<Long> sourceIds;\n"
+ " @DbJson private java.util.List<Long> jsonIds;\n"
+ " @DbJsonB private java.util.List<Long> jsonbIds;\n"
+ " @Transient private String computed;\n"
+ " public java.util.List<Long> sourceIds() { return sourceIds; }\n"
+ " public java.util.List<Long> jsonIds() { return jsonIds; }\n"
+ " public java.util.List<Long> jsonbIds() { return jsonbIds; }\n"
+ " public String computed() { return computed; }\n"
+ "}\n");
writeSource(sourceDir, "org.tests.dbarray.ProcessLogDto",
"package org.tests.dbarray;\n"
+ "public class ProcessLogDto {\n"
+ " private final java.util.List<Long> sourceIds;\n"
+ " private final java.util.List<Long> jsonIds;\n"
+ " private final java.util.List<Long> jsonbIds;\n"
+ " private final String computed;\n"
+ " public ProcessLogDto(java.util.List<Long> sourceIds, java.util.List<Long> jsonIds,\n"
+ " java.util.List<Long> jsonbIds, String computed) {\n"
+ " this.sourceIds = sourceIds; this.jsonIds = jsonIds; this.jsonbIds = jsonbIds; this.computed = computed;\n"
+ " }\n"
+ " public java.util.List<Long> getSourceIds() { return sourceIds; }\n"
+ " public java.util.List<Long> getJsonIds() { return jsonIds; }\n"
+ " public java.util.List<Long> getJsonbIds() { return jsonbIds; }\n"
+ " public String getComputed() { return computed; }\n"
+ "}\n");
writeSource(sourceDir, "org.tests.dbarray.package-info",
"@io.ebean.annotation.DtoMapping(source = ProcessLog.class, target = ProcessLogDto.class)\n"
+ "package org.tests.dbarray;\n");
writeSource(sourceDir, "io.ebean.typequery.Generated",
"package io.ebean.typequery;\n"
+ "public @interface Generated { String value(); }\n");
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, Locale.getDefault(), null)) {
List<Path> sourceFiles;
try (var walk = Files.walk(sourceDir)) {
sourceFiles = walk.filter(path -> path.toString().endsWith(".java")).collect(Collectors.toList());
}
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromPaths(sourceFiles);
List<String> options = List.of(
"-d", outDir.toString(),
"-s", genSourceDir.toString(),
"-classpath", System.getProperty("java.class.path"),
"-processor", Processor.class.getName());
JavaCompiler.CompilationTask task = compiler.getTask(
null, fileManager, diagnostics, options, null, compilationUnits);
assertTrue(task.call(), "compilation failed: " + errors(diagnostics));
Path mapperFile;
try (var walk = Files.walk(genSourceDir)) {
mapperFile = walk.filter(path -> path.getFileName().toString().equals("ProcessLogDtoMapper.java"))
.findFirst()
.orElseThrow(() -> new AssertionError("generated mapper source not found"));
}
String generated = Files.readString(mapperFile);
assertTrue(generated.contains("select(\"sourceIds,jsonIds,jsonbIds\")"), generated);
assertTrue(generated.contains("source.sourceIds()"), generated);
assertTrue(generated.contains("source.jsonIds()"), generated);
assertTrue(generated.contains("source.jsonbIds()"), generated);
assertTrue(generated.contains("source.computed()"), generated);
assertTrue(!generated.contains("fetch(\"sourceIds\")"), generated);
assertTrue(!generated.contains("fetch(\"jsonIds\")"), generated);
assertTrue(!generated.contains("fetch(\"jsonbIds\")"), generated);
}
}
private List<String> errors(DiagnosticCollector<JavaFileObject> diagnostics) {
return diagnostics.getDiagnostics().stream()
.filter(diagnostic -> diagnostic.getKind() == Diagnostic.Kind.ERROR)
.map(diagnostic -> diagnostic.getMessage(Locale.getDefault()))
.collect(Collectors.toList());
}
private void writeSource(Path sourceDir, String fqn, String content) {
try {
Path packageDir = sourceDir.resolve(fqn.substring(0, fqn.lastIndexOf('.')).replace('.', '/'));
Files.createDirectories(packageDir);
String simpleName = fqn.substring(fqn.lastIndexOf('.') + 1);
try (Writer writer = Files.newBufferedWriter(packageDir.resolve(simpleName + ".java"))) {
writer.write(content);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>tests</artifactId>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>tests</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>test-dto-mapping</artifactId>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>tests</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>test-java16</artifactId>
+3 -3
View File
@@ -6,7 +6,7 @@
<parent>
<artifactId>tests</artifactId>
<groupId>io.ebean</groupId>
<version>18.5.0</version>
<version>18.4.0</version>
</parent>
<artifactId>test-kotlin</artifactId>
@@ -40,7 +40,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
</dependency>
<dependency>
@@ -53,7 +53,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>18.5.0</version>
<version>18.4.0</version>
<scope>test</scope>
</dependency>