You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2008/06/01 20:53:45 UTC

svn commit: r662267 - in /ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005: ./ Domain/ Fixtures/ bin/Debug/

Author: gbayon
Date: Sun Jun  1 11:53:44 2008
New Revision: 662267

URL: http://svn.apache.org/viewvc?rev=662267&view=rev
Log:
Show use of a JsonInterpreter which support configuration file in JSON format
such as
{
  "sqlMapConfig": {
      "properties": {"@uri": "file://../../database.config"},
      
      "settings": {
          "setting": {"@useStatementNamespaces": "${useStatementNamespaces}"},
          "setting": {"@cacheModelsEnabled": "true"},
          "setting": {"@validateSqlMap": "false"},
          "setting": {"@useReflectionOptimizer": "true"}
          },
          
      "providers": {"@uri": "file://providers.config"},

      "database":{
          "provider": {"@name": "sqlServer2.0"},
          "dataSource": {"@name": "iBatisNet","@connectionString": "data source=${datasource};database=${database};Integrated Security=SSPI;"}
          },
          
      "typeHandlers":{
          "typeHandler": {"@type": "string","@callback": "AnsiStringTypeHandler"}
          },
          
      "sqlMaps":{
          "sqlMap": {"@uri": "file://../../${directory}/DocumentModule.xml"},
          "sqlMap": {"@uri": "file://../../${directory}/AccountModule.xml"}
          }
    }
}

Added:
    ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/JsonInterpreter.cs   (with props)
    ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.dll   (with props)
    ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.licence.txt
    ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap.config.json
Modified:
    ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj
    ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ConfigureTest.cs
    ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap_StatementOnly.config

Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj?rev=662267&r1=662266&r2=662267&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj Sun Jun  1 11:53:44 2008
@@ -28,6 +28,7 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Newtonsoft.Json, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
     <Reference Include="nunit.framework, Version=2.4.4.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
     <Reference Include="System" />
     <Reference Include="System.configuration" />
@@ -36,6 +37,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Domain\JsonInterpreter.cs" />
     <Compile Include="Domain\SimpleSqlSource.cs" />
     <Compile Include="Domain\SqlSourceWithInlineParameter.cs" />
     <Compile Include="Domain\SqlSourceWithParameter.cs" />
@@ -148,6 +150,8 @@
     <EmbeddedResource Include="Maps\Account.xml" />
   </ItemGroup>
   <ItemGroup>
+    <Content Include="bin\Debug\Newtonsoft.Json.dll" />
+    <Content Include="bin\Debug\Newtonsoft.Json.licence.txt" />
     <Content Include="cool.jpg">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
@@ -207,6 +211,7 @@
     <Content Include="Scripts\ps_SelectAccountWithOutPutParam.sql" />
     <Content Include="Scripts\ps_SelectAllAccount.sql" />
     <None Include="App.config" />
