Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More changes for cql3 using rowkey as blob instead of text

  • Loading branch information...
commit 9313bca366c7619aa929ff3ab93d6c9b9dfa3b44 1 parent ac47627
@easility easility authored
View
36 src/main/java/com/alvazan/orm/layer9z/spi/db/cassandracql3/CqlSession.java
@@ -30,7 +30,6 @@
import com.alvazan.orm.api.z8spi.action.RemoveColumn;
import com.alvazan.orm.api.z8spi.action.RemoveIndex;
import com.alvazan.orm.api.z8spi.conv.StandardConverters;
-import com.alvazan.orm.api.z8spi.conv.StorageTypeEnum;
import com.alvazan.orm.api.z8spi.iter.AbstractCursor;
import com.alvazan.orm.api.z8spi.iter.DirectCursor;
import com.alvazan.orm.api.z8spi.meta.DboColumnMeta;
@@ -53,7 +52,7 @@
private Session session = null;
private Cluster cluster = null;
private KeyspaceMetadata keyspaces = null;
- private String keys = "cql70";
+ private String keys = "cql72";
@Inject
private Provider<Row> rowProvider;
@@ -94,7 +93,7 @@ public void sendChanges(List<Action> actions, MetaLookup ormSession) {
}
private void persist(Persist action, MetaLookup ormSession) {
- StorageTypeEnum type = action.getColFamily().getNameStorageType();
+ //StorageTypeEnum type = action.getColFamily().getNameStorageType();
String colFamily = action.getColFamily().getColumnFamily();
String table = lookupOrCreate(colFamily, ormSession);
List<Column> s = action.getColumns();
@@ -107,13 +106,20 @@ private void persist(Persist action, MetaLookup ormSession) {
PreparedStatement statement = session.prepare("INSERT INTO " + keys + "." + table + "(id, colname, colvalue) VALUES (?, ?, ?)");
BoundStatement boundStatement = new BoundStatement(statement);
if (colValue != null) {
- session.execute(boundStatement.bind(StandardConverters.convertFromBytes(String.class, rowkey),
+ session.execute(boundStatement.bind(ByteBuffer.wrap(rowkey),
StandardConverters.convertFromBytes(String.class, c.getName()),
ByteBuffer.wrap(c.getValue())));
- } else {
- session.execute(boundStatement.bind(StandardConverters.convertFromBytes(String.class, rowkey),
+
+/* session.execute(boundStatement.bind(StandardConverters.convertToString(rowkey),
+ StandardConverters.convertToString(c.getName()),
+ ByteBuffer.wrap(c.getValue())));
+*/ } else {
+ session.execute(boundStatement.bind(ByteBuffer.wrap(rowkey),
StandardConverters.convertFromBytes(String.class, c.getName()), ByteBuffer.wrap(nullArray)));
- }
+
+/* session.execute(boundStatement.bind(StandardConverters.convertToString(rowkey),
+ StandardConverters.convertToString(c.getName()), ByteBuffer.wrap(nullArray)));
+*/ }
} catch (Exception e) {
System.out.println(c.getValue() + "Exception:" + e.getMessage());
@@ -168,8 +174,8 @@ private void remove(Remove action, MetaLookup ormSession) {
throw new IllegalArgumentException("action param is missing ActionEnum so we know to remove entire row or just columns in the row");
switch (action.getAction()) {
case REMOVE_ENTIRE_ROW:
- String rowKey = StandardConverters.convertFromBytes(String.class, action.getRowKey());
- Clause eqClause = QueryBuilder.eq("id", rowKey);
+ //String rowKey = StandardConverters.convertFromBytes(String.class, action.getRowKey());
+ Clause eqClause = QueryBuilder.eq("id", ByteBuffer.wrap(action.getRowKey()));
Query query = QueryBuilder.delete().from(keys, table).where(eqClause);
session.execute(query);
break;
@@ -186,7 +192,7 @@ private void removeColumns(Remove action, String table) {
if (rowKey != null) {
for (byte[] name : action.getColumns()) {
String colName = StandardConverters.convertFromBytes(String.class, name);
- removeColumnImpl(rowKey, table, colName);
+ removeColumnImpl(action.getRowKey(), table, colName);
}
}
}
@@ -197,12 +203,12 @@ private void removeColumn(RemoveColumn action, MetaLookup ormSession) {
String rowKey = StandardConverters.convertFromBytes(String.class, action.getRowKey());
if (rowKey != null) {
String colName = StandardConverters.convertFromBytes(String.class, action.getColumn());
- removeColumnImpl(rowKey, table, colName);
+ removeColumnImpl(action.getRowKey(), table, colName);
}
}
- private void removeColumnImpl(String rowKey, String table, String colName) {
- Clause eqClause = QueryBuilder.eq("id", rowKey);
+ private void removeColumnImpl(byte[] rowKey, String table, String colName) {
+ Clause eqClause = QueryBuilder.eq("id",ByteBuffer.wrap(rowKey));
Clause eqColClause = QueryBuilder.eq("colname", colName);
Query query = QueryBuilder.delete().from(keys, table).where(eqClause).and(eqColClause);
session.execute(query);
@@ -273,6 +279,7 @@ private String lookupOrCreate(String colFamily1, MetaLookup ormSession) {
if (cluster.getMetadata().getKeyspace(keys).getTable(colFamily1.toLowerCase()) == null) {
try {
String colType = null;
+ String idType = " (id text,";
if (colFamily1.equalsIgnoreCase("StringIndice")) {
colType = "colname text,";
} else if (colFamily1.equalsIgnoreCase("IntegerIndice")) {
@@ -280,9 +287,10 @@ private String lookupOrCreate(String colFamily1, MetaLookup ormSession) {
} else if (colFamily1.equalsIgnoreCase("DecimalIndice")) {
colType = "colname float,";
} else {
+ idType = " (id blob,";
colType = "colname text,";
}
- session.execute("CREATE TABLE " + keys + "." + colFamily1 + " (id text," + colType + "colvalue blob,"
+ session.execute("CREATE TABLE " + keys + "." + colFamily1 + idType + colType + "colvalue blob,"
+ "PRIMARY KEY (id,colname, colvalue)" + ") WITH COMPACT STORAGE");
} catch (Exception e) {
View
33 src/main/java/com/alvazan/orm/layer9z/spi/db/cassandracql3/CursorKeysToRowsCql3.java
@@ -128,10 +128,12 @@ private void loadCache() {
ResultSet resultSet = null;
if (keysToLookup.size() > 0) {
- String[] keyStrings = new String[keysToLookup.size()];
+ //String[] keyStrings = new String[keysToLookup.size()];
+ ByteBuffer[] keyStrings = new ByteBuffer[keysToLookup.size()];
int count = 0;
for (byte[] rowKey : keysToLookup) {
- keyStrings[count] = StandardConverters.convertFromBytes(String.class, rowKey);
+ //keyStrings[count] = StandardConverters.convertFromBytes(String.class, rowKey);
+ keyStrings[count] = ByteBuffer.wrap(rowKey);
count++;
}
@@ -196,10 +198,12 @@ private void loadCacheBackward() {
ResultSet resultSet = null;
if (keysToLookup.size() > 0) {
- String[] keyStrings = new String[keysToLookup.size()];
+ //String[] keyStrings = new String[keysToLookup.size()];
+ ByteBuffer[] keyStrings = new ByteBuffer[keysToLookup.size()];
int count = 0;
for (byte[] rowKey : keysToLookup) {
- keyStrings[count] = StandardConverters.convertFromBytes(String.class, rowKey);
+ //keyStrings[count] = StandardConverters.convertFromBytes(String.class, rowKey);
+ keyStrings[count] = ByteBuffer.wrap(rowKey);
count++;
}
@@ -244,19 +248,25 @@ private void loadCacheBackward() {
private void fillCache(Map<ByteArray, KeyValue<Row>> map, ResultSet cursor, List<byte[]> keysToLookup) {
- String rowKey = null;
+ //String rowKey = null;
+ byte[] rowKey = null;
List<List<com.datastax.driver.core.Row>> cqlRows = new ArrayList<List<com.datastax.driver.core.Row>>();
List<com.datastax.driver.core.Row> actualRowList = new ArrayList<com.datastax.driver.core.Row>();
if (cursor == null)
return;
for (com.datastax.driver.core.Row cqlRow : cursor) {
- String rowKey1 = cqlRow.getString("id");
- if (rowKey1.equals(rowKey)) {
+ ByteBuffer data = cqlRow.getBytes("id");
+ byte[] val = new byte[data.remaining()];
+ data.get(val);
+
+
+// String rowKey1 = cqlRow.getBytes("id");
+ if (val.equals(rowKey)) {
actualRowList.add(cqlRow);
} else {
if (rowKey != null)
cqlRows.add(actualRowList);
- rowKey = rowKey1;
+ rowKey = val;
actualRowList = new ArrayList<com.datastax.driver.core.Row>();
actualRowList.add(cqlRow);
}
@@ -267,7 +277,12 @@ private void fillCache(Map<ByteArray, KeyValue<Row>> map, ResultSet cursor, List
Row r = rowProvider.get();
byte[] cqlRowKey = null;
for (com.datastax.driver.core.Row cqlRow : actualRow) {
- cqlRowKey = StandardConverters.convertToBytes(cqlRow.getString("id"));
+ //cqlRowKey = StandardConverters.convertToBytes(cqlRow.getString("id"));
+
+ ByteBuffer cqlRowKeyData = cqlRow.getBytes("id");
+ cqlRowKey = new byte[cqlRowKeyData.remaining()];
+ cqlRowKeyData.get(cqlRowKey);
+
kv.setKey(cqlRowKey);
r.setKey(cqlRowKey);
byte[] name = StandardConverters.convertToBytes(cqlRow.getString("colname"));
Please sign in to comment.
Something went wrong with that request. Please try again.