Exemplo n.º 1
0
        public BaseSqlMapDao()
        {
            //DomSqlMapBuilder builder = new DomSqlMapBuilder(true);
            //sqlMap = builder.Configure();

            Assembly assembly = Assembly.Load("IBatisNetDemo");
            Stream   stream   = assembly.GetManifestResourceStream("IBatisNetDemo.sqlmap.config");

            DomSqlMapBuilder builder = new DomSqlMapBuilder();

            sqlMap = builder.Configure(stream);
        }
Exemplo n.º 2
0
        public Class1()
        {
            //string fileName = "sqlMap.config";
            //DomSqlMapBuilder builder = new DomSqlMapBuilder();
            //ISqlMapper mapper = builder.Configure(fileName);


            Assembly assembly = Assembly.Load("BioA.SqlMaps");
            Stream   stream   = assembly.GetManifestResourceStream("BioA.SqlMaps.SqlMap.config");

            DomSqlMapBuilder builder = new DomSqlMapBuilder();
            ISqlMapper       mapper  = builder.Configure(stream);
        }
Exemplo n.º 3
0
        public void TestConfigureRelativePath()
        {
            DomSqlMapBuilder builder = new DomSqlMapBuilder();

            NameValueCollection properties = new NameValueCollection();

            properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test");
            properties.Add("nullableInt", "int");
            builder.Properties = properties;

            ISqlMapper mapper = builder.Configure(_fileName);

            Assert.IsNotNull(mapper);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 针对视图查询使用
        /// </summary>
        /// <returns></returns>
        protected static void NewInitMapper(string path)
        {
            XmlDocument XD = readdatabase(path);

            ConfigureHandler handler = new ConfigureHandler(Configure);
            DomSqlMapBuilder builder = new DomSqlMapBuilder();

            //_mapper = builder.ConfigureAndWatch(DefaultConfig.LISMap, handler);
            _newmapper = builder.Configure(XD);
            //连接串解密
            // _mapper.DataSource.ConnectionString = _mapper.DataSource.ConnectionString.Replace(conn, new DESEncrypt().Decrypt(conn.Trim(), key));

            //  _mapper.DataSource.ConnectionString = info.Connectionstring;
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected override object InternalCreate(CreationContext context)
        {
            String fileName         = (String)Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_FILE];
            bool   isEmbedded       = (bool)Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_EMBEDDED];
            String connectionString = (String)Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_CONNECTION_STRING];

            DomSqlMapBuilder domSqlMapBuilder = new DomSqlMapBuilder();
            ISqlMapper       sqlMapper;

            if (isEmbedded)
            {
                XmlDocument sqlMapConfig = Resources.GetEmbeddedResourceAsXmlDocument(fileName);
                sqlMapper = domSqlMapBuilder.Configure(sqlMapConfig);
            }
            else
            {
                sqlMapper = domSqlMapBuilder.Configure(fileName);
            }

            if (connectionString != null && connectionString.Length > 0)
            {
                sqlMapper.DataSource.ConnectionString = connectionString;
            }

            if (sqlMapper != null)
            {
                return(sqlMapper);
            }
            else
            {
                throw new FacilityException(
                          string.Format("The IBatisNet Facility was unable to successfully configure SqlMapper ID [{0}] with File [{1}] that was set to Embedded [{2}]."
                                        , Model.Name, Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_FILE].ToString()
                                        , Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_EMBEDDED].ToString()));
            }
        }
Exemplo n.º 6
0
        public static ISqlMapper GetMapper()
        {
            if (mapper == null)
            {
                Assembly myAssembly = Assembly.Load("DataAccess");

                using (Stream stream = myAssembly.GetManifestResourceStream("DataAccess.IBatisConfig.SqlMap.config"))
                {
                    DomSqlMapBuilder d = new DomSqlMapBuilder(); //初始化一个DomSqlMapBuilder
                    mapper = d.Configure(stream);                //调用Configure方法并指定配置文件的名称,返回一个SqlMapper
                }
            }

            return(mapper);
        }
