gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject [02/37] gora git commit: Adding Cassandra Mapping file reading
Date Wed, 23 Aug 2017 20:55:00 GMT
Adding Cassandra Mapping file reading


Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/a7b99f83
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/a7b99f83
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/a7b99f83

Branch: refs/heads/master
Commit: a7b99f83aaf385cbe6772a5a0c7843b65153ec57
Parents: cd3522a
Author: madhawa-gunasekara <madhawag@wso2.com>
Authored: Thu Jun 22 15:36:48 2017 +0530
Committer: madhawa <madhawa30@gmail.com>
Committed: Fri Jun 23 00:52:39 2017 +0530

----------------------------------------------------------------------
 gora-cassandra-cql/pom.xml                      |  47 +----
 .../org/apache/gora/cassandra/bean/Field.java   |  54 ++++++
 .../apache/gora/cassandra/bean/KeySpace.java    |  84 +++++++++
 .../apache/gora/cassandra/bean/PrimaryKey.java  |   7 +
 .../gora/cassandra/store/CassandraMapping.java  |  60 +++++++
 .../cassandra/store/CassandraQueryFactory.java  |  58 ++++++
 .../gora/cassandra/store/CassandraStore.java    | 178 +++++++++++++++++--
 .../apache/gora/cassandra/store/Constants.java  |  75 ++++----
 .../src/test/conf/gora-cassandra-mapping.xml    |  78 ++++----
 .../gora/cassandra/GoraCassandraTestDriver.java |   3 +-
 .../cassandra/store/TestCassandraStore.java     |   9 +-
 11 files changed, 514 insertions(+), 139 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/pom.xml
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/pom.xml b/gora-cassandra-cql/pom.xml
index b17fd41..11da4fc 100644
--- a/gora-cassandra-cql/pom.xml
+++ b/gora-cassandra-cql/pom.xml
@@ -17,22 +17,6 @@
   -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-     <!--
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements.  See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You under the Apache License, Version 2.0
-    (the "License"); you may not use this file except in compliance with
-    the License.  You may obtain a copy of the License at
-
-        http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
-    -->
     <modelVersion>4.0.0</modelVersion>
 
     <parent>    
@@ -65,6 +49,7 @@
     </ciManagement>
 
     <properties>
+        <guava.version>17.0</guava.version>
         <osgi.import>*</osgi.import>
         <osgi.export>org.apache.gora.cassandra*;version="${project.version}";-noimport:=true</osgi.export>
     </properties>
