Azavea.Open.DAO.Memory.MemoryDaLayer.Delete C# (CSharp) Method

Delete() public method

Deletes a data object record using the mapping and criteria for what's deleted.
public Delete ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping The mapping of the table from which to delete.
crit Azavea.Open.DAO.Criteria.DaoCriteria Criteria for deletion. NOTE: Only the expressions are observed, /// other things (like "order" or start / limit) are ignored. /// WARNING: A null or empty (no expression) criteria will /// delete ALL records!
return int
        public override int Delete(ITransaction transaction, ClassMapping mapping, DaoCriteria crit)
        {
            // Find all the records that don't match, and just keep those.
            DaoCriteria inverseCrit = new DaoCriteria();
            foreach (IExpression expr in crit.Expressions)
            {
                inverseCrit.Expressions.Add(expr.Invert());
            }
            IDictionary<string, MemoryObject> table = GetTable(mapping);
            int retVal;
            lock (table)
            {
                int oldCount = table.Count;
                MemoryDataReader reader = new MemoryDataReader(this, mapping, inverseCrit,
                                                               table.Values.GetEnumerator());
                IDictionary<string, MemoryObject> tempTable = new Dictionary<string, MemoryObject>();
                while (reader.Read())
                {
                    MemoryObject keeper = reader.GetCurrentObject();
                    tempTable[keeper.GetKey()] = keeper;
                }
                table.Clear();
                foreach (KeyValuePair<string, MemoryObject> kvp in tempTable)
                {
                    table.Add(kvp);
                }
                retVal = oldCount - table.Count;
            }
            return retVal;
        }