Permalink
Browse files

moved static factory IntraOp methods up to Operations class

  • Loading branch information...
1 parent f7ab375 commit 1127ad0c93678be7e959421eb42a6e7c168e7f03 @zznate committed Jan 15, 2013
@@ -112,13 +112,13 @@ public static void main(String[] args) throws Exception {
IntraClient i = new IntraClient();
i.payload="json";
IntraReq req = new IntraReq();
- req.add( IntraOp.setKeyspaceOp("myks") );
- req.add( IntraOp.createKsOp("myks", 1));
- req.add( IntraOp.createCfOp("mycf"));
- req.add( IntraOp.setColumnFamilyOp("mycf") );
- req.add( IntraOp.setAutotimestampOp() );
- req.add( IntraOp.setOp("5", "6", "7"));
- req.add( IntraOp.sliceOp("5", "1", "9", 4));
+ req.add( Operations.setKeyspaceOp("myks") );
+ req.add( Operations.createKsOp("myks", 1));
+ req.add( Operations.createCfOp("mycf"));
+ req.add( Operations.setColumnFamilyOp("mycf") );
+ req.add( Operations.setAutotimestampOp() );
+ req.add( Operations.setOp("5", "6", "7"));
+ req.add( Operations.sliceOp("5", "1", "9", 4));
//req.add( IntraOp.setOp("bob", new Object [] { 4, "stuff" }, 10) );
//req.add( IntraOp.getOp("bob", new Object [] { 4, "stuff" }) );
//req.add( IntraOp.setKeyspaceOp("otherks") );
@@ -49,224 +49,14 @@ public IntraOp set(String key, Object value){
return this;
}
-
public Map<String, Object> getOp() {
return op;
}
-
- public static IntraOp setKeyspaceOp(String keyspace){
- checkForBlankStr(keyspace, "keyspace", Type.SETKEYSPACE);
- IntraOp i = new IntraOp(Type.SETKEYSPACE);
- i.set("keyspace", keyspace);
- return i;
- }
-
- public static IntraOp setColumnFamilyOp(String columnFamily){
- checkForBlankStr(columnFamily, "columnFamily",Type.SETCOLUMNFAMILY);
- IntraOp i = new IntraOp(Type.SETCOLUMNFAMILY);
- i.set("columnfamily", columnFamily);
- return i;
- }
-
- public static IntraOp setAutotimestampOp(){
- IntraOp i = new IntraOp(Type.AUTOTIMESTAMP);
- return i;
- }
-
- public static IntraOp setOp(Object rowkey, Object columnName, Object columnValue){
- Preconditions.checkArgument(rowkey != null, "The rowkey cannot be null for {}", Type.SET);
- Preconditions.checkArgument(columnName != null, "The columnName cannot be null for {}", Type.SET);
- Preconditions.checkArgument(columnValue != null, "Cannot set a column to null for {}", Type.SET);
- IntraOp i = new IntraOp(Type.SET);
- i.set("rowkey", rowkey);
- i.set("name", columnName);
- i.set("value", columnValue);
- return i;
- }
-
- public static IntraOp batchSetOp(List<Map> rows){
- IntraOp i = new IntraOp(Type.BATCHSET);
- i.set("rows", rows);
- return i;
- }
- public static IntraOp getOp(Object rowkey, Object columnName){
- Preconditions.checkArgument(rowkey != null, "The rowkey cannot be null for {}", Type.GET);
- Preconditions.checkArgument(columnName != null, "The columnName cannot be null for {}", Type.GET);
- IntraOp i = new IntraOp(Type.GET);
- i.set("rowkey", rowkey);
- i.set("name", columnName);
- return i;
- }
-
- public static IntraOp getResRefOp(int reference, String wanted){
- Preconditions.checkArgument(reference >= 0);
- checkForBlankStr(wanted, "wanted", Type.GETREF);
- IntraOp i = new IntraOp(Type.GETREF);
- i.set("resultref", reference);
- i.set("wanted", wanted);
- return i;
- }
-
- public static IntraOp sliceOp( Object rowkey , Object start, Object end, int size){
- Preconditions.checkArgument(rowkey != null,"A row key is required for {}", Type.SLICE);
- Preconditions.checkArgument(size > 0, "A slice size must be positive integer for {}", Type.SLICE);
- IntraOp i = new IntraOp(Type.SLICE);
- i.set("rowkey", rowkey);
- i.set("start", start);
- i.set("end", end);
- i.set("size", size);
- return i;
- }
-
- public static IntraOp columnPredicateOp( Object rowkey, Object [] columnList){
- Preconditions.checkArgument(columnList != null, "You much provide a columnList array");
- IntraOp i = new IntraOp(Type.COLUMNPREDICATE);
- i.set("wantedcols", columnList);
- return i;
- }
-
- public static IntraOp forEachOp( int opRef, IntraOp action){
- Preconditions.checkArgument(action != null, "The IntraOp action cannot be null");
- IntraOp i = new IntraOp(Type.FOREACH);
- i.set("action", action);
- return i;
- }
-
- public static IntraOp createCfOp(String cfName){
- checkForBlankStr(cfName, "columnFamily name", Type.CREATECOLUMNFAMILY);
- IntraOp i = new IntraOp(Type.CREATECOLUMNFAMILY);
- i.set("name", cfName);
- return i;
- }
-
- public static IntraOp createKsOp(String ksname, int replication){
- checkForBlankStr(ksname, "keyspace name", Type.CREATEKEYSPACE);
- Preconditions.checkArgument(replication > 0,
- "A value for positive value for 'replication' is required for {}", Type.CREATEKEYSPACE);
- IntraOp i = new IntraOp(Type.CREATEKEYSPACE);
- i.set("name", ksname);
- i.set("replication", replication);
- return i;
- }
-
- public static IntraOp consistencyOp(String name){
- // Force an IllegalArgumentException
- ConsistencyLevel.valueOf(name);
- IntraOp i = new IntraOp(Type.CONSISTENCY);
- i.set("level", name);
- return i;
- }
-
- public static IntraOp listKeyspacesOp(){
- IntraOp i = new IntraOp(Type.LISTKEYSPACES);
- return i;
- }
-
- public static IntraOp listColumnFamilyOp(String keyspace){
- checkForBlankStr(keyspace, "Keyspace name", Type.LISTCOLUMNFAMILY);
- IntraOp i = new IntraOp(Type.LISTCOLUMNFAMILY);
- i.set("keyspace", keyspace);
- return i;
- }
-
- public static IntraOp assumeOp(String keyspace,String columnfamily,String type, String clazz){
- IntraOp i = new IntraOp(Type.ASSUME);
- i.set("keyspace", keyspace);
- i.set("columnfamily", columnfamily);
- i.set("type", type); //should be column rowkey value
- i.set("clazz", clazz );
- return i;
- }
-
- public static IntraOp createProcessorOp(String name, String spec, String value){
- IntraOp i = new IntraOp(Type.CREATEPROCESSOR);
- i.set("name",name);
- i.set("spec", spec);
- i.set("value", value);
- return i;
- }
-
- public static IntraOp processOp(String processorName, Map params, int inputId){
- IntraOp i = new IntraOp(Type.PROCESS);
- i.set("processorname", processorName);
- i.set("params", params);
- i.set("input", inputId);
- return i;
- }
-
- public static IntraOp dropKeyspaceOp(String ksname){
- IntraOp i = new IntraOp(Type.DROPKEYSPACE);
- i.set("keyspace", ksname);
- return i;
- }
-
- public static IntraOp createFilterOp(String name, String spec, String value) {
- IntraOp i = new IntraOp(Type.CREATEFILTER);
- i.set("name", name);
- i.set("spec", spec);
- i.set("value", value);
- return i;
- }
-
- public static IntraOp filterModeOp(String name, boolean on) {
- IntraOp i = new IntraOp(Type.FILTERMODE);
- i.set("name", name);
- i.set("on", on);
- return i;
- }
-
- public static IntraOp cqlQuery(String query, String version){
- IntraOp i = new IntraOp(Type.CQLQUERY);
- i.set("query", query);
- i.set("version", version );
- return i;
- }
-
- public static IntraOp clear(int resultId){
- IntraOp i = new IntraOp(Type.CLEAR);
- i.set("id", resultId);
- return i;
- }
-
- public static IntraOp createMultiProcess(String name, String spec, String value){
- IntraOp i = new IntraOp(Type.CREATEMULTIPROCESS);
- i.set("name", name);
- i.set("spec", spec);
- i.set("value", value);
- return i;
- }
-
- public static IntraOp multiProcess(String processorName, Map params){
- IntraOp i = new IntraOp(Type.MULTIPROCESS);
- i.set("name", processorName);
- i.set("params", params);
- return i;
- }
-
public Type getType() {
return type;
}
-
- public static IntraOp saveState(){
- IntraOp i = new IntraOp(Type.STATE);
- i.set("mode", "save");
- return i;
- }
-
- public static IntraOp restoreState(int id){
- IntraOp i = new IntraOp(Type.STATE);
- i.set("mode", "get");
- i.set("id", id);
- return i;
- }
- private static void checkForBlankStr(String arg, String msg, Type type) {
- Preconditions.checkArgument(arg != null && arg.length() > 0,
- "A non-blank '{}' is required for {}", new Object[]{msg,type});
- }
-
-
public enum Type {
LISTCOLUMNFAMILY {
Oops, something went wrong.

0 comments on commit 1127ad0

Please sign in to comment.