Example #1
1
        public void TestConfigureRelativePathViaBuilder()
        {
            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);
        }
Example #2
0
        public void ConfigurationWatcherTestOnSqlMapConfig()
        {
            //string fileName = @"..\..\Maps\MSSQL\SqlClient\Account.xml";

               			ConfigureHandler handler = new ConfigureHandler(MyHandler);

            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.ConfigureAndWatch(_fileName, handler);

            // test that the mapper was correct build
            Assert.IsNotNull(mapper);

            FileInfo fi = Resources.GetFileInfo(_fileName);
            fi.LastWriteTime = DateTime.Now;

            fi.Refresh();

            // Let's give a small bit of time for the change to propagate.
            // The ConfigWatcherHandler class has a timer which
            // waits for 500 Millis before delivering
            // the event notification.
            System.Threading.Thread.Sleep(600);

            Assert.IsTrue(_hasChanged);

            _hasChanged = false;
        }
Example #3
0
 /// <summary>
 /// 实例化SqlMap对象
 /// </summary>
 /// <param name="mapperName">通常.config文件</param>
 /// <returns></returns>
 public static ISqlMapper GetMapper(string mapperName)
 {
     if (string.IsNullOrEmpty(mapperName))
     {
         throw new Exception("MapperName为空!");
     }
     if (mapperName.ToLower().LastIndexOf(".config") == -1)
     {
         mapperName += ".config";
     }
     ISqlMapper mapper = null;
     if (dictMappers.ContainsKey(mapperName))
     {
         mapper = dictMappers[mapperName];
     }
     else
     {
         if (mapper == null)
         {
             lock (objSync)
             {
                 if (mapper == null)
                 {
                     mapper = new DomSqlMapBuilder().Configure(mapperName);
                     mapper.SessionStore = new HybridWebThreadSessionStore(mapper.Id);
                     dictMappers.Add(mapperName, mapper);
                 }
             }
         }
     }
     return mapper;
 }
Example #4
0
 public ProductService()
 {
     DomSqlMapBuilder getdombuilder = new DomSqlMapBuilder();
     if(getdombuilder!=null)
         ProductService._getsqlmapper = getdombuilder.Configure() as SqlMapper;
     _getsqlManager = Mapper.Instance();
 }
Example #5
0
        /// <summary>
        /// 模块加载处理。
        /// </summary>
        /// <param name="builder">Autofac容器</param>
        protected override void Load(ContainerBuilder builder)
        {
            // 注册IBatisNet。
            builder.Register(c =>
                {
                    var sqlMapBuilder = new DomSqlMapBuilder();

                    return sqlMapBuilder.Configure(HttpContext.Current.Server.MapPath("~/App_Data/IBatisNet/MSSQL/SqlConfig-Reader.xml"));
                })
                .As<ISqlMapper>()
                .SingleInstance();

            builder.Register(c => new SqlMapperManager(c.Resolve<ISqlMapper>()))
                .SingleInstance();

            builder.Register(c => new Persistence {SqlMapperManager = c.Resolve<SqlMapperManager>()})
                .InstancePerLifetimeScope();

            // 注册基于SQL Server的DynamicQueryProvider
            builder.Register(c => new IBatisNetMSSQLDynamicQueryProvider(c.Resolve<ISqlMapper>()))
                .As<DynamicQueryProvider>()
                .InstancePerLifetimeScope();

            // 注册DynamicQuery
            builder.Register(c => new DynamicQuery { Provider = c.Resolve<DynamicQueryProvider>() })
                .InstancePerLifetimeScope();
        }
Example #6
0
        /// <summary>
        /// 实例化SqlMap对象
        /// </summary>
        /// <param name="mapperName"></param>
        /// <returns></returns>
        public static ISqlMapper GetMapper(string mapperName)
        {
            if (string.IsNullOrEmpty(mapperName))
                throw new ArgumentNullException("GetMapper: 配置文件不能为空");

            if (mapperName.ToLower().LastIndexOf(".config") == -1)
                mapperName += ".config";

            ISqlMapper mapper = null;
            if (dictMappers.ContainsKey(mapperName))
            {
                mapper = dictMappers[mapperName];
            }
            else
            {
                if (mapper != null)
                    return mapper;

                lock (objSync)
                {
                    if (mapper == null)
                    {
                        string ConfigFile = string.Empty;
                        string ConfigRoot = SystemConfigManager.GetConfigRootDir();
                        ConfigFile = String.Format("{0}\\MyBatis\\ConnectionString\\", ConfigRoot);
                        mapper = new DomSqlMapBuilder().Configure(ConfigFile + mapperName);
                        mapper.SessionStore = new HybridWebThreadSessionStore(mapper.Id);
                        dictMappers.Add(mapperName, mapper);
                    }
                }
            }

            return mapper;
        }
Example #7
0
		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 IBatisNetIntegration 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()));
			}
		}
Example #8
0
        protected static void InitMapper()
        {
            ConfigureHandler handler = new ConfigureHandler(Configure);
            DomSqlMapBuilder builder = new DomSqlMapBuilder();

            _mapper = builder.ConfigureAndWatch(handler);
        }
