Permalink
Browse files

More fixes for mongodb

  • Loading branch information...
1 parent fe1ca14 commit abbc75d659ae9fdb4f7706a4ec031972ebb3a082 @easility easility committed Apr 8, 2013
View
2 src/main/java/com/alvazan/orm/layer9z/spi/db/mongodb/CursorOfIndexes.java
@@ -19,13 +19,11 @@
public class CursorOfIndexes extends AbstractCursor<IndexColumn> {
- //private Info info;
private byte[] rowKey;
private Integer batchSize;
private BatchListener batchListener;
private DB db;
private ListIterator<IndexColumn> cachedRows;
- //private Provider<Row> rowProvider;
//private Cache cache;
private String indTable;
private boolean needToGetBatch;
View
16 src/main/java/com/alvazan/orm/layer9z/spi/db/mongodb/MongoDbSession.java
@@ -270,18 +270,21 @@ private void remove(Remove action, MetaLookup ormSession) {
}
private void removeColumns(Remove action, DBCollection table) {
- for (byte[] name : action.getColumns()) {
- DBObject row = table.findOne(name);
- table.remove(row);
+ DBObject row = table.findOne(action.getRowKey());
+ if (row != null) {
+ for (byte[] name : action.getColumns()) {
+ row.removeField(StandardConverters.convertFromBytes(String.class, name)); }
}
}
private void removeColumn(RemoveColumn action, MetaLookup ormSession) {
String colFamily = action.getColFamily().getColumnFamily();
DBCollection table = lookupColFamily(colFamily, ormSession);
- DBObject row = table.findOne(action.getColumn());
- table.remove(row);
+ DBObject row = table.findOne(action.getRowKey());
+ if (row != null)
+ row.removeField(StandardConverters.convertFromBytes(String.class, action.getColumn()));
+ //table.remove(row);
}
private void persist(Persist action, MetaLookup ormSession) {
@@ -293,7 +296,8 @@ private void persist(Persist action, MetaLookup ormSession) {
byte[] value = new byte[0];
if(col.getValue() != null)
value = col.getValue();
- doc.append(StandardConverters.convertFromBytes(String.class, col.getName()), value);
+ //doc.append(StandardConverters.convertFromBytes(String.class, col.getName()), value);
+ doc.append(StandardConverters.convertToString(col.getName()), value);
}
table.findAndModify(row, doc);
}
View
18 src/main/java/com/alvazan/orm/layer9z/spi/db/mongodb/MongoDbUtil.java
@@ -1,5 +1,6 @@
package com.alvazan.orm.layer9z.spi.db.mongodb;
+import java.math.BigDecimal;
import java.util.Set;
import com.alvazan.orm.api.z8spi.Key;
@@ -16,7 +17,7 @@ static void processColumns(DBObject mdbRow, Row r) {
Set<String> columns = mdbRow.keySet();
for (String col : columns) {
if(!col.equalsIgnoreCase("_id")) {
- byte[] name = StandardConverters.convertToBytes(col);
+ byte[] name = StandardConverters.convertFromString(byte[].class, col);
byte[] val = StandardConverters.convertToBytes(mdbRow.get(col));
Column c = new Column();
c.setName(name);
@@ -49,11 +50,14 @@ public static BasicDBObject createRowQuery(Key from, Key to, DboColumnMeta colMe
if (colMeta != null) {
if (from != null) {
valFrom = colMeta.getStorageType().convertFromNoSql(from.getKey());
+ valFrom = checkForBigDecimal(valFrom);
}
if (to != null) {
valTo = colMeta.getStorageType().convertFromNoSql(to.getKey());
+ valTo = checkForBigDecimal(valTo);
}
- }
+ } else
+ return query;
if (from != null) {
if (from.isInclusive())
@@ -72,4 +76,14 @@ public static BasicDBObject createRowQuery(Key from, Key to, DboColumnMeta colMe
range = range.reverse();*/
return query;
}
+
+ public static Object checkForBigDecimal(Object val) {
+ // This is a hack as MongoDb doesn't support BigDecimal. See https://jira.mongodb.org/browse/SCALA-23
+ if (val instanceof BigDecimal) {
+ BigDecimal bigDec = (BigDecimal) val;
+ return bigDec.doubleValue();
+ }
+ return val;
+ }
+
}

0 comments on commit abbc75d

Please sign in to comment.