#region Apache Notice
/*****************************************************************************
* $Revision: 374175 $
* $LastChangedDate: 2006-02-19 12:37:22 +0100 (Sun, 19 Feb 2006) $
* $LastChangedBy: gbayon $
*
* iBATIS.NET Data Mapper
* Copyright (C) 2006/2005 - The Apache Software Foundation
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
********************************************************************************/
#endregion
#region using
using System;
using System.Collections;
#if dotnet2
using System.Collections.Generic;
#endif
using System.Collections.Specialized;
using System.Data;
using IBatisNet.Common;
using IBatisNet.Common.Utilities.Objects;
using IBatisNet.Common.Utilities.Objects.Members;
using IBatisNet.DataMapper.Configuration.Cache;
using IBatisNet.DataMapper.Configuration.ParameterMapping;
using IBatisNet.DataMapper.Configuration.ResultMapping;
using IBatisNet.DataMapper.DataExchange;
using IBatisNet.DataMapper.Exceptions;
using IBatisNet.DataMapper.MappedStatements;
using IBatisNet.DataMapper.SessionStore;
using IBatisNet.DataMapper.TypeHandlers;
using IBatisNet.Common.Utilities;
#endregion
namespace IBatisNet.DataMapper
{
///
/// Contract for an
///
public interface ISqlMapper
{
///
/// Name used to identify the the
///
string Id { get; }
///
/// Allow to set a custom session store like the
///
/// Set it after the configuration and before use of the
///
/// sqlMapper.SessionStore = new HybridWebThreadSessionStore( sqlMapper.Id );
///
ISessionStore SessionStore { set; }
///
/// Gets a value indicating whether this instance is session started.
///
///
/// true if this instance is session started; otherwise, false.
///
bool IsSessionStarted { get; }
///
/// Returns the DalSession instance
/// currently being used by the SqlMap.
///
ISqlMapSession LocalSession { get; }
///
/// Gets the DB helper parameter cache.
///
/// The DB helper parameter cache.
DBHelperParameterCache DBHelperParameterCache { get; }
///
/// Creates a new SqlMapSession that will be used to query the data source.
///
/// A new session
ISqlMapSession CreateSqlMapSession();
///
/// A flag that determines whether cache models were enabled
/// when this SqlMap was built.
///
bool IsCacheModelsEnabled { get;set; }
///
/// Factory for DataExchange objects
///
DataExchangeFactory DataExchangeFactory { get; }
///
/// The TypeHandlerFactory
///
TypeHandlerFactory TypeHandlerFactory { get; }
///
/// The meta factory for object factory
///
IObjectFactory ObjectFactory { get; }
///
/// The factory which build
///
AccessorFactory AccessorFactory { get; }
///
/// Get a ParameterMap by name
///
/// The name of the ParameterMap
/// The ParameterMap
ParameterMap GetParameterMap(string name);
///
/// Adds a (named) ParameterMap.
///
/// the ParameterMap to add
void AddParameterMap(ParameterMap parameterMap);
///
/// Gets a ResultMap by name
///
/// The name of the result map
/// The ResultMap
IResultMap GetResultMap(string name);
///
/// Adds a (named) ResultMap
///
/// The ResultMap to add
void AddResultMap(IResultMap resultMap);
///
/// The ParameterMap collection
///
HybridDictionary ParameterMaps { get; }
///
/// The ResultMap collection
///
HybridDictionary ResultMaps { get; }
///
/// The MappedStatements collection
///
HybridDictionary MappedStatements { get; }
///
/// Gets a cache by name
///
/// The name of the cache to get
/// The cache object
CacheModel GetCache(string name);
///
/// Adds a (named) cache.
///
/// The cache to add
void AddCache(CacheModel cache);
///
/// Adds a (named) MappedStatement.
///
/// The key name
/// The statement to add
void AddMappedStatement(string key, IMappedStatement mappedStatement);
///
/// Begins the transaction.
///
///
ISqlMapSession BeginTransaction();
///
/// Begins the transaction.
///
/// if set to true [open connection].
///
ISqlMapSession BeginTransaction(bool openConnection);
///
/// Begins the transaction.
///
/// The connection string.
///
ISqlMapSession BeginTransaction(string connectionString);
///
/// Begins the transaction.
///
/// if set to true [open new connection].
/// The isolation level.
///
ISqlMapSession BeginTransaction(bool openNewConnection, IsolationLevel isolationLevel);
///
/// Begins the transaction.
///
/// The connection string.
/// if set to true [open new connection].
/// The isolation level.
///
ISqlMapSession BeginTransaction(string connectionString, bool openNewConnection, IsolationLevel isolationLevel);
///
/// Begins the transaction.
///
/// The isolation level.
///
ISqlMapSession BeginTransaction(IsolationLevel isolationLevel);
///
/// Begins the transaction.
///
/// The connection string.
/// The isolation level.
///
ISqlMapSession BeginTransaction(string connectionString, IsolationLevel isolationLevel);
///
/// Closes the connection.
///
void CloseConnection();
///
/// Commits the transaction.
///
/// if set to true [close connection].
void CommitTransaction(bool closeConnection);
///
/// Commits the transaction.
///
void CommitTransaction();
///
/// Gets or sets the data source.
///
/// The data source.
IDataSource DataSource { get; set; }
///
/// Executes a Sql DELETE statement.
/// Delete returns the number of rows effected.
///
/// The name of the statement to execute.
/// The parameter object.
/// The number of rows effected.
int Delete(string statementName, object parameterObject);
///
/// Flushes all cached objects that belong to this SqlMap
///
void FlushCaches();
///
/// Gets the data cache stats.
///
///
string GetDataCacheStats();
///
/// Gets a MappedStatement by name
///
/// The id of the statement
/// The MappedStatement
IMappedStatement GetMappedStatement(string id);
///
/// Executes a Sql INSERT statement.
/// Insert is a bit different from other update methods, as it
/// provides facilities for returning the primary key of the
/// newly inserted row (rather than the effected rows). This
/// functionality is of course optional.
///
/// The parameter object is generally used to supply the input
/// data for the INSERT values.
///
/// The name of the statement to execute.
/// The parameter object.
/// The primary key of the newly inserted row.
/// This might be automatically generated by the RDBMS,
/// or selected from a sequence table or other source.
///
object Insert(string statementName, object parameterObject);
///
/// Opens the connection.
///
///
ISqlMapSession OpenConnection();
///
/// Opens the connection.
///
/// The connection string.
///
ISqlMapSession OpenConnection(string connectionString);
///
/// Alias to QueryForMap, .NET spirit.
/// Feature idea by Ted Husted.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The property of the result object to be used as the key.
/// The property of the result object to be used as the value (or null)
/// A IDictionary (Hashtable) of object containing the rows keyed by keyProperty.
///If a transaction is not in progress, or the database throws an exception.
IDictionary QueryForDictionary(string statementName, object parameterObject, string keyProperty, string valueProperty);
///
/// Alias to QueryForMap, .NET spirit.
/// Feature idea by Ted Husted.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The property of the result object to be used as the key.
/// A IDictionary (Hashtable) of object containing the rows keyed by keyProperty.
IDictionary QueryForDictionary(string statementName, object parameterObject, string keyProperty);
///
/// Executes a Sql SELECT statement that returns data to populate
/// a number of result objects.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// An Ilist object used to hold the objects.
/// A List of result objects.
void QueryForList(string statementName, object parameterObject, IList resultObject);
///
/// Executes a Sql SELECT statement that returns data to populate
/// a number of result objects.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// A List of result objects.
IList QueryForList(string statementName, object parameterObject);
///
/// Executes the SQL and retuns all rows selected.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The number of rows to skip over.
/// The maximum number of rows to return.
/// A List of result objects.
IList QueryForList(string statementName, object parameterObject, int skipResults, int maxResults);
///
/// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
/// in the keyProperty parameter. The value at each key will be the entire result object.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The property of the result object to be used as the key.
/// A IDictionary (Hashtable) of object containing the rows keyed by keyProperty.
IDictionary QueryForMap(string statementName, object parameterObject, string keyProperty);
///
/// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
/// in the keyProperty parameter. The value at each key will be the value of the property specified
/// in the valueProperty parameter. If valueProperty is null, the entire result object will be entered.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The property of the result object to be used as the key.
/// The property of the result object to be used as the value (or null)
/// A IDictionary (Hashtable) of object containing the rows keyed by keyProperty.
///If a transaction is not in progress, or the database throws an exception.
IDictionary QueryForMap(string statementName, object parameterObject, string keyProperty, string valueProperty);
///
/// Runs a query with a custom object that gets a chance to deal
/// with each row as it is processed.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The property of the result object to be used as the key.
/// The property of the result object to be used as the value (or null)
///
/// A IDictionary (Hashtable) of object containing the rows keyed by keyProperty.
///If a transaction is not in progress, or the database throws an exception.
IDictionary QueryForMapWithRowDelegate(string statementName, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate);
///
/// Executes a Sql SELECT statement that returns a single object of the type of the
/// resultObject parameter.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// An object of the type to be returned.
/// The single result object populated with the result set data.
object QueryForObject(string statementName, object parameterObject, object resultObject);
///
/// Executes a Sql SELECT statement that returns that returns data
/// to populate a single object instance.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The single result object populated with the result set data.
object QueryForObject(string statementName, object parameterObject);
///
/// Executes the SQL and retuns a subset of the results in a dynamic PaginatedList that can be used to
/// automatically scroll through results from a database table.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL
/// The maximum number of objects to store in each page
/// A PaginatedList of beans containing the rows
[Obsolete("This method will be remove in future version.", false)]
PaginatedList QueryForPaginatedList(string statementName, object parameterObject, int pageSize);
///
/// Runs a query for list with a custom object that gets a chance to deal
/// with each row as it is processed.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
///
/// A List of result objects.
IList QueryWithRowDelegate(string statementName, object parameterObject, RowDelegate rowDelegate);
///
/// Rolls the back transaction.
///
void RollBackTransaction();
///
/// Rolls the back transaction.
///
/// if set to true [close connection].
void RollBackTransaction(bool closeConnection);
///
/// Executes a Sql UPDATE statement.
/// Update can also be used for any other update statement type,
/// such as inserts and deletes. Update returns the number of
/// rows effected.
///
/// The parameter object is generally used to supply the input
/// data for the UPDATE values as well as the WHERE clause parameter(s).
///
/// The name of the statement to execute.
/// The parameter object.
/// The number of rows effected.
int Update(string statementName, object parameterObject);
#if dotnet2
///
/// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
/// in the keyProperty parameter. The value at each key will be the value of the property specified
/// in the valueProperty parameter. If valueProperty is null, the entire result object will be entered.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The property of the result object to be used as the key.
/// The property of the result object to be used as the value (or null)
/// A IDictionary of object containing the rows keyed by keyProperty.
///If a transaction is not in progress, or the database throws an exception.
IDictionary QueryForDictionary(string statementName, object parameterObject, string keyProperty, string valueProperty);
///
/// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
/// in the keyProperty parameter. The value at each key will be the entire result object.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The property of the result object to be used as the key.
/// A IDictionary of object containing the rows keyed by keyProperty.
IDictionary QueryForDictionary(string statementName, object parameterObject, string keyProperty);
///
/// Runs a query with a custom object that gets a chance to deal
/// with each row as it is processed.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The property of the result object to be used as the key.
/// The property of the result object to be used as the value (or null)
/// A delegate called once per row in the QueryForDictionary method>
/// A IDictionary (Hashtable) of object containing the rows keyed by keyProperty.
///If a transaction is not in progress, or the database throws an exception.
IDictionary QueryForDictionary(string statementName, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate);
///
/// Executes a Sql SELECT statement that returns a single object of the type of the
/// resultObject parameter.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// An object of the type to be returned.
/// The single result object populated with the result set data.
T QueryForObject(string statementName, object parameterObject, T instanceObject);
///
/// Executes a Sql SELECT statement that returns that returns data
/// to populate a single object instance.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The single result object populated with the result set data.
T QueryForObject(string statementName, object parameterObject);
///
/// Executes a Sql SELECT statement that returns data to populate
/// a number of result objects.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// A List of result objects.
IList QueryForList(string statementName, object parameterObject);
///
/// Executes a Sql SELECT statement that returns data to populate
/// a number of result objects.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// An Ilist object used to hold the objects.
void QueryForList(string statementName, object parameterObject, IList resultObject);
///
/// Executes the SQL and retuns all rows selected.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
/// The number of rows to skip over.
/// The maximum number of rows to return.
/// A List of result objects.
IList QueryForList(string statementName, object parameterObject, int skipResults, int maxResults);
///
/// Runs a query for list with a custom object that gets a chance to deal
/// with each row as it is processed.
///
/// The parameter object is generally used to supply the input
/// data for the WHERE clause parameter(s) of the SELECT statement.
///
/// The name of the sql statement to execute.
/// The object used to set the parameters in the SQL.
///
/// A List of result objects.
IList QueryWithRowDelegate(string statementName, object parameterObject, RowDelegate rowDelegate);
#endif
}
}