SQLINQ Class Library  (April 2015)
Using SQLINQ to transform UML to C#
Assets.SQLINQ.SQLite.Patterns.Repository Class Reference

The purpose of the repository is to keep track of all objects that are loaded in from calls to the database. The system keeps track of the transient objects and will return the current transient object first before reloading one from a database. More...

Static Public Member Functions

static void ThrowUOWException (Exception aException, string aMessage, BaseClass aAffectedObject=null)
 
static SQLiteConnection GetTemporaryDatabaseConnection ()
 Gets a connection to the database, remember to not persist the connection. Use a Using statement for more than one statement. More...
 
static void InitializeRepository (string aFullPathToLibraryDatabase)
 Used to load a new database. When using it, make sure that all your internal objects have been flushed or you may run into issues where saving data from a previous database will give you erroneous results. More...
 
static void ClearMemoryObjects ()
 Clears the objects in memory. This is an routine is called after a new database is loaded. More...
 
static TCLASS GetUOW< TCLASS > (int aOID)
 Gets the specified object from the unit of work of type T. More...
 
static void AddUOW< TCLASS > (TCLASS aObject)
 Internal Method Exposed for others to use. Adds the specified object to the repository if it doesn't already exist. If you want to delete the existing object, you need to use Delete first, as Add silently ends if a duplicate exists. More...
 
static void DeleteUOW< TCLASS > (TCLASS aObject)
 Internal Method Exposed for others to use. Deletes an object from the repository so that it can be reloaded from the database. More...
 
static void AddReadFactory< TTABLE > (Func< IBaseTable, BaseClass > aMethod)
 Adds a factory method for a given type. When adding a factory this way, your method is guaranteed to receive an object of type "T". More...
 
static TCLASS Factory< TTABLE, TCLASS > (IBaseTable aRow, bool aFailWithNull=true)
 Returns an object for a given table instance. If the obect has been cached in memory, that object is returned instead of retreving a fresh copy from the database. Use this method for single rows, there is an overload for a list of rows. More...
 
static IEnumerable< TCLASS > Factory< TTABLE, TCLASS > (IEnumerable< TTABLE > aRows, bool aFailSilently=true)
 Allows an enumerated set of rows to be sent and transformed using factory methods that have been specified. If you pass this method a set of ROWS that it cannot transform then it will fail silently unless the second parameter is true. More...
 
static void AddGetOIDMethod< TTABLE > (Func< int, IBaseTable > aGetMethod)
 Gets the method that is used to return a row for a given OID and type. More...
 
static TCLASS GetByOID< TTABLE, TCLASS > (int aOID)
 Returns a table instance for the generic T with a given OID. If you haven't called AddGetOIDMethod with the methods returning table rows, this call will return a null. More...
 
static IEnumerable< TCLASS > GetAllForeignKey< TTABLE, TCLASS > (string aQueryField, int aOID)
 Gets all the rows in a given table that match a foreign key OID. More...
 
static ValidationResult Commit ()
 Write all the dirty objects back to the database as a transaction. Unit of Work is extremely fast as compared to individual object saves. An object save locks the database, changes the rows, releases the database. A Unit Of Work, writes the changes out in memory, then writes changes to the database as a single set. More...
 
static void RegisterUpdate (BaseClass aBaseClass)
 This method is called when ever the IsDirty flag changes from false to true. It allows a user to control the order in which a UnitOfWork writes the updates to the database. Enabling the proper sequencing of updates interspersed with inserts and deletes. More...
 
static bool Save< TTABLE, TCLASS > (TTABLE aTableRow, TCLASS aObject)
 Method to Insert, Update or delete a row in the database. More...
 

Static Public Attributes

static ValidationResult ValidationMessages = null
 Contains a set of messages generated by an Object's Validate() method, not null if generated. More...
 

Properties

static bool IsInitialized [get]
 
static bool isUnitOfWorkCommit [get]
 If True, the SAVE is part of a Unit Of Work Commit. More...
 
static string UnitOfWorkMessage [get]
 The message that was generated by your application during an object save. More...
 
static BaseClass UnitOfWorkObject [get]
 The object affected by a failure. Could be null if not specified. More...
 
static bool HasDatabase [get]
 

Detailed Description

The purpose of the repository is to keep track of all objects that are loaded in from calls to the database. The system keeps track of the transient objects and will return the current transient object first before reloading one from a database.

Member Function Documentation

static void Assets.SQLINQ.SQLite.Patterns.Repository.AddGetOIDMethod< TTABLE > ( Func< int, IBaseTable aGetMethod)
static

Gets the method that is used to return a row for a given OID and type.

Template Parameters
TTABLE
Parameters
aGetMethod
Type Constraints
TTABLE :IBaseTable 
static void Assets.SQLINQ.SQLite.Patterns.Repository.AddReadFactory< TTABLE > ( Func< IBaseTable, BaseClass aMethod)
static

Adds a factory method for a given type. When adding a factory this way, your method is guaranteed to receive an object of type "T".

Parameters
aMethodA factory method accepting "T".
Template Parameters
TType of objects your method will transform.
Type Constraints
TTABLE :IBaseTable 
static void Assets.SQLINQ.SQLite.Patterns.Repository.AddUOW< TCLASS > ( TCLASS  aObject)
static

Internal Method Exposed for others to use. Adds the specified object to the repository if it doesn't already exist. If you want to delete the existing object, you need to use Delete first, as Add silently ends if a duplicate exists.

Parameters
aObjectThe object to add.
Type Constraints
TCLASS :BaseClass 
static void Assets.SQLINQ.SQLite.Patterns.Repository.ClearMemoryObjects ( )
static

