Beispiel #1
0
        public object Clone()
        {
            var conn = new CqlConnection(_connectionStringBuilder.ConnectionString);

            if (State != System.Data.ConnectionState.Closed && State != System.Data.ConnectionState.Broken)
            {
                conn.Open();
            }
            return(conn);
        }
Beispiel #2
0
 protected override void TestFixtureSetUp()
 {
     base.TestFixtureSetUp();
     var cb = new CassandraConnectionStringBuilder
     {
         ContactPoints = new[] { TestCluster.InitialContactPoint }, 
         Port = 9042
     };
     _connection = new CqlConnection(cb.ToString());
 }
        public void TestCqlCommand()
        {
            var target = new CqlCommand();

            // test CreateDbParameter()
            var parameter = target.CreateParameter();
            Assert.IsNotNull(parameter);

            // test Parameters
            var parameterCollection = target.Parameters;
            Assert.IsNotNull(parameterCollection);
            Assert.AreEqual(parameterCollection, target.Parameters);

            // test Connection
            var connection = new CqlConnection("contact points=127.0.0.1;port=9042");
            Assert.IsNull(target.Connection);
            target.Connection = connection;
            Assert.AreEqual(connection, target.Connection);

            // test IsPrepared
            Assert.IsTrue(target.IsPrepared);

            // test CommandText
            var cqlQuery = "test query";
            Assert.IsNull(target.CommandText);
            target.CommandText = cqlQuery;
            Assert.AreEqual(cqlQuery, target.CommandText);

            // test CommandTimeout, it should always return -1
            var timeout = 1;
            Assert.AreEqual(-1, target.CommandTimeout);
            target.CommandTimeout = timeout;
            Assert.AreEqual(-1, target.CommandTimeout);

            // test CommandType, it should always return CommandType.Text
            var commandType = CommandType.TableDirect;
            Assert.AreEqual(CommandType.Text, target.CommandType);
            target.CommandType = commandType;
            Assert.AreEqual(CommandType.Text, target.CommandType);

            // test DesignTimeVisible, it should always return true
            Assert.IsTrue(target.DesignTimeVisible);
            target.DesignTimeVisible = false;
            Assert.IsTrue(target.DesignTimeVisible);

            // test UpdateRowSource, it should always return UpdateRowSource.FirstReturnedRecord
            var updateRowSource = UpdateRowSource.Both;
            Assert.AreEqual(UpdateRowSource.FirstReturnedRecord, target.UpdatedRowSource);
            target.UpdatedRowSource = updateRowSource;
            Assert.AreEqual(UpdateRowSource.FirstReturnedRecord, target.UpdatedRowSource);
        }
Beispiel #4
0
        public void CommandExecuteReaderUsesSyncExecute()
        {
            var connection = new CqlConnection();
            var sessionMock = new Mock<ISession>();
            var rowset = new RowSet();
            sessionMock
                .Setup(s => s.Execute(It.IsAny<string>(), It.IsAny<ConsistencyLevel>()))
                .Returns(rowset)
                .Verifiable();
            connection.ManagedConnection = sessionMock.Object;

            var cmd = (CqlCommand) connection.CreateCommand();
            cmd.CommandText = "INSERT INTO dummy_cf (a,b) VALUES (1,2)";
            var reader = cmd.ExecuteReader();
            reader.Dispose();
            sessionMock.Verify();
        }
 public object Clone()
 {
     var conn = new CqlConnection(_connectionStringBuilder.ConnectionString);
     if (State != System.Data.ConnectionState.Closed && State != System.Data.ConnectionState.Broken)
         conn.Open();
     return conn;
 }
 public CqlBatchTransaction(CqlConnection cqlConnection)
 {
     CqlConnection = cqlConnection;
 }
        /// <summary>
        /// Run the provided query against the source database to get the data to be moved.
        /// </summary>
        /// <param name="server">ip or name of the source database</param>
        /// <param name="keyspace">name of the keyspace to use for the source query</param>
        /// <param name="query">query to get source data</param>
        /// <param name="gotSourceData">Data retrieved</param>
        /// <param name="sourceData">indicator of if an error was thrown</param>
        private static void GetSourceData(string server, string keyspace, string query, TransferResultsInfo info, out bool gotSourceData, out List<dynamic> sourceData)
        {
            sourceData = new List<dynamic>();
            gotSourceData = true;

            try
            {
                CqlConnection srcConn = new CqlConnection("Contact Points=" + server, server);
                CqlCommand srcCmd = new CqlCommand();
                srcConn.Open();
                srcConn.ChangeDatabase(keyspace);
                srcCmd.Connection = srcConn;

                srcCmd.CommandType = CommandType.Text;
                srcCmd.CommandText = query;

                sourceData = srcCmd.ExecuteDynamics();

                info.SourceCount = sourceData.Count;

                //cleanup
                srcCmd.Connection.Close();
                srcCmd.Connection.Dispose();
                srcCmd.Dispose();
            }
            catch (Exception ex)
            {
                info.Message = "Error getting source data: \r\n" + ex.Message;
                gotSourceData = false;
            }
        }
        /// <summary>
        /// Insert retrived data into destination table
        /// </summary>
        /// <param name="server">ip or name of the destination database</param>
        /// <param name="keyspace">name of the keyspace to use for the insert</param>
        /// <param name="columnFamily">name of the column family for the insert</param>
        /// <param name="sourceData">data retrieved from the source</param>
        private static void InsertIntoDest(string server, string keyspace, string columnFamily, List<dynamic> sourceData, TransferResultsInfo info)
        {
            try
            {
                CqlConnection destConn = new CqlConnection("Contact Points=" + server, server);
                CqlCommand destCmd = new CqlCommand();

                destConn.Open();
                destConn.ChangeDatabase(keyspace);
                destCmd.Connection = destConn;

                destCmd.CommandText = "SELECT COUNT(*) FROM " + columnFamily;
                info.OriginalDestCount = Convert.ToInt32(destCmd.ExecuteScalar());

                destCmd.InsertDynamicList(sourceData, columnFamily);

                destCmd.CommandText = "SELECT COUNT(*) FROM " + columnFamily;
                info.AfterDestCount = Convert.ToInt32(destCmd.ExecuteScalar());

                //cleanup
                destCmd.Connection.Close();
                destCmd.Connection.Dispose();
                destCmd.Dispose();
            }
            catch (Exception ex)
            {
                info.Message = "Error writting to destination: \r\n" + ex.Message;
            }
        }
 public CqlBatchTransaction(CqlConnection cqlConnection)
 {
     CqlConnection = cqlConnection;
 }
Beispiel #10
0
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();

            var host = "127.0.0.1";
            if (TestUtils.UseRemoteCcm)
            {
                host = Options.Default.IP_PREFIX + "1";
            }
            var cb = new CassandraConnectionStringBuilder();
            cb.ContactPoints = new[] { host};
            cb.Port = 9042;
            _connection = new CqlConnection(cb.ToString());
        }