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
@@ -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;