WIP update api

This commit is contained in:
Rob Bygrave
2014-04-20 16:57:14 +12:00
parent 96e4b4640f
commit f7a37537db
20 changed files with 41 additions and 122 deletions
+1 -1
View File
@@ -169,7 +169,7 @@
<plugin>
<groupId>org.avaje.ebeanorm</groupId>
<artifactId>avaje-ebeanorm-mavenenhancer</artifactId>
<version>3.2.2</version>
<version>4.0.1-RC1</version>
<executions>
<execution>
<id>main</id>
@@ -499,6 +499,10 @@ public final class EntityBeanIntercept implements Serializable {
public int getLazyLoadProperty() {
return lazyLoadProperty;
}
public String getLazyLoadProp() {
return getProperty(lazyLoadProperty);
}
/**
* Load the bean when it is a reference.
@@ -364,8 +364,7 @@ public class DefaultBeanLoader {
SpiQuery<?> query = (SpiQuery<?>) server.createQuery(desc.getBeanType());
if (ebi != null) {
int propIndex = ebi.getLazyLoadProperty();
query.setLazyLoadProperty(ebi.getProperty(propIndex));
query.setLazyLoadProperty(ebi.getLazyLoadProp());
}
// don't collect autoFetch usage profiling information
@@ -74,6 +74,7 @@ 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;
@@ -955,7 +956,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
Collection<?> actualDetails = bc.getActualDetails();
for (Object bean : actualDetails) {
// Collect the id values
idList.add(targetDescriptor.getId(bean));
idList.add(targetDescriptor.getId((EntityBean)bean));
}
CachedManyIds ids = new CachedManyIds(idList);
cachePutCachedManyIds(parentId, many.getName(), ids);
@@ -1345,7 +1346,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
* Create a reference bean based on the id.
*/
@SuppressWarnings("unchecked")
public T createReference(Boolean readOnly, Object id, Object parent) {
public T createReference(Boolean readOnly, Object id) {//, Object parent) {
if (cacheSharableBeans && !Boolean.FALSE.equals(readOnly)) {
CachedBeanData d = (CachedBeanData) getBeanCache().get(id);
@@ -2355,11 +2356,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
return localDescriptor.jsonReadObject(ctx, path);
}
}
@SuppressWarnings("unchecked")
private T createJsonBean() {
return (T)createEntityBean();
}
private ReadBeanState jsonReadObject(ReadJsonContext ctx, String path) {
@@ -130,7 +130,7 @@ public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
return beanMap;
}
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
public void refresh(EbeanServer server, Query<?> query, Transaction t, EntityBean parentBean) {
BeanMap<?, ?> newBeanMap = (BeanMap<?, ?>) server.findMap(query, t);
refresh(newBeanMap, parentBean);
}
@@ -149,7 +149,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
/**
* Add the bean to the appropriate collection on the parent bean.
*/
public void addBeanToCollectionWithCreate(Object parentBean, Object detailBean) {
public void addBeanToCollectionWithCreate(EntityBean parentBean, EntityBean detailBean) {
BeanCollection<?> bc = (BeanCollection<?>)super.getValue(parentBean);
if (bc == null) {
bc = (BeanCollection<?>)help.createEmpty(false);
@@ -507,7 +507,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
for (int i=0; i < parentIds.size(); i++) {
for (int y = 0; y < exportedProperties.length; y++) {
Object compId = parentIds.get(i);
expandedList.add(exportedProperties[y].getValue(compId));
expandedList.add(exportedProperties[y].getValue((EntityBean)compId));
}
}
return expandedList;
@@ -83,7 +83,7 @@ public interface IdBinder {
/**
* Return the id values for a given bean.
*/
public Object[] getIdValues(Object bean);
public Object[] getIdValues(EntityBean bean);
/**
* Build a string of the logical expressions.
@@ -131,7 +131,7 @@ public interface IdBinder {
* Read the id value from the result set and set it to the bean also returning
* it.
*/
public Object readSet(DbReadContext ctx, Object bean) throws SQLException;
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException;
/**
* Ignore the appropriate number of scalar properties for this id.
@@ -92,7 +92,7 @@ public final class IdBinderEmpty implements IdBinder {
return null;
}
public Object[] getIdValues(Object bean) {
public Object[] getIdValues(EntityBean bean) {
return null;
}
@@ -111,7 +111,7 @@ public final class IdBinderEmpty implements IdBinder {
public void loadIgnore(DbReadContext ctx) {
}
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException {
return null;
}
@@ -122,7 +122,7 @@ public final class IdBinderEmpty implements IdBinder {
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
}
public Object convertSetId(Object idValue, Object bean) {
public Object convertSetId(Object idValue, EntityBean bean) {
return idValue;
}
@@ -131,6 +131,6 @@ public final class IdBinderEmpty implements IdBinder {
}
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
}
}
@@ -78,7 +78,7 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
* @param likeType
* the type of Like wild card used
*/
public DefaultExampleExpression(Object entity, boolean caseInsensitive, LikeType likeType) {
public DefaultExampleExpression(EntityBean entity, boolean caseInsensitive, LikeType likeType) {
this.entity = entity;
this.caseInsensitive = caseInsensitive;
this.likeType = likeType;
@@ -183,8 +183,6 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
for (int i = 0; i < list.size(); i++) {
list.get(i).queryPlanHash(request, builder);
}
return hc;
}
/**
@@ -5,20 +5,15 @@ import java.util.Iterator;
import java.util.List;
import com.avaje.ebean.bean.BeanLoader;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.bean.EntityBeanIntercept;
import com.avaje.ebean.bean.ObjectGraphNode;
import com.avaje.ebean.bean.PersistenceContext;
import com.avaje.ebeaninternal.api.LoadBeanBuffer;
import com.avaje.ebeaninternal.api.LoadBeanContext;
import com.avaje.ebeaninternal.api.LoadBeanRequest;
import com.avaje.ebeaninternal.api.LoadContext;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.server.core.OrmQueryRequest;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.querydefn.OrmQueryProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Default implementation of LoadBeanContext.
@@ -178,7 +173,7 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
}
}
LoadBeanRequest req = new LoadBeanRequest(this, null, true, ebi.getLazyLoadProperty(), context.hitCache);
LoadBeanRequest req = new LoadBeanRequest(this, null, true, ebi.getLazyLoadProp(), context.hitCache);
context.desc.getEbeanServer().loadBean(req);
}
@@ -5,11 +5,12 @@ import java.util.List;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.BeanCollectionLoader;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.bean.ObjectGraphNode;
import com.avaje.ebean.bean.PersistenceContext;
import com.avaje.ebeaninternal.api.LoadManyBuffer;
import com.avaje.ebeaninternal.api.LoadManyContext;
import com.avaje.ebeaninternal.api.LoadManyRequest;
import com.avaje.ebeaninternal.api.LoadManyBuffer;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.server.core.OrmQueryRequest;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
@@ -174,7 +175,7 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
synchronized (this) {
boolean useCache = context.hitCache && !onlyIds;
if (useCache) {
Object ownerBean = bc.getOwnerBean();
EntityBean ownerBean = bc.getOwnerBean();
BeanDescriptor<? extends Object> parentDesc = context.desc.getBeanDescriptor(ownerBean.getClass());
Object parentId = parentDesc.getId(ownerBean);
if (parentDesc.cacheLoadMany(context.property, bc, parentId, context.parent.isReadOnly())) {
@@ -1111,7 +1111,7 @@ public final class DefaultPersister implements Persister {
// check for partial objects
if (request.isLoadedProperty(prop)) {
Object detailBean = prop.getValue(request.getBean());
Object detailBean = prop.getValue(request.getEntityBean());
if (detailBean != null) {
if (isReference(detailBean)) {
// skip saving a reference
@@ -47,16 +47,16 @@ public class FactoryBaseProperties {
for (int i = 0; i < props.length; i++) {
if(DmlMode.WHERE.equals(mode) && !withLobs && !props[i].isDbUpdatable()) {
// skip non-updatable column from where clause
} else {
// if(DmlMode.WHERE.equals(mode) && !withLobs && !props[i].isDbUpdatable()) {
// // skip non-updatable column from where clause
// } else {
Bindable item = factoryProperty.create(props[i], mode, withLobs);
if (item != null) {
list.add(item);
} else {
// null where readOnly (Secondary tables) or Lob exclusion
}
}
// }
}
}
@@ -94,7 +94,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
private Object lazyLoadParentId;
private Object lazyLoadParentBean;
private EntityBean lazyLoadParentBean;
/**
* Holds the previous loaded bean.
@@ -466,7 +466,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
if (lazyLoadParentId != null) {
if (!lazyLoadParentId.equals(this.lazyLoadParentId)) {
// get the appropriate parent bean from the persistence context
this.lazyLoadParentBean = persistenceContext.get(lazyLoadManyProperty.getBeanDescriptor().getBeanType(), lazyLoadParentId);
this.lazyLoadParentBean = (EntityBean)persistenceContext.get(lazyLoadManyProperty.getBeanDescriptor().getBeanType(), lazyLoadParentId);
this.lazyLoadParentId = lazyLoadParentId;
}
@@ -29,8 +29,9 @@ class CQueryIteratorSimple<T> implements QueryIterator<T> {
}
}
@SuppressWarnings("unchecked")
public T next() {
return cquery.getLoadedBean();
return (T)cquery.getLoadedBean();
}
public void close() {
@@ -36,7 +36,7 @@ class CQueryIteratorWithBuffer<T> implements QueryIterator<T> {
int i = -1;
while (moreToLoad && ++i < bufferSize) {
if (cquery.hasNextBean(true)) {
buffer.add(cquery.getLoadedBean());
buffer.add((T)cquery.getLoadedBean());
} else {
moreToLoad = false;
}
@@ -1,39 +0,0 @@
package com.avaje.ebeaninternal.server.query;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
public class LoadedPropertiesCache {
static ConcurrentHashMap<Integer, Set<String>> cache = new ConcurrentHashMap<Integer, Set<String>>(250, 0.75f, 16);
public static Set<String> get(int partialHash, Set<String> partialProps, BeanDescriptor<?> desc){
int manyHash = desc.getNamesOfManyPropsHash();
int totalHash = 37*partialHash + manyHash;
Integer key = Integer.valueOf(totalHash);
Set<String> includedProps = cache.get(key);
if (includedProps == null){
// its not in the cache so build it
LinkedHashSet<String> mergeNames = new LinkedHashSet<String>();
mergeNames.addAll(partialProps);
if (manyHash != 0){
mergeNames.addAll(desc.getNamesOfManyProps());
}
// we want it to be immutable and cache it
includedProps = Collections.unmodifiableSet(mergeNames);
cache.put(key, includedProps);
}
return includedProps;
}
}
@@ -4,7 +4,6 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.EntityBean;
@@ -499,55 +498,19 @@ public class SqlTreeNodeBean implements SqlTreeNode {
return "SqlTreeNodeBean: " + desc;
}
private boolean isLoadContextBeanNeeded(Mode queryMode, Object contextBean) {
private boolean isLoadContextBeanNeeded(Mode queryMode, EntityBean contextBean) {
// if explicitly set loadContextBean to true, then reload
if (queryMode.isLoadContextBean()) {
return true;
}
// if contextBean is not EntityBean (I doubt this will happen), then reload
if (!(contextBean instanceof EntityBean)) {
return true;
}
EntityBean cb = (EntityBean) contextBean;
// always reload if contextBean is reference
if (cb._ebean_getIntercept().isReference()) {
return true;
}
// when localBean is partial object
if (partialObject) {
// don't reload if localBean is partial object but contextBean is not
if (cb._ebean_intercept().getLoadedProps() == null) {
return false;
}
// when both localBean and contextBean are partial objects
if (cb._ebean_getIntercept().getLoadedProps().containsAll(partialProps)) {
// don't reload if contextBean has all the properties which are included
// for localBean
return false;
} else {
// otherwise reload, need to add the loadedProps of context bean to the
// incluededProps of localBean
partialProps.addAll(cb._ebean_getIntercept().getLoadedProps());
// recalculate partialHash and includedProps
partialHash = partialProps.hashCode();
includedProps = LoadedPropertiesCache.get(partialHash, partialProps, desc);
return true;
}
}
// when localBean is not partial object
if (cb._ebean_getIntercept().getLoadedProps() != null) {
if (contextBean._ebean_getIntercept().isFullyLoadedBean()) {
// reload if contextBean is partial object
return true;
return false;
}
// return false by default
return false;
// return true by default
return true;
}
}
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.query;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
@@ -79,13 +79,13 @@ public class WriteJsonContext implements JsonWriter {
return;
}
Object o = it.next();
EntityBean o = (EntityBean)it.next();
BeanDescriptor<?> d = getDecriptor(o.getClass());
d.jsonWrite(this, o);
while (it.hasNext()) {
appendComma();
Object t = it.next();
EntityBean t = (EntityBean)it.next();
d.jsonWrite(this, t);
}
endAssocMany();