@@ -136,12 +121,12 @@
             <groupId>com.datastax.cassandra</groupId>
             <artifactId>cassandra-driver-core</artifactId>
             <version>${cassandra-driver.version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>com.google.guava</groupId>
-                    <artifactId>guava</artifactId>
-                </exclusion>
-            </exclusions>
+        </dependency>
+
+        <dependency>
+        <groupId>com.datastax.cassandra</groupId>
+        <artifactId>cassandra-driver-mapping</artifactId>
+            <version>${cassandra-driver.version}</version>
         </dependency>
 
         <!-- Cassandra Dependencies -->
@@ -165,26 +150,11 @@
             </exclusions>
         </dependency>
 
-        <!-- dependency>
-            <groupId>org.apache.cassandra</groupId>
-            <artifactId>cassandra-thrift</artifactId>
-        </dependency-->
-
-        <!--<dependency>-->
-        <!--<groupId>org.hectorclient</groupId>-->
-        <!--<artifactId>hector-core</artifactId>-->
-        <!--<exclusions>-->
-        <!--<exclusion>-->
-        <!--<groupId>org.apache.cassandra</groupId>-->
-        <!--<artifactId>cassandra-all</artifactId>-->
-        <!--</exclusion>-->
-        <!--</exclusions>-->
-        <!--</dependency>-->
-
         <!-- Misc Dependencies -->
         <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
+            <version>${guava.version}</version>
         </dependency>
 
         <dependency>
@@ -192,7 +162,6 @@
             <artifactId>jdom</artifactId>
         </dependency>
 
-
         <dependency>
             <groupId>org.apache.avro</groupId>
             <artifactId>avro</artifactId>

http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/Field.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/Field.java b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/Field.java
new file mode 100644
index 0000000..2bd997f
--- /dev/null
+++ b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/Field.java
@@ -0,0 +1,54 @@
+package org.apache.gora.cassandra.bean;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by madhawa on 6/22/17.
+ */
+public class Field {
+
+  private String fieldName;
+
+  private String columnName;
+
+  private String type;
+
+  public Field() {
+    properties = new HashMap<>(2);
+  }
+
+  private Map<String, String> properties;
+
+  public void setFieldName(String fieldName) {
+    this.fieldName = fieldName;
+  }
+
+  public void setColumnName(String columnName) {
+    this.columnName = columnName;
+  }
+
+  public void addProperty(String key, String value) {
+    properties.put(key, value);
+  }
+
+  public String getFieldName() {
+    return fieldName;
+  }
+
+  public String getColumnName() {
+    return columnName;
+  }
+
+  public String getType() {
+    return type;
+  }
+
+  public void setType(String type) {
+    this.type = type;
+  }
+
+  public String getProperty(String key) {
+    return this.properties.get(key);
+  }
+}

http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/KeySpace.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/KeySpace.java
b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/KeySpace.java
new file mode 100644
index 0000000..af563da
--- /dev/null
+++ b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/KeySpace.java
@@ -0,0 +1,84 @@
+package org.apache.gora.cassandra.bean;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class represents the Cassandra Keyspace.
+ */
+public class KeySpace {
+  public String getName() {
+    return name;
+  }
+
+  public boolean isDurableWritesEnabled() {
+    return durableWritesEnabled;
+  }
+
+  public PlacementStrategy getPlacementStrategy() {
+    return placementStrategy;
+  }
+
+  public int getReplicationFactor() {
+    return replicationFactor;
+  }
+
+  public Map<String, Integer> getDataCenters() {
+    return dataCenters;
+  }
+
+  public void addDataCenter(String key, Integer value) {
+    this.dataCenters.put(key, value);
+  }
+
+  private String name;
+
+  private Map<String, String> properties;
+
+  private boolean durableWritesEnabled;
+
+  public KeySpace() {
+    this.properties = new HashMap<>();
+  }
+
+  public enum PlacementStrategy {
+    SimpleStrategy,
+    NetworkTopologyStrategy,
+  }
+
+  public void setPlacementStrategy(PlacementStrategy placementStrategy) {
+    this.placementStrategy = placementStrategy;
+    if(placementStrategy.equals(PlacementStrategy.NetworkTopologyStrategy) && this.dataCenters
== null) {
+      this.dataCenters = new HashMap<>();
+    }
+  }
+
+  private PlacementStrategy placementStrategy;
+
+  public void setReplicationFactor(int replicationFactor) {
+    this.replicationFactor = replicationFactor;
+  }
+
+  private int replicationFactor;
+
+  private Map<String, Integer> dataCenters;
+
+  private List<String> tables;
+
+  public void addProperty(String key, String value) {
+    this.properties.put(key, value);
+  }
+
+  public String getProperty(String key) {
+    return this.properties.get(key);
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public void setDurableWritesEnabled(boolean durableWritesEnabled) {
+    this.durableWritesEnabled = durableWritesEnabled;
+  }
+}

http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/PrimaryKey.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/PrimaryKey.java
b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/PrimaryKey.java
new file mode 100644
index 0000000..d3477f2
--- /dev/null
+++ b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/bean/PrimaryKey.java
@@ -0,0 +1,7 @@
+package org.apache.gora.cassandra.bean;
+
+/**
+ * Created by madhawa on 6/22/17.
+ */
+public class PrimaryKey {
+}

http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraMapping.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraMapping.java
b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraMapping.java
new file mode 100644
index 0000000..e533d57
--- /dev/null
+++ b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraMapping.java
@@ -0,0 +1,60 @@
+package org.apache.gora.cassandra.store;
+
+import org.apache.gora.cassandra.bean.Field;
+import org.apache.gora.cassandra.bean.KeySpace;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by madhawa on 6/22/17.
+ */
+public class CassandraMapping {
+
+  public KeySpace getKeySpace() {
+    return keySpace;
+  }
+
+  public void setKeySpace(KeySpace keySpace) {
+    this.keySpace = keySpace;
+  }
+
+  private KeySpace keySpace;
+
+  public List<Field> getFieldList() {
+    return fieldList;
+  }
+
+  private List<Field> fieldList;
+
+  private Map<String, String> tableProperties;
+
+  public CassandraMapping() {
+    this.fieldList = new ArrayList<>();
+    this.tableProperties = new HashMap<>();
+  }
+
+  public void setCoreName(String coreName) {
+    this.coreName = coreName;
+  }
+
+  public String getCoreName() {
+    return coreName;
+  }
+
+  private String coreName;
+
+  public void addCassandraField(Field field) {
+    this.fieldList.add(field);
+  }
+
+  public void addProperty(String key, String value) {
+        this.tableProperties.put(key,value);
+  }
+
+  public String getProperty(String key) {
+    return this.tableProperties.get(key);
+  }
+}

http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraQueryFactory.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraQueryFactory.java
b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraQueryFactory.java
new file mode 100644
index 0000000..e70eaee
--- /dev/null
+++ b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraQueryFactory.java
@@ -0,0 +1,58 @@
+package org.apache.gora.cassandra.store;
+
+import org.apache.gora.cassandra.bean.Field;
+import org.apache.gora.cassandra.bean.KeySpace;
+
+import java.util.Map;
+
+class CassandraQueryFactory {
+
+  static String getCreateKeySpaceQuery(CassandraMapping mapping) {
+    KeySpace keySpace = mapping.getKeySpace();
+    StringBuilder stringBuffer = new StringBuilder();
+    stringBuffer.append("CREATE KEYSPACE ").append(keySpace.getName()).append(" WITH REPLICATION
= { 'class' : ");
+    KeySpace.PlacementStrategy placementStrategy = keySpace.getPlacementStrategy();
+    stringBuffer.append("'").append(placementStrategy).append("'").append(", ").append("'");
+    switch (placementStrategy) {
+      case SimpleStrategy:
+        stringBuffer.append("replication_factor").append("'").append(" : ").append(keySpace.getReplicationFactor()).append("
}");
+        break;
+      case NetworkTopologyStrategy:
+        boolean isCommaNeeded = false;
+        for (Map.Entry<String, Integer> entry : keySpace.getDataCenters().entrySet())
{
+          if (isCommaNeeded) {
+            stringBuffer.append(", '");
+          }
+          stringBuffer.append(entry.getKey()).append("'").append(" : ").append(entry.getValue());
+          isCommaNeeded = true;
+        }
+        stringBuffer.append(" }");
+        break;
+    }
+
+    if(keySpace.isDurableWritesEnabled()) {
+      stringBuffer.append(" AND DURABLE_WRITES = ").append(keySpace.isDurableWritesEnabled());
+    }
+    return stringBuffer.toString();
+  }
+
+  static String getCreateTableQuery(CassandraMapping mapping) {
+    StringBuilder stringBuffer = new StringBuilder();
+stringBuffer.append("CREATE TABLE ").append(mapping.getCoreName()).append(" (");
+    boolean isCommaNeeded = false;
+    for(Field field : mapping.getFieldList()) {
+      if(isCommaNeeded) {
+        stringBuffer.append(", ");
+      }
+      stringBuffer.append(field.getColumnName()).append(" ").append(field.getType());
+      boolean isStaticColumn = Boolean.parseBoolean(field.getProperty("static"));
+      if( isStaticColumn) {
+        stringBuffer.append(" STATIC");
+      }
+      isCommaNeeded =true;
+    }
+
+    return stringBuffer.toString();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
index b4c6e68..4bd1ad3 100644
--- a/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
+++ b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/CassandraStore.java
@@ -17,15 +17,24 @@
 
 package org.apache.gora.cassandra.store;
 
+import com.datastax.driver.mapping.Mapper;
+import com.datastax.driver.mapping.MappingManager;
 import com.datastax.driver.core.*;
 import com.datastax.driver.core.policies.*;
+import org.apache.gora.cassandra.bean.Field;
+import org.apache.gora.cassandra.bean.KeySpace;
 import org.apache.gora.persistency.BeanFactory;
 import org.apache.gora.persistency.impl.PersistentBase;
 import org.apache.gora.query.PartitionQuery;
 import org.apache.gora.query.Query;
 import org.apache.gora.query.Result;
+import org.apache.gora.store.DataStoreFactory;
 import org.apache.gora.store.impl.DataStoreBase;
 import org.apache.hadoop.conf.Configuration;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,25 +46,18 @@ import java.util.Properties;
 
 public class CassandraStore<K, T extends PersistentBase> extends DataStoreBase<K,
T> {
 
-  /**
-   * Consistency property level for Cassandra column families
-   */
-  private static final String COL_FAM_CL = "cf.consistency.level";
-
-  /**
-   * Consistency property level for Cassandra read operations.
-   */
-  private static final String READ_OP_CL = "read.consistency.level";
-
-  /**
-   * Consistency property level for Cassandra write operations.
-   */
-  private static final String WRITE_OP_CL = "write.consistency.level";
+  private static final String DEFAULT_MAPPING_FILE = "gora-cassandra-mapping.xml";
 
   public static final Logger LOG = LoggerFactory.getLogger(CassandraStore.class);
 
   private Cluster cluster;
 
+  private CassandraMapping mapping;
+
+  private boolean isUseCassandraMappingManager;
+
+  private Mapper<T> mapper;
+
   private Session session;
 
   public CassandraStore() {
@@ -67,10 +69,19 @@ public class CassandraStore<K, T extends PersistentBase> extends
DataStoreBase<K
     LOG.debug("Initializing Cassandra store");
     super.initialize(keyClass, persistentClass, properties);
     try {
+      String mappingFile = DataStoreFactory.getMappingFile(properties, this,
+              DEFAULT_MAPPING_FILE);
+      mapping = readMapping(mappingFile);
+      isUseCassandraMappingManager = Boolean.parseBoolean(properties.getProperty(Constants.USE_CASSANDRA_MAPPING_MANAGER));
       Cluster.Builder builder = Cluster.builder();
       populateSettings(builder, properties);
       this.cluster = builder.build();
       this.session = this.cluster.connect();
+      if (isUseCassandraMappingManager) {
+        MappingManager mappingManager = new MappingManager(session);
+        mapper = mappingManager.mapper(persistentClass);
+      }
+
     } catch (Exception e) {
       LOG.error("Error while initializing Cassandra store: {}",
               new Object[]{e.getMessage()});
@@ -78,6 +89,126 @@ public class CassandraStore<K, T extends PersistentBase> extends
DataStoreBase<K
     }
   }
 
+  private CassandraMapping readMapping(String filename) throws IOException {
+    CassandraMapping map = new CassandraMapping();
+    try {
+      SAXBuilder builder = new SAXBuilder();
+      Document doc = builder.build(getClass().getClassLoader()
+              .getResourceAsStream(filename));
+
+      List<Element> keyspaces = doc.getRootElement().getChildren("keyspace");
+
+      List<Element> classes = doc.getRootElement().getChildren("class");
+
+      boolean classMatched = false;
+      for (Element classElement : classes) {
+        if (classElement.getAttributeValue("keyClass").equals(
+                keyClass.getCanonicalName())
+                && classElement.getAttributeValue("name").equals(
+                persistentClass.getCanonicalName())) {
+
+          classMatched = true;
+          String tableName = getSchemaName(
+                  classElement.getAttributeValue("table"), persistentClass);
+          map.setCoreName(tableName);
+
+          List classAttributes = classElement.getAttributes();
+          for (Object anAttributeList : classAttributes) {
+            Attribute attribute = (Attribute) anAttributeList;
+            String attributeName = attribute.getName();
+            String attributeValue = attribute.getValue();
+            map.addProperty(attributeName, attributeValue);
+          }
+
+          List<Element> fields = classElement.getChildren("field");
+
+          for (Element field : fields) {
+            Field cassandraField = new Field();
+
+            List fieldAttributes = field.getAttributes();
+            for (Object anAttributeList : fieldAttributes) {
+              Attribute attribute = (Attribute) anAttributeList;
+              String attributeName = attribute.getName();
+              String attributeValue = attribute.getValue();
+              switch (attributeName) {
+                case "name":
+                  cassandraField.setFieldName(attributeValue);
+                  break;
+                case "column":
+                  cassandraField.setColumnName(attributeValue);
+                  break;
+                default:
+                  cassandraField.addProperty(attributeName, attributeValue);
+                  break;
+              }
+            }
+            map.addCassandraField(cassandraField);
+          }
+          break;
+        }
+        LOG.warn("Check that 'keyClass' and 'name' parameters in gora-solr-mapping.xml "
+                + "match with intended values. A mapping mismatch has been found therefore
"
+                + "no mapping has been initialized for class mapping at position "
+                + " {} in mapping file.", classes.indexOf(classElement));
+      }
+      if (!classMatched) {
+        LOG.error("Check that 'keyClass' and 'name' parameters in {} no mapping has been
initialized for {} class mapping", filename, persistentClass);
+      }
+
+      String keyspaceName = map.getProperty("keyspace");
+      if (keyspaceName != null) {
+        KeySpace keyspace = null;
+        for (Element keyspaceElement : keyspaces) {
+          if (keyspaceName.equals(keyspaceElement.getAttributeValue("name"))) {
+            keyspace = new KeySpace();
+            List fieldAttributes = keyspaceElement.getAttributes();
+            for (Object attributeObject : fieldAttributes) {
+              Attribute attribute = (Attribute) attributeObject;
+              String attributeName = attribute.getName();
+              String attributeValue = attribute.getValue();
+              switch (attributeName) {
+                case "name":
+                  keyspace.setName(attributeValue);
+                  break;
+                case "durableWrite":
+                  keyspace.setDurableWritesEnabled(Boolean.parseBoolean(attributeValue));
+                  break;
+                default:
+                  keyspace.addProperty(attributeName, attributeValue);
+                  break;
+              }
+            }
+            Element placementStrategy =  keyspaceElement.getChild("placementStrategy");
+            switch (KeySpace.PlacementStrategy.valueOf(placementStrategy.getAttributeValue("name")))
{
+              case SimpleStrategy:
+                keyspace.setPlacementStrategy(KeySpace.PlacementStrategy.SimpleStrategy);
+                keyspace.setReplicationFactor(Integer.parseInt(placementStrategy.getAttributeValue("replication_factor")));
+                break;
+              case NetworkTopologyStrategy:
+                List<Element> dataCenters =  placementStrategy.getChildren("datacenter");
+                keyspace.setPlacementStrategy(KeySpace.PlacementStrategy.NetworkTopologyStrategy);
+                for(Element dataCenter : dataCenters) {
+                 String dataCenterName = dataCenter.getAttributeValue("name");
+                  Integer dataCenterReplicationFactor = Integer.valueOf(dataCenter.getAttributeValue("replication_factor"));
+                  keyspace.addDataCenter(dataCenterName, dataCenterReplicationFactor);
+                }
+                break;
+            }
+            map.setKeySpace(keyspace);
+            break;
+          }
+
+        }
+
+      }
+
+    } catch (Exception ex) {
+      throw new IOException(ex);
+    }
+
+    return map;
+  }
+
   private void populateSettings(Cluster.Builder builder, Properties properties) {
     String serversParam = properties.getProperty(Constants.CASSANDRA_SERVERS);
     String[] servers = serversParam.split(",");
@@ -416,7 +547,11 @@ public class CassandraStore<K, T extends PersistentBase> extends
DataStoreBase<K
 
   @Override
   public T get(K key) {
-    return super.get(key);
+    if (isUseCassandraMappingManager) {
+      return mapper.get(key);
+    } else {
+      return super.get(key);
+    }
   }
 
   @Override
@@ -426,12 +561,21 @@ public class CassandraStore<K, T extends PersistentBase> extends
DataStoreBase<K
 
   @Override
   public void put(K key, T obj) {
-
+    if (isUseCassandraMappingManager) {
+      mapper.save(obj);
+    } else {
+      super.get(key);
+    }
   }
 
   @Override
   public boolean delete(K key) {
-    return false;
+    if (isUseCassandraMappingManager) {
+      mapper.delete(key);
+      return true;
+    } else {
+      return false;
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/Constants.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/Constants.java
b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/Constants.java
index d90a24b..c79301a 100644
--- a/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/Constants.java
+++ b/gora-cassandra-cql/src/main/java/org/apache/gora/cassandra/store/Constants.java
@@ -20,81 +20,82 @@ package org.apache.gora.cassandra.store;
 public class Constants {
 
   /* string (multiple values with comma separated) */
-  public static final String CASSANDRA_SERVERS = "gora.cassandrastore.cassandraServers";
+  public static final String CASSANDRA_SERVERS = "gora.cassandra.store.cassandraServers";
   /* string */
-  public static final String KEYSPACE = "gora.cassandrastore.keyspace";
+  public static final String KEYSPACE = "gora.cassandra.store.keyspace";
   /* integer */
-  public static final String PORT = "gora.cassandrastore.port";
+  public static final String PORT = "gora.cassandra.store.port";
   /* string */
-  public static final String CLUSTER_NAME = "gora.cassandrastore.clusterName";
+  public static final String CLUSTER_NAME = "gora.cassandra.store.clusterName";
   /* "LZ4", "SNAPPY", "NONE" */
-  public static final String COMPRESSION = "gora.cassandrastore.compression";
+  public static final String COMPRESSION = "gora.cassandra.store.compression";
   /* string */
-  public static final String USERNAME = "gora.cassandrastore.username";
+  public static final String USERNAME = "gora.cassandra.store.username";
   /* string */
-  public static final String PASSWORD = "gora.cassandrastore.password";
+  public static final String PASSWORD = "gora.cassandra.store.password";
   /* "RoundRobinPolicy", "LatencyAwareRoundRobinPolicy", "TokenAwareRoundRobinPolicy" */
-  public static final String LOAD_BALANCING_POLICY = "gora.cassandrastore.loadBalancingPolicy";
+  public static final String LOAD_BALANCING_POLICY = "gora.cassandra.store.loadBalancingPolicy";
   /* boolean */
-  public static final String ENABLE_JMX_REPORTING = "gora.cassandrastore.enableJMXReporting";
+  public static final String ENABLE_JMX_REPORTING = "gora.cassandra.store.enableJMXReporting";
   /* boolean */
-  public static final String ENABLE_METRICS = "gora.cassandrastore.enableMetrics";
+  public static final String ENABLE_METRICS = "gora.cassandra.store.enableMetrics";
   /* inter */
-  public static final String LOCAL_CORE_CONNECTIONS_PER_HOST = "gora.cassandrastore.localCoreConnectionsPerHost";
+  public static final String LOCAL_CORE_CONNECTIONS_PER_HOST = "gora.cassandra.store.localCoreConnectionsPerHost";
   /* integer */
-  public static final String REMOTE_CORE_CONNECTIONS_PER_HOST = "gora.cassandrastore.remoteCoreConnectionsPerHost";
+  public static final String REMOTE_CORE_CONNECTIONS_PER_HOST = "gora.cassandra.store.remoteCoreConnectionsPerHost";
   /* integer */
-  public static final String LOCAL_MAX_CONNECTIONS_PER_HOST = "gora.cassandrastore.localMaxConnectionsPerHost";
+  public static final String LOCAL_MAX_CONNECTIONS_PER_HOST = "gora.cassandra.store.localMaxConnectionsPerHost";
   /* integer */
-  public static final String REMOTE_MAX_CONNECTIONS_PER_HOST = "gora.cassandrastore.remoteMaxConnectionsPerHost";
+  public static final String REMOTE_MAX_CONNECTIONS_PER_HOST = "gora.cassandra.store.remoteMaxConnectionsPerHost";
   /* integer */
-  public static final String LOCAL_NEW_CONNECTION_THRESHOLD= "gora.cassandrastore.localNewConnectionThreshold";
+  public static final String LOCAL_NEW_CONNECTION_THRESHOLD= "gora.cassandra.store.localNewConnectionThreshold";
   /* integer */
-  public static final String REMOTE_NEW_CONNECTION_THRESHOLD = "gora.cassandrastore.remoteNewConnectionThreshold";
+  public static final String REMOTE_NEW_CONNECTION_THRESHOLD = "gora.cassandra.store.remoteNewConnectionThreshold";
   /* integer */
-  public static final String LOCAL_MAX_REQUESTS_PER_CONNECTION = "gora.cassandrastore.localMaxRequestsPerConnection";
+  public static final String LOCAL_MAX_REQUESTS_PER_CONNECTION = "gora.cassandra.store.localMaxRequestsPerConnection";
   /* integer */
-  public static final String REMOTE_MAX_REQUESTS_PER_CONNECTION = "gora.cassandrastore.remoteMaxRequestsPerConnection";
+  public static final String REMOTE_MAX_REQUESTS_PER_CONNECTION = "gora.cassandra.store.remoteMaxRequestsPerConnection";
   /* integer */
-  public static final String PROTOCOL_VERSION = "gora.cassandrastore.protocolVersion";
+  public static final String PROTOCOL_VERSION = "gora.cassandra.store.protocolVersion";
   /* "ALL", "ANY", "EACH_QUORUM", "LOCAL_ONE", "LOCAL_QUORUM", "LOCAL_SERIAL", "ONE", "QUORUM",
"SERIAL", "THREE", "TWO" */
-  public static final String CONSISTENCY_LEVEL = "gora.cassandrastore.consistencyLevel";
+  public static final String CONSISTENCY_LEVEL = "gora.cassandra.store.consistencyLevel";
   /* integer */
   public static final String FETCH_SIZE = "fetchSize";
   /* "ALL", "ANY", "EACH_QUORUM", "LOCAL_ONE", "LOCAL_QUORUM", "LOCAL_SERIAL", "ONE", "QUORUM",
"SERIAL", "THREE", "TWO" */
-  public static final String SERIAL_CONSISTENCY_LEVEL = "gora.cassandrastore.serialConsistencyLevel";
+  public static final String SERIAL_CONSISTENCY_LEVEL = "gora.cassandra.store.serialConsistencyLevel";
   /* "ConstantReconnectionPolicy", "ExponentialReconnectionPolicy",  */
-  public static final String RECONNECTION_POLICY = "gora.cassandrastore.reconnectionPolicy";
+  public static final String RECONNECTION_POLICY = "gora.cassandra.store.reconnectionPolicy";
   /* long */
-  public static final String CONSTANT_RECONNECTION_POLICY_DELAY = "gora.cassandrastore.constantReconnectionPolicyDelay";
+  public static final String CONSTANT_RECONNECTION_POLICY_DELAY = "gora.cassandra.store.constantReconnectionPolicyDelay";
   /* long */
-  public static final String EXPONENTIAL_RECONNECTION_POLICY_BASE_DELAY = "gora.cassandrastore.exponentialReconnectionPolicyBaseDelay";
+  public static final String EXPONENTIAL_RECONNECTION_POLICY_BASE_DELAY = "gora.cassandra.store.exponentialReconnectionPolicyBaseDelay";
   /* long */
-  public static final String EXPONENTIAL_RECONNECTION_POLICY_MAX_DELAY = "gora.cassandrastore.exponentialReconnectionPolicyMaxDelay";
+  public static final String EXPONENTIAL_RECONNECTION_POLICY_MAX_DELAY = "gora.cassandra.store.exponentialReconnectionPolicyMaxDelay";
   /* "DefaultRetryPolicy", "DowngradingConsistencyRetryPolicy", "FallthroughRetryPolicy",
    * "LoggingDefaultRetryPolicy", "LoggingDowngradingConsistencyRetryPolicy", "LoggingFallthroughRetryPolicy"
*/
-  public static final String RETRY_POLICY = "gora.cassandrastore.retryPolicy";
+  public static final String RETRY_POLICY = "gora.cassandra.store.retryPolicy";
   /* integer */
-  public static final String CONNECTION_TIMEOUT_MILLIS = "gora.cassandrastore.connectionTimeoutMillis";
+  public static final String CONNECTION_TIMEOUT_MILLIS = "gora.cassandra.store.connectionTimeoutMillis";
   /* boolean */
-  public static final String KEEP_ALIVE = "gora.cassandrastore.keepAlive";
+  public static final String KEEP_ALIVE = "gora.cassandra.store.keepAlive";
   /* integer */
-  public static final String READ_TIMEOUT_MILLIS = "gora.cassandrastore.readTimeoutMillis";
+  public static final String READ_TIMEOUT_MILLIS = "gora.cassandra.store.readTimeoutMillis";
   /* integer */
-  public static final String RECEIVER_BUFFER_SIZE = "gora.cassandrastore.receiverBufferSize";
+  public static final String RECEIVER_BUFFER_SIZE = "gora.cassandra.store.receiverBufferSize";
   /* boolean */
-  public static final String REUSE_ADDRESS = "gora.cassandrastore.reuseAddress";
+  public static final String REUSE_ADDRESS = "gora.cassandra.store.reuseAddress";
   /* integer */
-  public static final String SEND_BUFFER_SIZE = "gora.cassandrastore.sendBufferSize";
+  public static final String SEND_BUFFER_SIZE = "gora.cassandra.store.sendBufferSize";
   /* integer */
-  public static final String SO_LINGER = "gora.cassandrastore.soLinger";
+  public static final String SO_LINGER = "gora.cassandra.store.soLinger";
   /* boolean */
-  public static final String TCP_NODELAY = "gora.cassandrastore.tcpNoDelay";
+  public static final String TCP_NODELAY = "gora.cassandra.store.tcpNoDelay";
   /* boolean */
-  public static final String ENABLE_SSL = "gora.cassandrastore.enableSSL";
+  public static final String ENABLE_SSL = "gora.cassandra.store.enableSSL";
   /* string */
-  public static final String DATA_CENTER = "gora.cassandrastore.dataCenter";
+  public static final String DATA_CENTER = "gora.cassandra.store.dataCenter";
   /* boolean */
-  public static final String ALLOW_REMOTE_DCS_FOR_LOCAL_CONSISTENCY_LEVEL = "gora.cassandrastore.allowRemoteDCsForLocalConsistencyLevel";
+  public static final String ALLOW_REMOTE_DCS_FOR_LOCAL_CONSISTENCY_LEVEL = "gora.cassandra.store.allowRemoteDCsForLocalConsistencyLevel";
 
+  public static final String USE_CASSANDRA_MAPPING_MANAGER = "gora.cassandra.store.useCassandraMappingManager";
 }

http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/src/test/conf/gora-cassandra-mapping.xml
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/test/conf/gora-cassandra-mapping.xml b/gora-cassandra-cql/src/test/conf/gora-cassandra-mapping.xml
index 460063f..b039638 100644
--- a/gora-cassandra-cql/src/test/conf/gora-cassandra-mapping.xml
+++ b/gora-cassandra-cql/src/test/conf/gora-cassandra-mapping.xml
@@ -49,47 +49,49 @@
    at http://gora.apache.org/current/gora-cassandra.html
 -->
 
-<gora-otd>
-  <keyspace name="Employee" host="localhost:9160" placement_strategy="org.apache.cassandra.locator.SimpleStrategy"
-      replication_factor="1" cluster="Gora Cassandra Test Cluster">
-    <family name="p" gc_grace_seconds="5"/>
-     <family name="sc" type="super" />
-  </keyspace>
 
-  <keyspace name="WebPage" host="localhost:9160" placement_strategy="org.apache.cassandra.locator.SimpleStrategy"
-      replication_factor="1" cluster="Gora Cassandra Test Cluster">
-    <family name="p" gc_grace_seconds="5"/>
-    <family name="sc" type="super"/>
-  </keyspace>
+<gora-otd>
+    <keyspace name="EmployeeSpace" durableWrite="false">
+        <placementStrategy name="SimpleStrategy" replication_factor="1"/>
+    </keyspace>
 
-  <keyspace name="TokenDatum" host="localhost:9160" placement_strategy="org.apache.cassandra.locator.SimpleStrategy"
-      replication_factor="1" cluster="Gora Cassandra Test Cluster">
-    <family name="p" gc_grace_seconds="5"/>
-    <family name="sc" type="super"/>
-  </keyspace>
+    <keyspace name="WebPage" durableWrite="true">
+        <placementStrategy name="NetworkTopologyStrategy">
+            <datacenter name="dc1" replication_factor="1"/>
+            <datacenter name="dc2" replication_factor="1"/>
+        </placementStrategy>
+    </keyspace>
 
-  <class name="org.apache.gora.examples.generated.Employee" keyClass="java.lang.String"
keyspace="Employee">
-    <field name="name"  family="p" qualifier="info:nm" ttl="10"/>
-    <field name="dateOfBirth"  family="p" qualifier="info:db" ttl="10"/>
-    <field name="ssn"  family="p" qualifier="info:sn" ttl="10"/>
-    <field name="salary"  family="p" qualifier="info:sl" ttl="10"/>
-    <field name="boss" family="p" qualifier="info:bs" ttl="10"/>
-    <field name="webpage" family="p" qualifier="info:wp" ttl="10"/>
-  </class>
+    <class name="org.apache.gora.examples.generated.Employee1" keyClass="java.lang.String"
keyspace="EmployeeSpace"
+           table="Employee" compactStorage="true" id="31323131">
+        <field name="lname" column="name" type="text" ttl="10" static="true"/>
+        <field name="fname" column="name" type="text" ttl="10"/>
+        <field name="srilankan" column="srilankan" type="boolean" ttl="10"/>
+        <field name="age" column="srilankan" type="int" ttl="10"/>
+        <field name="id" column="srilankan" type="uuid" ttl="10"/>
+    </class>
 
-  <class name="org.apache.gora.examples.generated.WebPage" keyClass="java.lang.String"
keyspace="WebPage">
-    <field name="url" family="p" qualifier="c:u" ttl="10"/>
-    <field name="content" family="p" qualifier="p:cnt:c" ttl="10"/>
-    <field name="parsedContent" family="sc" qualifier="p:parsedContent" ttl="10"/>
-    <field name="outlinks" family="sc" qualifier="p:outlinks" ttl="10"/>
-    <field name="headers" family="sc" qualifier="p:headers" ttl="10"/>
-    <field name="metadata" family="p" qualifier="c:mt" ttl="10"/>
-    <field name="byteData" family="sc" qualifier="p:byteData" ttl="10"/>
-    <field name="stringData" family="sc" qualifier="p:stringData" ttl="10"/>
-  </class>
+    <class name="org.apache.gora.examples.generated.Employee" keyClass="org.apache.gora.examples.generated.SensorKey"
keyspace="WebPage"
+           compactStorage="true" id="31323131">
+        <field name="lname" column="name" type="text" ttl="10" primarykey="true"/>
+        <field name="fname" column="name" type="text" ttl="10"/>
+        <field name="srilankan" column="srilankan" type="boolean" ttl="10"/>
+        <field name="age" column="srilankan" type="int" ttl="10"/>
+        <field name="id" column="srilankan" type="uuid" ttl="10"/>
+    </class>
 
-  <class name="org.apache.gora.examples.generated.TokenDatum" keyClass="java.lang.String"
keyspace="TokenDatum">
-    <field name="count"  family="p" qualifier="common:count" ttl="10"/>
-  </class>
+    <cassandraKey name="org.apache.gora.examples.generated.SensorKey">
+        <partitionKey>
+            <field composite="true">
+                <column name="id" type=""/>
+                <column name="name" type=""/>
+            </field>
+            <field name="sensorId" type="UTF8Type"/>
+            <field name="year" type="IntegerType"/>
+        </partitionKey>
+        <clusterKey>
+            <field name="date" type="LongType" order="desc"/>
+        </clusterKey>
+    </cassandraKey>
 
-</gora-otd>
+</gora-otd>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/GoraCassandraTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/GoraCassandraTestDriver.java
b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/GoraCassandraTestDriver.java
index b36aca4..ccb9b97 100644
--- a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/GoraCassandraTestDriver.java
+++ b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/GoraCassandraTestDriver.java
@@ -40,8 +40,7 @@ import org.slf4j.LoggerFactory;
  * This driver is the base for all test cases that require an embedded Cassandra
  * server. In this case we draw on Hector's @see EmbeddedServerHelper.
  * It starts (setUp) and stops (tearDown) embedded Cassandra server.
- * 
- * @author lewismc
+ *
  */
 
 public class GoraCassandraTestDriver extends GoraTestDriver {

http://git-wip-us.apache.org/repos/asf/gora/blob/a7b99f83/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStore.java
----------------------------------------------------------------------
diff --git a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStore.java
b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStore.java
index 9518891..44c54b9 100644
--- a/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStore.java
+++ b/gora-cassandra-cql/src/test/java/org/apache/gora/cassandra/store/TestCassandraStore.java
@@ -23,18 +23,14 @@
  */
 package org.apache.gora.cassandra.store;
 
-import java.io.IOException;
-
 import org.apache.gora.cassandra.GoraCassandraTestDriver;
-import org.apache.gora.examples.generated.Employee;
-import org.apache.gora.examples.generated.WebPage;
-import org.apache.gora.store.DataStore;
-import org.apache.gora.store.DataStoreFactory;
 import org.apache.gora.store.DataStoreTestBase;
 import org.apache.hadoop.conf.Configuration;
 import org.junit.Before;
 import org.junit.Ignore;
 
+import java.io.IOException;
+
 /**
  * Test for CassandraStore.
  */
@@ -42,6 +38,7 @@ public class TestCassandraStore extends DataStoreTestBase{
 
   private Configuration conf;
 
+
   static {
     setTestDriver(new GoraCassandraTestDriver());
   }


Mime
View raw message