Example #9
0
 /// <summary>
 /// 只在系统启动时调用一次
 /// </summary>
 public static void InitSqlMapper()
 {
     var builder = new DomSqlMapBuilder();
     var configfileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CONFIGPATH, FILENAME);
     _sqlMapper = builder.Configure(configfileName);
     Console.WriteLine("动态查询模板配置完毕");
 }
        public static ISqlMapper Build(string contextName)
        {
            DomSqlMapBuilder builder = new DomSqlMapBuilder();

            if (contextName.Length > 0)
                contextName = contextName + ".";

            Stream stream = new EmbeddedResourceHelper().GetEmbeddedFile(Assembly.GetCallingAssembly(), contextName + "sqlmap.config");
            return builder.Configure(stream);
        }
Example #11
0
 protected static void InitMapper()
 {
     ConfigureHandler handler = new ConfigureHandler(Configure);
     DomSqlMapBuilder builder = new DomSqlMapBuilder();
     /*
     XmlDocument sqlMapConfig = Resources.GetEmbeddedResourceAsXmlDocument("MamShare.Persistence.Config.SqlMap.config, MamShare.Persistence");
     _mapper = builder.Configure(sqlMapConfig);
     */
     _mapper = builder.ConfigureAndWatch("SqlMap.config",handler);
 }
Example #12
0
        /// <summary>
        /// Init the 'default' SqlMapper defined by the SqlMap.Config file.
        /// </summary>
        protected static void InitMapper()
        {
            ConfigureHandler handler = new ConfigureHandler(Configure);
            DomSqlMapBuilder builder = new DomSqlMapBuilder();
            string resourceDirectory = ConfigurationManager.AppSettings.Get("sqlmapconfig");
            string resource = InitMapXML(resourceDirectory);

            InitMapXML(resourceDirectory);

            ISqlMapper sqlmapper = builder.ConfigureAndWatch(resource, handler);

            _Mapper = sqlmapper;
        }
Example #13
0
        static CentaPostCacheRW()
        {
            try
            {
                var builder = new DomSqlMapBuilder();
                Mapper = builder.Configure("SqlMap.config") as SqlMapper;

            }
            catch (IBatisNet.DataMapper.Exceptions.DataMapperException ex)
            {
                throw ex;
            }
        }
 public static ISqlMapper GetInstance(String SqlMapConfigPath = "SqlMap.config")
 {
     if (_mapperContainer[SqlMapConfigPath] == null)
     {
         lock (syncRoot)
         {
             if (_mapperContainer[SqlMapConfigPath] == null)
             {
                 ISqlMapper _mapper = new DomSqlMapBuilder().ConfigureAndWatch(SqlMapConfigPath, MapperContainer.Configure);
                 _mapperContainer.Add(SqlMapConfigPath, _mapper);
             }
         }
     }
     return _mapperContainer[SqlMapConfigPath] as ISqlMapper;
 }
Example #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
        }
Example #16
0
 static MyIbatisNet()
 {
     if (SqlMap == null)
     {
         lock (syncObj)
         {
             if (SqlMap == null)
             {
                 Assembly assembly = Assembly.Load("Test.Respository");
                 Stream stream = assembly.GetManifestResourceStream("Test.Respository.sqlmap.config");
                 DomSqlMapBuilder builder = new DomSqlMapBuilder();
                 SqlMap = builder.Configure(stream);
             }
         }
     }
 }
