Exemple #1
0
 private Cql(string cql, object[] args, CqlQueryOptions queryOptions)
 {
     AutoPage     = true;
     Statement    = cql;
     Arguments    = args;
     QueryOptions = queryOptions;
 }
Exemple #2
0
 private Cql(string cql, object[] args, CqlQueryOptions queryOptions)
 {
     AutoPage = true;
     Statement = cql;
     Arguments = args;
     QueryOptions = queryOptions;
 }
Exemple #3
0
 public CqlBatch(MapperFactory mapperFactory, CqlGenerator cqlGenerator, BatchType type)
 {
     _mapperFactory = mapperFactory ?? throw new ArgumentNullException(nameof(mapperFactory));
     _cqlGenerator  = cqlGenerator ?? throw new ArgumentNullException(nameof(cqlGenerator));
     _statements    = new List <Cql>();
     BatchType      = type;
     Options        = new CqlQueryOptions();
 }
        public void Update <T>(T poco, CqlQueryOptions queryOptions = null)
        {
            // Get statement and bind values from POCO
            string             cql           = _cqlGenerator.GenerateUpdate <T>();
            Func <T, object[]> getBindValues = _mapperFactory.GetValueCollector <T>(cql, primaryKeyValuesLast: true);

            object[] values = getBindValues(poco);

            _statements.Add(Cql.New(cql, values, queryOptions ?? CqlQueryOptions.None));
        }
Exemple #5
0
        public Task InsertAsync <T>(T poco, CqlQueryOptions queryOptions = null)
        {
            // Get statement and bind values from POCO
            string             cql           = _cqlGenerator.GenerateInsert <T>();
            Func <T, object[]> getBindValues = _mapperFactory.GetValueCollector <T>(cql);

            object[] values = getBindValues(poco);

            return(ExecuteAsync(Cql.New(cql, values, queryOptions ?? CqlQueryOptions.None)));
        }
Exemple #6
0
        private void Insert <T>(bool ifNotExists, T poco, CqlQueryOptions queryOptions = null)
        {
            // Get statement and bind values from POCO
            string             cql           = _cqlGenerator.GenerateInsert <T>(ifNotExists);
            Func <T, object[]> getBindValues = _mapperFactory.GetValueCollector <T>(cql);

            object[] values = getBindValues(poco);

            _statements.Add(Cql.New(cql, values, queryOptions ?? CqlQueryOptions.None));
        }
Exemple #7
0
        /// <inheritdoc />
        public Task DeleteAsync <T>(T poco, CqlQueryOptions queryOptions = null)
        {
            // Get the statement and bind values from POCO
            string             cql           = _cqlGenerator.GenerateDelete <T>();
            Func <T, object[]> getBindValues = _mapperFactory.GetValueCollector <T>(cql, primaryKeyValuesOnly: true);

            object[] values = getBindValues(poco);

            return(ExecuteAsync(Cql.New(cql, values, queryOptions ?? CqlQueryOptions.None)));
        }
Exemple #8
0
        public Task <AppliedInfo <T> > InsertIfNotExistsAsync <T>(T poco, CqlQueryOptions queryOptions = null)
        {
            // Get statement and bind values from POCO
            var cql           = _cqlGenerator.GenerateInsert <T>(true);
            var getBindValues = _mapperFactory.GetValueCollector <T>(cql);
            var values        = getBindValues(poco);

            return(ExecuteAsyncAndAdapt(
                       Cql.New(cql, values, queryOptions ?? CqlQueryOptions.None),
                       (stmt, rs) => AppliedInfo <T> .FromRowSet(_mapperFactory, cql, rs)));
        }
Exemple #9
0
        private void Insert <T>(bool ifNotExists, bool insertNulls, T poco, CqlQueryOptions queryOptions = null, int?ttl = null)
        {
            var pocoData        = _mapperFactory.PocoDataFactory.GetPocoData <T>();
            var queryIdentifier = $"INSERT ID {pocoData.KeyspaceName}/{pocoData.TableName}";
            var getBindValues   = _mapperFactory.GetValueCollector <T>(queryIdentifier);
            //get values first to identify null values
            var values = getBindValues(poco);
            //generate INSERT query based on null values (if insertNulls set)
            var cql         = _cqlGenerator.GenerateInsert <T>(insertNulls, values, out var queryParameters, ifNotExists, ttl);
            var cqlInstance = Cql.New(cql, queryParameters, queryOptions ?? CqlQueryOptions.None);

            _statements.Add(cqlInstance);
        }
