public IKeyspace Create( ICassandraClient client, string keyspaceName, IDictionary<string, Dictionary<string, string>> keyspaceDesc, ConsistencyLevel consistencyLevel, FailoverPolicy failoverPolicy, IKeyedObjectPool<Endpoint, ICassandraClient> pool) { switch (client.Version) { case CassandraVersion.v0_6_0_beta_3: throw new NotImplementedException("Version 0.6.0 not implimented yet"); default: case CassandraVersion.v0_5_1: return new _051.Keyspace( client, keyspaceName, keyspaceDesc, consistencyLevel, failoverPolicy, pool, monitor ); } }
/// <summary> /// Creates a unique map name for the keyspace and its consistency level /// </summary> /// <param name="keyspaceName"></param> /// <param name="consistencyLevel"></param> /// <param name="failoverPolicy"></param> /// <returns></returns> string BuildKeyspaceMapName(string keyspaceName, ConsistencyLevel consistencyLevel, FailoverPolicy failoverPolicy) { return string.Format("{0}[{1},{2}]", keyspaceName, consistencyLevel, failoverPolicy); }
public IKeyspace GetKeyspace(string keyspaceName, ConsistencyLevel consistencyLevel, FailoverPolicy failoverPolicy) { var key = BuildKeyspaceMapName(keyspaceName, consistencyLevel, failoverPolicy); IKeyspace keyspace; if (keyspaceMap.ContainsKey(key)) keyspace = keyspaceMap[key]; else { if (Keyspaces.Contains(keyspaceName)) { IDictionary<string, Dictionary<string, string>> keyspaceDesc = null; if(Version == CassandraVersion.v0_5_1) keyspaceDesc = cassandra051.describe_keyspace(keyspaceName); else if(Version == CassandraVersion.v0_6_0_beta_3) keyspaceDesc = cassandra060.describe_keyspace(keyspaceName); keyspace = keyspaceFactory.Create(this, keyspaceName, keyspaceDesc, consistencyLevel, failoverPolicy, pool); IKeyspace tmp = null; if (!keyspaceMap.ContainsKey(key)) { keyspaceMap.Add(key, keyspace); tmp = keyspaceMap[key]; } if (tmp != null) // There was another put that got here before we did. keyspace = tmp; } else throw new Exception("Requested key space not exist, keyspaceName=" + keyspaceName); } return keyspace; }