diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java
index eb5238417..0f29201cc 100644
--- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java
+++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java
@@ -1238,7 +1238,6 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
if (ids != null) {
return !ids.isEmpty();
}
-
try {
request.initTransIfRequired();
return !request.findIds().isEmpty();
diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java
index 718df243c..f314e868a 100644
--- a/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java
+++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java
@@ -572,7 +572,7 @@ public final class OrmQueryRequest extends BeanRequest implements SpiOrmQuery
private ElPropertyValue mapProperty() {
ElPropertyValue property = beanDescriptor.elGetValue(query.getMapKey());
if (property == null) {
- throw new IllegalStateException("Unknown map key property "+query.getMapKey());
+ throw new IllegalStateException("Unknown map key property " + query.getMapKey());
}
return property;
}
diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java
index 4ce4bd6c5..eee73e4c0 100644
--- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java
+++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java
@@ -349,10 +349,10 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
builder = RawSqlBuilder.unparsed(sql.getQuery());
}
- for (Map.Entry columnMapping : sql.getColumnMapping().entrySet()) {
+ for (Map.Entry columnMapping : sql.getColumnMapping().entrySet()) {
builder.columnMapping(columnMapping.getKey(), columnMapping.getValue());
}
- for (Map.Entry aliasMapping : sql.getAliasMapping().entrySet()) {
+ for (Map.Entry aliasMapping : sql.getAliasMapping().entrySet()) {
builder.tableAliasMapping(aliasMapping.getKey(), aliasMapping.getValue());
}
info.addRawSql(sql.getName(), builder.create());
@@ -410,7 +410,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
@Override
public boolean isTableManaged(String tableName) {
return tableToDescMap.get(tableName.toLowerCase()) != null
- || tableToViewDescMap.get(tableName.toLowerCase()) != null;
+ || tableToViewDescMap.get(tableName.toLowerCase()) != null;
}
/**
@@ -618,7 +618,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
DeployBeanInfo> info = createDeployBeanInfo(entityClass);
deployInfoMap.put(entityClass, info);
Class> embeddedIdType = info.getEmbeddedIdType();
- if (embeddedIdType != null){
+ if (embeddedIdType != null) {
embeddedIdTypes.add(embeddedIdType);
}
}
@@ -788,8 +788,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
Class> targetType = prop.getTargetType();
DeployBeanInfo> info = deployInfoMap.get(targetType);
if (info == null) {
- String msg = "Can not find descriptor [" + targetType + "] for " + prop.getFullBeanName();
- throw new PersistenceException(msg);
+ throw new PersistenceException("Can not find descriptor [" + targetType + "] for " + prop.getFullBeanName());
}
return info.getDescriptor();
}
@@ -901,21 +900,17 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
Class> owningType = oneToMany.getOwningType();
if (!oneToMany.getCascadeInfo().isSave()) {
// The property MUST have persist cascading so that inserts work.
-
Class> targetType = oneToMany.getTargetType();
String msg = "Error on " + oneToMany.getFullBeanName() + ". @OneToMany MUST have ";
msg += "Cascade.PERSIST or Cascade.ALL because this is a unidirectional ";
msg += "relationship. That is, there is no property of type " + owningType + " on " + targetType;
-
throw new PersistenceException(msg);
}
// mark this property as unidirectional
oneToMany.setUnidirectional();
-
// specify table and table alias...
BeanTable beanTable = beanTable(owningType);
-
// define the TableJoin
DeployTableJoin oneToManyJoin = oneToMany.getTableJoin();
if (!oneToManyJoin.hasJoinColumns()) {
@@ -951,27 +946,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
String mappedBy = prop.getMappedBy();
// get the mappedBy property
DeployBeanDescriptor> targetDesc = targetDescriptor(prop);
- DeployBeanProperty mappedProp = targetDesc.getBeanProperty(mappedBy);
- if (mappedProp == null) {
- String m = "Error on " + prop.getFullBeanName();
- m += " Can not find mappedBy property [" + targetDesc + "." + mappedBy + "] ";
- throw new PersistenceException(m);
- }
-
- if (!(mappedProp instanceof DeployBeanPropertyAssocOne>)) {
- String m = "Error on " + prop.getFullBeanName();
- m += ". mappedBy property [" + targetDesc + "." + mappedBy + "]is not a OneToOne?";
- throw new PersistenceException(m);
- }
-
- DeployBeanPropertyAssocOne> mappedAssocOne = (DeployBeanPropertyAssocOne>) mappedProp;
-
- if (!mappedAssocOne.isOneToOne()) {
- String m = "Error on " + prop.getFullBeanName();
- m += ". mappedBy property [" + targetDesc + "." + mappedBy + "]is not a OneToOne?";
- throw new PersistenceException(m);
- }
-
+ DeployBeanPropertyAssocOne> mappedAssocOne = mappedOneToOne(prop, mappedBy, targetDesc);
DeployTableJoin tableJoin = prop.getTableJoin();
if (!tableJoin.hasJoinColumns()) {
// define Join as the inverse of the mappedBy property
@@ -987,6 +962,21 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
}
}
+ private DeployBeanPropertyAssocOne> mappedOneToOne(DeployBeanPropertyAssocOne> prop, String mappedBy, DeployBeanDescriptor> targetDesc) {
+ DeployBeanProperty mappedProp = targetDesc.getBeanProperty(mappedBy);
+ if (mappedProp == null) {
+ throw new PersistenceException("Error on " + prop.getFullBeanName() + " Can not find mappedBy property [" + targetDesc + "." + mappedBy + "]");
+ }
+ if (!(mappedProp instanceof DeployBeanPropertyAssocOne>)) {
+ throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property [" + targetDesc + "." + mappedBy + "]is not a OneToOne?");
+ }
+ DeployBeanPropertyAssocOne> mappedAssocOne = (DeployBeanPropertyAssocOne>) mappedProp;
+ if (!mappedAssocOne.isOneToOne()) {
+ throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property [" + targetDesc + "." + mappedBy + "]is not a OneToOne?");
+ }
+ return mappedAssocOne;
+ }
+
private void checkUniDirectionalPrimaryKeyJoin(DeployBeanPropertyAssocOne> prop) {
if (prop.isPrimaryKeyJoin()) {
// uni-directional PrimaryKeyJoin ...
@@ -1008,7 +998,6 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
return;
}
DeployBeanDescriptor> targetDesc = targetDescriptor(prop);
-
if (targetDesc.isDraftableElement()) {
// automatically turning on orphan removal and CascadeType.ALL
prop.setModifyListenMode(BeanCollection.ModifyListenMode.REMOVALS);
@@ -1040,23 +1029,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
String mappedBy = prop.getMappedBy();
// get the mappedBy property
- DeployBeanProperty mappedProp = targetDesc.getBeanProperty(mappedBy);
- if (mappedProp == null) {
- String m = "Error on " + prop.getFullBeanName();
- m += " Can not find mappedBy property [" + mappedBy + "] ";
- m += "in [" + targetDesc + "]";
- throw new PersistenceException(m);
- }
-
- if (!(mappedProp instanceof DeployBeanPropertyAssocOne>)) {
- String m = "Error on " + prop.getFullBeanName();
- m += ". mappedBy property [" + mappedBy + "]is not a ManyToOne?";
- m += "in [" + targetDesc + "]";
- throw new PersistenceException(m);
- }
-
- DeployBeanPropertyAssocOne> mappedAssocOne = (DeployBeanPropertyAssocOne>) mappedProp;
-
+ DeployBeanPropertyAssocOne> mappedAssocOne = mappedManyToOne(prop, targetDesc, mappedBy);
DeployTableJoin tableJoin = prop.getTableJoin();
if (!tableJoin.hasJoinColumns()) {
// define Join as the inverse of the mappedBy property
@@ -1079,6 +1052,17 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
}
}
+ private DeployBeanPropertyAssocOne> mappedManyToOne(DeployBeanPropertyAssocMany> prop, DeployBeanDescriptor> targetDesc, String mappedBy) {
+ DeployBeanProperty mappedProp = targetDesc.getBeanProperty(mappedBy);
+ if (mappedProp == null) {
+ throw new PersistenceException("Error on " + prop.getFullBeanName() + " Can not find mappedBy property [" + mappedBy + "] " + "in [" + targetDesc + "]");
+ }
+ if (!(mappedProp instanceof DeployBeanPropertyAssocOne>)) {
+ throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property [" + mappedBy + "]is not a ManyToOne?" + "in [" + targetDesc + "]");
+ }
+ return (DeployBeanPropertyAssocOne>) mappedProp;
+ }
+
/**
* For mappedBy copy the joins from the other side.
*/
@@ -1094,33 +1078,10 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
// get the mappedBy property
DeployBeanDescriptor> targetDesc = targetDescriptor(prop);
- DeployBeanProperty mappedProp = targetDesc.getBeanProperty(mappedBy);
-
- if (mappedProp == null) {
- String m = "Error on " + prop.getFullBeanName();
- m += " Can not find mappedBy property [" + mappedBy + "] ";
- m += "in [" + targetDesc + "]";
- throw new PersistenceException(m);
- }
-
- if (!(mappedProp instanceof DeployBeanPropertyAssocMany>)) {
- String m = "Error on " + prop.getFullBeanName();
- m += ". mappedBy property [" + targetDesc + "." + mappedBy + "] is not a ManyToMany?";
- throw new PersistenceException(m);
- }
-
- DeployBeanPropertyAssocMany> mappedAssocMany = (DeployBeanPropertyAssocMany>) mappedProp;
-
- if (!mappedAssocMany.isManyToMany()) {
- String m = "Error on " + prop.getFullBeanName();
- m += ". mappedBy property [" + targetDesc + "." + mappedBy + "] is not a ManyToMany?";
- throw new PersistenceException(m);
- }
+ DeployBeanPropertyAssocMany> mappedAssocMany = mappedManyToMany(prop, mappedBy, targetDesc);
// define the relationships/joins on this side as the
// reverse of the other mappedBy side ...
-
- // DeployTableJoin mappedJoin = mappedAssocMany.getTableJoin();
DeployTableJoin mappedIntJoin = mappedAssocMany.getIntersectionJoin();
DeployTableJoin mappendInverseJoin = mappedAssocMany.getInverseJoin();
@@ -1142,6 +1103,22 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
}
}
+ private DeployBeanPropertyAssocMany> mappedManyToMany(DeployBeanPropertyAssocMany> prop, String mappedBy, DeployBeanDescriptor> targetDesc) {
+ DeployBeanProperty mappedProp = targetDesc.getBeanProperty(mappedBy);
+ if (mappedProp == null) {
+ throw new PersistenceException("Error on " + prop.getFullBeanName() + " Can not find mappedBy property [" + mappedBy + "] " + "in [" + targetDesc + "]");
+ }
+ if (!(mappedProp instanceof DeployBeanPropertyAssocMany>)) {
+ throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property [" + targetDesc + "." + mappedBy + "] is not a ManyToMany?");
+ }
+
+ DeployBeanPropertyAssocMany> mappedAssocMany = (DeployBeanPropertyAssocMany>) mappedProp;
+ if (!mappedAssocMany.isManyToMany()) {
+ throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property [" + targetDesc + "." + mappedBy + "] is not a ManyToMany?");
+ }
+ return mappedAssocMany;
+ }
+
private void setBeanControllerFinderListener(DeployBeanDescriptor descriptor) {
persistControllerManager.addPersistControllers(descriptor);
postLoadManager.addPostLoad(descriptor);
diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/grammer/EqlWhereListener.java b/ebean-core/src/main/java/io/ebeaninternal/server/grammer/EqlWhereListener.java
index f66677a64..683bf1421 100644
--- a/ebean-core/src/main/java/io/ebeaninternal/server/grammer/EqlWhereListener.java
+++ b/ebean-core/src/main/java/io/ebeaninternal/server/grammer/EqlWhereListener.java
@@ -136,7 +136,7 @@ abstract class EqlWhereListener extends EQLBaseListener {
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "rawtypes"})
private List
*/
private int delete(PersistRequestBean> request) {
-
DeleteUnloadedForeignKeys unloadedForeignKeys = null;
-
if (request.isPersistCascade()) {
// delete children first ... register the
// bean to handle bi-directional cascading
@@ -879,16 +818,13 @@ public final class DefaultPersister implements Persister {
int count = request.executeOrQueue();
request.removeFromPersistenceContext();
-
if (request.isPersistCascade()) {
deleteAssocOne(request);
-
if (unloadedForeignKeys != null) {
unloadedForeignKeys.deleteCascade();
}
}
request.complete();
-
// return true if using JDBC batch (as we can't tell until the batch is flushed)
return count;
}
@@ -901,11 +837,9 @@ public final class DefaultPersister implements Persister {
*
*/
private void saveAssocMany(PersistRequestBean> request) {
-
EntityBean parentBean = request.entityBean();
BeanDescriptor> desc = request.descriptor();
SpiTransaction t = request.transaction();
-
EntityBean orphanForRemoval = request.importedOrphanForRemoval();
if (orphanForRemoval != null) {
delete(orphanForRemoval, request.transaction(), true);
@@ -972,7 +906,6 @@ public final class DefaultPersister implements Persister {
*
*/
private void deleteAssocMany(PersistRequestBean> request) {
-
SpiTransaction t = request.transaction();
t.depth(-1);
@@ -1014,7 +947,6 @@ public final class DefaultPersister implements Persister {
deleteManyIntersection(parentBean, many, t, request.isPublish(), false);
}
} else {
-
if (ModifyListenMode.REMOVALS == many.modifyListenMode()) {
// PrivateOwned ...
// if soft delete then check target also supports soft delete
@@ -1023,7 +955,6 @@ public final class DefaultPersister implements Persister {
if (details instanceof BeanCollection>) {
Set> modifyRemovals = ((BeanCollection>) details).getModifyRemovals();
if (modifyRemovals != null && !modifyRemovals.isEmpty()) {
-
// delete the orphans that have been removed from the collection
for (Object detail : modifyRemovals) {
EntityBean detailBean = (EntityBean) detail;
@@ -1035,11 +966,9 @@ public final class DefaultPersister implements Persister {
}
}
}
-
deleteManyDetails(t, desc, parentBean, many, null, deleteMode);
}
}
-
// restore the depth
t.depth(+1);
}
@@ -1054,7 +983,6 @@ public final class DefaultPersister implements Persister {
*/
void deleteManyDetails(SpiTransaction t, BeanDescriptor> desc, EntityBean parentBean,
BeanPropertyAssocMany> many, List excludeDetailIds, DeleteMode deleteMode) {
-
if (many.cascadeInfo().isDelete()) {
// cascade delete the beans in the collection
BeanDescriptor> targetDesc = many.targetDescriptor();
@@ -1083,7 +1011,6 @@ public final class DefaultPersister implements Persister {
* Will use delete by object if the child entity has manyToMany relationships.
*/
private void deleteChildrenById(SpiTransaction t, BeanDescriptor> targetDesc, List childIds, DeleteMode deleteMode) {
-
if (!targetDesc.isDeleteByBulk()) {
// convert into a list of reference objects and perform delete by object
List refList = new ArrayList<>(childIds.size());
@@ -1091,7 +1018,6 @@ public final class DefaultPersister implements Persister {
refList.add(targetDesc.createReference(id, null));
}
deleteList(refList, t, deleteMode, true);
-
} else {
// perform delete by statement if possible
delete(targetDesc, null, childIds, t, deleteMode);
@@ -1102,16 +1028,13 @@ public final class DefaultPersister implements Persister {
* Save any associated one beans.
*/
private void saveAssocOne(PersistRequestBean> request) {
-
BeanDescriptor> desc = request.descriptor();
-
// imported ones with save cascade
for (BeanPropertyAssocOne> prop : desc.propertiesOneImportedSave()) {
// check for partial objects
if (prop.isOrphanRemoval() && request.isDirtyProperty(prop)) {
request.setImportedOrphanForRemoval(prop);
}
-
if (request.isLoadedProperty(prop)) {
EntityBean detailBean = prop.getValueAsEntityBean(request.entityBean());
if (detailBean != null
@@ -1125,7 +1048,6 @@ public final class DefaultPersister implements Persister {
}
}
}
-
for (BeanPropertyAssocOne> prop : desc.propertiesOneExportedSave()) {
if (prop.isOrphanRemoval() && request.isDirtyProperty(prop)) {
deleteOrphan(request, prop);
@@ -1145,9 +1067,7 @@ public final class DefaultPersister implements Persister {
* loaded but required for Delete cascade.
*/
private DeleteUnloadedForeignKeys getDeleteUnloadedForeignKeys(PersistRequestBean> request) {
-
DeleteUnloadedForeignKeys fkeys = null;
-
for (BeanPropertyAssocOne> one : request.descriptor().propertiesOneImportedDelete()) {
if (!request.isLoadedProperty(one)) {
// we have cascade Delete on a partially populated bean and
@@ -1158,7 +1078,6 @@ public final class DefaultPersister implements Persister {
fkeys.add(one);
}
}
-
return fkeys;
}
@@ -1166,9 +1085,7 @@ public final class DefaultPersister implements Persister {
* Delete any associated one beans.
*/
private void deleteAssocOne(PersistRequestBean> request) {
-
DeleteMode deleteMode = request.deleteMode();
-
for (BeanPropertyAssocOne> prop : request.descriptor().propertiesOneImportedDelete()) {
if (deleteMode.isHard() || prop.isTargetSoftDelete()) {
if (request.isLoadedProperty(prop)) {
@@ -1196,7 +1113,7 @@ public final class DefaultPersister implements Persister {
* Create the Persist Request Object additionally specifying the publish status.
*/
private PersistRequestBean createRequestInternal(T bean, Transaction t, PersistRequest.Type type) {
- BeanManager mgr = getBeanManager(bean);
+ BeanManager mgr = beanManager(bean.getClass());
return createRequest(bean, t, null, mgr, type, Flags.ZERO);
}
@@ -1206,7 +1123,7 @@ public final class DefaultPersister implements Persister {
* This call determines the PersistRequest.Type based on bean state and the insert flag (root persist type).
*/
private PersistRequestBean createRequestRecurse(T bean, Transaction t, Object parentBean, int flags) {
- BeanManager mgr = getBeanManager(bean);
+ BeanManager mgr = beanManager(bean.getClass());
BeanDescriptor desc = mgr.getBeanDescriptor();
EntityBean entityBean = (EntityBean) bean;
PersistRequest.Type type;
@@ -1225,7 +1142,7 @@ public final class DefaultPersister implements Persister {
* Create the Persist Request Object that wraps all the objects used to
* perform an insert, update or delete.
*/
- @SuppressWarnings({"unchecked"})
+ @SuppressWarnings({"unchecked", "rawtypes"})
private PersistRequestBean createRequest(T bean, Transaction t, Object parentBean, BeanManager> mgr,
PersistRequest.Type type, int flags) {
// no delete requests come here
@@ -1242,7 +1159,7 @@ public final class DefaultPersister implements Persister {
@SuppressWarnings({"unchecked"})
private PersistRequestBean createDeleteRequest(Object bean, Transaction t, PersistRequest.Type type, int flags) {
- BeanManager mgr = getBeanManager(bean);
+ BeanManager mgr = beanManager(bean.getClass());
if (type == Type.DELETE_PERMANENT) {
type = Type.DELETE;
} else if (type == Type.DELETE && mgr.getBeanDescriptor().isSoftDelete()) {
@@ -1256,9 +1173,8 @@ public final class DefaultPersister implements Persister {
}
private String errNotRegistered(Class> beanClass) {
- String msg = "The type [" + beanClass + "] is not a registered entity?";
- msg += " If you don't explicitly list the entity classes to use Ebean will search for them in the classpath.";
- return msg;
+ return "The type [" + beanClass + "] is not a registered entity?"
+ + " If you don't explicitly list the entity classes to use Ebean will search for them in the classpath.";
}
/**
@@ -1269,10 +1185,10 @@ public final class DefaultPersister implements Persister {
*
*/
@SuppressWarnings("unchecked")
- private BeanManager getBeanManager(Object bean) {
- BeanManager mgr = (BeanManager) beanDescriptorManager.beanManager(bean.getClass());
+ private BeanManager beanManager(Class> cls) {
+ BeanManager mgr = (BeanManager)beanDescriptorManager.beanManager(cls);
if (mgr == null) {
- throw new PersistenceException(errNotRegistered(bean.getClass()));
+ throw new PersistenceException(errNotRegistered(cls));
}
return mgr;
}