Class RowsetBase
Provides base for rowsets.
Rowsets are mutable lists of documents where all documents(rows) must adhere to the same same schema (hence called "rows"),
however a rowset may contain a mix of dynamic and typed documents as long as they have the same schema.
Rowsets are not thread-safe
Inheritance
System.Object
RowsetBase
Implements
System.Collections.Generic.IList<
Doc>
System.Collections.Generic.ICollection<
Doc>
System.Collections.Generic.IEnumerable<
Doc>
System.Collections.IEnumerable
System.Collections.Generic.IComparer<
Doc>
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: Azos.dll
Syntax
[Serializable]
public abstract class RowsetBase : IList<Doc>, ICollection<Doc>, IEnumerable<Doc>, IEnumerable, IComparer<Doc>, IJSONWritable, IValidatable
Constructors
RowsetBase(Schema)
Declaration
protected RowsetBase(Schema schema)
Parameters
| Type |
Name |
Description |
| Schema |
schema |
|
Fields
m_Changes
Declaration
protected List<DocChange> m_Changes
Field Value
| Type |
Description |
| System.Collections.Generic.List<DocChange> |
|
m_List
Declaration
protected List<Doc> m_List
Field Value
| Type |
Description |
| System.Collections.Generic.List<Doc> |
|
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<DocChange> Changes { get; }
Property Value
| Type |
Description |
| System.Collections.Generic.IEnumerable<DocChange> |
|
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 Doc 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(Doc)
Declaration
Parameters
| Type |
Name |
Description |
| Doc |
doc |
|
Check(Doc)
Checks argument for being non-null and of the same schema with this rowset
Declaration
protected void Check(Doc doc)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
|
Clear()
Declaration
Compare(Doc, Doc)
Declaration
public abstract int Compare(Doc docA, Doc docB)
Parameters
| Type |
Name |
Description |
| Doc |
docA |
|
| Doc |
docB |
|
Returns
| Type |
Description |
| System.Int32 |
|
Contains(Doc)
Declaration
public bool Contains(Doc doc)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
|
Returns
| Type |
Description |
| System.Boolean |
|
CopyTo(Doc[], Int32)
Declaration
public void CopyTo(Doc[] array, int arrayIndex)
Parameters
| Type |
Name |
Description |
| Doc[] |
array |
|
| System.Int32 |
arrayIndex |
|
Delete(Doc, 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(Doc doc, 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(Doc, 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(Doc doc, IDataStoreKey key = null)
Parameters
Returns
| Type |
Description |
| System.Int32 |
|
DoInsert(Doc)
Tries to insert a document. If another doc with the same set of key fields already in the table returns -1, otherwise
returns insertion index
Declaration
protected virtual int DoInsert(Doc doc)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
|
Returns
| Type |
Description |
| System.Int32 |
|
DoKeyDocFromValues<T>(T, Object[])
Declaration
protected T DoKeyDocFromValues<T>(T kdoc, params object[] keys)
where T : Doc
Parameters
| Type |
Name |
Description |
| T |
kdoc |
|
| System.Object[] |
keys |
|
Returns
Type Parameters
DoUpdate(Doc, IDataStoreKey, Func<Doc, Doc, Doc>)
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(Doc doc, IDataStoreKey key = null, Func<Doc, Doc, Doc> docUpgrade = null)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
Document instance
|
| IDataStoreKey |
key |
Primary key
|
| System.Func<Doc, Doc, Doc> |
docUpgrade |
When not null, is called with old and new instance of the doc to be updated. It returns
the doc to be saved. Note that the returned doc must have the same key and schema or else the function will throw.
|
Returns
| Type |
Description |
| System.Int32 |
|
DoUpgrade(Int32, Doc, Func<Doc, Doc, Doc>)
Apply docUpgrade function to the doc stored at index "idx" and the new "doc" passed as second argument,
and store the returned doc back at index "idx".
Declaration
protected virtual void DoUpgrade(int idx, Doc newDoc, Func<Doc, Doc, Doc> docUpgrade)
Parameters
| Type |
Name |
Description |
| System.Int32 |
idx |
|
| Doc |
newDoc |
|
| System.Func<Doc, Doc, Doc> |
docUpgrade |
|
DoUpsert(Doc, Func<Doc, Boolean>, Func<Doc, Doc, Doc>)
Tries to find a doc with the same set of key fields in this table and if found, replaces it and returns true,
otherwise inserts the doc (if schemas match) and returns false. Optionally pass updateWhere condition
that may check whether update needs to be performed
Declaration
protected virtual UpdateResult DoUpsert(Doc doc, Func<Doc, bool> updateWhere, Func<Doc, Doc, Doc> docUpgrade = null)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
|
| System.Func<Doc, System.Boolean> |
updateWhere |
|
| System.Func<Doc, Doc, Doc> |
docUpgrade |
|
Returns
FindByKey(Doc)
Tries to find a row by specified keyset and returns it or null if not found
Declaration
public Doc FindByKey(Doc keyDoc)
Parameters
| Type |
Name |
Description |
| Doc |
keyDoc |
|
Returns
FindByKey(Doc, Func<Doc, 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 Doc FindByKey(Doc doc, Func<Doc, bool> extraWhere)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
|
| System.Func<Doc, System.Boolean> |
extraWhere |
|
Returns
FindByKey(Func<Doc, Boolean>, Object[])
Tries to find a doc index by specified keyset and extra WHERE clause and returns it or null if not found
Declaration
public Doc FindByKey(Func<Doc, bool> extraWhere, params object[] keys)
Parameters
| Type |
Name |
Description |
| System.Func<Doc, 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 Doc FindByKey(params object[] keys)
Parameters
| Type |
Name |
Description |
| System.Object[] |
keys |
|
Returns
FindIndexByKey(Doc)
Tries to find a doc index by specified keyset and returns it or null if not found
Declaration
public int FindIndexByKey(Doc keyDoc)
Parameters
| Type |
Name |
Description |
| Doc |
keyDoc |
|
Returns
| Type |
Description |
| System.Int32 |
|
FindIndexByKey(Doc, Func<Doc, 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(Doc doc, Func<Doc, bool> extraWhere)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
|
| System.Func<Doc, System.Boolean> |
extraWhere |
|
Returns
| Type |
Description |
| System.Int32 |
|
FindIndexByKey(Func<Doc, 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<Doc, bool> extraWhere, params object[] keys)
Parameters
| Type |
Name |
Description |
| System.Func<Doc, 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 : TypedDoc, 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 : TypedDoc, 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 DocChange? GetChangeAt(int idx)
Parameters
| Type |
Name |
Description |
| System.Int32 |
idx |
|
Returns
GetEnumerator()
Declaration
public IEnumerator<Doc> GetEnumerator()
Returns
| Type |
Description |
| System.Collections.Generic.IEnumerator<Doc> |
|
IndexOf(Doc)
Declaration
public int IndexOf(Doc doc)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
|
Returns
| Type |
Description |
| System.Int32 |
|
Insert(Doc)
Inserts the doc. Returns insertion index
Declaration
public int Insert(Doc doc)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
|
Returns
| Type |
Description |
| System.Int32 |
|
Insert(Int32, Doc)
Declaration
public virtual void Insert(int index, Doc doc)
Parameters
| Type |
Name |
Description |
| System.Int32 |
index |
|
| Doc |
doc |
|
KeyDocFromValues(Object[])
Creates key row out of field values for keys
Declaration
public Doc KeyDocFromValues(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(Doc)
Declaration
public bool Remove(Doc item)
Parameters
| Type |
Name |
Description |
| Doc |
item |
|
Returns
| Type |
Description |
| System.Boolean |
|
RemoveAt(Int32)
Declaration
public void RemoveAt(int index)
Parameters
| Type |
Name |
Description |
| System.Int32 |
index |
|
SearchForDoc(Doc, out Int32)
Provides rowsearching. Override to do binary search in sorted rowsets
Declaration
protected virtual int SearchForDoc(Doc doc, out int index)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
A doc 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(Doc, IDataStoreKey, Func<Doc, Doc, Doc>)
Updates the doc, Returns the row index or -1
Declaration
public UpdateResult Update(Doc doc, IDataStoreKey key = null, Func<Doc, Doc, Doc> docUpgrade = null)
Parameters
Returns
Upsert(Doc, Func<Doc, Boolean>, Func<Doc, Doc, Doc>)
Tries to find a doc for update and if found, updates it and returns true,
otherwise inserts the doc (if schemas match) and returns false. Optionally pass updateWhere condition
that may check whether update needs to be performed
Declaration
public UpdateResult Upsert(Doc doc, Func<Doc, bool> updateWhere = null, Func<Doc, Doc, Doc> rowUpgrade = null)
Parameters
| Type |
Name |
Description |
| Doc |
doc |
|
| System.Func<Doc, System.Boolean> |
updateWhere |
|
| System.Func<Doc, Doc, Doc> |
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