MultitenantDataServices

Implements IDataServices fro multi-tenant environments.

Namespace:
Inetdev.Multitenancy
Type:
Class
Public:
Yes
Protected:
No
Sealed:
No
Abstract:
Yes
Inherits from:
System.Object
Implements:
Inetdev.Data.IDataServices

Constructors

MultitenantDataServices

Default constructor

Signature:
protected Void MultitenantDataServices()

Properties

Alias

Alias of the table.

Signature:
public String Alias { get; set; }

CommandBuilder

Database engine command builder.

Signature:
public IDbCmdBuilder CommandBuilder { get; set; }

DataAccessAPI

Database engine API.

Signature:
public IDbAccess DataAccessAPI { get; set; }

DataModelAuditor

Gets or set the service for modification auditing.

Signature:
public IDataModelAuditor DataModelAuditor { get; set; }

DataModelCmdBuilder

Database engine command builder for data model objects.

Signature:
public IDataModelCmdBuilder DataModelCmdBuilder { get; set; }

Fields

A collection of fields that defines the table columns.

Signature:
public IDictionary<String, Field> Fields { get; set; }

Schema

Schema to which the table belongs to.

Signature:
public String Schema { get; set; }

SequenceName

Name of the sequence.

Signature:
public String SequenceName { get; set; }

StringToDbTypeConverter

Converts string to object of a specified DbType.

Signature:
public IStringToDbTypeConverter StringToDbTypeConverter { get; set; }

Table

Database table name.

Signature:
public String Table { get; set; }

Methods

AppendFilterTerms

Appends to the where clause all set terms.

Signature:
public Void AppendFilterTerms(statement, terms, match)
Parameters
Name Type Summary
statement Statement Statement to add terms.
terms List<Term> A collections of terms.
match MatchKind How to match the terms.
Exceptions
Type Summary
ArgumentNullException Thrown when statement is null.
ArgumentNullException Thrown when terms is null.
InvalidTermColumnNameException Thrown when a term.Column name does not exists within the fields collection.

AppendPartitionKeyPredicate

Appends to statement a predicate that equals field to the specified partitionKeyValue.

Signature:
protected Void AppendPartitionKeyPredicate(statement, field, partitionKeyValue)
Remarks

The predicate is appended only if it does not exists.

Parameters
Name Type Summary
statement Statement The Statement to append the predicate to.
field Field A Field to filter by.
partitionKeyValue Object The actual value of the partition key.
Exceptions
Type Summary
ArgumentNullException Thrown when statement is null.
ArgumentNullException Thrown when field is null.
MissingPartitionKeyException Thrown when partitionKeyValue is null.

AppendPartitionKeyPredicate

Appends to statement a predicate that equals the partition key field to the partition key property of the model.

Signature:
protected Void AppendPartitionKeyPredicate(statement, model)
Parameters
Name Type Summary
statement Statement The Statement to append the predicate to.
model IDataModel An IDataModel.
Exceptions
Type Summary
ArgumentNullException

Thrown when statement is null.

-or-

When model is null.

MissingPartitionKeyPropertyException Thrown when model does not has a partition key property.
MissingPartitionKeyException Thrown when model does not has it's the partition key property set.
InvalidOperationException Thrown when the field that maps to the partition key property cannot be found.

AppendStaticTerms

Appends to the where clause all set static terms.

Signature:
public Void AppendStaticTerms(statement, terms)
Parameters
Name Type Summary
statement Statement Statement to add terms.
terms List<StaticTerm> A collections of terms.
Exceptions
Type Summary
ArgumentNullException Thrown when statement is null.
ArgumentNullException Thrown when terms is null.
InvalidTermColumnNameException Thrown when a term.Column name does not exists within the fields collection.

BuildModelList

Builds a list of domain model objects of dataModelType from the specified reader.

Signature:
protected IEnumerable<IDataModel> BuildModelList(dataModelType, reader)
Returns

A list of domain model objects.

Parameters
Name Type Summary
dataModelType Type Type of the domain model object to retrieve.
reader IDataReader The data reader containing the database data.
Exceptions
Type Summary
ArgumentNullException Thrown when dataModelType is null.
ArgumentNullException Thrown when reader is null.

BuildModelList