Exemple #10
0
        /// <inheritdoc />
        public Task InsertAsync <T>(T poco, bool insertNulls, int?ttl, CqlQueryOptions queryOptions = null)
        {
            var pocoData        = _mapperFactory.PocoDataFactory.GetPocoData <T>();
            var queryIdentifier = string.Format("INSERT ID {0}/{1}", pocoData.KeyspaceName, pocoData.TableName);
            var getBindValues   = _mapperFactory.GetValueCollector <T>(queryIdentifier);
            //get values first to identify null values
            var values = getBindValues(poco);

            object[] queryParameters;
            //generate INSERT query based on null values (if insertNulls set)
            var cql = _cqlGenerator.GenerateInsert <T>(insertNulls, values, out queryParameters, ttl: ttl);

            return(ExecuteAsync(Cql.New(cql, queryParameters, queryOptions ?? CqlQueryOptions.None)));
        }
Exemple #11
0
        private void Insert <T>(bool ifNotExists, bool insertNulls, T poco, CqlQueryOptions queryOptions = null)
        {
            var pocoData        = _mapperFactory.PocoDataFactory.GetPocoData <T>();
            var queryIdentifier = string.Format("INSERT ID {0}/{1}", pocoData.KeyspaceName, pocoData.TableName);
            var getBindValues   = _mapperFactory.GetValueCollector <T>(queryIdentifier);
            //get values first to identify null values
            var values = getBindValues(poco);

            //generate INSERT query based on null values (if insertNulls set)
            object[] queryParameters;
            var      cql = _cqlGenerator.GenerateInsert <T>(insertNulls, values, out queryParameters, ifNotExists);

            _statements.Add(Cql.New(cql, queryParameters, queryOptions ?? CqlQueryOptions.None));
        }
 public CqlBatch(MapperFactory mapperFactory, CqlGenerator cqlGenerator, BatchType type)
 {
     if (mapperFactory == null)
     {
         throw new ArgumentNullException("mapperFactory");
     }
     if (cqlGenerator == null)
     {
         throw new ArgumentNullException("cqlGenerator");
     }
     _mapperFactory = mapperFactory;
     _cqlGenerator  = cqlGenerator;
     _statements    = new List <Cql>();
     BatchType      = type;
     Options        = new CqlQueryOptions();
 }
Exemple #13
0
        /// <inheritdoc />
        public Task DeleteAsync <T>(T poco, string executionProfile, CqlQueryOptions queryOptions = null)
        {
            if (executionProfile == null)
            {
                throw new ArgumentNullException(nameof(executionProfile));
            }

            // Get the statement and bind values from POCO
            string             cql           = _cqlGenerator.GenerateDelete <T>();
            Func <T, object[]> getBindValues = _mapperFactory.GetValueCollector <T>(cql, primaryKeyValuesOnly: true);

            object[] values      = getBindValues(poco);
            var      cqlInstance = Cql.New(cql, values, queryOptions ?? CqlQueryOptions.None).WithExecutionProfile(executionProfile);

            return(ExecuteAsync(cqlInstance));
        }
Exemple #14
0
 /// <inheritdoc />
 public AppliedInfo <T> InsertIfNotExists <T>(T poco, CqlQueryOptions queryOptions = null)
 {
     return(InsertIfNotExists(poco, true, queryOptions));
 }
Exemple #15
0
 /// <inheritdoc />
 public AppliedInfo <T> InsertIfNotExists <T>(T poco, bool insertNulls, CqlQueryOptions queryOptions = null)
 {
     return(InsertIfNotExists(poco, insertNulls, null, queryOptions));
 }
Exemple #16
0
 /// <inheritdoc />
 public void Insert <T>(T poco, bool insertNulls, int?ttl, CqlQueryOptions queryOptions = null)
 {
     Insert(poco, Configuration.DefaultExecutionProfileName, insertNulls, ttl, queryOptions);
 }
Exemple #17
0
        /// <inheritdoc />
        public void Insert <T>(T poco, string executionProfile, bool insertNulls, int?ttl, CqlQueryOptions queryOptions = null)
        {
            if (executionProfile == null)
            {
                throw new ArgumentNullException(nameof(executionProfile));
            }

            //Wait async method to be completed or throw
            TaskHelper.WaitToComplete(InsertAsync(poco, executionProfile, insertNulls, ttl, queryOptions), _queryAbortTimeout);
        }
