Beispiel #1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="CqlConnection" /> class.
        /// </summary>
        /// <param name="config"> The config. </param>
        public CqlConnection(ClusterConfig config)
        {
            //add the config to the list, or get an existing instance with the same parameters
            ClusterConfig c = Configs.GetOrAdd(config.ToString(), config);

            //get the cluster based on the instance
            Cluster cluster = Clusters.GetOrAdd(c, conf => new Cluster(conf));

            //set the connection provider to the found cluster
            _cluster = cluster;
        }
Beispiel #2
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="CqlConnection" /> class.
        /// </summary>
        /// <param name="connectionString"> The connection string. </param>
        public CqlConnection(string connectionString)
        {
            //get the cluster config, or add one if none exists
            ClusterConfig config = Configs.GetOrAdd(connectionString, connString =>
                                                                          {
                                                                              //create new config
                                                                              var cc = new ClusterConfig(connString);

                                                                              //get if a similar already exists, or add it otherwise
                                                                              return Configs.GetOrAdd(cc.ToString(), cc);
                                                                          });

            //fetch the cluster, or create one
            Cluster cluster = Clusters.GetOrAdd(config, conf => new Cluster(conf));

            //set the connection provider to the cluster
            _cluster = cluster;
        }