Author: rgrabowski
Date: Mon Sep  5 13:23:10 2005
New Revision: 278826

URL: http://svn.apache.org/viewcvs?rev=278826&view=rev
Log:
Fix for IBATISNET-100 that postpones associating cacheModels to statements 
until all sqlMap resources have been processed. This alleviates some of the 
issues with having to load sqlMap resources in a certain order if the 
cacheModel references statements from a different namespace. A log message is 
generated each time a cacheModel is associated with a statement. Also changed 
the SqlMap.xsd file to longer require a statements node. This allows 
cacheModels nodes, resultMaps nodes, etc. to be in their own file.

Modified:
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs
    ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs?rev=278826&r1=278825&r2=278826&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs 
Mon Sep  5 13:23:10 2005
@@ -811,6 +811,30 @@
                        _configScope.ErrorContext.Reset();
                        #endregion 
 
+                       #region Register Trigger Statements for Cache Models
+                       foreach (DictionaryEntry entry in 
_configScope.CacheModelFlushOnExecuteStatements)
+                       {
+                               string cacheModelId = (string)entry.Key;
+                               IList statementsToRegister = (IList)entry.Value;
+
+                               if (statementsToRegister != null && 
statementsToRegister.Count > 0)
+                               {
+                                       foreach (string statementName in 
statementsToRegister)
+                                       {
+                                               CacheModel cacheModel = 
_configScope.SqlMapper.GetCache(cacheModelId);
+                                               IMappedStatement 
mappedStatement = 
(IMappedStatement)_configScope.SqlMapper.MappedStatements[statementName];
+
+                                               if (_logger.IsDebugEnabled)
+                                               {
+                                                       
_logger.Debug("Registering trigger statement [" + mappedStatement.Name + "] to 
cache model [" + cacheModel.Id + "]");
+                                               }
+
+                                               
cacheModel.RegisterTriggerStatement(mappedStatement);
+                                       }
+                               }
+                       }
+                       #endregion
+
                        #region Resolve "resultMap" attribute on Result 
Property + initialize Discriminator property 
 
                        foreach(DictionaryEntry entry in 
_configScope.SqlMapper.ResultMaps)
@@ -1265,9 +1289,14 @@
                                                        statementName = 
ApplyNamespace( statementName ); 
                                                }
 
-                                               IMappedStatement 
mappedStatement = _configScope.SqlMapper.GetMappedStatement(statementName);
-
-                                               
cacheModel.RegisterTriggerStatement(mappedStatement);
+                                               // delay registering statements 
to cache model until all sqlMap files have been processed
+                                               IList statementNames = 
(IList)_configScope.CacheModelFlushOnExecuteStatements[cacheModel.Id];
+                                               if (statementNames == null)
+                                               {
+                                                       statementNames = new 
ArrayList();
+                                               }
+                                               
statementNames.Add(statementName);
+                                               
_configScope.CacheModelFlushOnExecuteStatements[cacheModel.Id] = statementNames;
                                        }
 
                                        // Get Properties

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs?rev=278826&r1=278825&r2=278826&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs 
(original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs Mon 
Sep  5 13:23:10 2005
@@ -68,6 +68,7 @@
                private DataSource _dataSource = null;
                private bool _isXmlValid = true;
                private XmlNamespaceManager _nsmgr = null;
+               private HybridDictionary _cacheModelFlushOnExecuteStatements = 
new HybridDictionary();
 
                #endregion
        
@@ -166,7 +167,6 @@
                        set { _isCacheModelsEnabled = value; }
                        get { return _isCacheModelsEnabled; }
                }
-               
 
                /// <summary>
                /// External data source
@@ -255,6 +255,15 @@
                        set { _useEmbedStatementParams = value; }
                }
 
+               /// <summary>
+               /// Temporary storage for mapping cache model ids (key is 
System.String) to statements (value is IList which contains IMappedStatements).
+               /// </summary>
+               public HybridDictionary CacheModelFlushOnExecuteStatements
+               {
+                       get { return _cacheModelFlushOnExecuteStatements; }
+                       set { _cacheModelFlushOnExecuteStatements = value; }
+               }
+
                #endregion 
 
                /// <summary>
@@ -321,5 +330,6 @@
 
                        return handler;
                }
+
        }
 }

Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd?rev=278826&r1=278825&r2=278826&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMap.xsd Mon Sep  5 13:23:10 
2005
@@ -670,7 +670,7 @@
                                <xs:element ref="alias" minOccurs="0"/>
                                <xs:element ref="cacheModels" minOccurs="0"/>
                                <xs:element ref="resultMaps" minOccurs="0"/>
-                               <xs:element ref="statements"/>
+                               <xs:element ref="statements" minOccurs="0" />
                                <xs:element ref="parameterMaps" minOccurs="0"/>
                        </xs:sequence>
                        <xs:attribute name="namespace" type="xs:string" 
use="required"/>


Reply via email to