Exemple #1
0
        public override IAsyncResult BeginExecute(AsyncCallback callback, object state)
        {
            var visitor = new CqlExpressionVisitor();

            visitor.Evaluate(Expression);
            return(InternalBeginExecute(visitor.GetSelect(), visitor.Mappings, visitor.Alter, callback, state));
        }
Exemple #2
0
        protected override string GetCql(out object[] values)
        {
            var visitor = new CqlExpressionVisitor();

            visitor.Evaluate(Expression);
            return(visitor.GetSelect(out values));
        }
Exemple #3
0
        /// <summary>
        /// Evaluates the Linq query, executes asynchronously the cql statement and adapts the results.
        /// </summary>
        public Task <IEnumerable <TEntity> > ExecuteAsync()
        {
            bool withValues = GetTable().GetSession().BinaryProtocolVersion > 1;

            var visitor = new CqlExpressionVisitor();

            visitor.Evaluate(Expression);
            object[] values;
            string   cql        = visitor.GetSelect(out values, withValues);
            var      adaptation =
                InternalExecuteAsync(cql, values).ContinueWith((t) =>
            {
                var rs     = t.Result;
                QueryTrace = rs.Info.QueryTrace;

                CqlColumn[] cols = rs.Columns;
                var colToIdx     = new Dictionary <string, int>();
                for (int idx = 0; idx < cols.Length; idx++)
                {
                    colToIdx.Add(cols[idx].Name, idx);
                }
                return(AdaptRows(rs, colToIdx, visitor));
            }, TaskContinuationOptions.ExecuteSynchronously);

            return(adaptation);
        }
Exemple #4
0
        protected override string CqlString()
        {
            var visitor = new CqlExpressionVisitor();

            visitor.Evaluate(Expression);
            return(visitor.GetSelect());
        }
        protected override string GetCql(out object[] values)
        {
            var visitor = new CqlExpressionVisitor(PocoData, Table.Name, Table.KeyspaceName);

            visitor.Evaluate(Expression);
            return(visitor.GetSelect(out values));
        }
Exemple #6
0
        public override string ToString()
        {
            var visitor = new CqlExpressionVisitor();

            visitor.Evaluate(Expression);
            object[] _;
            return(visitor.GetSelect(out _, false));
        }
        /// <summary>
        /// Evaluates the Linq query, executes asynchronously the cql statement and adapts the results.
        /// </summary>
        public async Task <IEnumerable <TEntity> > ExecuteAsync()
        {
            var visitor = new CqlExpressionVisitor(PocoData, Table.Name, Table.KeyspaceName);

            object[] values;
            var      cql = visitor.GetSelect(Expression, out values);
            var      rs  = await InternalExecuteAsync(cql, values).ConfigureAwait(false);

            return(AdaptResult(cql, rs));
        }
        /// <summary>
        /// Evaluates the Linq query, executes asynchronously the cql statement and adapts the results.
        /// </summary>
        public Task <IEnumerable <TEntity> > ExecuteAsync()
        {
            var visitor = new CqlExpressionVisitor(PocoData, Table.Name, Table.KeyspaceName);

            visitor.Evaluate(Expression);
            object[] values;
            var      cql = visitor.GetSelect(out values);

            return(InternalExecuteAsync(cql, values).Continue(t => AdaptResult(cql, t.Result)));
        }
Exemple #9
0
        public override IAsyncResult BeginExecute(AsyncCallback callback, object state)
        {
            bool withValues = GetTable().GetSession().BinaryProtocolVersion > 1;
            var  visitor    = new CqlExpressionVisitor();

            visitor.Evaluate(Expression);
            object[] values;
            string   cql = visitor.GetSelect(out values, withValues);

            return(InternalBeginExecute(cql, values, visitor.Mappings, visitor.Alter, callback, state));
        }
Exemple #10
0
        /// <summary>
        /// Asynchronously executes the query and returns a task of a page of results
        /// </summary>
        public async Task <IPage <TEntity> > ExecutePagedAsync()
        {
            SetAutoPage(false);
            var visitor = new CqlExpressionVisitor(PocoData, Table.Name, Table.KeyspaceName);

            object[] values;
            var      cql = visitor.GetSelect(Expression, out values);
            var      rs  = await InternalExecuteAsync(cql, values).ConfigureAwait(false);

            var mapper = MapperFactory.GetMapper <TEntity>(cql, rs);

            return(new Page <TEntity>(rs.Select(mapper), PagingState, rs.PagingState));
        }
Exemple #11
0
        /// <summary>
        /// Evaluates the Linq query, executes asynchronously the cql statement and adapts the results.
        /// </summary>
        public Task <IEnumerable <TEntity> > ExecuteAsync()
        {
            var visitor = new CqlExpressionVisitor(PocoData, Table.Name, Table.KeyspaceName);

            visitor.Evaluate(Expression);
            object[] values;
            var      cql        = visitor.GetSelect(out values);
            var      adaptation = InternalExecuteAsync(cql, values).Continue(t =>
            {
                var rs     = t.Result;
                var mapper = MapperFactory.GetMapper <TEntity>(cql, rs);
                return(rs.Select(mapper));
            });

            return(adaptation);
        }
Exemple #12
0
        /// <summary>
        /// Asynchronously executes the query with the provided execution profile and returns a task of a page of results
        /// </summary>
        public async Task <IPage <TEntity> > ExecutePagedAsync(string executionProfile)
        {
            if (executionProfile == null)
            {
                throw new ArgumentNullException(nameof(executionProfile));
            }

            SetAutoPage(false);
            var visitor = new CqlExpressionVisitor(PocoData, Table.Name, Table.KeyspaceName);
            var cql     = visitor.GetSelect(Expression, out object[] values);
            var rs      = await InternalExecuteWithProfileAsync(executionProfile, cql, values).ConfigureAwait(false);

            var mapper = MapperFactory.GetMapper <TEntity>(cql, rs);

            return(new Page <TEntity>(rs.Select(mapper), PagingState, rs.PagingState));
        }
        public void StartsWith_Test()
        {
            var table = new Table<LinqDecoratedWithStringCkEntity>(null);
            var query = table.Where(t => t.pk == "a" && t.ck1.StartsWith("foo") && t.pk == "bar");
            var pocoData = MappingConfiguration.Global.MapperFactory.GetPocoData<LinqDecoratedWithStringCkEntity>();
            var visitor = new CqlExpressionVisitor(pocoData, "x_ts", null);
            visitor.Evaluate(query.Expression);
            object[] parameters;

            var queryCql = visitor.GetSelect(out parameters);

            Assert.That(parameters, Is.EquivalentTo(new[] { "a", "foo", "foo" + Encoding.UTF8.GetString(new byte[] { 0xF4, 0x8F, 0xBF, 0xBF }), "bar" }));
            Assert.AreEqual(@"SELECT ""x_pk"", ""x_ck1"", ""x_f1"" FROM ""x_ts"" WHERE ""x_pk"" = ? AND ""x_ck1"" >= ? AND ""x_ck1"" < ? AND ""x_pk"" = ?", queryCql);
        }