mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a41e88162 | ||
|
|
2e5becf48c | ||
|
|
4094339407 | ||
|
|
bf24949efb | ||
|
|
a01362abad | ||
|
|
4387c662b6 | ||
|
|
ecdd027b3e | ||
|
|
2b0f572f4d | ||
|
|
0a1704e6a9 | ||
|
|
854c208f92 | ||
|
|
e6f604764c | ||
|
|
9b501b3dc8 | ||
|
|
c2fb23a25c | ||
|
|
1ad7ace9bd | ||
|
|
6a3a7eafea | ||
|
|
896aed0b38 | ||
|
|
f7359aacd7 | ||
|
|
d77fb9265b | ||
|
|
db27844eca |
@@ -9,7 +9,7 @@
|
||||
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean</artifactId>
|
||||
<version>12.2.1</version>
|
||||
<version>12.2.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ebean</name>
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:git@github.com:ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-12.2.1</tag>
|
||||
<tag>ebean-12.2.3</tag>
|
||||
</scm>
|
||||
|
||||
<profiles>
|
||||
@@ -64,7 +64,7 @@
|
||||
<dependency>
|
||||
<groupId>io.avaje</groupId>
|
||||
<artifactId>config</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
@@ -72,9 +72,9 @@
|
||||
to assist with IDE auto-completion with Ebean API
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-jsr305</artifactId>
|
||||
<version>1.1</version>
|
||||
<groupId>io.avaje</groupId>
|
||||
<artifactId>avaje-jsr305</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -292,7 +292,7 @@
|
||||
<plugin>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-maven-plugin</artifactId>
|
||||
<version>12.2.1</version>
|
||||
<version>12.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>test</id>
|
||||
|
||||
@@ -101,6 +101,22 @@ public class DB {
|
||||
// return originalPrimaryServer;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Return the ScriptRunner for the default database.
|
||||
* <p>
|
||||
* Useful to run SQL scripts that are resources. For example a test script
|
||||
* for inserting seed data for a particular test.
|
||||
*
|
||||
* <pre>{@code
|
||||
*
|
||||
* DB.script().run("/scripts/test-script.sql")
|
||||
*
|
||||
* }</pre>
|
||||
*/
|
||||
public static ScriptRunner script() {
|
||||
return getDefault().script();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ExpressionFactory from the default database.
|
||||
* <p>
|
||||
|
||||
@@ -913,6 +913,7 @@ public final class EntityBeanIntercept implements Serializable {
|
||||
}
|
||||
|
||||
private void preGetterCallback(int propertyIndex) {
|
||||
PreGetterCallback preGetterCallback = this.preGetterCallback;
|
||||
if (preGetterCallback != null) {
|
||||
preGetterCallback.preGetterTrigger(propertyIndex);
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ import io.ebeaninternal.server.changelog.DefaultChangeLogPrepare;
|
||||
import io.ebeaninternal.server.changelog.DefaultChangeLogRegister;
|
||||
import io.ebeaninternal.server.cluster.ClusterManager;
|
||||
import io.ebeaninternal.server.core.bootup.BootupClasses;
|
||||
import io.ebeaninternal.server.core.timezone.CloneDataTimeZone;
|
||||
import io.ebeaninternal.server.core.timezone.OracleDataTimeZone;
|
||||
import io.ebeaninternal.server.core.timezone.DataTimeZone;
|
||||
import io.ebeaninternal.server.core.timezone.LocalDataTimeZone;
|
||||
import io.ebeaninternal.server.core.timezone.MySqlDataTimeZone;
|
||||
import io.ebeaninternal.server.core.timezone.NoDataTimeZone;
|
||||
import io.ebeaninternal.server.core.timezone.SimpleDataTimeZone;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
@@ -529,12 +529,12 @@ public class InternalConfiguration {
|
||||
String tz = serverConfig.getDataTimeZone();
|
||||
if (tz == null) {
|
||||
if (isMySql(getPlatform())) {
|
||||
return new LocalDataTimeZone();
|
||||
return new MySqlDataTimeZone();
|
||||
}
|
||||
return new NoDataTimeZone();
|
||||
}
|
||||
if (getPlatform().base() == Platform.ORACLE) {
|
||||
return new CloneDataTimeZone(tz);
|
||||
return new OracleDataTimeZone(tz);
|
||||
} else {
|
||||
return new SimpleDataTimeZone(tz);
|
||||
}
|
||||
|
||||
+5
-5
@@ -5,11 +5,11 @@ import java.util.Calendar;
|
||||
/**
|
||||
* Implementation of DataTimeZone when single Calendar instance is used with local timezone.
|
||||
*/
|
||||
public class LocalDataTimeZone implements DataTimeZone {
|
||||
public class MySqlDataTimeZone implements DataTimeZone {
|
||||
|
||||
protected final Calendar zone;
|
||||
|
||||
public LocalDataTimeZone() {
|
||||
public MySqlDataTimeZone() {
|
||||
this.zone = Calendar.getInstance();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class LocalDataTimeZone implements DataTimeZone {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Calendar getDateTimeZone() {
|
||||
return zone; // workaround for MySQL. TODO: rename class to MySqlDataTimeZone!?
|
||||
}
|
||||
public Calendar getDateTimeZone() {
|
||||
return zone;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -8,9 +8,9 @@ import java.util.Calendar;
|
||||
* Used with Oracle JDBC driver as that wants to mutate the Calender.
|
||||
* </p>
|
||||
*/
|
||||
public class CloneDataTimeZone extends SimpleDataTimeZone {
|
||||
public class OracleDataTimeZone extends SimpleDataTimeZone {
|
||||
|
||||
public CloneDataTimeZone(String zoneId) {
|
||||
public OracleDataTimeZone(String zoneId) {
|
||||
super(zoneId);
|
||||
}
|
||||
|
||||
@@ -1002,6 +1002,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
orderProperty.setDbInsertable(orderColumn.isInsertable());
|
||||
orderProperty.setDbUpdateable(orderColumn.isUpdatable());
|
||||
orderProperty.setDbRead(true);
|
||||
orderProperty.setOwningType(targetDesc.getBeanType());
|
||||
|
||||
targetDesc.setOrderColumn(orderProperty);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.persist.dml;
|
||||
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
@@ -44,7 +45,10 @@ final class InsertMeta {
|
||||
|
||||
private final String[] identityDbColumns;
|
||||
|
||||
private final Platform platform;
|
||||
|
||||
InsertMeta(DatabasePlatform dbPlatform, BeanDescriptor<?> desc, Bindable shadowFKey, BindableId id, BindableList all) {
|
||||
this.platform = dbPlatform.getPlatform();
|
||||
this.discriminator = getDiscriminator(desc);
|
||||
this.id = id;
|
||||
this.all = all;
|
||||
@@ -162,7 +166,11 @@ final class InsertMeta {
|
||||
|
||||
request.append("insert into ").append(table);
|
||||
if (nullId && noColumnsForInsert(draftTable)) {
|
||||
request.append(" default values");
|
||||
if (this.platform.base() == Platform.MYSQL) {
|
||||
request.append(" values (default)");
|
||||
} else {
|
||||
request.append(" default values");
|
||||
}
|
||||
return request.toString();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -22,8 +22,8 @@ public class EbeanServer_refresh {
|
||||
map.put("tableName", "e_basic");
|
||||
|
||||
EbeanServer server = Ebean.getDefaultServer();
|
||||
server.script().run("/scripts/test-script.sql");
|
||||
server.script().run("/scripts/test-script-2.sql", map);
|
||||
DB.script().run("/scripts/test-script.sql");
|
||||
DB.script().run("/scripts/test-script-2.sql", map);
|
||||
server.script().run(this.getClass().getResource("/scripts/test-script.sql"));
|
||||
server.script().run(this.getClass().getResource("/scripts/test-script-2.sql"), map);
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.lang.reflect.Field;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.ebean.annotation.Platform.H2;
|
||||
import static io.ebean.annotation.Platform.POSTGRES;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -40,14 +42,14 @@ public class TestAnnotationBase extends BaseTestCase {
|
||||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Where(clause = "SELECT 'mysql' from 1", platforms = Platform.MYSQL)
|
||||
@Where(clause = "SELECT 'h2' from 1", platforms = Platform.H2)
|
||||
@Where(clause = "SELECT 'h2' from 1", platforms = H2)
|
||||
@Where(clause = "SELECT 'other' from 1")
|
||||
public @interface MetaTest {
|
||||
|
||||
}
|
||||
|
||||
@Index(name = "ano_1", columnNames = "direct")
|
||||
@Index(name = "ano_2", columnNames = "direct")
|
||||
@Index(name = "ano_1", columnNames = "direct", platforms = {H2, POSTGRES})
|
||||
@Index(name = "ano_2", columnNames = "direct", platforms = {H2, POSTGRES})
|
||||
@MappedSuperclass
|
||||
public static class MappedBaseEntity {
|
||||
|
||||
@@ -58,7 +60,7 @@ public class TestAnnotationBase extends BaseTestCase {
|
||||
public static class TestAnnotationBaseEntity extends MappedBaseEntity {
|
||||
|
||||
@Where(clause = "SELECT 'mysql' from 1", platforms = Platform.MYSQL)
|
||||
@Where(clause = "SELECT 'h2' from 1", platforms = Platform.H2)
|
||||
@Where(clause = "SELECT 'h2' from 1", platforms = H2)
|
||||
@Where(clause = "SELECT 'other' from 1")
|
||||
private String direct;
|
||||
|
||||
@@ -178,7 +180,7 @@ public class TestAnnotationBase extends BaseTestCase {
|
||||
final DeployBeanProperty direct = createProperty(directFld);
|
||||
|
||||
assertEquals("SELECT 'mysql' from 1", where(direct, Platform.MYSQL));
|
||||
assertEquals("SELECT 'h2' from 1", where(direct, Platform.H2));
|
||||
assertEquals("SELECT 'h2' from 1", where(direct, H2));
|
||||
assertEquals("SELECT 'other' from 1", where(direct, Platform.POSTGRES));
|
||||
|
||||
// meta
|
||||
@@ -186,7 +188,7 @@ public class TestAnnotationBase extends BaseTestCase {
|
||||
final DeployBeanProperty meta = createProperty(metaFld);
|
||||
|
||||
assertEquals("SELECT 'mysql' from 1", where(meta, Platform.MYSQL));
|
||||
assertEquals("SELECT 'h2' from 1", where(meta, Platform.H2));
|
||||
assertEquals("SELECT 'h2' from 1", where(meta, H2));
|
||||
assertEquals("SELECT 'other' from 1", where(meta, Platform.POSTGRES));
|
||||
|
||||
// mixed
|
||||
@@ -194,7 +196,7 @@ public class TestAnnotationBase extends BaseTestCase {
|
||||
final DeployBeanProperty mixed = createProperty(mixedFld);
|
||||
|
||||
assertEquals("SELECT 'mysql' from 1", where(mixed, Platform.MYSQL));
|
||||
assertEquals("SELECT 'h2' from 1", where(mixed, Platform.H2));
|
||||
assertEquals("SELECT 'h2' from 1", where(mixed, H2));
|
||||
assertEquals("SELECT 'other' from 1", where(mixed, Platform.POSTGRES));
|
||||
assertEquals("SELECT 'oracle' from 1", where(mixed, Platform.ORACLE));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.tests.defaultvalues;
|
||||
|
||||
import io.ebean.annotation.Draft;
|
||||
import io.ebean.annotation.Draftable;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Draftable
|
||||
public class DefaultsModel {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
@Draft
|
||||
boolean draft;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
List<ReferencedDefaultsModel> relatedModels;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<ReferencedDefaultsModel> getRelatedModels() {
|
||||
return relatedModels;
|
||||
}
|
||||
|
||||
public void setRelatedModels(final List<ReferencedDefaultsModel> relatedModels) {
|
||||
this.relatedModels = relatedModels;
|
||||
}
|
||||
|
||||
public boolean isDraft() {
|
||||
return draft;
|
||||
}
|
||||
|
||||
public void setDraft(final boolean draft) {
|
||||
this.draft = draft;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.tests.defaultvalues;
|
||||
|
||||
import io.ebean.annotation.Draft;
|
||||
import io.ebean.annotation.Draftable;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
@Draftable
|
||||
public class ReferencedDefaultsModel {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
String name;
|
||||
|
||||
@Draft
|
||||
boolean draft;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isDraft() {
|
||||
return draft;
|
||||
}
|
||||
|
||||
public void setDraft(final boolean draft) {
|
||||
this.draft = draft;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.tests.defaultvalues;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestDefaults extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testInsertDefaultValues() {
|
||||
final DefaultsModel main = new DefaultsModel();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final ReferencedDefaultsModel ref = new ReferencedDefaultsModel();
|
||||
ref.setName("r" + i);
|
||||
main.getRelatedModels().add(ref);
|
||||
}
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
Ebean.save(main);
|
||||
final List<String> current = LoggedSqlCollector.current();
|
||||
|
||||
assertThat(current).isNotEmpty();
|
||||
if (isMySql()) {
|
||||
assertThat(current.get(0)).contains("insert into defaults_model_draft values (default);");
|
||||
} else {
|
||||
assertThat(current.get(0)).contains("insert into defaults_model_draft default values;");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.tests.inheritance.cache;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
@@ -9,6 +10,7 @@ import javax.persistence.Table;
|
||||
@DiscriminatorValue(value = "1")
|
||||
public class CIStreet extends CIStreetParent {
|
||||
|
||||
@Column(name="num")
|
||||
protected String number;
|
||||
|
||||
public String getNumber() {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.tests.order;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OrderColumn;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class OrderMaster {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@OneToMany(mappedBy = "master")
|
||||
@OrderColumn(name = "sort_order")
|
||||
List<OrderReferencedChild> children;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<OrderReferencedChild> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(final List<OrderReferencedChild> children) {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.tests.order;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
@DiscriminatorValue("D")
|
||||
public class OrderReferencedChild extends OrderReferencedParent {
|
||||
|
||||
String childName;
|
||||
|
||||
@ManyToOne
|
||||
OrderMaster master;
|
||||
|
||||
public OrderReferencedChild(final String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public String getChildName() {
|
||||
return childName;
|
||||
}
|
||||
|
||||
public void setChildName(final String childName) {
|
||||
this.childName = childName;
|
||||
}
|
||||
|
||||
public OrderMaster getMaster() {
|
||||
return master;
|
||||
}
|
||||
|
||||
public void setMaster(final OrderMaster master) {
|
||||
this.master = master;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.tests.order;
|
||||
|
||||
import io.ebean.annotation.Index;
|
||||
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@Entity
|
||||
@MappedSuperclass
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "type")
|
||||
@Index(columnNames = "type")
|
||||
public class OrderReferencedParent {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
String name;
|
||||
|
||||
public OrderReferencedParent(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.tests.order;
|
||||
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.TransactionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestOrderColumn extends TransactionalTestCase {
|
||||
|
||||
@Test
|
||||
public void testOrderColumnInheritance() {
|
||||
final OrderMaster master = new OrderMaster();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final OrderReferencedChild child = new OrderReferencedChild("p" + i);
|
||||
child.setChildName("c" + i);
|
||||
|
||||
master.getChildren().add(child);
|
||||
}
|
||||
|
||||
Ebean.save(master);
|
||||
|
||||
final OrderMaster result = Ebean.find(OrderMaster.class).findOne();
|
||||
|
||||
assertThat(result.getChildren()).hasSize(5);
|
||||
assertThat(result.getChildren()).extracting(OrderReferencedChild::getName).containsExactly("p0", "p1", "p2", "p3", "p4");
|
||||
assertThat(result.getChildren()).extracting(OrderReferencedChild::getChildName).containsExactly("c0", "c1", "c2", "c3", "c4");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user