//****************************************************************************************************** // ITableOperations.cs - Gbtc // // Copyright © 2016, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this // file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 05/12/2016 - J. Ritchie Carroll // Generated original version of source code. // //****************************************************************************************************** using System; using System.Collections; using System.Data; namespace GSF.Data.Model { /// /// Defines a common interface for implementations of . /// public interface ITableOperations { /// /// Gets the table name defined for the modeled table, includes any escaping as defined in model. /// string TableName { get; } /// /// Gets the table name defined for the modeled table without any escape characters. /// /// /// A table name will only be escaped if the model requested escaping with the . /// string UnescapedTableName { get; } /// /// Gets flag that determines if modeled table has a primary key that is an identity field. /// bool HasPrimaryKeyIdentityField { get; } /// /// Gets or sets delegate used to handle table operation exceptions. /// /// /// When exception handler is provided, table operations will not throw exceptions for database calls, any /// encountered exceptions will be passed to handler for processing. Otherwise, exceptions will be thrown /// on the call stack. /// Action ExceptionHandler { get; set; } /// /// Gets or sets flag that determines if field names should be treated as case sensitive. Defaults to false. /// /// /// In cases where modeled table fields have applied , this flag will be used /// to properly update escaped field names that may be case sensitive. /// bool UseCaseSensitiveFieldNames { get; set; } /// /// Queries database and returns modeled table records for the specified parameters. /// /// Field name expression used for sort order, include ASC or DESC as needed - does not include ORDER BY; defaults to primary keys. /// Record restriction to apply, if any. /// Limit of number of record to return. /// An enumerable of modeled table row instances for queried records. /// /// If no record or is provided, all rows will be returned. /// IEnumerable QueryRecords(string orderByExpression = null, RecordRestriction restriction = null, int limit = -1); /// /// Queries database and returns modeled table records for the specified sorting, paging and search parameters. /// /// Field name to order-by. /// Sort ascending flag; set to false for descending. /// Page number of records to return (1-based). /// Current page size. /// Text to search. /// An enumerable of modeled table row instances for queried records. /// /// This function is used for record paging. Primary keys are cached server-side, typically per user session, to maintain desired per-page sort order. /// IEnumerable QueryRecords(string sortField, bool ascending, int page, int pageSize, string searchText); /// /// Queries database and returns modeled table records for the specified sorting and paging parameters. /// /// Field name to order-by. /// Sort ascending flag; set to false for descending. /// Page number of records to return (1-based). /// Current page size. /// Record restriction to apply, if any. /// An enumerable of modeled table row instances for queried records. /// /// This function is used for record paging. Primary keys are cached server-side, typically per user session, to maintain desired per-page sort order. /// IEnumerable QueryRecords(string sortField, bool ascending, int page, int pageSize, RecordRestriction restriction = null); /// /// Gets the total record count for the modeled table based on search parameter. /// /// Text to search. /// Total record count for the modeled table. int QueryRecordCount(string searchText); /// /// Gets the total record count for the modeled table. /// /// Record restriction to apply, if any. /// Total record count for the modeled table. int QueryRecordCount(RecordRestriction restriction = null); /// /// Creates a new modeled table record queried from the specified . /// /// Primary keys values of the record to load. /// New modeled table record queried from the specified . object LoadRecord(params object[] primaryKeys); /// /// Creates a new modeled table record queried from the specified . /// /// of queried data to be loaded. /// New modeled table record queried from the specified . object LoadRecord(DataRow row); /// /// Deletes the record referenced by the specified . /// /// Primary keys values of the record to load. /// Number of rows affected. int DeleteRecord(params object[] primaryKeys); /// /// Deletes the specified modeled table from the database. /// /// Record to delete. /// Number of rows affected. int DeleteRecord(object record); /// /// Deletes the record referenced by the specified . /// /// of queried data to be deleted. /// Number of rows affected. int DeleteRecord(DataRow row); /// /// Deletes the records referenced by the specified . /// /// Record restriction to apply /// Number of rows affected. /// cannot be null. int DeleteRecord(RecordRestriction restriction); /// /// Updates the database with the specified modeled table . /// /// Record to update. /// Record restriction to apply, if any. /// Number of rows affected. /// /// Record restriction is only used for custom update expressions or in cases where modeled /// table has no defined primary keys. /// int UpdateRecord(object record, RecordRestriction restriction = null); /// /// Updates the database with the specified . /// /// of queried data to be updated. /// Record restriction to apply, if any. /// Number of rows affected. /// /// Record restriction is only used for custom update expressions or in cases where modeled /// table has no defined primary keys. /// int UpdateRecord(DataRow row, RecordRestriction restriction = null); /// /// Adds the specified modeled table to the database. /// /// Record to add. /// Number of rows affected. int AddNewRecord(object record); /// /// Adds the specified to the database. /// /// of queried data to be added. /// Number of rows affected. int AddNewRecord(DataRow row); /// /// Gets the primary key values from the specified . /// /// Record of data to retrieve primary keys from. /// Primary key values from the specified . object[] GetPrimaryKeys(object record); /// /// Gets the primary key values from the specified . /// /// of queried data. /// Primary key values from the specified . object[] GetPrimaryKeys(DataRow row); /// /// Gets the field names for the table; if is true, also includes any escaping as defined in model. /// /// Flag that determines if field names should include any escaping as defined in the model. /// Array of field names. /// /// A field name will only be escaped if the model requested escaping with the . /// string[] GetFieldNames(bool escaped); /// /// Get the primary key field names for the table; if is true, also includes any escaping as defined in model. /// /// Flag that determines if field names should include any escaping as defined in the model. /// Array of primary key field names. /// /// A field name will only be escaped if the model requested escaping with the . /// string[] GetPrimaryKeyFieldNames(bool escaped); /// /// Attempts to get the specified for a field. /// /// Type of attribute to attempt to get. /// Name of field to use for attribute lookup. /// Type of attribute to lookup. /// true if attribute was found; otherwise, false. bool TryGetFieldAttribute(string fieldName, out TAttribute attribute) where TAttribute : Attribute; /// /// Determines if the specified field has an associated attribute. /// /// Type of attribute to search for. /// Name of field to use for attribute lookup. /// true if field has attribute; otherwise, false. bool FieldHasAttribute(string fieldName) where TAttribute : Attribute; /// /// Gets the value for the specified field. /// /// Modeled table record. /// Field name to retrieve. /// Field value or null if field is not found. object GetFieldValue(object record, string fieldName); /// /// Gets the for the specified field. /// /// Field name to retrieve. /// Field or null if field is not found. Type GetFieldType(string fieldName); } }