Exemplo n.º 1
0
        /// <summary>
        /// 执行查询,将结果集返回到一个DataSet
        /// </summary>
        /// <param name="cmdText">sql语句</param>
        /// <param name="tableMappingName">查询结果在DataSet里保存的表名数组</param>
        /// <returns>结果集</returns>
        public System.Data.DataSet QueryDataSet(string cmdText, string[] tableMappingName)
        {
            System.Data.DataSet ds = new System.Data.DataSet();
            try
            {
                DbConnection connection = (DbConnection)this.Session.Connection;
                ITransaction trans      = this.Session.Transaction;
                DbCommand    command    = connection.CreateCommand();
                command.CommandText = cmdText;
                command.CommandType = System.Data.CommandType.Text;
                // LocalSessionFactoryObject sessionfactory = GetDbProviderthis.SessionFactory as Spring.Data.NHibernate.LocalSessionFactoryObject;
                DbDataAdapter adapter = IDbProvider.CreateDataAdapter() as DbDataAdapter;
                adapter.SelectCommand = command;
                ITableMappingCollection mappingCollection = DoCreateMappingCollection(tableMappingName);
                foreach (DataTableMapping dataTableMapping in mappingCollection)
                {
                    adapter.TableMappings.Add(((ICloneable)dataTableMapping).Clone());
                }

                trans.Enlist(command);
                adapter.Fill(ds);
            }
            catch (DbException e)
            {
                ExceptionHandler.AsynchronousThreadExceptionHandler = new DbExceptionHandler();
                ExceptionHandler.AsynchronousThreadExceptionHandler.HandleException(e);
            }

            return(ds);
        }
Exemplo n.º 2
0
 protected virtual void ValidateFillWithParameterArguments(DataSet dataSet, string sql, IDbParameters parameters, ITableMappingCollection tableMapping)
 {
     ValidateFillWithParameterArguments(dataSet, sql, parameters);
     if (tableMapping == null)
     {
         throw new ArgumentNullException("tableMapping", "ITableMappingCollection for DataSet Fill operations can not be null");
     }
 }
Exemplo n.º 3
0
 protected virtual void ValidateFillArguments(DataSet dataSet, string sql,
                                              ITableMappingCollection tableMappingCollection)
 {
     ValidateFillArguments(dataSet, sql);
     if (tableMappingCollection == null)
     {
         throw new ArgumentNullException("tableMappingCollection", "ITableMappingCollection for DataSet Fill operations can not be null");
     }
 }
Exemplo n.º 4
0
        public int DataTableUpdate(DataTable dataTable,
                                   ITableMappingCollection mappingCollection,
                                   CommandType insertCommandtype, string insertSql, IDbParameters insertParameters,
                                   CommandType updateCommandtype, string updateSql, IDbParameters updateParameters,
                                   CommandType deleteCommandtype, string deleteSql, IDbParameters deleteParameters,
                                   IDataAdapterSetter dataAdapterSetter)
        {
            //TODO - refactor to remove cut-n-pasted code.
            IDbCommand insertCommand = null;
            if (insertSql != null)
            {
                insertCommand = DbProvider.CreateCommand();
                insertCommand.CommandType = insertCommandtype;
                insertCommand.CommandText = insertSql;
                ParameterUtils.CopyParameters(insertCommand, insertParameters);
            }
            IDbCommand updateCommand = null;
            if (updateSql != null)
            {
                updateCommand = DbProvider.CreateCommand();
                updateCommand.CommandType = updateCommandtype;
                updateCommand.CommandText = updateSql;
                ParameterUtils.CopyParameters(updateCommand, updateParameters);
            }
            IDbCommand deleteCommand = null;
            if (deleteSql != null)
            {
                deleteCommand = DbProvider.CreateCommand();
                deleteCommand.CommandType = deleteCommandtype;
                deleteCommand.CommandText = deleteSql;
                ParameterUtils.CopyParameters(deleteCommand, deleteParameters);
            }

            int returnVal = (int)Execute(new DataAdapterUpdateCallback(dataTable, mappingCollection,
                                                                       insertCommand, updateCommand, deleteCommand, null));

            if (insertSql != null)
            {
                ParameterUtils.CopyParameters(insertParameters, insertCommand);
            }
            if (updateSql != null)
            {
                ParameterUtils.CopyParameters(updateParameters, updateCommand);
            }
            if (deleteSql != null)
            {
                ParameterUtils.CopyParameters(deleteParameters, deleteCommand);
            }
            return returnVal;
        }
