From 0e5157969dafa03d4c94f79ce78f21c8075fc6da Mon Sep 17 00:00:00 2001 From: rbygrave <=> Date: Tue, 2 Oct 2012 13:26:27 +1300 Subject: [PATCH] Remove underlying Scala support --- pom.xml | 9 +- .../server/core/DefaultBeanLoader.java | 2 +- .../server/deploy/BeanListHelp.java | 334 +++++++------- .../server/deploy/BeanMapHelp.java | 410 +++++++++--------- .../server/deploy/BeanPropertyAssocMany.java | 25 +- .../server/deploy/BeanSetHelp.java | 348 +++++++-------- .../deploy/CollectionTypeConverter.java | 24 - .../server/deploy/DetermineManyType.java | 91 ++-- .../ebeaninternal/server/deploy/ManyType.java | 15 +- .../server/deploy/ScalaBufferConverter.java | 29 -- .../server/deploy/ScalaMapConverter.java | 29 -- .../server/deploy/ScalaSetConverter.java | 30 -- .../deploy/parse/DeployCreateProperties.java | 43 +- .../server/deploy/parse/DetectScala.java | 43 -- .../server/persist/DefaultPersister.java | 12 +- .../ebeaninternal/server/persist/DmlUtil.java | 57 +-- .../server/type/ScalaOptionTypeConverter.java | 42 -- .../server/type/ScalarTypeScalaDouble.java | 28 -- 18 files changed, 615 insertions(+), 956 deletions(-) delete mode 100644 src/main/java/com/avaje/ebeaninternal/server/deploy/CollectionTypeConverter.java delete mode 100644 src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaBufferConverter.java delete mode 100644 src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaMapConverter.java delete mode 100644 src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaSetConverter.java delete mode 100644 src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DetectScala.java delete mode 100644 src/main/java/com/avaje/ebeaninternal/server/type/ScalaOptionTypeConverter.java delete mode 100644 src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeScalaDouble.java diff --git a/pom.xml b/pom.xml index bb01ea3ed..beadd6f67 100644 --- a/pom.xml +++ b/pom.xml @@ -77,13 +77,6 @@ provided - - org.scala-lang - scala-library - 2.10.0-M6 - provided - - com.h2database h2 @@ -128,7 +121,7 @@ org.avaje.ebeanorm avaje-ebeanorm-mavenenhancer - 3.1.1-SNAPSHOT + 3.1.1 main diff --git a/src/main/java/com/avaje/ebeaninternal/server/core/DefaultBeanLoader.java b/src/main/java/com/avaje/ebeaninternal/server/core/DefaultBeanLoader.java index 5b94b3a8f..ab322fe3d 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/core/DefaultBeanLoader.java +++ b/src/main/java/com/avaje/ebeaninternal/server/core/DefaultBeanLoader.java @@ -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(); diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanListHelp.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanListHelp.java index 9fdecc077..1b424dc11 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanListHelp.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanListHelp.java @@ -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 implements BeanCollectionHelp { - - private final BeanPropertyAssocMany many; - private final BeanDescriptor targetDescriptor; - private BeanCollectionLoader loader; - - public BeanListHelp(BeanPropertyAssocMany 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()); - } - 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() : new BeanList(); - } - - public BeanCollection createReference(Object parentBean, String propertyName) { - - return new BeanList(loader, parentBean, propertyName); - } - - public ArrayList validate(Object manyValue) { - - ArrayList 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(); - } - 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 implements BeanCollectionHelp { + + private final BeanPropertyAssocMany many; + private final BeanDescriptor targetDescriptor; + private BeanCollectionLoader loader; + + public BeanListHelp(BeanPropertyAssocMany 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()); + } + 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() : new BeanList(); + } + + public BeanCollection createReference(Object parentBean, String propertyName) { + + return new BeanList(loader, parentBean, propertyName); + } + + public ArrayList validate(Object manyValue) { + + ArrayList 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(); + } + 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(); + } + +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanMapHelp.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanMapHelp.java index 41f97fec6..978233959 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanMapHelp.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanMapHelp.java @@ -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 implements BeanCollectionHelp { - - private final BeanPropertyAssocMany many; - private final BeanDescriptor 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 targetDescriptor, String mapKey) { - this(null, targetDescriptor, mapKey); - } - - public BeanMapHelp(BeanPropertyAssocMany many){ - this(many, many.getTargetDescriptor(), many.getMapKey()); - } - - /** - * When help is attached to a specific many property. - */ - private BeanMapHelp(BeanPropertyAssocMany many, BeanDescriptor 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 bm = (BeanMap)bc; - Map actualMap = bm.getActualMap(); - if (actualMap == null){ - actualMap = new LinkedHashMap(); - bm.setActualMap(actualMap); - } - return new Adder(beanProp, actualMap); - - } else if (bc instanceof Map) { - return new Adder(beanProp, (Map)bc); - - } else { - throw new RuntimeException("Unhandled type "+bc); - } - } - - static class Adder implements BeanCollectionAdd { - - private final BeanProperty beanProperty; - - private final Map map; - - Adder(BeanProperty beanProperty, Map 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 map = (Map) collection; - map.put(keyValue, bean); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public BeanCollection createReference(Object parentBean, String propertyName) { - - return new BeanMap(loader, parentBean, propertyName); - } - - public ArrayList validate(Object manyValue) { - - ArrayList 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(); - } - 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 implements BeanCollectionHelp { + + private final BeanPropertyAssocMany many; + private final BeanDescriptor 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 targetDescriptor, String mapKey) { + this(null, targetDescriptor, mapKey); + } + + public BeanMapHelp(BeanPropertyAssocMany many){ + this(many, many.getTargetDescriptor(), many.getMapKey()); + } + + /** + * When help is attached to a specific many property. + */ + private BeanMapHelp(BeanPropertyAssocMany many, BeanDescriptor 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 bm = (BeanMap)bc; + Map actualMap = bm.getActualMap(); + if (actualMap == null){ + actualMap = new LinkedHashMap(); + bm.setActualMap(actualMap); + } + return new Adder(beanProp, actualMap); + + } else if (bc instanceof Map) { + return new Adder(beanProp, (Map)bc); + + } else { + throw new RuntimeException("Unhandled type "+bc); + } + } + + static class Adder implements BeanCollectionAdd { + + private final BeanProperty beanProperty; + + private final Map map; + + Adder(BeanProperty beanProperty, Map 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 map = (Map) collection; + map.put(keyValue, bean); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public BeanCollection createReference(Object parentBean, String propertyName) { + + return new BeanMap(loader, parentBean, propertyName); + } + + public ArrayList validate(Object manyValue) { + + ArrayList 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(); + } + 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(); + } + +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssocMany.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssocMany.java index 960676d44..833d59d88 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssocMany.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanPropertyAssocMany.java @@ -87,9 +87,7 @@ public class BeanPropertyAssocMany extends BeanPropertyAssoc { String deleteByParentIdSql; String deleteByParentIdInSql; - - final CollectionTypeConverter typeConverter; - + /** * Create this property. */ @@ -99,7 +97,7 @@ public class BeanPropertyAssocMany extends BeanPropertyAssoc { 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 extends BeanPropertyAssoc { } } - /** - * 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 extends BeanPropertyAssoc { @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); } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanSetHelp.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanSetHelp.java index 18a4680c8..244c339fe 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanSetHelp.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanSetHelp.java @@ -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 implements BeanCollectionHelp { - - private final BeanPropertyAssocMany many; - private final BeanDescriptor targetDescriptor; - private BeanCollectionLoader loader; - - /** - * When attached to a specific many property. - */ - public BeanSetHelp(BeanPropertyAssocMany 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()); - } - 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() : new BeanSet(); - } - - public BeanCollection createReference(Object parentBean, String propertyName) { - - return new BeanSet(loader, parentBean, propertyName); - } - - public ArrayList validate(Object manyValue) { - - ArrayList 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(); - } - 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 implements BeanCollectionHelp { + + private final BeanPropertyAssocMany many; + private final BeanDescriptor targetDescriptor; + private BeanCollectionLoader loader; + + /** + * When attached to a specific many property. + */ + public BeanSetHelp(BeanPropertyAssocMany 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()); + } + 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() : new BeanSet(); + } + + public BeanCollection createReference(Object parentBean, String propertyName) { + + return new BeanSet(loader, parentBean, propertyName); + } + + public ArrayList validate(Object manyValue) { + + ArrayList 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(); + } + 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(); + } +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/CollectionTypeConverter.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/CollectionTypeConverter.java deleted file mode 100644 index 29ecff903..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/CollectionTypeConverter.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.avaje.ebeaninternal.server.deploy; - -/** - * Used to convert between collection types. - *

- * This typically means wrap and unwrap mutable scala collection types of Buffer, Set and Map. - *

- * - * @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); - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/DetermineManyType.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/DetermineManyType.java index 7042abf6b..6fe93ae59 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/DetermineManyType.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/DetermineManyType.java @@ -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. - *

- * Scala types require CollectionTypeConverter's to wrap and unwrap from the - * underlying java types used. - *

- */ -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; + } +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/ManyType.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/ManyType.java index 8fff64f24..59e375c8a 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/ManyType.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/ManyType.java @@ -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; - } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaBufferConverter.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaBufferConverter.java deleted file mode 100644 index 50bb84543..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaBufferConverter.java +++ /dev/null @@ -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; - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaMapConverter.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaMapConverter.java deleted file mode 100644 index 525d4b8f8..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaMapConverter.java +++ /dev/null @@ -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; - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaSetConverter.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaSetConverter.java deleted file mode 100644 index 238c0de3c..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/ScalaSetConverter.java +++ /dev/null @@ -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; - } - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DeployCreateProperties.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DeployCreateProperties.java index 0722cdc98..dd6260dd7 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DeployCreateProperties.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DeployCreateProperties.java @@ -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){ diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DetectScala.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DetectScala.java deleted file mode 100644 index 9511da836..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/DetectScala.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java b/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java index a8c29748c..df13ae07c 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java @@ -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()) { diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/DmlUtil.java b/src/main/java/com/avaje/ebeaninternal/server/persist/DmlUtil.java index 9d17f9fc1..b528ee821 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/DmlUtil.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/DmlUtil.java @@ -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; + } +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalaOptionTypeConverter.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalaOptionTypeConverter.java deleted file mode 100644 index 5491bfb5e..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalaOptionTypeConverter.java +++ /dev/null @@ -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 the underlying type - */ -public class ScalaOptionTypeConverter implements ScalarTypeConverter, S>{ - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public Option getNullValue() { - return (scala.Option)scala.None$.MODULE$; - } - - public S unwrapValue(Option beanType) { - - if (beanType.isEmpty()){ - return null; - } else { - return beanType.get(); - } - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public Option wrapValue(S scalarType) { - if (scalarType == null){ - return (scala.Option)scala.None$.MODULE$; - } - if (scalarType instanceof scala.Some){ - return (Option)scalarType; - } - return new scala.Some(scalarType); - } - - -} diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeScalaDouble.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeScalaDouble.java deleted file mode 100644 index 4c5f7e8a3..000000000 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeScalaDouble.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.avaje.ebeaninternal.server.type; - -import scala.Double; - -import com.avaje.ebean.config.ScalarTypeConverter; - -public class ScalarTypeScalaDouble extends ScalarTypeWrapper { - - public ScalarTypeScalaDouble() { - super(Object.class, new ScalarTypeDouble(), new Converter()); - } - - static class Converter implements ScalarTypeConverter { - - 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(); - } - - } -}