Merge remote-tracking branch 'upstream/master' into tmp3

# Conflicts:
#	ebean-test/src/test/java/org/tests/model/tevent/TEventOne.java
This commit is contained in:
Roland Praml
2022-02-07 10:51:49 +01:00
23 changed files with 69 additions and 74 deletions
@@ -11,10 +11,6 @@ public class CockroachPlatform extends PostgresPlatform {
public CockroachPlatform() {
super();
this.platform = Platform.COCKROACH;
// no like escape clause supported
this.likeSpecialCharacters = new char[]{'%', '_'};
this.likeClauseRaw = "like ?";
this.likeClauseEscaped = "like ?";
}
/**
@@ -22,7 +18,7 @@ public class CockroachPlatform extends PostgresPlatform {
*/
@Override
public boolean isDdlAutoCommit() {
return true;
return false;
}
}
@@ -283,7 +283,7 @@ public final class InternalConfiguration {
private MultiValueBind createMultiValueBind(Platform platform) {
// only Postgres at this stage
if (platform.base() == Platform.POSTGRES || platform.base() == Platform.YUGABYTE) {
if (platform.base() == Platform.POSTGRES || platform.base() == Platform.YUGABYTE || platform.base() == Platform.COCKROACH) {
return new PostgresMultiValueBind();
}
return new MultiValueBind();
@@ -81,8 +81,7 @@ public final class DefaultPersister implements Persister {
int rc = request.executeOrQueue();
request.commitTransIfRequired();
return rc;
} catch (RuntimeException e) {
} catch (Throwable e) {
request.rollbackTransIfRequired();
throw e;
} finally {
@@ -383,8 +382,7 @@ public final class DefaultPersister implements Persister {
req.resetDepth();
req.commitTransIfRequired();
req.flushBatchOnCascade();
} catch (RuntimeException ex) {
} catch (Throwable ex) {
req.rollbackTransIfRequired();
throw ex;
} finally {
@@ -420,8 +418,7 @@ public final class DefaultPersister implements Persister {
req.resetDepth();
req.commitTransIfRequired();
req.flushBatchOnCascade();
} catch (RuntimeException ex) {
} catch (Throwable ex) {
req.rollbackTransIfRequired();
throw ex;
} finally {
@@ -559,7 +556,7 @@ public final class DefaultPersister implements Persister {
req.flushBatchOnCascade();
return rows;
} catch (RuntimeException ex) {
} catch (Throwable ex) {
req.rollbackTransIfRequired();
throw ex;
} finally {
@@ -757,7 +757,7 @@ final class CQueryBuilder {
}
boolean isPlatformDistinctOn() {
return dbPlatform.isPlatform(Platform.POSTGRES) || dbPlatform.isPlatform(Platform.YUGABYTE);
return dbPlatform.isPlatform(Platform.POSTGRES) || dbPlatform.isPlatform(Platform.YUGABYTE) || dbPlatform.isPlatform(Platform.COCKROACH);
}
boolean isPlatformDistinctNoLobs() {
@@ -209,7 +209,8 @@ public final class DefaultTypeManager implements TypeManager {
private boolean isPostgresCompatible(DatabasePlatform databasePlatform) {
return databasePlatform.isPlatform(Platform.POSTGRES)
|| databasePlatform.isPlatform(Platform.YUGABYTE);
|| databasePlatform.isPlatform(Platform.YUGABYTE)
|| databasePlatform.isPlatform(Platform.COCKROACH);
}
private boolean hstoreSupport() {
@@ -21,21 +21,9 @@ public class CockroachDdl extends PlatformDdl {
return NativeDbArray.logicalToNative(logicalArrayType);
}
/**
* Map bigint, integer and smallint all into serial.
*/
@Override
public String asIdentityColumn(String columnDefn, DdlIdentity identity) {
if ("bigint".equalsIgnoreCase(columnDefn)) {
return "serial";
}
if ("integer".equalsIgnoreCase(columnDefn)) {
return "serial";
}
if ("smallint".equalsIgnoreCase(columnDefn)) {
return "serial";
}
return columnDefn;
return asIdentityStandardOptions(columnDefn, identity);
}
@Override
@@ -200,7 +200,7 @@ public abstract class BaseTestCase {
}
public boolean isPostgresCompatible() {
return isPostgres() || isYugabyte();
return isPostgres() || isYugabyte() || isCockroach();
}
public boolean isPostgres() {
@@ -211,6 +211,10 @@ public abstract class BaseTestCase {
return Platform.YUGABYTE == platform().base();
}
public boolean isCockroach() {
return Platform.COCKROACH == platform().base();
}
public boolean isMySql() {
return Platform.MYSQL == platform();
}
@@ -281,7 +285,7 @@ public abstract class BaseTestCase {
* Platform specific IN clause assert.
*/
protected void platformAssertIn(String sql, String containsIn) {
if (isPostgres() || isYugabyte()) {
if (isPostgresCompatible()) {
assertThat(sql).contains(containsIn+" = any(");
} else {
assertThat(sql).contains(containsIn+" in ");
@@ -293,7 +297,7 @@ public abstract class BaseTestCase {
* Platform specific NOT IN clause assert.
*/
protected void platformAssertNotIn(String sql, String containsIn) {
if (isPostgres() || isYugabyte()) {
if (isPostgresCompatible()) {
assertThat(sql).contains(containsIn+" != all(");
} else {
assertThat(sql).contains(containsIn+" not in ");
@@ -1,16 +1,16 @@
package main;
//import io.ebean.docker.commands.CockroachConfig;
//import io.ebean.docker.commands.CockroachContainer;
import io.ebean.docker.commands.CockroachConfig;
import io.ebean.docker.commands.CockroachContainer;
public class StartCockroach {
public static void main(String[] args) {
// CockroachConfig config = new CockroachConfig();
// config.setDbName("unit");
//
// CockroachContainer container = new CockroachContainer(config);
// container.startWithDropCreate();
CockroachConfig config = new CockroachConfig("v21.2.4");
config.setDbName("unit");
CockroachContainer container = new CockroachContainer(config);
container.start();
}
}
@@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
public class TestAggregateFormula extends BaseTestCase {
@IgnorePlatform({Platform.SQLSERVER, Platform.MYSQL, Platform.MARIADB, Platform.NUODB})
@IgnorePlatform({Platform.SQLSERVER, Platform.MYSQL, Platform.MARIADB, Platform.NUODB, Platform.COCKROACH})
@Test
public void minDistinctOrderByNulls() {
@@ -35,7 +35,7 @@ public class TestQueryUsingConnection extends BaseTestCase {
}
}
@IgnorePlatform(Platform.SQLSERVER)
@IgnorePlatform({Platform.SQLSERVER, Platform.COCKROACH})
@Test
public void usingTransaction() {
@@ -56,7 +56,7 @@ public class TestEncrypt extends BaseTestCase {
assertThat(loggedSql.get(1)).contains("left join e_basicenc t1 on t1.id = t0.other_id");
}
@IgnorePlatform({Platform.ORACLE, Platform.DB2})
@IgnorePlatform({Platform.ORACLE, Platform.DB2, Platform.COCKROACH})
@Test
public void asDto() {
DB.find(EBasicEncrypt.class).delete();
@@ -33,7 +33,7 @@ public class TestJsonMapBasic extends BaseTestCase {
}
@Test
@ForPlatform(Platform.POSTGRES)
@ForPlatform({Platform.POSTGRES, Platform.COCKROACH})
public void whereManyPredicatePg() {
bean.setName("own1");
@@ -5,6 +5,7 @@ import io.ebean.annotation.DocEmbedded;
import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
/**
@@ -27,7 +28,7 @@ public class OrderDetail implements Serializable {
Integer shipQty;
Double unitPrice;
BigDecimal unitPrice;
@ManyToOne
@DocEmbedded(doc = "id,name,sku")
@@ -41,7 +42,7 @@ public class OrderDetail implements Serializable {
public OrderDetail() {
}
public OrderDetail(Product product, Integer orderQty, Double unitPrice) {
public OrderDetail(Product product, Integer orderQty, BigDecimal unitPrice) {
this.product = product;
this.orderQty = orderQty;
this.unitPrice = unitPrice;
@@ -89,11 +90,11 @@ public class OrderDetail implements Serializable {
this.shipQty = shipQty;
}
public Double getUnitPrice() {
public BigDecimal getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(Double unitPrice) {
public void setUnitPrice(BigDecimal unitPrice) {
this.unitPrice = unitPrice;
}
@@ -5,6 +5,7 @@ import io.ebean.Database;
import io.ebean.Transaction;
import org.tests.model.basic.Order.Status;
import java.math.BigDecimal;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
@@ -213,9 +214,9 @@ public class ResetBasicData {
order.setOrderDate(Date.valueOf("2018-07-01"));
List<OrderDetail> details = new ArrayList<>();
details.add(new OrderDetail(product1, 5, 10.50));
details.add(new OrderDetail(product2, 3, 1.10));
details.add(new OrderDetail(product3, 1, 2.00));
details.add(new OrderDetail(product1, 5, BigDecimal.valueOf(10.50)));
details.add(new OrderDetail(product2, 3, BigDecimal.valueOf(1.10)));
details.add(new OrderDetail(product3, 1, BigDecimal.valueOf(2.00)));
order.setDetails(details);
order.addShipment(new OrderShipment());
DB.save(order);
@@ -231,7 +232,7 @@ public class ResetBasicData {
order.setOrderDate(Date.valueOf("2018-06-01"));
List<OrderDetail> details = new ArrayList<>();
details.add(new OrderDetail(product1, 4, 10.50));
details.add(new OrderDetail(product1, 4, BigDecimal.valueOf(10.50)));
order.setDetails(details);
order.addShipment(new OrderShipment());
DB.save(order);
@@ -247,9 +248,9 @@ public class ResetBasicData {
order.setOrderDate(Date.valueOf("2018-07-02"));
List<OrderDetail> details = new ArrayList<>();
details.add(new OrderDetail(product1, 3, 10.50));
details.add(new OrderDetail(product3, 40, 2.10));
details.add(new OrderDetail(product1, 5, 10.00));
details.add(new OrderDetail(product1, 3, BigDecimal.valueOf(10.50)));
details.add(new OrderDetail(product3, 40, BigDecimal.valueOf(2.10)));
details.add(new OrderDetail(product1, 5, BigDecimal.valueOf(10.00)));
order.setDetails(details);
order.addShipment(new OrderShipment());
DB.save(order);
@@ -70,7 +70,7 @@ public class TestHistoryExclude extends BaseTestCase {
linkFound.getDocs().size();
}
@IgnorePlatform({Platform.ORACLE, Platform.DB2})
@IgnorePlatform({Platform.ORACLE, Platform.DB2, Platform.COCKROACH})
@Test
public void testAsOfThenLazy() {
@@ -37,7 +37,7 @@ public class TestHistoryInclude extends BaseTestCase {
assertThat(linkFound.getDocs().size()).isEqualTo(2);
}
@IgnorePlatform({Platform.ORACLE, Platform.DB2})
@IgnorePlatform({Platform.ORACLE, Platform.DB2, Platform.COCKROACH})
@Test
public void testAsOfThenLazy() {
@@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestHistoryOneToMany extends BaseTestCase {
@IgnorePlatform({Platform.ORACLE, Platform.DB2})
@IgnorePlatform({Platform.ORACLE, Platform.DB2, Platform.COCKROACH})
@Test
public void test() throws InterruptedException {
@@ -4,6 +4,7 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Version;
import java.math.BigDecimal;
@Entity
public class TEventMany {
@@ -18,12 +19,12 @@ public class TEventMany {
int myUnits;
double amount;
BigDecimal amount;
@Version
Long version;
public TEventMany(String description, int myUnits, double amount) {
public TEventMany(String description, int myUnits, BigDecimal amount) {
this.description = description;
this.myUnits = myUnits;
this.amount = amount;
@@ -61,11 +62,11 @@ public class TEventMany {
this.myUnits = myUnits;
}
public double getAmount() {
public BigDecimal getAmount() {
return amount;
}
public void setAmount(double amount) {
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
@@ -3,6 +3,7 @@ package org.tests.model.tevent;
import io.ebean.annotation.Aggregation;
import javax.persistence.*;
import java.math.BigDecimal;
import java.util.List;
@Entity
@@ -33,10 +34,10 @@ public class TEventOne {
Long count;
@Aggregation("sum(logs.myUnits)")
Double totalUnits;
BigDecimal totalUnits;
@Aggregation("sum(logs.myUnits * logs.amount)")
Double totalAmount;
BigDecimal totalAmount;
@OneToMany(mappedBy = "event", cascade = CascadeType.ALL)
List<TEventMany> logs;
@@ -72,11 +73,11 @@ public class TEventOne {
return customFormula;
}
public Double getTotalUnits() {
public BigDecimal getTotalUnits() {
return totalUnits;
}
public Double getTotalAmount() {
public BigDecimal getTotalAmount() {
return totalAmount;
}
@@ -3,6 +3,8 @@ package org.tests.query;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.Query;
import io.ebean.annotation.IgnorePlatform;
import io.ebean.annotation.Platform;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.CKeyParent;
import org.tests.model.basic.ResetBasicData;
@@ -37,6 +39,7 @@ public class TestQueryAlias extends BaseTestCase {
assertThat(sql).contains("(myt0.one_key) in (select st0.one_key from ckey_parent st0)");
}
@IgnorePlatform(Platform.COCKROACH)
@Test
public void testExistsWithConcat() {
@@ -13,6 +13,7 @@ import org.tests.model.basic.ResetBasicData;
import org.tests.model.tevent.TEventMany;
import org.tests.model.tevent.TEventOne;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;
@@ -24,15 +25,15 @@ public class TestAggregationCount extends BaseTestCase {
@BeforeAll
public static void setup() {
TEventOne one = new TEventOne("first", TEventOne.Status.AA);
one.getLogs().add(new TEventMany("all", 1, 10));
one.getLogs().add(new TEventMany("be", 2, 12.2));
one.getLogs().add(new TEventMany("add", 3, 13));
one.getLogs().add(new TEventMany("all", 1, BigDecimal.valueOf(10)));
one.getLogs().add(new TEventMany("be", 2, BigDecimal.valueOf(12.2)));
one.getLogs().add(new TEventMany("add", 3, BigDecimal.valueOf(13)));
DB.save(one);
TEventOne two = new TEventOne("second", TEventOne.Status.AA);
two.getLogs().add(new TEventMany("at", 10, 10));
two.getLogs().add(new TEventMany("add", 30, 13));
two.getLogs().add(new TEventMany("alf", 30, 13));
two.getLogs().add(new TEventMany("at", 10, BigDecimal.valueOf(10)));
two.getLogs().add(new TEventMany("add", 30, BigDecimal.valueOf(13)));
two.getLogs().add(new TEventMany("alf", 30, BigDecimal.valueOf(13)));
DB.save(two);
TEventOne three = new TEventOne("thrird", TEventOne.Status.BB);
@@ -53,7 +54,7 @@ public class TestAggregationCount extends BaseTestCase {
for (TEventOne eventOne : list) {
// lazy loading on Aggregation properties
// is not expected to work at this stage
Double totalAmount = eventOne.getTotalAmount();
BigDecimal totalAmount = eventOne.getTotalAmount();
assertThat(totalAmount).isNull();
}
}
@@ -9,6 +9,7 @@ import org.tests.model.basic.*;
import org.tests.model.basic.Order.Status;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@@ -36,14 +37,14 @@ public class TestTextJsonUpdateCascade extends TransactionalTestCase {
OrderDetail orderDetail0 = order.getDetails().get(0);
orderDetail0.setShipQty(300);
orderDetail0.setUnitPrice(56.98d);
orderDetail0.setUnitPrice(BigDecimal.valueOf(56.98d));
// remove one of the details...
OrderDetail removedDetail = order.getDetails().remove(2);
assertNotNull(removedDetail);
Product p = DB.reference(Product.class, 1);
OrderDetail newDetail = new OrderDetail(p, 899, 12.12d);
OrderDetail newDetail = new OrderDetail(p, 899, BigDecimal.valueOf(12.12d));
// newDetail.setOrder(order);
order.addDetail(newDetail);
+1 -1
View File
@@ -5,7 +5,7 @@
drop view order_agg_vw if exists;
</ddl-script>
<ddl-script name="order views" platforms="db2,h2,postgres,oracle,mysql,mariadb,nuodb,yugabyte">
<ddl-script name="order views" platforms="db2,h2,postgres,oracle,mysql,mariadb,nuodb,yugabyte,cockroach">
create or replace view order_agg_vw as
select d.order_id, sum(d.order_qty * d.unit_price) as order_total,
sum(d.ship_qty * d.unit_price) as ship_total