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/03 21:58:52 UTC
svn commit: r662868 - in /ibatis/trunk/cs/V3/src:
Apache.Ibatis.DataMapper.SqlClient.Test.2005/
Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/
Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/
Apache.Ibatis.DataMapper.SqlClient.Test....
Author: gbayon
Date: Tue Jun 3 12:58:51 2008
New Revision: 662868
URL: http://svn.apache.org/viewvc?rev=662868&view=rev
Log:
implement IBATISNET-269
Added:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/NVelocitySqlSource.cs (with props)
ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/NVelocity.dll (with props)
ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Newtonsoft.Json.dll (with props)
ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Newtonsoft.Json.licence.txt
ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Nvelocity.license.txt
Removed:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.dll
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/Newtonsoft.Json.licence.txt
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/Mapping/DynamicTest.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Modules/AliasModule.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/DynamicAccount.xml
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildStatements.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/DeSerializerFactory.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Sql/External/ExternalSql.cs
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=662868&r1=662867&r2=662868&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 Tue Jun 3 12:58:51 2008
@@ -28,8 +28,15 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Newtonsoft.Json, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
+ <Reference Include="Newtonsoft.Json, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\External-Bin\Net\2.0\Newtonsoft.Json.dll</HintPath>
+ </Reference>
<Reference Include="nunit.framework, Version=2.4.4.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
+ <Reference Include="NVelocity, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\External-Bin\Net\2.0\NVelocity.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
@@ -38,6 +45,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Domain\JsonInterpreter.cs" />
+ <Compile Include="Domain\NVelocitySqlSource.cs" />
<Compile Include="Domain\SimpleSqlSource.cs" />
<Compile Include="Domain\SqlSourceWithInlineParameter.cs" />
<Compile Include="Domain\SqlSourceWithParameter.cs" />
@@ -150,8 +158,6 @@
<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>
Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/NVelocitySqlSource.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/NVelocitySqlSource.cs?rev=662868&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/NVelocitySqlSource.cs (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/NVelocitySqlSource.cs Tue Jun 3 12:58:51 2008
@@ -0,0 +1,66 @@
+using System.Collections.Generic;
+using System.IO;
+using Apache.Ibatis.Common.Contracts;
+using Apache.Ibatis.DataMapper.MappedStatements;
+using Apache.Ibatis.DataMapper.Model.Sql.External;
+using NVelocity;
+using NVelocity.App;
+
+namespace Apache.Ibatis.DataMapper.SqlClient.Test.Domain
+{
+ /// <summary>
+ /// NVelocity implemantation of <see cref="ISqlSource"/>
+ /// which parse sql string
+ /// </summary>
+ /// <remarks>
+ /// See http://www.castleproject.org/others/nvelocity/index.html
+ /// </remarks>
+ public class NVelocitySqlSource : ISqlSource
+ {
+ private readonly VelocityEngine velocityEngine = null;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="NVelocitySqlSource"/> class.
+ /// </summary>
+ public NVelocitySqlSource()
+ {
+ velocityEngine = new VelocityEngine();
+ velocityEngine.Init();
+
+ }
+
+ #region ISqlSource Members
+
+ /// <summary>
+ /// Gets the SQL.
+ /// </summary>
+ /// <param name="mappedStatement">The mapped statement.</param>
+ /// <param name="parameterObject">The parameter object.</param>
+ /// <returns></returns>
+ /// <remarks>
+ /// Paremeters should be typeof IDictionary<string, object>
+ /// </remarks>
+ public string GetSql(IMappedStatement mappedStatement, object parameterObject)
+ {
+ Contract.Assert.That(parameterObject, Is.TypeOf<IDictionary<string, object>>()).When("Processing NVelocity source for statement :" + mappedStatement.Id);
+
+ StringWriter sw = new StringWriter();
+ ExternalSql externalSql = (ExternalSql)mappedStatement.Statement.Sql;
+
+ VelocityContext velocityContext = new VelocityContext();
+
+ IDictionary<string, object> dico = (IDictionary<string, object>)parameterObject;
+
+ foreach(string key in dico.Keys)
+ {
+ velocityContext.Put(key, dico[key]);
+ }
+
+ bool success = velocityEngine.Evaluate(velocityContext, sw, "error", externalSql.CommandText);
+
+ return sw.GetStringBuilder().ToString();
+ }
+
+ #endregion
+ }
+}
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/NVelocitySqlSource.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/NVelocitySqlSource.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/DynamicTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/DynamicTest.cs?rev=662868&r1=662867&r2=662868&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/DynamicTest.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/DynamicTest.cs Tue Jun 3 12:58:51 2008
@@ -1,6 +1,12 @@
+using System;
using System.Collections;
+using System.Collections.Generic;
+using System.IO;
using Apache.Ibatis.DataMapper.SqlClient.Test.Domain;
using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
+using NVelocity;
+using NVelocity.App;
namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping
{
@@ -35,6 +41,47 @@
#region Dynamic tests
+ [Test]
+ public void Nvelocity_simple_sql_template_should_work()
+ {
+ Account paramAccount = new Account();
+ paramAccount.Id = 1;
+
+ IDictionary<string, object> parameters = new Dictionary<string, object>();
+ parameters.Add("account", paramAccount);
+
+ Account account = dataMapper.QueryForObject<Account>("NVelocity.Simple", parameters);
+ Assert.That(account, Is.Not.Null);
+ AssertAccount1(account);
+ }
+
+ [Test]
+ public void Nvelocity_template_with_if_should_work()
+ {
+ Account paramAccount = new Account();
+ paramAccount.FirstName = "Joe";
+ paramAccount.Id = 1;
+
+ IDictionary<string, object> parameters = new Dictionary<string, object>();
+ parameters.Add("account", paramAccount);
+
+ Account account = dataMapper.QueryForObject<Account>("NVelocity.If", parameters);
+ Assert.That(account.FirstName, Is.EqualTo("Joe"));
+ Assert.That(account.LastName, Is.Null);
+
+ paramAccount = new Account();
+ paramAccount.LastName = "Dalton";
+ paramAccount.Id = 1;
+
+ parameters = new Dictionary<string, object>();
+ parameters.Add("account", paramAccount);
+
+ account = dataMapper.QueryForObject<Account>("NVelocity.If", parameters);
+ Assert.That(account.LastName, Is.EqualTo("Dalton"));
+ Assert.That(account.FirstName, Is.Null);
+
+ }
+
/// <summary>
/// Test Dynamic Sql On Column Selection
/// JIRA IBATISNET-114
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Modules/AliasModule.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Modules/AliasModule.cs?rev=662868&r1=662867&r2=662868&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Modules/AliasModule.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Modules/AliasModule.cs Tue Jun 3 12:58:51 2008
@@ -14,6 +14,7 @@
RegisterAlias<SimpleSqlSource>();
RegisterAlias<SqlSourceWithParameter>();
RegisterAlias<SqlSourceWithInlineParameter>();
+ RegisterAlias<NVelocitySqlSource>();
}
}
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/DynamicAccount.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/DynamicAccount.xml?rev=662868&r1=662867&r2=662868&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/DynamicAccount.xml (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/DynamicAccount.xml Tue Jun 3 12:58:51 2008
@@ -10,6 +10,27 @@
<statements>
+ <!-- Nvelocity dynamic source -->
+ <select id="NVelocity.Simple" sqlSource="NVelocitySqlSource" resultMap="account-result" parameterClass="map">
+ select * from Accounts where Account_Id= $account.id
+ </select>
+
+ <select id="NVelocity.If" sqlSource="NVelocitySqlSource" resultClass="Account" remapResults="true" parameterClass="map">
+ SELECT
+ Account_ID as Id,
+
+ #if($account.FirstName == "Joe")
+ Account_FirstName as FirstName,
+ #elseif($account.LastName == "Dalton")
+ Account_LastName as LastName,
+ #end
+
+ Account_Email as EmailAddress
+ FROM
+ Accounts
+ where Account_Id= $account.id
+ </select>
+
<sql id="includeComplex">
<dynamic prepend="where">
<isParameterPresent>
@@ -72,7 +93,7 @@
SELECT
Account_ID as Id,
<dynamic>
- <isEqual property="LastName" compareValue="Dalton" >
+ <isEqual property="FirstName" compareValue="Dalton" >
Account_FirstName as FirstName,
</isEqual>
<isEqual property="LastName" compareValue="Dalton" >
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildStatements.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildStatements.cs?rev=662868&r1=662867&r2=662868&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildStatements.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildStatements.cs Tue Jun 3 12:58:51 2008
@@ -217,7 +217,18 @@
{
if (statement.SqlSource!=null)
{
- ExternalSql externalSql = new ExternalSql(modelStore, statement);
+ string commandText = string.Empty;
+
+ if (statementConfiguration.Children.Count>0)
+ {
+ IConfiguration child = statementConfiguration.Children[0];
+ if (child.Type == ConfigConstants.ELEMENT_TEXT || child.Type == ConfigConstants.ELEMENT_CDATA)
+ {
+ commandText = child.Value;
+ }
+ }
+
+ ExternalSql externalSql = new ExternalSql(modelStore, statement, commandText);
statement.Sql = externalSql;
}
else
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/DeSerializerFactory.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/DeSerializerFactory.cs?rev=662868&r1=662867&r2=662868&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/DeSerializerFactory.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/DeSerializerFactory.cs Tue Jun 3 12:58:51 2008
@@ -23,15 +23,11 @@
********************************************************************************/
#endregion
-using System.Collections;
-using System.Collections.Specialized;
-using Apache.Ibatis.DataMapper.Scope;
using System.Collections.Generic;
-using Apache.Ibatis.DataMapper.Model;
-using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config;
using Apache.Ibatis.Common.Contracts;
-using Apache.Ibatis.DataMapper.Exceptions;
using Apache.Ibatis.Common.Exceptions;
+using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config;
+using Apache.Ibatis.DataMapper.Model;
namespace Apache.Ibatis.DataMapper.Configuration.Serializers
{
@@ -78,7 +74,7 @@
if (serializerMap.ContainsKey(id))
{
- return (IDeSerializer)serializerMap[id];
+ return serializerMap[id];
}
else
{
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Sql/External/ExternalSql.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Sql/External/ExternalSql.cs?rev=662868&r1=662867&r2=662868&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Sql/External/ExternalSql.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Sql/External/ExternalSql.cs Tue Jun 3 12:58:51 2008
@@ -46,26 +46,40 @@
private readonly InlineParemeterMapBuilder inlineParemeterMapBuilder = null;
private readonly DataExchangeFactory dataExchangeFactory = null;
private readonly DBHelperParameterCache dbHelperParameterCache = null;
+ private readonly string commandText = string.Empty;
+
+ /// <summary>
+ /// Gets the command text.
+ /// </summary>
+ /// <value>The command text.</value>
+ public string CommandText
+ {
+ get { return commandText; }
+ }
/// <summary>
/// Initializes a new instance of the <see cref="ExternalSql"/> class.
/// </summary>
/// <param name="modelStore">The model store.</param>
/// <param name="statement">The statement.</param>
+ /// <param name="commandText">The command text.</param>
public ExternalSql(
IModelStore modelStore,
- IStatement statement)
+ IStatement statement,
+ string commandText)
{
Contract.Require.That(modelStore, Is.Not.Null).When("retrieving argument modelStore in ExternalSql constructor");
Contract.Require.That(statement, Is.Not.Null).When("retrieving argument statement in ExternalSql constructor");
this.statement = statement;
+ this.commandText = commandText;
dataExchangeFactory = modelStore.DataExchangeFactory;
dbHelperParameterCache = modelStore.DBHelperParameterCache;
inlineParemeterMapBuilder = new InlineParemeterMapBuilder(modelStore);
}
+
#region ISql Members
/// <summary>
Added: ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/NVelocity.dll
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/NVelocity.dll?rev=662868&view=auto
==============================================================================
Binary file - no diff available.
Propchange: ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/NVelocity.dll
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Newtonsoft.Json.dll
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Newtonsoft.Json.dll?rev=662868&view=auto
==============================================================================
Binary file - no diff available.
Propchange: ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Newtonsoft.Json.dll
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Newtonsoft.Json.licence.txt
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Newtonsoft.Json.licence.txt?rev=662868&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Newtonsoft.Json.licence.txt (added)
+++ ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Newtonsoft.Json.licence.txt Tue Jun 3 12:58:51 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/External-Bin/Net/2.0/Nvelocity.license.txt
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Nvelocity.license.txt?rev=662868&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Nvelocity.license.txt (added)
+++ ibatis/trunk/cs/V3/src/External-Bin/Net/2.0/Nvelocity.license.txt Tue Jun 3 12:58:51 2008
@@ -0,0 +1,13 @@
+Copyright 2004-2005 Castle Project - http://www.castleproject.org/
+
+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.