Exemplo n.º 7
0
        public static ISqlMapper GenerateMapper(this Assembly callingAssembly)
        {
            var assemblyName = callingAssembly.ManifestModule.Name;

            Logger.Debug($"Generating an ISqlMapper for {assemblyName}");

            var builderProps = new NameValueCollection();

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["MyBatisDBServerName"]))
            {
                builderProps.Add("servername", ConfigurationManager.AppSettings["MyBatisDBServerName"]);
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["MyBatisDBUserName"]))
            {
                builderProps.Add("username", ConfigurationManager.AppSettings["MyBatisDBUserName"]);
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["MyBatisDBPassword"]))
            {
                builderProps.Add("password", ConfigurationManager.AppSettings["MyBatisDBPassword"]);
            }

            if (ConfigurationManager.ConnectionStrings["MyBatisDBConnection"] != null)
            {
                builderProps.Add("connectionString", ConfigurationManager.ConnectionStrings["MyBatisDBConnection"].ConnectionString);
                builderProps.Add("provider", ConfigurationManager.ConnectionStrings["MyBatisDBConnection"].ProviderName);
            }

            var builder = new DomSqlMapBuilder {
                ValidateSqlMapConfig = true, Properties = builderProps
            };
            var resources = callingAssembly.GetManifestResourceNames();

            try
            {
                var cfgResourceName = resources.Single(x => x.StartsWith($"{callingAssembly.GetName().Name}.SqlMap.") && x.EndsWith(".config"));
                var mapper          = builder.Configure(callingAssembly.GetManifestResourceStream(cfgResourceName));

                return(mapper);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, $"There was a problem when generating the SqlMapper for {assemblyName}");

                throw;
            }
        }
Exemplo n.º 8
0
        public void InsertProduct(Product getproduct)
        {
            ISqlMapper       _getsqlManager = null;
            DomSqlMapBuilder getdombuilder  = new DomSqlMapBuilder();

            if (getdombuilder != null)
            {
                ProductService._getsqlmapper = getdombuilder.Configure() as SqlMapper;
            }
            _getsqlManager = Mapper.Instance();

            if (_getsqlManager != null)
            {
                _getsqlManager.Insert("InsertProduct", getproduct);
            }
        }