Builds a list of domain model objects of dataModelType from the specified reader.

Signature:
protected IEnumerable<IDataModel> BuildModelList(dataModelType, reader, parent)
Returns

A list of domain model objects.

Parameters
Name Type Summary
dataModelType Type Type of the domain model object to retrieve.
reader IDataReader The data reader containing the database data.
parent IDataModel Parent object of the model being constructed.
Exceptions
Type Summary
ArgumentNullException Thrown when dataModelType is null.
ArgumentNullException Thrown when reader is null.

BuildModelList

Builds a list of domain model objects of from the specified SelectStatement.

Signature:
protected IEnumerable BuildModelList<T>(statement)
Returns

A list of domain model objects.

Parameters
Name Type Summary
statement SelectStatement The SelectStatement to excecute.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

BuildModelList

Builds a list of domain model objects of from the specified SelectStatement.

Signature:
protected IEnumerable BuildModelList<T>(statement, parent)
Returns

A list of domain model objects.

Parameters
Name Type Summary
statement SelectStatement The SelectStatement to excecute.
parent IDataModel The parent object of the model being constructed.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

BuildModelListAsync

Builds a list of domain model objects of from the specified SelectStatement.

Signature:
protected Task<IEnumerable> BuildModelListAsync<T>(statement)
Returns

A list of domain model objects.

Parameters
Name Type Summary
statement SelectStatement The SelectStatement to excecute.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

BuildModelListAsync

Builds a list of domain model objects of from the specified SelectStatement.

Signature:
protected Task<IEnumerable> BuildModelListAsync<T>(statement, parent)
Returns

A list of domain model objects.

Parameters
Name Type Summary
statement SelectStatement The SelectStatement to excecute.
parent IDataModel The parent object of the model being constructed.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

Delete

Deletes a record from the underlaying repository.

Signature:
public Int32 Delete(model, timestampKind, expectedTimestamp)
Returns

Amount of records affected.

Parameters
Name Type Summary
model IDataModel An IDataModel to be deleted.
timestampKind TimestampKind Kind of timestamp to apply to the WHERE clause.
expectedTimestamp DateTime Timestamp that is expected to be on the database.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingRequiredPropertyException Thrown when the object is not correctly initialized.
MissingPartitionKeyException Thrown when model does not have a PartitionKey.
ConcurrectActionMissedException Thrown when no record was affected and a timestamp kind was specified.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.

DeleteAsync

Deletes a record from the underlaying repository.

Signature:
public Task<Int32> DeleteAsync(model, timestampKind, expectedTimestamp)
Returns

Amount of records affected.

Parameters
Name Type Summary
model IDataModel An IDataModel to be deleted.
timestampKind TimestampKind Kind of timestamp to apply to the WHERE clause.
expectedTimestamp DateTime Timestamp that is expected to be on the database.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingRequiredPropertyException Thrown when the object is not correctly initialized.
MissingPartitionKeyException Thrown when model does not have a PartitionKey.
ConcurrectActionMissedException Thrown when no record was affected and a timestamp kind was specified.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.

EnsureModelConfiguration

Ensures that model is valid for multi-tenant operations.

Signature:
protected Void EnsureModelConfiguration(model)
Parameters
Name Type Summary
model IDataModel A, IDataModel to validate.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingPartitionKeyPropertyException Thrown when model does not has a partition key property.
MissingPartitionKeyException Thrown when model does not has the partition key property set.

EnsureObjectState

Ensures that this object has a valid state.

Signature:
protected Void EnsureObjectState()
Exceptions
Type Summary
MissingRequiredPropertyException Thrown when a required property is not initialized.

EnumerateModel

Enumerates an IDataModel of from the specified reader.

Signature:
protected IEnumerable EnumerateModel<T>(reader)
Returns

An enumeration of IDataModel of .

Parameters
Name Type Summary
reader IDataReader An IDataReader with the database data.
Exceptions
Type Summary
ArgumentNullException Thrown when reader is null.

EnumerateModel

Enumerates an IDataModel of from the specified reader.

Signature:
protected IEnumerable EnumerateModel<T>(reader, parent)
Returns

An enumeration of IDataModel of .

