Author: gbayon
Date: Thu Jun 5 12:29:34 2008
New Revision: 663710
URL: http://svn.apache.org/viewvc?rev=663710&view=rev
Log:
IBATISNET-269 Allow to change de Dynamuc SQL ibatis engine via Configuration,
see the property DynamicSqlEngine on ConfigurationSetting
Modified:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/NVelocitySqlSource.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/VelocityTest.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Dynamic.Velocity.xml
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ConfigurationSetting.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/DefaultModelBuilder.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildStatements.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Statements/IStatement.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Statements/Statement.cs
Modified:
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=663710&r1=663709&r2=663710&view=diff
==============================================================================
---
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/NVelocitySqlSource.cs
(original)
+++
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Domain/NVelocitySqlSource.cs
Thu Jun 5 12:29:34 2008
@@ -32,7 +32,6 @@
{
velocityEngine = new VelocityEngine();
velocityEngine.Init();
-
}
#region ISqlSource Members
@@ -55,11 +54,6 @@
string commandText = externalSql.CommandText;
- if (logger.IsDebugEnabled)
- {
- logger.Debug("Parse velocity string '" + commandText);
- }
-
if (commandText.Contains(VELOCITY_DIRECTIVE))
{
VelocityContext velocityContext = new VelocityContext();
@@ -87,6 +81,11 @@
commandText = sw.GetStringBuilder().ToString();
}
+ if (logger.IsDebugEnabled)
+ {
+ logger.Debug("SQL command text parse by velocity: " +
commandText);
+ }
+
return commandText;
}
Modified:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/VelocityTest.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/VelocityTest.cs?rev=663710&r1=663709&r2=663710&view=diff
==============================================================================
---
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/VelocityTest.cs
(original)
+++
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/VelocityTest.cs
Thu Jun 5 12:29:34 2008
@@ -28,6 +28,7 @@
IResource resource = ResourceLoaderRegistry.GetResource(uri);
ConfigurationSetting setting = new ConfigurationSetting();
+ setting.DynamicSqlEngine = new NVelocitySqlSource();
IConfigurationEngine engine = new
DefaultConfigurationEngine(setting);
engine.RegisterInterpreter(new
XmlConfigurationInterpreter(resource));
Modified:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Dynamic.Velocity.xml
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Dynamic.Velocity.xml?rev=663710&r1=663709&r2=663710&view=diff
==============================================================================
---
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Dynamic.Velocity.xml
(original)
+++
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Dynamic.Velocity.xml
Thu Jun 5 12:29:34 2008
@@ -22,11 +22,11 @@
<statements>
- <select id="NVelocity.Simple" sqlSource="NVelocitySqlSource"
resultMap="account-result" parameterClass="map">
+ <select id="NVelocity.Simple" 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 id="NVelocity.If" resultClass="Account" remapResults="true"
parameterClass="map">
SELECT
Account_ID as Id,
@@ -42,7 +42,7 @@
where Account_Id= $account.id
</select>
- <select id="NVelocity.InlineParameter" sqlSource="NVelocitySqlSource"
resultClass="Account">
+ <select id="NVelocity.InlineParameter" resultClass="Account">
select
Account_ID as Id,
Account_FirstName as FirstName,
@@ -54,7 +54,7 @@
#end
</select>
- <select id="NVelocity.For" sqlSource="NVelocitySqlSource"
parameterClass="list" resultClass="Account">
+ <select id="NVelocity.For" parameterClass="list" resultClass="Account">
<![CDATA[
select
Account_ID as Id,
@@ -72,8 +72,7 @@
]]>
</select>
-
- <procedure id="NVelocity.Procedure" sqlSource="NVelocitySqlSource"
parameterClass="map">
+ <procedure id="NVelocity.Procedure" parameterClass="map">
ps_InsertAccountWithDefault
@{account.Id,column=Account_ID}
,@{account.FirstName,column=Account_FirstName}
Modified:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ConfigurationSetting.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ConfigurationSetting.cs?rev=663710&r1=663709&r2=663710&view=diff
==============================================================================
---
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ConfigurationSetting.cs
(original)
+++
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ConfigurationSetting.cs
Thu Jun 5 12:29:34 2008
@@ -36,7 +36,7 @@
/// The <see cref="ConfigurationSetting"/> class allows the user to set by
code some
/// setting that will drive the iBATIS engine and his configuration.
/// </summary>
- public class ConfigurationSetting
+ public sealed class ConfigurationSetting
{
private IObjectFactory objectFactory = null;
private IGetAccessorFactory getAccessorFactory = null;
@@ -46,7 +46,17 @@
private ISessionStore sessionStore = null;
private readonly IDictionary<string, string> properties = new
Dictionary<string, string>();
private bool validateMapperConfigFile = false;
+ private ISqlSource dynamicSqlEngine = null;
+ /// <summary>
+ /// Gets or sets the dynamic SQL engine.
+ /// </summary>
+ /// <value>The dynamic SQL engine.</value>
+ public ISqlSource DynamicSqlEngine
+ {
+ get { return dynamicSqlEngine; }
+ set { dynamicSqlEngine = value; }
+ }
/// <summary>
/// Indicates whether we enable or not the validation of Mapper config
files.
Modified:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/DefaultModelBuilder.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/DefaultModelBuilder.cs?rev=663710&r1=663709&r2=663710&view=diff
==============================================================================
---
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/DefaultModelBuilder.cs
(original)
+++
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/DefaultModelBuilder.cs
Thu Jun 5 12:29:34 2008
@@ -77,6 +77,7 @@
private bool useReflectionOptimizer = true;
private readonly WaitResultPropertyResolution
waitResultPropertyResolution = null;
private readonly WaitDiscriminatorResolution
waitDiscriminatorResolution = null;
+ private ISqlSource dynamicSqlEngine = null;
/// <summary>
/// Initializes a new instance of the <see
cref="DefaultModelBuilder"/> class.
@@ -120,6 +121,7 @@
dataSource = configurationSetting.DataSource;
sessionFactory = configurationSetting.SessionFactory;
sessionStore = configurationSetting.SessionStore;
+ dynamicSqlEngine = configurationSetting.DynamicSqlEngine;
}
if (objectFactory == null)
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=663710&r1=663709&r2=663710&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
Thu Jun 5 12:29:34 2008
@@ -23,25 +23,21 @@
********************************************************************************/
#endregion
+using System.Text;
using Apache.Ibatis.Common.Configuration;
-using Apache.Ibatis.DataMapper.Model.Sql.External;
-using Apache.Ibatis.DataMapper.Model.Statements;
+using Apache.Ibatis.Common.Contracts;
+using Apache.Ibatis.Common.Exceptions;
using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config;
using Apache.Ibatis.DataMapper.Configuration.Serializers;
-using Apache.Ibatis.Common.Exceptions;
using Apache.Ibatis.DataMapper.MappedStatements;
-using System.Text;
+using Apache.Ibatis.DataMapper.Model.ParameterMapping;
using Apache.Ibatis.DataMapper.Model.Sql.Dynamic;
using Apache.Ibatis.DataMapper.Model.Sql.Dynamic.Elements;
-using Apache.Ibatis.DataMapper.Model.ParameterMapping;
-using System;
-using Apache.Ibatis.DataMapper.DataExchange;
-using Apache.Ibatis.DataMapper.Model.Sql;
+using Apache.Ibatis.DataMapper.Model.Sql.External;
using Apache.Ibatis.DataMapper.Model.Sql.SimpleDynamic;
using Apache.Ibatis.DataMapper.Model.Sql.Static;
+using Apache.Ibatis.DataMapper.Model.Statements;
using Apache.Ibatis.DataMapper.Session;
-using Apache.Ibatis.Common.Contracts;
-
namespace Apache.Ibatis.DataMapper.Configuration
{
@@ -215,24 +211,32 @@
/// <param name="statement">The statement.</param>
private void ProcessSqlStatement(IConfiguration
statementConfiguration, IStatement statement)
{
+ if(dynamicSqlEngine!=null)
+ {
+ statement.SqlSource = dynamicSqlEngine;
+ }
+
if (statement.SqlSource!=null)
{
+ #region SqlSource
string commandText = string.Empty;
- if (statementConfiguration.Children.Count>0)
+ 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;
+ statement.Sql = externalSql;
+ #endregion
}
else
{
+ #region other case
bool isDynamic = false;
DynamicSql dynamic = new DynamicSql(
@@ -254,7 +258,7 @@
string newSqlCommandText = string.Empty;
ParameterMap map =
inlineParemeterMapBuilder.BuildInlineParemeterMap(statement, sqlText, out
newSqlCommandText);
- if (map!=null)
+ if (map != null)
{
statement.ParameterMap = map;
}
@@ -292,10 +296,10 @@
session.Close();
}
- }
-
+ }
}
- }
+ #endregion
+ }
Contract.Ensure.That(statement.Sql, Is.Not.Null).When("process Sql
statement.");
}
Modified:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Statements/IStatement.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Statements/IStatement.cs?rev=663710&r1=663709&r2=663710&view=diff
==============================================================================
---
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Statements/IStatement.cs
(original)
+++
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Statements/IStatement.cs
Thu Jun 5 12:29:34 2008
@@ -46,10 +46,8 @@
/// </summary>
public interface IStatement
{
-
#region Properties
-
-
+
/// <summary>
/// Gets a value indicating whether [allow remapping].
/// </summary>
@@ -111,11 +109,12 @@
/// <value>The list class.</value>
Type ListClass { get; }
+
/// <summary>
- /// Gets the SQL source.
+ /// Gets or sets the SQL source.
/// </summary>
/// <value>The SQL source.</value>
- ISqlSource SqlSource { get; }
+ ISqlSource SqlSource { get; set; }
#endregion
Modified:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Statements/Statement.cs
URL:
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Statements/Statement.cs?rev=663710&r1=663709&r2=663710&view=diff
==============================================================================
---
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Statements/Statement.cs
(original)
+++
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Statements/Statement.cs
Thu Jun 5 12:29:34 2008
@@ -75,7 +75,7 @@
[NonSerialized]
private readonly string extends = string.Empty;
private ISql sql = null;
- private readonly ISqlSource sqlSource = null;
+ private ISqlSource sqlSource = null;
#endregion
@@ -273,6 +273,7 @@
public ISqlSource SqlSource
{
get { return sqlSource; }
+ set { sqlSource = value;}
}
#endregion