Esempio n. 1
0
        /// <summary>
        /// 目前Oracle 的批量处理只能在独立的事务中进行处理,使用的是Oracle.DataAccess.
        /// 以后Oracle 升级到11G 后再使用TransactionScope.
        /// </summary>
        /// <param name="xmlFileName"></param>
        /// <param name="sqlName"></param>
        /// <param name="lstData">实体集合类或者DataRow[]数组</param>
        public override void WriteToServer(string xmlFileName, string sqlName, System.Collections.IList lstData)
        {
            MB.Util.TraceEx.Write("准备进行Oracle批量处理!");
            if (lstData == null || lstData.Count == 0)
            {
                return;
            }
            if (this.DbTransaction != null)
            {
                writeToServer(xmlFileName, sqlName, lstData, this.DbTransaction.Connection as System.Data.Common.DbConnection);
                return;
            }

            Database db           = MB.Orm.Persistence.DatabaseHelper.CreateDatabase();
            var      oracleHelper = new SimulatedOracleHelper();
            var      cnStr        = oracleHelper.GetOracleDataAccessConnectionString(db);

            if (!oracleHelper.CheckProviderIsOracleDataAccess(db))
            {
                throw new Exception(string.Format("请配置providerName类型为Oracle.DataAccess.Client,其它类型暂不支持!"));
            }

            using (var cn = db.GetOpenConnection())
            {
                //System.Data.Common.DbConnection cn = null;
                //if (oracleHelper.CheckProviderIsOracleDataAccess(db))
                //    cn = db.GetOpenConnection(); //db.CreateConnection();
                //else
                //    cn = oracleHelper.CreateOracleConnection(cnStr);// new OracleConnection(cnStr);

                try
                {
                    writeToServer(xmlFileName, sqlName, lstData, cn.Connection);
                }
                catch (Exception ex)
                {
                    // tran.Rollback();
                    throw new MB.Util.APPException("Oracle数据库批量处理有误" + ex.Message, MB.Util.APPMessageType.SysDatabaseInfo);
                }
                finally
                {
                    try
                    {
                        //if (tran != null) {
                        //    tran.Dispose();
                        //}

                        //if (cn != null) {
                        //    cn.Close();
                        //    cn.Dispose();
                        //}
                    }
                    catch (Exception ex)
                    {
                        MB.Util.TraceEx.Write("资源释放出错!" + ex.Message);
                    }
                }
            }
            MB.Util.TraceEx.Write("结束进行Oracle批量处理!");
        }
Esempio n. 2
0
        //转换成oracle 相对应的类型.
        private object convertToOracleType(SimulatedOracleHelper oracleHelper, Type oracleDbType, System.Data.DbType dbType)
        {
            switch (dbType)
            {
            case System.Data.DbType.String:
                return(oracleHelper.GetOracleDbTypeValue(oracleDbType, "Varchar2"));

            //return OracleDbType.Varchar2;
            case System.Data.DbType.Decimal:
                return(oracleHelper.GetOracleDbTypeValue(oracleDbType, "Decimal"));

            //return OracleDbType.Decimal;
            case System.Data.DbType.Int16:
                return(oracleHelper.GetOracleDbTypeValue(oracleDbType, "Int16"));

            //return OracleDbType.Int16;
            case System.Data.DbType.Int32:
                return(oracleHelper.GetOracleDbTypeValue(oracleDbType, "Int32"));

            // return OracleDbType.Int32;
            case System.Data.DbType.Int64:
                return(oracleHelper.GetOracleDbTypeValue(oracleDbType, "Int64"));

            //return OracleDbType.Int64;
            case System.Data.DbType.Double:
                return(oracleHelper.GetOracleDbTypeValue(oracleDbType, "Double"));

            // return OracleDbType.Double;
            case System.Data.DbType.DateTime:
                return(oracleHelper.GetOracleDbTypeValue(oracleDbType, "Date"));

            //return OracleDbType.Date;
            case System.Data.DbType.Boolean:
                return(oracleHelper.GetOracleDbTypeValue(oracleDbType, "Char"));

            //return OracleDbType.Char;
            case System.Data.DbType.Binary:
                return(oracleHelper.GetOracleDbTypeValue(oracleDbType, "Blob"));

            //return OracleDbType.Blob;
            case System.Data.DbType.Byte:
                return(oracleHelper.GetOracleDbTypeValue(oracleDbType, "Byte"));

            // return OracleDbType.Byte;
            default:
                throw new MB.Util.APPException(string.Format("把DbType{0} 转换为OravleDbType 时出错,请检查相应的数据类型是否已经处理",
                                                             dbType.ToString()), MB.Util.APPMessageType.SysDatabaseInfo);
            }
            //return null;
        }
Esempio n. 3
0
        //创建DBCommand 对象.
        public System.Data.Common.DbCommand createDbCommandByXml(Database db, string xmlFileName, string sqlName, IList lstData)
        {
            SimulatedOracleHelper oh = new SimulatedOracleHelper();

            MB.Orm.Persistence.PersistenceManagerHelper pm = new PersistenceManagerHelper();
            var dbType = MB.Orm.Persistence.DatabaseHelper.GetDatabaseType(db);
            List <System.Data.Common.DbCommand> dbCmds = new List <System.Data.Common.DbCommand>();

            MB.Orm.DbSql.SqlString sqlStr = this.GetXmlSqlString(db, xmlFileName, sqlName);

            IList <SqlParamInfo> tPars = sqlStr.ParamFields;

            if (_PersistenceManagerHelper == null)
            {
                _PersistenceManagerHelper = new PersistenceManagerHelper();
            }

            var dbCmd = oh.CreateOracleCommand(_PersistenceManagerHelper.ReplaceSqlParamsByDatabaseType(db, sqlStr.SqlStr));// new OracleCommand(_PersistenceManagerHelper.ReplaceSqlParamsByDatabaseType(db, sqlStr.SqlStr));
            //dbCmd.ArrayBindCount = lstData.Count;
            List <SqlParamInfo> overcastPars = new List <SqlParamInfo>();

            oh.SetCommandArrayBindCount(dbCmd, lstData.Count);

            Type oracleDbType = oh.GetOracleDbType();
            Dictionary <string, ArrayList> pValues = paramValues(db, tPars, lstData);

            for (int i = 0; i < tPars.Count; i++)
            {
                SqlParamInfo parInfo = tPars[i];
                if (parInfo.Overcast)
                {
                    dbCmd.CommandText = pm.ReaplaceSpecString(dbCmd.CommandText, MB.Orm.DbSql.SqlShareHelper.ORACLE_PARAM_PREFIX + pm.CreateParName(db, parInfo.Name), pValues[parInfo.Name][0] == null ? null : pValues[parInfo.Name][0].ToString());
                }
                else
                {
                    var oraInfo = oh.CreateOracleParameter(parInfo.Name, convertToOracleType(oh, oracleDbType, parInfo.DbType));// new OracleParameter(parInfo.Name, convertToOracleType(parInfo.DbType));
                    oraInfo.Direction = System.Data.ParameterDirection.Input;
                    oraInfo.Value     = pValues[parInfo.Name].ToArray();
                    dbCmd.Parameters.Add(oraInfo);
                }
            }

            return(dbCmd);
        }