Skip to content
Browse files

More stuff related to CQl3

  • Loading branch information...
1 parent 6a2a0a2 commit 1a653b69af13416407349f74152e0079550341e3 @easility easility committed Nov 24, 2013
View
18 src/main/java/com/alvazan/orm/layer9z/spi/db/cassandracql3/Cql3Util.java
@@ -42,7 +42,7 @@ public static IndexColumn convertToIndexCol(com.datastax.driver.core.Row row, St
return c;
}
- public static Where createRowQuery(Key from, Key to, DboColumnMeta colMeta, Select selectQuery, String rowKey) {
+ 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);
@@ -51,11 +51,11 @@ public static Where createRowQuery(Key from, Key to, DboColumnMeta colMeta, Sele
if (colMeta != null) {
if (from != null) {
valFrom = colMeta.getStorageType().convertFromNoSql(from.getKey());
- valFrom = checkForBoolean(valFrom);
+ valFrom = checkForBooleanAndNull(valFrom, indTable);
}
if (to != null) {
valTo = colMeta.getStorageType().convertFromNoSql(to.getKey());
- valTo = checkForBoolean(valTo);
+ valTo = checkForBooleanAndNull(valTo, indTable);
}
} else
return selectWhere;
@@ -101,10 +101,14 @@ public static Where createRowQueryFromValues(List<byte[]> values, DboColumnMeta
return selectWhere;
}
- public static Object checkForBoolean(Object val) {
- if (val == null)
- return null;
- else if (val instanceof Boolean) {
+ 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;
View
42 src/main/java/com/alvazan/orm/layer9z/spi/db/cassandracql3/CqlSession.java
@@ -230,7 +230,16 @@ else if (table.equalsIgnoreCase("DecimalIndice"))
log.info("Index: " + column.toString() + " already removed.");
} else {
Clause eqClause = QueryBuilder.eq("id", rowKey);
- Clause indClause = QueryBuilder.eq("colname", indValue);
+ Clause indClause = null;
+ if (indValue != null) {
+ indClause = QueryBuilder.eq("colname", indValue);
+ } else {
+ if (table.equalsIgnoreCase("IntegerIndice")) {
+ indClause = QueryBuilder.eq("colname", ByteBuffer.wrap(new byte[0]));
+ } else {
+ indClause = QueryBuilder.eq("colname", "");
+ }
+ }
Clause fkClause = QueryBuilder.eq("colvalue", ByteBuffer.wrap(fk));
Query query = QueryBuilder.delete().from(keys, table).where(eqClause).and(indClause).and(fkClause);
session.execute(query);
@@ -239,37 +248,42 @@ else if (table.equalsIgnoreCase("DecimalIndice"))
public boolean findIndexRow(String table, String rowKey, byte[] key, Object indValue) {
Select selectQuery = QueryBuilder.select().all().from(keys, table).allowFiltering();
- //Where whereClause = Cql3Util.createRowQuery(from, to, columnMeta, selectQuery, rowKeyString);
Where selectWhere = selectQuery.where();
Clause rkClause = QueryBuilder.eq("id", rowKey);
selectWhere.and(rkClause);
- Clause indClause = QueryBuilder.eq("colname", indValue);
+ Clause indClause = null;
+ if (indValue != null) {
+ indClause = QueryBuilder.eq("colname", indValue);
+ } else {
+ if (table.equalsIgnoreCase("IntegerIndice")) {
+ indClause = QueryBuilder.eq("colname", ByteBuffer.wrap(new byte[0]));
+ } else {
+ indClause = QueryBuilder.eq("colname", "");
+ }
+ }
selectWhere.and(indClause);
Clause keyClause = QueryBuilder.eq("colvalue", ByteBuffer.wrap(key));
selectWhere.and(keyClause);
Query query = selectWhere.limit(1);
- // System.out.println("QUERY FOR FINDINDEXROW IS: " + query);
ResultSet resultSet = session.execute(query);
- // System.out.println("resultSet.isExhausted()" + resultSet.isExhausted());
return !resultSet.isExhausted();
- }
+ }
private String lookupOrCreate(String colFamily1, MetaLookup ormSession) {
if (cluster.getMetadata().getKeyspace(keys).getTable(colFamily1.toLowerCase()) == null) {
try {
+ String colType = null;
if (colFamily1.equalsIgnoreCase("StringIndice")) {
- session.execute("CREATE TABLE " + keys + "." + colFamily1 + " (id text," + "colname text," + "colvalue blob,"
- + "PRIMARY KEY (id,colname, colvalue)" + ") WITH COMPACT STORAGE");
+ colType = "colname text,";
} else if (colFamily1.equalsIgnoreCase("IntegerIndice")) {
- session.execute("CREATE TABLE " + keys + "." + colFamily1 + " (id text," + "colname bigint," + "colvalue blob,"
- + "PRIMARY KEY (id,colname, colvalue)" + ") WITH COMPACT STORAGE");
+ colType = "colname bigint,";
} else if (colFamily1.equalsIgnoreCase("DecimalIndice")) {
- session.execute("CREATE TABLE " + keys + "." + colFamily1 + " (id text," + "colname float," + "colvalue blob,"
- + "PRIMARY KEY (id,colname, colvalue)" + ") WITH COMPACT STORAGE");
+ colType = "colname float,";
} else {
- session.execute("CREATE TABLE " + keys + "." + colFamily1
- + " (id text, colname text, colvalue blob, PRIMARY KEY (id,colname, colvalue)) WITH COMPACT STORAGE");
+ colType = "colname text,";
}
+ session.execute("CREATE TABLE " + keys + "." + colFamily1 + " (id text," + colType + "colvalue blob,"
+ + "PRIMARY KEY (id,colname, colvalue)" + ") WITH COMPACT STORAGE");
} catch (Exception e) {
System.out.println("Excepion in creating table" + colFamily1 + " creation:" + e.getMessage());
View
3 src/main/java/com/alvazan/orm/layer9z/spi/db/cassandracql3/CursorOfIndexes.java
@@ -105,14 +105,13 @@ private void loadCache(boolean reverse) {
String rowKeyString = StandardConverters.convertFromBytes(String.class, rowKey);
Select selectQuery = QueryBuilder.select().all().from(keySpace, indTable).allowFiltering();
- Where whereClause = Cql3Util.createRowQuery(from, to, columnMeta, selectQuery, rowKeyString);
+ Where whereClause = Cql3Util.createRowQuery(from, to, columnMeta, selectQuery, rowKeyString, indTable);
Query query = null;
if (batchSize != null)
query = whereClause.limit(batchSize);
else
query = whereClause.disableTracing();
- //System.out.println("QUERY IS: " + query);
resultSet = session.execute(query);
// Need to see where we use this batchListener
View
3 src/main/java/com/alvazan/orm/layer9z/spi/db/cassandracql3/StartQueryManyKeys.java
@@ -53,14 +53,13 @@ public StartQueryManyKeys(String keys, ScanInfo info, Session session2, List<byt
Object value = null;
value = columnMeta.getStorageType().convertFromNoSql(val);
- value = Cql3Util.checkForBoolean(value);
+ value = Cql3Util.checkForBooleanAndNull(value, indTable);
Clause valClause = QueryBuilder.eq("colname", value);
selectWhere.and(valClause);
Query query = selectWhere.disableTracing();
- System.out.println("QUERY of STARTQUERYMANYKEY IS: " + query);
Future future = session.executeAsync(query);
futures.add(future);
}

0 comments on commit 1a653b6

Please sign in to comment.
Something went wrong with that request. Please try again.