public override string ToString() { object[] _; var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); return visitor.GetUpdate(out _, _ttl, _timestamp, false); }
public override string CqlString() { var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); return(visitor.GetCount()); }
protected override string GetCql() { var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); return(visitor.GetDelete()); }
/// <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); }
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)); }
protected override string GetCql(out object[] values) { bool withValues = GetTable().GetSession().BinaryProtocolVersion > 1; var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); return visitor.GetUpdate(out values, _ttl, _timestamp, withValues); }
private Expression FillUpdateProjection(MemberExpression node) { PocoColumn column; if (node.Expression == null || node.Expression.NodeType != ExpressionType.Parameter) { column = _pocoData.GetColumnByMemberName(_currentBindingName.Get()); if (column == null) { throw new InvalidOperationException("No mapping defined for member: " + node.Member.Name); } if (column.IsCounter) { var value = CqlExpressionVisitor.GetClosureValue(node); if (!(value is long || value is int)) { throw new ArgumentException("Only Int64 and Int32 values are supported as counter increment of decrement values"); } _projections.Add(Tuple.Create(column, value, ExpressionType.Increment)); return(node); } AddProjection(node, column); return(node); } column = _pocoData.GetColumnByMemberName(node.Member.Name); if (column == null) { throw new InvalidOperationException("No mapping defined for member: " + node.Member.Name); } _projections.Add(Tuple.Create(column, (object)column.ColumnName, ExpressionType.Assign)); return(node); }
public override string GetCql() { var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); return(visitor.GetUpdate()); }
public new Task <TEntity> ExecuteAsync() { bool withValues = GetTable().GetSession().BinaryProtocolVersion > 1; var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); object[] values; string cql = visitor.GetCount(out values, withValues); var adaptation = InternalExecuteAsync(cql, values).ContinueWith((t) => { var rs = t.Result; var result = default(TEntity); var row = rs.FirstOrDefault(); if (row != null) { result = (TEntity)row[0]; } return(result); }, TaskContinuationOptions.ExecuteSynchronously); return(adaptation); }
protected override string GetCql(out object[] values) { var visitor = new CqlExpressionVisitor(PocoData, Table.Name, Table.KeyspaceName); visitor.Evaluate(Expression); return(visitor.GetSelect(out values)); }
protected internal override string GetCql(out object[] values) { var visitor = new CqlExpressionVisitor(PocoData, Table.Name, Table.KeyspaceName); visitor.Evaluate(Expression); return(visitor.GetDelete(out values, _timestamp, _ifExists)); }
protected override string GetCql() { var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); return(visitor.GetUpdate(_ttl, _timestamp)); }
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(); visitor.Evaluate(Expression); return(visitor.GetSelect(out values)); }
public override string ToString() { var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); object[] _; return visitor.GetDelete(out _, _timestamp, _ifExists, false); }
protected override Expression VisitBinary(BinaryExpression node) { if (_parsePhase.Get() == ParsePhase.Condition) { if (node.NodeType == ExpressionType.AndAlso) { // It's the AND of the WHERE/IF clause Visit(node.Left); // Add the new condition for the right portion _conditions.Add(new BinaryConditionItem()); Visit(node.Right); return(node); } var condition = _conditions.Last(); if (BinaryConditionItem.IsSupported(node.NodeType)) { if (node.NodeType == ExpressionType.Equal && IsBoolMember(node.Left)) { // Handle x.prop == boolValue explicitly FillBooleanCondition((MemberExpression)node.Left, condition); Visit(node.Right); return(node); } if (node.NodeType == ExpressionType.Equal && IsBoolMember(node.Right)) { // Handle boolValue == x.prop explicitly FillBooleanCondition((MemberExpression)node.Right, condition); Visit(node.Left); return(node); } Visit(CqlExpressionVisitor.DropNullableConversion(node.Left)); condition.SetOperator(node.NodeType); Visit(CqlExpressionVisitor.DropNullableConversion(node.Right)); return(node); } if (!CqlExpressionVisitor.CqlUnsupTags.Contains(node.NodeType)) { condition.SetParameter(Expression.Lambda(node).Compile().DynamicInvoke()); return(node); } } else if (_parsePhase.Get() == ParsePhase.SelectBinding) { var column = _pocoData.GetColumnByMemberName(_currentBindingName.Get()); if (column == null) { throw new ArgumentException("Trying to select a column does it excluded in the mappings"); } AddProjection(node, column); _selectFields.Add(column.ColumnName); return(node); } throw new CqlLinqNotSupportedException(node, _parsePhase.Get()); }
protected override string GetCql(out object[] values) { var withValues = GetTable().GetSession().BinaryProtocolVersion > 1; var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); return(visitor.GetDelete(out values, _timestamp, _ifExists, withValues)); }
public override string ToString() { var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); object[] _; return(visitor.GetSelect(out _, false)); }
public override string ToString() { object[] _; var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); return(visitor.GetUpdate(out _, _ttl, _timestamp, false)); }
public override string ToString() { var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); object[] _; return(visitor.GetDelete(out _, _timestamp, _ifExists, false)); }
protected override string GetCql(out object[] values) { bool withValues = GetTable().GetSession().BinaryProtocolVersion > 1; var visitor = new CqlExpressionVisitor(); visitor.Evaluate(Expression); var type = GetTable().GetEntityType(); return(visitor.GetUpdate(out values, type, _ttl, _timestamp, withValues)); }
/// <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))); }
/// <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)); }
protected internal override string GetCql(out object[] values) { var getBindValues = _mapperFactory.GetValueCollector <TEntity>("INSERT ALL LINQ"); var parameters = new List <object>(getBindValues(_entity)); var visitor = new CqlExpressionVisitor(PocoData, Table.Name, Table.KeyspaceName); var cql = visitor.GetInsert(_entity, _ifNotExists, _ttl, _timestamp, parameters); values = parameters.ToArray(); return(cql); }
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)); }
/// <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)); }
protected override Expression VisitUnary(UnaryExpression node) { if (_parsePhase.Get() == ParsePhase.Condition) { var condition = _conditions.Last(); if (node.NodeType == ExpressionType.Not && node.Operand.NodeType == ExpressionType.MemberAccess) { // We are evaluating a boolean expression parameter, the value we are trying to match is false FillBooleanCondition((MemberExpression)node.Operand, condition, false); return(node); } if (BinaryConditionItem.IsSupported(node.NodeType)) { condition.SetOperator(node.NodeType); Visit(CqlExpressionVisitor.DropNullableConversion(node.Operand)); } else if (node.NodeType == ExpressionType.Convert) { Visit(node.Operand); } else { var val = Expression.Lambda(node).Compile().DynamicInvoke(); condition.SetParameter(val); } return(node); } if (_parsePhase.Get() == ParsePhase.SelectBinding) { if (node.NodeType == ExpressionType.Convert && node.Type.Name == "Nullable`1") { // ReSharper disable once AssignNullToNotNullAttribute return(Visit(node.Operand)); } var column = _pocoData.GetColumnByMemberName(_currentBindingName.Get()); if (column != null && column.IsCounter) { var value = Expression.Lambda(node).Compile().DynamicInvoke(); if (!(value is long || value is int)) { throw new ArgumentException("Only Int64 and Int32 values are supported as counter increment of decrement values"); } _projections.Add(Tuple.Create(column, value, ExpressionType.Increment)); _selectFields.Add(column.ColumnName); return(node); } } throw new CqlLinqNotSupportedException(node, _parsePhase.Get()); }
/// <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)); }
/// <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); }
private Expression FillCondition(MemberExpression node) { var condition = _conditions.Last(); if (node.Expression == null || node.Expression.NodeType == ExpressionType.MemberAccess) { var val = CqlExpressionVisitor.GetClosureValue(node); condition.SetParameter(val); return(node); } if (node.Expression.NodeType == ExpressionType.Parameter) { var column = _pocoData.GetColumnByMemberName(node.Member.Name); if (column == null) { throw new InvalidOperationException($"No mapping defined for member: {node.Member.Name}"); } condition.SetColumn(column); if (column.ColumnType == typeof(bool)) { condition.SetOperator(ExpressionType.Equal); // We are evaluating a boolean expression parameter, the value we are trying to match is true condition.SetParameter(true); } return(node); } if (node.Expression.NodeType == ExpressionType.Constant) { var val = CqlExpressionVisitor.GetClosureValue(node); if (val is CqlToken) { var tokenValues = (val as CqlToken).Values; condition.SetFunctionName("token").AllowMultipleParameters(); foreach (var pk in tokenValues) { condition.SetParameter(pk); } } else { condition.SetParameter(val); } return(node); } return(node); }
private static object GetFieldValue(MemberExpression node) { var fieldInfo = (FieldInfo)node.Member; if (node.Expression is MemberExpression) { // The field of a field instance var instance = CqlExpressionVisitor.GetClosureValue((MemberExpression)node.Expression); return(fieldInfo.GetValue(instance)); } if (node.Expression == null) { // Static field return(fieldInfo.GetValue(null)); } return(fieldInfo.GetValue(((ConstantExpression)node.Expression).Value)); }
private static object GetClosureValue(MemberExpression node) { object value; if (node.Member.MemberType == MemberTypes.Field) { value = CqlExpressionVisitor.GetFieldValue(node); } else if (node.Member.MemberType == MemberTypes.Property) { value = CqlExpressionVisitor.GetPropertyValue(node); } else { value = Expression.Lambda(node).Compile().DynamicInvoke(); } return(value); }
private static object GetPropertyValue(MemberExpression node) { var propertyInfo = (PropertyInfo)node.Member; if (node.Expression == null) { return(propertyInfo.GetValue(null)); } if (node.Expression is MemberExpression) { // Field property var instance = CqlExpressionVisitor.GetClosureValue((MemberExpression)node.Expression); return(propertyInfo.GetValue(instance, null)); } // Current instance property return(propertyInfo.GetValue(((ConstantExpression)node.Expression).Value, null)); }
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); }
protected internal override string GetCql(out object[] values) { var visitor = new CqlExpressionVisitor(PocoData, Table.Name, Table.KeyspaceName); visitor.Evaluate(Expression); return visitor.GetUpdate(out values, _ttl, _timestamp); }