Example #1
0
        public static void BatchDelete(this CyanTable table, IEnumerable<CyanEntity> entities, bool unconditionalUpdate = false)
        {
            foreach (var partition in GetBatchPartitions(entities))
            {
                if (partition.Length == 1)
                {
                    // no need for a batch request
                    table.Delete(partition[0], unconditionalUpdate);
                }
                else
                {
                    var batch = table.Batch();
                    foreach (var entity in partition)
                        batch.Delete(entity, unconditionalUpdate);

                    batch.Commit();
                }
            }
        }
Example #2
0
        public static IEnumerable<dynamic> BatchUpdate(this CyanTable table,
            Func<CyanTable, IEnumerable<dynamic>> entityModifier,
            bool unconditionalUpdate = false)
        {
            var success = false;
            List<dynamic> ret = null;
            do
            {
                var toUpdate = entityModifier(table);
                ret = new List<dynamic>();

                var batch = table.Batch();
                foreach (var item in toUpdate)
                    ret.Add(batch.Update(item, unconditionalUpdate));

                success = batch.TryCommit();
            } while (!success);

            return ret;
        }
Example #3
0
        public static IEnumerable<dynamic> BatchInsert(this CyanTable table, IEnumerable<CyanEntity> entities)
        {
            foreach (var partition in GetBatchPartitions(entities))
            {
                if (partition.Length == 1)
                {
                    // no need for a batch request
                    yield return table.Insert(partition[0]);
                }
                else
                {
                    List<dynamic> ret = new List<dynamic>();
                    var batch = table.Batch();
                    foreach (var entity in partition)
                        ret.Add(batch.Insert(entity));

                    batch.Commit();

                    foreach (var item in ret)
                        yield return item;
                }
            }
        }