Permalink
Browse files

More changes for CQL3

  • Loading branch information...
1 parent 9313bca commit fc8c91dbca9310b5fc1d22557fbc262ccd9b8f7e @easility easility committed Dec 7, 2013
@@ -5,6 +5,4 @@
public static final String CASSANDRA_BUILDER = "nosql.cassandra.builder";
public static final String CASSANDRA_CF_CREATE_CALLBACK = "nosql.cassandra.createcfcallback";
- public static final String NULL_STRING_FORCQL3 = "_n";
-
}
@@ -20,7 +20,6 @@
import com.alvazan.orm.api.z8spi.NoSqlRawSession;
import com.alvazan.orm.api.z8spi.Row;
import com.alvazan.orm.api.z8spi.ScanInfo;
-import com.alvazan.orm.api.z8spi.SpiConstants;
import com.alvazan.orm.api.z8spi.action.Action;
import com.alvazan.orm.api.z8spi.action.Column;
import com.alvazan.orm.api.z8spi.action.IndexColumn;
@@ -52,7 +51,7 @@
private Session session = null;
private Cluster cluster = null;
private KeyspaceMetadata keyspaces = null;
- private String keys = "cql72";
+ private String keys = "cql74";
@Inject
private Provider<Row> rowProvider;
@@ -93,33 +92,23 @@ public void sendChanges(List<Action> actions, MetaLookup ormSession) {
}
private void persist(Persist action, MetaLookup ormSession) {
- //StorageTypeEnum type = action.getColFamily().getNameStorageType();
String colFamily = action.getColFamily().getColumnFamily();
String table = lookupOrCreate(colFamily, ormSession);
List<Column> s = action.getColumns();
byte[] rowkey = action.getRowKey();
- byte[] nullArray = StandardConverters.convertToBytes(SpiConstants.NULL_STRING_FORCQL3);
for (Column c : s) {
try {
- String colValue = StandardConverters.convertFromBytes(String.class, c.getValue());
PreparedStatement statement = session.prepare("INSERT INTO " + keys + "." + table + "(id, colname, colvalue) VALUES (?, ?, ?)");
BoundStatement boundStatement = new BoundStatement(statement);
- if (colValue != null) {
- session.execute(boundStatement.bind(ByteBuffer.wrap(rowkey),
- StandardConverters.convertFromBytes(String.class, c.getName()),
+ if (c.getValue() != null && c.getValue().length != 0) {
+ session.execute(boundStatement.bind(ByteBuffer.wrap(rowkey), StandardConverters.convertFromBytes(String.class, c.getName()),
ByteBuffer.wrap(c.getValue())));
-/* 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)));
-*/ }
+ } else {
+ session.execute(boundStatement.bind(ByteBuffer.wrap(rowkey), StandardConverters.convertFromBytes(String.class, c.getName()),
+ ByteBuffer.wrap(new byte[0])));
+ }
} catch (Exception e) {
System.out.println(c.getValue() + "Exception:" + e.getMessage());
@@ -2,6 +2,7 @@
import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -15,7 +16,6 @@
import com.alvazan.orm.api.z8spi.KeyValue;
import com.alvazan.orm.api.z8spi.Row;
import com.alvazan.orm.api.z8spi.RowHolder;
-import com.alvazan.orm.api.z8spi.SpiConstants;
import com.alvazan.orm.api.z8spi.action.Column;
import com.alvazan.orm.api.z8spi.conv.ByteArray;
import com.alvazan.orm.api.z8spi.conv.StandardConverters;
@@ -141,7 +141,8 @@ private void loadCache() {
list.beforeFetchingNextBatch();
try {
Clause inClause = QueryBuilder.in("id", keyStrings);
- Query query = QueryBuilder.select().all().from(keys, cf.getColumnFamily()).where(inClause).limit(batchSize);
+ //change the batchsize
+ Query query = QueryBuilder.select().all().from(keys, cf.getColumnFamily()).where(inClause).limit(100);
resultSet = session.execute(query);
} catch (Exception e) {
System.out.println(" Exception:" + e.getMessage());
@@ -210,8 +211,9 @@ private void loadCacheBackward() {
if (list != null)
list.beforeFetchingNextBatch();
try {
+ // CHANGE THE BATCHSIZE
Clause inClause = QueryBuilder.in("id", keyStrings);
- Query query = QueryBuilder.select().all().from(keys, cf.getColumnFamily()).where(inClause).limit(batchSize);
+ Query query = QueryBuilder.select().all().from(keys, cf.getColumnFamily()).where(inClause).limit(100);
resultSet = session.execute(query);
} catch (Exception e) {
System.out.println(" Exception:" + e.getMessage());
@@ -248,7 +250,6 @@ private void loadCacheBackward() {
private void fillCache(Map<ByteArray, KeyValue<Row>> map, ResultSet cursor, List<byte[]> keysToLookup) {
- //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>();
@@ -259,9 +260,7 @@ private void fillCache(Map<ByteArray, KeyValue<Row>> map, ResultSet cursor, List
byte[] val = new byte[data.remaining()];
data.get(val);
-
-// String rowKey1 = cqlRow.getBytes("id");
- if (val.equals(rowKey)) {
+ if (Arrays.equals(val, rowKey)) {
actualRowList.add(cqlRow);
} else {
if (rowKey != null)
@@ -272,13 +271,12 @@ private void fillCache(Map<ByteArray, KeyValue<Row>> map, ResultSet cursor, List
}
}
cqlRows.add(actualRowList);
+
for (List<com.datastax.driver.core.Row> actualRow : cqlRows) {
KeyValue<Row> kv = new KeyValue<Row>();
Row r = rowProvider.get();
byte[] cqlRowKey = null;
for (com.datastax.driver.core.Row cqlRow : actualRow) {
- //cqlRowKey = StandardConverters.convertToBytes(cqlRow.getString("id"));
-
ByteBuffer cqlRowKeyData = cqlRow.getBytes("id");
cqlRowKey = new byte[cqlRowKeyData.remaining()];
cqlRowKeyData.get(cqlRowKey);
@@ -289,10 +287,9 @@ private void fillCache(Map<ByteArray, KeyValue<Row>> map, ResultSet cursor, List
ByteBuffer data = cqlRow.getBytes("colvalue");
byte[] val = new byte[data.remaining()];
data.get(val);
- String strValue = StandardConverters.convertFromBytes(String.class, val);
Column c = new Column();
c.setName(name);
- if (!strValue.equals(SpiConstants.NULL_STRING_FORCQL3))
+ if (val.length != 0)
c.setValue(val);
r.put(c);

0 comments on commit fc8c91d

Please sign in to comment.