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 2006/11/13 20:30:01 UTC
svn commit: r474455 - in /ibatis/trunk/cs/mapper:
IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/
IBatisNet.DataMapper.Test/NUnit/SqlMapTests/ IBatisNet.DataMapper/
IBatisNet.DataMapper/Configuration/
IBatisNet.DataMapper/Configuration/ResultMapping/ I...
Author: gbayon
Date: Mon Nov 13 11:30:00 2006
New Revision: 474455
URL: http://svn.apache.org/viewvc?view=rev&rev=474455
Log:
Fix for IBATISNET-116
Added:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/SqlDeSerializer.cs (with props)
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/DynamicAccount.xml
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultProperty.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/DynamicAccount.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/DynamicAccount.xml?view=diff&rev=474455&r1=474454&r2=474455
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/DynamicAccount.xml (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/DynamicAccount.xml Mon Nov 13 11:30:00 2006
@@ -10,6 +10,34 @@
<statements>
+ <sql id="includeComplex">
+ <dynamic prepend="where">
+ <isParameterPresent>
+ <isNotEmpty prepend="and" property="Id">
+ Account_ID = #Id#
+ </isNotEmpty>
+ <isNotEmpty prepend="and" property="FirstName">
+ Account_FirstName = #FirstName#
+ </isNotEmpty>
+ <isNotEmpty prepend="and" property="LastName">
+ Account_LastName = #LastName#
+ </isNotEmpty>
+ </isParameterPresent>
+ </dynamic>
+ </sql>
+
+ <select id="DynamicWithPrepend"
+ parameterClass="Account"
+ resultClass="Account">
+ select
+ Account_ID as Id,
+ Account_FirstName as FirstName,
+ Account_LastName as LastName,
+ Account_Email as EmailAddress
+ from Accounts
+ <include refid="includeComplex"/>
+ </select>
+
<statement id="DynamicJIRA168"
parameterClass="Query"
resultClass="Account">
@@ -400,30 +428,6 @@
<iterate open="(" close=")" conjunction="OR">
Account_ID = #[]#
</iterate>
- </isParameterPresent>
- </dynamic>
- </statement>
-
- <statement id="DynamicWithPrepend"
- parameterClass="Account"
- resultClass="Account">
- select
- Account_ID as Id,
- Account_FirstName as FirstName,
- Account_LastName as LastName,
- Account_Email as EmailAddress
- from Accounts
- <dynamic prepend="where">
- <isParameterPresent>
- <isNotEmpty prepend="and" property="Id" >
- Account_ID = #Id#
- </isNotEmpty>
- <isNotEmpty prepend="and" property="FirstName" >
- Account_FirstName = #FirstName#
- </isNotEmpty>
- <isNotEmpty prepend="and" property="LastName" >
- Account_LastName = #LastName#
- </isNotEmpty>
</isParameterPresent>
</dynamic>
</statement>
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs?view=diff&rev=474455&r1=474454&r2=474455
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/GroupByTest.cs Mon Nov 13 11:30:00 2006
@@ -19,21 +19,15 @@
/// <summary>
/// SetUp
/// </summary>
- [SetUp]
- public void SetUp()
+ [TestFixtureSetUp]
+ protected override void SetUpFixture()
{
+ base.SetUpFixture();
InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-drop.sql");
InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-schema.sql");
InitScript(sqlMap.DataSource, ScriptDirectory + "petstore-init.sql");
}
- /// <summary>
- /// TearDown
- /// </summary>
- [TearDown]
- public void TearDown()
- {
- }
/// <summary>
/// Dispose the SqlMap
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs?view=diff&rev=474455&r1=474454&r2=474455
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs Mon Nov 13 11:30:00 2006
@@ -202,6 +202,11 @@
/// </summary>
private const string XML_PARAMETERMAP = "sqlMap/parameterMaps/parameterMap";
+ /// <summary>
+ /// Token for xml path to sql elements.
+ /// </summary>
+ private const string SQL_STATEMENT = "sqlMap/statements/sql";
+
/// <summary>
/// Token for xml path to statement elements.
/// </summary>
@@ -1143,6 +1148,16 @@
#region Load statements
+ #region Sql tag
+ foreach (XmlNode xmlNode in _configScope.SqlMapDocument.SelectNodes(ApplyMappingNamespacePrefix(SQL_STATEMENT), _configScope.XmlNamespaceManager))
+ {
+ _configScope.ErrorContext.MoreInfo = "loading sql tag";
+ _configScope.NodeContext = xmlNode; // A sql tag
+
+ SqlDeSerializer.Deserialize(xmlNode, _configScope);
+ }
+ #endregion
+
#region Statement tag
Statement statement;
foreach (XmlNode xmlNode in _configScope.SqlMapDocument.SelectNodes( ApplyMappingNamespacePrefix(XML_STATEMENT), _configScope.XmlNamespaceManager))
@@ -1519,7 +1534,7 @@
data = NodeUtils.ParsePropertyTokens(data, _configScope.Properties);
SqlText sqlText;
- if ( postParseRequired)
+ if (postParseRequired)
{
sqlText = new SqlText();
sqlText.Text = data.ToString();
@@ -1531,8 +1546,25 @@
dynamic.AddChild(sqlText);
sqlBuffer.Append(data);
- }
- else
+ }
+ else if (child.Name == "include")
+ {
+ NameValueCollection prop = NodeUtils.ParseAttributes(child, _configScope.Properties);
+ string refid = NodeUtils.GetStringAttribute(prop, "refid");
+ XmlNode includeNode = (XmlNode)_configScope.SqlIncludes[refid];
+
+ if (includeNode == null)
+ {
+ String nsrefid = _configScope.ApplyNamespace(refid);
+ includeNode = (XmlNode)_configScope.SqlIncludes[nsrefid];
+ if (includeNode == null)
+ {
+ throw new ConfigurationException("Could not find SQL tag to include with refid '" + refid + "'");
+ }
+ }
+ isDynamic = ParseDynamicTags(includeNode, dynamic, sqlBuffer, isDynamic, false, statement);
+ }
+ else
{
string nodeName = child.Name;
IDeSerializer serializer = _deSerializerFactory.GetDeSerializer(nodeName);
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultProperty.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultProperty.cs?view=diff&rev=474455&r1=474454&r2=474455
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultProperty.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/ResultMapping/ResultProperty.cs Mon Nov 13 11:30:00 2006
@@ -393,7 +393,7 @@
#if dotnet2
_isGenericIList = TypeUtils.IsImplementGenericIListInterface(this.MemberType);
#endif
- _isIList = typeof (IList).IsAssignableFrom(this.MemberType);
+ _isIList = typeof(IList).IsAssignableFrom(this.MemberType);
// set the list factory
#if dotnet2
@@ -435,7 +435,7 @@
}
else
#endif
- if (typeof(IList).IsAssignableFrom(this.MemberType))
+ if (_isIList)
{
if (this.MemberType.IsArray)
{
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/SqlDeSerializer.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/SqlDeSerializer.cs?view=auto&rev=474455
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/SqlDeSerializer.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/SqlDeSerializer.cs Mon Nov 13 11:30:00 2006
@@ -0,0 +1,69 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: 469233 $
+ * $Date$
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ********************************************************************************/
+#endregion
+
+#region Using
+
+using System.Collections.Specialized;
+using System.Xml;
+using IBatisNet.Common.Exceptions;
+using IBatisNet.Common.Xml;
+using IBatisNet.DataMapper.Scope;
+
+#endregion
+
+namespace IBatisNet.DataMapper.Configuration.Serializers
+{
+ /// <summary>
+ /// Summary description for ArgumentPropertyDeSerializer.
+ /// </summary>
+ public sealed class SqlDeSerializer
+ {
+ /// <summary>
+ /// Deserialize a sql tag
+ /// </summary>
+ /// <param name="node"></param>
+ /// <param name="configScope"></param>
+ /// <returns></returns>
+ public static void Deserialize(XmlNode node, ConfigurationScope configScope)
+ {
+ NameValueCollection prop = NodeUtils.ParseAttributes(node, configScope.Properties);
+
+ string id = NodeUtils.GetStringAttribute(prop, "id");
+
+ if (configScope.UseStatementNamespaces)
+ {
+ id = configScope.ApplyNamespace(id);
+ }
+ if (configScope.SqlIncludes.Contains(id))
+ {
+ throw new ConfigurationException("Duplicate <sql>-include '" + id + "' found.");
+ }
+ else
+ {
+ configScope.SqlIncludes.Add(id, node);
+ }
+ }
+ }
+}
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/SqlDeSerializer.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/Serializers/SqlDeSerializer.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj?view=diff&rev=474455&r1=474454&r2=474455
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.20005.csproj Mon Nov 13 11:30:00 2006
@@ -255,6 +255,7 @@
<Compile Include="Configuration\Serializers\SelectDeSerializer.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Configuration\Serializers\SqlDeSerializer.cs" />
<Compile Include="Configuration\Serializers\StatementDeSerializer.cs">
<SubType>Code</SubType>
</Compile>
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj?view=diff&rev=474455&r1=474454&r2=474455
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj Mon Nov 13 11:30:00 2006
@@ -478,6 +478,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Configuration\Serializers\SqlDeSerializer.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Configuration\Serializers\StatementDeSerializer.cs"
SubType = "Code"
BuildAction = "Compile"
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs?view=diff&rev=474455&r1=474454&r2=474455
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs Mon Nov 13 11:30:00 2006
@@ -60,6 +60,8 @@
private ErrorContext _errorContext = null;
private HybridDictionary _providers = new HybridDictionary();
+ private HybridDictionary _sqlIncludes = new HybridDictionary();
+
private NameValueCollection _properties = new NameValueCollection();
private XmlDocument _sqlMapConfigDocument = null;
@@ -97,6 +99,14 @@
#region Properties
+ /// <summary>
+ /// The list of sql fragment
+ /// </summary>
+ public HybridDictionary SqlIncludes
+ {
+ get { return _sqlIncludes; }
+ }
+
/// <summary>
/// XmlNamespaceManager
/// </summary>
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd?view=diff&rev=474455&r1=474454&r2=474455
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd Mon Nov 13 11:30:00 2006
@@ -83,6 +83,7 @@
<xs:element name="delete">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element ref="include"/>
<xs:element ref="generate"/>
<xs:element ref="isEmpty"/>
<xs:element ref="isEqual"/>
@@ -114,6 +115,11 @@
</xs:attribute>
</xs:complexType>
</xs:element>
+ <xs:element name="include">
+ <xs:complexType mixed="true">
+ <xs:attribute name="refid" type="xs:string"/>
+ </xs:complexType>
+ </xs:element>
<xs:element name="dynamic">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
@@ -158,6 +164,7 @@
<xs:element name="insert">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element ref="include"/>
<xs:element ref="selectKey"/>
<xs:element ref="generate"/>
<xs:element ref="dynamic"/>
@@ -659,6 +666,7 @@
<xs:element name="select">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element ref="include"/>
<xs:element ref="dynamic"/>
<xs:element ref="isEmpty"/>
<xs:element ref="isEqual"/>
@@ -725,9 +733,33 @@
<xs:attribute name="namespace" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
+ <xs:element name="sql">
+ <xs:complexType mixed="true">
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element ref="dynamic"/>
+ <xs:element ref="isEmpty"/>
+ <xs:element ref="isEqual"/>
+ <xs:element ref="isGreaterEqual"/>
+ <xs:element ref="isGreaterThan"/>
+ <xs:element ref="isLessThan"/>
+ <xs:element ref="isLessEqual"/>
+ <xs:element ref="isNotEmpty"/>
+ <xs:element ref="isNotEqual"/>
+ <xs:element ref="isNotNull"/>
+ <xs:element ref="isNotParameterPresent"/>
+ <xs:element ref="isNotPropertyAvailable"/>
+ <xs:element ref="isNull"/>
+ <xs:element ref="isParameterPresent"/>
+ <xs:element ref="isPropertyAvailable"/>
+ <xs:element ref="iterate"/>
+ </xs:choice>
+ <xs:attribute name="id" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
<xs:element name="statement">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element ref="include"/>
<xs:element ref="dynamic"/>
<xs:element ref="isEmpty"/>
<xs:element ref="isEqual"/>
@@ -765,6 +797,7 @@
<xs:element name="statements">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
+ <xs:element ref="sql"/>
<xs:element ref="statement"/>
<xs:element ref="insert"/>
<xs:element ref="update"/>
@@ -783,6 +816,7 @@
<xs:element name="update">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element ref="include"/>
<xs:element ref="generate"/>
<xs:element ref="dynamic"/>
<xs:element ref="isEmpty"/>