Permalink
Browse files

Starting CQL3

  • Loading branch information...
1 parent 2e58327 commit 5eea2f883da934e295b6ae96f0f34492f0331ef6 @easility easility committed Aug 26, 2013
View
@@ -26,7 +26,8 @@ dependencies {
provided (group: 'com.netflix.astyanax', name: 'astyanax', version: '1.56.42') {
exclude group: 'org.slf4j'
exclude group: 'log4j'
- }
+ }
+ compile group: 'com.datastax.cassandra', name: 'cassandra-driver-core', version: '1.0.2'
compile group: 'org.javassist', name: 'javassist', version: '3.16.1-GA'
compile group: 'com.google.inject', name: 'guice', version: '3.0'
compile group: 'args4j', name: 'args4j', version: '2.0.16'
View
@@ -23,6 +23,7 @@
<package name="astyanax" package="com.netflix.astyanax" subpackages="include"/>
<package name="mongodb" package="com.mongodb" subpackages="include"/>
<package name="cassandra" package="org.apache.cassandra" subpackages="include"/>
+<package name="cassandracql3" package="com.datastax.driver.core" subpackages="include"/>
<package name="hbase" package="org.apache.hadoop" subpackages="include"/>
<package name="args" package="org.kohsuke.args4j"/>
<package name="logback" package="ch.qos.logback" subpackages="include"/>
@@ -126,6 +127,10 @@
<depends>astyanax</depends>
<depends>cassandra</depends>
</package>
+<package name="cql" package="com.alvazan.orm.layer9z.spi.db.cassandracql3">
+ <depends>api8</depends>
+ <depends>cassandracql3</depends>
+</package>
<package name="hadoop" package="com.alvazan.orm.layer9z.spi.db.hbase">
<depends>api8</depends>
<depends>hbase</depends>
@@ -28,6 +28,10 @@
public static final String HBASE_KEYSPACE = "nosql.hbase.keyspace";
public static final String HBASE_SEEDS = "nosql.hbase.seeds";
+ public static final String CQL_CLUSTERNAME = "nosql.cql.clusterName";
+ public static final String CQL_KEYSPACE = "nosql.cql.keyspace";
+ public static final String CQL_SEEDS = "nosql.cql.seeds";
+
private static final String OUR_IMPL = "com.alvazan.orm.impl.bindings.BootstrapImpl";
public static final String SPI_IMPL = "nosql.spi.implementation";
@@ -111,4 +115,13 @@ public static void createAndAddBestHBaseConfiguration(Map<String, Object> proper
protected abstract void createBestHBaseConfig(Map<String, Object> properties,
String clusterName, String keyspace2, String seeds2);
+ public static void createAndAddBestCqlConfiguration(Map<String, Object> properties, String clusterName, String keyspace, String seeds) {
+ Bootstrap bootstrap = createInstance(OUR_IMPL);
+ bootstrap.createBestHBaseConfig(properties, clusterName, keyspace, seeds);
+ }
+
+ protected abstract void createBestCqlConfig(Map<String, Object> properties,
+ String clusterName, String keyspace2, String seeds2);
+
+
}
@@ -4,7 +4,7 @@
import java.util.Map;
public enum DbTypeEnum {
- CASSANDRA("cassandra"), IN_MEMORY("inmemory"), MONGODB("mongodb"), HBASE("hbase");
+ CASSANDRA("cassandra"), IN_MEMORY("inmemory"), MONGODB("mongodb"), HBASE("hbase"),CQL("cql");
private static final Map<String, DbTypeEnum> LOOKUP = new HashMap<String, DbTypeEnum>();
@@ -144,4 +144,12 @@ protected void createBestHBaseConfig(Map<String, Object> properties,
properties.put(Bootstrap.HBASE_KEYSPACE, keyspace2);
properties.put(Bootstrap.HBASE_SEEDS, seeds2);
}
+
+ @Override
+ protected void createBestCqlConfig(Map<String, Object> properties,
+ String clusterName, String keyspace2, String seeds2) {
+ properties.put(Bootstrap.CQL_CLUSTERNAME, clusterName);
+ properties.put(Bootstrap.CQL_KEYSPACE, keyspace2);
+ properties.put(Bootstrap.CQL_SEEDS, seeds2);
+ }
}
@@ -9,6 +9,7 @@
import com.alvazan.orm.layer5.nosql.cache.NoSqlReadCacheImpl;
import com.alvazan.orm.layer5.nosql.cache.NoSqlWriteCacheImpl;
import com.alvazan.orm.layer9z.spi.db.cassandra.CassandraSession;
+import com.alvazan.orm.layer9z.spi.db.cassandracql3.CqlSession;
import com.alvazan.orm.layer9z.spi.db.hbase.HbaseSession;
import com.alvazan.orm.layer9z.spi.db.inmemory.InMemorySession;
import com.alvazan.orm.layer9z.spi.db.mongodb.MongoDbSession;
@@ -64,6 +65,9 @@ private void bindRawSession(String name, Binder binder) {
case HBASE:
binder.bind(NoSqlRawSession.class).annotatedWith(Names.named(name)).to(HbaseSession.class).asEagerSingleton();
break;
+ case CQL:
+ binder.bind(NoSqlRawSession.class).annotatedWith(Names.named(name)).to(CqlSession.class).asEagerSingleton();
+ break;
default:
throw new RuntimeException("bug, unsupported database type="+type);
}
@@ -0,0 +1,117 @@
+package com.alvazan.orm.layer9z.spi.db.cassandracql3;
+
+import java.util.List;
+import java.util.Map;
+
+import com.alvazan.orm.api.z8spi.BatchListener;
+import com.alvazan.orm.api.z8spi.Cache;
+import com.alvazan.orm.api.z8spi.ColumnSliceInfo;
+import com.alvazan.orm.api.z8spi.Key;
+import com.alvazan.orm.api.z8spi.KeyValue;
+import com.alvazan.orm.api.z8spi.MetaLookup;
+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.action.Action;
+import com.alvazan.orm.api.z8spi.action.Column;
+import com.alvazan.orm.api.z8spi.action.IndexColumn;
+import com.alvazan.orm.api.z8spi.iter.AbstractCursor;
+import com.alvazan.orm.api.z8spi.iter.DirectCursor;
+import com.alvazan.orm.api.z8spi.meta.DboTableMeta;
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.KeyspaceMetadata;
+import com.datastax.driver.core.Session;
+
+public class CqlSession implements NoSqlRawSession {
+ private Session session = null;
+ private Cluster cluster = null;
+
+ @Override
+ public void sendChanges(List<Action> actions, MetaLookup session) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void clearDatabase() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void start(Map<String, Object> properties) {
+ String cqlSeed = "localhost";
+ String keys="newKeyspace";
+ cluster = Cluster.builder().addContactPoint(cqlSeed).build();
+ session = cluster.connect();
+ List<KeyspaceMetadata> keyspaces = cluster.getMetadata().getKeyspaces();
+ int count = 0;
+ for (KeyspaceMetadata ks : keyspaces) {
+ if (ks.getName().equalsIgnoreCase(keys)) {
+ count++;
+ }
+ }
+ if (count == 0) {
+ session.execute("CREATE KEYSPACE "+keys+" WITH replication "
+ + "= {'class':'SimpleStrategy', 'replication_factor':3};");
+ }
+ Session session = cluster.connect(keys);
+
+ }
+
+
+ @Override
+ public void close() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public AbstractCursor<Column> columnSlice(ColumnSliceInfo sliceInfo,
+ Integer batchSize, BatchListener l, MetaLookup mgr) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AbstractCursor<IndexColumn> scanIndex(ScanInfo scan, Key from,
+ Key to, Integer batchSize, BatchListener l, MetaLookup mgr) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AbstractCursor<IndexColumn> scanIndex(ScanInfo scanInfo,
+ List<byte[]> values, BatchListener list, MetaLookup mgr) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AbstractCursor<KeyValue<Row>> find(DboTableMeta colFamily,
+ DirectCursor<byte[]> rowKeys, Cache cache, int batchSize,
+ BatchListener list, MetaLookup mgr) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void readMetaAndCreateTable(MetaLookup ormSession, String colFamily) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public AbstractCursor<Row> allRows(DboTableMeta colFamily, MetaLookup mgr,
+ int batchSize) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Object getDriverHelper() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
@@ -0,0 +1,31 @@
+package com.alvazan.orm.layer9z.spi.db.cassandracql3;
+
+import com.alvazan.orm.api.z8spi.ColumnType;
+import com.alvazan.orm.api.z8spi.conv.StorageTypeEnum;
+import com.datastax.driver.core.TableMetadata;
+
+public class Info {
+
+ private StorageTypeEnum rowKeyType;
+ private ColumnType columnType;
+ private TableMetadata tableMetadata;
+ public StorageTypeEnum getRowKeyType() {
+ return rowKeyType;
+ }
+ public void setRowKeyType(StorageTypeEnum rowKeyType) {
+ this.rowKeyType = rowKeyType;
+ }
+ public ColumnType getColumnType() {
+ return columnType;
+ }
+ public void setColumnType(ColumnType columnType) {
+ this.columnType = columnType;
+ }
+ public TableMetadata getTableMetadata() {
+ return tableMetadata;
+ }
+ public void setTableMetadata(TableMetadata tableMetadata) {
+ this.tableMetadata = tableMetadata;
+ }
+
+}

0 comments on commit 5eea2f8

Please sign in to comment.