+    <None Include="bin\Debug\SqlMap.config.json" />
     <None Include="DataBase.config" />
     <None Include="Scripts\ps_SelectByIdList.sql" />
     <Content Include="Scripts\ps_SelectLineItem.sql" />

Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/JsonInterpreter.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/JsonInterpreter.cs?rev=662267&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/JsonInterpreter.cs (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/JsonInterpreter.cs Sun Jun  1 11:53:44 2008
@@ -0,0 +1,84 @@
+
+using System;
+using System.IO;
+using System.Xml;
+using Apache.Ibatis.Common.Resources;
+using Apache.Ibatis.DataMapper.Configuration;
+using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config;
+using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config.Xml;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Converters;
+
+
+// http://www.codeplex.com/Json
+
+namespace Apache.Ibatis.DataMapper.SqlClient.Test.Domain
+{
+	public class JsonInterpreter : AbstractInterpreter 
+	{
+	    private readonly XmlConfigurationInterpreter xmlInterpreter = null;
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="JsonInterpreter"/> class.
+        /// </summary>
+        /// <param name="source">The <see cref="IResource"/>.</param>
+        public JsonInterpreter(IResource source) : base(source)
+        {
+            string xmlContents = string.Empty;
+            using(source)
+            {
+                JsonReader reader = new JsonTextReader(new StreamReader(source.Stream));
+                reader.Read();
+
+                XmlNodeConverter toXml = new XmlNodeConverter();
+                XmlDocument xmlDoc = (XmlDocument)toXml.ReadJson(reader, typeof(XmlDocument));
+                xmlContents = xmlDoc.OuterXml;
+                reader.Close();                
+            }
+
+            IResource resource = new StaticContentResource(xmlContents);
+
+            xmlInterpreter = new XmlConfigurationInterpreter(resource);
+        }
+
+        /// <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))
+        {}
+
+
+	    //private XmlInterpreter _xmlInterpreter = new XmlInterpreter();
+
+
+
+        ///// <summary>
+        ///// Gets or sets the kernel.
+        ///// </summary>
+        ///// <value>The kernel.</value>
+        //public IKernel Kernel
+        //{
+        //    get { return _xmlInterpreter.Kernel ; }
+        //    set { _xmlInterpreter.Kernel = value; }
+        //}
+
+        //public override void ProcessResource(IResource source, IConfigurationStore store)
+        //{
+
+        //    XmlNodeConverter toXml = new XmlNodeConverter();
+        //    JsonReader reader = new JsonReader(source.GetStreamReader());
+        //    reader.Read();
+        //    XmlDocument xmlDoc = (XmlDocument)toXml.ReadJson(reader, typeof(XmlDocument));
+        //    StaticContentResource xmlSource = new StaticContentResource(xmlDoc.OuterXml);
+
+        //    _xmlInterpreter.ProcessResource(xmlSource, store);
+        //}
+
+        public override void ProcessResource(IConfigurationStore store)
+        {
+            xmlInterpreter.ProcessResource(store);
+        }
+    }
+}

Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/JsonInterpreter.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/JsonInterpreter.cs
------------------------------------------------------------------------------
    svn:keywords = Id LastChangedDate LastChangedBy

Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ConfigureTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ConfigureTest.cs?rev=662267&r1=662266&r2=662267&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ConfigureTest.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ConfigureTest.cs Sun Jun  1 11:53:44 2008
@@ -7,6 +7,7 @@
 using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config;
 using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config.Xml;
 using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config.Xml.Processor;
+using Apache.Ibatis.DataMapper.SqlClient.Test.Domain;
 using NUnit.Framework;
 using NUnit.Framework.SyntaxHelpers;
 
@@ -30,6 +31,19 @@
         }
         #endregion 
 	    
+        [Test]
+        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);
+        }
+
+
         /// <summary>
         /// Test XmlProcessorTest
         /// </summary>

Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.dll
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.dll?rev=662267&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.dll
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.licence.txt
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.licence.txt?rev=662267&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.licence.txt (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.licence.txt Sun Jun  1 11:53:44 2008
@@ -0,0 +1,11 @@
+License:
+
+Copyright (c) 2007 James Newton-King
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 
+to deal in the Software without restriction, 
+including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file

Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap.config.json
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap.config.json?rev=662267&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap.config.json (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap.config.json Sun Jun  1 11:53:44 2008
@@ -0,0 +1,28 @@
+{
+  "sqlMapConfig": {
+      "properties": {"@uri": "file://../../database.config"},
+      
+      "settings": {
+          "setting": {"@useStatementNamespaces": "${useStatementNamespaces}"},
+          "setting": {"@cacheModelsEnabled": "true"},
+          "setting": {"@validateSqlMap": "false"},
+          "setting": {"@useReflectionOptimizer": "true"}
+          },
+          
+      "providers": {"@uri": "file://providers.config"},
+
+      "database":{
+          "provider": {"@name": "sqlServer2.0"},
+          "dataSource": {"@name": "iBatisNet","@connectionString": "data source=${datasource};database=${database};Integrated Security=SSPI;"}
+          },
+          
+      "typeHandlers":{
+          "typeHandler": {"@type": "string","@callback": "AnsiStringTypeHandler"}
+          },
+          
+      "sqlMaps":{
+          "sqlMap": {"@uri": "file://../../${directory}/DocumentModule.xml"},
+          "sqlMap": {"@uri": "file://../../${directory}/AccountModule.xml"}
+          }
+    }
+}
\ No newline at end of file

Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap_StatementOnly.config
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap_StatementOnly.config?rev=662267&r1=662266&r2=662267&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap_StatementOnly.config (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap_StatementOnly.config Sun Jun  1 11:53:44 2008
@@ -24,7 +24,6 @@
     <dataSource name="iBatisNet" connectionString="data source=${datasource};database=${database};Integrated Security=SSPI;"/>
   </database>
 
-
   <typeHandlers>
     <typeHandler type="string" callback="AnsiStringTypeHandler"/>
   </typeHandlers>