<MetamergeConfig created="Wed Dec 10 17:33:00 CET 2008" createdBy="NO010196" version="6.1">
<Folder name="AssemblyLines"/>
<Folder name="Connectors">
<Connector name="CacheConnector">
<InheritFrom>system:/Connectors/ibmdi.ScriptConnector</InheritFrom>
<ConnectorMode>Iterator</ConnectorMode>
<ConnectorState>Enabled</ConnectorState>
<Configuration>
<InheritFrom>[parent]</InheritFrom>
<parameter name="connectorType">com.ibm.di.connector.ScriptConnector</parameter>
<parameter name="debug">false</parameter>
<parameter name="includeFiles"/>
<parameter name="parserOption">Useless</parameter>
<parameter name="script"><![CDATA[// Cache Connector v. 1.0
//
// This Connector pre-reads the data references by the Iterator
// named in the connectorName variable into a java.util.HashMap
// and allows searches (lookup). Good for making files randomly
// accessible or sorting them quickly.
//
// Note that all Entries in the Iterator's result set are loaded into
// memory. Note also that this implementation does not support
// duplicates with the same key value -- these are lost.
//

var connectorName = "Classifications";  // Connector to use
var keyAttribute = "CLASSIFICATIONID";  // Unique Attribute to use
var keyIsCaseSensitive = false;		// Controls if search/sort is case sensitive

var tree = new java.util.TreeMap();
var keyset = null;
var itr = null;                   // for the set Iterator

var fileConn = system.loadConnector("Connectors/" + connectorName);

if (fileConn == null)
   throw "Connector specified for caching not found: Connectors/" + connectorName;

selectEntries(); // So Lookup mode works too
java.lang.System.getProperties().put("cacheConnector.tree", tree);

function selectEntries()
{
   var e;       // local Entry variable.
   var cnt = 0; // cnt used to ensure uniqueness for the key Attribute

   try { // try-catch used in case connector not initialized
      fileConn.terminate();
   } catch (ignoreException) {  
      // Do nothing
   } 

   main.logmsg("* Initializing Cache Connector using Connectors/" + connectorName);

   fileConn.initialize(null);
   fileConn.selectEntries();

   tree.clear(); // Clear the Hastable.

   try {
      // Load entries from the Iterator into the HashMap
      while ((e = fileConn.getNextEntry()) != null) {
         keyval = e.getString(keyAttribute);

         if (keyval == null)
            break; // skip this one since it has no key value

         if (!keyIsCaseSensitive)
            keyval = keyval.toLowerCase();

         tree.put(keyval, e);
         cnt++;
      }
   } catch (ex) {
      main.logmsg("ERROR", "* Cache Connector - Error occurred during iteration with Connectors/" + 
                     connectorName);
      main.logmsg("ERROR", "* Exception: " + ex);
   }

   // Set up an Iterator for Iterator Mode
   itr = tree.keySet().iterator();
   
   main.logmsg("* " + tree.size() + " of " + cnt + " entries cached.");
   if (cnt != tree.size())
      main.logmsg("WARN", "* Not all data has been cached. Some entries either lacked or had duplicate key values.");
}


function getNextEntry ()
{
   if (!itr.hasNext()) {
      result.setStatus (0);
      return;
   }

   nxt = itr.next();

   entry.merge(tree.get(nxt));
   result.setStatus (1); // Set status to "entry returned"
}


function findEntry ()
{
   var e; // entry
   var crit_vector = search.getCriteria();
   var crit = crit_vector.get(0);
   var cval = crit.value;

   if (!keyIsCaseSensitive)
      cval = cval.toLowerCase();

   // First I have to make sure the data has been cached
   try {
      tree.size();
   } catch (exc) {
      selectEntries(); // If not, then cache it now
   }

   var e = tree.get(cval);

   if (e != null) {
      entry.merge(e);
      result.setStatus (1); // Set status to "entry(s) returned"
   } else 
      result.setStatus (0); // Status = "none found"
}

]]></parameter>
</Configuration>
<ComputeChanges>true</ComputeChanges>
<DeltaBehavior>0</DeltaBehavior>
<DeltaStrict>true</DeltaStrict>
<Parser>
<InheritFrom>[parent]</InheritFrom>
</Parser>
<AttributeMap name="Input">
<InheritFrom>[parent]</InheritFrom>
</AttributeMap>
<AttributeMap name="Output">
<InheritFrom>[parent]</InheritFrom>
</AttributeMap>
<DeltaSettings>
<WhenToCommit>After every database operation</WhenToCommit>
<Driver>CloudScape</Driver>
</DeltaSettings>
<Schema name="Input">
<InheritFrom>[parent]</InheritFrom>
</Schema>
<Schema name="Output">
<InheritFrom>[parent]</InheritFrom>
</Schema>
<LinkCriteria>
<InheritFrom>[parent]</InheritFrom>
<AdvancedLinkMode>false</AdvancedLinkMode>
</LinkCriteria>
<Hooks>
<InheritFrom>[parent]</InheritFrom>
</Hooks>
<CheckpointConfig/>
<SandboxConfig/>
<Reconnect>
<InheritFrom>[parent]</InheritFrom>
<parameter name="initreconnect">false</parameter>
<parameter name="numberOfRetries">1</parameter>
<parameter name="retryDelay">10</parameter>
</Reconnect>
<Operations/>
<OperationCarrierIsProperty>false</OperationCarrierIsProperty>
<PoolDefinition>
<InheritFrom>[parent]</InheritFrom>
<Enabled>false</Enabled>
<MinPoolSize>0</MinPoolSize>
<PurgeInterval>0</PurgeInterval>
<InitializeAttempts>1</InitializeAttempts>
</PoolDefinition>
<PoolInstance/>
<InitializeOption>0</InitializeOption>
</Connector>
</Folder>
<Folder name="Parsers"/>
<Folder name="EventHandlers"/>
<Folder name="Scripts"/>
<JavaLibraries/>
<JavaProperties/>
<Folder name="Includes"/>
<Folder name="Config">
<LogConfig name="Logging"/>
<InstanceProperties name="AutoStart">
<AutoStart/>
</InstanceProperties>
<TombstonesConfig name="Tombstones"/>
<SolutionInterface name="SolutionInterface"/>
</Folder>
<Folder name="Functions"/>
<Folder name="AttributeMaps"/>
<Properties name="Properties">
<Stores/>
</Properties>
</MetamergeConfig>