Parameters
Name Type Summary
reader IDataReader An IDataReader with the database data.
parent IDataModel Parent object of the model beeing constructed.
Exceptions
Type Summary
ArgumentNullException Thrown when reader is null.

GetModel

Gets a domain model object of dataModelType looking for it's primary key.

Signature:
public IDataModel GetModel(dataModelType, model)
Returns

An initialized data model object.

Parameters
Name Type Summary
dataModelType Type The Type of the domain model object to retrieve.
model IDataModel An IDataModel holding the primary key to look for.
Exceptions
Type Summary
ArgumentNullException

Thrown when dataModelType is null.

-or-

Thrown when model is null.

MissingPartitionKeyPropertyException Thrown when model does not has a partition key property.
MissingPartitionKeyException Thrown when model does not has the partition key property set.
MissingRequiredPropertyException Thrown when the this data service object was not properly initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModel

Gets a model object of type looking for it primary key in the underlying repository.

Signature:
public GetModel<T>(model)
Returns

An initialized data model object.

Parameters
Name Type Summary
model T An instance of the model with the primary key to look for.
Exceptions
Type Summary
ArgumentNullException Thown the model is null.
MissingPartitionKeyPropertyException Thrown when model does not has a partition key property.
MissingPartitionKeyException Thrown when model does not has the partition key property set.
MissingRequiredPropertyException Thrown when the this data service object was not properly initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelAsync

Gets a domain model object of dataModelType looking for it's primary key.

Signature:
public Task<IDataModel> GetModelAsync(dataModelType, model)
Returns

An initialized data model object.

Parameters
Name Type Summary
dataModelType Type The Type of the domain model object to retrieve.
model IDataModel An IDataModel holding the primary key to look for.
Exceptions
Type Summary
ArgumentNullException

Thrown when dataModelType is null.

-or-

Thrown when model is null.

MissingPartitionKeyPropertyException Thrown when model does not has a partition key property.
MissingPartitionKeyException Thrown when model does not has the partition key property set.
MissingRequiredPropertyException Thrown when the this data service object was not properly initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelAsync

Gets a model object of type looking for it primary key in the underlying repository.

Signature:
public Task GetModelAsync<T>(model)
Returns

An initialized data model object.

Parameters
Name Type Summary
model T An instance of the model with the primary key to look for.
Exceptions
Type Summary
ArgumentNullException Thown the model is null.
MissingPartitionKeyPropertyException Thrown when model does not has a partition key property.
MissingPartitionKeyException Thrown when model does not has the partition key property set.
MissingRequiredPropertyException Thrown when the this data service object was not properly initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelByIdentity

Gets a domain model object of dataModelType looking for it's identity property.

Signature:
public IDataModel GetModelByIdentity(dataModelType, model)
Returns

An initialized data model object.

Parameters
Name Type Summary
dataModelType Type The Type of the domain model object to retrieve.
model IDataModel An IDataModel holding the identity to look for.
Exceptions
Type Summary
ArgumentNullException

Thrown when dataModelType is null.

-or-

Thrown when model is null.

MissingPartitionKeyPropertyException Thrown when model does not has a partition key property.
MissingPartitionKeyException Thrown when model does not has the partition key property set.
MissingRequiredPropertyException Thrown when the this data service object was not properly initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelByIdentity

Gets a model object of type looking for the identity field in the underlying table.

Signature:
public GetModelByIdentity<T>(model)
Returns

An initialized data model object.

Parameters
Name Type Summary
model T An instance of the model object with the identity data.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingPartitionKeyPropertyException Thrown when model does not has a partition key property.
MissingPartitionKeyException Thrown when model does not has the partition key property set.
MissingRequiredPropertyException Thrown when a required property is not initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelByIdentityAsync

Gets a domain model object of dataModelType looking for it's identity property.

Signature:
public Task<IDataModel> GetModelByIdentityAsync(dataModelType, model)
Returns

An initialized data model object.

Parameters
Name Type Summary
dataModelType Type The Type of the domain model object to retrieve.
model IDataModel An IDataModel holding the identity to look for.
Exceptions
Type Summary
ArgumentNullException

Thrown when dataModelType is null.

-or-

Thrown when model is null.

MissingPartitionKeyPropertyException Thrown when model does not has a partition key property.
MissingPartitionKeyException Thrown when model does not has the partition key property set.
MissingRequiredPropertyException Thrown when the this data service object was not properly initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelByIdentityAsync

