mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
Merge in v4 code changes
This commit is contained in:
commit
96e4b4640f
171 files changed
+2747
-3848
No files matched your search
@@ -8,6 +8,7 @@ import com.avaje.ebean.Transaction;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.bean.BeanCollectionAdd;
|
||||
import com.avaje.ebean.bean.BeanCollectionLoader;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
|
||||
/**
|
||||
@@ -41,22 +42,22 @@ public interface BeanCollectionHelp<T> {
|
||||
/**
|
||||
* Add a bean to the List Set or Map.
|
||||
*/
|
||||
public void add(BeanCollection<?> collection, Object bean);
|
||||
public void add(BeanCollection<?> collection, EntityBean bean);
|
||||
|
||||
/**
|
||||
* Create a lazy loading proxy for a List Set or Map.
|
||||
*/
|
||||
public BeanCollection<T> createReference(Object parentBean, String propertyName);
|
||||
public BeanCollection<T> createReference(EntityBean parentBean, String propertyName);
|
||||
|
||||
/**
|
||||
* Refresh the List Set or Map.
|
||||
*/
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean);
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, EntityBean parentBean);
|
||||
|
||||
/**
|
||||
* Apply the new refreshed BeanCollection to the appropriate property of the parent bean.
|
||||
*/
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean);
|
||||
public void refresh(BeanCollection<?> bc, EntityBean parentBean);
|
||||
|
||||
/**
|
||||
* Write the collection out as json.
|
||||
|
||||
@@ -15,9 +15,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.SqlUpdate;
|
||||
import com.avaje.ebean.Transaction;
|
||||
@@ -77,6 +74,8 @@ import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
import com.avaje.ebeaninternal.util.SortByClause;
|
||||
import com.avaje.ebeaninternal.util.SortByClause.Property;
|
||||
import com.avaje.ebeaninternal.util.SortByClauseParser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Describes Beans including their deployment information.
|
||||
@@ -180,12 +179,11 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
*/
|
||||
private final BeanDescriptorMap owner;
|
||||
|
||||
/**
|
||||
* The EntityBean type used to create new EntityBeans.
|
||||
*/
|
||||
private final Class<?> factoryType;
|
||||
|
||||
private final boolean enhancedBean;
|
||||
|
||||
private final String[] properties;
|
||||
|
||||
private final int propertyCount;
|
||||
|
||||
|
||||
/**
|
||||
* Intercept pre post on insert,update,delete and postLoad(). Server side
|
||||
@@ -223,7 +221,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
/**
|
||||
* Derived list of properties that are used for version concurrency checking.
|
||||
*/
|
||||
private final BeanProperty[] propertiesVersion;
|
||||
private final BeanProperty versionProperty;
|
||||
private final BeanProperty propertiesNaturalKey;
|
||||
|
||||
/**
|
||||
@@ -284,11 +282,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
*/
|
||||
final BeanProperty[] propertiesNonTransient;
|
||||
|
||||
/**
|
||||
* Set to true if the bean has version properties or an embedded bean has
|
||||
* version properties.
|
||||
*/
|
||||
private final BeanProperty propertyFirstVersion;
|
||||
|
||||
/**
|
||||
* Set when the Id property is a single non-embedded property. Can make life
|
||||
@@ -348,6 +341,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
|
||||
private final String descriptorId;
|
||||
|
||||
|
||||
private SpiEbeanServer ebeanServer;
|
||||
|
||||
private ServerCache beanCache;
|
||||
@@ -363,6 +357,8 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
this.cacheManager = owner.getCacheManager();
|
||||
this.serverName = owner.getServerName();
|
||||
this.entityType = deploy.getEntityType();
|
||||
this.properties = deploy.getProperties();
|
||||
this.propertyCount = this.properties.length;
|
||||
this.name = InternString.intern(deploy.getName());
|
||||
this.baseTableAlias = "t0";
|
||||
this.fullName = InternString.intern(deploy.getFullName());
|
||||
@@ -370,8 +366,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
|
||||
this.typeManager = typeManager;
|
||||
this.beanType = deploy.getBeanType();
|
||||
this.factoryType = deploy.getFactoryType();
|
||||
this.enhancedBean = beanType.equals(factoryType);
|
||||
this.namedQueries = deploy.getNamedQueries();
|
||||
this.namedUpdates = deploy.getNamedUpdates();
|
||||
|
||||
@@ -416,7 +410,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
this.propertiesBaseCompound = listHelper.getBaseCompound();
|
||||
this.propertiesId = listHelper.getId();
|
||||
this.propertiesNaturalKey = listHelper.getNaturalKey();
|
||||
this.propertiesVersion = listHelper.getVersion();
|
||||
this.versionProperty = listHelper.getVersionProperty();
|
||||
this.propertiesEmbedded = listHelper.getEmbedded();
|
||||
this.propertiesLocal = listHelper.getLocal();
|
||||
this.unidirectional = listHelper.getUnidirectional();
|
||||
@@ -440,7 +434,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
this.namesOfManyPropsHash = namesOfManyProps.hashCode();
|
||||
|
||||
this.derivedTableJoins = listHelper.getTableJoin();
|
||||
this.propertyFirstVersion = listHelper.getFirstVersion();
|
||||
|
||||
if (propertiesId.length == 1) {
|
||||
this.propertySingleId = propertiesId[0];
|
||||
@@ -491,19 +484,19 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
* Determine the concurrency mode based on the existence of a non-null version
|
||||
* property value.
|
||||
*/
|
||||
public ConcurrencyMode determineConcurrencyMode(Object bean) {
|
||||
public ConcurrencyMode determineConcurrencyMode(EntityBean bean) {
|
||||
|
||||
if (propertyFirstVersion == null) {
|
||||
if (versionProperty == null) {
|
||||
return ConcurrencyMode.NONE;
|
||||
}
|
||||
Object v = propertyFirstVersion.getValue(bean);
|
||||
Object v = versionProperty.getValue(bean);
|
||||
return (v == null) ? ConcurrencyMode.NONE : ConcurrencyMode.VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Set of embedded beans that have changed.
|
||||
*/
|
||||
public Set<String> getDirtyEmbeddedProperties(Object bean) {
|
||||
public Set<String> getDirtyEmbeddedProperties(EntityBean bean) {
|
||||
|
||||
HashSet<String> dirtyProperties = null;
|
||||
|
||||
@@ -532,7 +525,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
/**
|
||||
* Determine the non-null properties of the bean.
|
||||
*/
|
||||
public Set<String> determineLoadedProperties(Object bean) {
|
||||
public Set<String> determineLoadedProperties(EntityBean bean) {
|
||||
|
||||
HashSet<String> nonNullProps = new HashSet<String>();
|
||||
|
||||
@@ -563,6 +556,14 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
public int getPropertyCount() {
|
||||
return propertyCount;
|
||||
}
|
||||
|
||||
public String[] getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the Id properties first.
|
||||
* <p>
|
||||
@@ -663,10 +664,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
return inheritInfo != null;
|
||||
}
|
||||
|
||||
protected boolean isDynamicSubclass() {
|
||||
return !beanType.equals(factoryType);
|
||||
}
|
||||
|
||||
public SqlUpdate deleteById(Object id, List<Object> idList) {
|
||||
if (id != null) {
|
||||
return deleteById(id);
|
||||
@@ -902,10 +899,14 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
}
|
||||
}
|
||||
|
||||
public void cachePutBean(T bean) {
|
||||
cachePutBeanData((EntityBean)bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a bean into the bean cache.
|
||||
*/
|
||||
public void cachePutBeanData(Object bean) {
|
||||
public void cachePutBeanData(EntityBean bean) {
|
||||
|
||||
CachedBeanData beanData = CachedBeanDataFromBean.extract(this, bean);
|
||||
|
||||
@@ -936,10 +937,10 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
bc.checkEmptyLazyLoad();
|
||||
for (int i = 0; i < idList.size(); i++) {
|
||||
Object id = idList.get(i);
|
||||
Object refBean = targetDescriptor.createReference(readOnly, id, null);
|
||||
Object refBean = targetDescriptor.createReference(readOnly, id);
|
||||
EntityBeanIntercept refEbi = ((EntityBean) refBean)._ebean_getIntercept();
|
||||
|
||||
many.add(bc, refBean);
|
||||
many.add(bc, (EntityBean)refBean);
|
||||
persistenceContext.put(id, refBean);
|
||||
refEbi.setPersistenceContext(persistenceContext);
|
||||
}
|
||||
@@ -948,7 +949,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
|
||||
public void cachePutMany(BeanPropertyAssocMany<?> many, BeanCollection<?> bc, Object parentId) {
|
||||
BeanDescriptor<?> targetDescriptor = many.getTargetDescriptor();
|
||||
|
||||
ArrayList<Object> idList = new ArrayList<Object>();
|
||||
|
||||
// get the underlying collection of beans (in the List, Set or Map)
|
||||
@@ -998,14 +998,14 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
}
|
||||
}
|
||||
|
||||
T bean = (T) createBean();
|
||||
EntityBean bean = createBean();
|
||||
convertSetId(id, bean);
|
||||
if (Boolean.TRUE.equals(readOnly)) {
|
||||
((EntityBean) bean)._ebean_getIntercept().setReadOnly(true);
|
||||
bean._ebean_getIntercept().setReadOnly(true);
|
||||
}
|
||||
|
||||
CachedBeanDataToBean.load(this, bean, d);
|
||||
return bean;
|
||||
return (T)bean;
|
||||
}
|
||||
|
||||
public boolean cacheIsNaturalKey(String propName) {
|
||||
@@ -1035,13 +1035,16 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
* Remove a bean from the cache given its Id.
|
||||
*/
|
||||
public void cacheDelete(Object id, PersistRequestBean<T> deleteRequest) {
|
||||
if (queryCache != null) {
|
||||
queryCache.clear();
|
||||
}
|
||||
if (beanCache != null) {
|
||||
beanCache.remove(id);
|
||||
}
|
||||
for (int i = 0; i < propertiesOneImported.length; i++) {
|
||||
BeanPropertyAssocMany<?> many = propertiesOneImported[i].getRelationshipProperty();
|
||||
if (many != null) {
|
||||
propertiesOneImported[i].cacheDelete(true, deleteRequest.getBean());
|
||||
propertiesOneImported[i].cacheDelete(true, deleteRequest.getEntityBean());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1051,7 +1054,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
queryCache.clear();
|
||||
}
|
||||
for (int i = 0; i < propertiesOneImported.length; i++) {
|
||||
propertiesOneImported[i].cacheDelete(false, insertRequest.getBean());
|
||||
propertiesOneImported[i].cacheDelete(false, insertRequest.getEntityBean());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1060,17 +1063,22 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
*/
|
||||
public void cacheUpdate(Object id, PersistRequestBean<T> updateRequest) {
|
||||
|
||||
if (queryCache != null) {
|
||||
queryCache.clear();
|
||||
}
|
||||
|
||||
ServerCache cache = getBeanCache();
|
||||
CachedBeanData cd = (CachedBeanData) cache.get(id);
|
||||
if (cd != null) {
|
||||
CachedBeanData newCd = CachedBeanDataUpdate.update(this, cd, updateRequest);
|
||||
cache.put(id, newCd);
|
||||
if (newCd.isNaturalKeyUpdate() && naturalKeyCache != null) {
|
||||
Object oldKey = propertiesNaturalKey.getValue(updateRequest.getOldValues());
|
||||
Object newKey = propertiesNaturalKey.getValue(updateRequest.getBean());
|
||||
if (oldKey != null) {
|
||||
naturalKeyCache.remove(oldKey);
|
||||
}
|
||||
//FIXME: natural key invalidate old value
|
||||
//Object oldKey = propertiesNaturalKey.getValue(updateRequest.getOldValues());
|
||||
Object newKey = propertiesNaturalKey.getValue(updateRequest.getEntityBean());
|
||||
//if (oldKey != null) {
|
||||
// naturalKeyCache.remove(oldKey);
|
||||
//}
|
||||
if (newKey != null) {
|
||||
naturalKeyCache.put(newKey, id);
|
||||
}
|
||||
@@ -1087,24 +1095,24 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
}
|
||||
|
||||
public boolean loadFromCache(EntityBeanIntercept ebi) {
|
||||
Object bean = ebi.getOwner();
|
||||
EntityBean bean = ebi.getOwner();
|
||||
Object id = getId(bean);
|
||||
|
||||
return loadFromCache(bean, ebi, id);
|
||||
}
|
||||
|
||||
public boolean loadFromCache(Object bean, EntityBeanIntercept ebi, Object id) {
|
||||
public boolean loadFromCache(EntityBean bean, EntityBeanIntercept ebi, Object id) {
|
||||
|
||||
CachedBeanData cacheData = (CachedBeanData) getBeanCache().get(id);
|
||||
if (cacheData == null) {
|
||||
return false;
|
||||
}
|
||||
String lazyLoadProperty = ebi.getLazyLoadProperty();
|
||||
if (lazyLoadProperty != null && !cacheData.containsProperty(lazyLoadProperty)) {
|
||||
int lazyLoadProperty = ebi.getLazyLoadProperty();
|
||||
if (lazyLoadProperty > -1 && !cacheData.containsProperty(lazyLoadProperty)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CachedBeanDataToBean.load(this, bean, ebi, cacheData);
|
||||
CachedBeanDataToBean.load(this, bean, cacheData);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1315,7 +1323,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
/**
|
||||
* Create an EntityBean.
|
||||
*/
|
||||
public Object createBean() {
|
||||
public EntityBean createBean() {
|
||||
return createEntityBean();
|
||||
}
|
||||
|
||||
@@ -1327,6 +1335,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
// Note factoryType is used indirectly via beanReflect
|
||||
return (EntityBean) beanReflect.createEntityBean();
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
throw new PersistenceException(ex);
|
||||
}
|
||||
@@ -1348,25 +1357,18 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
}
|
||||
}
|
||||
try {
|
||||
Object bean = createBean();
|
||||
EntityBean eb = createBean();
|
||||
|
||||
convertSetId(id, bean);
|
||||
|
||||
EntityBean eb = (EntityBean) bean;
|
||||
convertSetId(id, eb);
|
||||
|
||||
EntityBeanIntercept ebi = eb._ebean_getIntercept();
|
||||
ebi.setBeanLoaderByServerName(ebeanServer.getName());
|
||||
|
||||
if (parent != null) {
|
||||
// Special case for a OneToOne ... parent
|
||||
// needs to be added to context prior to query
|
||||
ebi.setParentBean(parent);
|
||||
}
|
||||
|
||||
// Note: not creating proxies for many's...
|
||||
ebi.setReference();
|
||||
|
||||
return (T) bean;
|
||||
return (T) eb;
|
||||
|
||||
} catch (Exception ex) {
|
||||
throw new PersistenceException(ex);
|
||||
@@ -1443,7 +1445,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
/**
|
||||
* Get a property value from a bean of this type.
|
||||
*/
|
||||
public Object getValue(Object bean, String property) {
|
||||
public Object getValue(EntityBean bean, String property) {
|
||||
return getBeanProperty(property).getValue(bean);
|
||||
}
|
||||
|
||||
@@ -1473,13 +1475,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
return beanType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class type this BeanDescriptor describes.
|
||||
*/
|
||||
public Class<?> getFactoryType() {
|
||||
return factoryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bean class name this descriptor is used for.
|
||||
* <p>
|
||||
@@ -1511,16 +1506,10 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
* unique id then a Map is built with the keys being the names of the
|
||||
* properties that make up the unique id.
|
||||
*/
|
||||
public Object getId(Object bean) {
|
||||
public Object getId(EntityBean bean) {
|
||||
|
||||
if (propertySingleId != null) {
|
||||
if (inheritInfo != null && !enhancedBean) {
|
||||
// avoid generated method via forced reflection use
|
||||
return propertySingleId.getValueViaReflection(bean);
|
||||
|
||||
} else {
|
||||
return propertySingleId.getValue(bean);
|
||||
}
|
||||
}
|
||||
|
||||
// it is a concatenated id Not embedded
|
||||
@@ -1564,7 +1553,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
* after it has been converted to the correct type.
|
||||
* </p>
|
||||
*/
|
||||
public Object convertSetId(Object idValue, Object bean) {
|
||||
public Object convertSetId(Object idValue, EntityBean bean) {
|
||||
return idBinder.convertSetId(idValue, bean);
|
||||
}
|
||||
|
||||
@@ -1596,19 +1585,16 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
*/
|
||||
public boolean lazyLoadMany(EntityBeanIntercept ebi) {
|
||||
|
||||
String lazyLoadProperty = ebi.getLazyLoadProperty();
|
||||
BeanProperty lazyLoadBeanProp = getBeanProperty(lazyLoadProperty);
|
||||
int lazyLoadProperty = ebi.getLazyLoadProperty();
|
||||
if (lazyLoadProperty == -1) {
|
||||
return false;
|
||||
}
|
||||
String lazyLoadPropertyName = ebi.getProperty(lazyLoadProperty);
|
||||
BeanProperty lazyLoadBeanProp = getBeanProperty(lazyLoadPropertyName);
|
||||
|
||||
if (lazyLoadBeanProp instanceof BeanPropertyAssocMany<?>) {
|
||||
BeanPropertyAssocMany<?> manyProp = (BeanPropertyAssocMany<?>) lazyLoadBeanProp;
|
||||
manyProp.createReference(ebi.getOwner());
|
||||
Set<String> loadedProps = ebi.getLoadedProps();
|
||||
HashSet<String> newLoadedProps = new HashSet<String>();
|
||||
if (loadedProps != null) {
|
||||
newLoadedProps.addAll(loadedProps);
|
||||
}
|
||||
newLoadedProps.add(lazyLoadProperty);
|
||||
ebi.setLoadedProps(newLoadedProps);
|
||||
ebi.setLoadedLazy();
|
||||
return true;
|
||||
}
|
||||
@@ -1754,7 +1740,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
return prop;
|
||||
}
|
||||
|
||||
protected Object getBeanPropertyWithInheritance(Object bean, String propName) {
|
||||
protected Object getBeanPropertyWithInheritance(EntityBean bean, String propName) {
|
||||
|
||||
BeanDescriptor<?> desc = getBeanDescriptor(bean.getClass());
|
||||
BeanProperty beanProperty = desc.findBeanProperty(propName);
|
||||
@@ -2191,33 +2177,24 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
* Note that this DOES NOT find a version property on an embedded bean.
|
||||
* </p>
|
||||
*/
|
||||
public BeanProperty firstVersionProperty() {
|
||||
return propertyFirstVersion;
|
||||
public BeanProperty getVersionProperty() {
|
||||
return versionProperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this is an Update (rather than insert) given that the bean
|
||||
* is involved in a stateless update.
|
||||
*/
|
||||
public boolean isStatelessUpdate(Object bean) {
|
||||
if (propertyFirstVersion == null) {
|
||||
public boolean isStatelessUpdate(EntityBean bean) {
|
||||
if (versionProperty == null) {
|
||||
Object versionValue = getId(bean);
|
||||
return !DmlUtil.isNullOrZero(versionValue);
|
||||
} else {
|
||||
Object versionValue = propertyFirstVersion.getValue(bean);
|
||||
Object versionValue = versionProperty.getValue(bean);
|
||||
return !DmlUtil.isNullOrZero(versionValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 'Version' properties on this bean. These are 'Counter' or 'Update
|
||||
* Timestamp' type properties. Note version properties can also be on embedded
|
||||
* beans rather than on the bean itself.
|
||||
*/
|
||||
public BeanProperty[] propertiesVersion() {
|
||||
return propertiesVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scalar properties without the unique id or secondary table properties.
|
||||
*/
|
||||
@@ -2242,7 +2219,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
return propertiesLocal;
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJsonContext ctx, Object bean) {
|
||||
public void jsonWrite(WriteJsonContext ctx, EntityBean bean) {
|
||||
|
||||
if (bean != null) {
|
||||
|
||||
@@ -2268,7 +2245,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void jsonWriteProperties(WriteJsonContext ctx, Object bean) {
|
||||
private void jsonWriteProperties(WriteJsonContext ctx, EntityBean bean) {
|
||||
|
||||
boolean referenceBean = ctx.isReferenceBean();
|
||||
|
||||
@@ -2297,7 +2274,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
|
||||
if (!explicitAllProps && props == null) {
|
||||
// just render the loaded properties
|
||||
props = ctx.getLoadedProps();
|
||||
props = ((EntityBean)bean)._ebean_getIntercept().getLoadedPropertyNames();
|
||||
}
|
||||
if (props != null) {
|
||||
// render only the appropriate properties (when not all properties)
|
||||
@@ -2386,7 +2363,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
|
||||
private ReadBeanState jsonReadObject(ReadJsonContext ctx, String path) {
|
||||
|
||||
T bean = createJsonBean();
|
||||
EntityBean bean = createEntityBean();
|
||||
ctx.pushBean(bean, path, this);
|
||||
|
||||
do {
|
||||
@@ -2421,7 +2398,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
|
||||
if (isLoadedReference(loadedProps)) {
|
||||
ebi.setReference();
|
||||
} else {
|
||||
ebi.setLoadedProps(loadedProps);
|
||||
ebi.setLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ import com.avaje.ebeaninternal.server.lib.util.Dnode;
|
||||
import com.avaje.ebeaninternal.server.reflect.BeanReflect;
|
||||
import com.avaje.ebeaninternal.server.reflect.BeanReflectFactory;
|
||||
import com.avaje.ebeaninternal.server.reflect.BeanReflectGetter;
|
||||
import com.avaje.ebeaninternal.server.reflect.BeanReflectProperties;
|
||||
import com.avaje.ebeaninternal.server.reflect.BeanReflectSetter;
|
||||
import com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflectFactory;
|
||||
import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
@@ -1298,43 +1299,34 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
// abstract classes as well.
|
||||
|
||||
Class<?> beanType = desc.getBeanType();
|
||||
Class<?> factType = desc.getFactoryType();
|
||||
|
||||
BeanReflect beanReflect = reflectFactory.create(beanType, factType);
|
||||
BeanReflectProperties reflectProps = new BeanReflectProperties(beanType);
|
||||
|
||||
BeanReflect beanReflect = reflectFactory.create(beanType);
|
||||
desc.setBeanReflect(beanReflect);
|
||||
desc.setProperties(reflectProps.getProperties());
|
||||
|
||||
try {
|
||||
Iterator<DeployBeanProperty> it = desc.propertiesAll();
|
||||
while (it.hasNext()) {
|
||||
DeployBeanProperty prop = it.next();
|
||||
String propName = prop.getName();
|
||||
Iterator<DeployBeanProperty> it = desc.propertiesAll();
|
||||
while (it.hasNext()) {
|
||||
DeployBeanProperty prop = it.next();
|
||||
String propName = prop.getName();
|
||||
|
||||
Integer pos = reflectProps.getPropertyIndex(propName);
|
||||
if (pos == null) {
|
||||
throw new IllegalStateException("Property "+propName+" not found in "+reflectProps);
|
||||
}
|
||||
|
||||
if (desc.isAbstract() || beanReflect.isVanillaOnly()) {
|
||||
// use reflection in the case of imported abstract class
|
||||
// with
|
||||
// inheritance. Refer Bug 166
|
||||
prop.setGetter(ReflectGetter.create(prop));
|
||||
prop.setSetter(ReflectSetter.create(prop));
|
||||
|
||||
} else {
|
||||
// use generated code for getting setting property values
|
||||
BeanReflectGetter getter = beanReflect.getGetter(propName);
|
||||
BeanReflectSetter setter = beanReflect.getSetter(propName);
|
||||
prop.setGetter(getter);
|
||||
prop.setSetter(setter);
|
||||
if (getter == null) {
|
||||
// should never happen
|
||||
String m = "BeanReflectGetter for " + prop.getFullBeanName() + " was not found?";
|
||||
throw new RuntimeException(m);
|
||||
}
|
||||
}
|
||||
BeanReflectGetter getter = beanReflect.getGetter(propName, pos.intValue());
|
||||
BeanReflectSetter setter = beanReflect.getSetter(propName, pos.intValue());
|
||||
prop.setGetter(getter);
|
||||
prop.setSetter(setter);
|
||||
prop.setPropertyIndex(pos.intValue());
|
||||
|
||||
if (getter == null) {
|
||||
String m = "BeanReflectGetter for " + prop.getFullBeanName() + " was not found?";
|
||||
throw new RuntimeException(m);
|
||||
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
Class<?> superClass = desc.getBeanType().getSuperclass();
|
||||
String msg = "Error with [" + desc.getFullName() + "] I believe it is not enhanced but it's superClass [" + superClass + "] is?"
|
||||
+ " (You are not allowed to mix enhancement in a single inheritance hierarchy)";
|
||||
throw new PersistenceException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1345,13 +1337,15 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
*/
|
||||
private void setConcurrencyMode(DeployBeanDescriptor<?> desc) {
|
||||
|
||||
if (!desc.getConcurrencyMode().equals(ConcurrencyMode.ALL)) {
|
||||
if (desc.getConcurrencyMode() != null) {
|
||||
// concurrency mode explicitly set during deployment
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkForVersionProperties(desc)) {
|
||||
desc.setConcurrencyMode(ConcurrencyMode.VERSION);
|
||||
} else {
|
||||
desc.setConcurrencyMode(ConcurrencyMode.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1390,91 +1384,35 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
Class<?> beanClass = desc.getBeanType();
|
||||
|
||||
if (desc.isAbstract()) {
|
||||
if (hasEntityBeanInterface(beanClass)) {
|
||||
checkEnhanced(desc, beanClass);
|
||||
} else {
|
||||
checkSubclass(desc, beanClass);
|
||||
}
|
||||
return;
|
||||
if (!hasEntityBeanInterface(beanClass)) {
|
||||
throw new IllegalStateException("Bean "+beanClass+" is not enhanced?");
|
||||
}
|
||||
try {
|
||||
Object testBean = null;
|
||||
try {
|
||||
testBean = beanClass.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
// expected when no default constructor
|
||||
logger.debug("no default constructor on " + beanClass + " e:" + e);
|
||||
} catch (IllegalAccessException e) {
|
||||
// expected when no default constructor
|
||||
logger.debug("no default constructor on " + beanClass + " e:" + e);
|
||||
}
|
||||
if (testBean instanceof EntityBean == false) {
|
||||
checkSubclass(desc, beanClass);
|
||||
|
||||
} else {
|
||||
String className = beanClass.getName();
|
||||
try {
|
||||
// check that it really is enhanced (rather than mixed
|
||||
// enhancement)
|
||||
String marker = ((EntityBean) testBean)._ebean_getMarker();
|
||||
if (!marker.equals(className)) {
|
||||
String msg = "Error with [" + desc.getFullName() + "] It has not been enhanced but it's superClass ["
|
||||
+ beanClass.getSuperclass() + "] is?" + " (You are not allowed to mix enhancement in a single inheritance hierarchy)"
|
||||
+ " marker[" + marker + "] className[" + className + "]";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
} catch (AbstractMethodError e) {
|
||||
throw new PersistenceException("Old Ebean v1.0 enhancement detected in Ebean v1.1 - please do a clean enhancement.", e);
|
||||
}
|
||||
|
||||
checkEnhanced(desc, beanClass);
|
||||
}
|
||||
|
||||
} catch (PersistenceException ex) {
|
||||
throw ex;
|
||||
|
||||
} catch (Exception ex) {
|
||||
throw new PersistenceException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEnhanced(DeployBeanDescriptor<?> desc, Class<?> beanClass) {
|
||||
// the bean already implements EntityBean
|
||||
checkInheritedClasses(true, beanClass);
|
||||
desc.setFactoryType(beanClass);
|
||||
enhancedClassCount++;
|
||||
}
|
||||
checkInheritedClasses(beanClass);
|
||||
|
||||
private void checkSubclass(DeployBeanDescriptor<?> desc, Class<?> beanClass) {
|
||||
|
||||
throw new PersistenceException("Entity type "+beanClass+" is not an enhanced entity bean. Subclassing is not longer supported in Ebean");
|
||||
if (!beanClass.getName().startsWith("com.avaje.ebean.meta")) {
|
||||
enhancedClassCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the inherited classes are the same as the entity bean (aka all
|
||||
* enhanced or all dynamically subclassed).
|
||||
*/
|
||||
private void checkInheritedClasses(boolean ensureEnhanced, Class<?> beanClass) {
|
||||
private void checkInheritedClasses(Class<?> beanClass) {
|
||||
Class<?> superclass = beanClass.getSuperclass();
|
||||
if (Object.class.equals(superclass)) {
|
||||
// we got to the top of the inheritance
|
||||
return;
|
||||
}
|
||||
boolean isClassEnhanced = EntityBean.class.isAssignableFrom(superclass);
|
||||
|
||||
if (ensureEnhanced != isClassEnhanced) {
|
||||
String msg;
|
||||
if (ensureEnhanced) {
|
||||
msg = "Class [" + superclass + "] is not enhanced and [" + beanClass + "] is - (you can not mix!!)";
|
||||
} else {
|
||||
msg = "Class [" + superclass + "] is enhanced and [" + beanClass + "] is not - (you can not mix!!)";
|
||||
}
|
||||
throw new IllegalStateException(msg);
|
||||
if (!EntityBean.class.isAssignableFrom(superclass)) {
|
||||
throw new IllegalStateException("Super type "+superclass+" is not enhanced?");
|
||||
}
|
||||
|
||||
|
||||
// recursively continue up the inheritance hierarchy
|
||||
checkInheritedClasses(ensureEnhanced, superclass);
|
||||
checkInheritedClasses(superclass);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,16 +16,4 @@ public class BeanEmbeddedMeta {
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if at least one property is a version property.
|
||||
*/
|
||||
public boolean isEmbeddedVersion() {
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
if (properties[i].isVersion()){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.text.StringFormatter;
|
||||
import com.avaje.ebean.text.StringParser;
|
||||
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
|
||||
@@ -95,7 +96,7 @@ public final class BeanFkeyProperty implements ElPropertyValue {
|
||||
/**
|
||||
* Returns null as not an AssocOne.
|
||||
*/
|
||||
public Object[] getAssocOneIdValues(Object value) {
|
||||
public Object[] getAssocOneIdValues(EntityBean value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -159,7 +160,7 @@ public final class BeanFkeyProperty implements ElPropertyValue {
|
||||
throw new RuntimeException("ElPropertyDeploy only - not implemented");
|
||||
}
|
||||
|
||||
public void elSetReference(Object bean) {
|
||||
public void elSetReference(EntityBean bean) {
|
||||
throw new RuntimeException("ElPropertyDeploy only - not implemented");
|
||||
}
|
||||
|
||||
@@ -167,15 +168,15 @@ public final class BeanFkeyProperty implements ElPropertyValue {
|
||||
throw new RuntimeException("ElPropertyDeploy only - not implemented");
|
||||
}
|
||||
|
||||
public void elSetValue(Object bean, Object value, boolean populate, boolean reference) {
|
||||
public void elSetValue(EntityBean bean, Object value, boolean populate, boolean reference) {
|
||||
throw new RuntimeException("ElPropertyDeploy only - not implemented");
|
||||
}
|
||||
|
||||
public Object elGetValue(Object bean) {
|
||||
public Object elGetValue(EntityBean bean) {
|
||||
throw new RuntimeException("ElPropertyDeploy only - not implemented");
|
||||
}
|
||||
|
||||
public Object elGetReference(Object bean) {
|
||||
public Object elGetReference(EntityBean bean) {
|
||||
throw new RuntimeException("ElPropertyDeploy only - not implemented");
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.avaje.ebean.Transaction;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.bean.BeanCollectionAdd;
|
||||
import com.avaje.ebean.bean.BeanCollectionLoader;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.common.BeanList;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
|
||||
@@ -35,11 +36,11 @@ public final class BeanListHelp<T> implements BeanCollectionHelp<T> {
|
||||
public void setLoader(BeanCollectionLoader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal add bypassing any modify listening.
|
||||
*/
|
||||
public void add(BeanCollection<?> collection, Object bean) {
|
||||
public void add(BeanCollection<?> collection, EntityBean bean) {
|
||||
collection.internalAdd(bean);
|
||||
}
|
||||
|
||||
@@ -70,7 +71,7 @@ public final class BeanListHelp<T> implements BeanCollectionHelp<T> {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public void addBean(Object bean) {
|
||||
public void addBean(EntityBean bean) {
|
||||
list.add(bean);
|
||||
}
|
||||
}
|
||||
@@ -90,20 +91,20 @@ public final class BeanListHelp<T> implements BeanCollectionHelp<T> {
|
||||
return beanList;
|
||||
}
|
||||
|
||||
public BeanCollection<T> createReference(Object parentBean, String propertyName) {
|
||||
public BeanCollection<T> createReference(EntityBean parentBean, String propertyName) {
|
||||
|
||||
BeanList<T> beanList = new BeanList<T>(loader, parentBean, propertyName);
|
||||
beanList.setModifyListening(many.getModifyListenMode());
|
||||
return beanList;
|
||||
}
|
||||
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, EntityBean parentBean) {
|
||||
|
||||
BeanList<?> newBeanList = (BeanList<?>) server.findList(query, t);
|
||||
refresh(newBeanList, parentBean);
|
||||
}
|
||||
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean) {
|
||||
public void refresh(BeanCollection<?> bc, EntityBean parentBean) {
|
||||
|
||||
BeanList<?> newBeanList = (BeanList<?>) bc;
|
||||
|
||||
@@ -152,7 +153,7 @@ public final class BeanListHelp<T> implements BeanCollectionHelp<T> {
|
||||
ctx.appendComma();
|
||||
}
|
||||
Object detailBean = list.get(j);
|
||||
targetDescriptor.jsonWrite(ctx, detailBean);
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean)detailBean);
|
||||
}
|
||||
ctx.endAssocMany();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.avaje.ebean.Transaction;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.bean.BeanCollectionAdd;
|
||||
import com.avaje.ebean.bean.BeanCollectionLoader;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.common.BeanMap;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
|
||||
@@ -93,7 +94,7 @@ public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public void addBean(Object bean) {
|
||||
public void addBean(EntityBean bean) {
|
||||
Object keyValue = beanProperty.getValue(bean);
|
||||
map.put(keyValue, bean);
|
||||
}
|
||||
@@ -111,18 +112,16 @@ public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
|
||||
return beanMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal add bypassing any modify listening.
|
||||
*/
|
||||
public void add(BeanCollection<?> collection, Object bean) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void add(BeanCollection<?> collection, EntityBean bean) {
|
||||
|
||||
Object keyValue = beanProperty.getValueIntercept(bean);
|
||||
|
||||
((BeanMap<?,?>) collection).internalPut(keyValue, bean);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public BeanCollection<T> createReference(Object parentBean, String propertyName) {
|
||||
public BeanCollection<T> createReference(EntityBean parentBean, String propertyName) {
|
||||
|
||||
BeanMap beanMap = new BeanMap(loader, parentBean, propertyName);
|
||||
if (many != null) {
|
||||
@@ -136,7 +135,7 @@ public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
|
||||
refresh(newBeanMap, parentBean);
|
||||
}
|
||||
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean) {
|
||||
public void refresh(BeanCollection<?> bc, EntityBean parentBean) {
|
||||
|
||||
BeanMap<?, ?> newBeanMap = (BeanMap<?, ?>) bc;
|
||||
Map<?, ?> current = (Map<?, ?>) many.getValue(parentBean);
|
||||
@@ -187,7 +186,7 @@ public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
|
||||
}
|
||||
//FIXME: json write map key ...
|
||||
Object detailBean = entry.getValue();
|
||||
targetDescriptor.jsonWrite(ctx, detailBean);
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean)detailBean);
|
||||
}
|
||||
ctx.endAssocMany();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.avaje.ebeaninternal.server.text.json.ReadJsonContext;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
import com.avaje.ebeaninternal.util.ValueUtil;
|
||||
|
||||
/**
|
||||
* Description of a property of a bean. Includes its deployment information such
|
||||
@@ -141,6 +140,8 @@ public class BeanProperty implements ElPropertyValue {
|
||||
*/
|
||||
final String name;
|
||||
|
||||
final int propertyIndex;
|
||||
|
||||
/**
|
||||
* The reflected field.
|
||||
*/
|
||||
@@ -249,8 +250,6 @@ public class BeanProperty implements ElPropertyValue {
|
||||
|
||||
final DbEncryptFunction dbEncryptFunction;
|
||||
|
||||
final boolean dynamicSubclassWithInheritance;
|
||||
|
||||
int deployOrder;
|
||||
|
||||
final boolean jsonSerialize;
|
||||
@@ -265,11 +264,8 @@ public class BeanProperty implements ElPropertyValue {
|
||||
|
||||
this.descriptor = descriptor;
|
||||
this.name = InternString.intern(deploy.getName());
|
||||
if (descriptor != null) {
|
||||
this.dynamicSubclassWithInheritance = (descriptor.isDynamicSubclass() && descriptor.hasInheritance());
|
||||
} else {
|
||||
this.dynamicSubclassWithInheritance = false;
|
||||
}
|
||||
this.propertyIndex = deploy.getPropertyIndex();
|
||||
|
||||
this.unidirectionalShadow = deploy.isUndirectionalShadow();
|
||||
this.localEncrypted = deploy.isLocalEncrypted();
|
||||
this.dbEncrypted = deploy.isDbEncrypted();
|
||||
@@ -363,7 +359,7 @@ public class BeanProperty implements ElPropertyValue {
|
||||
|
||||
this.descriptor = source.descriptor;
|
||||
this.name = InternString.intern(source.getName());
|
||||
this.dynamicSubclassWithInheritance = source.dynamicSubclassWithInheritance;
|
||||
this.propertyIndex = source.propertyIndex;
|
||||
|
||||
this.dbColumn = InternString.intern(override.getDbColumn());
|
||||
this.sqlFormulaJoin = InternString.intern(override.getSqlFormulaJoin());
|
||||
@@ -473,14 +469,7 @@ public class BeanProperty implements ElPropertyValue {
|
||||
return formula;
|
||||
}
|
||||
|
||||
public boolean hasChanged(Object bean, Object oldValues) {
|
||||
Object value = getValue(bean);
|
||||
Object oldVal = getValue(oldValues);
|
||||
|
||||
return !ValueUtil.areEqual(value, oldVal);
|
||||
}
|
||||
|
||||
public void copyProperty(Object sourceBean, Object destBean) {
|
||||
public void copyProperty(EntityBean sourceBean, EntityBean destBean) {
|
||||
Object value = getValue(sourceBean);
|
||||
setValue(destBean, value);
|
||||
}
|
||||
@@ -561,7 +550,7 @@ public class BeanProperty implements ElPropertyValue {
|
||||
return owningType.isAssignableFrom(type);
|
||||
}
|
||||
|
||||
public Object readSetOwning(DbReadContext ctx, Object bean, Class<?> type) throws SQLException {
|
||||
public Object readSetOwning(DbReadContext ctx, EntityBean bean, Class<?> type) throws SQLException {
|
||||
|
||||
try {
|
||||
Object value = scalarType.read(ctx.getDataReader());
|
||||
@@ -599,7 +588,7 @@ public class BeanProperty implements ElPropertyValue {
|
||||
return scalarType.read(ctx.getDataReader());
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean, Class<?> type) throws SQLException {
|
||||
public Object readSet(DbReadContext ctx, EntityBean bean, Class<?> type) throws SQLException {
|
||||
|
||||
try {
|
||||
Object value = scalarType.read(ctx.getDataReader());
|
||||
@@ -690,15 +679,9 @@ public class BeanProperty implements ElPropertyValue {
|
||||
* Set the value of the property without interception or
|
||||
* PropertyChangeSupport.
|
||||
*/
|
||||
public void setValue(Object bean, Object value) {
|
||||
public void setValue(EntityBean bean, Object value) {
|
||||
try {
|
||||
if (bean instanceof EntityBean) {
|
||||
setter.set(bean, value);
|
||||
} else {
|
||||
Object[] args = new Object[1];
|
||||
args[0] = value;
|
||||
writeMethod.invoke(bean, args);
|
||||
}
|
||||
setter.set(bean, value);
|
||||
} catch (Exception ex) {
|
||||
String beanType = bean == null ? "null" : bean.getClass().getName();
|
||||
String msg = "set " + name + " on [" + descriptor + "] arg[" + value + "] type[" + beanType
|
||||
@@ -710,15 +693,9 @@ public class BeanProperty implements ElPropertyValue {
|
||||
/**
|
||||
* Set the value of the property.
|
||||
*/
|
||||
public void setValueIntercept(Object bean, Object value) {
|
||||
public void setValueIntercept(EntityBean bean, Object value) {
|
||||
try {
|
||||
if (bean instanceof EntityBean) {
|
||||
setter.setIntercept(bean, value);
|
||||
} else {
|
||||
Object[] args = new Object[1];
|
||||
args[0] = value;
|
||||
writeMethod.invoke(bean, args);
|
||||
}
|
||||
setter.setIntercept(bean, value);
|
||||
} catch (Exception ex) {
|
||||
String beanType = bean == null ? "null" : bean.getClass().getName();
|
||||
String msg = "setIntercept " + name + " on [" + descriptor + "] arg[" + value + "] type[" + beanType
|
||||
@@ -729,34 +706,20 @@ public class BeanProperty implements ElPropertyValue {
|
||||
|
||||
private static Object[] NO_ARGS = new Object[0];
|
||||
|
||||
/**
|
||||
* Return the property value taking inheritance into account.
|
||||
*/
|
||||
public Object getValueWithInheritance(Object bean) {
|
||||
if (dynamicSubclassWithInheritance) {
|
||||
return descriptor.getBeanPropertyWithInheritance(bean, name);
|
||||
}
|
||||
return getValue(bean);
|
||||
}
|
||||
|
||||
public Object getCacheDataValue(Object bean){
|
||||
public Object getCacheDataValue(EntityBean bean){
|
||||
return getValue(bean);
|
||||
}
|
||||
|
||||
public void setCacheDataValue(Object bean, Object cacheData, Object oldValues, boolean readOnly){
|
||||
public void setCacheDataValue(EntityBean bean, Object cacheData){
|
||||
setValue(bean, cacheData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the property method.
|
||||
*/
|
||||
public Object getValue(Object bean) {
|
||||
public Object getValue(EntityBean bean) {
|
||||
try {
|
||||
if (bean instanceof EntityBean) {
|
||||
return getter.get(bean);
|
||||
} else {
|
||||
return readMethod.invoke(bean, NO_ARGS);
|
||||
}
|
||||
return getter.get(bean);
|
||||
} catch (Exception ex) {
|
||||
String beanType = bean == null ? "null" : bean.getClass().getName();
|
||||
String msg = "get " + name + " on [" + descriptor + "] type[" + beanType + "] threw error.";
|
||||
@@ -777,13 +740,9 @@ public class BeanProperty implements ElPropertyValue {
|
||||
}
|
||||
}
|
||||
|
||||
public Object getValueIntercept(Object bean) {
|
||||
public Object getValueIntercept(EntityBean bean) {
|
||||
try {
|
||||
if (bean instanceof EntityBean) {
|
||||
return getter.getIntercept(bean);
|
||||
} else {
|
||||
return readMethod.invoke(bean, NO_ARGS);
|
||||
}
|
||||
return getter.getIntercept(bean);
|
||||
} catch (Exception ex) {
|
||||
String beanType = bean == null ? "null" : bean.getClass().getName();
|
||||
String msg = "getIntercept " + name + " on [" + descriptor + "] type[" + beanType + "] threw error.";
|
||||
@@ -798,24 +757,25 @@ public class BeanProperty implements ElPropertyValue {
|
||||
return convertToLogicalType(value);
|
||||
}
|
||||
|
||||
public void elSetReference(Object bean) {
|
||||
public void elSetReference(EntityBean bean) {
|
||||
throw new RuntimeException("Should not be called");
|
||||
}
|
||||
|
||||
public void elSetValue(Object bean, Object value, boolean populate, boolean reference) {
|
||||
public void elSetValue(EntityBean bean, Object value, boolean populate, boolean reference) {
|
||||
if (bean != null) {
|
||||
setValueIntercept(bean, value);
|
||||
// Not using setValueIntercept at this stage
|
||||
setValue(bean, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Object elGetValue(Object bean) {
|
||||
public Object elGetValue(EntityBean bean) {
|
||||
if (bean == null) {
|
||||
return null;
|
||||
}
|
||||
return getValueIntercept(bean);
|
||||
}
|
||||
|
||||
public Object elGetReference(Object bean) {
|
||||
public Object elGetReference(EntityBean bean) {
|
||||
throw new RuntimeException("Not expected to call this");
|
||||
}
|
||||
|
||||
@@ -826,6 +786,13 @@ public class BeanProperty implements ElPropertyValue {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the position of this property in the enhanced bean.
|
||||
*/
|
||||
public int getPropertyIndex() {
|
||||
return propertyIndex;
|
||||
}
|
||||
|
||||
public String getElName() {
|
||||
return name;
|
||||
}
|
||||
@@ -851,7 +818,7 @@ public class BeanProperty implements ElPropertyValue {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object[] getAssocOneIdValues(Object bean) {
|
||||
public Object[] getAssocOneIdValues(EntityBean bean) {
|
||||
// Returns null as not an AssocOne.
|
||||
return null;
|
||||
}
|
||||
@@ -1177,7 +1144,7 @@ public class BeanProperty implements ElPropertyValue {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void jsonWrite(WriteJsonContext ctx, Object bean) {
|
||||
public void jsonWrite(WriteJsonContext ctx, EntityBean bean) {
|
||||
if(!jsonSerialize){
|
||||
return;
|
||||
}
|
||||
@@ -1189,7 +1156,7 @@ public class BeanProperty implements ElPropertyValue {
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonRead(ReadJsonContext ctx, Object bean) {
|
||||
public void jsonRead(ReadJsonContext ctx, EntityBean bean) {
|
||||
if(!jsonDeserialize){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty {
|
||||
/**
|
||||
* Return true if the unique id properties are all not null for this bean.
|
||||
*/
|
||||
public boolean hasId(Object bean) {
|
||||
public boolean hasId(EntityBean bean) {
|
||||
|
||||
BeanDescriptor<?> targetDesc = getTargetDescriptor();
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.bean.BeanCollection.ModifyListenMode;
|
||||
import com.avaje.ebean.bean.BeanCollectionAdd;
|
||||
import com.avaje.ebean.bean.BeanCollectionLoader;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.deploy.id.ImportedId;
|
||||
@@ -158,22 +159,22 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(Object bean) {
|
||||
public Object getValue(EntityBean bean) {
|
||||
return super.getValue(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueIntercept(Object bean) {
|
||||
public Object getValueIntercept(EntityBean bean) {
|
||||
return super.getValueIntercept(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object bean, Object value) {
|
||||
public void setValue(EntityBean bean, Object value) {
|
||||
super.setValue(bean, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueIntercept(Object bean, Object value) {
|
||||
public void setValueIntercept(EntityBean bean, Object value) {
|
||||
super.setValueIntercept(bean, value);
|
||||
}
|
||||
|
||||
@@ -324,7 +325,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readSet(DbReadContext ctx, Object bean, Class<?> type) throws SQLException {
|
||||
public Object readSet(DbReadContext ctx, EntityBean bean, Class<?> type) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -342,21 +343,21 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void add(BeanCollection<?> collection, Object bean) {
|
||||
public void add(BeanCollection<?> collection, EntityBean bean) {
|
||||
help.add(collection, bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the appropriate list set or map.
|
||||
*/
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, EntityBean parentBean) {
|
||||
help.refresh(server, query, t, parentBean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the refreshed BeanCollection to the property of the parentBean.
|
||||
*/
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean) {
|
||||
public void refresh(BeanCollection<?> bc, EntityBean parentBean) {
|
||||
help.refresh(bc, parentBean);
|
||||
}
|
||||
|
||||
@@ -364,7 +365,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
* Return the Id values from the given bean.
|
||||
*/
|
||||
@Override
|
||||
public Object[] getAssocOneIdValues(Object bean) {
|
||||
public Object[] getAssocOneIdValues(EntityBean bean) {
|
||||
return targetDescriptor.getIdBinder().getIdValues(bean);
|
||||
}
|
||||
|
||||
@@ -435,7 +436,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
* Set the join properties from the parent bean to the child bean.
|
||||
* This is only valid for OneToMany and NOT valid for ManyToMany.
|
||||
*/
|
||||
public void setJoinValuesToChild(Object parent, Object child, Object mapKeyValue) {
|
||||
public void setJoinValuesToChild(EntityBean parent, EntityBean child, Object mapKeyValue) {
|
||||
|
||||
if (mapKeyProperty != null){
|
||||
mapKeyProperty.setValue(child, mapKeyValue);
|
||||
@@ -468,7 +469,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
return mapKey;
|
||||
}
|
||||
|
||||
public BeanCollection<?> createReferenceIfNull(Object parentBean) {
|
||||
public BeanCollection<?> createReferenceIfNull(EntityBean parentBean) {
|
||||
|
||||
Object v = getValue(parentBean);
|
||||
if (v instanceof BeanCollection<?>){
|
||||
@@ -479,7 +480,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public BeanCollection<?> createReference(Object parentBean) {
|
||||
public BeanCollection<?> createReference(EntityBean parentBean) {
|
||||
|
||||
BeanCollection<?> ref = help.createReference(parentBean, name);
|
||||
setValue(parentBean, ref);
|
||||
@@ -494,7 +495,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
return help.getBeanCollectionAdd(bc, mapKey);
|
||||
}
|
||||
|
||||
public Object getParentId(Object parentBean) {
|
||||
public Object getParentId(EntityBean parentBean) {
|
||||
return descriptor.getId(parentBean);
|
||||
}
|
||||
|
||||
@@ -518,8 +519,9 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
sqlUpd.addParameter(parentId);
|
||||
return;
|
||||
}
|
||||
EntityBean parent = (EntityBean)parentId;
|
||||
for (int i = 0; i < exportedProperties.length; i++) {
|
||||
Object embVal = exportedProperties[i].getValue(parentId);
|
||||
Object embVal = exportedProperties[i].getValue(parent);
|
||||
sqlUpd.addParameter(embVal);
|
||||
}
|
||||
}
|
||||
@@ -531,8 +533,9 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
|
||||
} else {
|
||||
|
||||
EntityBean parent = (EntityBean)parentId;
|
||||
for (int i = 0; i < exportedProperties.length; i++) {
|
||||
Object embVal = exportedProperties[i].getValue(parentId);
|
||||
Object embVal = exportedProperties[i].getValue(parent);
|
||||
q.setParameter(pos++, embVal);
|
||||
}
|
||||
}
|
||||
@@ -574,7 +577,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void setPredicates(SpiQuery<?> query, Object parentBean) {
|
||||
public void setPredicates(SpiQuery<?> query, EntityBean parentBean) {
|
||||
|
||||
if (manyToMany){
|
||||
// for ManyToMany lazy loading we need to include a
|
||||
@@ -586,7 +589,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
if (embeddedExportedProperties) {
|
||||
// use the EmbeddedId object instead of the parentBean
|
||||
BeanProperty[] uids = descriptor.propertiesId();
|
||||
parentBean = uids[0].getValue(parentBean);
|
||||
parentBean = (EntityBean)uids[0].getValue(parentBean);
|
||||
}
|
||||
|
||||
for (int i = 0; i < exportedProperties.length; i++) {
|
||||
@@ -741,7 +744,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
|
||||
public IntersectionRow buildManyDeleteChildren(Object parentBean, ArrayList<Object> excludeDetailIds) {
|
||||
public IntersectionRow buildManyDeleteChildren(EntityBean parentBean, ArrayList<Object> excludeDetailIds) {
|
||||
|
||||
IntersectionRow row = new IntersectionRow(tableJoin.getTable());
|
||||
if (excludeDetailIds != null && !excludeDetailIds.isEmpty()) {
|
||||
@@ -751,14 +754,14 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
return row;
|
||||
}
|
||||
|
||||
public IntersectionRow buildManyToManyDeleteChildren(Object parentBean) {
|
||||
public IntersectionRow buildManyToManyDeleteChildren(EntityBean parentBean) {
|
||||
|
||||
IntersectionRow row = new IntersectionRow(intersectionJoin.getTable());
|
||||
buildExport(row, parentBean);
|
||||
return row;
|
||||
}
|
||||
|
||||
public IntersectionRow buildManyToManyMapBean(Object parent, Object other) {
|
||||
public IntersectionRow buildManyToManyMapBean(EntityBean parent, EntityBean other) {
|
||||
|
||||
IntersectionRow row = new IntersectionRow(intersectionJoin.getTable());
|
||||
|
||||
@@ -767,11 +770,11 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
return row;
|
||||
}
|
||||
|
||||
private void buildExport(IntersectionRow row, Object parentBean) {
|
||||
private void buildExport(IntersectionRow row, EntityBean parentBean) {
|
||||
|
||||
if (embeddedExportedProperties) {
|
||||
BeanProperty[] uids = descriptor.propertiesId();
|
||||
parentBean = uids[0].getValue(parentBean);
|
||||
parentBean = (EntityBean)uids[0].getValue(parentBean);
|
||||
}
|
||||
for (int i = 0; i < exportedProperties.length; i++) {
|
||||
Object val = exportedProperties[i].getValue(parentBean);
|
||||
@@ -785,7 +788,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
* Set the predicates for lazy loading of the association.
|
||||
* Handles predicates for both OneToMany and ManyToMany.
|
||||
*/
|
||||
private void buildImport(IntersectionRow row, Object otherBean) {
|
||||
private void buildImport(IntersectionRow row, EntityBean otherBean) {
|
||||
|
||||
importedId.buildImport(row, otherBean);
|
||||
}
|
||||
@@ -793,12 +796,12 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
/**
|
||||
* Return true if the otherBean has an Id value.
|
||||
*/
|
||||
public boolean hasImportedId(Object otherBean) {
|
||||
public boolean hasImportedId(EntityBean otherBean) {
|
||||
|
||||
return null != targetDescriptor.getId(otherBean);
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJsonContext ctx, Object bean) {
|
||||
public void jsonWrite(WriteJsonContext ctx, EntityBean bean) {
|
||||
if(!this.jsonSerialize){
|
||||
return;
|
||||
}
|
||||
@@ -819,7 +822,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonRead(ReadJsonContext ctx, Object bean){
|
||||
public void jsonRead(ReadJsonContext ctx, EntityBean bean){
|
||||
if(!this.jsonDeserialize){
|
||||
return;
|
||||
}
|
||||
@@ -836,7 +839,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
// probably empty array
|
||||
break;
|
||||
}
|
||||
Object detailBean = detailBeanState.getBean();
|
||||
EntityBean detailBean = (EntityBean)detailBeanState.getBean();
|
||||
add.addBean(detailBean);
|
||||
|
||||
if (bean != null && childMasterProperty != null){
|
||||
|
||||
@@ -34,8 +34,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
|
||||
private final boolean oneToOneExported;
|
||||
|
||||
private final boolean embeddedVersion;
|
||||
|
||||
private final boolean importedPrimaryKey;
|
||||
|
||||
private final LocalHelp localHelp;
|
||||
@@ -78,11 +76,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
// Overriding of the columns and use table alias of owning BeanDescriptor
|
||||
BeanEmbeddedMeta overrideMeta = BeanEmbeddedMetaFactory.create(owner, deploy, descriptor);
|
||||
embeddedProps = overrideMeta.getProperties();
|
||||
if (id) {
|
||||
embeddedVersion = false;
|
||||
} else {
|
||||
embeddedVersion = overrideMeta.isEmbeddedVersion();
|
||||
}
|
||||
embeddedPropsMap = new HashMap<String, BeanProperty>();
|
||||
for (int i = 0; i < embeddedProps.length; i++) {
|
||||
embeddedPropsMap.put(embeddedProps[i].getName(), embeddedProps[i]);
|
||||
@@ -91,7 +84,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
} else {
|
||||
embeddedProps = null;
|
||||
embeddedPropsMap = null;
|
||||
embeddedVersion = false;
|
||||
}
|
||||
localHelp = createHelp(embedded, oneToOneExported);
|
||||
}
|
||||
@@ -130,11 +122,11 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public void cacheDelete(boolean clearOnNull, Object bean) {
|
||||
public void cacheDelete(boolean clearOnNull, EntityBean bean) {
|
||||
if (targetDescriptor.isBeanCaching() && relationshipProperty != null) {
|
||||
Object assocBean = getValue(bean);
|
||||
if (assocBean != null) {
|
||||
Object parentId = targetDescriptor.getId(assocBean);
|
||||
Object parentId = targetDescriptor.getId((EntityBean)assocBean);
|
||||
if (parentId != null) {
|
||||
targetDescriptor.cacheRemoveCachedManyIds(parentId, relationshipProperty.getName());
|
||||
return;
|
||||
@@ -249,8 +241,9 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
|
||||
} else {
|
||||
int pos = 1;
|
||||
EntityBean parent = (EntityBean)parentId;
|
||||
for (int i = 0; i < exportedProperties.length; i++) {
|
||||
Object embVal = exportedProperties[i].getValue(parentId);
|
||||
Object embVal = exportedProperties[i].getValue(parent);
|
||||
q.setParameter(pos++, embVal);
|
||||
}
|
||||
}
|
||||
@@ -270,41 +263,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasChangedEmbedded(Object bean, Object oldValues) {
|
||||
|
||||
Object embValue = getValue(oldValues);
|
||||
if (embValue instanceof EntityBean) {
|
||||
// the embedded bean .. has its own old values
|
||||
return ((EntityBean) embValue)._ebean_getIntercept().isNewOrDirty();
|
||||
}
|
||||
if (embValue == null) {
|
||||
return getValue(bean) != null;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChanged(Object bean, Object oldValues) {
|
||||
if (embedded) {
|
||||
return hasChangedEmbedded(bean, oldValues);
|
||||
}
|
||||
Object value = getValue(bean);
|
||||
Object oldVal = getValue(oldValues);
|
||||
if (oneToOneExported) {
|
||||
// FKey on other side
|
||||
return false;
|
||||
} else {
|
||||
if (value == null) {
|
||||
return oldVal != null;
|
||||
} else if (oldValues == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return importedId.hasChanged(value, oldVal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return meta data for the deployment of the embedded bean specific to this
|
||||
* property.
|
||||
@@ -342,13 +300,6 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
return oneToOneExported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the associated bean has version properties.
|
||||
*/
|
||||
public boolean isEmbeddedVersion() {
|
||||
return embeddedVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* If true this bean maps to the primary key.
|
||||
*/
|
||||
@@ -364,7 +315,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
return getPropertyType();
|
||||
}
|
||||
|
||||
public Object getCacheDataValue(Object bean){
|
||||
public Object getCacheDataValue(EntityBean bean){
|
||||
if (embedded) {
|
||||
throw new RuntimeException();
|
||||
} else {
|
||||
@@ -372,24 +323,19 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
if (ap == null){
|
||||
return null;
|
||||
} else {
|
||||
return targetDescriptor.getId(ap);
|
||||
return targetDescriptor.getId((EntityBean)ap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCacheDataValue(Object bean, Object cacheData, Object oldValues, boolean readOnly){
|
||||
@Override
|
||||
public void setCacheDataValue(EntityBean bean, Object cacheData){
|
||||
if (cacheData != null) {
|
||||
if (embedded){
|
||||
throw new RuntimeException();
|
||||
} else {
|
||||
T ref = targetDescriptor.createReference(Boolean.FALSE, cacheData, null);
|
||||
T ref = targetDescriptor.createReference(Boolean.FALSE, cacheData);
|
||||
setValue(bean, ref);
|
||||
if (oldValues != null){
|
||||
setValue(oldValues, ref);
|
||||
}
|
||||
if (readOnly){
|
||||
((EntityBean)ref)._ebean_intercept().setReadOnly(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -398,7 +344,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
* Return the Id values from the given bean.
|
||||
*/
|
||||
@Override
|
||||
public Object[] getAssocOneIdValues(Object bean) {
|
||||
public Object[] getAssocOneIdValues(EntityBean bean) {
|
||||
return targetDescriptor.getIdBinder().getIdValues(bean);
|
||||
}
|
||||
|
||||
@@ -451,7 +397,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
return targetDescriptor.createEntityBean();
|
||||
}
|
||||
|
||||
public void elSetReference(Object bean) {
|
||||
public void elSetReference(EntityBean bean) {
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value != null) {
|
||||
((EntityBean) value)._ebean_getIntercept().setReference();
|
||||
@@ -459,7 +405,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object elGetReference(Object bean) {
|
||||
public Object elGetReference(EntityBean bean) {
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value == null) {
|
||||
value = targetDescriptor.createEntityBean();
|
||||
@@ -565,7 +511,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readSet(DbReadContext ctx, Object bean, Class<?> type) throws SQLException {
|
||||
public Object readSet(DbReadContext ctx, EntityBean bean, Class<?> type) throws SQLException {
|
||||
boolean assignable = (type == null || owningType.isAssignableFrom(type));
|
||||
return localHelp.readSet(ctx, bean, assignable);
|
||||
}
|
||||
@@ -579,6 +525,24 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
// pass in null for the bean so any data read is ignored
|
||||
return localHelp.read(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EntityBean bean, Object value) {
|
||||
super.setValue(bean, value);
|
||||
if (value instanceof EntityBean) {
|
||||
EntityBean embedded = (EntityBean)value;
|
||||
embedded._ebean_getIntercept().setEmbeddedOwner(bean, propertyIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueIntercept(EntityBean bean, Object value) {
|
||||
super.setValueIntercept(bean, value);
|
||||
if (value instanceof EntityBean) {
|
||||
EntityBean embedded = (EntityBean)value;
|
||||
embedded._ebean_getIntercept().setEmbeddedOwner(bean, propertyIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIgnore(DbReadContext ctx) {
|
||||
@@ -615,7 +579,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
|
||||
abstract Object read(DbReadContext ctx) throws SQLException;
|
||||
|
||||
abstract Object readSet(DbReadContext ctx, Object bean, boolean assignAble) throws SQLException;
|
||||
abstract Object readSet(DbReadContext ctx, EntityBean bean, boolean assignAble) throws SQLException;
|
||||
|
||||
abstract void appendSelect(DbSqlContext ctx, boolean subQuery);
|
||||
|
||||
@@ -632,7 +596,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
Object readSet(DbReadContext ctx, Object bean, boolean assignable) throws SQLException {
|
||||
Object readSet(DbReadContext ctx, EntityBean bean, boolean assignable) throws SQLException {
|
||||
Object dbVal = read(ctx);
|
||||
if (bean != null && assignable) {
|
||||
// set back to the parent bean
|
||||
@@ -694,7 +658,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
Object readSet(DbReadContext ctx, Object bean, boolean assignable) throws SQLException {
|
||||
Object readSet(DbReadContext ctx, EntityBean bean, boolean assignable) throws SQLException {
|
||||
Object val = read(ctx);
|
||||
if (bean != null && assignable) {
|
||||
setValue(bean, val);
|
||||
@@ -733,16 +697,13 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
return existing;
|
||||
}
|
||||
|
||||
// parent always null for this case (but here to document)
|
||||
Object parent = null;
|
||||
|
||||
Boolean readOnly = ctx.isReadOnly();
|
||||
Object ref;
|
||||
if (targetInheritInfo != null) {
|
||||
// for inheritance hierarchy create the correct type for this row...
|
||||
ref = rowDescriptor.createReference(readOnly, id, parent);
|
||||
// for inheritance hierarchy create the correct type for this row...
|
||||
ref = rowDescriptor.createReference(readOnly, id);
|
||||
} else {
|
||||
ref = targetDescriptor.createReference(readOnly, id, parent);
|
||||
ref = targetDescriptor.createReference(readOnly, id);
|
||||
}
|
||||
|
||||
Object existingBean = ctx.getPersistenceContext().putIfAbsent(id, ref);
|
||||
@@ -802,7 +763,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
* Read and set a Reference bean.
|
||||
*/
|
||||
@Override
|
||||
Object readSet(DbReadContext ctx, Object bean, boolean assignable) throws SQLException {
|
||||
Object readSet(DbReadContext ctx, EntityBean bean, boolean assignable) throws SQLException {
|
||||
|
||||
Object dbVal = read(ctx);
|
||||
if (bean != null && assignable) {
|
||||
@@ -828,8 +789,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
Object parent = null;
|
||||
Object ref = targetDescriptor.createReference(ctx.isReadOnly(), id, parent);
|
||||
Object ref = targetDescriptor.createReference(ctx.isReadOnly(), id);
|
||||
|
||||
EntityBeanIntercept ebi = ((EntityBean) ref)._ebean_getIntercept();
|
||||
if (Boolean.TRUE.equals(ctx.isReadOnly())) {
|
||||
@@ -867,7 +827,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(WriteJsonContext ctx, Object bean) {
|
||||
public void jsonWrite(WriteJsonContext ctx, EntityBean bean) {
|
||||
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value == null){
|
||||
@@ -881,7 +841,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
ctx.pushParentBean(bean);
|
||||
ctx.beginAssocOne(name);
|
||||
BeanDescriptor<?> refDesc = descriptor.getBeanDescriptor(value.getClass());
|
||||
refDesc.jsonWrite(ctx, value);
|
||||
refDesc.jsonWrite(ctx, (EntityBean)value);
|
||||
ctx.endAssocOne();
|
||||
ctx.popParentBean();
|
||||
}
|
||||
@@ -889,7 +849,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonRead(ReadJsonContext ctx, Object bean){
|
||||
public void jsonRead(ReadJsonContext ctx, EntityBean bean){
|
||||
|
||||
T assocBean = targetDescriptor.jsonReadBean(ctx, name);
|
||||
setValue(bean, assocBean);
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyCompound;
|
||||
import com.avaje.ebeaninternal.server.el.ElPropertyChainBuilder;
|
||||
@@ -89,7 +90,7 @@ public class BeanPropertyCompound extends BeanProperty {
|
||||
* Get the underlying compound type.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getValueUnderlying(Object bean) {
|
||||
public Object getValueUnderlying(EntityBean bean) {
|
||||
|
||||
Object value = getValue(bean);
|
||||
if (typeConverter != null){
|
||||
@@ -97,27 +98,7 @@ public class BeanPropertyCompound extends BeanProperty {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(Object bean) {
|
||||
return super.getValue(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueIntercept(Object bean) {
|
||||
return super.getValueIntercept(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object bean, Object value) {
|
||||
super.setValue(bean, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueIntercept(Object bean, Object value) {
|
||||
super.setValueIntercept(bean, value);
|
||||
}
|
||||
|
||||
|
||||
public ElPropertyValue buildElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) {
|
||||
|
||||
if (chain == null) {
|
||||
@@ -154,7 +135,7 @@ public class BeanPropertyCompound extends BeanProperty {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readSet(DbReadContext ctx, Object bean, Class<?> type) throws SQLException {
|
||||
public Object readSet(DbReadContext ctx, EntityBean bean, Class<?> type) throws SQLException {
|
||||
|
||||
boolean assignable = (type == null || owningType.isAssignableFrom(type));
|
||||
|
||||
@@ -192,17 +173,17 @@ public class BeanPropertyCompound extends BeanProperty {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object elGetReference(Object bean) {
|
||||
public Object elGetReference(EntityBean bean) {
|
||||
return bean;
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJsonContext ctx, Object bean) {
|
||||
public void jsonWrite(WriteJsonContext ctx, EntityBean bean) {
|
||||
|
||||
Object valueObject = getValueIntercept(bean);
|
||||
compoundType.jsonWrite(ctx, valueObject, name);
|
||||
}
|
||||
|
||||
public void jsonRead(ReadJsonContext ctx, Object bean){
|
||||
public void jsonRead(ReadJsonContext ctx, EntityBean bean){
|
||||
|
||||
Object objValue = compoundType.jsonRead(ctx);
|
||||
setValue(bean, objValue);
|
||||
|
||||
@@ -73,7 +73,7 @@ public class BeanPropertyCompoundRoot {
|
||||
* Set the value of the property without interception or
|
||||
* PropertyChangeSupport.
|
||||
*/
|
||||
public void setRootValue(Object bean, Object value) {
|
||||
public void setRootValue(EntityBean bean, Object value) {
|
||||
try {
|
||||
if (bean instanceof EntityBean) {
|
||||
setter.set(bean, value);
|
||||
@@ -92,7 +92,7 @@ public class BeanPropertyCompoundRoot {
|
||||
/**
|
||||
* Set the value of the property.
|
||||
*/
|
||||
public void setRootValueIntercept(Object bean, Object value) {
|
||||
public void setRootValueIntercept(EntityBean bean, Object value) {
|
||||
try {
|
||||
if (bean instanceof EntityBean) {
|
||||
setter.setIntercept(bean, value);
|
||||
|
||||
+14
-12
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import com.avaje.ebeaninternal.server.type.CtCompoundProperty;
|
||||
@@ -30,20 +31,21 @@ public class BeanPropertyCompoundScalar extends BeanProperty {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object getValue(Object valueObject) {
|
||||
if (typeConverter != null){
|
||||
valueObject = typeConverter.unwrapValue(valueObject);
|
||||
public Object getValue(EntityBean valueObject) {
|
||||
Object val = valueObject;
|
||||
if (typeConverter != null){
|
||||
val = typeConverter.unwrapValue(val);
|
||||
}
|
||||
return ctProperty.getValue(valueObject);
|
||||
return ctProperty.getValue(val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object bean, Object value) {
|
||||
public void setValue(EntityBean bean, Object value) {
|
||||
setValueInCompound(bean, value, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setValueInCompound(Object bean, Object value, boolean intercept) {
|
||||
public void setValueInCompound(EntityBean bean, Object value, boolean intercept) {
|
||||
|
||||
Object compoundValue = ctProperty.setValue(bean, value);
|
||||
|
||||
@@ -65,7 +67,7 @@ public class BeanPropertyCompoundScalar extends BeanProperty {
|
||||
* No interception on embedded scalar values inside a CVO.
|
||||
*/
|
||||
@Override
|
||||
public void setValueIntercept(Object bean, Object value) {
|
||||
public void setValueIntercept(EntityBean bean, Object value) {
|
||||
setValueInCompound(bean, value, true);
|
||||
}
|
||||
|
||||
@@ -73,27 +75,27 @@ public class BeanPropertyCompoundScalar extends BeanProperty {
|
||||
* No interception on embedded scalar values inside a CVO.
|
||||
*/
|
||||
@Override
|
||||
public Object getValueIntercept(Object bean) {
|
||||
public Object getValueIntercept(EntityBean bean) {
|
||||
return getValue(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object elGetReference(Object bean) {
|
||||
public Object elGetReference(EntityBean bean) {
|
||||
return getValue(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object elGetValue(Object bean) {
|
||||
public Object elGetValue(EntityBean bean) {
|
||||
return getValue(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elSetReference(Object bean) {
|
||||
public void elSetReference(EntityBean bean) {
|
||||
super.elSetReference(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elSetValue(Object bean, Object value, boolean populate, boolean reference) {
|
||||
public void elSetValue(EntityBean bean, Object value, boolean populate, boolean reference) {
|
||||
super.elSetValue(bean, value, populate, reference);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.avaje.ebean.Transaction;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.bean.BeanCollectionAdd;
|
||||
import com.avaje.ebean.bean.BeanCollectionLoader;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.common.BeanSet;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
|
||||
@@ -72,15 +73,12 @@ public final class BeanSetHelp<T> implements BeanCollectionHelp<T> {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
public void addBean(Object bean) {
|
||||
public void addBean(EntityBean bean) {
|
||||
set.add(bean);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal add bypassing any modify listening.
|
||||
*/
|
||||
public void add(BeanCollection<?> collection, Object bean) {
|
||||
public void add(BeanCollection<?> collection, EntityBean bean) {
|
||||
collection.internalAdd(bean);
|
||||
}
|
||||
|
||||
@@ -95,20 +93,20 @@ public final class BeanSetHelp<T> implements BeanCollectionHelp<T> {
|
||||
return beanSet;
|
||||
}
|
||||
|
||||
public BeanCollection<T> createReference(Object parentBean, String propertyName) {
|
||||
public BeanCollection<T> createReference(EntityBean parentBean, String propertyName) {
|
||||
|
||||
BeanSet<T> beanSet = new BeanSet<T>(loader, parentBean, propertyName);
|
||||
beanSet.setModifyListening(many.getModifyListenMode());
|
||||
return beanSet;
|
||||
}
|
||||
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, EntityBean parentBean) {
|
||||
|
||||
BeanSet<?> newBeanSet = (BeanSet<?>)server.findSet(query, t);
|
||||
refresh(newBeanSet, parentBean);
|
||||
}
|
||||
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean) {
|
||||
public void refresh(BeanCollection<?> bc, EntityBean parentBean) {
|
||||
|
||||
BeanSet<?> newBeanSet = (BeanSet<?>)bc;
|
||||
|
||||
@@ -158,7 +156,7 @@ public final class BeanSetHelp<T> implements BeanCollectionHelp<T> {
|
||||
if (count++ > 0){
|
||||
ctx.appendComma();
|
||||
}
|
||||
targetDescriptor.jsonWrite(ctx, detailBean);
|
||||
targetDescriptor.jsonWrite(ctx, (EntityBean)detailBean);
|
||||
}
|
||||
ctx.endAssocMany();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.event.BeanPersistListener;
|
||||
|
||||
@@ -110,10 +109,10 @@ public class ChainedBeanPersistListener<T> implements BeanPersistListener<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updated(T bean, Set<String> updatedProperties) {
|
||||
public boolean updated(T bean) {
|
||||
boolean notifyCluster = false;
|
||||
for (int i = 0; i < chain.length; i++) {
|
||||
if (chain[i].updated(bean, updatedProperties)) {
|
||||
if (chain[i].updated(bean)) {
|
||||
notifyCluster = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class DRawSqlSelect {
|
||||
sqlTree.setSummary(desc.getName());
|
||||
|
||||
LinkedHashSet<String> includedProps = new LinkedHashSet<String>();
|
||||
SqlTreeProperties selectProps = new SqlTreeProperties();
|
||||
SqlTreeProperties selectProps = new SqlTreeProperties(desc);
|
||||
|
||||
for (int i = 0; i < selectColumns.length; i++) {
|
||||
|
||||
@@ -156,7 +156,6 @@ public class DRawSqlSelect {
|
||||
}
|
||||
}
|
||||
|
||||
selectProps.setIncludedProperties(includedProps);
|
||||
SqlTreeNode sqlRoot = new SqlTreeNodeRoot(desc, selectProps, null, withId);
|
||||
sqlTree.setRootNode(sqlRoot);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.deploy;
|
||||
import java.util.Map;
|
||||
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.EntityBeanIntercept;
|
||||
import com.avaje.ebean.bean.PersistenceContext;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
@@ -72,12 +73,12 @@ public interface DbReadContext {
|
||||
/**
|
||||
* Set back the bean that has just been loaded with its id.
|
||||
*/
|
||||
public void setLoadedBean(Object loadedBean, Object id, Object lazyLoadParentId);
|
||||
public void setLoadedBean(EntityBean loadedBean, Object id, Object lazyLoadParentId);
|
||||
|
||||
/**
|
||||
* Set back the 'detail' bean that has just been loaded.
|
||||
*/
|
||||
public void setLoadedManyBean(Object loadedBean);
|
||||
public void setLoadedManyBean(EntityBean loadedBean);
|
||||
|
||||
/**
|
||||
* Return the query mode.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
|
||||
/**
|
||||
@@ -32,7 +33,7 @@ public class ExportedProperty {
|
||||
/**
|
||||
* Return the property value from the bean.
|
||||
*/
|
||||
public Object getValue(Object bean){
|
||||
public Object getValue(EntityBean bean){
|
||||
return property.getValue(bean);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.deploy.id.IdBinder;
|
||||
import com.avaje.ebeaninternal.server.deploy.parse.DeployInheritInfo;
|
||||
@@ -223,7 +224,7 @@ public class InheritInfo {
|
||||
/**
|
||||
* Create an EntityBean for this type.
|
||||
*/
|
||||
public Object createBean() {
|
||||
public EntityBean createBean() {
|
||||
return descriptor.createBean();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import com.avaje.ebeaninternal.server.reflect.BeanReflectGetter;
|
||||
|
||||
/**
|
||||
* For abstract classes that hold the id property we need to
|
||||
* use reflection to get the id values some times.
|
||||
* <p>
|
||||
* This provides the BeanReflectGetter objects to do that.
|
||||
* </p>
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class ReflectGetter {
|
||||
|
||||
/**
|
||||
* Create a reflection based BeanReflectGetter for getting the
|
||||
* id from abstract inheritance hierarchy object.
|
||||
*/
|
||||
public static BeanReflectGetter create(DeployBeanProperty prop) {
|
||||
|
||||
if (!prop.isId()){
|
||||
// not expecting this to ever be used/called
|
||||
return new NonIdGetter(prop.getFullBeanName());
|
||||
|
||||
} else {
|
||||
String property = prop.getFullBeanName();
|
||||
Method readMethod = prop.getReadMethod();
|
||||
if (readMethod == null){
|
||||
String m = "Abstract class with no readMethod for "+property;
|
||||
throw new RuntimeException(m);
|
||||
}
|
||||
return new IdGetter(property, readMethod);
|
||||
}
|
||||
}
|
||||
|
||||
public static class IdGetter implements BeanReflectGetter {
|
||||
|
||||
public static final Object[] NO_ARGS = new Object[0];
|
||||
|
||||
private final Method readMethod;
|
||||
private final String property;
|
||||
|
||||
public IdGetter(String property, Method readMethod) {
|
||||
this.property = property;
|
||||
this.readMethod = readMethod;
|
||||
}
|
||||
|
||||
public Object get(Object bean) {
|
||||
try {
|
||||
return readMethod.invoke(bean, NO_ARGS);
|
||||
} catch (Exception e) {
|
||||
String m = "Error on ["+property+"] using readMethod "+readMethod;
|
||||
throw new RuntimeException(m, e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getIntercept(Object bean) {
|
||||
return get(bean);
|
||||
}
|
||||
}
|
||||
|
||||
public static class NonIdGetter implements BeanReflectGetter {
|
||||
|
||||
private final String property;
|
||||
|
||||
public NonIdGetter(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public Object get(Object bean) {
|
||||
|
||||
String m = "Not expecting this method to be called on ["+property
|
||||
+"] as it is a NON ID property on an abstract class";
|
||||
throw new RuntimeException(m);
|
||||
}
|
||||
|
||||
public Object getIntercept(Object bean) {
|
||||
return get(bean);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import com.avaje.ebeaninternal.server.reflect.BeanReflectSetter;
|
||||
|
||||
/**
|
||||
* A place holder for BeanReflectSetter that should never be called.
|
||||
* <p>
|
||||
* This is for properties of classes that are abstract and at the root
|
||||
* of an inheritance hierarchy.
|
||||
* </p>
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class ReflectSetter {
|
||||
|
||||
/**
|
||||
* Creates place holder objects that should never be called.
|
||||
*/
|
||||
public static BeanReflectSetter create(DeployBeanProperty prop) {
|
||||
|
||||
String fullName = prop.getFullBeanName();
|
||||
Method writeMethod = prop.getWriteMethod();
|
||||
return new RefCalled(fullName, writeMethod);
|
||||
}
|
||||
|
||||
static class RefCalled implements BeanReflectSetter {
|
||||
|
||||
final String fullName;
|
||||
final Method writeMethod;
|
||||
|
||||
RefCalled(String fullName, Method writeMethod) {
|
||||
this.fullName = fullName;
|
||||
this.writeMethod = writeMethod;
|
||||
}
|
||||
public void set(Object bean, Object value) {
|
||||
Object[] a = new Object[1];
|
||||
a[0] = value;
|
||||
try {
|
||||
writeMethod.invoke(bean, a);
|
||||
} catch (Exception e) {
|
||||
String beanType = bean == null ? "null" : bean.getClass().toString();
|
||||
String msg = "Error setting value on "+fullName+" value["+value+"] on type["+beanType+"]";
|
||||
throw new RuntimeException(msg, e);
|
||||
}
|
||||
}
|
||||
public void setIntercept(Object bean, Object value) {
|
||||
String msg = "Not expecting setIntercept to be called. Refer Bug 368";
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.deploy;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployTableJoin;
|
||||
@@ -103,7 +104,7 @@ public final class TableJoin {
|
||||
}
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean, Class<?> type) throws SQLException {
|
||||
public Object readSet(DbReadContext ctx, EntityBean bean, Class<?> type) throws SQLException {
|
||||
for (int i = 0, x = properties.length; i < x; i++) {
|
||||
properties[i].readSet(ctx, bean, type);
|
||||
}
|
||||
|
||||
+8
-2
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
@@ -17,7 +18,7 @@ public class GeneratedCounter implements GeneratedProperty {
|
||||
/**
|
||||
* Always returns a 1.
|
||||
*/
|
||||
public Object getInsertValue(BeanProperty prop, Object bean) {
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean) {
|
||||
Integer i = Integer.valueOf(1);
|
||||
return BasicTypeConverter.convert(i, numberType);
|
||||
}
|
||||
@@ -25,7 +26,7 @@ public class GeneratedCounter implements GeneratedProperty {
|
||||
/**
|
||||
* Increments the current value by one.
|
||||
*/
|
||||
public Object getUpdateValue(BeanProperty prop, Object bean) {
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean) {
|
||||
Number currVal = (Number) prop.getValue(bean);
|
||||
Integer nextVal = Integer.valueOf(currVal.intValue() + 1);
|
||||
return BasicTypeConverter.convert(nextVal, numberType);
|
||||
@@ -38,6 +39,11 @@ public class GeneratedCounter implements GeneratedProperty {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInAllUpdates() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include this in every insert setting initial counter value to 1.
|
||||
*/
|
||||
|
||||
+8
-2
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
@@ -14,14 +15,14 @@ public class GeneratedCounterInteger implements GeneratedProperty {
|
||||
/**
|
||||
* Always returns a 1.
|
||||
*/
|
||||
public Object getInsertValue(BeanProperty prop, Object bean) {
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean) {
|
||||
return Integer.valueOf(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the current value by one.
|
||||
*/
|
||||
public Object getUpdateValue(BeanProperty prop, Object bean) {
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean) {
|
||||
Integer i = (Integer) prop.getValue(bean);
|
||||
return Integer.valueOf(i.intValue() + 1);
|
||||
}
|
||||
@@ -32,6 +33,11 @@ public class GeneratedCounterInteger implements GeneratedProperty {
|
||||
public boolean includeInUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInAllUpdates() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include this in every insert setting initial counter value to 1.
|
||||
|
||||
+8
-2
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
@@ -14,14 +15,14 @@ public class GeneratedCounterLong implements GeneratedProperty {
|
||||
/**
|
||||
* Always returns a 1.
|
||||
*/
|
||||
public Object getInsertValue(BeanProperty prop, Object bean) {
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean) {
|
||||
return Long.valueOf(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the current value by one.
|
||||
*/
|
||||
public Object getUpdateValue(BeanProperty prop, Object bean) {
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean) {
|
||||
Long i = (Long) prop.getValue(bean);
|
||||
return Long.valueOf(i.longValue() + 1);
|
||||
}
|
||||
@@ -33,6 +34,11 @@ public class GeneratedCounterLong implements GeneratedProperty {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInAllUpdates() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include this in every insert setting initial counter value to 1.
|
||||
*/
|
||||
|
||||
+8
-2
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
@@ -12,14 +13,14 @@ public class GeneratedInsertDate implements GeneratedProperty {
|
||||
/**
|
||||
* Return the current time as a Timestamp.
|
||||
*/
|
||||
public Object getInsertValue(BeanProperty prop, Object bean) {
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean) {
|
||||
return new Date(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Just returns the beans original insert timestamp value.
|
||||
*/
|
||||
public Object getUpdateValue(BeanProperty prop, Object bean) {
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean) {
|
||||
return prop.getValue(bean);
|
||||
}
|
||||
|
||||
@@ -30,6 +31,11 @@ public class GeneratedInsertDate implements GeneratedProperty {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInAllUpdates() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true.
|
||||
*/
|
||||
|
||||
+8
-2
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
@@ -10,14 +11,14 @@ public class GeneratedInsertLong implements GeneratedProperty {
|
||||
/**
|
||||
* Return the current time as a Timestamp.
|
||||
*/
|
||||
public Object getInsertValue(BeanProperty prop, Object bean) {
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean) {
|
||||
return Long.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Just returns the beans original insert timestamp value.
|
||||
*/
|
||||
public Object getUpdateValue(BeanProperty prop, Object bean) {
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean) {
|
||||
return prop.getValue(bean);
|
||||
}
|
||||
|
||||
@@ -28,6 +29,11 @@ public class GeneratedInsertLong implements GeneratedProperty {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInAllUpdates() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true.
|
||||
*/
|
||||
|
||||
+8
-2
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
@@ -12,14 +13,14 @@ public class GeneratedInsertTimestamp implements GeneratedProperty {
|
||||
/**
|
||||
* Return the current time as a Timestamp.
|
||||
*/
|
||||
public Object getInsertValue(BeanProperty prop, Object bean) {
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean) {
|
||||
return new Timestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Just returns the beans original insert timestamp value.
|
||||
*/
|
||||
public Object getUpdateValue(BeanProperty prop, Object bean) {
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean) {
|
||||
return prop.getValue(bean);
|
||||
}
|
||||
|
||||
@@ -29,6 +30,11 @@ public class GeneratedInsertTimestamp implements GeneratedProperty {
|
||||
public boolean includeInUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInAllUpdates() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true.
|
||||
|
||||
+9
-2
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
@@ -11,12 +12,12 @@ public interface GeneratedProperty {
|
||||
/**
|
||||
* Get the generated insert value for a specific property of a bean.
|
||||
*/
|
||||
public Object getInsertValue(BeanProperty prop, Object bean);
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean);
|
||||
|
||||
/**
|
||||
* Get the generated update value for a specific property of a bean.
|
||||
*/
|
||||
public Object getUpdateValue(BeanProperty prop, Object bean);
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean);
|
||||
|
||||
/**
|
||||
* Return true if this should always be includes in an update statement.
|
||||
@@ -25,6 +26,12 @@ public interface GeneratedProperty {
|
||||
* </p>
|
||||
*/
|
||||
public boolean includeInUpdate();
|
||||
|
||||
/**
|
||||
* Return true if the property should be included in an update even if
|
||||
* it is not loaded (ie. Last Updated Timestamp).
|
||||
*/
|
||||
public boolean includeInAllUpdates();
|
||||
|
||||
/**
|
||||
* Return true if this should be included in insert statements.
|
||||
|
||||
+8
-2
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
@@ -13,14 +14,14 @@ public class GeneratedUpdateDate implements GeneratedProperty {
|
||||
/**
|
||||
* Return now as a Timestamp.
|
||||
*/
|
||||
public Object getInsertValue(BeanProperty prop, Object bean) {
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean) {
|
||||
return new Date(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return now as a Timestamp.
|
||||
*/
|
||||
public Object getUpdateValue(BeanProperty prop, Object bean) {
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean) {
|
||||
return new Date(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@@ -30,6 +31,11 @@ public class GeneratedUpdateDate implements GeneratedProperty {
|
||||
public boolean includeInUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInAllUpdates() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include this in every insert.
|
||||
|
||||
+8
-2
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
@@ -10,14 +11,14 @@ public class GeneratedUpdateLong implements GeneratedProperty {
|
||||
/**
|
||||
* Return now as a Timestamp.
|
||||
*/
|
||||
public Object getInsertValue(BeanProperty prop, Object bean) {
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean) {
|
||||
return Long.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return now as a Timestamp.
|
||||
*/
|
||||
public Object getUpdateValue(BeanProperty prop, Object bean) {
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean) {
|
||||
return Long.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@@ -28,6 +29,11 @@ public class GeneratedUpdateLong implements GeneratedProperty {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInAllUpdates() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include this in every insert.
|
||||
*/
|
||||
|
||||
+8
-2
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
/**
|
||||
@@ -12,14 +13,14 @@ public class GeneratedUpdateTimestamp implements GeneratedProperty {
|
||||
/**
|
||||
* Return now as a Timestamp.
|
||||
*/
|
||||
public Object getInsertValue(BeanProperty prop, Object bean) {
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean) {
|
||||
return new Timestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return now as a Timestamp.
|
||||
*/
|
||||
public Object getUpdateValue(BeanProperty prop, Object bean) {
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean) {
|
||||
return new Timestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@@ -30,6 +31,11 @@ public class GeneratedUpdateTimestamp implements GeneratedProperty {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInAllUpdates() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include this in every insert.
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
@@ -168,6 +170,6 @@ public interface IdBinder {
|
||||
* If the bean is not null, then the value is set to the bean.
|
||||
* </p>
|
||||
*/
|
||||
public Object convertSetId(Object idValue, Object bean);
|
||||
public Object convertSetId(Object idValue, EntityBean bean);
|
||||
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
@@ -150,7 +153,7 @@ public final class IdBinderEmbedded implements IdBinder {
|
||||
|
||||
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
request.addBindValue(props[i].getValue(value));
|
||||
request.addBindValue(props[i].getValue((EntityBean)value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,11 +209,11 @@ public final class IdBinderEmbedded implements IdBinder {
|
||||
return idInValueSql;
|
||||
}
|
||||
|
||||
public Object[] getIdValues(Object bean) {
|
||||
bean = embIdProperty.getValue(bean);
|
||||
public Object[] getIdValues(EntityBean bean) {
|
||||
Object val = embIdProperty.getValue(bean);
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue(bean);
|
||||
bindvalues[i] = props[i].getValue((EntityBean)val);
|
||||
}
|
||||
return bindvalues;
|
||||
}
|
||||
@@ -219,14 +222,14 @@ public final class IdBinderEmbedded implements IdBinder {
|
||||
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue(value);
|
||||
bindvalues[i] = props[i].getValue((EntityBean)value);
|
||||
}
|
||||
return bindvalues;
|
||||
}
|
||||
|
||||
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue(value);
|
||||
Object embFieldValue = props[i].getValue((EntityBean)value);
|
||||
sqlUpdate.addParameter(embFieldValue);
|
||||
}
|
||||
}
|
||||
@@ -234,14 +237,14 @@ public final class IdBinderEmbedded implements IdBinder {
|
||||
public void bindId(DataBind dataBind, Object value) throws SQLException {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue(value);
|
||||
Object embFieldValue = props[i].getValue((EntityBean)value);
|
||||
props[i].bind(dataBind, embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public Object readData(DataInput dataInput) throws IOException {
|
||||
|
||||
Object embId = idDesc.createBean();
|
||||
EntityBean embId = idDesc.createBean();
|
||||
boolean notNull = true;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
@@ -261,7 +264,7 @@ public final class IdBinderEmbedded implements IdBinder {
|
||||
|
||||
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue(idValue);
|
||||
Object embFieldValue = props[i].getValue((EntityBean)idValue);
|
||||
props[i].writeData(dataOutput, embFieldValue);
|
||||
}
|
||||
}
|
||||
@@ -274,7 +277,7 @@ public final class IdBinderEmbedded implements IdBinder {
|
||||
|
||||
public Object read(DbReadContext ctx) throws SQLException {
|
||||
|
||||
Object embId = idDesc.createBean();
|
||||
EntityBean embId = idDesc.createBean();
|
||||
boolean notNull = true;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
@@ -291,7 +294,7 @@ public final class IdBinderEmbedded implements IdBinder {
|
||||
}
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
|
||||
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException {
|
||||
|
||||
Object embId = read(ctx);
|
||||
if (embId != null) {
|
||||
@@ -385,7 +388,7 @@ public final class IdBinderEmbedded implements IdBinder {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object convertSetId(Object idValue, Object bean) {
|
||||
public Object convertSetId(Object idValue, EntityBean bean) {
|
||||
|
||||
// can not cast/convert if it is embedded
|
||||
if (bean != null) {
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
@@ -131,5 +133,4 @@ public final class IdBinderEmpty implements IdBinder {
|
||||
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import java.util.Map;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
@@ -89,7 +90,6 @@ public final class IdBinderMultiple implements IdBinder {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getPropertyCount() {
|
||||
return props.length;
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public final class IdBinderMultiple implements IdBinder {
|
||||
|
||||
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
request.addBindValue(props[i].getValue(value));
|
||||
request.addBindValue(props[i].getValue((EntityBean)value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public final class IdBinderMultiple implements IdBinder {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object[] getIdValues(Object bean){
|
||||
public Object[] getIdValues(EntityBean bean){
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue(bean);
|
||||
@@ -238,7 +238,7 @@ public final class IdBinderMultiple implements IdBinder {
|
||||
}
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
|
||||
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException {
|
||||
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
boolean notNull = false;
|
||||
@@ -367,7 +367,7 @@ public final class IdBinderMultiple implements IdBinder {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object convertSetId(Object idValue, Object bean) {
|
||||
public Object convertSetId(Object idValue, EntityBean bean) {
|
||||
|
||||
// allow Map or String for concatenated id
|
||||
Map<?,?> mapVal = null;
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
@@ -44,6 +46,7 @@ public final class IdBinderSimple implements IdBinder {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
public String getOrderBy(String pathPrefix, boolean ascending){
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -108,7 +111,7 @@ public final class IdBinderSimple implements IdBinder {
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] getIdValues(Object bean){
|
||||
public Object[] getIdValues(EntityBean bean){
|
||||
return new Object[]{idProperty.getValue(bean)};
|
||||
}
|
||||
|
||||
@@ -159,7 +162,7 @@ public final class IdBinderSimple implements IdBinder {
|
||||
idProperty.loadIgnore(ctx);
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
|
||||
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException {
|
||||
Object id = idProperty.read(ctx);
|
||||
if (id != null){
|
||||
idProperty.setValue(bean, id);
|
||||
@@ -198,7 +201,7 @@ public final class IdBinderSimple implements IdBinder {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object convertSetId(Object idValue, Object bean) {
|
||||
public Object convertSetId(Object idValue, EntityBean bean) {
|
||||
|
||||
if (!idValue.getClass().equals(expectedType)){
|
||||
idValue = scalarType.toBeanType(idValue);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.deploy.id;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
|
||||
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
|
||||
@@ -48,22 +49,17 @@ public interface ImportedId {
|
||||
/**
|
||||
* Append to the DML statement to the where clause.
|
||||
*/
|
||||
public void dmlWhere(GenerateDmlRequest request, Object bean);
|
||||
|
||||
/**
|
||||
* Return true if the id value has changed.
|
||||
*/
|
||||
public boolean hasChanged(Object bean, Object oldValues);
|
||||
public void dmlWhere(GenerateDmlRequest request, EntityBean bean);
|
||||
|
||||
/**
|
||||
* Bind the value from the bean.
|
||||
*/
|
||||
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException;
|
||||
public Object bind(BindableRequest request, EntityBean bean) throws SQLException;
|
||||
|
||||
/**
|
||||
* For inserting into ManyToMany intersection.
|
||||
*/
|
||||
public void buildImport(IntersectionRow row, Object other);
|
||||
public void buildImport(IntersectionRow row, EntityBean other);
|
||||
|
||||
/**
|
||||
* Used to derive a missing concatenated key from multiple imported keys.
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.sql.SQLException;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanFkeyProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
|
||||
@@ -68,7 +69,7 @@ public class ImportedIdEmbedded implements ImportedId {
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlWhere(GenerateDmlRequest request, Object bean){
|
||||
public void dmlWhere(GenerateDmlRequest request, EntityBean bean){
|
||||
|
||||
Object embeddedId = null;
|
||||
if (bean != null) {
|
||||
@@ -82,10 +83,10 @@ public class ImportedIdEmbedded implements ImportedId {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
EntityBean embedded = (EntityBean)embeddedId;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isDbUpdatable()) {
|
||||
Object value = imported[i].foreignProperty.getValue(embeddedId);
|
||||
Object value = imported[i].foreignProperty.getValue(embedded);
|
||||
if (value == null){
|
||||
request.appendColumnIsNull(imported[i].localDbColumn);
|
||||
} else {
|
||||
@@ -96,14 +97,7 @@ public class ImportedIdEmbedded implements ImportedId {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasChanged(Object bean, Object oldValues) {
|
||||
Object id = foreignAssocOne.getValue(bean);
|
||||
Object oldId = foreignAssocOne.getValue(oldValues);
|
||||
|
||||
return !ValueUtil.areEqual(id, oldId);
|
||||
}
|
||||
|
||||
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
|
||||
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object embeddedId = null;
|
||||
|
||||
@@ -114,15 +108,16 @@ public class ImportedIdEmbedded implements ImportedId {
|
||||
if (embeddedId == null){
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isUpdateable()) {
|
||||
request.bind(null, imported[i].foreignProperty, imported[i].localDbColumn, true);
|
||||
request.bind(null, imported[i].foreignProperty, imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
EntityBean embedded = (EntityBean)embeddedId;
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isUpdateable()) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(embeddedId);
|
||||
request.bind(scalarValue, imported[i].foreignProperty, imported[i].localDbColumn, true);
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(embedded);
|
||||
request.bind(scalarValue, imported[i].foreignProperty, imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,9 +125,9 @@ public class ImportedIdEmbedded implements ImportedId {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void buildImport(IntersectionRow row, Object other){
|
||||
public void buildImport(IntersectionRow row, EntityBean other){
|
||||
|
||||
Object embeddedId = foreignAssocOne.getValue(other);
|
||||
EntityBean embeddedId = (EntityBean)foreignAssocOne.getValue(other);
|
||||
if (embeddedId == null){
|
||||
String msg = "Foreign Key value null?";
|
||||
throw new PersistenceException(msg);
|
||||
|
||||
@@ -2,13 +2,13 @@ package com.avaje.ebeaninternal.server.deploy.id;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
|
||||
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
|
||||
import com.avaje.ebeaninternal.util.ValueUtil;
|
||||
|
||||
/**
|
||||
* Imported concatenated id that is not embedded.
|
||||
@@ -55,7 +55,7 @@ public class ImportedIdMultiple implements ImportedId {
|
||||
}
|
||||
}
|
||||
|
||||
public void dmlWhere(GenerateDmlRequest request, Object bean){
|
||||
public void dmlWhere(GenerateDmlRequest request, EntityBean bean){
|
||||
if (bean == null){
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
request.appendColumnIsNull(imported[i].localDbColumn);
|
||||
@@ -72,32 +72,19 @@ public class ImportedIdMultiple implements ImportedId {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasChanged(Object bean, Object oldValues) {
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
Object id = imported[i].foreignProperty.getValue(bean);
|
||||
Object oldId = imported[i].foreignProperty.getValue(oldValues);
|
||||
if (!ValueUtil.areEqual(id, oldId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
|
||||
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
if (imported[i].owner.isUpdateable()) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(bean);
|
||||
request.bind(scalarValue, imported[i].foreignProperty, imported[i].localDbColumn, true);
|
||||
request.bind(scalarValue, imported[i].foreignProperty, imported[i].localDbColumn);
|
||||
}
|
||||
}
|
||||
// hmmm, not worrying about this just yet
|
||||
return null;
|
||||
}
|
||||
|
||||
public void buildImport(IntersectionRow row, Object other){
|
||||
public void buildImport(IntersectionRow row, EntityBean other){
|
||||
|
||||
for (int i = 0; i < imported.length; i++) {
|
||||
Object scalarValue = imported[i].foreignProperty.getValue(other);
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.List;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanFkeyProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
@@ -15,7 +16,6 @@ import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
|
||||
import com.avaje.ebeaninternal.server.deploy.IntersectionRow;
|
||||
import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
import com.avaje.ebeaninternal.server.persist.dmlbind.BindableRequest;
|
||||
import com.avaje.ebeaninternal.util.ValueUtil;
|
||||
|
||||
/**
|
||||
* Single scalar imported id.
|
||||
@@ -90,11 +90,11 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
|
||||
return localDbColumn;
|
||||
}
|
||||
|
||||
private Object getIdValue(Object bean) {
|
||||
return foreignProperty.getValueWithInheritance(bean);
|
||||
}
|
||||
private Object getIdValue(EntityBean bean) {
|
||||
return foreignProperty.getValue(bean);
|
||||
}
|
||||
|
||||
public void buildImport(IntersectionRow row, Object other){
|
||||
public void buildImport(IntersectionRow row, EntityBean other){
|
||||
|
||||
Object value = getIdValue(other);
|
||||
if (value == null){
|
||||
@@ -114,7 +114,7 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
|
||||
request.appendColumn(localDbColumn);
|
||||
}
|
||||
|
||||
public void dmlWhere(GenerateDmlRequest request, Object bean){
|
||||
public void dmlWhere(GenerateDmlRequest request, EntityBean bean){
|
||||
|
||||
if (owner.isDbUpdatable()){
|
||||
Object value = null;
|
||||
@@ -129,25 +129,13 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasChanged(Object bean, Object oldValues) {
|
||||
|
||||
Object id = getIdValue(bean);
|
||||
|
||||
if (oldValues != null){
|
||||
Object oldId = getIdValue(oldValues);
|
||||
return !ValueUtil.areEqual(id, oldId);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object bind(BindableRequest request, Object bean, boolean bindNull) throws SQLException {
|
||||
public Object bind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object value = null;
|
||||
if (bean != null){
|
||||
value = getIdValue(bean);
|
||||
}
|
||||
request.bind(value, foreignProperty, localDbColumn, bindNull);
|
||||
request.bind(value, foreignProperty, localDbColumn);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
+11
-24
@@ -62,11 +62,6 @@ public class DeployBeanDescriptor<T> {
|
||||
*/
|
||||
private LinkedHashMap<String, DeployBeanProperty> propMap = new LinkedHashMap<String, DeployBeanProperty>();
|
||||
|
||||
/**
|
||||
* The type of bean this describes.
|
||||
*/
|
||||
private final Class<T> beanType;
|
||||
|
||||
private EntityType entityType;
|
||||
|
||||
private final Map<String, DeployNamedQuery> namedQueries = new LinkedHashMap<String, DeployNamedQuery>();
|
||||
@@ -104,7 +99,7 @@ public class DeployBeanDescriptor<T> {
|
||||
/**
|
||||
* The concurrency mode for beans of this type.
|
||||
*/
|
||||
private ConcurrencyMode concurrencyMode = ConcurrencyMode.ALL;
|
||||
private ConcurrencyMode concurrencyMode;
|
||||
|
||||
private boolean updateChangesOnly;
|
||||
|
||||
@@ -131,11 +126,12 @@ public class DeployBeanDescriptor<T> {
|
||||
* faster than reflection at this stage.
|
||||
*/
|
||||
private BeanReflect beanReflect;
|
||||
private String[] properties;
|
||||
|
||||
/**
|
||||
* The EntityBean type used to create new EntityBeans.
|
||||
*/
|
||||
private Class<?> factoryType;
|
||||
private Class<T> beanType;
|
||||
|
||||
private List<BeanPersistController> persistControllers = new ArrayList<BeanPersistController>();
|
||||
private List<BeanPersistListener<T>> persistListeners = new ArrayList<BeanPersistListener<T>>();
|
||||
@@ -298,6 +294,14 @@ public class DeployBeanDescriptor<T> {
|
||||
return namedUpdates;
|
||||
}
|
||||
|
||||
public String[] getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(String[] props) {
|
||||
this.properties = props;
|
||||
}
|
||||
|
||||
public BeanReflect getBeanReflect() {
|
||||
return beanReflect;
|
||||
}
|
||||
@@ -309,23 +313,6 @@ public class DeployBeanDescriptor<T> {
|
||||
return beanType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class type this BeanDescriptor describes.
|
||||
*/
|
||||
public Class<?> getFactoryType() {
|
||||
return factoryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class used to create new EntityBean instances.
|
||||
* <p>
|
||||
* Normally this would be a subclass dynamically generated for this bean.
|
||||
* </p>
|
||||
*/
|
||||
public void setFactoryType(Class<?> factoryType) {
|
||||
this.factoryType = factoryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the BeanReflect used to create new instances of an EntityBean. This
|
||||
* could use reflection or code generation to do this.
|
||||
|
||||
@@ -198,6 +198,8 @@ public class DeployBeanProperty {
|
||||
*/
|
||||
private Method writeMethod;
|
||||
|
||||
private int propertyIndex;
|
||||
|
||||
private BeanReflectGetter getter;
|
||||
|
||||
private BeanReflectSetter setter;
|
||||
@@ -410,6 +412,14 @@ public class DeployBeanProperty {
|
||||
this.scalarType = scalarType;
|
||||
}
|
||||
|
||||
public int getPropertyIndex() {
|
||||
return propertyIndex;
|
||||
}
|
||||
|
||||
public void setPropertyIndex(int propertyIndex) {
|
||||
this.propertyIndex = propertyIndex;
|
||||
}
|
||||
|
||||
public BeanReflectGetter getGetter() {
|
||||
return getter;
|
||||
}
|
||||
|
||||
+304
-305
@@ -5,6 +5,9 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.avaje.ebean.bean.BeanCollection.ModifyListenMode;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptorMap;
|
||||
@@ -20,347 +23,343 @@ import com.avaje.ebeaninternal.server.deploy.TableJoin;
|
||||
*/
|
||||
public class DeployBeanPropertyLists {
|
||||
|
||||
private BeanProperty derivedFirstVersionProp;
|
||||
private static final Logger logger = LoggerFactory.getLogger(DeployBeanPropertyLists.class);
|
||||
|
||||
private final BeanDescriptor<?> desc;
|
||||
private BeanProperty versionProperty;
|
||||
|
||||
private final LinkedHashMap<String, BeanProperty> propertyMap;
|
||||
private final BeanDescriptor<?> desc;
|
||||
|
||||
private final ArrayList<BeanProperty> ids = new ArrayList<BeanProperty>();
|
||||
private final LinkedHashMap<String, BeanProperty> propertyMap;
|
||||
|
||||
private final ArrayList<BeanProperty> version = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> ids = new ArrayList<BeanProperty>();
|
||||
|
||||
private final ArrayList<BeanProperty> local = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> local = new ArrayList<BeanProperty>();
|
||||
|
||||
private final ArrayList<BeanProperty> manys = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> nonManys = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> manys = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> nonManys = new ArrayList<BeanProperty>();
|
||||
|
||||
private final ArrayList<BeanProperty> ones = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> ones = new ArrayList<BeanProperty>();
|
||||
|
||||
private final ArrayList<BeanProperty> onesExported = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> onesExported = new ArrayList<BeanProperty>();
|
||||
|
||||
private final ArrayList<BeanProperty> onesImported = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> onesImported = new ArrayList<BeanProperty>();
|
||||
|
||||
private final ArrayList<BeanProperty> embedded = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> embedded = new ArrayList<BeanProperty>();
|
||||
|
||||
private final ArrayList<BeanProperty> baseScalar = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> baseScalar = new ArrayList<BeanProperty>();
|
||||
|
||||
private final ArrayList<BeanPropertyCompound> baseCompound = new ArrayList<BeanPropertyCompound>();
|
||||
private final ArrayList<BeanPropertyCompound> baseCompound = new ArrayList<BeanPropertyCompound>();
|
||||
|
||||
private final ArrayList<BeanProperty> transients = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> transients = new ArrayList<BeanProperty>();
|
||||
|
||||
private final ArrayList<BeanProperty> nonTransients = new ArrayList<BeanProperty>();
|
||||
private final ArrayList<BeanProperty> nonTransients = new ArrayList<BeanProperty>();
|
||||
|
||||
private final TableJoin[] tableJoins;
|
||||
private final TableJoin[] tableJoins;
|
||||
|
||||
private final BeanPropertyAssocOne<?> unidirectional;
|
||||
private final BeanPropertyAssocOne<?> unidirectional;
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public DeployBeanPropertyLists(BeanDescriptorMap owner, BeanDescriptor<?> desc, DeployBeanDescriptor<?> deploy) {
|
||||
this.desc = desc;
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public DeployBeanPropertyLists(BeanDescriptorMap owner, BeanDescriptor<?> desc, DeployBeanDescriptor<?> deploy) {
|
||||
this.desc = desc;
|
||||
|
||||
DeployBeanPropertyAssocOne<?> deployUnidirectional = deploy.getUnidirectional();
|
||||
if (deployUnidirectional == null) {
|
||||
unidirectional = null;
|
||||
DeployBeanPropertyAssocOne<?> deployUnidirectional = deploy.getUnidirectional();
|
||||
if (deployUnidirectional == null) {
|
||||
unidirectional = null;
|
||||
} else {
|
||||
unidirectional = new BeanPropertyAssocOne(owner, desc, deployUnidirectional);
|
||||
}
|
||||
|
||||
this.propertyMap = new LinkedHashMap<String, BeanProperty>();
|
||||
|
||||
Iterator<DeployBeanProperty> deployIt = deploy.propertiesAll();
|
||||
while (deployIt.hasNext()) {
|
||||
DeployBeanProperty deployProp = deployIt.next();
|
||||
BeanProperty beanProp = createBeanProperty(owner, deployProp);
|
||||
propertyMap.put(beanProp.getName(), beanProp);
|
||||
}
|
||||
|
||||
Iterator<BeanProperty> it = propertyMap.values().iterator();
|
||||
|
||||
int order = 0;
|
||||
while (it.hasNext()) {
|
||||
BeanProperty prop = it.next();
|
||||
prop.setDeployOrder(order++);
|
||||
allocateToList(prop);
|
||||
}
|
||||
|
||||
List<DeployTableJoin> deployTableJoins = deploy.getTableJoins();
|
||||
tableJoins = new TableJoin[deployTableJoins.size()];
|
||||
for (int i = 0; i < deployTableJoins.size(); i++) {
|
||||
tableJoins[i] = new TableJoin(deployTableJoins.get(i), propertyMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the unidirectional.
|
||||
*/
|
||||
public BeanPropertyAssocOne<?> getUnidirectional() {
|
||||
return unidirectional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate the property to a list.
|
||||
*/
|
||||
private void allocateToList(BeanProperty prop) {
|
||||
if (prop.isTransient()) {
|
||||
transients.add(prop);
|
||||
return;
|
||||
}
|
||||
if (prop.isId()) {
|
||||
ids.add(prop);
|
||||
return;
|
||||
} else {
|
||||
nonTransients.add(prop);
|
||||
}
|
||||
|
||||
if (desc.getInheritInfo() != null && prop.isLocal()) {
|
||||
local.add(prop);
|
||||
}
|
||||
|
||||
if (prop instanceof BeanPropertyAssocMany<?>) {
|
||||
manys.add(prop);
|
||||
|
||||
} else {
|
||||
nonManys.add(prop);
|
||||
if (prop instanceof BeanPropertyAssocOne<?>) {
|
||||
if (prop.isEmbedded()) {
|
||||
embedded.add(prop);
|
||||
} else {
|
||||
unidirectional = new BeanPropertyAssocOne(owner, desc, deployUnidirectional);
|
||||
ones.add(prop);
|
||||
BeanPropertyAssocOne<?> assocOne = (BeanPropertyAssocOne<?>) prop;
|
||||
if (assocOne.isOneToOneExported()) {
|
||||
onesExported.add(prop);
|
||||
} else {
|
||||
onesImported.add(prop);
|
||||
}
|
||||
}
|
||||
|
||||
this.propertyMap = new LinkedHashMap<String, BeanProperty>();
|
||||
|
||||
Iterator<DeployBeanProperty> deployIt = deploy.propertiesAll();
|
||||
while (deployIt.hasNext()) {
|
||||
DeployBeanProperty deployProp = deployIt.next();
|
||||
BeanProperty beanProp = createBeanProperty(owner, deployProp);
|
||||
propertyMap.put(beanProp.getName(), beanProp);
|
||||
} else {
|
||||
// its a "base" property...
|
||||
if (prop.isVersion()) {
|
||||
if (versionProperty == null) {
|
||||
versionProperty = prop;
|
||||
} else {
|
||||
logger.warn("Multiple @Version properties - property " + prop.getFullBeanName()
|
||||
+ " not treated as a version property");
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<BeanProperty> it = propertyMap.values().iterator();
|
||||
|
||||
int order = 0;
|
||||
while (it.hasNext()) {
|
||||
BeanProperty prop = it.next();
|
||||
prop.setDeployOrder(order++);
|
||||
allocateToList(prop);
|
||||
}
|
||||
|
||||
List<DeployTableJoin> deployTableJoins = deploy.getTableJoins();
|
||||
tableJoins = new TableJoin[deployTableJoins.size()];
|
||||
for (int i = 0; i < deployTableJoins.size(); i++) {
|
||||
tableJoins[i] = new TableJoin(deployTableJoins.get(i), propertyMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the unidirectional.
|
||||
*/
|
||||
public BeanPropertyAssocOne<?> getUnidirectional() {
|
||||
return unidirectional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate the property to a list.
|
||||
*/
|
||||
private void allocateToList(BeanProperty prop) {
|
||||
if (prop.isTransient()) {
|
||||
transients.add(prop);
|
||||
return;
|
||||
}
|
||||
if (prop.isId()) {
|
||||
ids.add(prop);
|
||||
return;
|
||||
if (prop instanceof BeanPropertyCompound) {
|
||||
baseCompound.add((BeanPropertyCompound) prop);
|
||||
} else {
|
||||
nonTransients.add(prop);
|
||||
baseScalar.add(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (desc.getInheritInfo() != null && prop.isLocal()) {
|
||||
local.add(prop);
|
||||
public LinkedHashMap<String, BeanProperty> getPropertyMap() {
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
public TableJoin[] getTableJoin() {
|
||||
return tableJoins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the base scalar properties (excludes Id and secondary table
|
||||
* properties).
|
||||
*/
|
||||
public BeanProperty[] getBaseScalar() {
|
||||
return (BeanProperty[]) baseScalar.toArray(new BeanProperty[baseScalar.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyCompound[] getBaseCompound() {
|
||||
return (BeanPropertyCompound[]) baseCompound.toArray(new BeanPropertyCompound[baseCompound.size()]);
|
||||
}
|
||||
|
||||
public BeanProperty getNaturalKey() {
|
||||
String naturalKey = desc.getCacheOptions().getNaturalKey();
|
||||
if (naturalKey != null) {
|
||||
return propertyMap.get(naturalKey);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public BeanProperty[] getId() {
|
||||
return (BeanProperty[]) ids.toArray(new BeanProperty[ids.size()]);
|
||||
}
|
||||
|
||||
public BeanProperty[] getNonTransients() {
|
||||
return (BeanProperty[]) nonTransients.toArray(new BeanProperty[nonTransients.size()]);
|
||||
}
|
||||
|
||||
public BeanProperty[] getTransients() {
|
||||
return (BeanProperty[]) transients.toArray(new BeanProperty[transients.size()]);
|
||||
}
|
||||
|
||||
public BeanProperty getVersionProperty() {
|
||||
return versionProperty;
|
||||
}
|
||||
|
||||
public BeanProperty[] getLocal() {
|
||||
return (BeanProperty[]) local.toArray(new BeanProperty[local.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getEmbedded() {
|
||||
return (BeanPropertyAssocOne[]) embedded.toArray(new BeanPropertyAssocOne[embedded.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneExported() {
|
||||
return (BeanPropertyAssocOne[]) onesExported.toArray(new BeanPropertyAssocOne[onesExported.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneImported() {
|
||||
return (BeanPropertyAssocOne[]) onesImported.toArray(new BeanPropertyAssocOne[onesImported.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOnes() {
|
||||
return (BeanPropertyAssocOne[]) ones.toArray(new BeanPropertyAssocOne[ones.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneExportedSave() {
|
||||
return getOne(false, Mode.Save);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneExportedDelete() {
|
||||
return getOne(false, Mode.Delete);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneImportedSave() {
|
||||
return getOne(true, Mode.Save);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneImportedDelete() {
|
||||
return getOne(true, Mode.Delete);
|
||||
}
|
||||
|
||||
public BeanProperty[] getNonMany() {
|
||||
return (BeanProperty[]) nonManys.toArray(new BeanProperty[nonManys.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocMany<?>[] getMany() {
|
||||
return (BeanPropertyAssocMany[]) manys.toArray(new BeanPropertyAssocMany[manys.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocMany<?>[] getManySave() {
|
||||
return getMany(Mode.Save);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocMany<?>[] getManyDelete() {
|
||||
return getMany(Mode.Delete);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocMany<?>[] getManyToMany() {
|
||||
return getMany2Many();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mode used to determine which BeanPropertyAssoc to include.
|
||||
*/
|
||||
private enum Mode {
|
||||
Save, Delete, Validate;
|
||||
}
|
||||
|
||||
private BeanPropertyAssocOne<?>[] getOne(boolean imported, Mode mode) {
|
||||
ArrayList<BeanPropertyAssocOne<?>> list = new ArrayList<BeanPropertyAssocOne<?>>();
|
||||
for (int i = 0; i < ones.size(); i++) {
|
||||
BeanPropertyAssocOne<?> prop = (BeanPropertyAssocOne<?>) ones.get(i);
|
||||
if (imported != prop.isOneToOneExported()) {
|
||||
switch (mode) {
|
||||
case Save:
|
||||
if (prop.getCascadeInfo().isSave()) {
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
case Delete:
|
||||
if (prop.getCascadeInfo().isDelete()) {
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
case Validate:
|
||||
if (prop.getCascadeInfo().isValidate()) {
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prop instanceof BeanPropertyAssocMany<?>) {
|
||||
manys.add(prop);
|
||||
return (BeanPropertyAssocOne[]) list.toArray(new BeanPropertyAssocOne[list.size()]);
|
||||
}
|
||||
|
||||
} else {
|
||||
nonManys.add(prop);
|
||||
if (prop instanceof BeanPropertyAssocOne<?>) {
|
||||
if (prop.isEmbedded()) {
|
||||
embedded.add(prop);
|
||||
} else {
|
||||
ones.add(prop);
|
||||
BeanPropertyAssocOne<?> assocOne = (BeanPropertyAssocOne<?>) prop;
|
||||
if (assocOne.isOneToOneExported()) {
|
||||
onesExported.add(prop);
|
||||
} else {
|
||||
onesImported.add(prop);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// its a "base" property...
|
||||
if (prop.isVersion()) {
|
||||
version.add(prop);
|
||||
if (derivedFirstVersionProp == null) {
|
||||
derivedFirstVersionProp = prop;
|
||||
}
|
||||
}
|
||||
if (prop instanceof BeanPropertyCompound) {
|
||||
baseCompound.add((BeanPropertyCompound) prop);
|
||||
} else {
|
||||
baseScalar.add(prop);
|
||||
}
|
||||
}
|
||||
private BeanPropertyAssocMany<?>[] getMany2Many() {
|
||||
ArrayList<BeanPropertyAssocMany<?>> list = new ArrayList<BeanPropertyAssocMany<?>>();
|
||||
for (int i = 0; i < manys.size(); i++) {
|
||||
BeanPropertyAssocMany<?> prop = (BeanPropertyAssocMany<?>) manys.get(i);
|
||||
if (prop.isManyToMany()) {
|
||||
list.add(prop);
|
||||
}
|
||||
}
|
||||
|
||||
return (BeanPropertyAssocMany[]) list.toArray(new BeanPropertyAssocMany[list.size()]);
|
||||
}
|
||||
|
||||
private BeanPropertyAssocMany<?>[] getMany(Mode mode) {
|
||||
ArrayList<BeanPropertyAssocMany<?>> list = new ArrayList<BeanPropertyAssocMany<?>>();
|
||||
for (int i = 0; i < manys.size(); i++) {
|
||||
BeanPropertyAssocMany<?> prop = (BeanPropertyAssocMany<?>) manys.get(i);
|
||||
|
||||
switch (mode) {
|
||||
case Save:
|
||||
if (prop.getCascadeInfo().isSave() || prop.isManyToMany()
|
||||
|| ModifyListenMode.REMOVALS.equals(prop.getModifyListenMode())) {
|
||||
// Note ManyToMany always included as we always 'save'
|
||||
// the relationship via insert/delete of intersection table
|
||||
// REMOVALS means including PrivateOwned relationships
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
case Delete:
|
||||
if (prop.getCascadeInfo().isDelete() || ModifyListenMode.REMOVALS.equals(prop.getModifyListenMode())) {
|
||||
// REMOVALS means including PrivateOwned relationships
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
case Validate:
|
||||
if (prop.getCascadeInfo().isValidate()) {
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public BeanProperty getFirstVersion() {
|
||||
return derivedFirstVersionProp;
|
||||
}
|
||||
return (BeanPropertyAssocMany[]) list.toArray(new BeanPropertyAssocMany[list.size()]);
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, BeanProperty> getPropertyMap() {
|
||||
return propertyMap;
|
||||
}
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private BeanProperty createBeanProperty(BeanDescriptorMap owner, DeployBeanProperty deployProp) {
|
||||
|
||||
public TableJoin[] getTableJoin() {
|
||||
return tableJoins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the base scalar properties (excludes Id and secondary table
|
||||
* properties).
|
||||
*/
|
||||
public BeanProperty[] getBaseScalar() {
|
||||
return (BeanProperty[]) baseScalar.toArray(new BeanProperty[baseScalar.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyCompound[] getBaseCompound() {
|
||||
return (BeanPropertyCompound[]) baseCompound.toArray(new BeanPropertyCompound[baseCompound.size()]);
|
||||
if (deployProp instanceof DeployBeanPropertyAssocOne) {
|
||||
return new BeanPropertyAssocOne(owner, desc, (DeployBeanPropertyAssocOne) deployProp);
|
||||
}
|
||||
|
||||
public BeanProperty getNaturalKey() {
|
||||
String naturalKey = desc.getCacheOptions().getNaturalKey();
|
||||
if (naturalKey != null){
|
||||
return propertyMap.get(naturalKey);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public BeanProperty[] getId() {
|
||||
return (BeanProperty[]) ids.toArray(new BeanProperty[ids.size()]);
|
||||
}
|
||||
|
||||
public BeanProperty[] getNonTransients() {
|
||||
return (BeanProperty[]) nonTransients.toArray(new BeanProperty[nonTransients.size()]);
|
||||
}
|
||||
|
||||
public BeanProperty[] getTransients() {
|
||||
return (BeanProperty[]) transients.toArray(new BeanProperty[transients.size()]);
|
||||
}
|
||||
|
||||
public BeanProperty[] getVersion() {
|
||||
return (BeanProperty[]) version.toArray(new BeanProperty[version.size()]);
|
||||
}
|
||||
|
||||
public BeanProperty[] getLocal() {
|
||||
return (BeanProperty[]) local.toArray(new BeanProperty[local.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getEmbedded() {
|
||||
return (BeanPropertyAssocOne[]) embedded.toArray(new BeanPropertyAssocOne[embedded.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneExported() {
|
||||
return (BeanPropertyAssocOne[]) onesExported.toArray(new BeanPropertyAssocOne[onesExported.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneImported() {
|
||||
return (BeanPropertyAssocOne[]) onesImported.toArray(new BeanPropertyAssocOne[onesImported.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOnes() {
|
||||
return (BeanPropertyAssocOne[]) ones.toArray(new BeanPropertyAssocOne[ones.size()]);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneExportedSave() {
|
||||
return getOne(false, Mode.Save);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneExportedDelete() {
|
||||
return getOne(false, Mode.Delete);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneImportedSave() {
|
||||
return getOne(true, Mode.Save);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocOne<?>[] getOneImportedDelete() {
|
||||
return getOne(true, Mode.Delete);
|
||||
}
|
||||
|
||||
public BeanProperty[] getNonMany() {
|
||||
return (BeanProperty[]) nonManys.toArray(new BeanProperty[nonManys.size()]);
|
||||
if (deployProp instanceof DeployBeanPropertySimpleCollection<?>) {
|
||||
return new BeanPropertySimpleCollection(owner, desc, (DeployBeanPropertySimpleCollection) deployProp);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocMany<?>[] getMany() {
|
||||
return (BeanPropertyAssocMany[]) manys.toArray(new BeanPropertyAssocMany[manys.size()]);
|
||||
if (deployProp instanceof DeployBeanPropertyAssocMany) {
|
||||
return new BeanPropertyAssocMany(owner, desc, (DeployBeanPropertyAssocMany) deployProp);
|
||||
}
|
||||
|
||||
if (deployProp instanceof DeployBeanPropertyCompound) {
|
||||
return new BeanPropertyCompound(owner, desc, (DeployBeanPropertyCompound) deployProp);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocMany<?>[] getManySave() {
|
||||
return getMany(Mode.Save);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocMany<?>[] getManyDelete() {
|
||||
return getMany(Mode.Delete);
|
||||
}
|
||||
|
||||
public BeanPropertyAssocMany<?>[] getManyToMany() {
|
||||
return getMany2Many();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mode used to determine which BeanPropertyAssoc to include.
|
||||
*/
|
||||
private enum Mode {
|
||||
Save, Delete, Validate;
|
||||
}
|
||||
|
||||
private BeanPropertyAssocOne<?>[] getOne(boolean imported, Mode mode) {
|
||||
ArrayList<BeanPropertyAssocOne<?>> list = new ArrayList<BeanPropertyAssocOne<?>>();
|
||||
for (int i = 0; i < ones.size(); i++) {
|
||||
BeanPropertyAssocOne<?> prop = (BeanPropertyAssocOne<?>) ones.get(i);
|
||||
if (imported != prop.isOneToOneExported()) {
|
||||
switch (mode) {
|
||||
case Save:
|
||||
if (prop.getCascadeInfo().isSave()) {
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
case Delete:
|
||||
if (prop.getCascadeInfo().isDelete()) {
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
case Validate:
|
||||
if (prop.getCascadeInfo().isValidate()) {
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (BeanPropertyAssocOne[]) list.toArray(new BeanPropertyAssocOne[list.size()]);
|
||||
}
|
||||
|
||||
private BeanPropertyAssocMany<?>[] getMany2Many() {
|
||||
ArrayList<BeanPropertyAssocMany<?>> list = new ArrayList<BeanPropertyAssocMany<?>>();
|
||||
for (int i = 0; i < manys.size(); i++) {
|
||||
BeanPropertyAssocMany<?> prop = (BeanPropertyAssocMany<?>) manys.get(i);
|
||||
if (prop.isManyToMany()) {
|
||||
list.add(prop);
|
||||
}
|
||||
}
|
||||
|
||||
return (BeanPropertyAssocMany[]) list.toArray(new BeanPropertyAssocMany[list.size()]);
|
||||
}
|
||||
|
||||
private BeanPropertyAssocMany<?>[] getMany(Mode mode) {
|
||||
ArrayList<BeanPropertyAssocMany<?>> list = new ArrayList<BeanPropertyAssocMany<?>>();
|
||||
for (int i = 0; i < manys.size(); i++) {
|
||||
BeanPropertyAssocMany<?> prop = (BeanPropertyAssocMany<?>) manys.get(i);
|
||||
|
||||
switch (mode) {
|
||||
case Save:
|
||||
if (prop.getCascadeInfo().isSave() || prop.isManyToMany()
|
||||
|| ModifyListenMode.REMOVALS.equals(prop.getModifyListenMode())) {
|
||||
// Note ManyToMany always included as we always 'save'
|
||||
// the relationship via insert/delete of intersection table
|
||||
// REMOVALS means including PrivateOwned relationships
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
case Delete:
|
||||
if (prop.getCascadeInfo().isDelete()
|
||||
|| ModifyListenMode.REMOVALS.equals(prop.getModifyListenMode())) {
|
||||
// REMOVALS means including PrivateOwned relationships
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
case Validate:
|
||||
if (prop.getCascadeInfo().isValidate()) {
|
||||
list.add(prop);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (BeanPropertyAssocMany[]) list.toArray(new BeanPropertyAssocMany[list.size()]);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private BeanProperty createBeanProperty(BeanDescriptorMap owner, DeployBeanProperty deployProp) {
|
||||
|
||||
if (deployProp instanceof DeployBeanPropertyAssocOne) {
|
||||
|
||||
return new BeanPropertyAssocOne(owner, desc, (DeployBeanPropertyAssocOne) deployProp);
|
||||
}
|
||||
if (deployProp instanceof DeployBeanPropertySimpleCollection<?>) {
|
||||
|
||||
return new BeanPropertySimpleCollection(owner, desc, (DeployBeanPropertySimpleCollection)deployProp);
|
||||
}
|
||||
if (deployProp instanceof DeployBeanPropertyAssocMany) {
|
||||
|
||||
return new BeanPropertyAssocMany(owner, desc, (DeployBeanPropertyAssocMany) deployProp);
|
||||
}
|
||||
if (deployProp instanceof DeployBeanPropertyCompound) {
|
||||
|
||||
return new BeanPropertyCompound(owner, desc, (DeployBeanPropertyCompound) deployProp);
|
||||
}
|
||||
|
||||
return new BeanProperty(owner, desc, deployProp);
|
||||
}
|
||||
return new BeanProperty(owner, desc, deployProp);
|
||||
}
|
||||
}
|
||||
@@ -55,10 +55,8 @@ public class AnnotationClass extends AnnotationParser {
|
||||
|
||||
Entity entity = cls.getAnnotation(Entity.class);
|
||||
if (entity != null) {
|
||||
// checkDefaultConstructor();
|
||||
if (entity.name().equals("")) {
|
||||
descriptor.setName(cls.getSimpleName());
|
||||
|
||||
} else {
|
||||
descriptor.setName(entity.name());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user