Azavea.Open.DAO.Memory.MemoryDataReader.GetCurrentObject C# (CSharp) Method

GetCurrentObject() public method

Gets the current row as a memory object rather than piecemeal.
public GetCurrentObject ( ) : MemoryObject
return MemoryObject
        public MemoryObject GetCurrentObject()
        {
            IDictionary<string, object> currentValues = new Dictionary<string, object>();
            for (int x = 0; x < _namesByIndex.Length; x++)
            {
                currentValues[_namesByIndex[x]] = _valsByIndex[x];
            }
            return new MemoryObject(Mapping, currentValues);
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Updates a data object record using the "table" and a list of column/value pairs.
        /// </summary>
        /// <param name="transaction">The transaction to do this as part of.</param>
        /// <param name="mapping">The mapping of the table or other data container we're dealing with.</param>
        /// <param name="crit">All records matching this criteria will be updated per the dictionary of
        ///                    values.</param>
        /// <param name="propValues">A dictionary of column/value pairs for all non-ID columns to be updated.</param>
        /// <returns>The number of records affected.</returns>
        public override int Update(ITransaction transaction, ClassMapping mapping, DaoCriteria crit, IDictionary<string, object> propValues)
        {
            // Since the update might change one of the id fields, we can't just overwrite the
            // table with new values (since that might be an add).  Instead create a temp table,
            // put in everything that doesn't match, then put in everything that does after
            // modifying it.
            DaoCriteria inverseCrit = new DaoCriteria();
            foreach (IExpression expr in crit.Expressions)
            {
                inverseCrit.Expressions.Add(expr.Invert());
            }
            IDictionary<string, MemoryObject> table = GetTable(mapping);
            int retVal = 0;
            lock (table)
            {
                IDictionary<string, MemoryObject> tempTable = new Dictionary<string, MemoryObject>();

                // First the unchanged records.
                MemoryDataReader reader = new MemoryDataReader(this, mapping, inverseCrit,
                                                               table.Values.GetEnumerator());
                while (reader.Read())
                {
                    MemoryObject unchanged = reader.GetCurrentObject();
                    tempTable[unchanged.GetKey()] = unchanged;
                }
                // Now the changed ones.
                reader = new MemoryDataReader(this, mapping, crit, table.Values.GetEnumerator());
                while (reader.Read())
                {
                    MemoryObject changed = reader.GetCurrentObject();
                    // Set the changed values.
                    foreach (KeyValuePair<string, object> kvp in propValues)
                    {
                        changed.ColValues[kvp.Key] = kvp.Value;
                    }
                    tempTable[changed.GetKey()] = changed;
                    retVal++;
                }
                // Now replace the real table contents with the temp ones.
                table.Clear();
                foreach (KeyValuePair<string, MemoryObject> kvp in tempTable)
                {
                    table.Add(kvp);
                }
            }
            return retVal;
        }
All Usage Examples Of Azavea.Open.DAO.Memory.MemoryDataReader::GetCurrentObject