Exemplo n.º 5
0
 public virtual int DataSetUpdate(DataSet dataSet,
                                  ITableMappingCollection tableMapping,
                                  IDbCommand insertCommand,
                                  IDbCommand updateCommand,
                                  IDbCommand deleteCommand,
                                  IDataAdapterSetter dataAdapterSetter)
 {
     ValidateUpdateArguments(dataSet, tableMapping);
     return (int)Execute(new DataAdapterUpdateCallback(dataSet,
                                                       tableMapping,
                                                       insertCommand,
                                                       updateCommand,
                                                       deleteCommand,
                                                       dataAdapterSetter));
 }
 internal static Exception TablesIndexInt32(int index, ITableMappingCollection collection)
 {
     return CollectionIndexInt32(index, collection.GetType(), collection.Count);
 }
Exemplo n.º 7
0
 public DataAdapterUpdateWithCommandBuilderCallback(DataTable dataTable,
                                                    object commandBuilder,
                                                    ITableMappingCollection mappingCollection,
                                                    CommandType selectCommandType,
                                                    string selectSql,
                                                    IDbParameters selectParameters,
                                                    IDataAdapterSetter dataAdapterSetter)
 {
     containsDataSet = false;
     this.dataTable = dataTable;
     this.commandBuilder = commandBuilder;
     this.mappingCollection = mappingCollection;
     this.selectCommandType = selectCommandType;
     this.selectSql = selectSql;
     this.selectParameters = selectParameters;
     this.dataAdapterSetter = dataAdapterSetter;
 }
Exemplo n.º 8
0
 public DataAdapterFillCallback(DataTable dataTable,
                                CommandType commandType,
                                string sql,
                                ITableMappingCollection mappingCollection,
                                IDataAdapterSetter dataAdapterSetter,
                                IDataSetFillLifecycleProcessor fillLifecycleProcessor,
                                IDbParameters parameters)
 {
     containsDataSet = false;
     this.dataTable = dataTable;
     this.commandType = commandType;
     this.sql = sql;
     this.mappingCollection = mappingCollection;
     this.dataAdapterSetter = dataAdapterSetter;
     this.fillLifecycleProcessor = fillLifecycleProcessor;
     this.parameters = parameters;
 }
Exemplo n.º 9
0
        public virtual int DataSetFill(DataSet dataSet, CommandType commandType, string sql,
                                       ITableMappingCollection tableMapping,
                                       IDataAdapterSetter setter,
                                       IDataSetFillLifecycleProcessor fillLifecycleProcessor)
        {
            ValidateFillArguments(dataSet, sql, tableMapping);
            return (int)Execute(new DataAdapterFillCallback(dataSet,
                                                            commandType, sql,
                                                            tableMapping, setter, fillLifecycleProcessor, null));

        }
Exemplo n.º 10
0
 public virtual DataSet DataSetCreateWithParams(CommandType commandType, string sql,
                                                IDbParameters parameters,
                                                ITableMappingCollection tableMapping,
                                                IDataAdapterSetter dataAdapterSetter,
                                                IDataSetFillLifecycleProcessor fillLifecycleProcessor)
 {
     DataSet dataSet = CreateDataSet();
     DataSetFillWithParameters(dataSet, commandType, sql, parameters, tableMapping, dataAdapterSetter, fillLifecycleProcessor);
     return dataSet;
 }
Exemplo n.º 11
0
 public virtual DataSet DataSetCreateWithParams(CommandType commandType, string sql,
                                                IDbParameters parameters,
                                                ITableMappingCollection tableMapping)
 {
     DataSet dataSet = CreateDataSet();
     DataSetFillWithParameters(dataSet, commandType, sql, parameters, tableMapping);
     return dataSet;
 }
Exemplo n.º 12
0
 public virtual DataSet DataSetCreate(CommandType commandType, string sql,
                                      ITableMappingCollection tableMapping,
                                      IDataAdapterSetter setter,
                                      IDataSetFillLifecycleProcessor fillLifecycleProcessor)
 {
     DataSet dataSet = CreateDataSet();
     DataSetFill(dataSet, commandType, sql, tableMapping, setter, fillLifecycleProcessor);
     return dataSet;
 }
Exemplo n.º 13
0
 public virtual DataSet DataSetCreate(CommandType commandType, string sql,
                                      ITableMappingCollection tableMapping)
 {
     DataSet dataSet = CreateDataSet();
     DataSetFill(dataSet, commandType, sql, tableMapping);
     return dataSet;
 }
