Class RowsetBase
Provides base for rowset implementation.
Rowsets are mutable lists of rows where all rows must have the same schema, however a rowset may contain a mix of
dynamic and typed rows as long as they have the same schema.
Rowsets are not thread-safe
Inheritance
System.Object
RowsetBase
Implements
System.Collections.Generic.IList<
Row>
System.Collections.Generic.ICollection<
Row>
System.Collections.Generic.IEnumerable<
Row>
System.Collections.IEnumerable
System.Collections.Generic.IComparer<
Row>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: NFX.dll
Syntax
[Serializable]
public abstract class RowsetBase : IList<Row>, ICollection<Row>, IEnumerable<Row>, IEnumerable, IComparer<Row>, IJSONWritable, IValidatable
Constructors
RowsetBase(Schema)
Declaration
protected RowsetBase(Schema schema)
Parameters
Type |
Name |
Description |
Schema |
schema |
|
Fields
m_Changes
Declaration
protected List<RowChange> m_Changes
Field Value
Type |
Description |
System.Collections.Generic.List<RowChange> |
|
m_List
Declaration
protected List<Row> m_List
Field Value
Type |
Description |
System.Collections.Generic.List<Row> |
|
m_Schema
Declaration
protected Schema m_Schema
Field Value
Properties
AsReadonlyIList
Returns data as non-generic readonly IList
Declaration
public IList AsReadonlyIList { get; }
Property Value
Type |
Description |
System.Collections.IList |
|
ChangeCount
Returns a count of accumulated modifications performed on the rowset, or zero when no modifications have been made or
LogModifications = false
Declaration
public int ChangeCount { get; }
Property Value
Type |
Description |
System.Int32 |
|
Changes
Returns accumulated modifications performed on the rowset, or empty enumerator if no modifications have been made or
LogModifications = false
Declaration
public IEnumerable<RowChange> Changes { get; }
Property Value
Type |
Description |
System.Collections.Generic.IEnumerable<RowChange> |
|
Context
Provides dynamic view of rowset's data context - attributes applicable to the whole rowset
Declaration
public dynamic Context { get; }
Property Value
Type |
Description |
System.Object |
|
ContextMap
Provides dynamic view as JSONDataMap of rowset's data context - attributes applicable to the whole rowset
Declaration
public JSONDataMap ContextMap { get; }
Property Value
Count
Returns row count in this rowset
Declaration
public int Count { get; }
Property Value
Type |
Description |
System.Int32 |
|
InstanceGUID
Returns globaly-unique instance ID.
This ID is useful as a key for storing rowsets in object stores and posting data back from web client to server.
Declaration
public Guid InstanceGUID { get; }
Property Value
Type |
Description |
System.Guid |
|
IsReadOnly
Declaration
public bool IsReadOnly { get; }
Property Value
Type |
Description |
System.Boolean |
|
Item[Int32]
This method performs update on set
Declaration
public virtual Row this[int index] { get; set; }
Parameters
Type |
Name |
Description |
System.Int32 |
index |
|
Property Value
LogChanges
Gets/Sets whether this rowset keeps track of all modifications done to it.
This property must be set to true to be able to save changes into ICRUDDataStore
Declaration
public bool LogChanges { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
Schema
Returns a schema for rows that this rowset contains
Declaration
public Schema Schema { get; }
Property Value
Methods
Add(Row)
Declaration
Parameters
Type |
Name |
Description |
Row |
row |
|
Check(Row)
Checks argument for being non-null and of the same schema with this rowset
Declaration
protected void Check(Row row)
Parameters
Type |
Name |
Description |
Row |
row |
|
Clear()
Declaration
Compare(Row, Row)
Declaration
public abstract int Compare(Row rowA, Row rowB)
Parameters
Type |
Name |
Description |
Row |
rowA |
|
Row |
rowB |
|
Returns
Type |
Description |
System.Int32 |
|
Contains(Row)
Declaration
public bool Contains(Row row)
Parameters
Type |
Name |
Description |
Row |
row |
|
Returns
Type |
Description |
System.Boolean |
|
CopyTo(Row[], Int32)
Declaration
public void CopyTo(Row[] array, int arrayIndex)
Parameters
Type |
Name |
Description |
Row[] |
array |
|
System.Int32 |
arrayIndex |
|
Delete(Row, IDataStoreKey)
Tries to find a row with the same set of key fields in this table and if found, deletes it and returns its index, otherwise -1
Declaration
public int Delete(Row row, IDataStoreKey key = null)
Parameters
Returns
Type |
Description |
System.Int32 |
|
Delete(Object[])
Tries to find a row with the same set of key fields in this table and if found, deletes it and returns its index, otherwise -1
Declaration
public int Delete(params object[] keys)
Parameters
Type |
Name |
Description |
System.Object[] |
keys |
|
Returns
Type |
Description |
System.Int32 |
|
DeleteAll()
Deletes all rows from table. This method is similar to Purge() but does logging (when enabled)
Declaration
DoDelete(Row, IDataStoreKey)
Tries to find a row with the same set of key fields in this table and if found, deletes it and returns its index, otherwise -1
Declaration
protected virtual int DoDelete(Row row, IDataStoreKey key = null)
Parameters
Returns
Type |
Description |
System.Int32 |
|
DoInsert(Row)
Tries to insert a row. If another row with the same set of key fields already in the table returns -1, otherwise
returns insertion index
Declaration
protected virtual int DoInsert(Row row)
Parameters
Type |
Name |
Description |
Row |
row |
|
Returns
Type |
Description |
System.Int32 |
|
DoKeyRowFromValues<T>(T, Object[])
Declaration
protected T DoKeyRowFromValues<T>(T krow, params object[] keys)where T : Row
Parameters
Type |
Name |
Description |
T |
krow |
|
System.Object[] |
keys |
|
Returns
Type Parameters
DoUpdate(Row, IDataStoreKey, Func<Row, Row, Row>)
Tries to find a row with the same set of key fields in this table and if found, replaces it and returns its index,
otherwise returns -1
Declaration
protected virtual int DoUpdate(Row row, IDataStoreKey key = null, Func<Row, Row, Row> rowUpgrade = null)
Parameters
Type |
Name |
Description |
Row |
row |
Row
|
IDataStoreKey |
key |
Primary key
|
System.Func<Row, Row, Row> |
rowUpgrade |
When not null, is called with old and new instance of the row to be updated. It returns
the row to be saved. Note that the returned row must have the same key and schema or else the function will throw.
|
Returns
Type |
Description |
System.Int32 |
|
DoUpgrade(Int32, Row, Func<Row, Row, Row>)
Apply rowUpgrade function to the row stored at index "idx" and the new "row" passed as second argument,
and store the returned row back at index "idx".
Declaration
protected virtual void DoUpgrade(int idx, Row newRow, Func<Row, Row, Row> rowUpgrade)
Parameters
Type |
Name |
Description |
System.Int32 |
idx |
|
Row |
newRow |
|
System.Func<Row, Row, Row> |
rowUpgrade |
|
DoUpsert(Row, Func<Row, Boolean>, Func<Row, Row, Row>)
Tries to find a row with the same set of key fields in this table and if found, replaces it and returns true,
otherwise inserts the row (if schemas match) and returns false. Optionally pass updateWhere condition
that may check whether update needs to be performed
Declaration
protected virtual UpdateResult DoUpsert(Row row, Func<Row, bool> updateWhere, Func<Row, Row, Row> rowUpgrade = null)
Parameters
Type |
Name |
Description |
Row |
row |
|
System.Func<Row, System.Boolean> |
updateWhere |
|
System.Func<Row, Row, Row> |
rowUpgrade |
|
Returns
FindByKey(Row)
Tries to find a row by specified keyset and returns it or null if not found
Declaration
public Row FindByKey(Row keyRow)
Parameters
Type |
Name |
Description |
Row |
keyRow |
|
Returns
FindByKey(Row, Func<Row, Boolean>)
Tries to find a row by specified keyset and extra WHERE clause and returns it or null if not found.
This method does not perform well on Rowsets instances as a rowset is unordered list which does linear search.
In contrast, Tables are always ordered and perform binary search instead
Declaration
public Row FindByKey(Row row, Func<Row, bool> extraWhere)
Parameters
Type |
Name |
Description |
Row |
row |
|
System.Func<Row, System.Boolean> |
extraWhere |
|
Returns
FindByKey(Func<Row, Boolean>, Object[])
Tries to find a row index by specified keyset and extra WHERE clause and returns it or null if not found
Declaration
public Row FindByKey(Func<Row, bool> extraWhere, params object[] keys)
Parameters
Type |
Name |
Description |
System.Func<Row, System.Boolean> |
extraWhere |
|
System.Object[] |
keys |
|
Returns
FindByKey(Object[])
Tries to find a row by specified keyset and returns it or null if not found.
This method does not perform well on Rowsets instances as a rowset is unordered list which does linear search.
In contrast, Tables are always ordered and perform binary search instead
Declaration
public Row FindByKey(params object[] keys)
Parameters
Type |
Name |
Description |
System.Object[] |
keys |
|
Returns
FindIndexByKey(Row)
Tries to find a row index by specified keyset and returns it or null if not found
Declaration
public int FindIndexByKey(Row keyRow)
Parameters
Type |
Name |
Description |
Row |
keyRow |
|
Returns
Type |
Description |
System.Int32 |
|
FindIndexByKey(Row, Func<Row, Boolean>)
Tries to find a row index by specified keyset and extra WHERE clause and returns it or null if not found.
This method does not perform well on Rowsets instances as a rowset is unordered list which does linear search.
In contrast, Tables are always ordered and perform binary search instead
Declaration
public int FindIndexByKey(Row row, Func<Row, bool> extraWhere)
Parameters
Type |
Name |
Description |
Row |
row |
|
System.Func<Row, System.Boolean> |
extraWhere |
|
Returns
Type |
Description |
System.Int32 |
|
FindIndexByKey(Func<Row, Boolean>, Object[])
Tries to find a row index by specified keyset and extra WHERE clause and returns it or null if not found
Declaration
public int FindIndexByKey(Func<Row, bool> extraWhere, params object[] keys)
Parameters
Type |
Name |
Description |
System.Func<Row, System.Boolean> |
extraWhere |
|
System.Object[] |
keys |
|
Returns
Type |
Description |
System.Int32 |
|
FindIndexByKey(Object[])
Tries to find a row index by specified keyset and returns it or null if not found.
This method does not perform well on Rowsets instances as a rowset is unordered list which does linear search.
In contrast, Tables are always ordered and perform binary search instead
Declaration
public int FindIndexByKey(params object[] keys)
Parameters
Type |
Name |
Description |
System.Object[] |
keys |
|
Returns
Type |
Description |
System.Int32 |
|
FromJSON(JSONDataMap, Boolean, Boolean)
Reads either Table or Rowset from JSON created by WriteAsJSON. Metadata must be present
Declaration
public static RowsetBase FromJSON(JSONDataMap jsonMap, bool schemaOnly = false, bool readOnlySchema = false)
Parameters
Type |
Name |
Description |
JSONDataMap |
jsonMap |
|
System.Boolean |
schemaOnly |
|
System.Boolean |
readOnlySchema |
|
Returns
FromJSON(JSONDataMap, out Boolean, Boolean, Boolean, SetFieldFunc)
Reads either Table or Rowset from JSON created by WriteAsJSON. Metadata must be present.
allMatched==false when some data did not match schema (i.e. too little fields or extra fields supplied)
Declaration
public static RowsetBase FromJSON(JSONDataMap jsonMap, out bool allMatched, bool schemaOnly = false, bool readOnlySchema = false, SetFieldFunc setFieldFunc = null)
Parameters
Type |
Name |
Description |
JSONDataMap |
jsonMap |
|
System.Boolean |
allMatched |
|
System.Boolean |
schemaOnly |
|
System.Boolean |
readOnlySchema |
|
SetFieldFunc |
setFieldFunc |
|
Returns
FromJSON(String, Boolean, Boolean)
Reads either Table or Rowset from JSON created by WriteAsJSON. Metadata must be present
Declaration
public static RowsetBase FromJSON(string json, bool schemaOnly = false, bool readOnlySchema = false)
Parameters
Type |
Name |
Description |
System.String |
json |
|
System.Boolean |
schemaOnly |
|
System.Boolean |
readOnlySchema |
|
Returns
FromJSON<T>(JSONDataMap, ref RowsetBase, SetFieldFunc)
Reads either Table or Rowset from JSON created by WriteAsJSON.
Declaration
public static int FromJSON<T>(JSONDataMap jsonMap, ref RowsetBase result, SetFieldFunc setFieldFunc = null)where T : TypedRow, new ()
Parameters
Returns
Type |
Description |
System.Int32 |
Total number of rows found in JSON. If this number is less than
result.Count, then not all rows matched the schema of the resulting rowset.
|
Type Parameters
FromJSON<T>(String, ref RowsetBase, SetFieldFunc)
Reads either Table or Rowset from JSON created by WriteAsJSON.
Declaration
public static int FromJSON<T>(string json, ref RowsetBase result, SetFieldFunc setFieldFunc = null)where T : TypedRow, new ()
Parameters
Returns
Type |
Description |
System.Int32 |
Total number of rows found in JSON. If this number is less than
result.Count, then not all rows matched the schema of the resulting rowset.
|
Type Parameters
GetChangeAt(Int32)
Retrievs a change by index or null if index is out of bounds or changes are not logged
Declaration
public RowChange? GetChangeAt(int idx)
Parameters
Type |
Name |
Description |
System.Int32 |
idx |
|
Returns
GetEnumerator()
Declaration
public IEnumerator<Row> GetEnumerator()
Returns
Type |
Description |
System.Collections.Generic.IEnumerator<Row> |
|
IndexOf(Row)
Declaration
public int IndexOf(Row row)
Parameters
Type |
Name |
Description |
Row |
row |
|
Returns
Type |
Description |
System.Int32 |
|
Insert(Row)
Inserts the row. Returns insertion index
Declaration
public int Insert(Row row)
Parameters
Type |
Name |
Description |
Row |
row |
|
Returns
Type |
Description |
System.Int32 |
|
Insert(Int32, Row)
Declaration
public virtual void Insert(int index, Row row)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
|
Row |
row |
|
KeyRowFromValues(Object[])
Creates key row out of field values for keys
Declaration
public Row KeyRowFromValues(params object[] keys)
Parameters
Type |
Name |
Description |
System.Object[] |
keys |
|
Returns
Purge()
Deletes all rows from table without logging the deleted modifications even when LogModifications=true
Declaration
PurgeChanges()
Clears modifications accumulated by this instance
Declaration
public void PurgeChanges()
Remove(Row)
Declaration
public bool Remove(Row item)
Parameters
Type |
Name |
Description |
Row |
item |
|
Returns
Type |
Description |
System.Boolean |
|
RemoveAt(Int32)
Declaration
public void RemoveAt(int index)
Parameters
Type |
Name |
Description |
System.Int32 |
index |
|
SearchForRow(Row, out Int32)
Provides rowsearching. Override to do binary search in sorted rowsets
Declaration
protected virtual int SearchForRow(Row row, out int index)
Parameters
Type |
Name |
Description |
Row |
row |
A row to search for
|
System.Int32 |
index |
An index where search collapsed without finding the match. Used for sorted insertions
|
Returns
Type |
Description |
System.Int32 |
|
Update(Row, IDataStoreKey, Func<Row, Row, Row>)
Updates the row, Returns the row index or -1
Declaration
public UpdateResult Update(Row row, IDataStoreKey key = null, Func<Row, Row, Row> rowUpgrade = null)
Parameters
Returns
Upsert(Row, Func<Row, Boolean>, Func<Row, Row, Row>)
Tries to find a row for update and if found, updates it and returns true,
otherwise inserts the row (if schemas match) and returns false. Optionally pass updateWhere condition
that may check whether update needs to be performed
Declaration
public UpdateResult Upsert(Row row, Func<Row, bool> updateWhere = null, Func<Row, Row, Row> rowUpgrade = null)
Parameters
Type |
Name |
Description |
Row |
row |
|
System.Func<Row, System.Boolean> |
updateWhere |
|
System.Func<Row, Row, Row> |
rowUpgrade |
|
Returns
Validate(String)
Validates all rows in this rowset.
Override to perform custom validations.
The method is not expected to throw exception in case of failed validation, rather return exception instance because
throwing exception really hampers validation performance when many rows need to be validated
Declaration
public virtual Exception Validate(string targetName)
Parameters
Type |
Name |
Description |
System.String |
targetName |
|
Returns
Type |
Description |
System.Exception |
|
WriteAsJSON(TextWriter, Int32, JSONWritingOptions)
Writes rowset as JSON including schema information. Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class
Declaration
public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
Parameters
Type |
Name |
Description |
System.IO.TextWriter |
wri |
|
System.Int32 |
nestingLevel |
|
JSONWritingOptions |
options |
|
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type |
Description |
System.Collections.IEnumerator |
|
Implements
System.Collections.Generic.IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
System.Collections.Generic.IComparer<T>
Extension Methods