Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added stubbed out, some impls new structure

  • Loading branch information...
commit f0ec1fdb20c49252536246df93b7c84a03181e60 1 parent 41c0bd7
zznate authored
View
13 .gitignore
@@ -0,0 +1,13 @@
+.idea
+.DS_Store
+releases
+target
+tmp
+.classpath
+.project
+.settings
+out
+*.ipr
+*.iws
+*.iml
+.springBeans
View
41 src/main/java/com/datastax/tutorial/GetCityForNpanxx.java
@@ -0,0 +1,41 @@
+package com.datastax.tutorial;
+
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.HColumn;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.query.ColumnQuery;
+import me.prettyprint.hector.api.query.QueryResult;
+
+/**
+ * Get a single column, 'City', for a specific NPA/NXX combination.
+ * Uses @{@link HFactory} to construct a simple {@link ColumnQuery}
+ *
+ * Thrift API: http://wiki.apache.org/cassandra/API#get
+ *
+ * To run this example from maven:
+ * mvn -e exec:java -Dexec.args="get" -Dexec.mainClass="com.datastax.tutorial.TutorialRunner"
+ *
+ * NOTE: in the raw Thrift API, the get method throws a NotFoundException
+ * on a miss. Hector encapsulates this, instead returning NULL as 'get'
+ * is the *only* API method that will throw an exception in non-error conditions.
+ *
+ */
+public class GetCityForNpanxx extends TutorialCommand {
+
+
+ public GetCityForNpanxx(Keyspace keyspace) {
+ super(keyspace);
+ }
+
+ @Override
+ public QueryResult<HColumn<String,String>> execute() {
+ ColumnQuery<String, String, String> columnQuery = HFactory.createStringColumnQuery(keyspace);
+ columnQuery.setColumnFamily("Npanxx");
+ columnQuery.setKey("512204");
+ columnQuery.setName("city");
+ QueryResult<HColumn<String, String>> result = columnQuery.execute();
+ return result;
+ }
+
+
+}
View
18 src/main/java/com/datastax/tutorial/GetIndexedSlicesForCityState.java
@@ -0,0 +1,18 @@
+package com.datastax.tutorial;
+
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.query.QueryResult;
+
+public class GetIndexedSlicesForCityState extends TutorialCommand {
+
+ public GetIndexedSlicesForCityState(Keyspace keyspace) {
+ super(keyspace);
+ }
+
+ @Override
+ public QueryResult<?> execute() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
View
18 src/main/java/com/datastax/tutorial/GetRangeSlicesForAreaCode.java
@@ -0,0 +1,18 @@
+package com.datastax.tutorial;
+
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.query.QueryResult;
+
+public class GetRangeSlicesForAreaCode extends TutorialCommand {
+
+ public GetRangeSlicesForAreaCode(Keyspace keyspace) {
+ super(keyspace);
+ }
+
+ @Override
+ public QueryResult<?> execute() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
View
18 src/main/java/com/datastax/tutorial/GetRangeSlicesForStateCity.java
@@ -0,0 +1,18 @@
+package com.datastax.tutorial;
+
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.query.QueryResult;
+
+public class GetRangeSlicesForStateCity extends TutorialCommand {
+
+ public GetRangeSlicesForStateCity(Keyspace keyspace) {
+ super(keyspace);
+ }
+
+ @Override
+ public QueryResult<?> execute() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
View
42 src/main/java/com/datastax/tutorial/GetSliceForNpanxx.java
@@ -0,0 +1,42 @@
+package com.datastax.tutorial;
+
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.ColumnSlice;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.query.QueryResult;
+import me.prettyprint.hector.api.query.SliceQuery;
+
+/**
+ * Get all the columns for a single Npanxx row.
+ * Shows the construction of a {@link SliceQuery} with the
+ * {@link StringSerializer} defined in the parent class.
+ *
+ * Thrift API: http://wiki.apache.org/cassandra/API#get_slice
+ *
+ * To run this example from maven:
+ * mvn -e exec:java -Dexec.args="get_slice" -Dexec.mainClass="com.datastax.tutorial.TutorialRunner"
+ *
+ */
+public class GetSliceForNpanxx extends TutorialCommand {
+
+ public GetSliceForNpanxx(Keyspace keyspace) {
+ super(keyspace);
+ }
+
+ @Override
+ public QueryResult<?> execute() {
+ SliceQuery<String, String, String> sliceQuery =
+ HFactory.createSliceQuery(keyspace, stringSerializer, stringSerializer, stringSerializer);
+ sliceQuery.setColumnFamily("Npanxx");
+ sliceQuery.setKey("512202");
+ // We only ever have these four columns on Npanxx
+ sliceQuery.setColumnNames("city","state","lat","lng");
+ // The following would do the exact same as the above
+ // accept here we say get the first 4 columns according to comparator order
+ // sliceQuery.setRange("", "", false, 4);
+
+ QueryResult<ColumnSlice<String, String>> result = sliceQuery.execute();
+ return result;
+ }
+
+}
View
18 src/main/java/com/datastax/tutorial/MultigetSliceForNpanxx.java
@@ -0,0 +1,18 @@
+package com.datastax.tutorial;
+
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.query.QueryResult;
+
+public class MultigetSliceForNpanxx extends TutorialCommand {
+
+ public MultigetSliceForNpanxx(Keyspace keyspace) {
+ super(keyspace);
+ }
+
+ @Override
+ public QueryResult<?> execute() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
View
27 src/main/java/com/datastax/tutorial/TutorialCommand.java
@@ -0,0 +1,27 @@
+package com.datastax.tutorial;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import me.prettyprint.cassandra.serializers.IntegerSerializer;
+import me.prettyprint.cassandra.serializers.StringSerializer;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.query.QueryResult;
+
+public abstract class TutorialCommand {
+
+ protected Logger log = LoggerFactory.getLogger(TutorialCommand.class);
+
+ protected Keyspace keyspace;
+
+ public TutorialCommand(Keyspace keyspace) {
+ this.keyspace = keyspace;
+ }
+
+ public abstract QueryResult<?> execute();
+
+
+ static StringSerializer stringSerializer = StringSerializer.get();
+ static IntegerSerializer integerSerializer = IntegerSerializer.get();
+
+}
View
47 src/main/java/com/datastax/tutorial/TutorialRunner.java
@@ -0,0 +1,47 @@
+package com.datastax.tutorial;
+
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.query.QueryResult;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TutorialRunner {
+ private static Logger log = LoggerFactory.getLogger(TutorialRunner.class);
+
+ static Cluster tutorialCluster;
+ static Keyspace tutorialKeyspace;
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ tutorialCluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");
+
+ tutorialKeyspace = HFactory.createKeyspace("Tutorial", tutorialCluster);
+
+ TutorialCommand command = loadCommand(args[0]);
+
+ QueryResult<?> result = command.execute();
+
+ log.info("Result executed in: {} microseconds against host: {}",
+ result.getExecutionTimeMicro(), result.getHostUsed().getName());
+
+ log.info("Details of result:\n{}", result.get());
+
+ tutorialCluster.getConnectionManager().shutdown();
+ }
+
+
+ private static TutorialCommand loadCommand(String cmd) {
+ if ( cmd.equalsIgnoreCase("get")) {
+ return new GetCityForNpanxx(tutorialKeyspace);
+ } else if ( cmd.equalsIgnoreCase("get_slice")) {
+ return new GetSliceForNpanxx(tutorialKeyspace);
+ }
+ return null;
+ }
+
+}
View
6 src/main/resources/log4j.properties
@@ -0,0 +1,6 @@
+log4j.rootLogger=WARN,stdout
+
+# stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
+log4j.category.com.datastax=INFO
Please sign in to comment.
Something went wrong with that request. Please try again.