Exemple #18
0
        /// <inheritdoc />
        public Task <AppliedInfo <T> > InsertIfNotExistsAsync <T>(T poco, string executionProfile, bool insertNulls, int?ttl, CqlQueryOptions queryOptions = null)
        {
            if (executionProfile == null)
            {
                throw new ArgumentNullException(nameof(executionProfile));
            }

            var pocoData        = _mapperFactory.PocoDataFactory.GetPocoData <T>();
            var queryIdentifier = $"INSERT ID {pocoData.KeyspaceName}/{pocoData.TableName}";
            var getBindValues   = _mapperFactory.GetValueCollector <T>(queryIdentifier);
            //get values first to identify null values
            var values = getBindValues(poco);
            //generate INSERT query based on null values (if insertNulls set)
            var cql         = _cqlGenerator.GenerateInsert <T>(insertNulls, values, out var queryParameters, true, ttl);
            var cqlInstance = Cql.New(cql, queryParameters, queryOptions ?? CqlQueryOptions.None).WithExecutionProfile(executionProfile);

            return(ExecuteAsyncAndAdapt(
                       cqlInstance,
                       (stmt, rs) => AppliedInfo <T> .FromRowSet(_mapperFactory, cql, rs)));
        }
Exemple #19
0
 /// <inheritdoc />
 public Task <IEnumerable <T> > FetchAsync <T>(CqlQueryOptions options = null)
 {
     return(FetchAsync <T>(Cql.New(string.Empty, new object[0], options ?? CqlQueryOptions.None)));
 }
Exemple #20
0
 /// <inheritdoc />
 public void Insert <T>(T poco, string executionProfile, CqlQueryOptions queryOptions = null)
 {
     Insert(poco, executionProfile, true, queryOptions);
 }
Exemple #21
0
 /// <inheritdoc />
 public void Update <T>(T poco, CqlQueryOptions queryOptions = null)
 {
     //Wait async method to be completed or throw
     TaskHelper.WaitToComplete(UpdateAsync(poco, queryOptions), _queryAbortTimeout);
 }
Exemple #22
0
 /// <inheritdoc />
 public IPage <T> FetchPage <T>(CqlQueryOptions queryOptions = null)
 {
     return(FetchPage <T>(Cql.New(string.Empty, new object[0], queryOptions ?? new CqlQueryOptions())));
 }
Exemple #23
0
 /// <inheritdoc />
 public void Insert <T>(T poco, CqlQueryOptions queryOptions = null)
 {
     Insert(poco, true, queryOptions);
 }
Exemple #24
0
 /// <inheritdoc />
 public IEnumerable <T> Fetch <T>(CqlQueryOptions queryOptions = null)
 {
     // Just let the SQL be auto-generated
     return(Fetch <T>(Cql.New(string.Empty, new object[0], queryOptions ?? CqlQueryOptions.None)));
 }
Exemple #25
0
 internal static Cql New(string cql, object[] args, CqlQueryOptions queryOptions)
 {
     return new Cql(cql, args, queryOptions);
 }
Exemple #26
0
 /// <inheritdoc />
 public Task DeleteAsync <T>(T poco, CqlQueryOptions queryOptions = null)
 {
     return(DeleteAsync(poco, Configuration.DefaultExecutionProfileName, queryOptions));
 }
Exemple #27
0
 /// <inheritdoc />
 public AppliedInfo <T> InsertIfNotExists <T>(T poco, string executionProfile, bool insertNulls, CqlQueryOptions queryOptions = null)
 {
     return(InsertIfNotExists(poco, executionProfile, insertNulls, null, queryOptions));
 }
Exemple #28
0
 /// <inheritdoc />
 public void Insert <T>(T poco, bool insertNulls, CqlQueryOptions queryOptions = null)
 {
     Insert(poco, insertNulls, null, queryOptions);
 }
Exemple #29
0
 /// <inheritdoc />
 public AppliedInfo <T> InsertIfNotExists <T>(T poco, string executionProfile, bool insertNulls, int?ttl, CqlQueryOptions queryOptions = null)
 {
     return(TaskHelper.WaitToComplete(InsertIfNotExistsAsync(poco, executionProfile, insertNulls, ttl, queryOptions), _queryAbortTimeout));
 }
Exemple #30
0
 /// <inheritdoc />
 public void Insert <T>(T poco, string executionProfile, bool insertNulls, CqlQueryOptions queryOptions = null)
 {
     Insert(poco, executionProfile, insertNulls, null, queryOptions);
 }
Exemple #31
0
 /// <inheritdoc />
 public void Delete <T>(T poco, string executionProfile, CqlQueryOptions queryOptions = null)
 {
     //Wait async method to be completed or throw
     TaskHelper.WaitToComplete(DeleteAsync(poco, executionProfile, queryOptions), _queryAbortTimeout);
 }
Exemple #32
0
 /// <inheritdoc />
 public Task <AppliedInfo <T> > InsertIfNotExistsAsync <T>(T poco, bool insertNulls, int?ttl, CqlQueryOptions queryOptions = null)
 {
     return(InsertIfNotExistsAsync(poco, Configuration.DefaultExecutionProfileName, insertNulls, ttl, queryOptions));
 }