mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c4b8492da | ||
|
|
02dafc9838 | ||
|
|
0816810d3b | ||
|
|
1f6e2ee844 | ||
|
|
dc00765a98 | ||
|
|
a48b2f4ebe | ||
|
|
837563544f | ||
|
|
fd199f406b | ||
|
|
a48e96c7e9 | ||
|
|
7ba6e5f67d |
@@ -1,8 +1,5 @@
|
||||
package io.ebean.config;
|
||||
|
||||
import io.avaje.config.Config;
|
||||
import io.avaje.config.Configuration;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@@ -19,16 +16,6 @@ public class ContainerConfig {
|
||||
private String podName;
|
||||
private int port;
|
||||
private Properties properties;
|
||||
private Configuration configuration;
|
||||
|
||||
public ContainerConfig() {
|
||||
this.configuration = Config.asConfiguration();
|
||||
this.active = configuration.getBool("ebean.cluster.active", active);
|
||||
this.serviceName = configuration.getNullable("ebean.cluster.serviceName", serviceName);
|
||||
this.namespace = configuration.getNullable("ebean.cluster.namespace", namespace);
|
||||
this.podName = configuration.getNullable("ebean.cluster.podName", podName);
|
||||
this.port = configuration.getInt("ebean.cluster.port", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the service name.
|
||||
@@ -104,7 +91,7 @@ public class ContainerConfig {
|
||||
* Return the deployment properties.
|
||||
*/
|
||||
public Properties getProperties() {
|
||||
return properties != null ? properties : configuration.asProperties();
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,4 +101,25 @@ public class ContainerConfig {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the settings from properties.
|
||||
*/
|
||||
public void loadFromProperties(Properties properties) {
|
||||
this.properties = properties;
|
||||
this.active = getProperty(properties, "ebean.cluster.active", active);
|
||||
this.serviceName = properties.getProperty("ebean.cluster.serviceName", serviceName);
|
||||
this.namespace = properties.getProperty("ebean.cluster.namespace", namespace);
|
||||
this.podName = properties.getProperty("ebean.cluster.podName", podName);
|
||||
String portParam = properties.getProperty("ebean.cluster.port");
|
||||
if (portParam != null) {
|
||||
this.port = Integer.parseInt(portParam);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the boolean property setting.
|
||||
*/
|
||||
protected boolean getProperty(Properties properties, String key, boolean defaultValue) {
|
||||
return "true".equalsIgnoreCase(properties.getProperty(key, Boolean.toString(defaultValue)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,14 @@ package io.ebeaninternal.api;
|
||||
import io.ebeaninternal.server.core.SpiOrmQueryRequest;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.expression.platform.DbExpressionHandler;
|
||||
import io.ebeaninternal.server.expression.platform.DbExpressionRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Request object used for gathering expression sql and bind values.
|
||||
*/
|
||||
public interface SpiExpressionRequest {
|
||||
public interface SpiExpressionRequest extends DbExpressionRequest {
|
||||
|
||||
/**
|
||||
* Return the DB specific handler for JSON and ARRAY expressions.
|
||||
@@ -34,11 +35,13 @@ public interface SpiExpressionRequest {
|
||||
/**
|
||||
* Append to the expression sql without any parsing.
|
||||
*/
|
||||
@Override
|
||||
SpiExpressionRequest append(String expression);
|
||||
|
||||
/**
|
||||
* Append to the expression sql without any parsing.
|
||||
*/
|
||||
@Override
|
||||
SpiExpressionRequest append(char c);
|
||||
|
||||
/**
|
||||
@@ -47,6 +50,7 @@ public interface SpiExpressionRequest {
|
||||
* This is a fast path case when expression is a bean property path and falls back to using parse()
|
||||
* when that isn't the case.
|
||||
*/
|
||||
@Override
|
||||
SpiExpressionRequest property(String expression);
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,8 +41,8 @@ import io.ebeanservice.docstore.api.mapping.DocMappingBuilder;
|
||||
import io.ebeanservice.docstore.api.mapping.DocPropertyMapping;
|
||||
import io.ebeanservice.docstore.api.mapping.DocPropertyOptions;
|
||||
import io.ebeanservice.docstore.api.support.DocStructure;
|
||||
|
||||
import jakarta.persistence.PersistenceException;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
@@ -1182,14 +1182,14 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
* Returns true if this <code>isLob()</code> or the type will effectively map to a lob.
|
||||
*/
|
||||
@Override
|
||||
public boolean isDbLob() {
|
||||
public boolean isLobForPlatform() {
|
||||
if (lob) {
|
||||
return true;
|
||||
}
|
||||
switch (dbType) {
|
||||
case DbPlatformType.JSON:
|
||||
case DbPlatformType.JSONB:
|
||||
return dbLength == 0; // must be analog to DbPlatformTypeMapping.lookup
|
||||
return dbLength == 0 || dbLength > 4000; // must be analog to DbPlatformTypeMapping.lookup
|
||||
case DbPlatformType.JSONBlob:
|
||||
case DbPlatformType.JSONClob:
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ class DynamicPropertyAggregationFormula extends DynamicPropertyBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDbLob() {
|
||||
public boolean isLobForPlatform() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.BitwiseOp;
|
||||
|
||||
/**
|
||||
@@ -9,7 +8,7 @@ import io.ebeaninternal.server.expression.BitwiseOp;
|
||||
abstract class BaseDbExpression implements DbExpressionHandler {
|
||||
|
||||
@Override
|
||||
public void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
public void bitwise(DbExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
final String bitOp = bitOp(operator);
|
||||
request.append('(').property(propName).append(' ').append(bitOp).append(" ? ").append(compare).append(" ?)");
|
||||
}
|
||||
@@ -28,7 +27,7 @@ abstract class BaseDbExpression implements DbExpressionHandler {
|
||||
/**
|
||||
* Common alternative where the bitwise operation is a function (specifically bitand is used - H2 and Oracle).
|
||||
*/
|
||||
protected void bitwiseFunction(SpiExpressionRequest request, String propName, BitwiseOp operator, String compare) {
|
||||
protected void bitwiseFunction(DbExpressionRequest request, String propName, BitwiseOp operator, String compare) {
|
||||
final String funcName = functionName(operator);
|
||||
request.append(funcName).append('(').property(propName).append(", ?) ").append(compare).append(" ?");
|
||||
}
|
||||
|
||||
+3
-4
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.Op;
|
||||
|
||||
/**
|
||||
@@ -9,17 +8,17 @@ import io.ebeaninternal.server.expression.Op;
|
||||
class BasicDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
public void json(DbExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
throw new RuntimeException("JSON expressions only supported on Postgres and Oracle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayContains(SpiExpressionRequest request, String propName, boolean contains, Object... values) {
|
||||
public void arrayContains(DbExpressionRequest request, String propName, boolean contains, Object... values) {
|
||||
throw new RuntimeException("ARRAY expressions only supported on Postgres");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayIsEmpty(SpiExpressionRequest request, String propName, boolean empty) {
|
||||
public void arrayIsEmpty(DbExpressionRequest request, String propName, boolean empty) {
|
||||
throw new RuntimeException("ARRAY expressions only supported on Postgres");
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.BitwiseOp;
|
||||
import io.ebeaninternal.server.expression.Op;
|
||||
|
||||
@@ -12,22 +11,22 @@ public interface DbExpressionHandler {
|
||||
/**
|
||||
* Write the db platform specific json expression.
|
||||
*/
|
||||
void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value);
|
||||
void json(DbExpressionRequest request, String propName, String path, Op operator, Object value);
|
||||
|
||||
/**
|
||||
* Add SQL for ARRAY CONTAINS expression.
|
||||
*/
|
||||
void arrayContains(SpiExpressionRequest request, String propName, boolean contains, Object... values);
|
||||
void arrayContains(DbExpressionRequest request, String propName, boolean contains, Object... values);
|
||||
|
||||
/**
|
||||
* Add SQL for ARRAY IS EMPTY expression.
|
||||
*/
|
||||
void arrayIsEmpty(SpiExpressionRequest request, String propName, boolean empty);
|
||||
void arrayIsEmpty(DbExpressionRequest request, String propName, boolean empty);
|
||||
|
||||
/**
|
||||
* Add the bitwise expression.
|
||||
*/
|
||||
void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match);
|
||||
void bitwise(DbExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match);
|
||||
|
||||
/**
|
||||
* Performs a "CONCAT" operation for that platform.
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
/**
|
||||
* Request building the expression sql.
|
||||
*/
|
||||
public interface DbExpressionRequest {
|
||||
|
||||
/**
|
||||
* Append to the expression sql without any parsing.
|
||||
*/
|
||||
DbExpressionRequest append(String expression);
|
||||
|
||||
/**
|
||||
* Append to the expression sql without any parsing.
|
||||
*/
|
||||
DbExpressionRequest append(char c);
|
||||
|
||||
/**
|
||||
* Append to the expression sql with logical property parsing to db columns with logical path prefix.
|
||||
*/
|
||||
DbExpressionRequest property(String expression);
|
||||
}
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.BitwiseOp;
|
||||
|
||||
/**
|
||||
@@ -9,7 +8,7 @@ import io.ebeaninternal.server.expression.BitwiseOp;
|
||||
final class H2DbExpression extends BasicDbExpression {
|
||||
|
||||
@Override
|
||||
public void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
public void bitwise(DbExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
final String funcName = functionName(operator);
|
||||
request.append(funcName).append('(').property(propName).append(", cast(? as long)) ").append(compare).append(" cast(? as long)");
|
||||
}
|
||||
|
||||
+4
-5
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.BitwiseOp;
|
||||
import io.ebeaninternal.server.expression.Op;
|
||||
|
||||
@@ -10,17 +9,17 @@ import io.ebeaninternal.server.expression.Op;
|
||||
final class HanaDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
public void bitwise(DbExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
bitwiseFunction(request, propName, operator, compare);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
public void json(DbExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
request.append("json_value(").property(propName).append(", '$.").append(path).append("')").append(operator.bind());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayIsEmpty(SpiExpressionRequest request, String propName, boolean empty) {
|
||||
public void arrayIsEmpty(DbExpressionRequest request, String propName, boolean empty) {
|
||||
request.append("cardinality(").property(propName).append(')');
|
||||
if (empty) {
|
||||
request.append(" = 0");
|
||||
@@ -41,7 +40,7 @@ final class HanaDbExpression extends BaseDbExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayContains(SpiExpressionRequest request, String propName, boolean contains, Object... values) {
|
||||
public void arrayContains(DbExpressionRequest request, String propName, boolean contains, Object... values) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (i > 0) {
|
||||
request.append(" and ");
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.Op;
|
||||
|
||||
/**
|
||||
@@ -9,7 +8,7 @@ import io.ebeaninternal.server.expression.Op;
|
||||
final class MariaDbExpression extends BasicDbExpression {
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
public void json(DbExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
request.append('(').property(propName).append(" ->> '$.").append(path).append("')").append(operator.bind());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.Op;
|
||||
|
||||
/**
|
||||
@@ -9,7 +8,7 @@ import io.ebeaninternal.server.expression.Op;
|
||||
final class MySqlDbExpression extends BasicDbExpression {
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
public void json(DbExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
request.append('(').property(propName).append(" ->> '$.").append(path).append("')").append(operator.bind());
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.BitwiseOp;
|
||||
import io.ebeaninternal.server.expression.Op;
|
||||
|
||||
@@ -15,7 +14,7 @@ final class OracleDbExpression extends BaseDbExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
public void json(DbExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
if (operator == Op.EXISTS) {
|
||||
request.append("json_exists(").property(propName).append(", '$.").append(path).append("')");
|
||||
} else if (operator == Op.NOT_EXISTS) {
|
||||
@@ -26,17 +25,17 @@ final class OracleDbExpression extends BaseDbExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
public void bitwise(DbExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
bitwiseFunction(request, propName, operator, compare);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayContains(SpiExpressionRequest request, String propName, boolean contains, Object... values) {
|
||||
public void arrayContains(DbExpressionRequest request, String propName, boolean contains, Object... values) {
|
||||
throw new IllegalStateException("ARRAY expressions not supported on Oracle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayIsEmpty(SpiExpressionRequest request, String propName, boolean empty) {
|
||||
public void arrayIsEmpty(DbExpressionRequest request, String propName, boolean empty) {
|
||||
throw new IllegalStateException("ARRAY expressions not supported on Oracle");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.Op;
|
||||
|
||||
/**
|
||||
@@ -14,7 +13,7 @@ final class PostgresDbExpression extends BaseDbExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
public void json(DbExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
String[] paths = path.split("\\.");
|
||||
if (paths.length == 1) {
|
||||
// (t0.content ->> 'title') = 'Some value'
|
||||
@@ -34,7 +33,7 @@ final class PostgresDbExpression extends BaseDbExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayContains(SpiExpressionRequest request, String propName, boolean contains, Object... values) {
|
||||
public void arrayContains(DbExpressionRequest request, String propName, boolean contains, Object... values) {
|
||||
if (!contains) {
|
||||
request.append("not (");
|
||||
}
|
||||
@@ -49,7 +48,7 @@ final class PostgresDbExpression extends BaseDbExpression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayIsEmpty(SpiExpressionRequest request, String propName, boolean empty) {
|
||||
public void arrayIsEmpty(DbExpressionRequest request, String propName, boolean empty) {
|
||||
request.append("coalesce(cardinality(").property(propName).append("),0)");
|
||||
if (empty) {
|
||||
request.append(" = 0");
|
||||
|
||||
+3
-4
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.expression.platform;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.expression.Op;
|
||||
|
||||
/**
|
||||
@@ -9,19 +8,19 @@ import io.ebeaninternal.server.expression.Op;
|
||||
final class SqlServerDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public void json(final SpiExpressionRequest request, final String propName,
|
||||
public void json(final DbExpressionRequest request, final String propName,
|
||||
final String path, final Op operator, final Object value) {
|
||||
request.append("json_value(").property(propName).append(", '$.").append(path).append("')").append(operator.bind());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayContains(final SpiExpressionRequest request, final String propName,
|
||||
public void arrayContains(final DbExpressionRequest request, final String propName,
|
||||
final boolean contains, final Object... values) {
|
||||
throw new RuntimeException("ARRAY expressions not supported on Microsoft SQL Server");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void arrayIsEmpty(final SpiExpressionRequest request, final String propName, final boolean empty) {
|
||||
public void arrayIsEmpty(final DbExpressionRequest request, final String propName, final boolean empty) {
|
||||
throw new RuntimeException("ARRAY expressions not supported on Microsoft SQL Server");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public interface STreeProperty extends ScalarDataReader<Object> {
|
||||
/**
|
||||
* Returns true, if this is a lob property from db-perspective.
|
||||
*/
|
||||
boolean isDbLob();
|
||||
boolean isLobForPlatform();
|
||||
|
||||
/**
|
||||
* Return true if the property is an embedded type.
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class SqlTreeBuilder {
|
||||
private final SpiQuery.TemporalMode temporalMode;
|
||||
private SqlTreeNode rootNode;
|
||||
private boolean sqlDistinct;
|
||||
private final boolean distinctNoLobs;
|
||||
private final boolean platformDistinctNoLobs;
|
||||
private final SqlTreeCommon common;
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ public final class SqlTreeBuilder {
|
||||
this.query = null;
|
||||
this.subQuery = false;
|
||||
this.distinctOnPlatform = false;
|
||||
this.distinctNoLobs = false;
|
||||
this.platformDistinctNoLobs = false;
|
||||
this.queryDetail = queryDetail;
|
||||
this.predicates = predicates;
|
||||
this.temporalMode = SpiQuery.TemporalMode.CURRENT;
|
||||
@@ -98,7 +98,7 @@ public final class SqlTreeBuilder {
|
||||
this.predicates = predicates;
|
||||
this.alias = new SqlTreeAlias(request.baseTableAlias(), temporalMode);
|
||||
this.distinctOnPlatform = builder.isPlatformDistinctOn();
|
||||
this.distinctNoLobs = builder.isPlatformDistinctNoLobs();
|
||||
this.platformDistinctNoLobs = builder.isPlatformDistinctNoLobs();
|
||||
String fromForUpdate = builder.fromForUpdate(query);
|
||||
CQueryHistorySupport historySupport = builder.historySupport(query);
|
||||
CQueryDraftSupport draftSupport = builder.draftSupport(query);
|
||||
@@ -269,8 +269,8 @@ public final class SqlTreeBuilder {
|
||||
if (joinList != null) {
|
||||
joinList.add(selectNode);
|
||||
}
|
||||
if (sqlDistinct && distinctNoLobs) {
|
||||
selectNode.unselectLobs();
|
||||
if (sqlDistinct && platformDistinctNoLobs) {
|
||||
selectNode.unselectLobsForPlatform();
|
||||
}
|
||||
return selectNode;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,6 @@ interface SqlTreeNode {
|
||||
/**
|
||||
* Unselect lobs (for distinct queries on DB2 and Oracle).
|
||||
*/
|
||||
default void unselectLobs() {
|
||||
default void unselectLobsForPlatform() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,16 +379,16 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
||||
|
||||
|
||||
@Override
|
||||
public void unselectLobs() {
|
||||
public void unselectLobsForPlatform() {
|
||||
if (children != null) {
|
||||
for (SqlTreeNode child : children) {
|
||||
child.unselectLobs();
|
||||
child.unselectLobsForPlatform();
|
||||
}
|
||||
}
|
||||
if (hasLob()) {
|
||||
List<STreeProperty> lst = new ArrayList<>();
|
||||
for (STreeProperty prop : properties) {
|
||||
if (!prop.isDbLob()) {
|
||||
if (!prop.isLobForPlatform()) {
|
||||
lst.add(prop);
|
||||
}
|
||||
}
|
||||
@@ -399,7 +399,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
||||
|
||||
private boolean hasLob() {
|
||||
for (STreeProperty prop : properties) {
|
||||
if (prop.isDbLob()) {
|
||||
if (prop.isLobForPlatform()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package org.integration;
|
||||
|
||||
import io.ebean.DatabaseBuilder;
|
||||
import io.ebean.redis.DuelCache;
|
||||
import org.domain.Person;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.redis.DuelCache;
|
||||
import org.domain.Person;
|
||||
import org.domain.query.QPerson;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -14,21 +11,21 @@ import javax.sql.DataSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ClusterTest {
|
||||
class ClusterTest {
|
||||
|
||||
private Database createOther(DataSource dataSource) {
|
||||
DatabaseBuilder config = new DatabaseConfig();
|
||||
config.setDataSource(dataSource);
|
||||
config.loadFromProperties();
|
||||
config.setDefaultServer(false);
|
||||
config.setName("other");
|
||||
config.setDdlGenerate(false);
|
||||
config.setDdlRun(false);
|
||||
return DatabaseFactory.create(config);
|
||||
return Database.builder()
|
||||
.dataSource(dataSource)
|
||||
.loadFromProperties()
|
||||
.defaultDatabase(false)
|
||||
.name("other")
|
||||
.ddlGenerate(false)
|
||||
.ddlRun(false)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBothNear() throws InterruptedException {
|
||||
void testBothNear() throws InterruptedException {
|
||||
// ensure the default server exists first
|
||||
final Database db = DB.getDefault();
|
||||
Database other = createOther(db.pluginApi().dataSource());
|
||||
@@ -61,7 +58,7 @@ public class ClusterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws InterruptedException {
|
||||
void test() throws InterruptedException {
|
||||
// ensure the default server exists first
|
||||
final Database db = DB.getDefault();
|
||||
Database other = createOther(db.pluginApi().dataSource());
|
||||
@@ -116,6 +113,6 @@ public class ClusterTest {
|
||||
}
|
||||
|
||||
private void allowAsyncMessaging() throws InterruptedException {
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,19 @@ package org.example;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.test.PersistenceContextAccess;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.in;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -42,6 +46,24 @@ public class EbeanSpringModuleTest {
|
||||
super();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Rollback
|
||||
@Test
|
||||
public void testWithRollback() {
|
||||
// setup
|
||||
User user = new User();
|
||||
user.setName("rollback1");
|
||||
DB.save(user);
|
||||
|
||||
// this loads the user into the [transaction scoped] persistence context
|
||||
User found = DB.find(User.class, user.getOid());
|
||||
found.setName("mutated");
|
||||
|
||||
PersistenceContextAccess.clear();
|
||||
|
||||
userService.insideTestRollback(user.getOid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test app.
|
||||
*/
|
||||
|
||||
@@ -16,4 +16,6 @@ public interface UserService {
|
||||
void batchInsert();
|
||||
|
||||
void requiresNew();
|
||||
|
||||
void insideTestRollback(long oid);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* The Class UserServiceImpl.
|
||||
*
|
||||
@@ -28,6 +30,13 @@ public class UserServiceImpl implements UserService, ApplicationContextAware {
|
||||
@Autowired
|
||||
private Database ebeanServer;
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
||||
public void insideTestRollback(long oid) {
|
||||
User found = ebeanServer.find(User.class, oid);
|
||||
assertThat(found.getName()).isEqualTo("rollback1");
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
||||
public void save(User user) {
|
||||
ebeanServer.save(user);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package io.ebean.test;
|
||||
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.bean.PersistenceContext;
|
||||
import io.ebeaninternal.api.SpiTransaction;
|
||||
|
||||
/**
|
||||
* Provides tests access to the persistence context.
|
||||
* <p>
|
||||
* Expected to be used with tests that use Spring test {@code @Rollback} {@code @Transactional}.
|
||||
* These tests have an outer transaction that will rollback. The issue is that test setup code
|
||||
* is now running in the SAME TRANSACTION as the code under test (main code we are testing) and
|
||||
* that the Ebean Persistence Context is transaction scoped - so the test setup code can load
|
||||
* entities into the ebean persistence context during the test setup phase - we SHOULD clear the
|
||||
* persistence context AFTER the setup phase of the test and BEFORE we run the code under test.
|
||||
*
|
||||
* <pre>{@code
|
||||
*
|
||||
* @Test
|
||||
* @Transactional // spring transactional
|
||||
* @Rollback // spring test rollback
|
||||
* void myTestWithSpringRollback() {
|
||||
*
|
||||
* // Test Setup: this MIGHT load entities into the persistence context
|
||||
* performTestSetup();
|
||||
*
|
||||
* // clear out the persistence context
|
||||
* PersistenceContextAccess.clear();
|
||||
*
|
||||
* // Act
|
||||
* performActionsWeAreTestingHere();
|
||||
*
|
||||
* // Assert
|
||||
* assertThat(...)
|
||||
*
|
||||
* }
|
||||
*
|
||||
* }</pre>
|
||||
*/
|
||||
public class PersistenceContextAccess {
|
||||
|
||||
/**
|
||||
* Clear the persistence context of the current transaction.
|
||||
* <p>
|
||||
* This is expected to be called after test setup phase and before
|
||||
* the test executes the code we are looking to test - so
|
||||
* AFTER "setup" and BEFORE "act".
|
||||
*/
|
||||
public static void clear() {
|
||||
Transaction current = Transaction.current();
|
||||
if (current != null) {
|
||||
SpiTransaction spiTransaction = (SpiTransaction) current;
|
||||
PersistenceContext pc = spiTransaction.persistenceContext();
|
||||
if (pc != null) {
|
||||
pc.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,12 +12,20 @@ class ContainerConfigTest {
|
||||
|
||||
@Test
|
||||
void loadFromProperties() {
|
||||
ContainerConfig containerConfig = new ContainerConfig();
|
||||
Properties p = new Properties();
|
||||
p.setProperty("ebean.cluster.active", "true");
|
||||
p.setProperty("ebean.cluster.serviceName", "a");
|
||||
p.setProperty("ebean.cluster.namespace", "b");
|
||||
p.setProperty("ebean.cluster.podName", "c");
|
||||
p.setProperty("ebean.cluster.port", "42");
|
||||
|
||||
assertThat(containerConfig.isActive()).isFalse();
|
||||
assertThat(containerConfig.getServiceName()).isNull();
|
||||
assertThat(containerConfig.getNamespace()).isNull();
|
||||
assertThat(containerConfig.getPodName()).isNull();
|
||||
assertThat(containerConfig.getPort()).isEqualTo(0);
|
||||
ContainerConfig containerConfig = new ContainerConfig();
|
||||
containerConfig.loadFromProperties(p);
|
||||
|
||||
assertThat(containerConfig.isActive()).isTrue();
|
||||
assertThat(containerConfig.getServiceName()).isEqualTo("a");
|
||||
assertThat(containerConfig.getNamespace()).isEqualTo("b");
|
||||
assertThat(containerConfig.getPodName()).isEqualTo("c");
|
||||
assertThat(containerConfig.getPort()).isEqualTo(42);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# Deploy to Central
|
||||
|
||||
```shell
|
||||
## confirm on master and building
|
||||
git checkout master
|
||||
mvn clean verify
|
||||
|
||||
## set the appropriate version
|
||||
mvs
|
||||
|
||||
## run tests and package
|
||||
mvn -T 4 clean package
|
||||
|
||||
## deploy
|
||||
mvn -T 4 deploy -pl '!composites,!platforms' -Pcentral -DskipTests -DskipStagingRepositoryClose=true -DstagingProgressTimeoutMinutes=9
|
||||
|
||||
## git commit, git tag, git push --tags
|
||||
|
||||
## convert to javax
|
||||
./jakarta-to-javax.sh
|
||||
|
||||
## set javax version
|
||||
mvs
|
||||
|
||||
## deploy javax
|
||||
mvn -T 4 clean package
|
||||
mvn -T 4 deploy -pl '!composites,!platforms' -Pcentral -DskipTests -DskipStagingRepositoryClose=true -DstagingProgressTimeoutMinutes=9
|
||||
|
||||
## checkout / cleanup
|
||||
git checkout .
|
||||
|
||||
## goto ebean-15x branch
|
||||
git checkout ebean-15x
|
||||
|
||||
## update ebean-15x branch from master and resolve conflicts
|
||||
git merge master
|
||||
## resolve conflicts
|
||||
## git commit, git push
|
||||
|
||||
## set 15.x version
|
||||
mvs
|
||||
|
||||
## build and deploy 15.x
|
||||
mvn -T 4 clean package
|
||||
mvn -T 4 deploy -pl '!composites,!platforms' -Pcentral -DskipTests -DskipStagingRepositoryClose=true -DstagingProgressTimeoutMinutes=9
|
||||
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user