示例#1
0
        private CqlRowSet ProcessRowset(IOutput outp)
        {
            bool ok = false;

            try
            {
                if (outp is OutputError)
                {
                    var ex = (outp as OutputError).CreateException();
                    _logger.Error(ex);
                    throw ex;
                }
                else if (outp is OutputVoid)
                {
                    return(new CqlRowSet(outp as OutputVoid, this));
                }
                else if (outp is OutputSchemaChange)
                {
                    return(new CqlRowSet(outp as OutputSchemaChange, this));
                }
                else if (outp is OutputSetKeyspace)
                {
                    SetKeyspace(CqlQueryTools.CqlIdentifier((outp as OutputSetKeyspace).Value));
                    return(new CqlRowSet(outp as OutputSetKeyspace, this));
                }
                else if (outp is OutputRows)
                {
                    ok = true;
                    return(new CqlRowSet(outp as OutputRows, this, true));
                }
                else
                {
                    var ex = new DriverInternalError("Unexpected output kind");
                    _logger.Error(ex);
                    throw ex;
                }
            }
            finally
            {
                if (!ok)
                {
                    outp.Dispose();
                }
            }
        }
示例#2
0
        /// <summary>
        ///  Returns a CQL query representing this keyspace. This method returns a single
        ///  'CREATE KEYSPACE' query with the options corresponding to this name
        ///  definition.
        /// </summary>
        ///
        /// <returns>the 'CREATE KEYSPACE' query corresponding to this name.
        ///  <see>#ExportAsString</see></returns>
        public string AsCqlQuery()
        {
            var sb = new StringBuilder();

            sb.Append("CREATE KEYSPACE ").Append(CqlQueryTools.CqlIdentifier(Name)).Append(" WITH ");
            sb.Append("REPLICATION = { 'class' : '").Append(Replication["class"]).Append("'");
            foreach (var rep in Replication)
            {
                if (rep.Key == "class")
                {
                    continue;
                }
                sb.Append(", '").Append(rep.Key).Append("': '").Append(rep.Value).Append("'");
            }
            sb.Append(" } AND DURABLE_WRITES = ").Append(DurableWrites);
            sb.Append(";");
            return(sb.ToString());
        }
示例#3
0
        CassandraConnection AllocateConnection(IPAddress endPoint, out Exception outExc)
        {
            CassandraConnection nconn = null;

            outExc = null;

            try
            {
                nconn = new CassandraConnection(this, endPoint, _protocolOptions, _socketOptions, _clientOptions, _authProvider);

                var options = nconn.ExecuteOptions();

                if (!string.IsNullOrEmpty(_keyspace))
                {
                    var keyspaceId = CqlQueryTools.CqlIdentifier(_keyspace);
                    nconn.SetKeyspace(keyspaceId);
                }
            }
            catch (Exception ex)
            {
                if (nconn != null)
                {
                    nconn.Dispose();
                }

                if (CassandraConnection.IsStreamRelatedException(ex))
                {
                    HostIsDown(endPoint);
                    outExc = ex;
                    return(null);
                }
                else
                {
                    throw ex;
                }
            }

            _logger.Info("Allocated new connection");

            return(nconn);
        }
示例#4
0
 public static string GetDropKeyspaceCQL(string keyspace)
 {
     return(string.Format(
                @"DROP KEYSPACE {0}"
                , CqlQueryTools.CqlIdentifier(keyspace)));
 }
示例#5
0
 public static string GetUseKeyspaceCQL(string keyspace)
 {
     return(string.Format(
                @"USE {0}"
                , CqlQueryTools.CqlIdentifier(keyspace)));
 }