From 8765cb8356306024d8d7550917d87f598afa74ee Mon Sep 17 00:00:00 2001 From: Robin Bygrave Date: Fri, 17 Jun 2016 13:24:49 +1200 Subject: [PATCH] No effective change - reformat code --- .../server/deploy/AssocOneHelp.java | 1 + .../server/deploy/BeanCascadeInfo.java | 2 +- .../server/deploy/BeanCollectionHelp.java | 66 +-- .../deploy/BeanCollectionHelpFactory.java | 66 +-- .../server/deploy/BeanDescriptor.java | 130 ++--- .../deploy/BeanDescriptorCacheHelp.java | 26 +- .../deploy/BeanDescriptorDraftHelp.java | 10 +- .../server/deploy/BeanEmbeddedMeta.java | 26 +- .../deploy/BeanEmbeddedMetaFactory.java | 58 +- .../server/deploy/BeanFkeyProperty.java | 4 +- .../server/deploy/BeanManager.java | 36 +- .../server/deploy/BeanMapHelp.java | 3 +- .../server/deploy/BeanProperty.java | 18 +- .../server/deploy/BeanPropertyAssoc.java | 540 +++++++++--------- 14 files changed, 494 insertions(+), 492 deletions(-) diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/AssocOneHelp.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/AssocOneHelp.java index a3a3de6c3..1faabb50f 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/AssocOneHelp.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/AssocOneHelp.java @@ -21,6 +21,7 @@ abstract class AssocOneHelp { this.property = property; this.target = property.targetDescriptor; } + /** * Effectively skip reading (the jdbc resultSet as already in the persistence context etc). */ diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCascadeInfo.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCascadeInfo.java index 3fb3d59b2..c35d6f532 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCascadeInfo.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCascadeInfo.java @@ -42,7 +42,7 @@ public class BeanCascadeInfo { save = true; break; default: - throw new IllegalStateException("Unexpected CascadeType "+type); + throw new IllegalStateException("Unexpected CascadeType " + type); } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCollectionHelp.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCollectionHelp.java index 4cbbe3b8d..f870b7803 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCollectionHelp.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCollectionHelp.java @@ -16,48 +16,48 @@ import java.io.IOException; */ public interface BeanCollectionHelp { - /** - * Set the EbeanServer that owns the configuration. - */ - void setLoader(BeanCollectionLoader loader); - - /** - * Return the mechanism to add beans to the underlying collection. - *

- * For Map's this needs to take the mapKey. - *

- */ - BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey); + /** + * Set the EbeanServer that owns the configuration. + */ + void setLoader(BeanCollectionLoader loader); + + /** + * Return the mechanism to add beans to the underlying collection. + *

+ * For Map's this needs to take the mapKey. + *

+ */ + BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey); /** * Create an empty collection of the correct type without a parent bean. */ BeanCollection createEmptyNoParent(); - /** - * Create an empty collection of the correct type. - */ - BeanCollection createEmpty(EntityBean bean); + /** + * Create an empty collection of the correct type. + */ + BeanCollection createEmpty(EntityBean bean); - /** - * Add a bean to the List Set or Map. - */ - void add(BeanCollection collection, EntityBean bean, boolean withCheck); + /** + * Add a bean to the List Set or Map. + */ + void add(BeanCollection collection, EntityBean bean, boolean withCheck); - /** - * Create a lazy loading proxy for a List Set or Map. - */ - BeanCollection createReference(EntityBean parentBean); + /** + * Create a lazy loading proxy for a List Set or Map. + */ + BeanCollection createReference(EntityBean parentBean); - /** - * Refresh the List Set or Map. - */ - void refresh(EbeanServer server, Query query, Transaction t, EntityBean parentBean); - - /** - * Apply the new refreshed BeanCollection to the appropriate property of the parent bean. - */ - void refresh(BeanCollection bc, EntityBean parentBean); + /** + * Refresh the List Set or Map. + */ + void refresh(EbeanServer server, Query query, Transaction t, EntityBean parentBean); + + /** + * Apply the new refreshed BeanCollection to the appropriate property of the parent bean. + */ + void refresh(BeanCollection bc, EntityBean parentBean); /** * Write the collection out as json. diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCollectionHelpFactory.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCollectionHelpFactory.java index a812ba4b4..827be9818 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCollectionHelpFactory.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanCollectionHelpFactory.java @@ -13,42 +13,42 @@ public class BeanCollectionHelpFactory { static final BeanSetHelp SET_HELP = new BeanSetHelp(); - /** - * Create the helper based on the many property. - */ - public static BeanCollectionHelp create(BeanPropertyAssocMany manyProperty) { + /** + * Create the helper based on the many property. + */ + public static BeanCollectionHelp create(BeanPropertyAssocMany manyProperty) { - ManyType manyType = manyProperty.getManyType(); - switch (manyType) { - case LIST: - return new BeanListHelp(manyProperty); - case SET: - return new BeanSetHelp(manyProperty); - case MAP: - return new BeanMapHelp(manyProperty); - default: - throw new RuntimeException("Invalid type "+manyType); - } - - } + ManyType manyType = manyProperty.getManyType(); + switch (manyType) { + case LIST: + return new BeanListHelp(manyProperty); + case SET: + return new BeanSetHelp(manyProperty); + case MAP: + return new BeanMapHelp(manyProperty); + default: + throw new RuntimeException("Invalid type " + manyType); + } + + } @SuppressWarnings("unchecked") - public static BeanCollectionHelp create(OrmQueryRequest request) { + public static BeanCollectionHelp create(OrmQueryRequest request) { + + SpiQuery.Type manyType = request.getQuery().getType(); + + if (manyType.equals(SpiQuery.Type.LIST)) { + return LIST_HELP; + + } else if (manyType.equals(SpiQuery.Type.SET)) { + return SET_HELP; + + } else { + BeanDescriptor target = request.getBeanDescriptor(); + String mapKey = request.getQuery().getMapKey(); + return new BeanMapHelp(target, mapKey); + } + } - SpiQuery.Type manyType = request.getQuery().getType(); - - if (manyType.equals(SpiQuery.Type.LIST)){ - return LIST_HELP; - - } else if (manyType.equals(SpiQuery.Type.SET)) { - return SET_HELP; - - } else { - BeanDescriptor target = request.getBeanDescriptor(); - String mapKey = request.getQuery().getMapKey(); - return new BeanMapHelp(target, mapKey); - } - } - } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java index edb9e24f8..a86c15811 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java @@ -119,7 +119,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { for (int i = 0; i < propertyLength; i++) { - if (fromEbi.isLoadedProperty(i) ) { + if (fromEbi.isLoadedProperty(i)) { BeanProperty property = getBeanProperty(names[i]); if (!toEbi.isLoadedProperty(i)) { Object val = property.getValue(bean); @@ -228,9 +228,9 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { */ private final BeanDescriptorMap owner; - + private final String[] properties; - + /** * Intercept pre post on insert,update, and delete . */ @@ -276,7 +276,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { * Derived list of properties that are used for version concurrency checking. */ private final BeanProperty versionProperty; - + private final int versionPropertyIndex; private final BeanProperty whenModifiedProperty; @@ -287,7 +287,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { * Properties that are initialised in the constructor need to be 'unloaded' to support partial object queries. */ private final int[] unloadProperties; - + /** * Properties local to this type (not from a super type). */ @@ -298,7 +298,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { */ private final BeanProperty[] propertiesMutable; - + private final BeanPropertyAssocOne unidirectional; /** @@ -358,7 +358,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { private boolean deleteRecurseSkippable; private final EntityBean prototypeEntityBean; - + private final IdBinder idBinder; private String idBinderInLHSSql; @@ -499,7 +499,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { // Check if there are no cascade delete associated beans (also subject to // change in initialiseOther()). deleteRecurseSkippable = (0 == (propertiesOneExportedDelete.length + propertiesOneImportedDelete.length + propertiesManyDelete.length)); - + // object used to handle Id values this.idBinder = owner.createIdBinder(idProperty); this.whenModifiedProperty = findWhenModifiedProperty(); @@ -511,7 +511,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { this.versionPropertyIndex = -1; this.unloadProperties = new int[0]; this.propertiesIndex = new BeanProperty[0]; - + } else { EntityBeanIntercept ebi = prototypeEntityBean._ebean_getIntercept(); this.idPropertyIndex = (idProperty == null) ? -1 : ebi.findProperty(idProperty.getName()); @@ -529,40 +529,40 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { * These properties need to be unloaded when populating beans for queries. */ private int[] derivePropertiesToUnload(EntityBean prototypeEntityBean) { - + boolean[] loaded = prototypeEntityBean._ebean_getIntercept().getLoaded(); int[] props = new int[loaded.length]; int pos = 0; - + // collect the positions of the properties initialised in the default constructor. for (int i = 0; i < loaded.length; i++) { if (loaded[i]) { props[pos++] = i; } } - + if (pos == 0) { // nothing set in the constructor return new int[0]; } - + // populate a smaller/minimal array int[] unload = new int[pos]; System.arraycopy(props, 0, unload, 0, pos); return unload; } - + /** - * Create an entity bean that is used as a prototype/factory to create new instances. + * Create an entity bean that is used as a prototype/factory to create new instances. */ private EntityBean createPrototypeEntityBean(Class beanType) { if (Modifier.isAbstract(beanType.getModifiers())) { - return null; - } + return null; + } try { return (EntityBean) beanType.newInstance(); } catch (Exception e) { - throw new IllegalStateException("Error trying to create the prototypeEntityBean for "+beanType, e); + throw new IllegalStateException("Error trying to create the prototypeEntityBean for " + beanType, e); } } @@ -608,9 +608,10 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { * These properties need to be initialised prior to the association properties * as they are used to get the imported and exported properties. *

+ * * @param withHistoryTables map populated if @History is supported on this entity bean */ - public void initialiseId(Map withHistoryTables, Map draftTables) { + public void initialiseId(Map withHistoryTables, Map draftTables) { if (logger.isTraceEnabled()) { logger.trace("BeanDescriptor initialise " + fullName); @@ -644,9 +645,9 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { /** * Initialise the exported and imported parts for associated properties. * - * @param asOfTableMap the map of base tables to associated 'with history' tables + * @param asOfTableMap the map of base tables to associated 'with history' tables * @param asOfViewSuffix the suffix added to the table name to derive the 'with history' view name - * @param draftTableMap the map of base tables to associated 'draft' tables. + * @param draftTableMap the map of base tables to associated 'draft' tables. */ public void initialiseOther(Map asOfTableMap, String asOfViewSuffix, Map draftTableMap) { @@ -709,7 +710,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { propertiesMany[i].initialisePostTarget(); } if (inheritInfo != null && !inheritInfo.isRoot()) { - docStoreAdapter = (DocStoreBeanAdapter)inheritInfo.getRoot().desc().docStoreAdapter(); + docStoreAdapter = (DocStoreBeanAdapter) inheritInfo.getRoot().desc().docStoreAdapter(); } docMapping = docStoreAdapter.createDocMapping(); docStoreAdapter.registerPaths(); @@ -753,12 +754,12 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { PersistRequest.Type type = request.getType(); switch (type) { case INSERT: - return changeLogFilter.includeInsert(request) ? insertBeanChange(request): null; + return changeLogFilter.includeInsert(request) ? insertBeanChange(request) : null; case UPDATE: case SOFT_DELETE: - return changeLogFilter.includeUpdate(request) ? updateBeanChange(request): null; + return changeLogFilter.includeUpdate(request) ? updateBeanChange(request) : null; case DELETE: - return changeLogFilter.includeDelete(request) ? deleteBeanChange(request) :null; + return changeLogFilter.includeDelete(request) ? deleteBeanChange(request) : null; default: throw new IllegalStateException("Unhandled request type " + type); } @@ -959,7 +960,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { mapping.add(new DocPropertyMapping(discCol, DocPropertyType.INTEGER)); } } - for (BeanProperty prop: propertiesNonTransient) { + for (BeanProperty prop : propertiesNonTransient) { prop.docStoreMapping(mapping, prefix); } if (inheritInfo != null) { @@ -1121,7 +1122,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { public CachedBeanData cacheEmbeddedBeanExtract(EntityBean bean) { return cacheHelp.beanExtractData(this, bean); } - + /** * Load the embedded bean (taking into account inheritance). */ @@ -1177,7 +1178,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { public void cacheHandleDeleteById(Object id) { cacheHelp.beanCacheRemove(id); } - + /** * Returns true if it managed to populate/load the bean from the cache. */ @@ -1330,15 +1331,15 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { public List collectQueryPlanStatistics(boolean reset) { return collectQueryPlanStatisticsInternal(reset, false); } - + @Override public List collectAllQueryPlanStatistics(boolean reset) { return collectQueryPlanStatisticsInternal(reset, false); } - + public List collectQueryPlanStatisticsInternal(boolean reset, boolean collectAll) { List list = new ArrayList(queryPlanCache.size()); - for (CQueryPlan queryPlan : queryPlanCache.values()) { + for (CQueryPlan queryPlan : queryPlanCache.values()) { Snapshot snapshot = queryPlan.getSnapshot(reset); if (collectAll || snapshot.getExecutionCount() > 0) { list.add(snapshot); @@ -1413,7 +1414,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { /** * Return true if delete can use a single SQL statement. - * + *

* This implies cascade delete does not continue depth wise and that this is no * associated L2 bean caching. */ @@ -1529,7 +1530,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { @Override @SuppressWarnings("unchecked") public T createBean() { - return (T)createEntityBean(); + return (T) createEntityBean(); } /** @@ -1538,8 +1539,8 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { @SuppressWarnings("unchecked") public EntityBean createEntityBean() { try { - EntityBean bean = (EntityBean)prototypeEntityBean._ebean_newInstance(); - + EntityBean bean = (EntityBean) prototypeEntityBean._ebean_newInstance(); + if (unloadProperties.length > 0) { // 'unload' any properties initialised in the default constructor EntityBeanIntercept ebi = bean._ebean_getIntercept(); @@ -1548,7 +1549,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { } } return bean; - + } catch (Exception ex) { throw new PersistenceException(ex); } @@ -1806,7 +1807,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { public Object convertIdFromJson(Object idValue) { return idBinder.convertIdFromJson(idValue); } - + /** * Return the default order by that may need to be added if a many property is * included in the query. @@ -1871,7 +1872,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { /** * Register all the assoc many properties on this bean that are not populated with the load context. *

- * This provides further lazy loading via the load context. + * This provides further lazy loading via the load context. *

*/ public void lazyLoadRegister(String prefix, EntityBeanIntercept ebi, EntityBean bean, LoadContext loadContext) { @@ -1930,9 +1931,8 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { /** * Return a Comparator for local sorting of lists. - * - * @param sortByClause - * list of property names with optional ASC or DESC suffix. + * + * @param sortByClause list of property names with optional ASC or DESC suffix. */ @SuppressWarnings("unchecked") private ElComparator createComparator(String sortByClause) { @@ -2025,7 +2025,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { ElPropertyDeploy fk = elDeployCache.get(propName); if (fk != null && fk instanceof BeanFkeyProperty) { // propertyDeploy chain for foreign key column - return ((BeanFkeyProperty)fk).create(chain.getExpression(), chain.isContainsMany()); + return ((BeanFkeyProperty) fk).create(chain.getExpression(), chain.isContainsMany()); } } @@ -2087,7 +2087,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { */ public void resetManyProperties(Object dbBean) { - EntityBean bean = (EntityBean)dbBean; + EntityBean bean = (EntityBean) dbBean; for (int i = 0; i < propertiesMany.length; i++) { if (propertiesMany[i].isCascadeRefresh()) { propertiesMany[i].resetMany(bean); @@ -2336,10 +2336,14 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { */ public String getBaseTable(SpiQuery.TemporalMode mode) { switch (mode) { - case DRAFT: return draftTable; - case VERSIONS: return baseTableVersionsBetween; - case AS_OF: return baseTableAsOf; - default: return baseTable; + case DRAFT: + return draftTable; + case VERSIONS: + return baseTableVersionsBetween; + case AS_OF: + return baseTableAsOf; + default: + return baseTable; } } @@ -2554,19 +2558,17 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { /** * Return true if this bean should be inserted rather than updated. - * - * @param ebi - * The entity bean intercept - * @param insertMode - * true if the 'root request' was an insert rather than an update + * + * @param ebi The entity bean intercept + * @param insertMode true if the 'root request' was an insert rather than an update */ public boolean isInsertMode(EntityBeanIntercept ebi, boolean insertMode) { - + if (ebi.isLoaded()) { // must be an update as the bean is loaded return false; } - + if (idProperty.isEmbedded()) { // not using Id generator so just base on isLoaded() return !ebi.isLoaded(); @@ -2578,11 +2580,11 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { // same as the 'root request' return insertMode; } - + public boolean isReference(EntityBeanIntercept ebi) { return ebi.isReference() || hasIdPropertyOnly(ebi); } - + public boolean hasIdPropertyOnly(EntityBeanIntercept ebi) { return ebi.hasIdOnly(idPropertyIndex); } @@ -2631,13 +2633,13 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { } } } - + public ConcurrencyMode getConcurrencyMode(EntityBeanIntercept ebi) { - + if (!hasVersionProperty(ebi)) { return ConcurrencyMode.NONE; } else { - return concurrencyMode; + return concurrencyMode; } } @@ -2723,7 +2725,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { query.order(rawSql.getSql().getOrderBy()); } query.order().asc(idProperty.getName()); - } else if (!orderBy.containsProperty(idProperty.getName())){ + } else if (!orderBy.containsProperty(idProperty.getName())) { query.order().asc(idProperty.getName()); } } @@ -2855,8 +2857,8 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { public void jsonWrite(WriteJson writeJson, EntityBean bean) throws IOException { jsonHelp.jsonWrite(writeJson, bean, null); - } - + } + public void jsonWrite(WriteJson writeJson, EntityBean bean, String key) throws IOException { jsonHelp.jsonWrite(writeJson, bean, key); } @@ -2864,11 +2866,11 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { protected void jsonWriteProperties(WriteJson writeJson, EntityBean bean) throws IOException { jsonHelp.jsonWriteProperties(writeJson, bean); } - + public T jsonRead(ReadJson jsonRead, String path) throws IOException { return jsonHelp.jsonRead(jsonRead, path); } - + protected T jsonReadObject(ReadJson jsonRead, String path) throws IOException { return jsonHelp.jsonReadObject(jsonRead, path); } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java index 12a06bc67..064b42d5f 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java @@ -29,7 +29,7 @@ import java.util.Map; /** * Helper for BeanDescriptor that manages the bean, query and collection caches. - * + * * @param The entity bean type */ final class BeanDescriptorCacheHelp { @@ -55,7 +55,7 @@ final class BeanDescriptorCacheHelp { private final Class beanType; private final String cacheName; - + private final BeanPropertyAssocOne[] propertiesOneImported; private final String naturalKeyProperty; @@ -74,7 +74,7 @@ final class BeanDescriptorCacheHelp { private boolean cacheNotifyOnDelete; BeanDescriptorCacheHelp(BeanDescriptor desc, ServerCacheManager cacheManager, CacheOptions cacheOptions, - boolean cacheSharableBeans, BeanPropertyAssocOne[] propertiesOneImported) { + boolean cacheSharableBeans, BeanPropertyAssocOne[] propertiesOneImported) { this.desc = desc; this.beanType = desc.rootBeanType; @@ -88,7 +88,7 @@ final class BeanDescriptorCacheHelp { if (!cacheOptions.isEnableQueryCache()) { this.queryCache = null; } else { - this.queryCache = cacheManager.getQueryCache(beanType); + this.queryCache = cacheManager.getQueryCache(beanType); } if (cacheOptions.isEnableBeanCache()) { @@ -240,7 +240,7 @@ final class BeanDescriptorCacheHelp { manyLog.trace(" GET {}({}).{} - cache miss", cacheName, parentId, propertyName); } } else if (manyLog.isDebugEnabled()) { - manyLog.debug(" GET {}({}).{} - hit", cacheName, parentId, propertyName); + manyLog.debug(" GET {}({}).{} - hit", cacheName, parentId, propertyName); } return entry; } @@ -255,7 +255,7 @@ final class BeanDescriptorCacheHelp { // not in cache so return unsuccessful return false; } - + Object ownerBean = bc.getOwnerBean(); EntityBeanIntercept ebi = ((EntityBean) ownerBean)._ebean_getIntercept(); PersistenceContext persistenceContext = ebi.getPersistenceContext(); @@ -350,13 +350,13 @@ final class BeanDescriptorCacheHelp { // Not using a loadContext for beans coming out of L2 cache // so that means no batch lazy loading for these beans - EntityBean entityBean = (EntityBean)bean; + EntityBean entityBean = (EntityBean) bean; EntityBeanIntercept ebi = entityBean._ebean_getIntercept(); ebi.setPersistenceContext(context); Object id = desc.getId(entityBean); desc.contextPut(context, id, bean); } - + /** * Return the beanCache creating it if necessary. */ @@ -366,7 +366,7 @@ final class BeanDescriptorCacheHelp { } return beanCache; } - + /** * Clear the bean cache. */ @@ -422,7 +422,7 @@ final class BeanDescriptorCacheHelp { CachedBeanData beanCacheGetData(Object id) { return (CachedBeanData) getBeanCache().get(id); } - + T beanCacheGet(Object id, Boolean readOnly, PersistenceContext context) { T bean = beanCacheGetInternal(id, readOnly, context); if (bean != null) { @@ -430,7 +430,7 @@ final class BeanDescriptorCacheHelp { } return bean; } - + /** * Return a bean from the bean cache. */ @@ -457,7 +457,7 @@ final class BeanDescriptorCacheHelp { } } - return (T)loadBean(id, readOnly, data, context); + return (T) loadBean(id, readOnly, data, context); } /** @@ -636,7 +636,7 @@ final class BeanDescriptorCacheHelp { } } } - + // check if the bean itself was updated if (!updateRequest.isUpdatedManysOnly()) { diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorDraftHelp.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorDraftHelp.java index b4c2996c9..6fcc8319c 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorDraftHelp.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorDraftHelp.java @@ -8,7 +8,7 @@ import java.util.List; /** * Helper for BeanDescriptor that manages draft entity beans. - * + * * @param The entity bean type */ public final class BeanDescriptorDraftHelp { @@ -47,7 +47,7 @@ public final class BeanDescriptorDraftHelp { */ public boolean draftReset(T draftBean) { - EntityBean draftEntityBean = (EntityBean)draftBean; + EntityBean draftEntityBean = (EntityBean) draftBean; if (draftDirty != null) { // set @DraftDirty property to false @@ -72,11 +72,11 @@ public final class BeanDescriptorDraftHelp { public T publish(T draftBean, T liveBean) { if (liveBean == null) { - liveBean = (T)desc.createEntityBean(); + liveBean = (T) desc.createEntityBean(); } - EntityBean draft = (EntityBean)draftBean; - EntityBean live = (EntityBean)liveBean; + EntityBean draft = (EntityBean) draftBean; + EntityBean live = (EntityBean) liveBean; BeanProperty idProperty = desc.getIdProperty(); if (idProperty != null) { diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanEmbeddedMeta.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanEmbeddedMeta.java index db3ff928d..11557fac8 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanEmbeddedMeta.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanEmbeddedMeta.java @@ -2,18 +2,18 @@ package com.avaje.ebeaninternal.server.deploy; public class BeanEmbeddedMeta { - - final BeanProperty[] properties; - - public BeanEmbeddedMeta(BeanProperty[] properties) { - this.properties = properties; - } - /** - * Return the properties with over ridden mapping information. - */ - public BeanProperty[] getProperties() { - return properties; - } - + final BeanProperty[] properties; + + public BeanEmbeddedMeta(BeanProperty[] properties) { + this.properties = properties; + } + + /** + * Return the properties with over ridden mapping information. + */ + public BeanProperty[] getProperties() { + return properties; + } + } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanEmbeddedMetaFactory.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanEmbeddedMetaFactory.java index c37a9cb9d..9794c9963 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanEmbeddedMetaFactory.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanEmbeddedMetaFactory.java @@ -12,41 +12,41 @@ import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocOne; */ public class BeanEmbeddedMetaFactory { - /** - * Create BeanProperties for embedded beans using the deployment specific DB column name and table alias. - */ - public static BeanEmbeddedMeta create(BeanDescriptorMap owner, DeployBeanPropertyAssocOne prop) { + /** + * Create BeanProperties for embedded beans using the deployment specific DB column name and table alias. + */ + public static BeanEmbeddedMeta create(BeanDescriptorMap owner, DeployBeanPropertyAssocOne prop) { - // we can get a BeanDescriptor for an Embedded bean - // and know that it is NOT recursive, as Embedded beans are - // only allow to hold simple scalar types... - BeanDescriptor targetDesc = owner.getBeanDescriptor(prop.getTargetType()); - if (targetDesc == null){ - String msg = "Could not find BeanDescriptor for "+prop.getTargetType() - +". Perhaps the EmbeddedId class is not registered?"; - throw new PersistenceException(msg); - } + // we can get a BeanDescriptor for an Embedded bean + // and know that it is NOT recursive, as Embedded beans are + // only allow to hold simple scalar types... + BeanDescriptor targetDesc = owner.getBeanDescriptor(prop.getTargetType()); + if (targetDesc == null) { + String msg = "Could not find BeanDescriptor for " + prop.getTargetType() + + ". Perhaps the EmbeddedId class is not registered?"; + throw new PersistenceException(msg); + } - // deployment override information (column names) - Map propColMap = prop.getDeployEmbedded().getPropertyColumnMap(); + // deployment override information (column names) + Map propColMap = prop.getDeployEmbedded().getPropertyColumnMap(); - BeanProperty[] sourceProperties = targetDesc.propertiesBaseScalar(); + BeanProperty[] sourceProperties = targetDesc.propertiesBaseScalar(); - BeanProperty[] embeddedProperties = new BeanProperty[sourceProperties.length]; + BeanProperty[] embeddedProperties = new BeanProperty[sourceProperties.length]; - for (int i = 0; i < sourceProperties.length; i++) { + for (int i = 0; i < sourceProperties.length; i++) { - String propertyName = sourceProperties[i].getName(); - String dbColumn = propColMap.get(propertyName); - if (dbColumn == null) { - // dbColumn not overridden so take original - dbColumn = sourceProperties[i].getDbColumn(); - } + String propertyName = sourceProperties[i].getName(); + String dbColumn = propColMap.get(propertyName); + if (dbColumn == null) { + // dbColumn not overridden so take original + dbColumn = sourceProperties[i].getDbColumn(); + } - BeanPropertyOverride overrides = new BeanPropertyOverride(dbColumn); - embeddedProperties[i] = new BeanProperty(sourceProperties[i], overrides); - } + BeanPropertyOverride overrides = new BeanPropertyOverride(dbColumn); + embeddedProperties[i] = new BeanProperty(sourceProperties[i], overrides); + } - return new BeanEmbeddedMeta(embeddedProperties); - } + return new BeanEmbeddedMeta(embeddedProperties); + } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanFkeyProperty.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanFkeyProperty.java index 293daa3a4..f25c0e9c5 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanFkeyProperty.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanFkeyProperty.java @@ -21,7 +21,7 @@ public final class BeanFkeyProperty implements ElPropertyValue { public BeanFkeyProperty(String name, String dbColumn, int deployOrder) { this(null, name, dbColumn, deployOrder, false); } - + private BeanFkeyProperty(String prefix, String name, String dbColumn, int deployOrder, boolean containsMany) { this.prefix = prefix; this.name = name; @@ -32,7 +32,7 @@ public final class BeanFkeyProperty implements ElPropertyValue { } public String toString() { - return "prefix:"+prefix+" name:"+name+" dbColumn:"+dbColumn+" ph:"+placeHolder; + return "prefix:" + prefix + " name:" + name + " dbColumn:" + dbColumn + " ph:" + placeHolder; } public int getDeployOrder() { diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanManager.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanManager.java index e31716dc3..d77704f65 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanManager.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanManager.java @@ -7,27 +7,27 @@ import com.avaje.ebeaninternal.server.persist.BeanPersister; */ public class BeanManager { - private final BeanPersister persister; + private final BeanPersister persister; - private final BeanDescriptor descriptor; + private final BeanDescriptor descriptor; - public BeanManager(BeanDescriptor descriptor, BeanPersister persister) { - this.descriptor = descriptor; - this.persister = persister; - } + public BeanManager(BeanDescriptor descriptor, BeanPersister persister) { + this.descriptor = descriptor; + this.persister = persister; + } - /** - * Return the associated BeanPersister. - */ - public BeanPersister getBeanPersister() { - return persister; - } + /** + * Return the associated BeanPersister. + */ + public BeanPersister getBeanPersister() { + return persister; + } - /** - * Return the BeanDescriptor. - */ - public BeanDescriptor getBeanDescriptor() { - return descriptor; - } + /** + * Return the BeanDescriptor. + */ + public BeanDescriptor getBeanDescriptor() { + return descriptor; + } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanMapHelp.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanMapHelp.java index 363a293ef..9b31e7556 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanMapHelp.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanMapHelp.java @@ -38,7 +38,8 @@ public final class BeanMapHelp implements BeanCollectionHelp { /** * When help is attached to a specific many property. - */ public BeanMapHelp(BeanPropertyAssocMany many) { + */ + public BeanMapHelp(BeanPropertyAssocMany many) { this.many = many; this.targetDescriptor = many.getTargetDescriptor(); this.propertyName = many.getName(); diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java index c892599d1..9bbae9675 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java @@ -332,9 +332,9 @@ public class BeanProperty implements ElPropertyValue, Property { this.softDelete = deploy.isSoftDelete(); if (softDelete) { - ScalarTypeBoolean.BooleanBase boolType = (ScalarTypeBoolean.BooleanBase)scalarType; - this.softDeleteDbSet = dbColumn+"="+boolType.getDbTrueLiteral(); - this.softDeleteDbPredicate = "."+dbColumn+","+boolType.getDbFalseLiteral()+")="+boolType.getDbFalseLiteral(); + ScalarTypeBoolean.BooleanBase boolType = (ScalarTypeBoolean.BooleanBase) scalarType; + this.softDeleteDbSet = dbColumn + "=" + boolType.getDbTrueLiteral(); + this.softDeleteDbPredicate = "." + dbColumn + "," + boolType.getDbFalseLiteral() + ")=" + boolType.getDbFalseLiteral(); } else { this.softDeleteDbSet = null; this.softDeleteDbPredicate = null; @@ -763,7 +763,7 @@ public class BeanProperty implements ElPropertyValue, Property { public void setCacheDataValue(EntityBean bean, Object cacheData, PersistenceContext context) { if (cacheData instanceof String) { // parse back from string to support optimisation of java object serialisation - cacheData = scalarType.parse((String)cacheData); + cacheData = scalarType.parse((String) cacheData); } setValue(bean, cacheData); } @@ -776,7 +776,7 @@ public class BeanProperty implements ElPropertyValue, Property { } public Object getVal(Object bean) { - return getValue((EntityBean)bean); + return getValue((EntityBean) bean); } /** @@ -814,7 +814,7 @@ public class BeanProperty implements ElPropertyValue, Property { if (bean != null) { Object logicalVal = convertToLogicalType(value); - setValue((EntityBean)bean, logicalVal); + setValue((EntityBean) bean, logicalVal); } } @@ -823,7 +823,7 @@ public class BeanProperty implements ElPropertyValue, Property { if (bean == null) { return null; } - return getValueIntercept((EntityBean)bean); + return getValueIntercept((EntityBean) bean); } @Override @@ -1322,7 +1322,7 @@ public class BeanProperty implements ElPropertyValue, Property { // change in behavior for #318 objValue = null; String msg = "Error trying to use Jackson ObjectMapper to read transient property " - + getFullBeanName() +" - consider marking this property with @JsonIgnore"; + + getFullBeanName() + " - consider marking this property with @JsonIgnore"; logger.error(msg, e); } } @@ -1371,7 +1371,7 @@ public class BeanProperty implements ElPropertyValue, Property { DocPropertyType type = scalarType.getDocType(); DocPropertyOptions options = docOptions.copy(); - if (DocPropertyType.UUID == type || DocPropertyType.ENUM == type ||isStringId(type)) { + if (DocPropertyType.UUID == type || DocPropertyType.ENUM == type || isStringId(type)) { options.setCode(true); } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssoc.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssoc.java index 5b3619cff..f087c3cb3 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssoc.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssoc.java @@ -1,19 +1,7 @@ package com.avaje.ebeaninternal.server.deploy; -import java.util.ArrayList; - -import javax.persistence.PersistenceException; - -import com.avaje.ebean.text.PathProperties; -import com.avaje.ebeaninternal.server.query.SplitName; -import com.avaje.ebeanservice.docstore.api.mapping.DocMappingBuilder; -import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyMapping; -import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType; -import com.avaje.ebeanservice.docstore.api.support.DocStructure; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.avaje.ebean.bean.EntityBean; +import com.avaje.ebean.text.PathProperties; import com.avaje.ebeaninternal.server.core.InternString; import com.avaje.ebeaninternal.server.deploy.id.IdBinder; import com.avaje.ebeaninternal.server.deploy.id.ImportedId; @@ -22,213 +10,223 @@ import com.avaje.ebeaninternal.server.deploy.id.ImportedIdSimple; import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssoc; import com.avaje.ebeaninternal.server.el.ElPropertyChainBuilder; import com.avaje.ebeaninternal.server.el.ElPropertyValue; +import com.avaje.ebeaninternal.server.query.SplitName; import com.avaje.ebeaninternal.server.query.SqlJoinType; +import com.avaje.ebeanservice.docstore.api.mapping.DocMappingBuilder; +import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyMapping; +import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType; +import com.avaje.ebeanservice.docstore.api.support.DocStructure; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.PersistenceException; +import java.util.ArrayList; /** * Abstract base for properties mapped to an associated bean, list, set or map. */ public abstract class BeanPropertyAssoc extends BeanProperty { - private static final Logger logger = LoggerFactory.getLogger(BeanPropertyAssoc.class); + private static final Logger logger = LoggerFactory.getLogger(BeanPropertyAssoc.class); - /** - * The descriptor of the target. This MUST be initialised after construction - * so as to avoid a dependency loop between BeanDescriptors. - */ - BeanDescriptor targetDescriptor; + /** + * The descriptor of the target. This MUST be initialised after construction + * so as to avoid a dependency loop between BeanDescriptors. + */ + BeanDescriptor targetDescriptor; - IdBinder targetIdBinder; + IdBinder targetIdBinder; - InheritInfo targetInheritInfo; + InheritInfo targetInheritInfo; - String targetIdProperty; + String targetIdProperty; - /** - * Persist settings. - */ - final BeanCascadeInfo cascadeInfo; + /** + * Persist settings. + */ + final BeanCascadeInfo cascadeInfo; - /** - * Join between the beans. - */ - final TableJoin tableJoin; + /** + * Join between the beans. + */ + final TableJoin tableJoin; - /** - * The type of the joined bean. - */ - final Class targetType; + /** + * The type of the joined bean. + */ + final Class targetType; - /** - * The join table information. - */ - final BeanTable beanTable; - - final String mappedBy; + /** + * The join table information. + */ + final BeanTable beanTable; + + final String mappedBy; final String docStoreDoc; - - final String extraWhere; - boolean saveRecurseSkippable; + final String extraWhere; - /** - * Construct the property. - */ - public BeanPropertyAssoc(BeanDescriptor descriptor, DeployBeanPropertyAssoc deploy) { - super(descriptor, deploy); - this.extraWhere = InternString.intern(deploy.getExtraWhere()); - this.beanTable = deploy.getBeanTable(); - this.mappedBy = InternString.intern(deploy.getMappedBy()); - this.docStoreDoc = deploy.getDocStoreDoc(); - this.tableJoin = new TableJoin(deploy.getTableJoin()); + boolean saveRecurseSkippable; - this.targetType = deploy.getTargetType(); - this.cascadeInfo = deploy.getCascadeInfo(); - } - - /** - * Initialise post construction. - */ - @Override - public void initialise() { - // this *MUST* execute after the BeanDescriptor is - // put into the map to stop infinite recursion - targetDescriptor = descriptor.getBeanDescriptor(targetType); - if (!isTransient){ - targetIdBinder = targetDescriptor.getIdBinder(); - targetInheritInfo = targetDescriptor.getInheritInfo(); - saveRecurseSkippable = targetDescriptor.isSaveRecurseSkippable(); - - if (!targetIdBinder.isComplexId()){ - targetIdProperty = targetIdBinder.getIdProperty(); - } - } - } - - /** - * Create a ElPropertyValue for a *ToOne or *ToMany. - */ - protected ElPropertyValue createElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) { - - // associated or embedded bean - BeanDescriptor embDesc = getTargetDescriptor(); - - if (chain == null) { - chain = new ElPropertyChainBuilder(isEmbedded(), propName); - } - chain.add(this); - if (containsMany()) { - chain.setContainsMany(); - } - return embDesc.buildElGetValue(remainder, chain, propertyDeploy); - } - - /** - * Add table join with table alias based on prefix. - */ - public SqlJoinType addJoin(SqlJoinType joinType, String prefix, DbSqlContext ctx) { - return tableJoin.addJoin(joinType, prefix, ctx); - } - - /** - * Add table join with explicit table alias. - */ - public SqlJoinType addJoin(SqlJoinType joinType, String a1, String a2, DbSqlContext ctx) { - return tableJoin.addJoin(joinType, a1, a2, ctx); - } - - /** - * Return false. - */ - public boolean isScalar() { - return false; - } - - /** - * Return the mappedBy property. - * This will be null on the owning side. - */ - public String getMappedBy() { - return mappedBy; - } - - /** - * Return the Id property of the target entity type. - *

- * This will return null for multiple Id properties. - *

- */ - public String getTargetIdProperty() { - return targetIdProperty; - } - - /** - * Return the BeanDescriptor of the target. - */ - public BeanDescriptor getTargetDescriptor() { - return targetDescriptor; - } - - /** - * Return true if REFRESH should cascade. + /** + * Construct the property. */ - public boolean isCascadeRefresh() { - return cascadeInfo.isRefresh(); - } + public BeanPropertyAssoc(BeanDescriptor descriptor, DeployBeanPropertyAssoc deploy) { + super(descriptor, deploy); + this.extraWhere = InternString.intern(deploy.getExtraWhere()); + this.beanTable = deploy.getBeanTable(); + this.mappedBy = InternString.intern(deploy.getMappedBy()); + this.docStoreDoc = deploy.getDocStoreDoc(); + this.tableJoin = new TableJoin(deploy.getTableJoin()); - public boolean isSaveRecurseSkippable(Object bean) { + this.targetType = deploy.getTargetType(); + this.cascadeInfo = deploy.getCascadeInfo(); + } + + /** + * Initialise post construction. + */ + @Override + public void initialise() { + // this *MUST* execute after the BeanDescriptor is + // put into the map to stop infinite recursion + targetDescriptor = descriptor.getBeanDescriptor(targetType); + if (!isTransient) { + targetIdBinder = targetDescriptor.getIdBinder(); + targetInheritInfo = targetDescriptor.getInheritInfo(); + saveRecurseSkippable = targetDescriptor.isSaveRecurseSkippable(); + + if (!targetIdBinder.isComplexId()) { + targetIdProperty = targetIdBinder.getIdProperty(); + } + } + } + + /** + * Create a ElPropertyValue for a *ToOne or *ToMany. + */ + protected ElPropertyValue createElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) { + + // associated or embedded bean + BeanDescriptor embDesc = getTargetDescriptor(); + + if (chain == null) { + chain = new ElPropertyChainBuilder(isEmbedded(), propName); + } + chain.add(this); + if (containsMany()) { + chain.setContainsMany(); + } + return embDesc.buildElGetValue(remainder, chain, propertyDeploy); + } + + /** + * Add table join with table alias based on prefix. + */ + public SqlJoinType addJoin(SqlJoinType joinType, String prefix, DbSqlContext ctx) { + return tableJoin.addJoin(joinType, prefix, ctx); + } + + /** + * Add table join with explicit table alias. + */ + public SqlJoinType addJoin(SqlJoinType joinType, String a1, String a2, DbSqlContext ctx) { + return tableJoin.addJoin(joinType, a1, a2, ctx); + } + + /** + * Return false. + */ + public boolean isScalar() { + return false; + } + + /** + * Return the mappedBy property. + * This will be null on the owning side. + */ + public String getMappedBy() { + return mappedBy; + } + + /** + * Return the Id property of the target entity type. + *

+ * This will return null for multiple Id properties. + *

+ */ + public String getTargetIdProperty() { + return targetIdProperty; + } + + /** + * Return the BeanDescriptor of the target. + */ + public BeanDescriptor getTargetDescriptor() { + return targetDescriptor; + } + + /** + * Return true if REFRESH should cascade. + */ + public boolean isCascadeRefresh() { + return cascadeInfo.isRefresh(); + } + + public boolean isSaveRecurseSkippable(Object bean) { return saveRecurseSkippable && bean instanceof EntityBean && !((EntityBean) bean)._ebean_getIntercept().isNewOrDirty(); } - /** - * Return true if save can be skipped for unmodified bean(s) of this - * property. - *

- * That is, if a bean of this property is unmodified we don't need to - * saveRecurse because none of its associated beans have cascade save set to - * true. - *

- */ - public boolean isSaveRecurseSkippable() { - return saveRecurseSkippable; - } + /** + * Return true if save can be skipped for unmodified bean(s) of this + * property. + *

+ * That is, if a bean of this property is unmodified we don't need to + * saveRecurse because none of its associated beans have cascade save set to + * true. + *

+ */ + public boolean isSaveRecurseSkippable() { + return saveRecurseSkippable; + } - /** - * Return true if the unique id properties are all not null for this bean. - */ - public boolean hasId(EntityBean bean) { + /** + * Return true if the unique id properties are all not null for this bean. + */ + public boolean hasId(EntityBean bean) { - BeanDescriptor targetDesc = getTargetDescriptor(); - BeanProperty idProp = targetDesc.getIdProperty(); - if (idProp != null) { - Object value = idProp.getValue(bean); - if (value == null) { - return false; - } - } - // all the unique properties are non-null - return true; - } + BeanDescriptor targetDesc = getTargetDescriptor(); + BeanProperty idProp = targetDesc.getIdProperty(); + if (idProp != null) { + Object value = idProp.getValue(bean); + if (value == null) { + return false; + } + } + // all the unique properties are non-null + return true; + } - /** - * Return the type of the target. - *

- * This is the class of the associated bean, or beans contained in a list, - * set or map. - *

- */ - public Class getTargetType() { - return targetType; - } + /** + * Return the type of the target. + *

+ * This is the class of the associated bean, or beans contained in a list, + * set or map. + *

+ */ + public Class getTargetType() { + return targetType; + } - /** - * Return an extra clause to add to the query for loading or joining - * to this bean type. - */ - public String getExtraWhere() { - return extraWhere; - } + /** + * Return an extra clause to add to the query for loading or joining + * to this bean type. + */ + public String getExtraWhere() { + return extraWhere; + } /** * Return the elastic search doc for this embedded property. @@ -287,104 +285,104 @@ public abstract class BeanPropertyAssoc extends BeanProperty { } } - /** - * Return true if this association is updateable. - */ - public boolean isUpdateable() { + /** + * Return true if this association is updateable. + */ + public boolean isUpdateable() { return tableJoin.columns().length <= 0 || tableJoin.columns()[0].isUpdateable(); } - /** - * Return true if this association is insertable. - */ - public boolean isInsertable() { + /** + * Return true if this association is insertable. + */ + public boolean isInsertable() { return tableJoin.columns().length <= 0 || tableJoin.columns()[0].isInsertable(); } - /** - * return the join to use for the bean. - */ - public TableJoin getTableJoin() { - return tableJoin; - } + /** + * return the join to use for the bean. + */ + public TableJoin getTableJoin() { + return tableJoin; + } - /** - * Get the persist info. - */ - public BeanCascadeInfo getCascadeInfo() { - return cascadeInfo; - } + /** + * Get the persist info. + */ + public BeanCascadeInfo getCascadeInfo() { + return cascadeInfo; + } - /** - * Build the list of imported property. Matches BeanProperty from the target - * descriptor back to local database columns in the TableJoin. - */ - protected ImportedId createImportedId(BeanPropertyAssoc owner, BeanDescriptor target, TableJoin join) { + /** + * Build the list of imported property. Matches BeanProperty from the target + * descriptor back to local database columns in the TableJoin. + */ + protected ImportedId createImportedId(BeanPropertyAssoc owner, BeanDescriptor target, TableJoin join) { - BeanProperty idProp = target.getIdProperty(); - BeanProperty[] others = target.propertiesBaseScalar(); + BeanProperty idProp = target.getIdProperty(); + BeanProperty[] others = target.propertiesBaseScalar(); - if (descriptor.isSqlSelectBased()){ - String dbColumn = owner.getDbColumn(); - return new ImportedIdSimple(owner, dbColumn, idProp, 0); - } + if (descriptor.isSqlSelectBased()) { + String dbColumn = owner.getDbColumn(); + return new ImportedIdSimple(owner, dbColumn, idProp, 0); + } - TableJoinColumn[] cols = join.columns(); + TableJoinColumn[] cols = join.columns(); - if (idProp == null) { - return null; - } - if (!idProp.isEmbedded()) { - // simple single scalar id - if (cols.length != 1){ - String msg = "No Imported Id column for ["+idProp+"] in table ["+join.getTable()+"]"; - logger.error(msg); - return null; - } else { - BeanProperty[] idProps = {idProp}; - return createImportedScalar(owner, cols[0], idProps, others); - } - } else { - // embedded id - BeanPropertyAssocOne embProp = (BeanPropertyAssocOne)idProp; - BeanProperty[] embBaseProps = embProp.getTargetDescriptor().propertiesBaseScalar(); - ImportedIdSimple[] scalars = createImportedList(owner, cols, embBaseProps, others); + if (idProp == null) { + return null; + } + if (!idProp.isEmbedded()) { + // simple single scalar id + if (cols.length != 1) { + String msg = "No Imported Id column for [" + idProp + "] in table [" + join.getTable() + "]"; + logger.error(msg); + return null; + } else { + BeanProperty[] idProps = {idProp}; + return createImportedScalar(owner, cols[0], idProps, others); + } + } else { + // embedded id + BeanPropertyAssocOne embProp = (BeanPropertyAssocOne) idProp; + BeanProperty[] embBaseProps = embProp.getTargetDescriptor().propertiesBaseScalar(); + ImportedIdSimple[] scalars = createImportedList(owner, cols, embBaseProps, others); - return new ImportedIdEmbedded(owner, embProp, scalars); - } - } + return new ImportedIdEmbedded(owner, embProp, scalars); + } + } - private ImportedIdSimple[] createImportedList(BeanPropertyAssoc owner, TableJoinColumn[] cols, BeanProperty[] props, BeanProperty[] others) { + private ImportedIdSimple[] createImportedList(BeanPropertyAssoc owner, TableJoinColumn[] cols, BeanProperty[] props, BeanProperty[] others) { - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList(); - for (int i = 0; i < cols.length; i++) { - list.add(createImportedScalar(owner, cols[i], props, others)); - } - - return ImportedIdSimple.sort(list); - } + for (int i = 0; i < cols.length; i++) { + list.add(createImportedScalar(owner, cols[i], props, others)); + } - private ImportedIdSimple createImportedScalar(BeanPropertyAssoc owner, TableJoinColumn col, BeanProperty[] props, BeanProperty[] others) { + return ImportedIdSimple.sort(list); + } - String matchColumn = col.getForeignDbColumn(); - String localColumn = col.getLocalDbColumn(); - - for (int j = 0; j < props.length; j++) { - if (props[j].getDbColumn().equalsIgnoreCase(matchColumn)) { - return new ImportedIdSimple(owner, localColumn, props[j], j); - } - } + private ImportedIdSimple createImportedScalar(BeanPropertyAssoc owner, TableJoinColumn col, BeanProperty[] props, BeanProperty[] others) { - for (int j = 0; j < others.length; j++) { - if (others[j].getDbColumn().equalsIgnoreCase(matchColumn)) { - return new ImportedIdSimple(owner, localColumn, others[j], j+props.length); - } - } - - String msg = "Error with the Join on ["+getFullBeanName() - +"]. Could not find the local match for ["+matchColumn+"] "//in table["+searchTable+"]?" - +" Perhaps an error in a @JoinColumn"; - throw new PersistenceException(msg); - } + String matchColumn = col.getForeignDbColumn(); + String localColumn = col.getLocalDbColumn(); + + for (int j = 0; j < props.length; j++) { + if (props[j].getDbColumn().equalsIgnoreCase(matchColumn)) { + return new ImportedIdSimple(owner, localColumn, props[j], j); + } + } + + for (int j = 0; j < others.length; j++) { + if (others[j].getDbColumn().equalsIgnoreCase(matchColumn)) { + return new ImportedIdSimple(owner, localColumn, others[j], j + props.length); + } + } + + String msg = "Error with the Join on [" + getFullBeanName() + + "]. Could not find the local match for [" + matchColumn + "] "//in table["+searchTable+"]?" + + " Perhaps an error in a @JoinColumn"; + throw new PersistenceException(msg); + } }