Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package me.prettyprint.hector.api.factory;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
A convenience class with bunch of factory static methods to help create a mutator, queries etc.

Author(s):
Ran
zznate
 
 public final class HFactory {
 
   private static final Map<StringClusterclusters = new HashMap<StringCluster>();
 
 
   public static Cluster getCluster(String clusterName) {
     return .get(clusterName);
   }
  

Parameters:
clusterName The cluster name. This is an identifying string for the cluster, e.g. "production" or "test" etc. Clusters will be created on demand per each unique clusterName key.
hostIp host:ip format string
Returns:
 
   public static Cluster getOrCreateCluster(String clusterNameString hostIp) {    
     return getOrCreateCluster(clusterNamenew CassandraHostConfigurator(hostIp));
   }
 
   public static Cluster getOrCreateCluster(String clusterName,
       CassandraHostConfigurator cassandraHostConfigurator) {
     synchronized () {
       Cluster c = .get(clusterName);
       if (c == null) {
         c = createCluster(clusterNamecassandraHostConfigurator);
        .put(clusterNamec);
      }
      return c;
    }
  }
  public static Cluster createCluster(String clusterNameCassandraHostConfigurator cassandraHostConfigurator) {    
    return .get(clusterName) == null ? new ThriftCluster(clusterNamecassandraHostConfigurator) : .get(clusterName);
  }
  public static Cluster createCluster(String clusterNameCassandraHostConfigurator cassandraHostConfiguratorMap<StringStringcredentials) {
    return .get(clusterName) == null ? new ThriftCluster(clusterNamecassandraHostConfiguratorcredentials) : .get(clusterName);    
  }

  
Creates a Keyspace with the default consistency level policy.

Parameters:
keyspace
cluster
Returns:
  public static Keyspace createKeyspace(String keyspaceCluster cluster) {
    return createKeyspace(keyspacecluster,
  }
  public static Keyspace createKeyspace(String keyspaceCluster cluster,
      ConsistencyLevelPolicy consistencyLevelPolicy) {
    return createKeyspace(keyspacecluster,
        consistencyLevelPolicy.);
  }
  public static Keyspace createKeyspace(String keyspaceCluster cluster,
      ConsistencyLevelPolicy consistencyLevelPolicyFailoverPolicy failoverPolicy) {
    return new ExecutingKeyspace(keyspacecluster.getConnectionManager(), consistencyLevelPolicyfailoverPolicycluster.getCredentials());
  }
  public static Keyspace createKeyspace(String keyspaceCluster cluster,
      ConsistencyLevelPolicy consistencyLevelPolicyFailoverPolicy failoverPolicy,
      Map<StringStringcredentials) {
    return new ExecutingKeyspace(keyspacecluster.getConnectionManager(), consistencyLevelPolicyfailoverPolicycredentials);
  }
  }
  public static <K,N,V> Mutator<K> createMutator(Keyspace keyspaceSerializer<K> keySerializer) {
    return new MutatorImpl<K>(keyspacekeySerializer);
  }
  public static <K,N,V> ColumnQuery<K,N,V> createColumnQuery(Keyspace keyspaceSerializer<K> keySerializer,
      Serializer<N> nameSerializerSerializer<V> valueSerializer) {
    return new ThriftColumnQuery<K,N,V>(keyspacekeySerializernameSerializervalueSerializer);
  }
  public static <K, N> CountQuery<K, N> createCountQuery(Keyspace keyspace,
      Serializer<K> keySerializerSerializer<N> nameSerializer) {
    return new ThriftCountQuery<K, N>(keyspacekeySerializernameSerializer);
  }
  public static <K,SN> SuperCountQuery<K,SN> createSuperCountQuery(Keyspace keyspace,
      Serializer<K> keySerializerSerializer<SN> superNameSerializer) {
    return new ThriftSuperCountQuery<K,SN>(keyspacekeySerializersuperNameSerializer);
  }
  public static <K,SN,N> SubCountQuery<K,SN,N> createSubCountQuery(Keyspace keyspace,
      Serializer<K> keySerializerSerializer<SN> superNameSerializerSerializer<N> nameSerializer) {
    return new ThriftSubCountQuery<K,SN,N>(keyspacekeySerializersuperNameSerializernameSerializer);
  }
  public static ColumnQuery<StringStringStringcreateStringColumnQuery(Keyspace keyspace) {
    StringSerializer se = StringSerializer.get();
    return createColumnQuery(keyspacesesese);
  }
  public static <K,SN,N,V> SuperColumnQuery<K,SN,N,V> createSuperColumnQuery(Keyspace keyspace,
      Serializer<K> keySerializerSerializer<SN> sNameSerializerSerializer<N> nameSerializerSerializer<V> valueSerializer) {
    return new ThriftSuperColumnQuery<K,SN, N, V>(keyspacekeySerializersNameSerializernameSerializervalueSerializer);
  }
  public static <K,N,V> MultigetSliceQuery<K,N,V> createMultigetSliceQuery(
      Keyspace keyspaceSerializer<K> keySerializerSerializer<N> nameSerializerSerializer<V> valueSerializer) {
    return new ThriftMultigetSliceQuery<K,N,V>(keyspacekeySerializernameSerializervalueSerializer);
  }
  public static <K, SN, N, V> SubColumnQuery<K, SN, N, V> createSubColumnQuery(Keyspace keyspace,
      Serializer<K> keySerializerSerializer<SN> sNameSerializerSerializer<N> nameSerializer,
      Serializer<V> valueSerializer) {
    return new ThriftSubColumnQuery<K, SN, N, V>(keyspacekeySerializersNameSerializernameSerializer,
        valueSerializer);
  }
  public static <K,SN,N,V> MultigetSuperSliceQuery<K,SN,N,V> createMultigetSuperSliceQuery(
      Keyspace keyspaceSerializer<K> keySerializerSerializer<SN> sNameSerializerSerializer<N> nameSerializerSerializer<V> valueSerializer) {
    return new ThriftMultigetSuperSliceQuery<K,SN,N,V>(keyspacekeySerializersNameSerializernameSerializervalueSerializer);
  }
  public static <K,SN,N,V> MultigetSubSliceQuery<K,SN,N,V> createMultigetSubSliceQuery(
      Keyspace keyspaceSerializer<K> keySerializerSerializer<SN> sNameSerializerSerializer<N> nameSerializerSerializer<V> valueSerializer) {
    return new ThriftMultigetSubSliceQuery<K,SN,N,V>(keyspacekeySerializersNameSerializernameSerializervalueSerializer);
  }
  public static <K,N,V> RangeSlicesQuery<K,N,V> createRangeSlicesQuery(
      Keyspace keyspaceSerializer<K> keySerializerSerializer<N> nameSerializerSerializer<V> valueSerializer) {
    return new ThriftRangeSlicesQuery<K,N,V>(keyspacekeySerializernameSerializervalueSerializer);
  }
  public static <K,SN,N,V> RangeSuperSlicesQuery<K,SN,N,V> createRangeSuperSlicesQuery(
      Keyspace keyspaceSerializer<K> keySerializerSerializer<SN> sNameSerializerSerializer<N> nameSerializer,
      Serializer<V> valueSerializer) {
    return new ThriftRangeSuperSlicesQuery<K,SN,N,V>(keyspacekeySerializersNameSerializernameSerializervalueSerializer);
  }
  public static <K,N,V> IndexedSlicesQuery<K, N, V> createIndexedSlicesQuery(
      Keyspace keyspaceSerializer<K> keySerializerSerializer<N> nameSerializer,
      Serializer<V> valueSerializer) {
    return new IndexedSlicesQuery<K, N, V>(keyspacekeySerializernameSerializervalueSerializer);
  }
  public static <K,SN,N,V> RangeSubSlicesQuery<K,SN,N,V> createRangeSubSlicesQuery(
      Keyspace keyspaceSerializer<K> keySerializerSerializer<SN> sNameSerializerSerializer<N> nameSerializer,
      Serializer<V> valueSerializer) {
    return new ThriftRangeSubSlicesQuery<K,SN,N,V>(keyspacekeySerializersNameSerializernameSerializervalueSerializer);
  }
  public static <K,N,V> SliceQuery<K,N,V> createSliceQuery(
      Keyspace keyspaceSerializer<K> keySerializerSerializer<N> nameSerializerSerializer<V> valueSerializer) {
    return new ThriftSliceQuery<K,N,V>(keyspacekeySerializernameSerializervalueSerializer);
  }
  public static <K,SN,N,V> SubSliceQuery<K,SN,N,V> createSubSliceQuery(
      Keyspace keyspaceSerializer<K> keySerializerSerializer<SN> sNameSerializerSerializer<N> nameSerializer,
      Serializer<V> valueSerializer) {
    return new ThriftSubSliceQuery<K,SN,N,V>(keyspacekeySerializersNameSerializernameSerializervalueSerializer);
  }
  public static <K,SN,N,V> SuperSliceQuery<K,SN,N,V> createSuperSliceQuery(
      Keyspace keyspaceSerializer<K> keySerializerSerializer<SN> sNameSerializerSerializer<N> nameSerializer,
      Serializer<V> valueSerializer) {
    return new ThriftSuperSliceQuery<K,SN,N,V>(keyspacekeySerializersNameSerializernameSerializervalueSerializer);
  }

  
createSuperColumn accepts a variable number of column arguments

Parameters:
name supercolumn name
columns
superNameSerializer
nameSerializer
valueSerializer
Returns:
  public static <SN,N,V> HSuperColumn<SN, N, V> createSuperColumn(SN nameList<HColumn<N,V>> columns,
      Serializer<SN> superNameSerializerSerializer<N> nameSerializerSerializer<V> valueSerializer) {
    return new HSuperColumnImpl<SN, N, V>(namecolumnscreateClock(), superNameSerializer,
        nameSerializervalueSerializer);
  }
  public static <SN,N,V> HSuperColumn<SN,N,V> createSuperColumn(SN nameList<HColumn<N,V>> columns,
      long clockSerializer<SN> superNameSerializerSerializer<N> nameSerializer,
      Serializer<V> valueSerializer) {
    return new HSuperColumnImpl<SN, N, V>(namecolumnsclocksuperNameSerializernameSerializer,
        valueSerializer);
  }
  public static <N,V> HColumn<N,V> createColumn(N name, V valuelong clock,
      Serializer<N> nameSerializerSerializer<V> valueSerializer) {
    return new HColumnImpl<N, V>(namevalueclocknameSerializervalueSerializer);
  }

  
Creates a column with the clock of now.
  public static <N,V> HColumn<N, V> createColumn(N name, V value,
      Serializer<N> nameSerializerSerializer<V> valueSerializer) {
    return new HColumnImpl<N, V>(namevaluecreateClock(), nameSerializervalueSerializer);
  }

  
Convienience method for creating a column with a String name and String value
  public static HColumn<StringStringcreateStringColumn(String nameString value) {
    StringSerializer se = StringSerializer.get();
    return createColumn(namevaluesese);
  }

  
Creates a clock of now with the default clock resolution (micorosec) as defined in me.prettyprint.cassandra.service.CassandraHostConfigurator
  public static long createClock() {
  }
  public static KeyspaceDefinition createKeyspaceDefinition(String keyspace) {
    return new ThriftKsDef(keyspace);
  }
  public static KeyspaceDefinition createKeyspaceDefinition(String keyspaceNameString strategyClassint replicationFactor,
      List<ColumnFamilyDefinitioncfDefs) {
    return new ThriftKsDef(keyspaceNamestrategyClassreplicationFactorcfDefs);
  }
  public static ColumnFamilyDefinition createColumnFamilyDefinition(String keyspaceString cfName) {
    return new ThriftCfDef(keyspacecfName);
  }
  public static ColumnFamilyDefinition createColumnFamilyDefinition(String keyspaceString cfNameComparatorType comparatorType) {
    return new ThriftCfDef(keyspacecfNamecomparatorType);
  }
  public static ColumnFamilyDefinition createColumnFamilyDefinition(String keyspaceString cfNameComparatorType comparatorTypeList<ColumnDefinitioncolumnMetadata) {
    return new ThriftCfDef(keyspacecfNamecomparatorTypecolumnMetadata);
  }

  
Create a clock resolution based on clockResolutionName which has to match any of the constants defined at me.prettyprint.hector.api.ClockResolution

Parameters:
clockResolutionName type of clock resolution to create
Returns:
a ClockResolution
  public static ClockResolution createClockResolution(String clockResolutionName) {
      if (clockResolutionName.equals(.)) {
          return new SecondsClockResolution();
      } else if (clockResolutionName.equals(.)) {
          return new MillisecondsClockResolution();
      } else if (clockResolutionName.equals(.)) {
          return new MicrosecondsClockResolution();
      } else if (clockResolutionName.equals(.)) {
          return new MicrosecondsSyncClockResolution();
      }
      throw new RuntimeException(String.format("Unsupported clock resolution: %s"clockResolutionName));
  }
New to GrepCode? Check out our FAQ X