Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixing issue #126

  • Loading branch information...
commit 6a16018cf0a7761de27aebc33a3adfa2f27f9fff 1 parent daa413b
@easility easility authored
View
12 src/main/java/com/alvazan/orm/api/z8spi/meta/DboColumnEmbedSimpleMeta.java
@@ -16,8 +16,8 @@
private String valueType;
@SuppressWarnings("rawtypes")
- public void setup(DboTableMeta t, String colPrefix, Class collectionType, Class itemType, Class valueType) {
- super.setup(t, colPrefix, false);
+ public void setup(DboTableMeta t, String colPrefix, Class collectionType, Class itemType, Class valueType, boolean isIndexed) {
+ super.setup(t, colPrefix, isIndexed);
this.collectionType = collectionType.getName();
Class newType = translateType(itemType);
this.itemType = newType.getName();
@@ -34,13 +34,13 @@ public boolean isPartitionedByThisColumn() {
@Override
public String getIndexTableName() {
- return null;
+ return getStorageType().getIndexTableName();
}
@SuppressWarnings("rawtypes")
@Override
public Class getClassType() {
- return null;
+ return classForName(this.itemType);
}
@Override
@@ -101,6 +101,8 @@ private void parseOutKeyList(Row row, TypedRow entity) {
@Override
public String fetchColumnValueAsString(TypedRow row) {
- return null;
+ TypedColumn typedCol = row.getColumn(getColumnName());
+ Object value = typedCol.getValue();
+ return convertTypeToString(value);
}
}
View
44 src/main/java/com/alvazan/orm/impl/meta/data/EmbedInfo.java
@@ -0,0 +1,44 @@
+package com.alvazan.orm.impl.meta.data;
+
+import com.alvazan.orm.api.z8spi.conv.Converter;
+//This is just a DTO to wire few parameters for MetaEmbeddedSimple.java
+public class EmbedInfo {
+
+ private Converter converter;
+ private Converter valConverter;
+ private Class<?> type;
+ private Class<?> valueType;
+
+ public Converter getConverter() {
+ return this.converter;
+ }
+
+ public void setConverter(Converter converter) {
+ this.converter = converter;
+ }
+
+ public Converter getValConverter() {
+ return this.valConverter;
+ }
+
+ public void setValConverter(Converter valConverter) {
+ this.valConverter = valConverter;
+ }
+
+ public Class<?> getType() {
+ return this.type;
+ }
+
+ public void setType(Class<?> type) {
+ this.type = type;
+ }
+
+ public Class<?> getValueType() {
+ return this.valueType;
+ }
+
+ public void setValueType(Class<?> valueType) {
+ this.valueType = valueType;
+ }
+
+}
View
39 src/main/java/com/alvazan/orm/impl/meta/data/MetaEmbeddedSimple.java
@@ -13,6 +13,7 @@
import com.alvazan.orm.api.z8spi.action.Column;
import com.alvazan.orm.api.z8spi.conv.Converter;
import com.alvazan.orm.api.z8spi.conv.StandardConverters;
+import com.alvazan.orm.api.z8spi.conv.StorageTypeEnum;
import com.alvazan.orm.api.z8spi.meta.DboColumnEmbedSimpleMeta;
import com.alvazan.orm.api.z8spi.meta.DboColumnMeta;
import com.alvazan.orm.api.z8spi.meta.DboTableMeta;
@@ -37,11 +38,11 @@
// super.setup(field2, colName);
// this.converter = converter;
// }
- public void setup(DboTableMeta t, Field field, String colName, Converter converter, Converter valConverter, Class<?> type, Class<?> valueType) {
+ public void setup(DboTableMeta t, Field field, String colName, EmbedInfo embedInfo, boolean isIndexed) {
super.setup(field, colName);
- metaDbo.setup(t, colName, field.getType(), type, valueType);
- this.converter = converter;
- this.valueConverter = valConverter;
+ metaDbo.setup(t, colName, field.getType(), embedInfo.getType(), embedInfo.getValueType(), isIndexed);
+ this.converter = embedInfo.getConverter();
+ this.valueConverter = embedInfo.getValConverter();
}
@Override
@@ -73,7 +74,7 @@ private Object translateFromColumnSet(Row row, OWNER entity,
return retVal;
}
- @SuppressWarnings({ "rawtypes" })
+ @SuppressWarnings("unchecked")
private Map translateFromColumnMap(Row row,
OWNER entity, NoSqlSession session) {
byte[] bytes = StandardConverters.convertToBytes(columnName);
@@ -111,16 +112,16 @@ private Map translateFromColumnMap(Row row,
@Override
public void translateToColumn(InfoForIndex<OWNER> info) {
- OWNER entity = info.getEntity();
- RowToPersist row = info.getRow();
if(field.getType().equals(Map.class))
- translateToColumnMap(entity, row);
+ translateToColumnMap(info);
else
- translateToColumnList(entity, row);
+ translateToColumnList(info);
}
@SuppressWarnings("unchecked")
- private void translateToColumnMap(OWNER entity, RowToPersist row) {
+ private void translateToColumnMap(InfoForIndex<OWNER> info) {
+ OWNER entity = info.getEntity();
+ RowToPersist row = info.getRow();
Map values = (Map) ReflectionUtil.fetchFieldValue(entity, field);
if (values == null)
values = new HashMap();
@@ -158,7 +159,8 @@ private void translateToColumnMapImpl(Map toBeAdded, RowToPersist row, Collectio
}
@SuppressWarnings("unchecked")
- private void translateToColumnList(OWNER entity, RowToPersist row) {
+ private void translateToColumnList(InfoForIndex<OWNER> info) {
+ OWNER entity = info.getEntity();
Collection<T> values = (Collection<T>) ReflectionUtil.fetchFieldValue(entity, field);
if (values == null)
values = new ArrayList<T>();
@@ -170,16 +172,19 @@ private void translateToColumnList(OWNER entity, RowToPersist row) {
toBeAdded = coll.getToBeAdded();
}
- translateToColumnImpl(toBeAdded, row, toBeRemoved);
+ translateToColumnImpl(toBeAdded, info, toBeRemoved);
}
- private void translateToColumnImpl(Collection<T> toBeAdded, RowToPersist row, Collection<T> toBeRemoved) {
+ private void translateToColumnImpl(Collection<T> toBeAdded, InfoForIndex<OWNER> info, Collection<T> toBeRemoved) {
+ OWNER entity = info.getEntity();
+ RowToPersist row = info.getRow();
//removes first
for(T p : toBeRemoved) {
byte[] name = formTheName(p);
row.addEntityToRemove(name);
}
-
+ Object value = ReflectionUtil.fetchFieldValue(entity, field);
+ StorageTypeEnum storageType = metaDbo.getStorageType();
//now process all the existing columns (we can add same entity as many times as we like and it does not
//get duplicated)
for(T val : toBeAdded) {
@@ -188,6 +193,10 @@ private void translateToColumnImpl(Collection<T> toBeAdded, RowToPersist row, Co
c.setName(name);
row.getColumns().add(c);
+
+ byte[] byteVal = converter.convertToNoSql(val);
+ addIndexInfo(info, value, byteVal, storageType);
+ removeIndexInfo(info, value, byteVal, storageType);
}
}
@@ -218,7 +227,7 @@ public DboColumnMeta getMetaDbo() {
@Override
protected Object unwrapIfNeeded(Object value) {
- throw new UnsupportedOperationException();
+ return value;
}
@Override
View
14 src/main/java/com/alvazan/orm/impl/meta/scan/ScannerForField.java
@@ -39,6 +39,7 @@
import com.alvazan.orm.api.z8spi.conv.StandardConverters;
import com.alvazan.orm.api.z8spi.meta.DboTableMeta;
import com.alvazan.orm.api.z8spi.meta.ReflectionUtil;
+import com.alvazan.orm.impl.meta.data.EmbedInfo;
import com.alvazan.orm.impl.meta.data.IdInfo;
import com.alvazan.orm.impl.meta.data.MetaAbstractClass;
import com.alvazan.orm.impl.meta.data.MetaClassInheritance;
@@ -349,7 +350,11 @@ public MetaField processEmbedded(DboTableMeta t, Field field) {
type = (Class<?>) genType.getActualTypeArguments()[0];
valType = (Class<?>) genType.getActualTypeArguments()[1];
}
-
+
+ boolean isIndexed = false;
+ if (field.isAnnotationPresent(NoSqlIndexed.class))
+ isIndexed = true;
+
String colNameOrig = embedded.columnNamePrefix();
String colName = field.getName();
if(!"".equals(colNameOrig))
@@ -368,7 +373,12 @@ public MetaField processEmbedded(DboTableMeta t, Field field) {
valConverter = lookupConverter(field, valType);
MetaEmbeddedSimple meta = metaEmbeddedSimpleProvider.get();
- meta.setup(t, field, colName, converter, valConverter, type, valType);
+ EmbedInfo embedInfo = new EmbedInfo();
+ embedInfo.setConverter(converter);
+ embedInfo.setType(type);
+ embedInfo.setValConverter(valConverter);
+ embedInfo.setValueType(valType);
+ meta.setup(t, field, colName, embedInfo, isIndexed);
metaField = meta;
}
Please sign in to comment.
Something went wrong with that request. Please try again.