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 2005/03/03 23:30:58 UTC
svn commit: r156095 - in
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper: ./ Configuration/
MappedStatements/ Scope/ Test/ Test/Domain/ Test/Maps/MSSQL/Odbc/
Test/Maps/MSSQL/OleDb/ Test/Maps/MSSQL/SqlClient/ Test/NUnit/SqlMapTests/
Test/bin/Debug/
Author: gbayon
Date: Thu Mar 3 14:30:55 2005
New Revision: 156095
URL: http://svn.apache.org/viewcvs?view=rev&rev=156095
Log:
- Added a nuint test for typed colelction with submap
- Introduced ErrorContext object (to continue)
Added:
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/DocumentCollection.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ErrorContext.cs
Modified:
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Document.xml
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/document.xml
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Document.xml
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs
Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/DocumentCollection.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/DocumentCollection.cs?view=auto&rev=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/DocumentCollection.cs (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Domain/DocumentCollection.cs Thu Mar 3 14:30:55 2005
@@ -0,0 +1,51 @@
+using System;
+using System.Collections;
+
+namespace IBatisNet.DataMapper.Test.Domain
+{
+ public class DocumentCollection : CollectionBase
+ {
+ public DocumentCollection() {}
+
+ public Document this[int index] {
+ get { return (Document)List[index]; }
+ set { List[index] = value; }
+ }
+
+ public int Add(Document value) {
+ return List.Add(value);
+ }
+
+ public void AddRange(Document[] value) {
+ for (int i = 0; i < value.Length; i++) {
+ Add(value[i]);
+ }
+ }
+
+ public void AddRange(DocumentCollection value) {
+ for (int i = 0; i < value.Count; i++) {
+ Add(value[i]);
+ }
+ }
+
+ public bool Contains(Document value) {
+ return List.Contains(value);
+ }
+
+ public void CopyTo(Document[] array, int index) {
+ List.CopyTo(array, index);
+ }
+
+ public int IndexOf(Document value) {
+ return List.IndexOf(value);
+ }
+
+ public void Insert(int index, Document value) {
+ List.Insert(index, value);
+ }
+
+ public void Remove(Document value) {
+ List.Remove(value);
+ }
+ }
+}
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj?view=diff&r1=156094&r2=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj Thu Mar 3 14:30:55 2005
@@ -233,6 +233,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Domain\DocumentCollection.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Domain\Enumeration.cs"
SubType = "Code"
BuildAction = "Compile"
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Document.xml
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Document.xml?view=diff&r1=156094&r2=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Document.xml (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/Odbc/Document.xml Thu Mar 3 14:30:55 2005
@@ -6,6 +6,7 @@
<typeAlias alias="Document" type="IBatisNet.DataMapper.Test.Domain.Document, IBatisNet.DataMapper.Test" />
<typeAlias alias="Book" type="IBatisNet.DataMapper.Test.Domain.Book, IBatisNet.DataMapper.Test" />
<typeAlias alias="Newspaper" type="IBatisNet.DataMapper.Test.Domain.Newspaper, IBatisNet.DataMapper.Test" />
+ <typeAlias alias="DocumentCollection" type="IBatisNet.DataMapper.Test.Domain.DocumentCollection, IBatisNet.DataMapper.Test" />
<typeAlias alias="MyFormula" type="IBatisNet.DataMapper.Test.Domain.MyFormula, IBatisNet.DataMapper.Test" />
</alias>
@@ -38,21 +39,30 @@
<statements>
- <statement id="GetAllDocument"
+ <select id="GetAllDocument"
resultMap="document">
select
*
from Documents
order by Document_Type, Document_Id
- </statement>
-
- <statement id="GetAllDocumentWithFormula"
+ </select>
+
+ <select id="GetTypedCollection"
+ listClass="DocumentCollection"
+ resultMap="document">
+ select
+ *
+ from Documents
+ order by Document_Type, Document_Id
+ </select>
+
+ <select id="GetAllDocumentWithFormula"
resultMap="document-custom-formula">
select
*
from Documents
order by Document_Type, Document_Id
- </statement>
+ </select>
</statements>
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/document.xml
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/document.xml?view=diff&r1=156094&r2=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/document.xml (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/OleDb/document.xml Thu Mar 3 14:30:55 2005
@@ -6,6 +6,7 @@
<typeAlias alias="Document" type="IBatisNet.DataMapper.Test.Domain.Document, IBatisNet.DataMapper.Test" />
<typeAlias alias="Book" type="IBatisNet.DataMapper.Test.Domain.Book, IBatisNet.DataMapper.Test" />
<typeAlias alias="Newspaper" type="IBatisNet.DataMapper.Test.Domain.Newspaper, IBatisNet.DataMapper.Test" />
+ <typeAlias alias="DocumentCollection" type="IBatisNet.DataMapper.Test.Domain.DocumentCollection, IBatisNet.DataMapper.Test" />
<typeAlias alias="MyFormula" type="IBatisNet.DataMapper.Test.Domain.MyFormula, IBatisNet.DataMapper.Test" />
</alias>
@@ -38,21 +39,30 @@
<statements>
- <statement id="GetAllDocument"
+ <select id="GetAllDocument"
resultMap="document">
select
*
from Documents
order by Document_Type, Document_Id
- </statement>
+ </select>
- <statement id="GetAllDocumentWithFormula"
+ <select id="GetTypedCollection"
+ listClass="DocumentCollection"
+ resultMap="document">
+ select
+ *
+ from Documents
+ order by Document_Type, Document_Id
+ </select>
+
+ <select id="GetAllDocumentWithFormula"
resultMap="document-custom-formula">
select
*
from Documents
order by Document_Type, Document_Id
- </statement>
+ </select>
</statements>
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Document.xml
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Document.xml?view=diff&r1=156094&r2=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Document.xml (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Document.xml Thu Mar 3 14:30:55 2005
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0" encoding="utf-8" ?>
<sqlMap namespace="Document" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="SqlMap.xsd">
@@ -6,6 +6,7 @@
<typeAlias alias="Document" type="IBatisNet.DataMapper.Test.Domain.Document, IBatisNet.DataMapper.Test" />
<typeAlias alias="Book" type="IBatisNet.DataMapper.Test.Domain.Book, IBatisNet.DataMapper.Test" />
<typeAlias alias="Newspaper" type="IBatisNet.DataMapper.Test.Domain.Newspaper, IBatisNet.DataMapper.Test" />
+ <typeAlias alias="DocumentCollection" type="IBatisNet.DataMapper.Test.Domain.DocumentCollection, IBatisNet.DataMapper.Test" />
<typeAlias alias="MyFormula" type="IBatisNet.DataMapper.Test.Domain.MyFormula, IBatisNet.DataMapper.Test" />
</alias>
@@ -38,21 +39,30 @@
<statements>
- <statement id="GetAllDocument"
+ <select id="GetAllDocument"
resultMap="document">
select
*
from Documents
order by Document_Type, Document_Id
- </statement>
+ </select>
- <statement id="GetAllDocumentWithFormula"
+ <select id="GetTypedCollection"
+ listClass="DocumentCollection"
+ resultMap="document">
+ select
+ *
+ from Documents
+ order by Document_Type, Document_Id
+ </select>
+
+ <select id="GetAllDocumentWithFormula"
resultMap="document-custom-formula">
select
*
from Documents
order by Document_Type, Document_Id
- </statement>
+ </select>
</statements>
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs?view=diff&r1=156094&r2=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/InheritanceTest.cs Thu Mar 3 14:30:55 2005
@@ -43,6 +43,8 @@
#endregion
+ #region Tests
+
/// <summary>
/// Test All document with no formula
/// </summary>
@@ -72,6 +74,35 @@
}
/// <summary>
+ /// Test All document in a typed collection
+ /// </summary>
+ [Test]
+ public void GetTypedCollection()
+ {
+ DocumentCollection list = sqlMap.QueryForList("GetTypedCollection", null) as DocumentCollection;
+
+ Assert.AreEqual(6, list.Count);
+
+ Book book = (Book) list[0];
+ AssertBook(book, 1, "The World of Null-A", 55);
+
+ book = (Book) list[1];
+ AssertBook(book, 3, "Lord of the Rings", 3587);
+
+ Document document = (Document) list[2];
+ AssertDocument(document, 5, "Le Monde");
+
+ document = (Document) list[3];
+ AssertDocument(document, 6, "Foundation");
+
+ Newspaper news = (Newspaper) list[4];
+ AssertNewspaper(news, 2, "Le Progres de Lyon", "Lyon");
+
+ document = (Document) list[5];
+ AssertDocument(document, 4, "Le Canard enchaine");
+ }
+
+ /// <summary>
/// Test All document with formula
/// </summary>
[Test]
@@ -98,6 +129,7 @@
news = (Newspaper) list[5];
AssertNewspaper(news, 4, "Le Canard enchaine", "Paris");
}
+ #endregion
void AssertDocument(Document document, int id, string title)
{
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config?view=diff&r1=156094&r2=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/bin/Debug/IBatisNet.DataMapper.Test.dll.config Thu Mar 3 14:30:55 2005
@@ -12,13 +12,14 @@
<!-- To test Oracle set value="Oracle" -->
<!-- To test Access set value="Access" -->
<!-- To test MS Sql Server set value="MSSQL" -->
- <add key="database" value="Access"/>
+ <add key="database" value="MSSQL"/>
<!-- To test MS SqlServer via SqlClient value="SqlClient" -->
- <!-- To test Oracle via OracleClient value="OracleClient" -->
+ <!-- To test Oracle via MS Oracle provider value="OracleClient" -->
+ <!-- To test Oracle via Oracle provider value="ODP" -->
<!-- To test MySql via ByteFx value="ByteFx" -->
<!-- To test via OleDb provider (any database) value="OleDb" -->
<!-- To test via Odbc provider (any database) value="Odbc" -->
- <add key="providerType" value="OleDb"/>
+ <add key="providerType" value="SqlClient"/>
</appSettings>
<!-- This section contains the log4net configuration settings -->
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs?view=diff&r1=156094&r2=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs Thu Mar 3 14:30:55 2005
@@ -24,7 +24,7 @@
********************************************************************************/
#endregion
-#region Imports
+#region Using
using System;
using System.Collections;
using System.Collections.Specialized;
@@ -40,6 +40,7 @@
using IBatisNet.Common.Utilities.Objects;
using IBatisNet.DataMapper;
+using IBatisNet.DataMapper.Scope;
using IBatisNet.DataMapper.Configuration.Alias;
using IBatisNet.DataMapper.Configuration.Cache;
using IBatisNet.DataMapper.Configuration.ParameterMapping;
@@ -84,11 +85,6 @@
/// </summary>
private const string PROVIDERS_FILE_NAME = "providers.config";
- /// <summary>
- /// Token for xml path to SqlMapConfig assembly element.
- /// </summary>
- private const string XML_CONFIG_ASSEMBLY = "/sqlMapConfig/assembly";
-
// TODO: Other XML paths.
/// <summary>
@@ -116,6 +112,7 @@
private bool _useStatementNamespaces = false;
private bool _cacheModelsEnabled = false;
private string _assemblyResource = string.Empty;
+ private ErrorContext _errorContext = null;
private HybridDictionary _providers = new HybridDictionary();
private NameValueCollection _properties = new NameValueCollection();
@@ -138,20 +135,44 @@
#endregion
#region Methods
+
/// <summary>
- /// Load statement, parameters, resultmap.
- /// Used by Dao
+ /// Build a SqlMapper instance
/// </summary>
- public SqlMapper Build(XmlDocument document, DataSource dataSource, bool useConfigFileWatcher)
+ /// <param name="document">An xml configuration document</param>
+ /// <param name="dataSource">A data source</param>
+ /// <param name="useConfigFileWatcher"></param>
+ /// <param name="isCallFromDao"></param>
+ /// <returns>return an a SqlMapper instance</returns>
+ private SqlMapper Build(XmlDocument document,
+ DataSource dataSource,
+ bool useConfigFileWatcher, bool isCallFromDao)
{
_sqlMapConfig = document;
_dataSource = dataSource;
- _isCallFromDao = true;
+ _isCallFromDao = isCallFromDao;
_useConfigFileWatcher = useConfigFileWatcher;
_sqlMap = null;
+ _errorContext = new ErrorContext();
// Load sqlMap statement.
- return Initialize();
+ try
+ {
+ return Initialize();
+ }
+ catch(Exception e)
+ { _errorContext.Cause = e;
+ throw new ConfigurationException(_errorContext.ToString(),e);
+ }
+ }
+
+ /// <summary>
+ /// Load statement, parameters, resultmap.
+ /// Used by Dao
+ /// </summary>
+ public SqlMapper Build(XmlDocument document, DataSource dataSource, bool useConfigFileWatcher)
+ {
+ return Build(document, dataSource, useConfigFileWatcher, true);
}
@@ -163,14 +184,7 @@
/// <param name="useConfigFileWatcher"></param>
public SqlMapper Build(XmlDocument document, bool useConfigFileWatcher)
{
- _sqlMapConfig= document;
- _dataSource = null;
- _isCallFromDao = false;
- _useConfigFileWatcher = useConfigFileWatcher;
- _sqlMap = null;
-
- // Load DatAsource, provider & sqlMaps statement.
- return Initialize();
+ return Build(document, null, useConfigFileWatcher, false);
}
@@ -193,6 +207,8 @@
#region Load settings
+ _errorContext.Activity = "Loading global settings";
+
XmlNodeList settings = _sqlMapConfig.SelectNodes(XML_CONFIG_SETTINGS);
if (settings!=null)
@@ -229,32 +245,6 @@
#endregion
- #region Load the assembly
-
- // Which files must we allow to be used as Embedded Resources ?
- // - slqMap.config [No]
- // - providers.config [No]
- // - sqlMap files [yes]
- // - properties file (like Database.config) [Yes]
- // see contribution, NHibernate usage,
- // see http://www.codeproject.com/csharp/EmbeddedResourceStrings.asp
- // see http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=75
- XmlNode assemblyNode = _sqlMapConfig.SelectSingleNode(XML_CONFIG_ASSEMBLY);
- if (assemblyNode != null)
- {
- try
- {
- Assembly.Load(assemblyNode.InnerText);
- }
- catch (Exception e)
- {
- throw new ConfigurationException(
- string.Format("Unable to load assembly \"{0}\". Cause : ", e.Message ) ,e);
- }
- }
-
- #endregion
-
#region Load Global Properties
if (_isCallFromDao == false)
{
@@ -265,6 +255,7 @@
#region Load providers
if (_isCallFromDao == false)
{
+ _errorContext.Activity = "Loading Providers";
GetProviders(Resources.GetConfigAsXmlDocument(PROVIDERS_FILE_NAME));
}
#endregion
@@ -284,6 +275,7 @@
#region Load the DataSources
+ _errorContext.Activity = "Loading Database DataSource";
XmlNode nodeDataSource = _sqlMapConfig.SelectSingleNode("/sqlMapConfig/database/dataSource");
if (nodeDataSource == null)
{
@@ -300,6 +292,8 @@
{
if (_isCallFromDao == false)
{
+ _errorContext.Resource = nodeDataSource.OuterXml.ToString();
+ _errorContext.MoreInfo = "Parse DataSource";
XmlSerializer serializer = null;
serializer = new XmlSerializer(typeof(DataSource));
DataSource dataSource = (DataSource) serializer.Deserialize(new XmlNodeReader(nodeDataSource));
@@ -314,6 +308,7 @@
{
sqlMap.DataSource = _dataSource;
}
+ _errorContext.Reset();
}
#endregion
#endregion
@@ -321,14 +316,18 @@
#region Load Global TypeAlias
foreach (XmlNode xmlNode in _sqlMapConfig.SelectNodes("/sqlMapConfig/alias/typeAlias"))
{
+ _errorContext.Activity = "Loading Global Type alias";
TypeAlias typeAlias = null;
XmlSerializer serializer = new XmlSerializer(typeof(TypeAlias));
typeAlias = (TypeAlias) serializer.Deserialize(new XmlNodeReader(xmlNode));
+ _errorContext.ObjectId = typeAlias.ClassName;
+ _errorContext.MoreInfo = "Initialize type alias";
typeAlias.Initialize();
sqlMap.AddTypeAlias( typeAlias.Name, typeAlias );
}
+ _errorContext.Reset();
#endregion
#region Load sqlMap mapping files
@@ -383,6 +382,8 @@
if (provider.IsEnabled == true)
{
+ _errorContext.MoreInfo = "Init provider";
+ _errorContext.ObjectId = provider.Name;
provider.Initialisation();
_providers.Add(provider.Name, provider);
@@ -400,6 +401,7 @@
}
}
}
+ _errorContext.Reset();
}
@@ -413,6 +415,7 @@
/// <returns>A provider object.</returns>
private Provider ParseProvider(System.Xml.XmlNode node)
{
+ _errorContext.Activity = "Load DataBase Provider";
if (node != null)
{
// name
@@ -453,6 +456,8 @@
{
XmlSerializer serializer = null;
string sqlMapName = string.Empty;
+ _errorContext.Activity = "Loading Sql Map";
+ _errorContext.Resource = sqlMapNode.OuterXml.ToString();
if (_useConfigFileWatcher == true)
{
@@ -468,13 +473,18 @@
foreach (XmlNode xmlNode in config.SelectNodes("/sqlMap/alias/typeAlias"))
{
+ _errorContext.MoreInfo = "Loading type alias";
TypeAlias typeAlias = null;
serializer = new XmlSerializer(typeof(TypeAlias));
typeAlias = (TypeAlias) serializer.Deserialize(new XmlNodeReader(xmlNode));
+ _errorContext.ObjectId = typeAlias.ClassName;
+ _errorContext.MoreInfo = "Initialize type alias";
typeAlias.Initialize();
sqlMap.AddTypeAlias( typeAlias.Name, typeAlias );
}
+ _errorContext.MoreInfo = string.Empty;
+ _errorContext.ObjectId = string.Empty;
#endregion
@@ -482,6 +492,8 @@
foreach (XmlNode xmlNode in config.SelectNodes("/sqlMap/resultMaps/resultMap"))
{
+ _errorContext.MoreInfo = "Loading ResultMap";
+
BuildResultMap( config, xmlNode, sqlMapName, sqlMap );
}
@@ -1145,9 +1157,12 @@
private void ParseGlobalProperties(XmlNode xmlContext)
{
XmlNode nodeProperties = xmlContext.SelectSingleNode("properties");
+ _errorContext.Activity = "Loading global properties";
if (nodeProperties != null)
{
+ _errorContext.Resource = nodeProperties.OuterXml.ToString();
+
// Load the file defined by the resource attribut
XmlDocument propertiesConfig = Resources.GetAsXmlDocument(nodeProperties);
@@ -1156,19 +1171,6 @@
_properties[node.Attributes["key"].Value] = node.Attributes["value"].Value;
}
}
-
-// if (assemblyNode != null)
-// {
-// try
-// {
-// Assembly.Load(assemblyNode.InnerText);
-// }
-// catch (Exception e)
-// {
-// throw new ConfigurationException(
-// string.Format("Unable to load assembly \"{0}\". Cause : ", e.Message ) ,e);
-// }
-// }
}
@@ -1261,16 +1263,19 @@
private void BuildResultMap(XmlDocument config, XmlNode resultMapNode, string sqlMapName, SqlMapper sqlMap)
{
ResultMap resultMap = null;
-
XmlSerializer serializer = new XmlSerializer(typeof(ResultMap));
+ _errorContext.MoreInfo = "Build ResultMap";
+
string id = ((XmlAttribute)resultMapNode.Attributes.GetNamedItem("id")).Value;
+ _errorContext.ObjectId = id;
// Did we alredy process it
if (sqlMap.ResultMaps.Contains( sqlMapName + DOT + id ) == false)
{
resultMap = (ResultMap) serializer.Deserialize(new XmlNodeReader(resultMapNode));
resultMap.SqlMapName = sqlMapName;
+ _errorContext.MoreInfo = "Initialize resultMap";
resultMap.Initialize( sqlMap, resultMapNode);
resultMap.Id = sqlMapName + DOT + resultMap.Id;
@@ -1278,13 +1283,14 @@
if (resultMap.ExtendMap.Length >0)
{
ResultMap superMap = null;
- // Did we already buid it ?
+ // Did we already build it ?
if (sqlMap.ResultMaps.Contains(sqlMapName + DOT + resultMap.ExtendMap) == false)
{
XmlNode superNode = config.SelectSingleNode("/sqlMap/resultMaps/resultMap[@id='"+ resultMap.ExtendMap +"']");
if (superNode != null)
{
+ _errorContext.MoreInfo = "Build parent ResultMap";
BuildResultMap( config, superNode, sqlMapName, sqlMap);
superMap = sqlMap.GetResultMap(sqlMapName + DOT + resultMap.ExtendMap);
}
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj?view=diff&r1=156094&r2=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/IBatisNet.DataMapper.csproj Thu Mar 3 14:30:55 2005
@@ -598,6 +598,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Scope\ErrorContext.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Scope\RequestScope.cs"
SubType = "Code"
BuildAction = "Compile"
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs?view=diff&r1=156094&r2=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/MappedStatement.cs Thu Mar 3 14:30:55 2005
@@ -380,6 +380,7 @@
ResultProperty property = (ResultProperty)entry.Value;
SetObjectProperty(request, request.ResultMap, property, ref outObject, reader);
}
+ request.ResetResultmap();
}
else // else try to use a ResultClass
{
@@ -416,7 +417,6 @@
}
}
- request.Reset();
return outObject;
}
Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ErrorContext.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ErrorContext.cs?view=auto&rev=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ErrorContext.cs (added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ErrorContext.cs Thu Mar 3 14:30:55 2005
@@ -0,0 +1,164 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $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;
+using System.Text;
+
+#endregion
+
+namespace IBatisNet.DataMapper.Scope
+{
+ /// <summary>
+ /// An error context to help us create meaningful error messages.
+ /// </summary>
+ public class ErrorContext
+ {
+
+ #region Fields
+
+ private string _resource;
+ private string _activity;
+ private string _objectId;
+ private string _moreInfo;
+ private Exception _cause;
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// The resource causing the problem
+ /// </summary>
+ public string Resource
+ {
+ get { return _resource; }
+ set { _resource = value; }
+ }
+
+ /// <summary>
+ /// The activity that was happening when the error happened
+ /// </summary>
+ public string Activity
+ {
+ get { return _activity; }
+ set { _activity = value; }
+ }
+
+ /// <summary>
+ /// The object ID where the problem happened
+ /// </summary>
+ public string ObjectId
+ {
+ get { return _objectId; }
+ set { _objectId = value; }
+ }
+
+ /// <summary>
+ /// More information about the error
+ /// </summary>
+ public string MoreInfo
+ {
+ get { return _moreInfo; }
+ set { _moreInfo = value; }
+ }
+
+ /// <summary>
+ /// The cause of the error
+ /// </summary>
+ public Exception Cause
+ {
+ get { return _cause; }
+ set { _cause = value; }
+ }
+
+ #endregion
+
+
+
+ /// <summary>
+ /// Clear the error context
+ /// </summary>
+ public void Reset()
+ {
+ _resource = string.Empty;
+ _activity = string.Empty;;
+ _objectId = string.Empty;;
+ _moreInfo = string.Empty;;
+ _cause = null;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ public override string ToString()
+ {
+ StringBuilder message = new StringBuilder();
+
+ // resource
+ if (_resource != null)
+ {
+ message.Append(" \n--- The error occurred in ");
+ message.Append(_resource);
+ message.Append(".");
+ }
+
+ // activity
+ if (_activity != null)
+ {
+ message.Append(" \n--- The error occurred while ");
+ message.Append(_activity);
+ message.Append(".");
+ }
+
+ // object
+ if (_objectId != null)
+ {
+ message.Append(" \n--- Check the ");
+ message.Append(_objectId);
+ message.Append(".");
+ }
+
+ // more info
+ if (_moreInfo != null)
+ {
+ message.Append(" \n--- ");
+ message.Append(_moreInfo);
+ }
+
+ // cause
+ if (_cause != null)
+ {
+ message.Append(" \n--- Cause: ");
+ message.Append(_cause.ToString());
+ }
+
+ return message.ToString();
+ }
+
+
+ }
+}
Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs?view=diff&r1=156094&r2=156095
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs (original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/RequestScope.cs Thu Mar 3 14:30:55 2005
@@ -43,6 +43,7 @@
{
#region Fields
+ private ErrorContext _errorContext = null;
private ParameterMap _parameterMap = null;
private ResultMap _resultMap = null;
private ResultMap _initialResultMap = null;
@@ -51,9 +52,33 @@
#endregion
+ #region Constructors
+
+ /// <summary>
+ /// Default constructor
+ /// </summary>
+ public RequestScope()
+ {
+ _errorContext = new ErrorContext();
+ }
+ #endregion
+
+
+
#region Properties
/// <summary>
+ /// Get the request's error context
+ /// </summary>
+ public ErrorContext ErrorContext
+ {
+ get
+ {
+ return _errorContext;
+ }
+ }
+
+ /// <summary>
/// The 'select' result property to process after having process the main properties.
/// </summary>
public Queue QueueSelect
@@ -109,9 +134,9 @@
}
/// <summary>
- /// Reset
+ /// Reset the resulMap to his intila value
/// </summary>
- public void Reset()
+ public void ResetResultmap()
{
_resultMap = _initialResultMap;
}