mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Remove underlying Scala support
This commit is contained in:
@@ -202,7 +202,7 @@ public class DefaultBeanLoader {
|
||||
BeanDescriptor<?> parentDesc = server.getBeanDescriptor(parentBean.getClass());
|
||||
BeanPropertyAssocMany<?> many = (BeanPropertyAssocMany<?>) parentDesc.getBeanProperty(propertyName);
|
||||
|
||||
Object currentValue = many.getValueUnderlying(parentBean);
|
||||
Object currentValue = many.getValue(parentBean);
|
||||
if (currentValue instanceof BeanCollection<?>) {
|
||||
beanCollection = (BeanCollection<?>) currentValue;
|
||||
filterMany = beanCollection.getFilterMany();
|
||||
|
||||
@@ -1,167 +1,167 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.InvalidValue;
|
||||
import com.avaje.ebean.Query;
|
||||
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.common.BeanList;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
|
||||
/**
|
||||
* Helper object for dealing with Lists.
|
||||
*/
|
||||
public final class BeanListHelp<T> implements BeanCollectionHelp<T> {
|
||||
|
||||
private final BeanPropertyAssocMany<T> many;
|
||||
private final BeanDescriptor<T> targetDescriptor;
|
||||
private BeanCollectionLoader loader;
|
||||
|
||||
public BeanListHelp(BeanPropertyAssocMany<T> many) {
|
||||
this.many = many;
|
||||
this.targetDescriptor = many.getTargetDescriptor();
|
||||
}
|
||||
|
||||
public BeanListHelp() {
|
||||
this.many = null;
|
||||
this.targetDescriptor = null;
|
||||
}
|
||||
|
||||
public void setLoader(BeanCollectionLoader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public void add(BeanCollection<?> collection, Object bean) {
|
||||
collection.internalAdd(bean);
|
||||
}
|
||||
|
||||
public BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey) {
|
||||
|
||||
if (bc instanceof BeanList<?>) {
|
||||
|
||||
BeanList<?> bl = (BeanList<?>) bc;
|
||||
if (bl.getActualList() == null) {
|
||||
bl.setActualList(new ArrayList<Object>());
|
||||
}
|
||||
return bl;
|
||||
} else if (bc instanceof List<?>) {
|
||||
return new VanillaAdd((List<?>) bc);
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled type " + bc);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static class VanillaAdd implements BeanCollectionAdd {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final List list;
|
||||
|
||||
private VanillaAdd(List<?> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public void addBean(Object bean) {
|
||||
list.add(bean);
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<?> getIterator(Object collection) {
|
||||
return ((List<?>) collection).iterator();
|
||||
}
|
||||
|
||||
public Object createEmpty(boolean vanilla) {
|
||||
return vanilla ? new ArrayList<T>() : new BeanList<T>();
|
||||
}
|
||||
|
||||
public BeanCollection<T> createReference(Object parentBean, String propertyName) {
|
||||
|
||||
return new BeanList<T>(loader, parentBean, propertyName);
|
||||
}
|
||||
|
||||
public ArrayList<InvalidValue> validate(Object manyValue) {
|
||||
|
||||
ArrayList<InvalidValue> errs = null;
|
||||
|
||||
List<?> l = (List<?>) manyValue;
|
||||
for (int i = 0; i < l.size(); i++) {
|
||||
Object detailBean = l.get(i);
|
||||
InvalidValue invalid = targetDescriptor.validate(true, detailBean);
|
||||
if (invalid != null) {
|
||||
if (errs == null) {
|
||||
errs = new ArrayList<InvalidValue>();
|
||||
}
|
||||
errs.add(invalid);
|
||||
}
|
||||
}
|
||||
return errs;
|
||||
}
|
||||
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
|
||||
|
||||
BeanList<?> newBeanList = (BeanList<?>) server.findList(query, t);
|
||||
refresh(newBeanList, parentBean);
|
||||
}
|
||||
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean) {
|
||||
|
||||
BeanList<?> newBeanList = (BeanList<?>) bc;
|
||||
|
||||
List<?> currentList = (List<?>) many.getValueUnderlying(parentBean);
|
||||
|
||||
newBeanList.setModifyListening(many.getModifyListenMode());
|
||||
|
||||
if (currentList == null) {
|
||||
// the currentList is null? Not really expecting this...
|
||||
many.setValue(parentBean, newBeanList);
|
||||
|
||||
} else if (currentList instanceof BeanList<?>) {
|
||||
// normally this case, replace just the underlying list
|
||||
BeanList<?> currentBeanList = (BeanList<?>) currentList;
|
||||
currentBeanList.setActualList(newBeanList.getActualList());
|
||||
currentBeanList.setModifyListening(many.getModifyListenMode());
|
||||
|
||||
} else {
|
||||
// replace the entire list with the BeanList
|
||||
many.setValue(parentBean, newBeanList);
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJsonContext ctx, String name, Object collection, boolean explicitInclude) {
|
||||
|
||||
List<?> list;
|
||||
if (collection instanceof BeanCollection<?>) {
|
||||
BeanList<?> beanList = (BeanList<?>) collection;
|
||||
if (!beanList.isPopulated()) {
|
||||
if (explicitInclude) {
|
||||
// invoke lazy loading as collection
|
||||
// is explicitly included in the output
|
||||
beanList.size();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
list = beanList.getActualList();
|
||||
} else {
|
||||
list = (List<?>) collection;
|
||||
}
|
||||
|
||||
ctx.beginAssocMany(name);
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
if (j > 0) {
|
||||
ctx.appendComma();
|
||||
}
|
||||
Object detailBean = list.get(j);
|
||||
targetDescriptor.jsonWrite(ctx, detailBean);
|
||||
}
|
||||
ctx.endAssocMany();
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.InvalidValue;
|
||||
import com.avaje.ebean.Query;
|
||||
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.common.BeanList;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
|
||||
/**
|
||||
* Helper object for dealing with Lists.
|
||||
*/
|
||||
public final class BeanListHelp<T> implements BeanCollectionHelp<T> {
|
||||
|
||||
private final BeanPropertyAssocMany<T> many;
|
||||
private final BeanDescriptor<T> targetDescriptor;
|
||||
private BeanCollectionLoader loader;
|
||||
|
||||
public BeanListHelp(BeanPropertyAssocMany<T> many) {
|
||||
this.many = many;
|
||||
this.targetDescriptor = many.getTargetDescriptor();
|
||||
}
|
||||
|
||||
public BeanListHelp() {
|
||||
this.many = null;
|
||||
this.targetDescriptor = null;
|
||||
}
|
||||
|
||||
public void setLoader(BeanCollectionLoader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public void add(BeanCollection<?> collection, Object bean) {
|
||||
collection.internalAdd(bean);
|
||||
}
|
||||
|
||||
public BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey) {
|
||||
|
||||
if (bc instanceof BeanList<?>) {
|
||||
|
||||
BeanList<?> bl = (BeanList<?>) bc;
|
||||
if (bl.getActualList() == null) {
|
||||
bl.setActualList(new ArrayList<Object>());
|
||||
}
|
||||
return bl;
|
||||
} else if (bc instanceof List<?>) {
|
||||
return new VanillaAdd((List<?>) bc);
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled type " + bc);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static class VanillaAdd implements BeanCollectionAdd {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final List list;
|
||||
|
||||
private VanillaAdd(List<?> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public void addBean(Object bean) {
|
||||
list.add(bean);
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<?> getIterator(Object collection) {
|
||||
return ((List<?>) collection).iterator();
|
||||
}
|
||||
|
||||
public Object createEmpty(boolean vanilla) {
|
||||
return vanilla ? new ArrayList<T>() : new BeanList<T>();
|
||||
}
|
||||
|
||||
public BeanCollection<T> createReference(Object parentBean, String propertyName) {
|
||||
|
||||
return new BeanList<T>(loader, parentBean, propertyName);
|
||||
}
|
||||
|
||||
public ArrayList<InvalidValue> validate(Object manyValue) {
|
||||
|
||||
ArrayList<InvalidValue> errs = null;
|
||||
|
||||
List<?> l = (List<?>) manyValue;
|
||||
for (int i = 0; i < l.size(); i++) {
|
||||
Object detailBean = l.get(i);
|
||||
InvalidValue invalid = targetDescriptor.validate(true, detailBean);
|
||||
if (invalid != null) {
|
||||
if (errs == null) {
|
||||
errs = new ArrayList<InvalidValue>();
|
||||
}
|
||||
errs.add(invalid);
|
||||
}
|
||||
}
|
||||
return errs;
|
||||
}
|
||||
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
|
||||
|
||||
BeanList<?> newBeanList = (BeanList<?>) server.findList(query, t);
|
||||
refresh(newBeanList, parentBean);
|
||||
}
|
||||
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean) {
|
||||
|
||||
BeanList<?> newBeanList = (BeanList<?>) bc;
|
||||
|
||||
List<?> currentList = (List<?>) many.getValue(parentBean);
|
||||
|
||||
newBeanList.setModifyListening(many.getModifyListenMode());
|
||||
|
||||
if (currentList == null) {
|
||||
// the currentList is null? Not really expecting this...
|
||||
many.setValue(parentBean, newBeanList);
|
||||
|
||||
} else if (currentList instanceof BeanList<?>) {
|
||||
// normally this case, replace just the underlying list
|
||||
BeanList<?> currentBeanList = (BeanList<?>) currentList;
|
||||
currentBeanList.setActualList(newBeanList.getActualList());
|
||||
currentBeanList.setModifyListening(many.getModifyListenMode());
|
||||
|
||||
} else {
|
||||
// replace the entire list with the BeanList
|
||||
many.setValue(parentBean, newBeanList);
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJsonContext ctx, String name, Object collection, boolean explicitInclude) {
|
||||
|
||||
List<?> list;
|
||||
if (collection instanceof BeanCollection<?>) {
|
||||
BeanList<?> beanList = (BeanList<?>) collection;
|
||||
if (!beanList.isPopulated()) {
|
||||
if (explicitInclude) {
|
||||
// invoke lazy loading as collection
|
||||
// is explicitly included in the output
|
||||
beanList.size();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
list = beanList.getActualList();
|
||||
} else {
|
||||
list = (List<?>) collection;
|
||||
}
|
||||
|
||||
ctx.beginAssocMany(name);
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
if (j > 0) {
|
||||
ctx.appendComma();
|
||||
}
|
||||
Object detailBean = list.get(j);
|
||||
targetDescriptor.jsonWrite(ctx, detailBean);
|
||||
}
|
||||
ctx.endAssocMany();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,205 +1,205 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.InvalidValue;
|
||||
import com.avaje.ebean.Query;
|
||||
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.common.BeanMap;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
|
||||
/**
|
||||
* Helper specifically for dealing with Maps.
|
||||
*/
|
||||
public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
|
||||
|
||||
private final BeanPropertyAssocMany<T> many;
|
||||
private final BeanDescriptor<T> targetDescriptor;
|
||||
private final BeanProperty beanProperty;
|
||||
private BeanCollectionLoader loader;
|
||||
//private final String mapKey;
|
||||
|
||||
/**
|
||||
* When created for a given query that will return a map.
|
||||
*/
|
||||
public BeanMapHelp(BeanDescriptor<T> targetDescriptor, String mapKey) {
|
||||
this(null, targetDescriptor, mapKey);
|
||||
}
|
||||
|
||||
public BeanMapHelp(BeanPropertyAssocMany<T> many){
|
||||
this(many, many.getTargetDescriptor(), many.getMapKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* When help is attached to a specific many property.
|
||||
*/
|
||||
private BeanMapHelp(BeanPropertyAssocMany<T> many, BeanDescriptor<T> targetDescriptor, String mapKey){
|
||||
this.many = many;
|
||||
this.targetDescriptor = targetDescriptor;
|
||||
//this.mapKey = mapKey;
|
||||
this.beanProperty = targetDescriptor.getBeanProperty(mapKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an iterator of the values.
|
||||
*/
|
||||
public Iterator<?> getIterator(Object collection) {
|
||||
return ((Map<?,?>) collection).values().iterator();
|
||||
}
|
||||
|
||||
public void setLoader(BeanCollectionLoader loader){
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey) {
|
||||
|
||||
if(mapKey == null){
|
||||
mapKey = many.getMapKey();
|
||||
}
|
||||
BeanProperty beanProp = targetDescriptor.getBeanProperty(mapKey);
|
||||
|
||||
if (bc instanceof BeanMap<?,?>){
|
||||
BeanMap<Object, Object> bm = (BeanMap<Object, Object>)bc;
|
||||
Map<Object, Object> actualMap = bm.getActualMap();
|
||||
if (actualMap == null){
|
||||
actualMap = new LinkedHashMap<Object, Object>();
|
||||
bm.setActualMap(actualMap);
|
||||
}
|
||||
return new Adder(beanProp, actualMap);
|
||||
|
||||
} else if (bc instanceof Map<?,?>) {
|
||||
return new Adder(beanProp, (Map<Object, Object>)bc);
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled type "+bc);
|
||||
}
|
||||
}
|
||||
|
||||
static class Adder implements BeanCollectionAdd {
|
||||
|
||||
private final BeanProperty beanProperty;
|
||||
|
||||
private final Map<Object, Object> map;
|
||||
|
||||
Adder(BeanProperty beanProperty, Map<Object, Object> map) {
|
||||
this.beanProperty = beanProperty;
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public void addBean(Object bean) {
|
||||
Object keyValue = beanProperty.getValue(bean);
|
||||
map.put(keyValue, bean);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object createEmpty(boolean vanilla) {
|
||||
return vanilla ? new LinkedHashMap() : new BeanMap();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void add(BeanCollection<?> collection, Object bean) {
|
||||
|
||||
Object keyValue = beanProperty.getValueIntercept(bean);
|
||||
|
||||
Map<Object, Object> map = (Map<Object, Object>) collection;
|
||||
map.put(keyValue, bean);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public BeanCollection<T> createReference(Object parentBean, String propertyName) {
|
||||
|
||||
return new BeanMap(loader, parentBean, propertyName);
|
||||
}
|
||||
|
||||
public ArrayList<InvalidValue> validate(Object manyValue) {
|
||||
|
||||
ArrayList<InvalidValue> errs = null;
|
||||
|
||||
Map<?, ?> m = (Map<?, ?>) manyValue;
|
||||
Iterator<?> it = m.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
Object detailBean = (Object) it.next();
|
||||
InvalidValue invalid = targetDescriptor.validate(true, detailBean);
|
||||
if (invalid != null) {
|
||||
if (errs == null) {
|
||||
errs = new ArrayList<InvalidValue>();
|
||||
}
|
||||
errs.add(invalid);
|
||||
}
|
||||
}
|
||||
|
||||
return errs;
|
||||
}
|
||||
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
|
||||
BeanMap<?, ?> newBeanMap = (BeanMap<?, ?>) server.findMap(query, t);
|
||||
refresh(newBeanMap, parentBean);
|
||||
}
|
||||
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean) {
|
||||
|
||||
BeanMap<?, ?> newBeanMap = (BeanMap<?, ?>) bc;
|
||||
Map<?, ?> current = (Map<?, ?>) many.getValueUnderlying(parentBean);
|
||||
|
||||
newBeanMap.setModifyListening(many.getModifyListenMode());
|
||||
if (current == null) {
|
||||
// the currentMap is null? Not really expecting this...
|
||||
many.setValue(parentBean, newBeanMap);
|
||||
|
||||
} else if (current instanceof BeanMap<?,?>) {
|
||||
// normally this case, replace just the underlying list
|
||||
BeanMap<?, ?> currentBeanMap = (BeanMap<?, ?>) current;
|
||||
currentBeanMap.setActualMap(newBeanMap.getActualMap());
|
||||
currentBeanMap.setModifyListening(many.getModifyListenMode());
|
||||
|
||||
} else {
|
||||
// replace the entire set
|
||||
many.setValue(parentBean, newBeanMap);
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJsonContext ctx, String name, Object collection, boolean explicitInclude) {
|
||||
|
||||
Map<?,?> map;
|
||||
if (collection instanceof BeanCollection<?>){
|
||||
BeanMap<?,?> bc = (BeanMap<?,?>)collection;
|
||||
if (!bc.isPopulated()){
|
||||
if (explicitInclude){
|
||||
// invoke lazy loading as collection
|
||||
// is explicitly included in the output
|
||||
bc.size();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = bc.getActualMap();
|
||||
} else {
|
||||
map = (Map<?,?>)collection;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
ctx.beginAssocMany(name);
|
||||
Iterator<?> it = map.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<?, ?> entry = (Entry<?, ?>)it.next();
|
||||
if (count++ > 0){
|
||||
ctx.appendComma();
|
||||
}
|
||||
//FIXME: json write map key ...
|
||||
Object detailBean = entry.getValue();
|
||||
targetDescriptor.jsonWrite(ctx, detailBean);
|
||||
}
|
||||
ctx.endAssocMany();
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.InvalidValue;
|
||||
import com.avaje.ebean.Query;
|
||||
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.common.BeanMap;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
|
||||
/**
|
||||
* Helper specifically for dealing with Maps.
|
||||
*/
|
||||
public final class BeanMapHelp<T> implements BeanCollectionHelp<T> {
|
||||
|
||||
private final BeanPropertyAssocMany<T> many;
|
||||
private final BeanDescriptor<T> targetDescriptor;
|
||||
private final BeanProperty beanProperty;
|
||||
private BeanCollectionLoader loader;
|
||||
//private final String mapKey;
|
||||
|
||||
/**
|
||||
* When created for a given query that will return a map.
|
||||
*/
|
||||
public BeanMapHelp(BeanDescriptor<T> targetDescriptor, String mapKey) {
|
||||
this(null, targetDescriptor, mapKey);
|
||||
}
|
||||
|
||||
public BeanMapHelp(BeanPropertyAssocMany<T> many){
|
||||
this(many, many.getTargetDescriptor(), many.getMapKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* When help is attached to a specific many property.
|
||||
*/
|
||||
private BeanMapHelp(BeanPropertyAssocMany<T> many, BeanDescriptor<T> targetDescriptor, String mapKey){
|
||||
this.many = many;
|
||||
this.targetDescriptor = targetDescriptor;
|
||||
//this.mapKey = mapKey;
|
||||
this.beanProperty = targetDescriptor.getBeanProperty(mapKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an iterator of the values.
|
||||
*/
|
||||
public Iterator<?> getIterator(Object collection) {
|
||||
return ((Map<?,?>) collection).values().iterator();
|
||||
}
|
||||
|
||||
public void setLoader(BeanCollectionLoader loader){
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey) {
|
||||
|
||||
if(mapKey == null){
|
||||
mapKey = many.getMapKey();
|
||||
}
|
||||
BeanProperty beanProp = targetDescriptor.getBeanProperty(mapKey);
|
||||
|
||||
if (bc instanceof BeanMap<?,?>){
|
||||
BeanMap<Object, Object> bm = (BeanMap<Object, Object>)bc;
|
||||
Map<Object, Object> actualMap = bm.getActualMap();
|
||||
if (actualMap == null){
|
||||
actualMap = new LinkedHashMap<Object, Object>();
|
||||
bm.setActualMap(actualMap);
|
||||
}
|
||||
return new Adder(beanProp, actualMap);
|
||||
|
||||
} else if (bc instanceof Map<?,?>) {
|
||||
return new Adder(beanProp, (Map<Object, Object>)bc);
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled type "+bc);
|
||||
}
|
||||
}
|
||||
|
||||
static class Adder implements BeanCollectionAdd {
|
||||
|
||||
private final BeanProperty beanProperty;
|
||||
|
||||
private final Map<Object, Object> map;
|
||||
|
||||
Adder(BeanProperty beanProperty, Map<Object, Object> map) {
|
||||
this.beanProperty = beanProperty;
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public void addBean(Object bean) {
|
||||
Object keyValue = beanProperty.getValue(bean);
|
||||
map.put(keyValue, bean);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object createEmpty(boolean vanilla) {
|
||||
return vanilla ? new LinkedHashMap() : new BeanMap();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void add(BeanCollection<?> collection, Object bean) {
|
||||
|
||||
Object keyValue = beanProperty.getValueIntercept(bean);
|
||||
|
||||
Map<Object, Object> map = (Map<Object, Object>) collection;
|
||||
map.put(keyValue, bean);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public BeanCollection<T> createReference(Object parentBean, String propertyName) {
|
||||
|
||||
return new BeanMap(loader, parentBean, propertyName);
|
||||
}
|
||||
|
||||
public ArrayList<InvalidValue> validate(Object manyValue) {
|
||||
|
||||
ArrayList<InvalidValue> errs = null;
|
||||
|
||||
Map<?, ?> m = (Map<?, ?>) manyValue;
|
||||
Iterator<?> it = m.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
Object detailBean = (Object) it.next();
|
||||
InvalidValue invalid = targetDescriptor.validate(true, detailBean);
|
||||
if (invalid != null) {
|
||||
if (errs == null) {
|
||||
errs = new ArrayList<InvalidValue>();
|
||||
}
|
||||
errs.add(invalid);
|
||||
}
|
||||
}
|
||||
|
||||
return errs;
|
||||
}
|
||||
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
|
||||
BeanMap<?, ?> newBeanMap = (BeanMap<?, ?>) server.findMap(query, t);
|
||||
refresh(newBeanMap, parentBean);
|
||||
}
|
||||
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean) {
|
||||
|
||||
BeanMap<?, ?> newBeanMap = (BeanMap<?, ?>) bc;
|
||||
Map<?, ?> current = (Map<?, ?>) many.getValue(parentBean);
|
||||
|
||||
newBeanMap.setModifyListening(many.getModifyListenMode());
|
||||
if (current == null) {
|
||||
// the currentMap is null? Not really expecting this...
|
||||
many.setValue(parentBean, newBeanMap);
|
||||
|
||||
} else if (current instanceof BeanMap<?,?>) {
|
||||
// normally this case, replace just the underlying list
|
||||
BeanMap<?, ?> currentBeanMap = (BeanMap<?, ?>) current;
|
||||
currentBeanMap.setActualMap(newBeanMap.getActualMap());
|
||||
currentBeanMap.setModifyListening(many.getModifyListenMode());
|
||||
|
||||
} else {
|
||||
// replace the entire set
|
||||
many.setValue(parentBean, newBeanMap);
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJsonContext ctx, String name, Object collection, boolean explicitInclude) {
|
||||
|
||||
Map<?,?> map;
|
||||
if (collection instanceof BeanCollection<?>){
|
||||
BeanMap<?,?> bc = (BeanMap<?,?>)collection;
|
||||
if (!bc.isPopulated()){
|
||||
if (explicitInclude){
|
||||
// invoke lazy loading as collection
|
||||
// is explicitly included in the output
|
||||
bc.size();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
map = bc.getActualMap();
|
||||
} else {
|
||||
map = (Map<?,?>)collection;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
ctx.beginAssocMany(name);
|
||||
Iterator<?> it = map.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<?, ?> entry = (Entry<?, ?>)it.next();
|
||||
if (count++ > 0){
|
||||
ctx.appendComma();
|
||||
}
|
||||
//FIXME: json write map key ...
|
||||
Object detailBean = entry.getValue();
|
||||
targetDescriptor.jsonWrite(ctx, detailBean);
|
||||
}
|
||||
ctx.endAssocMany();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,9 +87,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
String deleteByParentIdSql;
|
||||
String deleteByParentIdInSql;
|
||||
|
||||
|
||||
final CollectionTypeConverter typeConverter;
|
||||
|
||||
|
||||
/**
|
||||
* Create this property.
|
||||
*/
|
||||
@@ -99,7 +97,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
this.manyToMany = deploy.isManyToMany();
|
||||
this.serverName = descriptor.getServerName();
|
||||
this.manyType = deploy.getManyType();
|
||||
this.typeConverter = manyType.getTypeConverter();
|
||||
|
||||
this.mapKey = deploy.getMapKey();
|
||||
this.fetchOrderBy = deploy.getFetchOrderBy();
|
||||
|
||||
@@ -147,19 +145,6 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying List Set or Map.
|
||||
* For unwrapping scala collection types etc.
|
||||
*/
|
||||
public Object getValueUnderlying(Object bean) {
|
||||
|
||||
Object value = getValue(bean);
|
||||
if (typeConverter != null){
|
||||
value = typeConverter.toUnderlying(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(Object bean) {
|
||||
return super.getValue(bean);
|
||||
@@ -172,17 +157,11 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
|
||||
@Override
|
||||
public void setValue(Object bean, Object value) {
|
||||
if (typeConverter != null){
|
||||
value = typeConverter.toWrapped(value);
|
||||
}
|
||||
super.setValue(bean, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueIntercept(Object bean, Object value) {
|
||||
if (typeConverter != null){
|
||||
value = typeConverter.toWrapped(value);
|
||||
}
|
||||
super.setValueIntercept(bean, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,174 +1,174 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.InvalidValue;
|
||||
import com.avaje.ebean.Query;
|
||||
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.common.BeanSet;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
|
||||
/**
|
||||
* Helper specifically for dealing with Sets.
|
||||
*/
|
||||
public final class BeanSetHelp<T> implements BeanCollectionHelp<T> {
|
||||
|
||||
private final BeanPropertyAssocMany<T> many;
|
||||
private final BeanDescriptor<T> targetDescriptor;
|
||||
private BeanCollectionLoader loader;
|
||||
|
||||
/**
|
||||
* When attached to a specific many property.
|
||||
*/
|
||||
public BeanSetHelp(BeanPropertyAssocMany<T> many){
|
||||
this.many = many;
|
||||
this.targetDescriptor = many.getTargetDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
* For a query that returns a set.
|
||||
*/
|
||||
public BeanSetHelp(){
|
||||
this.many = null;
|
||||
this.targetDescriptor = null;
|
||||
}
|
||||
|
||||
public void setLoader(BeanCollectionLoader loader){
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public Iterator<?> getIterator(Object collection) {
|
||||
return ((Set<?>) collection).iterator();
|
||||
}
|
||||
|
||||
public BeanCollectionAdd getBeanCollectionAdd(Object bc,String mapKey) {
|
||||
if (bc instanceof BeanSet<?>){
|
||||
BeanSet<?> beanSet = (BeanSet<?>)bc;
|
||||
if (beanSet.getActualSet() == null){
|
||||
beanSet.setActualSet(new LinkedHashSet<Object>());
|
||||
}
|
||||
return beanSet;
|
||||
} else if (bc instanceof Set<?>) {
|
||||
return new VanillaAdd((Set<?>)bc);
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled type "+bc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static class VanillaAdd implements BeanCollectionAdd {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final Set set;
|
||||
|
||||
private VanillaAdd(Set<?> set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
public void addBean(Object bean) {
|
||||
set.add(bean);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(BeanCollection<?> collection, Object bean) {
|
||||
collection.internalAdd(bean);
|
||||
}
|
||||
|
||||
public Object createEmpty(boolean vanilla) {
|
||||
return vanilla ? new LinkedHashSet<T>() : new BeanSet<T>();
|
||||
}
|
||||
|
||||
public BeanCollection<T> createReference(Object parentBean, String propertyName) {
|
||||
|
||||
return new BeanSet<T>(loader, parentBean, propertyName);
|
||||
}
|
||||
|
||||
public ArrayList<InvalidValue> validate(Object manyValue) {
|
||||
|
||||
ArrayList<InvalidValue> errs = null;
|
||||
|
||||
Set<?> set = (Set<?>)manyValue;
|
||||
Iterator<?> i = set.iterator();
|
||||
while (i.hasNext()) {
|
||||
Object detailBean = i.next();
|
||||
InvalidValue invalid = targetDescriptor.validate(true, detailBean);
|
||||
if (invalid != null){
|
||||
if (errs == null){
|
||||
errs = new ArrayList<InvalidValue>();
|
||||
}
|
||||
errs.add(invalid);
|
||||
}
|
||||
}
|
||||
return errs;
|
||||
}
|
||||
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
|
||||
|
||||
BeanSet<?> newBeanSet = (BeanSet<?>)server.findSet(query, t);
|
||||
refresh(newBeanSet, parentBean);
|
||||
}
|
||||
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean) {
|
||||
|
||||
BeanSet<?> newBeanSet = (BeanSet<?>)bc;
|
||||
|
||||
Set<?> current = (Set<?>)many.getValueUnderlying(parentBean);
|
||||
|
||||
newBeanSet.setModifyListening(many.getModifyListenMode());
|
||||
if (current == null){
|
||||
// the currentList is null? Not really expecting this...
|
||||
many.setValue(parentBean,newBeanSet);
|
||||
|
||||
} else if (current instanceof BeanSet<?>) {
|
||||
// normally this case, replace just the underlying list
|
||||
BeanSet<?> currentBeanSet = (BeanSet<?>)current;
|
||||
currentBeanSet.setActualSet(newBeanSet.getActualSet());
|
||||
currentBeanSet.setModifyListening(many.getModifyListenMode());
|
||||
|
||||
} else {
|
||||
// replace the entire set
|
||||
many.setValue(parentBean, newBeanSet);
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJsonContext ctx, String name, Object collection, boolean explicitInclude) {
|
||||
|
||||
Set<?> set;
|
||||
if (collection instanceof BeanCollection<?>){
|
||||
BeanSet<?> bc = (BeanSet<?>)collection;
|
||||
if (!bc.isPopulated()){
|
||||
if (explicitInclude){
|
||||
// invoke lazy loading as collection
|
||||
// is explicitly included in the output
|
||||
bc.size();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
set = bc.getActualSet();
|
||||
} else {
|
||||
set = (Set<?>)collection;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
ctx.beginAssocMany(name);
|
||||
Iterator<?> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
Object detailBean = it.next();
|
||||
if (count++ > 0){
|
||||
ctx.appendComma();
|
||||
}
|
||||
targetDescriptor.jsonWrite(ctx, detailBean);
|
||||
}
|
||||
ctx.endAssocMany();
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.InvalidValue;
|
||||
import com.avaje.ebean.Query;
|
||||
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.common.BeanSet;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJsonContext;
|
||||
|
||||
/**
|
||||
* Helper specifically for dealing with Sets.
|
||||
*/
|
||||
public final class BeanSetHelp<T> implements BeanCollectionHelp<T> {
|
||||
|
||||
private final BeanPropertyAssocMany<T> many;
|
||||
private final BeanDescriptor<T> targetDescriptor;
|
||||
private BeanCollectionLoader loader;
|
||||
|
||||
/**
|
||||
* When attached to a specific many property.
|
||||
*/
|
||||
public BeanSetHelp(BeanPropertyAssocMany<T> many){
|
||||
this.many = many;
|
||||
this.targetDescriptor = many.getTargetDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
* For a query that returns a set.
|
||||
*/
|
||||
public BeanSetHelp(){
|
||||
this.many = null;
|
||||
this.targetDescriptor = null;
|
||||
}
|
||||
|
||||
public void setLoader(BeanCollectionLoader loader){
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public Iterator<?> getIterator(Object collection) {
|
||||
return ((Set<?>) collection).iterator();
|
||||
}
|
||||
|
||||
public BeanCollectionAdd getBeanCollectionAdd(Object bc,String mapKey) {
|
||||
if (bc instanceof BeanSet<?>){
|
||||
BeanSet<?> beanSet = (BeanSet<?>)bc;
|
||||
if (beanSet.getActualSet() == null){
|
||||
beanSet.setActualSet(new LinkedHashSet<Object>());
|
||||
}
|
||||
return beanSet;
|
||||
} else if (bc instanceof Set<?>) {
|
||||
return new VanillaAdd((Set<?>)bc);
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled type "+bc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static class VanillaAdd implements BeanCollectionAdd {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final Set set;
|
||||
|
||||
private VanillaAdd(Set<?> set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
public void addBean(Object bean) {
|
||||
set.add(bean);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(BeanCollection<?> collection, Object bean) {
|
||||
collection.internalAdd(bean);
|
||||
}
|
||||
|
||||
public Object createEmpty(boolean vanilla) {
|
||||
return vanilla ? new LinkedHashSet<T>() : new BeanSet<T>();
|
||||
}
|
||||
|
||||
public BeanCollection<T> createReference(Object parentBean, String propertyName) {
|
||||
|
||||
return new BeanSet<T>(loader, parentBean, propertyName);
|
||||
}
|
||||
|
||||
public ArrayList<InvalidValue> validate(Object manyValue) {
|
||||
|
||||
ArrayList<InvalidValue> errs = null;
|
||||
|
||||
Set<?> set = (Set<?>)manyValue;
|
||||
Iterator<?> i = set.iterator();
|
||||
while (i.hasNext()) {
|
||||
Object detailBean = i.next();
|
||||
InvalidValue invalid = targetDescriptor.validate(true, detailBean);
|
||||
if (invalid != null){
|
||||
if (errs == null){
|
||||
errs = new ArrayList<InvalidValue>();
|
||||
}
|
||||
errs.add(invalid);
|
||||
}
|
||||
}
|
||||
return errs;
|
||||
}
|
||||
|
||||
public void refresh(EbeanServer server, Query<?> query, Transaction t, Object parentBean) {
|
||||
|
||||
BeanSet<?> newBeanSet = (BeanSet<?>)server.findSet(query, t);
|
||||
refresh(newBeanSet, parentBean);
|
||||
}
|
||||
|
||||
public void refresh(BeanCollection<?> bc, Object parentBean) {
|
||||
|
||||
BeanSet<?> newBeanSet = (BeanSet<?>)bc;
|
||||
|
||||
Set<?> current = (Set<?>)many.getValue(parentBean);
|
||||
|
||||
newBeanSet.setModifyListening(many.getModifyListenMode());
|
||||
if (current == null){
|
||||
// the currentList is null? Not really expecting this...
|
||||
many.setValue(parentBean,newBeanSet);
|
||||
|
||||
} else if (current instanceof BeanSet<?>) {
|
||||
// normally this case, replace just the underlying list
|
||||
BeanSet<?> currentBeanSet = (BeanSet<?>)current;
|
||||
currentBeanSet.setActualSet(newBeanSet.getActualSet());
|
||||
currentBeanSet.setModifyListening(many.getModifyListenMode());
|
||||
|
||||
} else {
|
||||
// replace the entire set
|
||||
many.setValue(parentBean, newBeanSet);
|
||||
}
|
||||
}
|
||||
|
||||
public void jsonWrite(WriteJsonContext ctx, String name, Object collection, boolean explicitInclude) {
|
||||
|
||||
Set<?> set;
|
||||
if (collection instanceof BeanCollection<?>){
|
||||
BeanSet<?> bc = (BeanSet<?>)collection;
|
||||
if (!bc.isPopulated()){
|
||||
if (explicitInclude){
|
||||
// invoke lazy loading as collection
|
||||
// is explicitly included in the output
|
||||
bc.size();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
set = bc.getActualSet();
|
||||
} else {
|
||||
set = (Set<?>)collection;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
ctx.beginAssocMany(name);
|
||||
Iterator<?> it = set.iterator();
|
||||
while (it.hasNext()) {
|
||||
Object detailBean = it.next();
|
||||
if (count++ > 0){
|
||||
ctx.appendComma();
|
||||
}
|
||||
targetDescriptor.jsonWrite(ctx, detailBean);
|
||||
}
|
||||
ctx.endAssocMany();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
/**
|
||||
* Used to convert between collection types.
|
||||
* <P>
|
||||
* This typically means wrap and unwrap mutable scala collection types of Buffer, Set and Map.
|
||||
* </p>
|
||||
*
|
||||
* @author rbygrave
|
||||
*
|
||||
*/
|
||||
public interface CollectionTypeConverter {
|
||||
|
||||
/**
|
||||
* Convert the wrapped type to the underlying Java List, Set or Map.
|
||||
*/
|
||||
public Object toUnderlying(Object wrapped);
|
||||
|
||||
/**
|
||||
* Wrap the underlying Java List, Set or Map into the final collection type.
|
||||
*/
|
||||
public Object toWrapped(Object wrapped);
|
||||
|
||||
}
|
||||
@@ -1,64 +1,27 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Determine the Many Type for a property.
|
||||
* <p>
|
||||
* Scala types require CollectionTypeConverter's to wrap and unwrap from the
|
||||
* underlying java types used.
|
||||
* </p>
|
||||
*/
|
||||
public class DetermineManyType {
|
||||
|
||||
private final boolean withScalaSupport;
|
||||
private final ManyType scalaBufMany;
|
||||
private final ManyType scalaSetMany;
|
||||
private final ManyType scalaMapMany;
|
||||
|
||||
public DetermineManyType(boolean withScalaSupport) {
|
||||
this.withScalaSupport = withScalaSupport;
|
||||
if (withScalaSupport){
|
||||
|
||||
CollectionTypeConverter bufConverter = new ScalaBufferConverter();
|
||||
CollectionTypeConverter setConverter = new ScalaSetConverter();
|
||||
CollectionTypeConverter mapConverter = new ScalaMapConverter();
|
||||
|
||||
this.scalaBufMany = new ManyType(ManyType.Underlying.LIST, bufConverter);
|
||||
this.scalaSetMany = new ManyType(ManyType.Underlying.SET, setConverter);
|
||||
this.scalaMapMany = new ManyType(ManyType.Underlying.MAP, mapConverter);
|
||||
|
||||
} else {
|
||||
this.scalaBufMany = null;
|
||||
this.scalaSetMany = null;
|
||||
this.scalaMapMany = null;
|
||||
}
|
||||
}
|
||||
|
||||
public ManyType getManyType(Class<?> type) {
|
||||
if (type.equals(List.class)){
|
||||
return ManyType.JAVA_LIST;
|
||||
}
|
||||
if (type.equals(Set.class)){
|
||||
return ManyType.JAVA_SET;
|
||||
}
|
||||
if (type.equals(Map.class)){
|
||||
return ManyType.JAVA_MAP;
|
||||
}
|
||||
if (withScalaSupport){
|
||||
// only get in here when scala in classpath
|
||||
if (type.equals(scala.collection.mutable.Buffer.class)){
|
||||
return scalaBufMany;
|
||||
}
|
||||
if (type.equals(scala.collection.mutable.Set.class)){
|
||||
return scalaSetMany;
|
||||
}
|
||||
if (type.equals(scala.collection.mutable.Map.class)){
|
||||
return scalaMapMany;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Determine the Many Type for a property.
|
||||
*/
|
||||
public class DetermineManyType {
|
||||
|
||||
public DetermineManyType() {
|
||||
}
|
||||
|
||||
public ManyType getManyType(Class<?> type) {
|
||||
if (type.equals(List.class)) {
|
||||
return ManyType.JAVA_LIST;
|
||||
}
|
||||
if (type.equals(Set.class)) {
|
||||
return ManyType.JAVA_SET;
|
||||
}
|
||||
if (type.equals(Map.class)) {
|
||||
return ManyType.JAVA_MAP;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,9 @@ public class ManyType {
|
||||
|
||||
private final Underlying underlying;
|
||||
|
||||
private final CollectionTypeConverter typeConverter;
|
||||
|
||||
private ManyType(Underlying underlying) {
|
||||
this(underlying, null);
|
||||
}
|
||||
|
||||
public ManyType(Underlying underlying, CollectionTypeConverter typeConverter) {
|
||||
public ManyType(Underlying underlying) {
|
||||
this.underlying = underlying;
|
||||
this.typeConverter = typeConverter;
|
||||
switch (underlying) {
|
||||
case LIST:
|
||||
queryType = SpiQuery.Type.LIST;
|
||||
@@ -57,12 +51,5 @@ public class ManyType {
|
||||
public Underlying getUnderlying() {
|
||||
return underlying;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type converter if there is one.
|
||||
*/
|
||||
public CollectionTypeConverter getTypeConverter() {
|
||||
return typeConverter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import scala.collection.JavaConversions;
|
||||
|
||||
/**
|
||||
* Converts between Java List and Scala mutable Buffer.
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class ScalaBufferConverter implements CollectionTypeConverter {
|
||||
|
||||
// @SuppressWarnings({ "rawtypes" })
|
||||
public Object toUnderlying(Object wrapped) {
|
||||
throw new IllegalArgumentException("Scala types not supported in this build");
|
||||
// if (wrapped instanceof JavaConversions.JListWrapper){
|
||||
// return ((JavaConversions.JListWrapper)wrapped).underlying();
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
|
||||
public Object toWrapped(Object wrapped) {
|
||||
throw new IllegalArgumentException("Scala types not supported in this build");
|
||||
// if (wrapped instanceof java.util.List<?>){
|
||||
// return JavaConversions.asScalaBuffer((java.util.List<?>)wrapped);
|
||||
// }
|
||||
// return wrapped;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import scala.collection.JavaConversions;
|
||||
|
||||
/**
|
||||
* Converts between Java Map and Scala mutable Map.
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class ScalaMapConverter implements CollectionTypeConverter {
|
||||
|
||||
// @SuppressWarnings({ "rawtypes" })
|
||||
public Object toUnderlying(Object wrapped) {
|
||||
throw new IllegalArgumentException("Scala types not supported in this build");
|
||||
// if (wrapped instanceof JavaConversions.JMapWrapper){
|
||||
// return ((JavaConversions.JMapWrapper)wrapped).underlying();
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
|
||||
public Object toWrapped(Object wrapped) {
|
||||
throw new IllegalArgumentException("Scala types not supported in this build");
|
||||
// if (wrapped instanceof java.util.Map<?,?>){
|
||||
// return JavaConversions.mapAsScalaMap((java.util.Map<?,?>)wrapped);
|
||||
// }
|
||||
// return wrapped;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import scala.collection.JavaConversions;
|
||||
import scala.collection.convert.DecorateAsScala;
|
||||
|
||||
/**
|
||||
* Converts between Java Set and Scala mutable Set.
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class ScalaSetConverter implements CollectionTypeConverter {
|
||||
|
||||
// @SuppressWarnings({ "rawtypes" })
|
||||
public Object toUnderlying(Object wrapped) {
|
||||
throw new IllegalArgumentException("Scala types not supported in this build");
|
||||
// if (wrapped instanceof JavaConversions.JSetWrapper){
|
||||
// return ((JavaConversions.JSetWrapper)wrapped).underlying();
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
|
||||
public Object toWrapped(Object wrapped) {
|
||||
throw new IllegalArgumentException("Scala types not supported in this build");
|
||||
// if (wrapped instanceof java.util.Set<?>){
|
||||
// return JavaConversions.asScalaSet((java.util.Set<?>)wrapped);
|
||||
// }
|
||||
// return wrapped;
|
||||
}
|
||||
|
||||
}
|
||||
+8
-35
@@ -12,7 +12,6 @@ import java.util.logging.Logger;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
import com.avaje.ebeaninternal.server.core.Message;
|
||||
import com.avaje.ebeaninternal.server.deploy.DetermineManyType;
|
||||
import com.avaje.ebeaninternal.server.deploy.ManyType;
|
||||
@@ -23,7 +22,6 @@ import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyCompound;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertySimpleCollection;
|
||||
import com.avaje.ebeaninternal.server.type.CtCompoundType;
|
||||
import com.avaje.ebeaninternal.server.type.ScalaOptionTypeConverter;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
import com.avaje.ebeaninternal.server.type.reflect.CheckImmutableResponse;
|
||||
@@ -38,33 +36,14 @@ import com.avaje.ebeaninternal.server.type.reflect.CheckImmutableResponse;
|
||||
public class DeployCreateProperties {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DeployCreateProperties.class.getName());
|
||||
|
||||
private final Class<?> scalaOptionClass;
|
||||
/**
|
||||
* Use to wrap and unwrap Scala Option.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final ScalarTypeConverter scalaOptionTypeConverter;
|
||||
|
||||
private final DetermineManyType determineManyType;
|
||||
|
||||
private final DetermineManyType determineManyType;
|
||||
|
||||
private final TypeManager typeManager;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public DeployCreateProperties(TypeManager typeManager) {
|
||||
this.typeManager = typeManager;
|
||||
|
||||
Class<?> tmpOptionClass = DetectScala.getScalaOptionClass();
|
||||
|
||||
if (tmpOptionClass == null){
|
||||
scalaOptionClass = null;
|
||||
scalaOptionTypeConverter = null;
|
||||
} else {
|
||||
scalaOptionClass = tmpOptionClass;
|
||||
scalaOptionTypeConverter = new ScalaOptionTypeConverter();
|
||||
}
|
||||
|
||||
this.determineManyType = new DetermineManyType(tmpOptionClass != null);
|
||||
this.determineManyType = new DetermineManyType();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,12 +272,6 @@ public class DeployCreateProperties {
|
||||
|
||||
Class<?> propertyType = field.getType();
|
||||
Class<?> innerType = propertyType;
|
||||
ScalarTypeConverter<?, ?> typeConverter = null;
|
||||
|
||||
if (propertyType.equals(scalaOptionClass)){
|
||||
innerType = determineTargetType(field);
|
||||
typeConverter = scalaOptionTypeConverter;
|
||||
}
|
||||
|
||||
// check for Collection type (list, set or map)
|
||||
ManyType manyType = determineManyType.getManyType(propertyType);
|
||||
@@ -318,17 +291,17 @@ public class DeployCreateProperties {
|
||||
}
|
||||
|
||||
if (innerType.isEnum() || innerType.isPrimitive()){
|
||||
return new DeployBeanProperty(desc, propertyType, null, typeConverter);
|
||||
return new DeployBeanProperty(desc, propertyType, null, null);
|
||||
}
|
||||
|
||||
ScalarType<?> scalarType = typeManager.getScalarType(innerType);
|
||||
if (scalarType != null) {
|
||||
return new DeployBeanProperty(desc, propertyType, scalarType, typeConverter);
|
||||
return new DeployBeanProperty(desc, propertyType, scalarType, null);
|
||||
}
|
||||
|
||||
CtCompoundType<?> compoundType = typeManager.getCompoundType(innerType);
|
||||
if (compoundType != null) {
|
||||
return new DeployBeanPropertyCompound(desc, propertyType, compoundType, typeConverter);
|
||||
return new DeployBeanPropertyCompound(desc, propertyType, compoundType, null);
|
||||
}
|
||||
|
||||
if (!isTransientField(field)){
|
||||
@@ -340,13 +313,13 @@ public class DeployCreateProperties {
|
||||
typeManager.recursiveCreateScalarDataReader(innerType);
|
||||
compoundType = typeManager.getCompoundType(innerType);
|
||||
if (compoundType != null) {
|
||||
return new DeployBeanPropertyCompound(desc, propertyType, compoundType, typeConverter);
|
||||
return new DeployBeanPropertyCompound(desc, propertyType, compoundType, null);
|
||||
}
|
||||
|
||||
} else {
|
||||
// use reflection to support simple immutable value objects
|
||||
scalarType = typeManager.recursiveCreateScalarTypes(innerType);
|
||||
return new DeployBeanProperty(desc, propertyType, scalarType, typeConverter);
|
||||
return new DeployBeanProperty(desc, propertyType, scalarType, null);
|
||||
}
|
||||
}
|
||||
} catch (Exception e){
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.parse;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.avaje.ebeaninternal.api.ClassUtil;
|
||||
|
||||
/**
|
||||
* Used to detected if Scala support is required.
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class DetectScala {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DetectScala.class.getName());
|
||||
|
||||
private static Class<?> scalaOptionClass = initScalaOptionClass();
|
||||
|
||||
private static boolean hasScalaSupport = scalaOptionClass != null;
|
||||
|
||||
private static Class<?> initScalaOptionClass() {
|
||||
try {
|
||||
return ClassUtil.forName("scala.Option");
|
||||
} catch (ClassNotFoundException e) {
|
||||
// scala not in the classpath...
|
||||
logger.fine("Scala type 'scala.Option' not found. Scala Support disabled.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if scala is in the classpath.
|
||||
*/
|
||||
public static boolean hasScalaSupport() {
|
||||
return hasScalaSupport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the scala.Option class or null if scala is not in the classpath.
|
||||
*/
|
||||
public static Class<?> getScalaOptionClass() {
|
||||
return scalaOptionClass;
|
||||
}
|
||||
}
|
||||
@@ -729,8 +729,8 @@ public final class DefaultPersister implements Persister {
|
||||
this.updateNullProperties = false;
|
||||
}
|
||||
|
||||
private Object getValueUnderlying() {
|
||||
return many.getValueUnderlying(parentBean);
|
||||
private Object getValue() {
|
||||
return many.getValue(parentBean);
|
||||
}
|
||||
|
||||
private boolean isModifyListenMode() {
|
||||
@@ -794,7 +794,7 @@ public final class DefaultPersister implements Persister {
|
||||
|
||||
private void removeAssocManyPrivateOwned(SaveManyPropRequest saveMany) {
|
||||
|
||||
Object details = saveMany.getValueUnderlying();
|
||||
Object details = saveMany.getValue();
|
||||
|
||||
// check that the list is not null and if it is a BeanCollection
|
||||
// check that is has been populated (don't trigger lazy loading)
|
||||
@@ -822,7 +822,7 @@ public final class DefaultPersister implements Persister {
|
||||
|
||||
BeanPropertyAssocMany<?> prop = saveMany.getMany();
|
||||
|
||||
Object details = saveMany.getValueUnderlying();
|
||||
Object details = saveMany.getValue();
|
||||
|
||||
// check that the list is not null and if it is a BeanCollection
|
||||
// check that is has been populated (don't trigger lazy loading)
|
||||
@@ -989,7 +989,7 @@ public final class DefaultPersister implements Persister {
|
||||
private void saveAssocManyIntersection(SaveManyPropRequest saveManyPropRequest, boolean deleteMissingChildren) {
|
||||
|
||||
BeanPropertyAssocMany<?> prop = saveManyPropRequest.getMany();
|
||||
Object value = prop.getValueUnderlying(saveManyPropRequest.getParentBean());
|
||||
Object value = prop.getValue(saveManyPropRequest.getParentBean());
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
@@ -1126,7 +1126,7 @@ public final class DefaultPersister implements Persister {
|
||||
|
||||
if (ModifyListenMode.REMOVALS.equals(manys[i].getModifyListenMode())) {
|
||||
// PrivateOwned ...
|
||||
Object details = manys[i].getValueUnderlying(parentBean);
|
||||
Object details = manys[i].getValue(parentBean);
|
||||
if (details instanceof BeanCollection<?>) {
|
||||
Set<?> modifyRemovals = ((BeanCollection<?>) details).getModifyRemovals();
|
||||
if (modifyRemovals != null && !modifyRemovals.isEmpty()) {
|
||||
|
||||
@@ -1,34 +1,23 @@
|
||||
package com.avaje.ebeaninternal.server.persist;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.parse.DetectScala;
|
||||
|
||||
/**
|
||||
* Utility object with helper methods for DML.
|
||||
*/
|
||||
public class DmlUtil {
|
||||
|
||||
private static final boolean hasScalaSupport = DetectScala.hasScalaSupport();
|
||||
|
||||
/**
|
||||
* Return true if the value is null or a Numeric 0 (for primitive int's and long's) or Option empty.
|
||||
*/
|
||||
public static boolean isNullOrZero(Object value){
|
||||
if (value == null){
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value instanceof Number){
|
||||
return ((Number)value).longValue() == 0l;
|
||||
}
|
||||
|
||||
if (hasScalaSupport){
|
||||
if (value instanceof scala.Option<?>) {
|
||||
if (((scala.Option<?>) value).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.persist;
|
||||
|
||||
|
||||
/**
|
||||
* Utility object with helper methods for DML.
|
||||
*/
|
||||
public class DmlUtil {
|
||||
|
||||
/**
|
||||
* Return true if the value is null or a Numeric 0 (for primitive int's and long's) or Option empty.
|
||||
*/
|
||||
public static boolean isNullOrZero(Object value){
|
||||
if (value == null){
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value instanceof Number){
|
||||
return ((Number)value).longValue() == 0l;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import scala.Option;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
|
||||
/**
|
||||
* A type converter to support scala.Option.
|
||||
*
|
||||
* @author rbygrave
|
||||
*
|
||||
* @param <S> the underlying type
|
||||
*/
|
||||
public class ScalaOptionTypeConverter<S> implements ScalarTypeConverter<scala.Option<S>, S>{
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public Option<S> getNullValue() {
|
||||
return (scala.Option)scala.None$.MODULE$;
|
||||
}
|
||||
|
||||
public S unwrapValue(Option<S> beanType) {
|
||||
|
||||
if (beanType.isEmpty()){
|
||||
return null;
|
||||
} else {
|
||||
return beanType.get();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public Option<S> wrapValue(S scalarType) {
|
||||
if (scalarType == null){
|
||||
return (scala.Option)scala.None$.MODULE$;
|
||||
}
|
||||
if (scalarType instanceof scala.Some){
|
||||
return (Option<S>)scalarType;
|
||||
}
|
||||
return new scala.Some<S>(scalarType);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import scala.Double;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
|
||||
public class ScalarTypeScalaDouble extends ScalarTypeWrapper<Object, java.lang.Double> {
|
||||
|
||||
public ScalarTypeScalaDouble() {
|
||||
super(Object.class, new ScalarTypeDouble(), new Converter());
|
||||
}
|
||||
|
||||
static class Converter implements ScalarTypeConverter<Object, java.lang.Double> {
|
||||
|
||||
public Double getNullValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object wrapValue(java.lang.Double scalarType) {
|
||||
return scalarType;
|
||||
}
|
||||
|
||||
public java.lang.Double unwrapValue(Object beanType) {
|
||||
return ((scala.Double)beanType).toDouble();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user