Permalink
Browse files

Merge branch 'master' of github.com:deanhiller/playorm

  • Loading branch information...
2 parents 8723db0 + f58864b commit a68dd3940d8db9907ddfbc3cfab92facac8c3716 Dean Hiller committed Dec 11, 2013
View
@@ -26,6 +26,7 @@ dependencies {
provided (group: 'com.netflix.astyanax', name: 'astyanax', version: '1.56.42') {
exclude group: 'org.slf4j'
exclude group: 'log4j'
+ exclude group: 'org.jboss.netty'
}
compile (group: 'com.datastax.cassandra', name: 'cassandra-driver-core', version: '1.0.2') {
exclude group: 'org.slf4j'
@@ -49,6 +50,7 @@ dependencies {
exclude group: 'org.apache.maven.scm'
exclude group: 'org.slf4j'
exclude group: 'log4j'
+ exclude group: 'org.jboss.netty'
}
provided (group: 'org.apache.hadoop', name: 'hadoop-core', version: '1.0.4')
compile 'org.antlr:antlr-runtime:3.2'
@@ -4,5 +4,5 @@
public static final String CASSANDRA_BUILDER = "nosql.cassandra.builder";
public static final String CASSANDRA_CF_CREATE_CALLBACK = "nosql.cassandra.createcfcallback";
-
+
}
@@ -1,5 +1,6 @@
package com.alvazan.orm.impl.meta.data;
+import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -24,7 +25,7 @@
import com.alvazan.orm.api.z8spi.meta.DboTableMeta;
import com.alvazan.orm.impl.meta.data.collections.CacheLoadCallback;
-public class NoSqlProxyImpl<T> implements MethodHandler {
+public class NoSqlProxyImpl<T> implements MethodHandler, Serializable {
private static final Logger log = LoggerFactory.getLogger(NoSqlProxyImpl.class);
private NoSqlSession session;
@@ -0,0 +1,121 @@
+package com.alvazan.orm.layer9z.spi.db.cassandracql3;
+
+
+import java.nio.ByteBuffer;
+
+import java.util.List;
+
+import com.alvazan.orm.api.z8spi.Key;
+
+import com.alvazan.orm.api.z8spi.action.IndexColumn;
+import com.alvazan.orm.api.z8spi.conv.StandardConverters;
+import com.alvazan.orm.api.z8spi.meta.DboColumnMeta;
+import com.datastax.driver.core.querybuilder.Clause;
+import com.datastax.driver.core.querybuilder.QueryBuilder;
+import com.datastax.driver.core.querybuilder.Select;
+import com.datastax.driver.core.querybuilder.Select.Where;
+
+
+public class Cql3Util {
+ public static IndexColumn convertToIndexCol(com.datastax.driver.core.Row row, String tableName) {
+ Object indValue = null;
+ if (tableName.equalsIgnoreCase("StringIndice")) {
+ indValue = row.getString("colname");
+ } else if (tableName.equalsIgnoreCase("IntegerIndice")) {
+ indValue = row.getLong("colname");
+ } else if (tableName.equalsIgnoreCase("DecimalIndice")) {
+ indValue = row.getFloat("colname");
+ }
+ ByteBuffer data = row.getBytes("colvalue");
+ byte[] val = new byte[data.remaining()];
+ data.get(val);
+ IndexColumn c = new IndexColumn();
+ // c.setColumnName(columnName); Will we ever need this now?
+ if (val != null) {
+ c.setPrimaryKey(val);
+ }
+ if (indValue != null) {
+ c.setIndexedValue(StandardConverters.convertToBytes(indValue));
+ }
+
+ c.setValue(null);
+ return c;
+ }
+
+ public static Where createRowQuery(Key from, Key to, DboColumnMeta colMeta, Select selectQuery, String rowKey, String indTable) {
+ Where selectWhere = selectQuery.where();
+ Clause rkClause = QueryBuilder.eq("id", rowKey);
+ selectWhere.and(rkClause);
+
+ Object valFrom = null, valTo = null;
+ if (colMeta != null) {
+ if (from != null) {
+ valFrom = colMeta.getStorageType().convertFromNoSql(from.getKey());
+ valFrom = checkForBooleanAndNull(valFrom, indTable);
+ }
+ if (to != null) {
+ valTo = colMeta.getStorageType().convertFromNoSql(to.getKey());
+ valTo = checkForBooleanAndNull(valTo, indTable);
+ }
+ } else
+ return selectWhere;
+
+ if (from != null) {
+ if (from.isInclusive()) {
+ Clause gteClause = QueryBuilder.gte("colname", valFrom);
+ selectWhere.and(gteClause);
+ } else {
+ Clause gtClause = QueryBuilder.gt("colname", valFrom);
+ selectWhere.and(gtClause);
+ }
+
+ }
+ if (to != null) {
+ if (to.isInclusive()) {
+ Clause lteClause = QueryBuilder.lte("colname", valTo);
+ selectWhere.and(lteClause);
+ }
+ else {
+ Clause ltClause = QueryBuilder.lt("colname", valTo);
+ selectWhere.and(ltClause);
+ }
+ }
+ return selectWhere;
+ }
+
+ public static Where createRowQueryFromValues(List<byte[]> values, DboColumnMeta colMeta, Select selectQuery, String rowKey) {
+ Where selectWhere = selectQuery.where();
+
+ Clause rkClause = QueryBuilder.eq("id", rowKey);
+ selectWhere.and(rkClause);
+
+ Object[] valStrings = new Object[values.size()];
+ int count = 0;
+ for (byte[] value : values) {
+ valStrings[count] = StandardConverters.convertFromBytes(String.class, value);
+ count++;
+ }
+
+ Clause inClause = QueryBuilder.in("colname", valStrings);
+ selectWhere.and(inClause);
+ return selectWhere;
+ }
+
+ public static Object checkForBooleanAndNull(Object val, String indTable) {
+ if (val == null) {
+ if (indTable.equalsIgnoreCase("IntegerIndice")) {
+ return ByteBuffer.wrap(new byte[0]);
+ } else {
+ return "";
+ }
+ } else if (val instanceof Boolean) {
+ Boolean b = (Boolean) val;
+ if (b)
+ return 1;
+ else
+ return 0;
+ }
+ return val;
+ }
+
+}
Oops, something went wrong.

0 comments on commit a68dd39

Please sign in to comment.