Remove Subclassing/Dynamic Proxy support - beans must be enhanced

This commit is contained in:
Robin Bygrave committed 2013-04-19 16:25:10 +12:00
1 parent 66880aa340
commit 2567022d95
63 files changed
+233 -2085

No files matched your search

@@ -936,7 +936,7 @@ public class BeanDescriptor<T> {
}
}
public boolean cacheLoadMany(BeanPropertyAssocMany<?> many, BeanCollection<?> bc, Object parentId, Boolean readOnly, boolean vanilla) {
public boolean cacheLoadMany(BeanPropertyAssocMany<?> many, BeanCollection<?> bc, Object parentId, Boolean readOnly) {
CachedManyIds ids = cacheGetCachedManyIds(parentId, many.getName());
if (ids == null) {
@@ -953,7 +953,7 @@ public class BeanDescriptor<T> {
bc.checkEmptyLazyLoad();
for (int i = 0; i < idList.size(); i++) {
Object id = idList.get(i);
Object refBean = targetDescriptor.createReference(vanilla, readOnly, id, null);
Object refBean = targetDescriptor.createReference(readOnly, id, null);
EntityBeanIntercept refEbi = ((EntityBean) refBean)._ebean_getIntercept();
many.add(bc, refBean);
@@ -999,22 +999,22 @@ public class BeanDescriptor<T> {
* Return a bean from the bean cache.
*/
@SuppressWarnings("unchecked")
public T cacheGetBean(Object id, boolean vanilla, Boolean readOnly) {
public T cacheGetBean(Object id, Boolean readOnly) {
CachedBeanData d = (CachedBeanData) getBeanCache().get(id);
if (d == null) {
return null;
}
if (cacheSharableBeans && !vanilla && !Boolean.FALSE.equals(readOnly)) {
if (cacheSharableBeans && !Boolean.FALSE.equals(readOnly)) {
Object bean = d.getSharableBean();
if (bean != null) {
return (T) bean;
}
}
T bean = (T) createBean(vanilla);
T bean = (T) createBean();
convertSetId(id, bean);
if (!vanilla && Boolean.TRUE.equals(readOnly)) {
if (Boolean.TRUE.equals(readOnly)) {
((EntityBean) bean)._ebean_getIntercept().setReadOnly(true);
}
@@ -1306,20 +1306,10 @@ public class BeanDescriptor<T> {
}
/**
* Create an EntityBean or "Vanilla" bean depending on the flag.
* Create an EntityBean.
*/
public Object createBean(boolean vanillaMode) {
return vanillaMode ? createVanillaBean() : createEntityBean();
}
/**
* Create a plain vanilla object.
* <p>
* Used for EmbeddedId Bean construction.
* </p>
*/
public Object createVanillaBean() {
return beanReflect.createVanillaBean();
public Object createBean() {
return createEntityBean();
}
/**
@@ -1341,9 +1331,9 @@ public class BeanDescriptor<T> {
* Create a reference bean based on the id.
*/
@SuppressWarnings("unchecked")
public T createReference(boolean vanillaMode, Boolean readOnly, Object id, Object parent) {
public T createReference(Boolean readOnly, Object id, Object parent) {
if (cacheSharableBeans && !vanillaMode && !Boolean.FALSE.equals(readOnly)) {
if (cacheSharableBeans && !Boolean.FALSE.equals(readOnly)) {
CachedBeanData d = (CachedBeanData) getBeanCache().get(id);
if (d != null) {
Object shareableBean = d.getSharableBean();
@@ -1353,26 +1343,24 @@ public class BeanDescriptor<T> {
}
}
try {
Object bean = createBean(vanillaMode);
Object bean = createBean();
convertSetId(id, bean);
if (!vanillaMode) {
EntityBean eb = (EntityBean) bean;
EntityBean eb = (EntityBean) bean;
EntityBeanIntercept ebi = eb._ebean_getIntercept();
ebi.setBeanLoaderByServerName(ebeanServer.getName());
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();
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;
} catch (Exception ex) {
@@ -2209,17 +2197,6 @@ public class BeanDescriptor<T> {
return propertyFirstVersion;
}
/**
* Return true if this an Insert (rather than Update) on a non-enhanced bean.
*/
public boolean isVanillaInsert(Object bean) {
if (propertyFirstVersion == null) {
return true;
}
Object versionValue = propertyFirstVersion.getValue(bean);
return DmlUtil.isNullOrZero(versionValue);
}
/**
* Return true if this is an Update (rather than insert) given that the bean
* is involved in a stateless update.
@@ -14,6 +14,9 @@ import java.util.Set;
import javax.persistence.PersistenceException;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.avaje.ebean.BackgroundExecutor;
import com.avaje.ebean.RawSql;
import com.avaje.ebean.RawSqlBuilder;
@@ -60,11 +63,7 @@ import com.avaje.ebeaninternal.server.reflect.BeanReflectFactory;
import com.avaje.ebeaninternal.server.reflect.BeanReflectGetter;
import com.avaje.ebeaninternal.server.reflect.BeanReflectSetter;
import com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflectFactory;
import com.avaje.ebeaninternal.server.subclass.SubClassManager;
import com.avaje.ebeaninternal.server.subclass.SubClassUtil;
import com.avaje.ebeaninternal.server.type.TypeManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Creates BeanDescriptors.
@@ -98,8 +97,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
private final BeanQueryAdapterManager beanQueryAdapterManager;
private final SubClassManager subClassManager;
private final NamingConvention namingConvention;
private final DeployCreateProperties createProperties;
@@ -153,8 +150,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
private final XmlConfig xmlConfig;
private final boolean allowSubclassing;
/**
* Create for a given database dbConfig.
*/
@@ -172,7 +167,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
this.bootupClasses = config.getBootupClasses();
this.createProperties = config.getDeployCreateProperties();
this.subClassManager = config.getSubClassManager();
this.typeManager = config.getTypeManager();
this.namingConvention = config.getServerConfig().getNamingConvention();
this.dbIdentity = config.getDatabasePlatform().getDbIdentity();
@@ -192,7 +186,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
this.reflectFactory = createReflectionFactory();
this.transientProperties = new TransientProperties();
this.allowSubclassing = config.getServerConfig().isAllowSubclassing();
}
public BeanDescriptor<?> getBeanDescriptorById(String descriptorId) {
@@ -201,17 +194,11 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
@SuppressWarnings("unchecked")
public <T> BeanDescriptor<T> getBeanDescriptor(Class<T> entityType) {
// remove $$EntityBean stuff
String className = SubClassUtil.getSuperClassName(entityType.getName());
return (BeanDescriptor<T>) descMap.get(className);
return (BeanDescriptor<T>) descMap.get(entityType.getName());
}
@SuppressWarnings("unchecked")
public <T> BeanDescriptor<T> getBeanDescriptor(String entityClassName) {
// remove $$EntityBean stuff
entityClassName = SubClassUtil.getSuperClassName(entityClassName);
return (BeanDescriptor<T>) descMap.get(entityClassName);
}
@@ -440,8 +427,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
}
public BeanManager<?> getBeanManager(String beanClassName) {
beanClassName = SubClassUtil.getSuperClassName(beanClassName);
return beanManagerMap.get(beanClassName);
}
@@ -1462,13 +1447,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
desc.setFactoryType(beanClass);
} else {
if (!allowSubclassing) {
throw new PersistenceException("This configuration does not allow entity subclassing [" + beanClass + "]");
}
subclassClassCount++;
Class<?> subClass = subClassManager.resolve(beanClass.getName());
desc.setFactoryType(subClass);
subclassedEntities.add(desc.getName());
throw new PersistenceException("Entity type "+beanClass+" is not an enhanced entity bean. Subclassing is not longer supported in Ebean");
}
}
@@ -382,13 +382,12 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
if (embedded){
throw new RuntimeException();
} else {
boolean vanillaMode = false;
T ref = targetDescriptor.createReference(vanillaMode, Boolean.FALSE, cacheData, null);
T ref = targetDescriptor.createReference(Boolean.FALSE, cacheData, null);
setValue(bean, ref);
if (oldValues != null){
setValue(oldValues, ref);
}
if (readOnly && !vanillaMode){
if (readOnly){
((EntityBean)ref)._ebean_intercept().setReadOnly(true);
}
}
@@ -438,11 +437,11 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
/**
* Create a vanilla bean of the target type to be used as an embeddedId
* Create a bean of the target type to be used as an embeddedId
* value.
*/
public Object createEmbeddedId() {
return getTargetDescriptor().createVanillaBean();
return getTargetDescriptor().createBean();
}
/**
@@ -736,16 +735,14 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
// parent always null for this case (but here to document)
Object parent = null;
boolean vanillaMode = ctx.isVanillaMode();
//ReferenceOptions options = ctx.getReferenceOptionsFor(beanProp);
Boolean readOnly = ctx.isReadOnly();
Object ref;
if (targetInheritInfo != null) {
// for inheritance hierarchy create the correct type for this row...
ref = rowDescriptor.createReference(vanillaMode, readOnly, id, parent);
ref = rowDescriptor.createReference(readOnly, id, parent);
} else {
ref = targetDescriptor.createReference(vanillaMode, readOnly, id, parent);
ref = targetDescriptor.createReference(readOnly, id, parent);
}
Object existingBean = ctx.getPersistenceContext().putIfAbsent(id, ref);
@@ -755,7 +752,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
// loaded a matching bean so we will use that instead.
ref = existingBean;
} else if (!vanillaMode){
} else {
EntityBeanIntercept ebi = ((EntityBean) ref)._ebean_getIntercept();
if (Boolean.TRUE.equals(ctx.isReadOnly())){
ebi.setReadOnly(true);
@@ -831,18 +828,15 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> {
if (existing != null) {
return existing;
}
boolean vanillaMode = ctx.isVanillaMode();
Object parent = null;
Object ref = targetDescriptor.createReference(vanillaMode, ctx.isReadOnly(), id, parent);
Object ref = targetDescriptor.createReference(ctx.isReadOnly(), id, parent);
if (!vanillaMode){
EntityBeanIntercept ebi = ((EntityBean) ref)._ebean_getIntercept();
if (Boolean.TRUE.equals(ctx.isReadOnly())) {
ebi.setReadOnly(true);
}
persistCtx.put(id, ref);
ctx.register(name, ebi);
EntityBeanIntercept ebi = ((EntityBean) ref)._ebean_getIntercept();
if (Boolean.TRUE.equals(ctx.isReadOnly())) {
ebi.setReadOnly(true);
}
persistCtx.put(id, ref);
ctx.register(name, ebi);
return ref;
}
@@ -13,35 +13,25 @@ import com.avaje.ebeaninternal.server.type.DataReader;
*/
public interface DbReadContext {
/**
* Return the state of the object graph.
*/
public Boolean isReadOnly();
/**
* Return the state of the object graph.
*/
public Boolean isReadOnly();
/**
* Propagate the state to the bean.
*/
public void propagateState(Object e);
/**
* Propagate the state to the bean.
*/
public void propagateState(Object e);
/**
* Return the DataReader.
*/
public DataReader getDataReader();
/**
* Return true if vanilla objects should be returned.
*/
public boolean isVanillaMode();
/**
* Return the DataReader.
*/
public DataReader getDataReader();
/**
* Return true if the query is using supplied SQL rather than generated SQL.
*/
public boolean isRawSql();
// /**
// * Return the reference options for a given bean property.
// */
// public ReferenceOptions getReferenceOptionsFor(BeanPropertyAssocOne<?> beanProperty);
/**
* Set the JoinNode - used by proxy/reference beans for profiling.
@@ -10,7 +10,6 @@ import com.avaje.ebeaninternal.server.core.InternString;
import com.avaje.ebeaninternal.server.deploy.id.IdBinder;
import com.avaje.ebeaninternal.server.deploy.parse.DeployInheritInfo;
import com.avaje.ebeaninternal.server.query.SqlTreeProperties;
import com.avaje.ebeaninternal.server.subclass.SubClassUtil;
/**
* Represents a node in the Inheritance tree. Holds information regarding Super
@@ -224,8 +223,8 @@ public class InheritInfo {
/**
* Create an EntityBean for this type.
*/
public Object createBean(boolean vanillaMode) {
return descriptor.createBean(vanillaMode);
public Object createBean() {
return descriptor.createBean();
}
/**
@@ -284,8 +283,7 @@ public class InheritInfo {
* Return the InheritInfo for the given bean type.
*/
private InheritInfo getTypeByClass(Class<?> beanType) {
String clsName = SubClassUtil.getSuperClassName(beanType.getName());
return typeMap.get(clsName);
return typeMap.get(beanType.getName());
}
private void registerWithRoot(InheritInfo info) {
@@ -293,8 +291,7 @@ public class InheritInfo {
String stringDiscValue = info.getDiscriminatorStringValue();
discMap.put(stringDiscValue, info);
}
String clsName = SubClassUtil.getSuperClassName(info.getType().getName());
typeMap.put(clsName, info);
typeMap.put(info.getType().getName(), info);
}
/**
@@ -238,7 +238,7 @@ public final class IdBinderEmbedded implements IdBinder {
String msg = "Failed to split ["+idTermValue+"] using | for id.";
throw new PersistenceException(msg);
}
Object embId = idDesc.createVanillaBean();
Object embId = idDesc.createBean();
for (int i = 0; i < props.length; i++) {
Object v = props[i].getScalarType().parse(split[i]);
props[i].setValue(embId, v);
@@ -299,7 +299,7 @@ public final class IdBinderEmbedded implements IdBinder {
public Object readData(DataInput dataInput) throws IOException {
Object embId = idDesc.createVanillaBean();
Object embId = idDesc.createBean();
boolean notNull = true;
for (int i = 0; i < props.length; i++) {
@@ -332,7 +332,7 @@ public final class IdBinderEmbedded implements IdBinder {
public Object read(DbReadContext ctx) throws SQLException {
Object embId = idDesc.createVanillaBean();
Object embId = idDesc.createBean();
boolean notNull = true;
for (int i = 0; i < props.length; i++) {