public bool AppendChangesToBatch(StringBuilder batchScript, string tablename) { bool enableTracing = false; foreach (var kv in _table) { if (!CqlEqualityComparer <TEntity> .Default.Equals(kv.Key, kv.Value.Entity)) { throw new InvalidOperationException(); } if (kv.Value.QueryTracingEnabled) { enableTracing = true; } var cql = ""; if (kv.Value.MutationType == MutationType.Add) { cql = CqlQueryTools.GetInsertCQL(kv.Value.Entity, tablename); } else if (kv.Value.MutationType == MutationType.Delete) { cql = CqlQueryTools.GetDeleteCQL(kv.Value.Entity, tablename); } else if (kv.Value.MutationType == MutationType.None) { if (kv.Value.CqlEntityUpdateMode == EntityUpdateMode.AllOrNone) { cql = CqlQueryTools.GetUpdateCQL(kv.Key, kv.Value.Entity, tablename, true); } else { cql = CqlQueryTools.GetUpdateCQL(kv.Key, kv.Value.Entity, tablename, false); } } else { continue; } if (cql != null) { batchScript.AppendLine(cql + ";"); } } return(enableTracing); }
protected override string GetCql() { return(CqlQueryTools.GetInsertCQL(_entity, (GetTable()).GetQuotedTableName(), _ttl, _timestamp)); }
public void SaveChangesOneByOne(Context context, string tablename, ConsistencyLevel consistencyLevel) { var commitActions = new List <Action>(); try { foreach (var kv in _table) { if (!CqlEqualityComparer <TEntity> .Default.Equals(kv.Key, kv.Value.Entity)) { throw new InvalidOperationException(); } var cql = ""; if (kv.Value.MutationType == MutationType.Add) { cql = CqlQueryTools.GetInsertCQL(kv.Value.Entity, tablename); } else if (kv.Value.MutationType == MutationType.Delete) { cql = CqlQueryTools.GetDeleteCQL(kv.Value.Entity, tablename); } else if (kv.Value.MutationType == MutationType.None) { cql = CqlQueryTools.GetUpdateCQL(kv.Key, kv.Value.Entity, tablename, kv.Value.CqlEntityUpdateMode == EntityUpdateMode.AllOrNone); } else { continue; } QueryTrace trace = null; if (cql != null) // null if nothing to update { var res = context.ExecuteWriteQuery(cql, consistencyLevel, kv.Value.QueryTracingEnabled); if (kv.Value.QueryTracingEnabled) { trace = res.Info.QueryTrace; } } var nkv = kv; commitActions.Add(() => { if (nkv.Value.QueryTracingEnabled) { if (trace != null) { lock (_traces) _traces[nkv.Key] = trace; } } _table.Remove(nkv.Key); if (nkv.Value.MutationType != MutationType.Delete && nkv.Value.CqlEntityTrackingMode != EntityTrackingMode.DetachAfterSave) { _table.Add(Clone(nkv.Value.Entity), new TableEntry() { Entity = nkv.Value.Entity, MutationType = MutationType.None, CqlEntityUpdateMode = nkv.Value.CqlEntityUpdateMode }); } }); } } finally { foreach (var act in commitActions) { act(); } } }
protected override string GetCql() { return(CqlQueryTools.GetInsertCQL(_entity, (GetTable()).GetTableName())); }