Example #17
0
		/// <summary>
		/// Initialize an sqlMap
		/// </summary>
		protected static void InitSqlMap()
		{
			//DateTime start = DateTime.Now;

			ConfigureHandler handler = new ConfigureHandler( Configure );
			DomSqlMapBuilder builder = new DomSqlMapBuilder();
#if dotnet2
            sqlMap = builder.ConfigureAndWatch("sqlmap" + "_" + ConfigurationManager.AppSettings["database"] + "_"
                + ConfigurationManager.AppSettings["providerType"] + ".config", handler);
#else
			sqlMap = builder.ConfigureAndWatch( "sqlmap"+ "_" +  ConfigurationSettings.AppSettings["database"] + "_"
				+ ConfigurationSettings.AppSettings["providerType"] +".config", handler );
#endif

            //string loadTime = DateTime.Now.Subtract(start).ToString();
            //Console.WriteLine("Loading configuration time :"+loadTime);
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="properties"></param>
        /// <param name="resources"></param>
        public void Configure(NameValueCollection properties, IDictionary resources)
        {
            DomSqlMapBuilder builder = new DomSqlMapBuilder();
            XmlDocument document = null;

            try
            {
                DataSource dataSource = (DataSource) resources["DataSource"];
                bool useConfigFileWatcher = (bool) resources["UseConfigFileWatcher"];

                if (resources.Contains("resource")||resources.Contains("sqlMapConfigFile"))
                {
                    string fileName = string.Empty;
                    if (resources.Contains("resource"))
                    {
                        fileName = (string) resources["resource"];
                    }else
                    {
                        fileName = (string) resources["sqlMapConfigFile"];
                    }
                    if (useConfigFileWatcher == true)
                    {
                        ConfigWatcherHandler.AddFileToWatch( Resources.GetFileInfo( fileName ) );
                    }
                    document = Resources.GetResourceAsXmlDocument(fileName);
                }
                else if ( resources.Contains("url") )
                {
                    document = Resources.GetUrlAsXmlDocument( (string) resources["url"] );
                }
                else if ( resources.Contains("embedded") )
                {
                    document = Resources.GetEmbeddedResourceAsXmlDocument( (string) resources["embedded"] );
                }
                else
                {
                    throw new ConfigurationException("Invalid attribute on daoSessionHandler/property ");
                }
                _sqlMap = builder.Build( document, dataSource, useConfigFileWatcher, properties);
            }
            catch(Exception e)
            {
                throw new ConfigurationException(string.Format("DaoManager could not configure SqlMapDaoSessionHandler.Cause: {0}", e.Message),e);
            }
        }
Example #19
0
        protected virtual void SetUpFixture()
        {
            //DateTime start = DateTime.Now;

            DomSqlMapBuilder builder = new DomSqlMapBuilder();
            #if dotnet2
            NameValueCollection properties = new NameValueCollection();
            properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection2, IBatisNet.DataMapper.Test");
            properties.Add("nullableInt", "int?");
            builder.Properties = properties;

            string fileName = "sqlmap" + "_" + ConfigurationManager.AppSettings["database"] + "_" + ConfigurationManager.AppSettings["providerType"] + ".config";
            #else
            NameValueCollection properties = new NameValueCollection();
            properties.Add("collection2Namespace","IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test");
            properties.Add("nullableInt", "int");
            builder.Properties = properties;

            string fileName = "sqlmap" + "_" + ConfigurationSettings.AppSettings["database"] + "_" + ConfigurationSettings.AppSettings["providerType"] + ".config";
            #endif
            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);
        }
Example #20
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);
        }
Example #21
0
 /// <summary>
 /// Init the 'default' SqlMapper defined by the SqlMap.Config file.
 /// </summary>
 public static void InitMapper()
 {
     ConfigureHandler handler = new ConfigureHandler(Configure);
     DomSqlMapBuilder builder = new DomSqlMapBuilder();
     _mapper = builder.ConfigureAndWatch("NurDocMapper.config", handler);
 }
 /// <summary>
 /// 初始化Ibatis的SqlMapper
 /// </summary>
 public static void InitMapper(string configFilePath = null)
 {
     var builder = new DomSqlMapBuilder();
     mapper = string.IsNullOrEmpty(configFilePath) ? builder.Configure() : builder.Configure(configFilePath);
     mapper.SessionStore = new HybridWebThreadSessionStore(mapper.Id);
 }
Example #23
0
        public void TestConfigureAbsolutePathViaUri()
        {
            _fileName = Resources.BaseDirectory+Path.DirectorySeparatorChar+_fileName;
            Uri uri = new Uri(_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(uri);

            Assert.IsNotNull(mapper);
        }
Example #24
0
 /// <summary>
 /// Init the 'default' SqlMapper defined by the SqlMap.Config file.
 /// </summary>
 protected static void InitMapper()
 {
     DomSqlMapBuilder builder = new DomSqlMapBuilder();
     string config = ConfigurationManager.AppSettings.Get("sqlmapconfig");
     _Mapper = builder.Configure(config);
 }
Example #25
0
 public void TestProcedure_Delete()
 {
     using (var repo = RepositoryContext.GetRepository())
     {
         var id = new DeleteProcedureClass();
         var addedcategory = repo.GetAll<Category>();
         id.ID = addedcategory[0].ID;
         var builder = new DomSqlMapBuilder();
         var configfileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config", "SqlMap.config");
         ISqlMapper mapper = builder.Configure(configfileName);
         mapper.Delete("DeleteProcedureTest", id);
     }
 }
Example #26
0
        public void TestConfigureViaStream()
        {
            // embeddedResource = "SqlMap_MSSQL_SqlClient.config, IBatisNet.DataMapper.Test";

            #if dotnet2
            Assembly assembly = Assembly.Load("IBatisNet.DataMapper.Test");
            #else
            Assembly assembly = Assembly.LoadWithPartialName ("IBatisNet.DataMapper.Test");
            #endif
            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");

            builder.Properties = properties;

            ISqlMapper mapper = builder.Configure(stream);

            Assert.IsNotNull(mapper);
        }
 /// <summary>
 /// 配置SQL映射
 /// </summary>
 /// <returns>SQL映射</returns>
 public static ISqlMapper GetMapper()
 {
     DomSqlMapBuilder builder = new DomSqlMapBuilder();
     ISqlMapper Map = builder.Configure("Config/sqlmap.config");
     return Map;
 }
Example #28
0
        public void TestConfigureAndWatchAbsolutePathWithFileSuffixViaBuilder()
        {
            _fileName = "file://"+Resources.BaseDirectory+Path.DirectorySeparatorChar+_fileName;
            ConfigureHandler handler = new ConfigureHandler(Configure);

            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.ConfigureAndWatch(_fileName, handler);

            Assert.IsNotNull(mapper);
        }