Ejemplo n.º 1
0
        /// <summary>
        /// Processes the SQL map element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessSqlMapElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Attributes.ContainsKey(ConfigConstants.ATTRIBUTE_URI))
            {
                string    uri      = element.Attributes[ConfigConstants.ATTRIBUTE_URI];
                IResource resource = ResourceLoaderRegistry.GetResource(uri);

                Contract.Assert.That(resource, Is.Not.Null).When("process Resource in ConfigurationInterpreter");

                using (resource)
                {
                    IConfiguration setting = configurationStore.Settings[ConfigConstants.ATTRIBUTE_VALIDATE_SQLMAP];
                    if (setting != null)
                    {
                        bool mustValidate = false;
                        Boolean.TryParse(setting.Value, out mustValidate);
                        if (mustValidate)
                        {
                            XmlDocument document = new XmlDocument();
                            document.Load(resource.Stream);
                            SchemaValidator.Validate(document.ChildNodes[1], "SqlMap.xsd");
                        }
                    }

                    resource.Stream.Position = 0;
                    using (XmlTextReader reader = new XmlTextReader(resource.Stream))
                    {
                        using (XmlMappingProcessor processor = new XmlMappingProcessor())
                        {
                            processor.Process(reader, configurationStore);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void ResultMap_configuration_via_code_should_override_file_configuration()
        {
            string    uri      = "assembly://Apache.Ibatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            // Before have 4 properties
            IConfigurationEngine engine = new DefaultConfigurationEngine();

            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();
            IConfiguration resultMap = engine.ConfigurationStore.GetResultMapConfiguration("Account.Category-result");

            Assert.That(resultMap.Children.Count, Is.EqualTo(3));

            // With code configuration override have only 1 properties
            engine = new DefaultConfigurationEngine();
            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));
            engine.RegisterModule(new AccountModule());

            engine.BuildMapperFactory();

            resultMap = engine.ConfigurationStore.GetResultMapConfiguration("Account.Category-result");
            Assert.That(resultMap.Children.Count, Is.EqualTo(1));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultConfigurationEngine"/> class.
        /// </summary>
        public DefaultConfigurationEngine()
        {
            configurationStore   = new DefaultConfigurationStore();
            configurationSetting = new ConfigurationSetting();
            modules = new List <IModule>();

            ResourceLoaderRegistry.ResetEventHandler();
            ResourceLoaderRegistry.LoadFileResource += FileResourceEventHandler;
        }
Ejemplo n.º 4
0
        public void JsonInterpreter_test()
        {
            IConfigurationStore store = new DefaultConfigurationStore();
            string    uri             = "SqlMap.config.Json";
            IResource resource        = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationInterpreter interpreter = new JsonInterpreter(resource);

            interpreter.ProcessResource(store);
        }
Ejemplo n.º 5
0
        public void Test_XmlConfigurationInterpreter_via_FilePath_WithoutProtocol()
        {
            string uri = "SqlMap_Test_Configure.config";
            IConfigurationStore store = new DefaultConfigurationStore();

            IConfigurationInterpreter interpreter = new XmlConfigurationInterpreter(
                ResourceLoaderRegistry.GetResource(uri));

            interpreter.ProcessResource(store);

            CheckResource(store);
        }
Ejemplo n.º 6
0
        public void Test_DefaultConfigurationEngine_via_File_Resource()
        {
            string    uri      = "file://~/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationEngine engine = new DefaultConfigurationEngine();

            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();

            CheckResource(engine.ConfigurationStore);
        }
Ejemplo n.º 7
0
        public void Test_DefaultConfigurationEngine_via_Assembly_Resource()
        {
            string    uri      = "assembly://MyBatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationEngine engine = new DefaultConfigurationEngine();

            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();

            CheckResource(engine.ConfigurationStore);
        }
Ejemplo n.º 8
0
        public void Test_XmlConfigurationInterpreter_via_AssemblyUri()
        {
            string uri = "assembly://MyBatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";

            IConfigurationStore store = new DefaultConfigurationStore();

            IConfigurationInterpreter interpreter = new XmlConfigurationInterpreter(
                ResourceLoaderRegistry.GetResource(uri));

            interpreter.ProcessResource(store);

            CheckResource(store);
        }
Ejemplo n.º 9
0
        public void SetUpFixture()
        {
            string    uri      = "file://~/SqlMap.event.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            ConfigurationSetting setting = new ConfigurationSetting();
            IConfigurationEngine engine  = new DefaultConfigurationEngine(setting);

            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));
            engine.RegisterModule(new EventModule());

            IMapperFactory mapperFactory = engine.BuildMapperFactory();

            sessionFactory = engine.ModelStore.SessionFactory;
            dataMapper     = ((IDataMapperAccessor)mapperFactory).DataMapper;
        }
Ejemplo n.º 10
0
        public void Should_contains_ResultMap_DocumentBook_with_5_properties()
        {
            string    uri      = "assembly://Apache.Ibatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationEngine engine = new DefaultConfigurationEngine();

            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();

            IConfiguration resultMap = engine.ConfigurationStore.GetResultMapConfiguration("Document.book");

            Assert.That(resultMap.Children.Count, Is.EqualTo(4));

            //Console.WriteLine(engine.ModelStore.ToString());
        }
Ejemplo n.º 11
0
        public void Should_contains_statement_GetAllAccountsOrderByName_with_2_child()
        {
            string    uri      = "assembly://Apache.Ibatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationEngine engine = new DefaultConfigurationEngine();

            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();

            IConfiguration statement = engine.ConfigurationStore.GetStatementConfiguration("GetAllAccountsOrderByName");

            Assert.That(statement.Children.Count, Is.EqualTo(2));

            //Console.WriteLine(engine.ConfigurationStore);
        }
        /// <summary>
        /// Adds an XML sql map configuration item.
        /// </summary>
        /// <param name="uri">A URI to XML data.</param>
        /// <param name="validate">Validate the XML sqlMap file using SqlMap.xsd</param>
        /// <example>
        /// <code>
        /// &lt;sqlMaps&gt;
        ///  &lt;sqlMap uri="file://../../Maps/Account.xml"/&gt;
        /// &lt;/sqlMaps&gt;
        /// </code>
        /// </example>
        public void AddSqlMap(string uri, bool validate)
        {
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            using (resource)
            {
                if (validate)
                {
                    XmlDocument document = new XmlDocument();
                    document.Load(resource.Stream);
                    SchemaValidator.Validate(document.ChildNodes[1], "SqlMap.xsd");
                }

                resource.Stream.Position = 0;
                using (XmlTextReader reader = new XmlTextReader(resource.Stream))
                {
                    using (XmlMappingProcessor processor = new XmlMappingProcessor())
                    {
                        processor.Process(reader, configurationStore);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public void Can_plug_HybridWebThreadSessionStore()
        {
            string    uri      = "assembly://Apache.Ibatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            ConfigurationSetting setting = new ConfigurationSetting();

            setting.SessionStore             = new HybridWebThreadSessionStore("test");
            setting.ValidateMapperConfigFile = true;

            IConfigurationEngine engine = new DefaultConfigurationEngine(setting);

            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            IMapperFactory mapperFactory = engine.BuildMapperFactory();
            IDataMapper    dataMapper    = ((IDataMapperAccessor)mapperFactory).DataMapper;

            Account account = dataMapper.QueryForObject <Account>("GetAccountViaResultClass", 1);

            Assert.AreEqual(1, account.Id, "account.Id");
            Assert.AreEqual("Joe", account.FirstName, "account.FirstName");
            Assert.AreEqual("Dalton", account.LastName, "account.LastName");
            Assert.AreEqual("*****@*****.**", account.EmailAddress, "account.EmailAddress");
        }
Ejemplo n.º 14
0
        public void Should_contains_ParameterMap_OrderInsertExtend_with_10_properties()
        {
            string    uri      = "assembly://Apache.Ibatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationEngine engine = new DefaultConfigurationEngine();

            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();

            IConfiguration parameterMap = engine.ConfigurationStore.GetParameterMapConfiguration("Order.insert-extend");

            Assert.That(parameterMap.Children.Count, Is.EqualTo(10));

            int index = parameterMap.Children.FindIndex(
                delegate(IConfiguration paramater)
                { return(paramater.Id == "CardNumber"); }
                );

            Assert.That(index, Is.EqualTo(5));

            //Console.WriteLine(engine.ConfigurationStore);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonInterpreter"/> class.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 public JsonInterpreter(string fileName)
     : base(ResourceLoaderRegistry.GetResource(fileName))
 {
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AbstractInterpreter"/> class
 /// from a file path.
 /// </summary>
 /// <param name="fileName">The filename.</param>
 public AbstractInterpreter(string fileName)
     : this(ResourceLoaderRegistry.GetResource(fileName))
 {
 }