Clears the objects in memory. This is an routine is called after a new database is loaded.

static ValidationResult Assets.SQLINQ.SQLite.Patterns.Repository.Commit ( )
static

Write all the dirty objects back to the database as a transaction. Unit of Work is extremely fast as compared to individual object saves. An object save locks the database, changes the rows, releases the database. A Unit Of Work, writes the changes out in memory, then writes changes to the database as a single set.

The Unit Of Work uses the timing of the setting of the object's DIRTY flag to control the order that objects are written to the database. See the BaseClass.IsDirty flag description for more information.

static void Assets.SQLINQ.SQLite.Patterns.Repository.DeleteUOW< TCLASS > ( TCLASS  aObject)
static

Internal Method Exposed for others to use. Deletes an object from the repository so that it can be reloaded from the database.

Parameters
aObjectA object.
Template Parameters
TThe 1st type parameter.
Type Constraints
TCLASS :BaseClass 
static TCLASS Assets.SQLINQ.SQLite.Patterns.Repository.Factory< TTABLE, TCLASS > ( IBaseTable  aRow,
bool  aFailWithNull = true 
)
static

Returns an object for a given table instance. If the obect has been cached in memory, that object is returned instead of retreving a fresh copy from the database. Use this method for single rows, there is an overload for a list of rows.

Template Parameters
TTABLE
TCLASS
Parameters
aRowDatabase row to load.
aFailWithNullIf TRUE (default), returns an null value if it cannot convert the row, otherwise, throws an argument exception.
Returns
The class object for the specified table row.
Type Constraints
TTABLE :IBaseTable 
TCLASS :BaseClass 
static IEnumerable<TCLASS> Assets.SQLINQ.SQLite.Patterns.Repository.Factory< TTABLE, TCLASS > ( IEnumerable< TTABLE >  aRows,
bool  aFailSilently = true 
)
static

Allows an enumerated set of rows to be sent and transformed using factory methods that have been specified. If you pass this method a set of ROWS that it cannot transform then it will fail silently unless the second parameter is true.

Parameters
aRowsThe rows in a table.
aFileSilentlyIf TRUE, throws a ArgumentException for rows it cannot handle.
Template Parameters
TINPUTA class implementing IBaseTable.
TRESULTA class whose base type is BaseClass.
Type Constraints
TCLASS :BaseClass 
TTABLE :IBaseTable 
static IEnumerable<TCLASS> Assets.SQLINQ.SQLite.Patterns.Repository.GetAllForeignKey< TTABLE, TCLASS > ( string  aQueryField,
int  aOID 
)
static

Gets all the rows in a given table that match a foreign key OID.

Template Parameters
TTABLETable class
TCLASSDomain class
Parameters
aQueryFieldField to query, such as ParentOID.
aOIDThe value for ParentOID
Returns
Returns an enumberable for the objects of the Table class.
Type Constraints
TTABLE :IBaseTable 
TTABLE :new() 
TCLASS :BaseClass 
static TCLASS Assets.SQLINQ.SQLite.Patterns.Repository.GetByOID< TTABLE, TCLASS > ( int  aOID)
static

Returns a table instance for the generic T with a given OID. If you haven't called AddGetOIDMethod with the methods returning table rows, this call will return a null.

Type Constraints
TTABLE :IBaseTable 
TCLASS :BaseClass 
static SQLiteConnection Assets.SQLINQ.SQLite.Patterns.Repository.GetTemporaryDatabaseConnection ( )
static

Gets a connection to the database, remember to not persist the connection. Use a Using statement for more than one statement.

The database.

static TCLASS Assets.SQLINQ.SQLite.Patterns.Repository.GetUOW< TCLASS > ( int  aOID)
static

Gets the specified object from the unit of work of type T.

Type Constraints
TCLASS :BaseClass 
static void Assets.SQLINQ.SQLite.Patterns.Repository.InitializeRepository ( string  aFullPathToLibraryDatabase)
static

Used to load a new database. When using it, make sure that all your internal objects have been flushed or you may run into issues where saving data from a previous database will give you erroneous results.

Parameters
aFullPathToLibraryDatabase
static void Assets.SQLINQ.SQLite.Patterns.Repository.RegisterUpdate ( BaseClass  aBaseClass)
static

This method is called when ever the IsDirty flag changes from false to true. It allows a user to control the order in which a UnitOfWork writes the updates to the database. Enabling the proper sequencing of updates interspersed with inserts and deletes.

Parameters
aBaseClass
static bool Assets.SQLINQ.SQLite.Patterns.Repository.Save< TTABLE, TCLASS > ( TTABLE  aTableRow,
TCLASS  aObject 
)
static

Method to Insert, Update or delete a row in the database.

Parameters
aTableRowRow to update.
aObjectThe class this row is based upon.
Template Parameters
TTABLEType of table being modified.
TCLASSType of class this table is based upon.
Type Constraints
TTABLE :IBaseTable 
TCLASS :BaseClass 

Member Data Documentation

ValidationResult Assets.SQLINQ.SQLite.Patterns.Repository.ValidationMessages = null
static

Contains a set of messages generated by an Object's Validate() method, not null if generated.

Property Documentation

bool Assets.SQLINQ.SQLite.Patterns.Repository.isUnitOfWorkCommit
staticget

If True, the SAVE is part of a Unit Of Work Commit.

string Assets.SQLINQ.SQLite.Patterns.Repository.UnitOfWorkMessage
staticget

The message that was generated by your application during an object save.

BaseClass Assets.SQLINQ.SQLite.Patterns.Repository.UnitOfWorkObject
staticget

The object affected by a failure. Could be null if not specified.