Exemplo n.º 14
0
        public void FillTypedDataSet(string storedProcedure, List <IDbDataParameter> parameters, ref DataSet ds, Type datasetType, ITableMappingCollection tableMapCollection)
        {
            //Dataset specific initialization
            if (ds == null)
            {
                ds = (DataSet)Activator.CreateInstance(datasetType);
            }
            try
            {
                //Establish Connection and command
                IDbCommand dbCmd = InitializeCommandAndConnection(ref parameters, storedProcedure);

                IDbDataAdapter da = GetAdapter();

                da.SelectCommand = dbCmd;
                foreach (ITableMapping tableMap in tableMapCollection)
                {
                    da.TableMappings.Add(new System.Data.Common.DataTableMapping(tableMap.SourceTable, tableMap.DataSetTable));
                }

                _connection.Open();
                da.Fill(ds);
                _connection.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Error getting data.", ex);
            }
        }
Exemplo n.º 15
0
 protected virtual void ValidateUpdateArguments(DataSet dataSet, ITableMappingCollection tableMapping)
 {
     if (dataSet == null)
     {
         throw new ArgumentNullException("dataSet", "DataSet argument can not be null for update operation");
     }
     if (tableMapping == null)
     {
         throw new ArgumentNullException("tableMapping", "TableMappings for DataSet Update operation can not be null");
     }
 }
Exemplo n.º 16
0
 protected virtual void ValidateUpdateWithCommandBuilderArguments(DataSet dataSet, ITableMappingCollection tableMapping, string selectSql)
 {
     if (dataSet == null)
     {
         throw new ArgumentNullException("dataSet", "DataSet can not be null for update operation");
     }
     if (tableMapping == null)
     {
         throw new ArgumentNullException("tableMapping", "TableMapping for DataSet Update operation can not be null");
     }
     if (selectSql == null)
     {
         throw new ArgumentNullException("selectSql", "SelectSql for DataSet Update operations can not be null");
     }
 }
Exemplo n.º 17
0
 public virtual int DataSetFillWithParameters(DataSet dataSet, CommandType commandType, string sql,
                                              IDbParameters parameters,
                                              ITableMappingCollection tableMapping)
 {
     ValidateFillWithParameterArguments(dataSet, sql, parameters, tableMapping);
     return (int)Execute(new DataAdapterFillCallback(dataSet,
                                                     commandType, sql,
                                                     tableMapping, null, null, parameters));
 }
Exemplo n.º 18
0
 public DataAdapterUpdateCallback(DataTable dataTable,
                                  ITableMappingCollection mappingCollection,
                                  IDbCommand insertCommand,
                                  IDbCommand updateCommand,
                                  IDbCommand deleteCommand,
                                  IDataAdapterSetter dataAdapterSetter)
 {
     containsDataSet = false;
     this.dataTable = dataTable;
     this.mappingCollection = mappingCollection;
     this.insertCommand = insertCommand;
     this.updateCommand = updateCommand;
     this.deleteCommand = deleteCommand;
     this.dataAdapterSetter = dataAdapterSetter;
 }
Exemplo n.º 19
0
 public virtual int DataSetFillWithParameters(DataSet dataSet, CommandType commandType, string sql,
                                              IDbParameters parameters,
                                              ITableMappingCollection tableMapping,
                                              IDataAdapterSetter dataAdapterSetter,
                                              IDataSetFillLifecycleProcessor fillLifecycleProcessor)
 {
     ValidateFillWithParameterArguments(dataSet, sql, parameters, tableMapping);
     return (int)Execute(new DataAdapterFillCallback(dataSet,
                                                     commandType, sql,
                                                     tableMapping, dataAdapterSetter, fillLifecycleProcessor, parameters));
 }
Exemplo n.º 20
0
 internal static Exception TablesIndexInt32(int index, ITableMappingCollection collection)
 {
     return(CollectionIndexInt32(index, collection.GetType(), collection.Count));
 }
Exemplo n.º 21
0
 public virtual int DataSetUpdateWithCommandBuilder(DataSet dataSet,
                                                    CommandType commandType,
                                                    string selectSql,
                                                    IDbParameters selectParameters,
                                                    ITableMappingCollection mappingCollection,
                                                    IDataAdapterSetter dataAdapterSetter)
 {
     ValidateUpdateWithCommandBuilderArguments(dataSet, mappingCollection, selectSql);
     return (int)Execute(new DataAdapterUpdateWithCommandBuilderCallback(dataSet,
                                                                         DbProvider.CreateCommandBuilder(),
                                                                         mappingCollection,
                                                                         commandType,
                                                                         selectSql,
                                                                         selectParameters,
                                                                         dataAdapterSetter));
 }