Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added stubbed out, some impls new structure
- Loading branch information
zznate
committed
Jan 27, 2011
1 parent
41c0bd7
commit f0ec1fd
Showing
10 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.idea | ||
.DS_Store | ||
releases | ||
target | ||
tmp | ||
.classpath | ||
.project | ||
.settings | ||
out | ||
*.ipr | ||
*.iws | ||
*.iml | ||
.springBeans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/datastax/tutorial/GetIndexedSlicesForCityState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/datastax/tutorial/GetRangeSlicesForAreaCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/datastax/tutorial/GetRangeSlicesForStateCity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/datastax/tutorial/GetSliceForNpanxx.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/datastax/tutorial/MultigetSliceForNpanxx.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |