Internal change only - just reuse class name as bean descriptor key

This commit is contained in:
Robin Bygrave
2015-08-21 18:28:10 +12:00
parent f8b8a41bce
commit 547fa342c4
5 changed files with 19 additions and 40 deletions
@@ -93,7 +93,7 @@ public interface SpiEbeanServer extends EbeanServer, BeanLoader, BeanCollectionL
/**
* Return BeanDescriptor using it's unique id.
*/
BeanDescriptor<?> getBeanDescriptorById(String descriptorId);
BeanDescriptor<?> getBeanDescriptorById(String className);
/**
* Return BeanDescriptors mapped to this table.
@@ -1967,10 +1967,10 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
/**
* Return the BeanDescriptor using its unique id.
* Return the BeanDescriptor using its class name.
*/
public BeanDescriptor<?> getBeanDescriptorById(String descriptorId) {
return beanDescriptorManager.getBeanDescriptorById(descriptorId);
public BeanDescriptor<?> getBeanDescriptorById(String beanClassName) {
return beanDescriptorManager.getBeanDescriptorByClassName(beanClassName);
}
/**
@@ -317,14 +317,12 @@ public class BeanDescriptor<T> implements MetaBeanInfo, SpiBeanType<T> {
private final String defaultSelectClause;
private final Set<String> defaultSelectClauseSet;
private final String descriptorId;
private SpiEbeanServer ebeanServer;
/**
* Construct the BeanDescriptor.
*/
public BeanDescriptor(BeanDescriptorMap owner, DeployBeanDescriptor<T> deploy, String descriptorId) {
public BeanDescriptor(BeanDescriptorMap owner, DeployBeanDescriptor<T> deploy) {
this.owner = owner;
this.serverName = owner.getServerName();
@@ -334,7 +332,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo, SpiBeanType<T> {
this.name = InternString.intern(deploy.getName());
this.baseTableAlias = "t0";
this.fullName = InternString.intern(deploy.getFullName());
this.descriptorId = descriptorId;
this.beanType = deploy.getBeanType();
this.prototypeEntityBean = createPrototypeEntityBean(beanType);
@@ -854,7 +851,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo, SpiBeanType<T> {
}
public void cacheManyPropClear(String propertyName) {
cacheHelp.manyPropClear(propertyName);
cacheHelp.manyPropClear(propertyName);
}
public void cacheBeanPut(T bean) {
@@ -874,7 +871,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo, SpiBeanType<T> {
public void cacheBeanLoadData(EntityBean bean, CachedBeanData data) {
cacheHelp.beanLoadData(bean, data);
}
/**
* Put a bean into the bean cache.
*/
@@ -902,7 +899,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo, SpiBeanType<T> {
public boolean cacheBeanLoad(EntityBean bean, EntityBeanIntercept ebi, Object id) {
return cacheHelp.beanCacheLoad(bean, ebi, id);
}
/**
* Returns true if it managed to populate/load the bean from the cache.
*/
@@ -923,7 +920,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo, SpiBeanType<T> {
* Invalidate parts of cache due to SqlUpdate or external modification etc.
*/
public void cacheHandleBulkUpdate(TableIUD tableIUD) {
cacheHelp.handleBulkUpdate(tableIUD);
cacheHelp.handleBulkUpdate(tableIUD);
}
/**
@@ -1305,11 +1302,10 @@ public class BeanDescriptor<T> implements MetaBeanInfo, SpiBeanType<T> {
}
/**
* Return the alternate "Id" that identifies this BeanDescriptor. This is an
* alternative to using the bean class name.
* Return bean class name.
*/
public String getDescriptorId() {
return descriptorId;
return fullName;
}
/**
@@ -129,7 +129,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
private final Map<Class<?>, BeanTable> beanTableMap = new HashMap<Class<?>, BeanTable>();
private final Map<String, BeanDescriptor<?>> descMap = new HashMap<String, BeanDescriptor<?>>();
private final Map<String, BeanDescriptor<?>> idDescMap = new HashMap<String, BeanDescriptor<?>>();
private final Map<String, BeanManager<?>> beanManagerMap = new HashMap<String, BeanManager<?>>();
@@ -235,17 +234,13 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
return (historySupport == null ) ? serverConfig.getAsOfViewSuffix() : historySupport.getVersionsBetweenSuffix(serverConfig.getAsOfViewSuffix());
}
public BeanDescriptor<?> getBeanDescriptorById(String descriptorId) {
return idDescMap.get(descriptorId);
}
@SuppressWarnings("unchecked")
public <T> BeanDescriptor<T> getBeanDescriptor(Class<T> entityType) {
return (BeanDescriptor<T>) descMap.get(entityType.getName());
}
@SuppressWarnings("unchecked")
public <T> BeanDescriptor<T> getBeanDescriptor(String entityClassName) {
public <T> BeanDescriptor<T> getBeanDescriptorByClassName(String entityClassName) {
return (BeanDescriptor<T>) descMap.get(entityClassName);
}
@@ -295,11 +290,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
Collections.sort(list, beanDescComparator);
immutableDescriptorList = Collections.unmodifiableList(list);
// put into map using the "desriptorId" (alternative to class name)
for (BeanDescriptor<?> d : list) {
idDescMap.put(d.getDescriptorId(), d);
}
initialiseAll();
readForeignKeys();
@@ -504,10 +494,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
DeployBeanInfo<T> info = createDeployBeanInfo(beanClass);
readDeployAssociations(info);
Integer key = getUniqueHash(info.getDescriptor());
return new BeanDescriptor<T>(this, info.getDescriptor(), key.toString());
return new BeanDescriptor<T>(this, info.getDescriptor());
}
private void registerBeanDescriptor(BeanDescriptor<?> desc) {
@@ -639,9 +626,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
}
for (DeployBeanInfo<?> info : deplyInfoMap.values()) {
DeployBeanDescriptor<?> deployBeanDescriptor = info.getDescriptor();
Integer key = getUniqueHash(deployBeanDescriptor);
registerBeanDescriptor(new BeanDescriptor(this, info.getDescriptor(), key.toString()));
registerBeanDescriptor(new BeanDescriptor(this, info.getDescriptor()));
}
}
@@ -670,11 +655,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
}
}
}
private Integer getUniqueHash(DeployBeanDescriptor<?> deployBeanDescriptor) {
return deployBeanDescriptor.getFullName().hashCode();
}
private void secondaryPropsJoins(DeployBeanInfo<?> info) {