Exemplo n.º 9
0
 static MyIbatisNet()
 {
     if (SqlMap == null)
     {
         lock (syncObj)
         {
             if (SqlMap == null)
             {
                 Assembly         assembly = Assembly.Load("SqlMaps");
                 Stream           stream   = assembly.GetManifestResourceStream("SqlMaps.sqlmap.config");
                 DomSqlMapBuilder builder  = new DomSqlMapBuilder();
                 SqlMap = builder.Configure(stream);
             }
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// ¹¹Ô캯Êý
 /// </summary>
 public SqlMapClientTemplate()
 {
     if (mapper == null)
     {
         lock (syncObj)
         {
             if (mapper == null)
             {
                 Assembly         assembly = Assembly.Load("SqlMaps");
                 Stream           stream   = assembly.GetManifestResourceStream("SqlMaps.sqlmap.config");
                 DomSqlMapBuilder builder  = new DomSqlMapBuilder();
                 mapper = builder.Configure(stream);
             }
         }
     }
 }
Exemplo n.º 11
0
        public void TestConfigureAbsolutePath()
        {
            _fileName = Resources.BaseDirectory + Path.DirectorySeparatorChar + _fileName;

            DomSqlMapBuilder builder = new DomSqlMapBuilder();

            NameValueCollection properties = new NameValueCollection();

            properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test");
            properties.Add("nullableInt", "int");
            builder.Properties = properties;

            ISqlMapper mapper = builder.Configure(_fileName);

            Assert.IsNotNull(mapper);
        }
Exemplo n.º 12
0
        protected virtual void SetUpFixture()
        {
            //DateTime start = DateTime.Now;

            DomSqlMapBuilder    builder    = new DomSqlMapBuilder();
            NameValueCollection properties = new NameValueCollection();

            properties.Add("collection2Namespace", "SqlBatis.DataMapper.Test.Domain.LineItemCollection2, SqlBatis.DataMapper.Test");
            properties.Add("nullableInt", "int?");
            ChildSetupProperties(properties);
            builder.Properties = properties;

            string fileName = "sqlmap" + "_" + Configuration["database"] + "_" + Configuration["providerType"] + ".config";

            try
            {
                sqlMap = builder.Configure(fileName);
            }
            catch (Exception ex)

            {
                Exception e = ex;
                while (e != null)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace.ToString());
                    e = e.InnerException;
                }
                throw;
            }

            if (sqlMap.DataSource.DbProvider.Name.IndexOf("PostgreSql") >= 0)
            {
                BaseTest.ConvertKey = new KeyConvert(Lower);
            }
            else if (sqlMap.DataSource.DbProvider.Name.IndexOf("oracle") >= 0)
            {
                BaseTest.ConvertKey = new KeyConvert(Upper);
            }
            else
            {
                BaseTest.ConvertKey = new KeyConvert(Normal);
            }

            //			string loadTime = DateTime.Now.Subtract(start).ToString();
            //			Console.WriteLine("Loading configuration time :"+loadTime);
        }
Exemplo n.º 13
0
        public void TestConfigureAbsolutePathWithFileSuffixViaBuilder()
        {
            _fileName = "file://" + Resources.BaseDirectory + Path.DirectorySeparatorChar + _fileName;

            DomSqlMapBuilder builder = new DomSqlMapBuilder();

            NameValueCollection properties = new NameValueCollection();

            properties.Add("collection2Namespace", "Mybatis.Mapper.Test.Domain.LineItemCollection, Mybatis.Mapper.Test");
            properties.Add("nullableInt", "int");
            ChildSetupProperties(properties);
            builder.Properties = properties;

            ISqlMapper mapper = builder.Configure(_fileName);

            Assert.IsNotNull(mapper);
        }
Exemplo n.º 14
0
        //https://stackoverflow.com/questions/21925935/dyanamically-change-the-database-name-in-sqlmapconfig-xml-file
        public static ISqlMapper CreateMapperFromEmbeddedResource(string resourceSqlMap, string resourceProviders, string resourceQueryRootPath,
                                                                  string connectionString, string providerName)
        {
            // Load the config file (embedded resource in assembly).
            XmlDocument xmlDoc = IBatisNet.Common.Utilities.Resources.GetEmbeddedResourceAsXmlDocument(resourceSqlMap);

            // providers
            if (string.IsNullOrEmpty(resourceProviders) == false)
            {
                xmlDoc["sqlMapConfig"]["providers"].Attributes["embedded"].InnerText = resourceProviders;
            }

            // database(provider)
            if (string.IsNullOrEmpty(providerName) == false)
            {
                xmlDoc["sqlMapConfig"]["database"]["provider"].Attributes["name"].InnerText = providerName;
            }

            // database(connectionString)
            if (string.IsNullOrEmpty(connectionString) == false)
            {
                xmlDoc["sqlMapConfig"]["database"]["dataSource"].Attributes["connectionString"].InnerText = connectionString;
            }

            // sqlMaps
            if (string.IsNullOrEmpty(resourceQueryRootPath) == false)
            {
                var sqlMapsRoot      = xmlDoc["sqlMapConfig"]["sqlMaps"];
                var queryFileNames   = IBatisNetMapperHelper.GetAllQueryXML(resourceQueryRootPath);
                var defaultNamespace = Assembly.GetExecutingAssembly().GetName().Name;
                foreach (var queryFile in queryFileNames)
                {
                    System.Xml.XmlElement elem = xmlDoc.CreateElement("sqlMap", sqlMapsRoot.NamespaceURI);
                    elem.SetAttribute("embedded", $"{queryFile}, {defaultNamespace}");
                    sqlMapsRoot.AppendChild(elem);
                }
            }

            // Instantiate Ibatis mapper using the XmlDocument via a Builder,
            // instead of Ibatis using the config file.
            DomSqlMapBuilder builder        = new DomSqlMapBuilder();
            ISqlMapper       ibatisInstance = builder.Configure(xmlDoc);

            return(ibatisInstance);
        }
Exemplo n.º 15
0
        public CustomerService()
        {
            #region Define the Base Map
            _getDaoManager = ServiceConfig.GetInstance().DaoManager;
            if (_getDaoManager != null)
            {
                _getbaseService = _getDaoManager.GetDao(typeof(CustomerMapDao)) as  ICustomerDao;
            }
            #endregion

            #region Use SqlMaper Style to Soleuv this Connection Problem f**k =---

            DomSqlMapBuilder getbuilder = new DomSqlMapBuilder();
            if (getbuilder != null)
            {
                _getsqlmaper = getbuilder.Configure() as SqlMapper;
            }
            #endregion
        }
Exemplo n.º 16
0
        public SqlMapperFactory(string configFileOfDataAccess)
        {
            _configFileOfDataAccess = configFileOfDataAccess;

            try
            {
                DomSqlMapBuilder builderReader = new DomSqlMapBuilder();
                _sqlMapperReader = builderReader.Configure(@"Config\SqlMapReader.config");//_configFileOfDataAccess);
                _sqlMapperReader.SessionStore = new HybridWebThreadSessionStore(_sqlMapperReader.Id);

                DomSqlMapBuilder builderWriter = new DomSqlMapBuilder();
                _sqlMapperWriter = builderWriter.Configure(@"Config\SqlMapWriter.config");
                _sqlMapperWriter.SessionStore = new HybridWebThreadSessionStore(_sqlMapperWriter.Id);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Constructor with sqlConfig file.
        /// </summary>
        /// <param name="sqlMapConfig">SQLConfig file</param>
        public SQLMap(string sqlMapConfig)
        {
            logger.Start("Constructor SQLMap - Map du lieu");
            try
            {
                logger.Param("Loi kết nối tới database", sqlMapConfig);
                //create SQLMapper from SQLConfig file
                this.str_SqlMapConfig = sqlMapConfig;
                DomSqlMapBuilder cDom = new DomSqlMapBuilder();
                sqlMap = (SqlMapper)cDom.Configure(sqlMapConfig);
                sqlMap.DataSource.ConnectionString = EncryptData(sqlMap.DataSource.ConnectionString);

                logger.Info("Creating SQLMapper sucessfull");
            }
            catch (SqlException ex)
            {
                logger.Error(ex.ToString());
            }
            logger.End("Constructor SQLMap");
        }
Exemplo n.º 18
0
        /// <summary>
        /// Constructor with sqlConfig file.
        /// </summary>
        /// <param name="sqlMapConfig">SQLConfig file</param>
        public SQLMapEmployee(string sqlMapConfig)
        {
            logger.Start("Constructor SQLMap - Map du lieu");
            try
            {
                logger.Param("Loi kết nối tới database", sqlMapConfig);
                //create SQLMapper from SQLConfig file
                this.str_SqlMapConfig = sqlMapConfig;
                DomSqlMapBuilder cDom = new DomSqlMapBuilder();
                sqlMapEmployee = (SqlMapper)cDom.Configure(sqlMapConfig);
                sqlMapEmployee.DataSource.ConnectionString = "Data Source=10.84.0.31;Initial Catalog=MixHRM_2017;User ID= HRM;Password=HRm11@122";//EncryptData(sqlMapEmployee.DataSource.ConnectionString);

                logger.Info("Creating SQLMapper sucessfull");
            }
            catch (SqlException ex)
            {
                logger.Error(ex.ToString());
            }
            logger.End("Constructor SQLMap");
        }
Exemplo n.º 19
0
        public void TestConfigureViaStream()
        {
            // embeddedResource = "bin.Debug.SqlMap_MSSQL_SqlClient.config, IBatisNet.DataMapper.Test";

            Assembly assembly = Assembly.Load("IBatisNet.DataMapper.Test");
            Stream   stream   = assembly.GetManifestResourceStream("IBatisNet.DataMapper.Test.SqlMap_MSSQL_SqlClient.config");

            DomSqlMapBuilder builder = new DomSqlMapBuilder();

            NameValueCollection properties = new NameValueCollection();

            properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test");
            properties.Add("nullableInt", "int");
            ChildSetupProperties(properties);
            builder.Properties = properties;

            ISqlMapper mapper = builder.Configure(stream);

            Assert.IsNotNull(mapper);
        }
Exemplo n.º 20
0
        protected ISqlMapper GetLocalSqlMap()
        {
            if (sqlMapper == null)
            {
                DomSqlMapBuilder builder = new DomSqlMapBuilder();
                sqlMapper = builder.Configure();
            }

            try
            {
                var isStart = sqlMapper.IsSessionStarted;
            }
            catch (Exception)
            {
                ISessionStore ss = new HybridWebThreadSessionStore(sqlMapper.Id);
                sqlMapper.SessionStore = ss;
            }

            return(sqlMapper);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Generates a Mapper object for your DAL.
        /// </summary>
        /// <param name="callingAssembly">The assembly that contains the actual Maps and SqlMap.config file.</param>
        /// <param name="builderProperties">A NameValueCollection comprised of all the variables you have specified within your SqlMap.config file.</param>
        public static ISqlMapper GenerateMapper(this Assembly callingAssembly, NameValueCollection builderProperties)
        {
            var assemblyName = callingAssembly.ManifestModule.Name;

            var builder = new DomSqlMapBuilder {
                ValidateSqlMapConfig = true, Properties = builderProperties
            };
            var resources = callingAssembly.GetManifestResourceNames();

            try
            {
                var cfgResourceName = resources.Single(x => x.StartsWith($"{callingAssembly.GetName().Name}.SqlMap.") && x.EndsWith(".config"));
                var mapper          = builder.Configure(callingAssembly.GetManifestResourceStream(cfgResourceName));

                return(mapper);
            }
            catch (Exception ex)
            {
                throw new Exception($"There was a problem when generating the SqlMapper for {assemblyName}.  See inner exception for details.", ex);
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// 单例模式
 /// </summary>
 static MyBatis()
 {
     if (SqlMapInterface == null)
     {
         lock (syncObj)
         {
             if (SqlMapInterface == null)
             {
                 Assembly         assembly = Assembly.Load("ERM.DAL");
                 Stream           stream   = assembly.GetManifestResourceStream("ERM.DAL.sqlmap.config");
                 DomSqlMapBuilder builder  = new DomSqlMapBuilder();
                 try
                 {
                     SqlMapInterface = builder.Configure(stream);
                     SqlMapInterface.DataSource.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Environment.CurrentDirectory + "\\db\\ERMDB.mdb;Persist Security Info=False";
                 }
                 catch
                 {
                 }
             }
         }
     }
 }
Exemplo n.º 23
0
        protected static void InitMapper()
        {
            ConfigureHandler handler = new ConfigureHandler(Configure);
            DomSqlMapBuilder builder = new DomSqlMapBuilder();

#if SQLMAP_ENCRYPT
            string encrypt_sqlmap_file = System.Configuration.ConfigurationManager.AppSettings["encrypt_sqlmap_file"];
            string fileMap             = HttpContext.Current.Server.MapPath(string.Format("~\\{0}", encrypt_sqlmap_file));
            if (!File.Exists(fileMap))
            {
                throw new FileNotFoundException(encrypt_sqlmap_file);
            }
            StreamReader tr    = new StreamReader(fileMap, Encoding.UTF8);
            string       input = tr.ReadToEnd();
            tr.Close();
            string site_key            = System.Configuration.ConfigurationManager.AppSettings["site_key"] + ".key";
            string output              = CryptManager.DecryptString(site_key, input);
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.LoadXml(output);
            _Mapper = builder.Configure(doc);
#else
            _Mapper = builder.ConfigureAndWatch("MSSqlMap.config", handler);
#endif
        }
Exemplo n.º 24
0
        private void InitSqlMap()
        {
            try
            {
                writeBuilder = new DomSqlMapBuilder();
                writeBuilder.ValidateSqlMapConfig = false;
                writeMapper = writeBuilder.Configure(this.sqlMapConfig);
                writeMapper.SessionStore = new HybridWebThreadSessionStore(writeMapper.Id);
                writeMapper.DataSource.ConnectionString = this.writeConnection;

                if (!string.IsNullOrEmpty(this.readOnlyConnection))
                {
                    readOnlyBuilder = new DomSqlMapBuilder();
                    readOnlyBuilder.ValidateSqlMapConfig = false;
                    readOnlyMapper = readOnlyBuilder.Configure(this.sqlMapConfig);
                    readOnlyMapper.SessionStore = new HybridWebThreadSessionStore(readOnlyMapper.Id);
                    readOnlyMapper.DataSource.ConnectionString = this.readOnlyConnection;
                }
            }
            catch (Exception ex)
            {
                throw new DataAccessException(string.Format("SqlMap对象创建失败,读写库:{0},只读库:{1},配置文件:{2}", ex, this.writeConnection, this.readOnlyConnection, this.sqlMapConfig.InnerXml), ex);
            }
        }
Exemplo n.º 25
0
        public TrunktypeDao()
        {
            DomSqlMapBuilder sqlMapBuilder = new DomSqlMapBuilder();

            this.sqlMapper = sqlMapBuilder.Configure("etc/mybatis.sqlmap.cfg.xml");
        }
Exemplo n.º 26
0
        public VvehiclenumberDao()
        {
            DomSqlMapBuilder sqlMapBuilder = new DomSqlMapBuilder();

            this.sqlMapper = sqlMapBuilder.Configure("etc/mybatis.sqlmap.cfg.xml");
        }
Exemplo n.º 27
0
        public CorporationmetadataDao()
        {
            DomSqlMapBuilder sqlMapBuilder = new DomSqlMapBuilder();

            this.sqlMapper = sqlMapBuilder.Configure("etc/mybatis.sqlmap.cfg.xml");
        }
        public UspUpdateRoleHasRightsDao()
        {
            DomSqlMapBuilder sqlMapBuilder = new DomSqlMapBuilder();

            this.sqlMapper = sqlMapBuilder.Configure("etc/mybatis.sqlmap.cfg.xml");
        }
 public IBatisNet.DataMapper.ISqlMapper Configure(XmlDocument mapConfig)
 {
     return(_builder.Configure(mapConfig));
 }
Exemplo n.º 30
0
        public VspeciallineinfoDao()
        {
            DomSqlMapBuilder sqlMapBuilder = new DomSqlMapBuilder();

            this.sqlMapper = sqlMapBuilder.Configure("etc/mybatis.sqlmap.cfg.xml");
        }