Gets a model object of type looking for the identity field in the underlying table.

Signature:
public Task GetModelByIdentityAsync<T>(model)
Returns

An initialized data model object.

Parameters
Name Type Summary
model T An instance of the model object with the identity data.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingPartitionKeyPropertyException Thrown when model does not has a partition key property.
MissingPartitionKeyException Thrown when model does not has the partition key property set.
MissingRequiredPropertyException Thrown when a required property is not initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetRowByIdentityStatement

Builds a SelectStatement that retrives a record looking by identity and filtering by the partition key.

Signature:
protected SelectStatement GetRowByIdentityStatement(model)
Returns

A SelectStatement to execute.

Parameters
Name Type Summary
model IDataModel An IDataModel that holds the identity.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingPartitionKeyException Thrown when model does not have a PartitionKey property or the property is not an IDataProperty.
DataServiceOperationNotSupportedException Thrown when the repository does not have an Identity column.

GetRowByPrimaryKeyStatement

Builds a SelectStatement that retrives a record looking by primary key and filtering by the partition key.

Signature:
protected SelectStatement GetRowByPrimaryKeyStatement(model)
Returns

A SelectStatement to execute.

Parameters
Name Type Summary
model IDataModel An IDataModel that holds the primary key.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingPartitionKeyException Thrown when model does not have a PartitionKey property or the property is not an IDataProperty.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

Insert

Inserts a record into the underlaying repository.

Signature:
public Int32 Insert(model)
Returns

Amount of records affected.

Parameters
Name Type Summary
model IDataModel An IDataModel to be inserted.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingRequiredPropertyException Thrown when the object is not correctly initialized.
MissingPartitionKeyException Thrown when model does not have a PartitionKey.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.

InsertAsync

Inserts a record into the underlaying repository.

Signature:
public Task<Int32> InsertAsync(model)
Returns

Amount of records affected.

Parameters
Name Type Summary
model IDataModel An IDataModel to be inserted.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingRequiredPropertyException Thrown when the object is not correctly initialized.
MissingPartitionKeyException Thrown when model does not have a PartitionKey.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.

RunCountStatement

Run a count statement and returns the count.

Signature:
protected Int32 RunCountStatement(statement)
Parameters
Name Type Summary
statement SelectStatement The statement to run.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

RunCountStatementAsync

Run a count statement and returns the count.

Signature:
protected Task<Int32> RunCountStatementAsync(statement)
Parameters
Name Type Summary
statement SelectStatement The statement to run.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

SanitizePageNumber

Calculates the maximum page number and returns the specified page or the maximun page number if page is not valid.

Signature:
protected Int32 SanitizePageNumber(page, pageLength, totalItems)
Returns

A sanitized page number.

Parameters
Name Type Summary
page Int32 Attempted page number.
pageLength Int32 Page length.
totalItems Int32 Total items.

Update

Updates a record on the underlaying repository.

Signature:
public Int32 Update(model, timestampKind, expectedTimestamp)
Returns

Amount of records affected.

Parameters
Name Type Summary
model IDataModel An IDataModel to be updated.
timestampKind TimestampKind Kind of timestamp to apply to the WHERE clause.
expectedTimestamp DateTime Timestamp that is expected to be on the database.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingRequiredPropertyException Thrown when the object is not correctly initialized.
MissingPartitionKeyException Thrown when model does not have a PartitionKey.
ConcurrectActionMissedException Thrown when no record was affected and a timestamp kind was specified.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.

UpdateAsync

Updates a record on the underlaying repository.

Signature:
public Task<Int32> UpdateAsync(model, timestampKind, expectedTimestamp)
Returns

Amount of records affected.

Parameters
Name Type Summary
model IDataModel An IDataModel to be updated.
timestampKind TimestampKind Kind of timestamp to apply to the WHERE clause.
expectedTimestamp DateTime Timestamp that is expected to be on the database.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingRequiredPropertyException Thrown when the object is not correctly initialized.
MissingPartitionKeyException Thrown when model does not have a PartitionKey.
ConcurrectActionMissedException Thrown when no record was affected and a timestamp kind was specified.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.