mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e59e72983 | ||
|
|
b56d68dac7 | ||
|
|
213562fcf1 | ||
|
|
d3a09b93c0 | ||
|
|
536ea57369 | ||
|
|
ac1dd4cbab | ||
|
|
bc33e05906 | ||
|
|
8ecc407cb0 | ||
|
|
2672dff512 | ||
|
|
74d907bbce | ||
|
|
53aacabce7 | ||
|
|
ab9cdd8f5b | ||
|
|
b3d439ed11 | ||
|
|
d57657c209 | ||
|
|
dd080c5933 | ||
|
|
0be98d7989 | ||
|
|
fca54dbbe3 |
+1
-1
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<name>ebean api</name>
|
||||
|
||||
@@ -931,10 +931,14 @@ public final class EntityBeanIntercept implements Serializable {
|
||||
* OneToMany and ManyToMany only set loaded state.
|
||||
*/
|
||||
public void preSetterMany(boolean interceptField, int propertyIndex, Object oldValue, Object newValue) {
|
||||
if (readOnly) {
|
||||
throw new IllegalStateException("This bean is readOnly");
|
||||
if (state == STATE_NEW) {
|
||||
setLoadedProperty(propertyIndex);
|
||||
} else {
|
||||
if (readOnly) {
|
||||
throw new IllegalStateException("This bean is readOnly");
|
||||
}
|
||||
setChangedProperty(propertyIndex);
|
||||
}
|
||||
setLoadedProperty(propertyIndex);
|
||||
}
|
||||
|
||||
private void setChangedPropertyValue(int propertyIndex, boolean setDirtyState, Object origValue) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
<!-- <parent>-->
|
||||
<!-- <groupId>org.avaje</groupId>-->
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:git@github.com:ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-parent-12.6.6</tag>
|
||||
<tag>ebean-parent-12.6.7</tag>
|
||||
</scm>
|
||||
|
||||
<name>ebean autotune</name>
|
||||
@@ -26,7 +26,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
<plugin>
|
||||
<groupId>io.repaint.maven</groupId>
|
||||
<artifactId>tiles-maven-plugin</artifactId>
|
||||
<version>2.18</version>
|
||||
<version>2.19</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<tiles>
|
||||
|
||||
+15
-15
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<name>ebean bom</name>
|
||||
@@ -81,88 +81,88 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-api</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core-type</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-ddl-generator</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-externalmapping-api</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-externalmapping-xml</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-autotune</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-querybean</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>querybean-generator</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>kotlin-querybean-generator</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-test</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-postgis</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-redis</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ebean-core-type</artifactId>
|
||||
@@ -21,7 +21,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-api</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
+5
-5
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ebean-core</artifactId>
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:git@github.com:ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-parent-12.6.6</tag>
|
||||
<tag>ebean-parent-12.6.7</tag>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
@@ -92,19 +92,19 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-api</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core-type</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-externalmapping-api</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -131,19 +131,10 @@ public class DatabasePlatformFactory {
|
||||
* Use JDBC DatabaseMetaData to determine the platform.
|
||||
*/
|
||||
private DatabasePlatform byDataSource(DataSource dataSource) {
|
||||
|
||||
Connection connection = null;
|
||||
try {
|
||||
connection = dataSource.getConnection();
|
||||
DatabaseMetaData metaData = connection.getMetaData();
|
||||
|
||||
return byDatabaseMeta(metaData, connection);
|
||||
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
return byDatabaseMeta(connection.getMetaData(), connection);
|
||||
} catch (SQLException ex) {
|
||||
throw new PersistenceException(ex);
|
||||
|
||||
} finally {
|
||||
JdbcClose.close(connection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +148,7 @@ public class DatabasePlatformFactory {
|
||||
final int minorVersion = metaData.getDatabaseMinorVersion();
|
||||
|
||||
if (dbProductName.contains("oracle")) {
|
||||
return new OraclePlatform();
|
||||
return oracleVersion(majorVersion);
|
||||
} else if (dbProductName.contains("microsoft")) {
|
||||
throw new IllegalArgumentException("For SqlServer please explicitly choose either sqlserver16 or sqlserver17 as the platform via DatabaseConfig.setDatabasePlatformName. Refer to issue #1340 for more details");
|
||||
} else if (dbProductName.contains("h2")) {
|
||||
@@ -188,6 +179,10 @@ public class DatabasePlatformFactory {
|
||||
return new DatabasePlatform();
|
||||
}
|
||||
|
||||
private DatabasePlatform oracleVersion(int majorVersion) {
|
||||
return majorVersion < 12 ? new Oracle11Platform() : new OraclePlatform();
|
||||
}
|
||||
|
||||
private DatabasePlatform mysqlVersion(int majorVersion, int minorVersion) {
|
||||
if (majorVersion <= 5 && minorVersion <= 5) {
|
||||
return new MySql55Platform();
|
||||
|
||||
+5
@@ -176,4 +176,9 @@ public abstract class DeployBeanPropertyAssoc<T> extends DeployBeanProperty {
|
||||
public void setFetchPreference(int fetchPreference) {
|
||||
this.fetchPreference = fetchPreference;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setTargetType(Class<?> targetType) {
|
||||
this.targetType = (Class<T>)targetType;
|
||||
}
|
||||
}
|
||||
|
||||
-13
@@ -65,19 +65,6 @@ public class DeployBeanPropertyAssocMany<T> extends DeployBeanPropertyAssoc<T> {
|
||||
this.manyType = manyType;
|
||||
}
|
||||
|
||||
/**
|
||||
* When generics is not used for manyType you can specify via annotations.
|
||||
* <p>
|
||||
* Really only expect this for Scala due to a Scala compiler bug at the moment.
|
||||
* Otherwise I'd probably not bother support this.
|
||||
* </p>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setTargetType(Class<?> cls) {
|
||||
this.targetType = (Class<T>) cls;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the many type.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.ebeaninternal.server.deploy.parse;
|
||||
|
||||
import io.ebean.config.BeanNotRegisteredException;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
import io.ebeaninternal.server.deploy.BeanTable;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssoc;
|
||||
|
||||
abstract class AnnotationAssoc extends AnnotationParser {
|
||||
|
||||
final BeanDescriptorManager factory;
|
||||
|
||||
AnnotationAssoc(DeployBeanInfo<?> info, ReadAnnotationConfig readConfig, BeanDescriptorManager factory) {
|
||||
super(info, readConfig);
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
void setTargetType(Class<?> targetType, DeployBeanPropertyAssoc<?> prop) {
|
||||
if (!targetType.equals(void.class)) {
|
||||
prop.setTargetType(targetType);
|
||||
}
|
||||
}
|
||||
|
||||
void setBeanTable(DeployBeanPropertyAssoc<?> prop) {
|
||||
BeanTable assoc = getBeanTable(prop);
|
||||
if (assoc == null) {
|
||||
throw new BeanNotRegisteredException(errorMsgMissingBeanTable(prop.getTargetType(), prop.getFullBeanName()));
|
||||
}
|
||||
prop.setBeanTable(assoc);
|
||||
}
|
||||
|
||||
BeanTable getBeanTable(DeployBeanPropertyAssoc<?> prop) {
|
||||
return factory.getBeanTable(prop.getTargetType());
|
||||
}
|
||||
|
||||
private String errorMsgMissingBeanTable(Class<?> type, String from) {
|
||||
return "Error with association to [" + type + "] from [" + from + "]. Is " + type + " registered? See https://ebean.io/docs/trouble-shooting#not-registered";
|
||||
}
|
||||
|
||||
}
|
||||
+10
-32
@@ -5,7 +5,6 @@ import io.ebean.annotation.FetchPreference;
|
||||
import io.ebean.annotation.HistoryExclude;
|
||||
import io.ebean.annotation.Where;
|
||||
import io.ebean.bean.BeanCollection.ModifyListenMode;
|
||||
import io.ebean.config.BeanNotRegisteredException;
|
||||
import io.ebean.config.NamingConvention;
|
||||
import io.ebean.config.TableName;
|
||||
import io.ebean.core.type.ScalarType;
|
||||
@@ -44,16 +43,10 @@ import static io.ebean.util.StringHelper.isNull;
|
||||
/**
|
||||
* Read the deployment annotation for Assoc Many beans.
|
||||
*/
|
||||
class AnnotationAssocManys extends AnnotationParser {
|
||||
class AnnotationAssocManys extends AnnotationAssoc {
|
||||
|
||||
private final BeanDescriptorManager factory;
|
||||
|
||||
/**
|
||||
* Create with the DeployInfo.
|
||||
*/
|
||||
AnnotationAssocManys(DeployBeanInfo<?> info, ReadAnnotationConfig readConfig, BeanDescriptorManager factory) {
|
||||
super(info, readConfig);
|
||||
this.factory = factory;
|
||||
super(info, readConfig, factory);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,15 +139,15 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
JoinTable joinTable = get(prop, JoinTable.class);
|
||||
if (joinTable != null) {
|
||||
if (prop.isManyToMany()) {
|
||||
// expected this
|
||||
readJoinTable(joinTable, prop);
|
||||
|
||||
} else {
|
||||
// OneToMany with @JoinTable
|
||||
prop.setO2mJoinTable();
|
||||
readJoinTable(joinTable, prop);
|
||||
manyToManyDefaultJoins(prop);
|
||||
}
|
||||
} else if (prop.isManyToMany()) {
|
||||
checkSelfManyToMany(prop);
|
||||
}
|
||||
|
||||
if (prop.getMappedBy() != null) {
|
||||
@@ -187,6 +180,12 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSelfManyToMany(DeployBeanPropertyAssocMany<?> prop) {
|
||||
if (prop.getTargetType().equals(descriptor.getBeanType())) {
|
||||
throw new IllegalStateException("@ManyToMany mapping for " + prop.getFullBeanName() + " requires explicit @JoinTable with joinColumns & inverseJoinColumns. Refer issue #2157");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void readElementCollection(DeployBeanPropertyAssocMany<?> prop, ElementCollection elementCollection) {
|
||||
|
||||
@@ -435,13 +434,7 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
prop.setInverseJoin(inverseDest);
|
||||
}
|
||||
|
||||
|
||||
private String errorMsgMissingBeanTable(Class<?> type, String from) {
|
||||
return "Error with association to [" + type + "] from [" + from + "]. Is " + type + " registered? See https://ebean.io/docs/trouble-shooting#not-registered";
|
||||
}
|
||||
|
||||
private void readToMany(ManyToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) {
|
||||
|
||||
manyProp.setMappedBy(propAnn.mappedBy());
|
||||
manyProp.setFetchType(propAnn.fetch());
|
||||
setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo());
|
||||
@@ -453,7 +446,6 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
}
|
||||
|
||||
private void readToOne(OneToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) {
|
||||
|
||||
manyProp.setMappedBy(propAnn.mappedBy());
|
||||
manyProp.setFetchType(propAnn.fetch());
|
||||
setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo());
|
||||
@@ -462,20 +454,6 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
manyProp.getTableJoin().setType(SqlJoinType.OUTER);
|
||||
}
|
||||
|
||||
private void setTargetType(Class<?> targetType, DeployBeanPropertyAssocMany<?> prop) {
|
||||
if (!targetType.equals(void.class)) {
|
||||
prop.setTargetType(targetType);
|
||||
}
|
||||
}
|
||||
|
||||
private void setBeanTable(DeployBeanPropertyAssocMany<?> manyProp) {
|
||||
BeanTable assoc = factory.getBeanTable(manyProp.getTargetType());
|
||||
if (assoc == null) {
|
||||
throw new BeanNotRegisteredException(errorMsgMissingBeanTable(manyProp.getTargetType(), manyProp.getFullBeanName()));
|
||||
}
|
||||
manyProp.setBeanTable(assoc);
|
||||
}
|
||||
|
||||
private String getM2MJoinTableName(BeanTable lhsTable, BeanTable rhsTable) {
|
||||
|
||||
TableName lhs = new TableName(lhsTable.getBaseTable());
|
||||
|
||||
+8
-24
@@ -33,18 +33,15 @@ import javax.validation.constraints.NotNull;
|
||||
/**
|
||||
* Read the deployment annotations for Associated One beans.
|
||||
*/
|
||||
public class AnnotationAssocOnes extends AnnotationParser {
|
||||
public class AnnotationAssocOnes extends AnnotationAssoc {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AnnotationAssocOnes.class);
|
||||
|
||||
private final BeanDescriptorManager factory;
|
||||
|
||||
/**
|
||||
* Create with the deploy Info.
|
||||
*/
|
||||
AnnotationAssocOnes(DeployBeanInfo<?> info, ReadAnnotationConfig readConfig, BeanDescriptorManager factory) {
|
||||
super(info, readConfig);
|
||||
this.factory = factory;
|
||||
super(info, readConfig, factory);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,25 +188,11 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
}
|
||||
}
|
||||
|
||||
private String errorMsgMissingBeanTable(Class<?> type, String from) {
|
||||
return "Error with association to [" + type + "] from [" + from + "]. Is " + type + " registered? Does it have the @Entity annotation? See https://ebean.io/docs/trouble-shooting#not-registered";
|
||||
}
|
||||
|
||||
private BeanTable beanTable(DeployBeanPropertyAssoc<?> prop) {
|
||||
BeanTable assoc = factory.getBeanTable(prop.getPropertyType());
|
||||
if (assoc == null) {
|
||||
throw new BeanNotRegisteredException(errorMsgMissingBeanTable(prop.getPropertyType(), prop.getFullBeanName()));
|
||||
}
|
||||
return assoc;
|
||||
}
|
||||
|
||||
private void readManyToOne(ManyToOne propAnn, DeployBeanProperty prop) {
|
||||
|
||||
DeployBeanPropertyAssocOne<?> beanProp = (DeployBeanPropertyAssocOne<?>) prop;
|
||||
private void readManyToOne(ManyToOne propAnn, DeployBeanPropertyAssocOne<?> beanProp) {
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), beanProp.getCascadeInfo());
|
||||
|
||||
beanProp.setBeanTable(beanTable(beanProp));
|
||||
setTargetType(propAnn.targetEntity(), beanProp);
|
||||
setBeanTable(beanProp);
|
||||
beanProp.setDbInsertable(true);
|
||||
beanProp.setDbUpdateable(true);
|
||||
beanProp.setNullable(propAnn.optional());
|
||||
@@ -232,7 +215,8 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
}
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), prop.getCascadeInfo());
|
||||
prop.setBeanTable(beanTable(prop));
|
||||
setTargetType(propAnn.targetEntity(), prop);
|
||||
setBeanTable(prop);
|
||||
}
|
||||
|
||||
private boolean readOrphanRemoval(OneToOne property) {
|
||||
@@ -261,7 +245,7 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
BeanTable baseBeanTable = factory.getBeanTable(info.getDescriptor().getBeanType());
|
||||
|
||||
String localPrimaryKey = baseBeanTable.getIdColumn();
|
||||
String foreignColumn = beanTable(prop).getIdColumn();
|
||||
String foreignColumn = getBeanTable(prop).getIdColumn();
|
||||
|
||||
prop.getTableJoin().addJoinColumn(new DeployTableJoinColumn(localPrimaryKey, foreignColumn, false, false));
|
||||
}
|
||||
|
||||
-8
@@ -145,14 +145,6 @@ public class DeployCreateProperties {
|
||||
private DeployBeanProperty createProp(DeployBeanDescriptor<?> desc, Field field) {
|
||||
|
||||
Class<?> propertyType = field.getType();
|
||||
|
||||
ManyToOne manyToOne = AnnotationUtil.get(field, ManyToOne.class);
|
||||
if (manyToOne != null) {
|
||||
Class<?> tt = manyToOne.targetEntity();
|
||||
if (!tt.equals(void.class)) {
|
||||
propertyType = tt;
|
||||
}
|
||||
}
|
||||
if (isSpecialScalarType(field)) {
|
||||
return new DeployBeanProperty(desc, propertyType, field.getGenericType());
|
||||
}
|
||||
|
||||
@@ -210,18 +210,6 @@ public class SaveManyBeans extends SaveManyBase {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasNewOrDirtyBeans() {
|
||||
if (collection == null) {
|
||||
return false;
|
||||
}
|
||||
for (Object bean : collection) {
|
||||
if (bean instanceof EntityBean && ((EntityBean) bean)._ebean_getIntercept().isNewOrDirty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the Id values of the details to remove 'missing children' for stateless updates.
|
||||
*/
|
||||
@@ -344,14 +332,18 @@ public class SaveManyBeans extends SaveManyBase {
|
||||
transaction.depth(-1);
|
||||
}
|
||||
|
||||
private boolean isChangedProperty() {
|
||||
return parentBean._ebean_getIntercept().isChangedProperty(many.getPropertyIndex());
|
||||
}
|
||||
|
||||
private void removeAssocManyOrphans() {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
if (!(value instanceof BeanCollection<?>)) {
|
||||
// if (!insertedParent && cascade && hasNewOrDirtyBeans()) {
|
||||
// persister.addToFlushQueue(many.deleteByParentId(request.getBeanId(), null), transaction, 0);
|
||||
// }
|
||||
if (!insertedParent && cascade && isChangedProperty()) {
|
||||
persister.addToFlushQueue(many.deleteByParentId(request.getBeanId(), null), transaction, 0);
|
||||
}
|
||||
} else {
|
||||
BeanCollection<?> c = (BeanCollection<?>) value;
|
||||
Set<?> modifyRemovals = c.getModifyRemovals();
|
||||
|
||||
@@ -296,10 +296,10 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
|
||||
this.cancelled = true;
|
||||
if (pstmt != null) {
|
||||
try {
|
||||
logger.debug("Cancelling query");
|
||||
pstmt.cancel();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error cancelling query";
|
||||
throw new PersistenceException(msg, e);
|
||||
throw new PersistenceException("Error cancelling query", e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -322,7 +322,6 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
|
||||
}
|
||||
|
||||
private boolean prepareBindExecuteQueryWithOption(boolean forwardOnlyHint) throws SQLException {
|
||||
|
||||
ResultSet resultSet = prepareResultSet(forwardOnlyHint);
|
||||
if (resultSet == null) {
|
||||
return false;
|
||||
@@ -334,19 +333,12 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
|
||||
ResultSet prepareResultSet(boolean forwardOnlyHint) throws SQLException {
|
||||
lock.lock();
|
||||
try {
|
||||
if (cancelled || query.isCancelled()) {
|
||||
// cancelled before we started
|
||||
cancelled = true;
|
||||
return null;
|
||||
if (cancelled) {
|
||||
throw new SQLException("Query cancelled");
|
||||
}
|
||||
|
||||
startNano = System.nanoTime();
|
||||
|
||||
// prepare
|
||||
SpiTransaction t = request.getTransaction();
|
||||
profileOffset = t.profileOffset();
|
||||
Connection conn = t.getInternalConnection();
|
||||
|
||||
if (query.isRawSql()) {
|
||||
ResultSet suppliedResultSet = query.getRawSql().getResultSet();
|
||||
if (suppliedResultSet != null) {
|
||||
@@ -356,6 +348,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
|
||||
}
|
||||
}
|
||||
|
||||
Connection conn = t.getInternalConnection();
|
||||
if (forwardOnlyHint) {
|
||||
// Use forward only hints for large resultSet processing (Issue 56, MySql specific)
|
||||
pstmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
@@ -363,18 +356,13 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
|
||||
} else {
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
}
|
||||
|
||||
if (query.getTimeout() > 0) {
|
||||
pstmt.setQueryTimeout(query.getTimeout());
|
||||
}
|
||||
if (query.getBufferFetchSizeHint() > 0) {
|
||||
pstmt.setFetchSize(query.getBufferFetchSizeHint());
|
||||
}
|
||||
|
||||
DataBind dataBind = queryPlan.bindEncryptedProperties(pstmt, conn);
|
||||
bindLog = predicates.bind(dataBind);
|
||||
|
||||
// executeQuery
|
||||
bindLog = predicates.bind(queryPlan.bindEncryptedProperties(pstmt, conn));
|
||||
return pstmt.executeQuery();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
|
||||
@@ -401,12 +401,6 @@ public class CQueryEngine {
|
||||
if (cquery != null) {
|
||||
cquery.close();
|
||||
}
|
||||
if (request.getQuery().isFutureFetch()) {
|
||||
// end the transaction for futureFindIds
|
||||
// as it had it's own transaction
|
||||
logger.debug("Future fetch completed!");
|
||||
request.getTransaction().end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -751,7 +751,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
|
||||
@Override
|
||||
public NaturalKeyQueryData<T> naturalKey() {
|
||||
|
||||
if (whereExpressions == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -767,7 +766,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -815,7 +813,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
copy.m2mIncludeJoin = m2mIncludeJoin;
|
||||
copy.profilingListener = profilingListener;
|
||||
copy.profileLocation = profileLocation;
|
||||
|
||||
copy.baseTable = baseTable;
|
||||
copy.rootTableAlias = rootTableAlias;
|
||||
copy.distinct = distinct;
|
||||
@@ -1100,7 +1097,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
|
||||
@Override
|
||||
public ObjectGraphNode setOrigin(CallOrigin callOrigin) {
|
||||
|
||||
// create a 'origin' which links this query to the profiling information
|
||||
ObjectGraphOrigin o = new ObjectGraphOrigin(calculateOriginQueryHash(), callOrigin, beanType.getName());
|
||||
parentNode = new ObjectGraphNode(o, null);
|
||||
@@ -1241,7 +1237,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
*/
|
||||
@Override
|
||||
public CQueryPlanKey prepare(SpiOrmQueryRequest<T> request) {
|
||||
|
||||
prepareExpressions(request);
|
||||
prepareForPaging();
|
||||
queryPlanKey = createQueryPlanKey();
|
||||
@@ -1252,7 +1247,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
* Prepare the expressions (compile sub-queries etc).
|
||||
*/
|
||||
private void prepareExpressions(BeanQueryRequest<?> request) {
|
||||
|
||||
if (whereExpressions != null) {
|
||||
whereExpressions.prepareExpression(request);
|
||||
}
|
||||
@@ -1267,7 +1261,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
* case, this is not a distinct query
|
||||
*/
|
||||
private void prepareForPaging() {
|
||||
|
||||
// add the rawSql statement - if any
|
||||
if (orderByIsEmpty()) {
|
||||
if (rawSql != null && rawSql.getSql() != null) {
|
||||
@@ -1678,7 +1671,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
if (bindParams == null) {
|
||||
bindParams = new BindParams();
|
||||
}
|
||||
@@ -1972,7 +1964,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
if (namedParams == null) {
|
||||
namedParams = new HashMap<>();
|
||||
}
|
||||
|
||||
return namedParams.computeIfAbsent(name, ONamedParam::new);
|
||||
}
|
||||
|
||||
@@ -2066,8 +2057,8 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
public void cancel() {
|
||||
lock.lock();
|
||||
try {
|
||||
cancelled = true;
|
||||
if (cancelableQuery != null) {
|
||||
if (!cancelled && cancelableQuery != null) {
|
||||
cancelled = true;
|
||||
cancelableQuery.cancel();
|
||||
}
|
||||
} finally {
|
||||
@@ -2095,7 +2086,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
*/
|
||||
@Override
|
||||
public Set<String> validate(BeanType<T> desc) {
|
||||
|
||||
SpiExpressionValidation validation = new SpiExpressionValidation(desc);
|
||||
if (whereExpressions != null) {
|
||||
whereExpressions.validate(validation);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- Generated by ebean unknown at 2020-12-07T09:40:50.461215Z
|
||||
-- Generated by ebean unknown at 2021-02-12T03:32:14.253435800Z
|
||||
create table asimple_bean (
|
||||
id bigint generated by default as identity not null,
|
||||
name varchar(255),
|
||||
@@ -486,6 +486,13 @@ create table child_person (
|
||||
constraint pk_child_person primary key (identifier)
|
||||
);
|
||||
|
||||
create table child_with_cache (
|
||||
id bigint generated by default as identity not null,
|
||||
name varchar(255),
|
||||
address varchar(255),
|
||||
constraint pk_child_with_cache primary key (id)
|
||||
);
|
||||
|
||||
create table cke_client (
|
||||
cod_cpny integer not null,
|
||||
cod_client varchar(100) not null,
|
||||
@@ -1168,6 +1175,12 @@ create table ebasic_json_unmapped (
|
||||
constraint pk_ebasic_json_unmapped primary key (id)
|
||||
);
|
||||
|
||||
create table e_basic_log (
|
||||
id bigint generated by default as identity not null,
|
||||
name varchar(255),
|
||||
constraint pk_e_basic_log primary key (id)
|
||||
);
|
||||
|
||||
create table e_basic_ndc (
|
||||
id integer generated by default as identity not null,
|
||||
name varchar(255),
|
||||
@@ -1227,6 +1240,14 @@ create table e_basic_with_ex (
|
||||
constraint pk_e_basic_with_ex primary key (id)
|
||||
);
|
||||
|
||||
create table e_basic_withlog (
|
||||
id bigint generated by default as identity not null,
|
||||
name varchar(255),
|
||||
deleted boolean default false not null,
|
||||
version bigint not null,
|
||||
constraint pk_e_basic_withlog primary key (id)
|
||||
);
|
||||
|
||||
create table e_basicverucon (
|
||||
id integer generated by default as identity not null,
|
||||
name varchar(127),
|
||||
@@ -2256,6 +2277,29 @@ create table looney (
|
||||
constraint pk_looney primary key (id)
|
||||
);
|
||||
|
||||
create table m2_mcache_child (
|
||||
id integer generated by default as identity not null,
|
||||
name varchar(255),
|
||||
constraint pk_m2_mcache_child primary key (id)
|
||||
);
|
||||
|
||||
create table m2_mcache_master (
|
||||
id integer generated by default as identity not null,
|
||||
constraint pk_m2_mcache_master primary key (id)
|
||||
);
|
||||
|
||||
create table m2mcache_set1 (
|
||||
m2_mcache_master_id integer not null,
|
||||
m2_mcache_child_id integer not null,
|
||||
constraint pk_m2mcache_set1 primary key (m2_mcache_master_id,m2_mcache_child_id)
|
||||
);
|
||||
|
||||
create table m2mcache_set2 (
|
||||
m2_mcache_master_id integer not null,
|
||||
m2_mcache_child_id integer not null,
|
||||
constraint pk_m2mcache_set2 primary key (m2_mcache_master_id,m2_mcache_child_id)
|
||||
);
|
||||
|
||||
create table maddress (
|
||||
id uuid not null,
|
||||
street varchar(255),
|
||||
@@ -3230,6 +3274,19 @@ create table e_save_test_c (
|
||||
constraint pk_e_save_test_c primary key (id)
|
||||
);
|
||||
|
||||
create table parent_a (
|
||||
id bigint generated by default as identity not null,
|
||||
child_id bigint,
|
||||
name varchar(255),
|
||||
constraint pk_parent_a primary key (id)
|
||||
);
|
||||
|
||||
create table parent_b (
|
||||
id bigint generated by default as identity not null,
|
||||
child_id bigint,
|
||||
constraint pk_parent_b primary key (id)
|
||||
);
|
||||
|
||||
create table parent_person (
|
||||
identifier integer generated by default as identity not null,
|
||||
name varchar(255),
|
||||
@@ -3361,6 +3418,15 @@ create table person_cache_info (
|
||||
constraint pk_person_cache_info primary key (person_id)
|
||||
);
|
||||
|
||||
create table persona (
|
||||
id bigint generated by default as identity not null,
|
||||
persona varchar(255),
|
||||
person_oid bigint,
|
||||
version integer not null,
|
||||
constraint uq_persona_person_oid unique (person_oid),
|
||||
constraint pk_persona primary key (id)
|
||||
);
|
||||
|
||||
create table phones (
|
||||
id bigint generated by default as identity not null,
|
||||
phone_number varchar(7) not null,
|
||||
@@ -4574,6 +4640,18 @@ alter table la_attr_value_attribute add constraint fk_la_attr_value_attribute_at
|
||||
create index ix_looney_tune_id on looney (tune_id);
|
||||
alter table looney add constraint fk_looney_tune_id foreign key (tune_id) references tune (id) on delete restrict on update restrict;
|
||||
|
||||
create index ix_m2mcache_set1_m2_mcache_master on m2mcache_set1 (m2_mcache_master_id);
|
||||
alter table m2mcache_set1 add constraint fk_m2mcache_set1_m2_mcache_master foreign key (m2_mcache_master_id) references m2_mcache_master (id) on delete restrict on update restrict;
|
||||
|
||||
create index ix_m2mcache_set1_m2_mcache_child on m2mcache_set1 (m2_mcache_child_id);
|
||||
alter table m2mcache_set1 add constraint fk_m2mcache_set1_m2_mcache_child foreign key (m2_mcache_child_id) references m2_mcache_child (id) on delete restrict on update restrict;
|
||||
|
||||
create index ix_m2mcache_set2_m2_mcache_master on m2mcache_set2 (m2_mcache_master_id);
|
||||
alter table m2mcache_set2 add constraint fk_m2mcache_set2_m2_mcache_master foreign key (m2_mcache_master_id) references m2_mcache_master (id) on delete restrict on update restrict;
|
||||
|
||||
create index ix_m2mcache_set2_m2_mcache_child on m2mcache_set2 (m2_mcache_child_id);
|
||||
alter table m2mcache_set2 add constraint fk_m2mcache_set2_m2_mcache_child foreign key (m2_mcache_child_id) references m2_mcache_child (id) on delete restrict on update restrict;
|
||||
|
||||
create index ix_mcontact_customer_id on mcontact (customer_id);
|
||||
alter table mcontact add constraint fk_mcontact_customer_id foreign key (customer_id) references mcustomer (id) on delete restrict on update restrict;
|
||||
|
||||
@@ -4796,6 +4874,12 @@ alter table rawinherit_parent_rawinherit_data add constraint fk_rawinherit_paren
|
||||
create index ix_rawinherit_parent_rawinherit_data_rawinherit_data on rawinherit_parent_rawinherit_data (rawinherit_data_id);
|
||||
alter table rawinherit_parent_rawinherit_data add constraint fk_rawinherit_parent_rawinherit_data_rawinherit_data foreign key (rawinherit_data_id) references rawinherit_data (id) on delete restrict on update restrict;
|
||||
|
||||
create index ix_parent_a_child_id on parent_a (child_id);
|
||||
alter table parent_a add constraint fk_parent_a_child_id foreign key (child_id) references child_with_cache (id) on delete restrict on update restrict;
|
||||
|
||||
create index ix_parent_b_child_id on parent_b (child_id);
|
||||
alter table parent_b add constraint fk_parent_b_child_id foreign key (child_id) references child_with_cache (id) on delete restrict on update restrict;
|
||||
|
||||
create index ix_parent_person_some_bean_id on parent_person (some_bean_id);
|
||||
alter table parent_person add constraint fk_parent_person_some_bean_id foreign key (some_bean_id) references e_basic (id) on delete restrict on update restrict;
|
||||
|
||||
@@ -4829,6 +4913,8 @@ alter table person add constraint fk_person_default_address_oid foreign key (def
|
||||
create index ix_person_cache_email_person_info_person_id on person_cache_email (person_info_person_id);
|
||||
alter table person_cache_email add constraint fk_person_cache_email_person_info_person_id foreign key (person_info_person_id) references person_cache_info (person_id) on delete restrict on update restrict;
|
||||
|
||||
alter table persona add constraint fk_persona_person_oid foreign key (person_oid) references person (oid) on delete restrict on update restrict;
|
||||
|
||||
create index ix_phones_person_id on phones (person_id);
|
||||
alter table phones add constraint fk_phones_person_id foreign key (person_id) references persons (id) on delete restrict on update restrict;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- Generated by ebean unknown at 2020-12-07T09:40:50.461215Z
|
||||
-- Generated by ebean unknown at 2021-02-12T03:32:14.253435800Z
|
||||
alter table bar drop constraint if exists fk_bar_foo_id;
|
||||
drop index if exists ix_bar_foo_id;
|
||||
|
||||
@@ -417,6 +417,18 @@ drop index if exists ix_la_attr_value_attribute_attribute;
|
||||
alter table looney drop constraint if exists fk_looney_tune_id;
|
||||
drop index if exists ix_looney_tune_id;
|
||||
|
||||
alter table m2mcache_set1 drop constraint if exists fk_m2mcache_set1_m2_mcache_master;
|
||||
drop index if exists ix_m2mcache_set1_m2_mcache_master;
|
||||
|
||||
alter table m2mcache_set1 drop constraint if exists fk_m2mcache_set1_m2_mcache_child;
|
||||
drop index if exists ix_m2mcache_set1_m2_mcache_child;
|
||||
|
||||
alter table m2mcache_set2 drop constraint if exists fk_m2mcache_set2_m2_mcache_master;
|
||||
drop index if exists ix_m2mcache_set2_m2_mcache_master;
|
||||
|
||||
alter table m2mcache_set2 drop constraint if exists fk_m2mcache_set2_m2_mcache_child;
|
||||
drop index if exists ix_m2mcache_set2_m2_mcache_child;
|
||||
|
||||
alter table mcontact drop constraint if exists fk_mcontact_customer_id;
|
||||
drop index if exists ix_mcontact_customer_id;
|
||||
|
||||
@@ -639,6 +651,12 @@ drop index if exists ix_rawinherit_parent_rawinherit_data_rawinherit_parent;
|
||||
alter table rawinherit_parent_rawinherit_data drop constraint if exists fk_rawinherit_parent_rawinherit_data_rawinherit_data;
|
||||
drop index if exists ix_rawinherit_parent_rawinherit_data_rawinherit_data;
|
||||
|
||||
alter table parent_a drop constraint if exists fk_parent_a_child_id;
|
||||
drop index if exists ix_parent_a_child_id;
|
||||
|
||||
alter table parent_b drop constraint if exists fk_parent_b_child_id;
|
||||
drop index if exists ix_parent_b_child_id;
|
||||
|
||||
alter table parent_person drop constraint if exists fk_parent_person_some_bean_id;
|
||||
drop index if exists ix_parent_person_some_bean_id;
|
||||
|
||||
@@ -672,6 +690,8 @@ drop index if exists ix_person_default_address_oid;
|
||||
alter table person_cache_email drop constraint if exists fk_person_cache_email_person_info_person_id;
|
||||
drop index if exists ix_person_cache_email_person_info_person_id;
|
||||
|
||||
alter table persona drop constraint if exists fk_persona_person_oid;
|
||||
|
||||
alter table phones drop constraint if exists fk_phones_person_id;
|
||||
drop index if exists ix_phones_person_id;
|
||||
|
||||
@@ -970,6 +990,8 @@ drop table if exists e_save_test_d;
|
||||
|
||||
drop table if exists child_person;
|
||||
|
||||
drop table if exists child_with_cache;
|
||||
|
||||
drop table if exists cke_client;
|
||||
|
||||
drop table if exists cke_user;
|
||||
@@ -1131,6 +1153,8 @@ drop table if exists ebasic_json_node_varchar;
|
||||
|
||||
drop table if exists ebasic_json_unmapped;
|
||||
|
||||
drop table if exists e_basic_log;
|
||||
|
||||
drop table if exists e_basic_ndc;
|
||||
|
||||
drop table if exists ebasic_no_sdchild;
|
||||
@@ -1145,6 +1169,8 @@ drop table if exists e_basic_withlife;
|
||||
|
||||
drop table if exists e_basic_with_ex;
|
||||
|
||||
drop table if exists e_basic_withlog;
|
||||
|
||||
drop table if exists e_basicverucon;
|
||||
|
||||
drop table if exists ecache_child;
|
||||
@@ -1463,6 +1489,14 @@ drop table if exists la_attr_value_attribute;
|
||||
|
||||
drop table if exists looney;
|
||||
|
||||
drop table if exists m2_mcache_child;
|
||||
|
||||
drop table if exists m2_mcache_master;
|
||||
|
||||
drop table if exists m2mcache_set1;
|
||||
|
||||
drop table if exists m2mcache_set2;
|
||||
|
||||
drop table if exists maddress;
|
||||
|
||||
drop table if exists mcontact;
|
||||
@@ -1715,6 +1749,10 @@ drop table if exists rawinherit_parent_rawinherit_data;
|
||||
|
||||
drop table if exists e_save_test_c;
|
||||
|
||||
drop table if exists parent_a;
|
||||
|
||||
drop table if exists parent_b;
|
||||
|
||||
drop table if exists parent_person;
|
||||
|
||||
drop table if exists c_participation;
|
||||
@@ -1745,6 +1783,8 @@ drop table if exists person_cache_email;
|
||||
|
||||
drop table if exists person_cache_info;
|
||||
|
||||
drop table if exists persona;
|
||||
|
||||
drop table if exists phones;
|
||||
|
||||
drop table if exists e_position;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class TestManyOneInterface extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
IAddress a = new Address();
|
||||
IAddress a = new Address("hello");
|
||||
|
||||
IPerson p = new Person();
|
||||
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package org.tests.batchload;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.BeanState;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.EntityBeanIntercept;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class TestBeanState extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> custs = DB.find(Customer.class).findList();
|
||||
|
||||
Customer customer = DB.find(Customer.class).setId(custs.get(0).getId()).select("name")
|
||||
.setUseCache(false)
|
||||
.findOne();
|
||||
|
||||
BeanState beanState = DB.getBeanState(customer);
|
||||
assertFalse(beanState.isNew());
|
||||
assertFalse(beanState.isDirty());
|
||||
assertFalse(beanState.isNewOrDirty());
|
||||
assertNotNull(beanState.getLoadedProps());
|
||||
|
||||
customer.setName("dirtyNameProp");
|
||||
assertTrue(beanState.isDirty());
|
||||
assertThat(beanState.getChangedProps()).containsOnly("name");
|
||||
|
||||
EntityBeanIntercept ebi = ((EntityBean) customer)._ebean_getIntercept();
|
||||
boolean[] dirtyProperties = ebi.getDirtyProperties();
|
||||
for (int i = 0; i < dirtyProperties.length; i++) {
|
||||
if (dirtyProperties[i]) {
|
||||
String dirtyPropertyName = ebi.getProperty(i);
|
||||
assertEquals("name", dirtyPropertyName);
|
||||
}
|
||||
}
|
||||
|
||||
customer.setStatus(Customer.Status.INACTIVE);
|
||||
|
||||
assertTrue(beanState.isDirty());
|
||||
assertThat(beanState.getChangedProps()).containsOnly("name", "status");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDisableLazyLoad_expect_lazyLoadingDisabled() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> custs = DB.find(Customer.class).order("id").findList();
|
||||
|
||||
Customer customer = DB.find(Customer.class)
|
||||
.setId(custs.get(0).getId())
|
||||
.select("id")
|
||||
.setUseCache(false)
|
||||
.findOne();
|
||||
|
||||
BeanState beanState = DB.getBeanState(customer);
|
||||
beanState.setDisableLazyLoad(true);
|
||||
assertNull(customer.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getChangedProps_when_setManyProperty() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Customer customer = DB.find(Customer.class).order("id").setMaxRows(1).findOne();
|
||||
|
||||
BeanState beanState = DB.getBeanState(customer);
|
||||
assertThat(beanState.getChangedProps()).isEmpty();
|
||||
|
||||
customer.setContacts(new ArrayList<>());
|
||||
assertThat(beanState.getChangedProps()).containsOnly("contacts");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getChangedProps_when_setManyProperty_onNewBean() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
|
||||
BeanState beanState = DB.getBeanState(customer);
|
||||
assertThat(beanState.getChangedProps()).isEmpty();
|
||||
|
||||
// when new state, then loaded
|
||||
customer.setContacts(new ArrayList<>());
|
||||
assertThat(beanState.getChangedProps()).isEmpty();
|
||||
assertThat(beanState.getLoadedProps()).containsOnly("contacts");
|
||||
|
||||
// set loaded state, then marked as changed
|
||||
beanState.setLoaded();
|
||||
customer.setContacts(new ArrayList<>());
|
||||
assertThat(beanState.getLoadedProps()).containsOnly("contacts");
|
||||
assertThat(beanState.getChangedProps()).containsOnly("contacts");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void readOnly_when_setManyProperty() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setContacts(new ArrayList<>());
|
||||
|
||||
BeanState beanState = DB.getBeanState(customer);
|
||||
beanState.setLoaded();
|
||||
beanState.setReadOnly(true);
|
||||
|
||||
// act, try to mutate read only bean
|
||||
customer.setContacts(new ArrayList<>());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void readOnly_when_setProperty() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setName("a");
|
||||
|
||||
BeanState beanState = DB.getBeanState(customer);
|
||||
beanState.setLoaded();
|
||||
beanState.setReadOnly(true);
|
||||
|
||||
// act, try to mutate read only bean
|
||||
customer.setName("b");
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package org.tests.batchload;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.BeanState;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.EntityBeanIntercept;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestLoadOnDirty extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> custs = Ebean.find(Customer.class).findList();
|
||||
|
||||
Customer customer = Ebean.find(Customer.class).setId(custs.get(0).getId()).select("name")
|
||||
.setUseCache(false)
|
||||
.findOne();
|
||||
|
||||
BeanState beanState = Ebean.getBeanState(customer);
|
||||
Assert.assertTrue(!beanState.isNew());
|
||||
Assert.assertTrue(!beanState.isDirty());
|
||||
Assert.assertTrue(!beanState.isNewOrDirty());
|
||||
Assert.assertNotNull(beanState.getLoadedProps());
|
||||
|
||||
customer.setName("dirtyNameProp");
|
||||
Assert.assertTrue(beanState.isDirty());
|
||||
Assert.assertTrue(beanState.getChangedProps().contains("name"));
|
||||
Assert.assertEquals(1, beanState.getChangedProps().size());
|
||||
|
||||
EntityBeanIntercept ebi = ((EntityBean) customer)._ebean_getIntercept();
|
||||
boolean[] dirtyProperties = ebi.getDirtyProperties();
|
||||
for (int i = 0; i < dirtyProperties.length; i++) {
|
||||
if (dirtyProperties[i]) {
|
||||
String dirtyPropertyName = ebi.getProperty(i);
|
||||
Assert.assertEquals("name", dirtyPropertyName);
|
||||
}
|
||||
}
|
||||
|
||||
customer.setStatus(Customer.Status.INACTIVE);
|
||||
|
||||
Assert.assertTrue(beanState.isDirty());
|
||||
Assert.assertTrue(beanState.getChangedProps().contains("status"));
|
||||
Assert.assertTrue(beanState.getChangedProps().contains("name"));
|
||||
Assert.assertEquals(2, beanState.getChangedProps().size());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableLazyLoad() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> custs = Ebean.find(Customer.class).order("id").findList();
|
||||
|
||||
Customer customer = Ebean.find(Customer.class)
|
||||
.setId(custs.get(0).getId())
|
||||
.select("id")
|
||||
.setUseCache(false)
|
||||
.findOne();
|
||||
|
||||
BeanState beanState = Ebean.getBeanState(customer);
|
||||
beanState.setDisableLazyLoad(true);
|
||||
Assert.assertNull(customer.getName());
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,7 @@ public class TestDeleteO2MOrphans extends BaseTestCase {
|
||||
|
||||
// assert
|
||||
COOne check = findById(id);
|
||||
//FIXME #2127 #2141: assertThat(check.getChildren()).hasSize(2);
|
||||
assertThat(check.getChildren()).hasSize(4);
|
||||
assertThat(check.getChildren()).hasSize(2);
|
||||
DB.delete(check);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@ public class Address implements IAddress {
|
||||
|
||||
private String street;
|
||||
|
||||
public Address(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public long getOid() {
|
||||
return oid;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.tests.model.interfaces;
|
||||
|
||||
public interface IPersona {
|
||||
|
||||
String persona();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.tests.model.interfaces;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class Persona implements IPersona {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
private final String persona;
|
||||
|
||||
@OneToOne(orphanRemoval = true, fetch = FetchType.LAZY, targetEntity = Person.class)
|
||||
private IPerson person;
|
||||
|
||||
public Persona(String persona) {
|
||||
this.persona = persona;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String persona() {
|
||||
return persona;
|
||||
}
|
||||
|
||||
public void setPerson(IPerson person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
public IPerson getPerson() {
|
||||
return person;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.tests.model.interfaces;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class SelfManyMany {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
private final String name;
|
||||
|
||||
@ManyToMany
|
||||
// requires explicit @JoinTable
|
||||
@JoinTable(name = "self_many_bridge",
|
||||
joinColumns = @JoinColumn(name = "self_1_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "self_2_id"))
|
||||
private List<SelfManyMany> related;
|
||||
|
||||
public SelfManyMany(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<SelfManyMany> getRelated() {
|
||||
return related;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.tests.model.interfaces;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestSelfMany extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void self_manyToMany() {
|
||||
|
||||
SelfManyMany m = new SelfManyMany("1");
|
||||
DB.save(m);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.tests.model.interfaces;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestTargetEntity extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Person person = setup();
|
||||
|
||||
Persona persona = new Persona("junk");
|
||||
persona.setPerson(person);
|
||||
DB.save(persona);
|
||||
|
||||
Persona found = DB.find(Persona.class, persona.getId());
|
||||
assertThat(found).isNotNull();
|
||||
assertThat(found.persona()).isEqualTo("junk");
|
||||
assertThat(found.getPerson().getDefaultAddress().getStreet()).isEqualTo("street");
|
||||
|
||||
DB.delete(persona);
|
||||
DB.delete(person);
|
||||
DB.delete(person.getDefaultAddress());
|
||||
}
|
||||
|
||||
private Person setup() {
|
||||
Address address = new Address("street");
|
||||
DB.save(address);
|
||||
Person person = new Person();
|
||||
person.setDefaultAddress(address);
|
||||
DB.save(person);
|
||||
return person;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.tests.query;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.FutureList;
|
||||
import io.ebean.Transaction;
|
||||
import org.tests.model.basic.Order;
|
||||
@@ -22,17 +22,19 @@ public class TestQueryFindFutureList extends BaseTestCase {
|
||||
ResetBasicData.reset();
|
||||
|
||||
// warm the connection pool
|
||||
Transaction t0 = Ebean.getServer(null).createTransaction();
|
||||
Transaction t1 = Ebean.getServer(null).createTransaction();
|
||||
Transaction t2 = Ebean.getServer(null).createTransaction();
|
||||
Transaction t0 = DB.createTransaction();
|
||||
Transaction t1 = DB.createTransaction();
|
||||
Transaction t2 = DB.createTransaction();
|
||||
t0.end();
|
||||
t1.end();
|
||||
t2.end();
|
||||
|
||||
FutureList<Order> futureList = Ebean.find(Order.class).findFutureList();
|
||||
FutureList<Order> futureList = DB.find(Order.class).findFutureList();
|
||||
|
||||
Thread.sleep(10);
|
||||
futureList.cancel(true);
|
||||
// calling again is ignored
|
||||
futureList.cancel(true);
|
||||
|
||||
// don't shutdown immediately
|
||||
Thread.sleep(50);
|
||||
@@ -43,12 +45,12 @@ public class TestQueryFindFutureList extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
FutureList<Order> futureList = Ebean.find(Order.class).findFutureList();
|
||||
FutureList<Order> futureList = DB.find(Order.class).findFutureList();
|
||||
|
||||
// wait for it to complete
|
||||
List<Order> orders = futureList.getUnchecked();
|
||||
|
||||
assertEquals(Ebean.find(Order.class).findCount(), orders.size());
|
||||
assertEquals(DB.find(Order.class).findCount(), orders.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,12 +58,12 @@ public class TestQueryFindFutureList extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
FutureList<Order> futureList = Ebean.find(Order.class).findFutureList();
|
||||
FutureList<Order> futureList = DB.find(Order.class).findFutureList();
|
||||
|
||||
// wait for it to complete
|
||||
List<Order> orders = futureList.getUnchecked(1, TimeUnit.SECONDS);
|
||||
|
||||
assertEquals(Ebean.find(Order.class).findCount(), orders.size());
|
||||
assertEquals(DB.find(Order.class).findCount(), orders.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<name>ebean ddl generation</name>
|
||||
@@ -29,14 +29,14 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core-type</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<name>ebean external mapping api</name>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
<!-- <parent>-->
|
||||
<!-- <groupId>org.avaje</groupId>-->
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:git@github.com:ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-parent-12.6.6</tag>
|
||||
<tag>ebean-parent-12.6.7</tag>
|
||||
</scm>
|
||||
|
||||
<name>ebean external mapping xml</name>
|
||||
@@ -33,7 +33,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-externalmapping-api</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -59,14 +59,14 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-ddl-generator</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
<plugin>
|
||||
<groupId>io.repaint.maven</groupId>
|
||||
<artifactId>tiles-maven-plugin</artifactId>
|
||||
<version>2.18</version>
|
||||
<version>2.19</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<tiles>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<name>ebean postgis</name>
|
||||
@@ -24,7 +24,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-test</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
<plugin>
|
||||
<groupId>io.repaint.maven</groupId>
|
||||
<artifactId>tiles-maven-plugin</artifactId>
|
||||
<version>2.18</version>
|
||||
<version>2.19</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<tiles>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
<!-- <parent>-->
|
||||
<!-- <groupId>org.avaje</groupId>-->
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:git@github.com:ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-parent-12.6.6</tag>
|
||||
<tag>ebean-parent-12.6.7</tag>
|
||||
</scm>
|
||||
|
||||
<name>ebean querybean</name>
|
||||
@@ -27,7 +27,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -67,14 +67,14 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-ddl-generator</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>querybean-generator</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
<plugin>
|
||||
<groupId>io.repaint.maven</groupId>
|
||||
<artifactId>tiles-maven-plugin</artifactId>
|
||||
<version>2.18</version>
|
||||
<version>2.19</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<tiles>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.ebean.typequery;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks generated query bean source code.
|
||||
* <p>
|
||||
* This is code generated by the query bean generator (annotation processor).
|
||||
*/
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Generated {
|
||||
|
||||
/**
|
||||
* The name of the generator used to generate this source.
|
||||
*/
|
||||
String value();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.example.domain;
|
||||
|
||||
import org.example.domain.api.ACity;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class AreaImpl {
|
||||
|
||||
@Id
|
||||
long id;
|
||||
|
||||
@OneToMany(targetEntity = CityImpl.class, cascade = CascadeType.ALL)
|
||||
List<ACity> cities;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<ACity> getCities() {
|
||||
return cities;
|
||||
}
|
||||
|
||||
public void setCities(List<ACity> cities) {
|
||||
this.cities = cities;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.example.domain;
|
||||
|
||||
import io.ebean.Model;
|
||||
import io.ebean.annotation.CreatedTimestamp;
|
||||
import io.ebean.annotation.UpdatedTimestamp;
|
||||
import io.ebean.annotation.WhenCreated;
|
||||
import io.ebean.annotation.WhenModified;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
@@ -11,10 +11,10 @@ import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* Base domain object with Id, version, whenCreated and whenUpdated.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Extending Model to enable the 'active record' style.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* whenCreated and whenUpdated are generally useful for maintaining external search services (like
|
||||
* elasticsearch) and audit.
|
||||
@@ -28,10 +28,10 @@ public abstract class BaseModel extends Model {
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
@CreatedTimestamp
|
||||
@WhenCreated
|
||||
Timestamp whenCreated;
|
||||
|
||||
@UpdatedTimestamp
|
||||
@WhenModified
|
||||
Timestamp whenUpdated;
|
||||
|
||||
public Long getId() {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.example.domain;
|
||||
|
||||
import org.example.domain.api.ACity;
|
||||
import org.example.domain.api.ACountry;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class CityImpl implements ACity {
|
||||
|
||||
@Id
|
||||
long id;
|
||||
|
||||
String name;
|
||||
|
||||
@ManyToOne(targetEntity = CountryImpl.class)
|
||||
ACountry country;
|
||||
|
||||
@Override
|
||||
public long id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ACountry country() {
|
||||
return country;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,13 +2,10 @@ package org.example.domain;
|
||||
|
||||
import io.ebean.annotation.DbArray;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Contact entity bean.
|
||||
@@ -22,28 +19,32 @@ public class Contact extends BaseModel {
|
||||
|
||||
@Column(length=50)
|
||||
String firstName;
|
||||
|
||||
|
||||
@Column(length=50)
|
||||
String lastName;
|
||||
|
||||
|
||||
@Column(length=200)
|
||||
String email;
|
||||
|
||||
@Column(length=20)
|
||||
String phone;
|
||||
|
||||
|
||||
@ManyToOne(optional=false)
|
||||
Customer customer;
|
||||
|
||||
@OneToMany(mappedBy = "contact")
|
||||
List<ContactNote> notes;
|
||||
|
||||
@OneToMany(cascade = CascadeType.PERSIST)
|
||||
@MapKey(name="key")
|
||||
Map<String,ContactOther> others;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public Contact() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct with a firstName and lastName.
|
||||
*/
|
||||
@@ -51,7 +52,7 @@ public class Contact extends BaseModel {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.example.domain;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* Contact entity bean.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name="be_contact_other")
|
||||
public class ContactOther extends BaseModel {
|
||||
|
||||
String key;
|
||||
|
||||
int something;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public int getSomething() {
|
||||
return something;
|
||||
}
|
||||
|
||||
public void setSomething(int something) {
|
||||
this.something = something;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.example.domain;
|
||||
|
||||
import org.example.domain.api.ACountry;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class CountryImpl implements ACountry {
|
||||
|
||||
@Id
|
||||
String code;
|
||||
|
||||
@Override
|
||||
public String code() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.example.domain.api;
|
||||
|
||||
public interface ACity {
|
||||
|
||||
long id();
|
||||
|
||||
String name();
|
||||
|
||||
ACountry country();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.example.domain.api;
|
||||
|
||||
public interface ACountry {
|
||||
String code();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.querytest;
|
||||
|
||||
import org.example.domain.query.QContact;
|
||||
import org.junit.Test;
|
||||
|
||||
public class QContactTest {
|
||||
|
||||
@Test
|
||||
public void test_oneToManyMap() {
|
||||
|
||||
new QContact()
|
||||
.others.fetch()
|
||||
.findList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.querytest;
|
||||
|
||||
import org.example.domain.query.QAreaImpl;
|
||||
import org.example.domain.query.QCityImpl;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TargetTest {
|
||||
|
||||
@Test
|
||||
public void test_oneToMany() {
|
||||
|
||||
new QAreaImpl()
|
||||
.cities.fetch()
|
||||
.findList();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_manyToOne() {
|
||||
|
||||
new QCityImpl()
|
||||
.country.fetch()
|
||||
.findList();
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>ebean-redis</artifactId>
|
||||
@@ -22,35 +22,35 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-api</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-querybean</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>querybean-generator</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-test</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<plugin>
|
||||
<groupId>io.repaint.maven</groupId>
|
||||
<artifactId>tiles-maven-plugin</artifactId>
|
||||
<version>2.18</version>
|
||||
<version>2.19</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<tiles>
|
||||
|
||||
+5
-5
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
<!-- <parent>-->
|
||||
<!-- <groupId>org.avaje</groupId>-->
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:git@github.com:ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-parent-12.6.6</tag>
|
||||
<tag>ebean-parent-12.6.7</tag>
|
||||
</scm>
|
||||
|
||||
<name>ebean test</name>
|
||||
@@ -43,14 +43,14 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-ddl-generator</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -146,7 +146,7 @@
|
||||
<plugin>
|
||||
<groupId>io.repaint.maven</groupId>
|
||||
<artifactId>tiles-maven-plugin</artifactId>
|
||||
<version>2.18</version>
|
||||
<version>2.19</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<tiles>
|
||||
|
||||
+6
-6
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<name>ebean composite</name>
|
||||
@@ -22,34 +22,34 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-api</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Technically optional but most expected to use query beans -->
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-querybean</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<!-- In future ebean-ddl-generator would only be dependency of ebean-test -->
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-ddl-generator</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
<!-- In future this is optional and not included by default -->
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-autotune</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<name>kotlin querybean generator</name>
|
||||
@@ -29,7 +29,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-querybean</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-core</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-ddl-generator</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
+1
-4
@@ -3,11 +3,8 @@ package io.ebean.querybean.generator;
|
||||
interface Constants {
|
||||
|
||||
String AT_GENERATED = "@Generated(\"io.ebean.querybean.kotlin-generator\")";
|
||||
|
||||
String AT_TYPEQUERYBEAN = "@TypeQueryBean(\"v1\")";
|
||||
|
||||
String GENERATED_9 = "javax.annotation.processing.Generated";
|
||||
String GENERATED_8 = "javax.annotation.Generated";
|
||||
String GENERATED = "io.ebean.typequery.Generated";
|
||||
|
||||
String MAPPED_SUPERCLASS = "javax.persistence.MappedSuperclass";
|
||||
String INHERITANCE = "javax.persistence.Inheritance";
|
||||
|
||||
+26
-41
@@ -50,7 +50,6 @@ class ProcessingContext implements Constants {
|
||||
private final Filer filer;
|
||||
private final Messager messager;
|
||||
private final Elements elementUtils;
|
||||
private final String generatedAnnotation;
|
||||
|
||||
private final PropertyTypeMap propertyTypeMap = new PropertyTypeMap();
|
||||
|
||||
@@ -99,9 +98,6 @@ class ProcessingContext implements Constants {
|
||||
this.filer = processingEnv.getFiler();
|
||||
this.messager = processingEnv.getMessager();
|
||||
this.elementUtils = processingEnv.getElementUtils();
|
||||
|
||||
boolean jdk8 = processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_8) <= 0;
|
||||
this.generatedAnnotation = generatedAnnotation(jdk8);
|
||||
this.generatedSources = initGeneratedSources(processingEnv);
|
||||
this.readModuleInfo = new ReadModuleInfo(this);
|
||||
}
|
||||
@@ -122,13 +118,6 @@ class ProcessingContext implements Constants {
|
||||
return elementUtils.getTypeElement(EBEAN_COMPONENT);
|
||||
}
|
||||
|
||||
private String generatedAnnotation(boolean jdk8) {
|
||||
if (jdk8) {
|
||||
return isTypeAvailable(GENERATED_8) ? GENERATED_8 : null;
|
||||
}
|
||||
return isTypeAvailable(GENERATED_9) ? GENERATED_9 : null;
|
||||
}
|
||||
|
||||
private String initGeneratedSources(ProcessingEnvironment processingEnv) {
|
||||
String generatedDir = processingEnv.getOptions().get("kapt.kotlin.generated");
|
||||
return (generatedDir != null) ? generatedDir : "target/generated-sources/kapt/compile";
|
||||
@@ -303,47 +292,51 @@ class ProcessingContext implements Constants {
|
||||
return new PropertyTypeEnum(fullType, Split.shortName(fullType));
|
||||
}
|
||||
|
||||
// look for targetEntity annotation attribute
|
||||
final String targetEntity = readTargetEntity(field);
|
||||
if (targetEntity != null) {
|
||||
final TypeElement element = elementUtils.getTypeElement(targetEntity);
|
||||
if (isEntityOrEmbedded(element)) {
|
||||
return createPropertyTypeAssoc(typeDef(element.asType()));
|
||||
}
|
||||
}
|
||||
if (isEntityOrEmbedded(fieldType)) {
|
||||
// public QAssocContact<QCustomer> contacts;
|
||||
return createPropertyTypeAssoc(typeDef(typeMirror));
|
||||
}
|
||||
|
||||
PropertyType result = null;
|
||||
if (typeMirror.getKind() == TypeKind.DECLARED) {
|
||||
DeclaredType declaredType = (DeclaredType) typeMirror;
|
||||
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
|
||||
if (typeArguments.size() == 1) {
|
||||
TypeMirror argType = typeArguments.get(0);
|
||||
if (argType.getKind() == TypeKind.WILDCARD) {
|
||||
argType = ((WildcardType) argType).getExtendsBound();
|
||||
}
|
||||
Element argElement = typeUtils.asElement(argType);
|
||||
Element argElement = asElement(argType);
|
||||
if (isEntityOrEmbedded(argElement)) {
|
||||
result = createPropertyTypeAssoc(typeDef(argElement.asType()));
|
||||
} else {
|
||||
// look for targetEntity annotation attribute
|
||||
final String targetEntity = readTargetEntity(field);
|
||||
if (targetEntity != null) {
|
||||
final TypeElement element = elementUtils.getTypeElement(targetEntity);
|
||||
if (isEntityOrEmbedded(element)) {
|
||||
result = createPropertyTypeAssoc(typeDef(element.asType()));
|
||||
}
|
||||
}
|
||||
return createPropertyTypeAssoc(typeDef(argElement.asType()));
|
||||
}
|
||||
} else if (typeArguments.size() == 2) {
|
||||
TypeMirror argType = typeArguments.get(1);
|
||||
Element argElement = asElement(argType);
|
||||
if (isEntityOrEmbedded(argElement)) {
|
||||
return createPropertyTypeAssoc(typeDef(argElement.asType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
return result;
|
||||
if (typeInstanceOf(typeMirror, "java.lang.Comparable")) {
|
||||
return new PropertyTypeScalarComparable(typeMirror.toString());
|
||||
} else {
|
||||
if (typeInstanceOf(typeMirror, "java.lang.Comparable")) {
|
||||
return new PropertyTypeScalarComparable(typeMirror.toString());
|
||||
} else {
|
||||
return new PropertyTypeScalar(typeMirror.toString());
|
||||
}
|
||||
return new PropertyTypeScalar(typeMirror.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private Element asElement(TypeMirror argType) {
|
||||
if (argType.getKind() == TypeKind.WILDCARD) {
|
||||
argType = ((WildcardType) argType).getExtendsBound();
|
||||
}
|
||||
return typeUtils.asElement(argType);
|
||||
}
|
||||
|
||||
private boolean typeInstanceOf(final TypeMirror typeMirror, final CharSequence desiredInterface) {
|
||||
TypeElement typeElement = (TypeElement) typeUtils.asElement(typeMirror);
|
||||
if (typeElement == null || typeElement.getQualifiedName().contentEquals("java.lang.Object")) {
|
||||
@@ -426,14 +419,6 @@ class ProcessingContext implements Constants {
|
||||
messager.printMessage(Diagnostic.Kind.NOTE, String.format(msg, args));
|
||||
}
|
||||
|
||||
boolean isGeneratedAvailable() {
|
||||
return generatedAnnotation != null;
|
||||
}
|
||||
|
||||
String getGeneratedAnnotation() {
|
||||
return generatedAnnotation;
|
||||
}
|
||||
|
||||
void readModuleInfo() {
|
||||
String factory = loadMetaInfServices();
|
||||
if (factory != null) {
|
||||
|
||||
+2
-7
@@ -90,10 +90,7 @@ class SimpleModuleInfoWriter {
|
||||
writer.append("import java.util.ArrayList;").eol();
|
||||
writer.append("import java.util.Collections;").eol();
|
||||
writer.append("import java.util.List;").eol();
|
||||
final String generated = processingContext.getGeneratedAnnotation();
|
||||
if (generated != null) {
|
||||
writer.append("import %s;", generated).eol();
|
||||
}
|
||||
writer.append("import %s;", Constants.GENERATED).eol();
|
||||
writer.eol();
|
||||
writer.append("import io.ebean.config.ModuleInfo;").eol();
|
||||
writer.append("import io.ebean.config.ModuleInfoLoader;").eol();
|
||||
@@ -102,9 +99,7 @@ class SimpleModuleInfoWriter {
|
||||
}
|
||||
|
||||
void buildAtContextModule(Append writer) {
|
||||
if (processingContext.isGeneratedAvailable()) {
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
}
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
writer.append("@ModuleInfo(");
|
||||
if (processingContext.hasOtherClasses()) {
|
||||
writer.append("other={%s}, ", otherClasses());
|
||||
|
||||
+3
-11
@@ -88,11 +88,7 @@ class SimpleQueryBeanWriter {
|
||||
}
|
||||
|
||||
private void gatherPropertyDetails() {
|
||||
|
||||
final String generated = processingContext.getGeneratedAnnotation();
|
||||
if (generated != null) {
|
||||
importTypes.add(generated);
|
||||
}
|
||||
importTypes.add(Constants.GENERATED);
|
||||
importTypes.add(beanFullName);
|
||||
importTypes.add(Constants.TQROOTBEAN);
|
||||
importTypes.add(Constants.TYPEQUERYBEAN);
|
||||
@@ -282,9 +278,7 @@ class SimpleQueryBeanWriter {
|
||||
writer.append(" * ").eol();
|
||||
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
||||
writer.append(" */").eol();
|
||||
if (processingContext.isGeneratedAvailable()) {
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
}
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
writer.append(Constants.AT_TYPEQUERYBEAN).eol();
|
||||
lang().beginAssocClass(writer, shortName, origShortName);
|
||||
|
||||
@@ -294,9 +288,7 @@ class SimpleQueryBeanWriter {
|
||||
writer.append(" * ").eol();
|
||||
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
||||
writer.append(" */").eol();
|
||||
if (processingContext.isGeneratedAvailable()) {
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
}
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
writer.append(Constants.AT_TYPEQUERYBEAN).eol();
|
||||
lang().beginClass(writer, shortName);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>ebean parent</name>
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:git@github.com:ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-parent-12.6.6</tag>
|
||||
<tag>ebean-parent-12.6.7</tag>
|
||||
</scm>
|
||||
|
||||
<licenses>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<artifactId>ebean-parent</artifactId>
|
||||
<groupId>io.ebean</groupId>
|
||||
<version>12.6.6</version>
|
||||
<version>12.6.7</version>
|
||||
</parent>
|
||||
|
||||
<name>querybean generator</name>
|
||||
|
||||
@@ -5,9 +5,7 @@ interface Constants {
|
||||
String AT_GENERATED = "@Generated(\"io.ebean.querybean.generator\")";
|
||||
|
||||
String AT_TYPEQUERYBEAN = "@TypeQueryBean(\"v1\")";
|
||||
|
||||
String GENERATED_9 = "javax.annotation.processing.Generated";
|
||||
String GENERATED_8 = "javax.annotation.Generated";
|
||||
String GENERATED = "io.ebean.typequery.Generated";
|
||||
|
||||
String MAPPED_SUPERCLASS = "javax.persistence.MappedSuperclass";
|
||||
String INHERITANCE = "javax.persistence.Inheritance";
|
||||
@@ -35,4 +33,4 @@ interface Constants {
|
||||
String METAINF_MANIFEST = "META-INF/ebean-generated-info.mf";
|
||||
String METAINF_SERVICES_MODULELOADER = "META-INF/services/io.ebean.config.ModuleInfoLoader";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+14
-32
@@ -46,7 +46,6 @@ class ProcessingContext implements Constants {
|
||||
private final Filer filer;
|
||||
private final Messager messager;
|
||||
private final Elements elementUtils;
|
||||
private final String generatedAnnotation;
|
||||
|
||||
private final PropertyTypeMap propertyTypeMap = new PropertyTypeMap();
|
||||
|
||||
@@ -95,9 +94,6 @@ class ProcessingContext implements Constants {
|
||||
this.filer = processingEnv.getFiler();
|
||||
this.messager = processingEnv.getMessager();
|
||||
this.elementUtils = processingEnv.getElementUtils();
|
||||
|
||||
boolean jdk8 = processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_8) <= 0;
|
||||
this.generatedAnnotation = generatedAnnotation(jdk8);
|
||||
this.readModuleInfo = new ReadModuleInfo(this);
|
||||
}
|
||||
|
||||
@@ -117,17 +113,6 @@ class ProcessingContext implements Constants {
|
||||
return elementUtils.getTypeElement(EBEAN_COMPONENT);
|
||||
}
|
||||
|
||||
private String generatedAnnotation(boolean jdk8) {
|
||||
if (jdk8) {
|
||||
return isTypeAvailable(GENERATED_8) ? GENERATED_8 : null;
|
||||
}
|
||||
return isTypeAvailable(GENERATED_9) ? GENERATED_9 : null;
|
||||
}
|
||||
|
||||
private boolean isTypeAvailable(String canonicalName) {
|
||||
return null != elementUtils.getTypeElement(canonicalName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather all the fields (properties) for the given bean element.
|
||||
*/
|
||||
@@ -286,6 +271,15 @@ class ProcessingContext implements Constants {
|
||||
return new PropertyTypeEnum(fullType, Split.shortName(fullType));
|
||||
}
|
||||
|
||||
// look for targetEntity annotation attribute
|
||||
final String targetEntity = readTargetEntity(field);
|
||||
if (targetEntity != null) {
|
||||
final TypeElement element = elementUtils.getTypeElement(targetEntity);
|
||||
if (isEntityOrEmbedded(element)) {
|
||||
return createPropertyTypeAssoc(typeDef(element.asType()));
|
||||
}
|
||||
}
|
||||
|
||||
if (isEntityOrEmbedded(fieldType)) {
|
||||
// public QAssocContact<QCustomer> contacts;
|
||||
return createPropertyTypeAssoc(typeDef(typeMirror));
|
||||
@@ -331,15 +325,11 @@ class ProcessingContext implements Constants {
|
||||
Element argElement = typeUtils.asElement(typeArguments.get(0));
|
||||
if (isEntityOrEmbedded(argElement)) {
|
||||
return createPropertyTypeAssoc(typeDef(argElement.asType()));
|
||||
} else {
|
||||
// look for targetEntity annotation attribute
|
||||
final String targetEntity = readTargetEntity(field);
|
||||
if (targetEntity != null) {
|
||||
final TypeElement element = elementUtils.getTypeElement(targetEntity);
|
||||
if (isEntityOrEmbedded(element)) {
|
||||
return createPropertyTypeAssoc(typeDef(element.asType()));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (typeArguments.size() == 2) {
|
||||
Element argElement = typeUtils.asElement(typeArguments.get(1));
|
||||
if (isEntityOrEmbedded(argElement)) {
|
||||
return createPropertyTypeAssoc(typeDef(argElement.asType()));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -408,14 +398,6 @@ class ProcessingContext implements Constants {
|
||||
messager.printMessage(Diagnostic.Kind.NOTE, String.format(msg, args));
|
||||
}
|
||||
|
||||
boolean isGeneratedAvailable() {
|
||||
return generatedAnnotation != null;
|
||||
}
|
||||
|
||||
String getGeneratedAnnotation() {
|
||||
return generatedAnnotation;
|
||||
}
|
||||
|
||||
void readModuleInfo() {
|
||||
String factory = loadMetaInfServices();
|
||||
if (factory != null) {
|
||||
|
||||
+2
-7
@@ -89,10 +89,7 @@ class SimpleModuleInfoWriter {
|
||||
writer.append("import java.util.ArrayList;").eol();
|
||||
writer.append("import java.util.Collections;").eol();
|
||||
writer.append("import java.util.List;").eol();
|
||||
final String generated = processingContext.getGeneratedAnnotation();
|
||||
if (generated != null) {
|
||||
writer.append("import %s;", generated).eol();
|
||||
}
|
||||
writer.append("import %s;", Constants.GENERATED).eol();
|
||||
writer.eol();
|
||||
writer.append("import io.ebean.config.ModuleInfo;").eol();
|
||||
writer.append("import io.ebean.config.ModuleInfoLoader;").eol();
|
||||
@@ -100,9 +97,7 @@ class SimpleModuleInfoWriter {
|
||||
}
|
||||
|
||||
void buildAtContextModule(Append writer) {
|
||||
if (processingContext.isGeneratedAvailable()) {
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
}
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
writer.append("@ModuleInfo(");
|
||||
if (processingContext.hasOtherClasses()) {
|
||||
writer.append("other={%s}, ", otherClasses());
|
||||
|
||||
+3
-10
@@ -62,10 +62,7 @@ class SimpleQueryBeanWriter {
|
||||
}
|
||||
|
||||
private void gatherPropertyDetails() {
|
||||
final String generated = processingContext.getGeneratedAnnotation();
|
||||
if (generated != null) {
|
||||
importTypes.add(generated);
|
||||
}
|
||||
importTypes.add(Constants.GENERATED);
|
||||
importTypes.add(beanFullName);
|
||||
importTypes.add(Constants.TQROOTBEAN);
|
||||
importTypes.add(Constants.TYPEQUERYBEAN);
|
||||
@@ -301,9 +298,7 @@ class SimpleQueryBeanWriter {
|
||||
writer.append(" * ").eol();
|
||||
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
||||
writer.append(" */").eol();
|
||||
if (processingContext.isGeneratedAvailable()) {
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
}
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
writer.append(Constants.AT_TYPEQUERYBEAN).eol();
|
||||
writer.append("public class Q%s<R> extends TQAssocBean<%s,R> {", shortName, origShortName).eol();
|
||||
|
||||
@@ -313,9 +308,7 @@ class SimpleQueryBeanWriter {
|
||||
writer.append(" * ").eol();
|
||||
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
||||
writer.append(" */").eol();
|
||||
if (processingContext.isGeneratedAvailable()) {
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
}
|
||||
writer.append(Constants.AT_GENERATED).eol();
|
||||
writer.append(Constants.AT_TYPEQUERYBEAN).eol();
|
||||
writer.append("public class Q%s extends TQRootBean<%1$s,Q%1$s> {", shortName).eol();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user