Oracle Connection Pooling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JWM

    Oracle Connection Pooling

    I am trying to implement Oracle connection pooling for the following code,
    which was written by someone else. Here is my main question -- this java
    file creates code that is executed every hour, but once per week, the oracle
    server is brought down for backup. At that time, I get an error that looks
    like I have the wrong credentials for the database. For every subsequent
    attempt to run the hourly process, I am getting a broken pipe error, untl
    the app server (Web Sphere) gets a restart.

    My thinking is that, if I implement connection pooling, I can essentially
    "trap" this connection that is getting orphaned and messing me up. Once it
    is "trapped" in the pool, I can forcefully close it, or just purge the pool
    of all connections, prior to getting my new connection. That way, I will
    get the first error descripbed above, but the process will work as designed
    the next time it runs, instead of getting the broken pipe error.

    Please, if anyone can help, let me know if what I am talking about is
    possible, and how I should modify my code to make it happen.

    Thanks.

    Joe Mack
    jwm68@sbcglobal .net

    -----------------------
    CODE
    -----------------------

    package com.proprietary .adapter;

    import java.sql.*;
    import org.w3c.dom.*;
    import java.text.Simpl eDateFormat;
    import java.util.*;
    import com.proprietary .util.*;
    import com.proprietary .object.*;
    import com.proprietary .security.authn .EncryptedData;
    import com.proprietary .adapter.*;
    import com.proprietary .msgcat.*;
    import oracle.jdbc.dri ver.*;
    import java.util.Resou rceBundle;


    public class HRActiveSyncAda pter extends ExampleTableRes ourceAdapter
    implements ActiveSync {
    private static final String code_id = "$Id: HRActiveSyncAda pter.java,v
    1.1 2003/09/25 12:33:47 tshah Exp $";

    //////////////////////////////////////////////////////////////////////
    //
    // Prototype XML
    //
    //////////////////////////////////////////////////////////////////////
    /*
    protected static final String DEFAULT_DRIVER =
    "oracle.jdbc.dr iver.OracleDriv er";
    protected static final String DEFAULT_PORT = "1521";
    protected static final String DEFAULT_HOSTNAM E = "server.test.co m";
    protected static final String DEFAULT_PREFIX =
    "jdbc:oracle:th in:server.test. com:1521:IDMD";
    */

    protected static final String DEFAULT_DRIVER =
    "oracle.jdbc.dr iver.OracleDriv er";
    protected static final String DEFAULT_PORT = "1521";
    protected static final String DEFAULT_HOSTNAM E = null;
    protected static final String DEFAULT_PREFIX = null;
    public static final String RA_UPDATE_IF_DE LETE = "Process deletes as
    updates";
    protected static final String DEFAULT_DATABAS E = "IDMD";
    protected static final String SQL_DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
    //"yyyy-MM-dd";
    protected static final String CREATE_HISTORY_ NAME = "createHistory" ;
    protected static final String TERM_HISTORY_NA ME = "termHistor y";
    protected static final String RA_PREHIRE_CREA TE = "Pre-hire";
    protected static final String RA_HIRE_SEARCH_ WINDOW = "Hire search
    window";
    protected static final String RA_HIRE_HISTORY = "Hire history
    length";
    protected static final String RA_TERM_SEARCH_ WINDOW = "Term search
    window";
    protected static final String RA_TERM_HISTORY = "Term history
    length";
    protected static final String RA_MOD_HISTORY = "Modificati on
    search window";
    protected static final String RA_TABLE_NAME = "Table name";
    protected static final String DEFAULT_TABLE_N AME = "LH_HR";

    protected Connection _connection = null;

    protected ResourceBundle dbbundle = null;

    ActiveSyncUtil _util = null;


    protected String theDriver = null;
    protected String thePort = null;
    protected String theHost = null;
    protected String thePrefix = null;



    /**
    * Simple struct to hold three strings, used for the schema description
    * below.
    */
    static class SchemaData {
    public String _columnName,
    _lighthouseMapp edName,
    _testData;

    public SchemaData(Stri ng columnName,
    String lighthouseMappe dName,
    String testData) {
    _columnName = columnName;
    _lighthouseMapp edName = lighthouseMappe dName;
    _testData = testData;
    } // SchemaData(Strg Strg Strg)
    }

    //////////////////////////////////////////////////////////////////////
    //
    // Constructors
    //
    //////////////////////////////////////////////////////////////////////



    public HRActiveSyncAda pter()
    {
    /*
    try {

    dbbundle = ResourceBundle. getBundle("HRAc tiveSync",Local e.getDefault()) ;

    theDriver = dbbundle.getStr ing("DB_DRIVER" );
    thePort = dbbundle.getStr ing("DB_PORT");
    theHost = dbbundle.getStr ing("DB_HOSTNAM E");
    thePrefix = dbbundle.getStr ing("DB_PREFIX" );

    DEFAULT_DRIVER = theDriver;
    DEFAULT_PORT = thePort;
    DEFAULT_HOSTNAM E = theHost;
    DEFAULT_PREFIX = thePrefix;



    } catch (Exception ex) {

    System.out.prin tln("HRActiveSy ncAdapter error reading
    HRActiveSync.pr operties: " + ex.toString());

    }


    */


    }



    //////////////////////////////////////////////////////////////////////
    //
    // Utilities
    //
    //////////////////////////////////////////////////////////////////////

    /**
    * make this into
    * jdbc:oracle:thi n:user/password@databa se
    */
    public String oracleFormatUrl (String prefix, String host, String port,
    String db) {
    if (prefix.toUpper Case().indexOf( "ORACLE") >= 0) {
    String user = null;
    Object pwd = null;
    try {
    user = (String) getRequiredResA ttrVal(RA_USER) ;
    pwd = (String) getRequiredResA ttrVal(RA_USER) ;
    } catch (proprietaryExc eption ex) {
    return null;
    }
    String password;
    if (pwd instanceof EncryptedData)
    password = ((EncryptedData )pwd).decryptTo String();
    else
    password = pwd.toString();

    return prefix + ":" + user + "/" + password + "@" + host + ":" +
    port + ":"
    + db;
    } else {
    return super.formatUrl (prefix,host,po rt,db);
    }
    }

    /**
    * MySql version. end up with:
    *
    "jdbc:mysql ://localhost:3306/mydatabase?user =username;passw ord=password";
    */
    public String formatUrl(Strin g prefix, String host, String port,
    String db) {

    if (prefix.toUpper Case().indexOf( "MYSQL") >= 0) {
    String user = null;
    Object pwd = null;
    try {
    user = (String) getRequiredResA ttrVal(RA_USER) ;
    pwd = (String) getRequiredResA ttrVal(RA_USER) ;
    } catch (proprietaryExc eption ex) {
    return null;
    }
    String password;
    if (pwd instanceof EncryptedData)
    password = ((EncryptedData )pwd).decryptTo String();
    else
    password = pwd.toString();

    return prefix + "://" + host + ":" + port + "/" + db; // +
    "?user=" + user + ";password= " + password;
    } else {
    return oracleFormatUrl (prefix,host,po rt,db);
    }
    }

    /**
    * These are methods implemented in sources to get and set attributes.
    * Since this is a source with a resource, just pass the calls through.
    */
    public Object getAttributeVal ue(String name) throws proprietaryExce ption
    {
    if ("name".equalsI gnoreCase(name) )
    return getResource().g etName();
    else
    return getResource().g etResourceAttri buteVal(name);
    }
    /**
    * These are methods implemented in sources to get and set attributes.
    * Since this is a source with a resource, just pass the calls through.
    */
    public void setAttributeVal ue(String name, Object value) throws
    proprietaryExce ption {
    getResource().s etResourceAttri buteVal(name,va lue);
    }

    /**
    * Map from a resource attribute to a proprietary attribute. Return null
    * if there's no mapping.
    */
    protected WSAttribute reverseMapAttr( String attr, Object value) {
    WSAttribute wsAttr = null;
    AccountAttribut eType attrType = getAttrTypeFrom MapName(attr);
    if (attrType != null) {
    wsAttr = new WSAttribute(att rType.getName() , value,
    attrType.getSyn tax());
    }
    return wsAttr;
    }

    //////////////////////////////////////////////////////////////////////
    //
    // ActiveSync implementation
    //
    //////////////////////////////////////////////////////////////////////

    /**
    * Return a sql date daysOffset from today.
    *
    * @param daysOffset positive or negative offset from today
    */
    protected static java.sql.Timest amp getDate(int daysOffset) {
    Calendar rightNow = Calendar.getIns tance();

    rightNow.add(Ca lendar.DATE,day sOffset);

    return new java.sql.Timest amp(rightNow.ge tTime().getTime ());
    }

    protected static String getDateString(i nt daysOffset) {
    java.sql.Timest amp date = getDate(daysOff set);

    return Util.dateToStri ng(date,SQL_DAT E_FORMAT);
    }

    protected int getIntRequiredR esAttrVal(Strin g name)
    throws proprietaryExce ption, java.lang.Numbe rFormatExceptio n {
    Object o = getRequiredResA ttrVal(_resourc e, name);
    if (o != null) {
    int i = Integer.parseIn t((String)o);
    return i;
    }
    return 0; // should not happen, the attribute was required, above
    }

    private void logIfFound(List viewIDs, String foundBy) {

    if (viewIDs != null) {
    StringBuffer sb = new StringBuffer();
    sb.append("Ligh thouse user(s) ");
    sb.append(found By);
    sb.append(": ");
    _util.listToStr ingBuffer(viewI Ds, sb);
    sb.append('\n') ;
    _util.logString (ActiveSync.TRA CE_LEVEL_INFO,s b.toString());
    }
    }

    /**
    * Find the view ID for this user and set it in the update. If found,
    * return true.
    */
    private boolean mapUserToViewID (IAPI update,
    String attributeName,
    String attributeValue,
    boolean attributeIsAcco untId)
    throws proprietaryExce ption, IAPI.IAPIExcept ion {

    List viewIDs = null;

    if ((viewIDs == null || viewIDs.size() < 1) &&
    attributeIsAcco untId &&
    attributeValue != null) {
    viewIDs = update.find(Att ribute.NAME.toS tring(),attribu teValue,
    2, false);
    logIfFound(view IDs, "Found by " + Attribute.NAME. toString());

    if (viewIDs == null) {
    viewIDs =
    update.find(Att ribute.RESOURCE _ACCOUNT_IDS.to String(),attrib uteValue, 2,
    true);
    logIfFound(view IDs, "Found by " +
    Attribute.RESOU RCE_ACCOUNT_IDS .toString());
    }
    }

    if (viewIDs == null && attributeName != null && attributeValue !=
    null) {
    viewIDs = update.find(att ributeName,attr ibuteValue, 2, false);
    logIfFound(view IDs, "Found by " + attributeName);
    }

    if (viewIDs == null) {
    _util.logString (IAPI.TRACE_LEV EL_INFO, "Received update for user
    " + attributeName + ":" + attributeValue + " not in Lighthouse\n");
    }
    else if (viewIDs.size() 1) {
    throw new com.proprietary .util.InternalE rror("found multiple
    matches for " + attributeName + ":" + attributeValue) ;
    }
    else {
    update.setViewI D((String)viewI Ds.get(0));
    return true;
    }
    return false;
    }
    /**
    * Give a table row result, get the attributes associated with it
    * and stuff them into the attributes of an IAPI object.
    *
    * This is what takes an update (filtered by the history) and builds
    * an IAPI object. That object is then submitted to make the update
    * to Lighthouse.
    *
    * @param row
    */
    protected IAPI buildEvent(Upda teRow row)
    throws proprietaryExce ption, IAPI.IAPIExcept ion{

    // attrib are the user attributes in a map, one entry for
    // each schema map row.
    Map attrib = row.getUserMap( );

    /** Options for provisioning. see UserViewConstan ts*/
    Map options = new HashMap();

    String command = IAPIUser.COMMAN D_CREATE;

    // The IAPI object to hold the update information
    IAPIUser iapi = new IAPIUser(option s,attrib,comman d,getResource() );

    // if we are tracing, ask the event to trace also
    iapi.setTraceLe vel(_util.getLo gLevel());
    iapi.setTraceFi le(_util.getLog FileFullPath()) ;

    // get the mapping attribute
    _util.logString (IAPI.TRACE_LEV EL_INFO,"Attrib ute Map: " +
    attrib.toString ());
    _util.logString (IAPI.TRACE_LEV EL_INFO,"LAN_ID : " +
    attrib.get("LAN _ID"));
    _util.logString (IAPI.TRACE_LEV EL_INFO,"ACTION CODE: " +
    attrib.get("act ionCode"));

    String accountId = (String)attrib. get("accountId" );
    String actionCode = null;
    String hrProcessed = null;

    _util.logString (IAPI.TRACE_LEV EL_INFO,"accoun tId: " + accountId);

    Object oactionCode = attrib.get("act ionCode");
    if(oactionCode != null) {
    _util.logString (IAPI.TRACE_LEV EL_INFO,"oactio nCode: " + oactionCode);
    actionCode = (String)oaction Code;
    }

    _util.logString (IAPI.TRACE_LEV EL_INFO,"action Code: " + actionCode);

    Object ohrProcessed = attrib.get("hrP rocessed");
    if(ohrProcessed != null) {
    _util.logString (IAPI.TRACE_LEV EL_INFO,"ohrPro cessed: " + ohrProcessed);
    hrProcessed = (String)ohrProc essed;
    }

    _util.logString (IAPI.TRACE_LEV EL_INFO,"hrProc essed: " + hrProcessed);

    if ( accountId == null )
    throw new proprietaryExce ption("Missing required attribute " +
    "accountId. Check schema map.");

    // map to a lighthouse user. If not found, turn into a create
    if (mapUserToViewI D(iapi,"account Id",accountId,t rue)) {
    iapi.setCommand (IAPIUser.COMMA ND_UPDATE);
    } else {
    if(oactionCode == null) {
    return null;
    }
    _util.logString (IAPI.TRACE_LEV EL_INFO,"Here") ;
    iapi.setCommand (IAPIUser.COMMA ND_CREATE);
    }

    return iapi;
    }

    /**
    * Give a table row result, get the attributes associated with it
    * and stuff them into the attributes of an event.
    *


    * @param row
    */
    protected IAPI buildTerminateE vent(UpdateRow row)
    throws proprietaryExce ption, IAPI.IAPIExcept ion {

    // attrib are the user attributes in a map, one entry for
    // each schema map row.
    Map attrib = row.getUserMap( );

    /** Options for provisioning. see UserViewConstan ts*/
    Map options = new HashMap();

    // pull out the proprietary account ID and find that view ID
    IAPIUser iapi = new
    IAPIUser(option s,attrib,IAPI.C OMMAND_DELETE,g etResource());

    boolean treatDeleteAsUp date = _util.checkOpti on(this,
    RA_UPDATE_IF_DE LETE);

    if (treatDeleteAsU pdate)
    _util.logString (IAPI.TRACE_LEV EL_INFO,
    "delete event changed to update because " +
    RA_UPDATE_IF_DE LETE + " true\n");

    // if we are tracing, ask the event to trace also
    iapi.setTraceLe vel(_util.getLo gLevel());
    iapi.setTraceFi le(_util.getLog FileFullPath()) ;

    // get the mapping attribute
    String accountId = (String)attrib. get("accountId" );
    if ( accountId == null )
    throw new proprietaryExce ption("Missing required attribute " +
    "accountId. Check schema map.");

    // map to a lighthouse user. If not found, it was logged, ignore.
    if (mapUserToViewI D(iapi,"account Id",accountId,t rue)) {
    if (treatDeleteAsU pdate)
    iapi.setCommand (IAPIUser.COMMA ND_UPDATE);
    else
    iapi.setCommand (IAPIUser.COMMA ND_DELETE);
    }
    else
    return null;

    return iapi;
    } // buildEvent(Upda teRow)

    /**
    * Take a list of arrays of UpdateRows, turn them into IAPI
    * objects, and submit them
    */
    protected void processCreateRe quests(List list)
    throws proprietaryExce ption, IAPI.IAPIExcept ion {

    String eventMsg = "";
    int eventHasError = 0;

    if (list != null) {

    Iterator it = list.iterator() ;
    while (it.hasNext() && !Thread.current Thread().isInte rrupted())
    {

    eventMsg = "";
    eventHasError = 0;

    UpdateRow row = (UpdateRow)it.n ext();

    if (row!=null)
    {


    logUpdate(IAPI. TRACE_LEVEL_INF O,row,null);
    IAPI event = buildEvent(row) ;
    proprietaryResu lt result = null;



    if (event != null) {


    try
    {

    result = event.submit();

    if (result!=null)
    {


    List errorList = result.getError s();

    if (errorList!=nul l)
    {

    Iterator errorIterator = errorList.itera tor();

    while (errorIterator. hasNext())
    {

    String proprietaryMsg = (String) errorIterator.n ext();

    if (proprietaryMsg !=null)
    {

    eventMsg = proprietaryMsg + eventMsg;

    eventHasError = 1;

    }

    }

    }


    }

    } catch (Exception evEx) {

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->proprietary
    Event exception in processCreateRe quests: " + evEx.toString() );

    eventHasError = 1;

    }

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->BEGINNING OF
    proprietaryRESU LT");
    logUpdate(IAPI. TRACE_LEVEL_INF O,row,result);
    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->END OF proprietaryRESU LT");

    if (eventHasError= =0)
    {

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->No Errors,
    Calling UpdateLHProcess ed");

    updateLHProcess ed(row);

    _util.logString (IAPI.TRACE_LEV EL_INFO, "Calling UpdateSOAFProce ssed");


    updateSOAFProce ssed(row);


    } else {

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->Error
    processing event, not calling UpdateLHProcess ed");

    updateSOAFProce ssed(row);

    _util.logString (IAPI.TRACE_LEV EL_INFO, "Calling UpdateSOAFProce ssed");

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->Errors
    found, dumping error list");

    List errorList = result.getError Messages();

    Iterator errorIterator = errorList.itera tor();

    while (errorIterator. hasNext())
    {

    Message proprietaryMsg = (Message) errorIterator.n ext();

    //SDM Append the message strings
    eventMsg = proprietaryMsg. getMessage() + eventMsg;

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->proprietary Event msg in
    processCreateRe quests: " + (String)proprie taryMsg.getMess age());
    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->proprietary Event msg in
    processCreateRe quests: " + proprietaryMsg. toXml() );

    eventHasError = 1;


    }
    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->End dumping
    error list");

    } // eventHasError == 0
    } // event != null
    } // row != null
    } //while
    } //if
    }


    protected void updateLHProcess ed(UpdateRow row)
    {

    PreparedStateme nt s = null;

    try {

    Map m = row.getAuditMap ();
    Object o = m.get("LAN_ID") ;

    //SDM 2-16, addition for HR_SEQ

    Object seqObject = m.get("HR_SEQ") ;
    String seqString = null;
    String lanid = null;

    if (seqObject!=nul l)
    seqString = seqObject.toStr ing();

    if (o != null)
    lanid = o.toString().to UpperCase();


    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->HR SEQ in
    processCreateRe quests: " + seqString);

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->Lan ID in
    processCreateRe quests: " + lanid);

    if (lanid != null && seqString!= null) {

    StringBuffer sb = new StringBuffer();
    sb.append("upda te LH_HR set LH_PROCESSED_YN ='Y' where
    upper(LAN_ID)=' ");

    sb.append(lanid );
    sb.append("' and HR_SEQ = ");
    sb.append(seqSt ring);

    String dml = sb.toString();

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->Update SQL in
    processCreateRe quests: " + dml);

    s = _connection.pre pareStatement(d ml);
    s.execute();

    /* SDM - 3/20 close statement before we prepare the next one */

    try {

    s.close();

    } catch (Exception closeEx) {


    }

    /* SDM - end of 3/20 mod to close 1st statement before creating second,
    finally block closes out 2nd statement */


    sb = new StringBuffer();

    sb.append("upda te LH_SOAF set LH_PROCESSED_YN ='R' where
    upper(LAN_ID)=' ");

    sb.append(lanid );
    sb.append("' and LH_PROCESSED_YN ='N'");

    dml = sb.toString();

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->Update SQL in
    processCreateRe quests: " + dml);

    s = _connection.pre pareStatement(d ml);

    s.execute();

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->After update SQL in
    processCreateRe quests");


    }
    //o != null

    } catch(Exception e){


    _util.logString (IAPI.TRACE_LEV EL_INFO, "exception setting
    LH_HR.LH_PROCES SED_YN to R in processCreateRe quests");

    } finally {

    try {

    s.close();

    } catch (Exception closeEx) {

    }


    }

    }



    protected void updateSOAFProce ssed(UpdateRow row)
    {

    PreparedStateme nt s = null;

    try {

    Map m = row.getAuditMap ();
    Object o = m.get("LAN_ID") ;

    String lanid = null;

    if (o != null)
    lanid = o.toString().to UpperCase();


    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->Lan ID in
    updateSOAFProce ssed: " + lanid);

    if (lanid != null) {

    StringBuffer sb = new StringBuffer();

    sb.append("upda te LH_SOAF set LH_PROCESSED_YN ='R' where
    upper(LAN_ID)=' ");

    sb.append(lanid );
    sb.append("' and LH_PROCESSED_YN ='N'");

    String dml = sb.toString();

    s = _connection.pre pareStatement(d ml);

    s.execute();


    }
    //o != null

    } catch(Exception e){


    _util.logString (IAPI.TRACE_LEV EL_INFO, "exception setting
    LH_HR.LH_PROCES SED_YN to R in updateSOAFProce ssed");

    } finally {

    try {

    s.close();

    } catch (Exception closeEx) {

    }


    }

    }


    /**
    * Take a list of arrays of UpdateRows, turn them into IAPI
    * objects, and submit them
    */
    protected void processTermRequ ests(List list)
    throws proprietaryExce ption, IAPI.IAPIExcept ion {

    if (list != null) {

    Iterator it = list.iterator() ;

    while (it.hasNext() && !Thread.current Thread().isInte rrupted())
    {

    UpdateRow row = (UpdateRow)it.n ext();

    logUpdate(IAPI. TRACE_LEVEL_INF O,row,null);
    IAPI event = buildTerminateE vent(row);
    if (event != null) {


    proprietaryResu lt result = event.submit();
    logUpdate(IAPI. TRACE_LEVEL_INF O,row,result);

    String eventMsg = "";
    int eventHasError = 0;

    if (result!=null)
    {


    List errorList = result.getError Messages();

    Iterator errorIterator = errorList.itera tor();

    while (errorIterator. hasNext())
    {

    Message proprietaryMsg = (Message) errorIterator.n ext();

    //SDM Append the message strings
    eventMsg = proprietaryMsg. getMessage() + eventMsg;

    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->proprietary Event msg in
    processTermRequ ests: " + proprietaryMsg. getMessage());
    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->proprietary Event msg in
    processTermRequ ests: " + proprietaryMsg. toXml() );

    eventHasError = 1;


    }


    }

    if (eventHasError= =0)
    {

    try
    {

    updateLHProcess ed(row);


    } catch(Exception e){

    _util.logString (IAPI.TRACE_LEV EL_INFO, "exception setting
    LH_HR.LH_PROCES SED_YN to R in processTermRequ ests");

    }

    } //eventHasErr == 0
    } //event != null
    } //while
    } // list != null
    }

    /**
    * From a result set and a list of column names,
    * make a Map. Only map names that are in the schema map, they are named
    * from the "left hand" side of the schema map
    *
    * @param result - the result set from JDBC
    * @param names - the list of names
    *
    * @returns the Map, with the attributes added.
    */
    protected UpdateRow rowToUpdateRow( ResultSet result, List names)
    throws java.sql.SQLExc eption {

    Map userMap = new HashMap(); // schema mapped data
    Map auditMap = new HashMap(); // raw columns
    for (int i=0; i < names.size(); i++) {
    SchemaData row = (SchemaData)nam es.get(i);
    Object rowData = result.getObjec t(i+1);
    if (rowData != null) {
    WSAttribute attr =
    reverseMapAttr( row._columnName ,rowData.toStri ng().trim());
    // if this is a mapped lighthouse attribute, stuff it as a
    string
    if (attr != null)

    userMap.put((St ring)attr.getNa me(),attr.getVa lueAsString());
    }

    // always stuff the audit data, even for null columns (like
    TERMINATION_DAT E)
    auditMap.put(ro w._columnName,r owData);
    } // for each column

    return new UpdateRow(audit Map,userMap);
    }
    /**
    * return true if a>b. This is used to figure out if we have already
    * processed a row, so it can fudge it if needs to.
    *
    * We expect LAST_MODIFIED_D ATE to be a native date object but do the
    * conversion if we have to. they should be java.sql.Timest amp(s).
    */
    protected boolean isAfter(Map a, Map b) {
    if (a == null || b == null) return true;

    Object oa = a.get("LAST_MOD IFIED_DATE");
    Object ob = b.get("LAST_MOD IFIED_DATE");
    java.util.Date da = null, db = null;
    try {
    if (oa instanceof java.util.Date)
    da = (java.util.Date )oa;
    else
    da = new
    java.util.Date( Util.stringToDa te(oa.toString( ),SQL_DATE_FORM AT).getTime());
    if (ob instanceof java.util.Date)
    db = (java.util.Date )ob;
    else
    db = new
    java.util.Date( Util.stringToDa te(ob.toString( ),SQL_DATE_FORM AT).getTime());
    } catch (java.text.Pars eException ex) {
    _util.logString (IAPI.TRACE_LEV EL_ERROR,"error parsing dates\n");

    _util.logString (IAPI.TRACE_LEV EL_ERROR,Util.s tackToString(ex ),false);
    }

    return (da != null && db != null) ? da.after(db) : true;
    }

    /**
    * return true if a>b. This is used to figure out if we have already
    * processed a row, so it can fudge it if needs to.
    *
    * We the strings to be native date objects toString()'ed. They should
    * be java.sql.Timest amp(s).
    */
    protected boolean isAfter(String a, String b) {
    if (a == null || b == null) return true;

    java.util.Date da = null, db = null;
    try {
    da = new
    java.util.Date( Util.stringToDa te(a,SQL_DATE_F ORMAT).getTime( ));
    db = new
    java.util.Date( Util.stringToDa te(b,SQL_DATE_F ORMAT).getTime( ));
    } catch (java.text.Pars eException ex) {
    _util.logString (IAPI.TRACE_LEV EL_ERROR,"error parsing dates\n");

    _util.logString (IAPI.TRACE_LEV EL_ERROR,Util.s tackToString(ex ),false);
    }

    return (da != null && db != null) ? da.after(db) : true;
    }

    /**
    * Because we get dates in different formats out of the different
    * sql drivers, handle a data, sql date, timestamp, or string.
    */
    protected String dateToString(Ob ject date) {
    if (date == null) return null;

    if (date instanceof java.util.Date) {
    //MWK for debug
    _util.logString (IAPI.TRACE_LEV EL_INFO, "preprocess ed date: " +
    date.toString() );
    return Util.dateToStri ng((java.util.D ate)date,SQL_DA TE_FORMAT);
    }
    else {
    return date.toString() ;
    }
    }


    // We are going to share our connection with the resource so that
    // we can use it to fetch user records.
    protected void connect() throws proprietaryExce ption {
    _connection = null;
    _connection = getConnection() ;
    }

    protected void disconnect() {
    if (_connection != null) {
    try {
    _connection.clo se();
    } catch (Throwable th) {
    }
    _connection = null;
    }
    }

    protected void addToHistoryMap (Map rowMap, Map map, String dateKey) {
    if (rowMap != null) {
    Object o = rowMap.get("BAD GE");
    Object date = rowMap.get(date Key);
    if (o != null && date != null) {
    // This may replace an existing item but is
    // generally a new entry
    map.put(o.toStr ing(),dateToStr ing(date));
    }
    }
    }

    /**
    * Given an existing map (or null), add name, date entries to
    * the map. Then trim off any entries older than the date.
    */
    protected Map addToHistoryMap (List updateRows, Map map, String dateKey,
    int historyLength) {
    if (map == null) map = new HashMap();

    // add new rows
    if (updateRows != null) {
    Iterator it = updateRows.iter ator();
    while (it.hasNext()) {
    UpdateRow row = (UpdateRow)it.n ext();
    Map rowMap = row.getAuditMap ();
    addToHistoryMap (rowMap,map,dat eKey);
    }
    }

    // trim old ones off
    Iterator it = map.entrySet(). iterator();
    String oldestDate = getDateString(-1*historyLength );
    while (it.hasNext()) {
    Map.Entry me = (Map.Entry)it.n ext();
    Object o = me.getValue();
    if (o != null) {
    String date = o.toString();
    if (isAfter(oldest Date,date)) it.remove();
    } else
    it.remove();
    }

    return map;
    }

    public int poll() {

    int numProcessed = 0;
    try {
    connect();

    // use this to get at our persistent data (the last row that we
    successfully processed)
    IAPI prox = new IAPIUser(null,n ull,null,getRes ource());
    UpdateRow ur = new UpdateRow();
    Map history = (Map)prox.getPr operty(CREATE_H ISTORY_NAME);

    if (history != null) {
    ur.setAuditMap( ActiveSyncUtil. reconstituteEmp tyStrings(histo ry));
    } else {
    ur = null;
    }

    if (Thread.current Thread().isInte rrupted()) {
    return numProcessed;
    }

    List requests = null;


    //SDM 5-5 most likely we are here because of a database connectivity
    issue
    //try to reconnect and perform the getAgain

    try {



    requests = getCreateReques ts();



    } catch (Exception getEx) {

    _util.logString (IAPI.TRACE_LEV EL_ERROR, "exception in getCreateReques ts -
    attempting reconnect: " + getEx.toString( ));

    try {

    disconnect();

    connect();

    requests = getCreateReques ts();

    } catch (Exception reconnectEx) {

    _util.logString (IAPI.TRACE_LEV EL_ERROR, "exception attempting to
    reconnect, throwing exception: " + reconnectEx.toS tring());


    throw reconnectEx;


    }


    }



    if (requests != null && requests.size() 0 &&
    !Thread.current Thread().isInte rrupted()) {

    numProcessed = requests.size() ;

    _util.logString (IAPI.TRACE_LEV EL_ERROR, "before
    processCreateRe quests, numprocessed: " + numProcessed);


    processCreateRe quests(requests );

    }


    } catch (Throwable th) {

    _util.logString (IAPI.TRACE_LEV EL_ERROR, "Error processing
    updates ");
    _util.logString (IAPI.TRACE_LEV EL_ERROR, Util.stackToStr ing(th));
    } finally {

    disconnect();

    }

    return numProcessed;
    }
    /**
    * Log whatever we want to from an update.
    */
    protected void logUpdate(int level, UpdateRow update, proprietaryResu lt
    result) {
    if (update == null || _util.getLogLev el() < level) return;

    Map audit = (update!= null) ? update.getAudit Map() : null;
    Map user = (update!= null) ? update.getUserM ap() : null;
    List msgs = (result != null) ? result.getMessa ges() : null;
    List errs = (result != null) ? result.getError s() : null;

    StringBuffer sb = new StringBuffer();
    if (result == null) {
    sb.append("Star ting update processing for resource ");
    sb.append(getRe source().getNam e());
    sb.append('\n') ;
    _util.logString (level,sb.toStr ing());
    sb.setLength(0) ;
    }

    _util.mapToStri ngBuffer(audit, sb);
    _util.mapToStri ngBuffer(user,s b);
    _util.listToStr ingBuffer(errs, sb);
    _util.listToStr ingBuffer(msgs, sb);

    try {
    _util.logString (level, sb.toString(), false);
    } catch (Throwable th) {
    System.out.prin tln("PeopleSoft Resource adapter. Error writing
    log: " + th.toString());
    }
    if (result != null) {
    sb.setLength(0) ;
    sb.append("End update processing for resource ");
    sb.append(getRe source().getNam e());
    sb.append('\n') ;
    _util.logString (level, sb.toString());
    }
    }

    public void callCompleted(I API call) {
    throw new java.lang.Unsup portedOperation Exception("Meth od
    callCompleted() not yet implemented.");
    }

    /**
    * One row of data from the audit log on PeopleSoft. Really just 2 maps
    * of attributes, one from the audit data and the other filled in by the
    * getUser data
    */
    class UpdateRow {
    Map _auditMap,
    _userMap;

    public UpdateRow() {
    }
    public UpdateRow(Map auditMap, Map userMap) {
    _auditMap = auditMap;
    _userMap = userMap;
    }

    public Map getAuditMap() { return _auditMap; }
    public Map getUserMap() { return _userMap; }
    public void setAuditMap(Map auditMap) { _auditMap = auditMap; }
    public void setUserMap(Map userMap) { _userMap = userMap; }
    } // class UpdateRow


    /**
    * Check to see if an account can be created.
    * We ping the server and see if the user already exists.
    */
    public proprietaryResu lt checkCreateAcco unt(WSUser user)
    throws proprietaryExce ption {

    proprietaryResu lt result = new proprietaryResu lt();

    Connection con = getConnection() ;
    closeConnection (con);

    return result;
    }

    /**
    * From here down is the database specific information
    */
    private static final String COLUMN_TERM_DAT E = "TERM_DATE" ;
    private static final String COLUMN_HIRE_DAT E = "LAST_HIRE_DATE ";
    private static final String COLUMN_HR_TYPE = "HR_TYPE";
    private static final String COLUMN_MODIFIED _DATE = "LAST_MODIFIED_ DATE";

    //////////////////////////////////////////////////////////////////////
    //
    // Prototype XML
    //

    //////////////////////////////////////////////////////////////////////
    /**
    * These are the columns in the database. The first entry is the column
    name.
    *
    * The second is the attribute name that we want to map it to (or null
    for
    * no attribute). This map name is used for the default schema in the
    * prototype xml for the adapter.
    *
    * The third entry is the test data. Things starting with TST will have
    an
    * ordinal appended in the test data generation. Things ending with
    _DATE
    * or _TIMESTAMP will get replaced with tomorrow's date or the timestamp
    * at execution time.
    *
    * This table is used to generate the prototype XML, the select
    statement,
    * and to parse the result set coming back from select.
    */
    private static final SchemaData[] _cols = {
    new SchemaData("HR_ SEQ", "sequenceNu m", "TST_SEQ_NU M"),
    new SchemaData("LAN _ID", "accountId" , "TST"),
    new SchemaData("ACT ION_CD", "actionCode ", "TST_ACTION_COD E"),
    new SchemaData("HR_ PROCESSED_YN", "hrProcesse d",
    "TST_HR_PROCESS ED"),
    new SchemaData("HR_ LOAD_DATE", "hrLoadDate ",
    "TST_HR_LOAD_DA TE"),
    new SchemaData("FIR STNAME", "firstname" , "TST_FIRST_NAME "),
    new SchemaData("MID DLEINIT", "middlename ", "TST_MIDDLE_NAM E"),
    new SchemaData("LAS TNAME", "lastname", "TST_LAST_NAME" ),
    new SchemaData("PRE FERREDNAME", "preferredName" ,
    "TST_NICK_FIRST "),
    new SchemaData("EMP LOYEEID", "employeeId ", "TST_EMPLOYEE_I D"),
    new SchemaData("DIV ISIONCODE", "division", "TST_DIVISION_I D"),
    new SchemaData("COS TCENTER", "costCenter ", "TST_COST_CENTE R"),
    new SchemaData("WOR KPHONE", "workPhone" , "TST_WORK_PHONE "),
    new SchemaData("JOB CODE", "jobCode", "TST_JOB_CODE") ,
    new SchemaData("ZIP ", "zipCode", "TST_ZIP_CODE") ,
    new SchemaData("EMP LOYEETYPE", "employeeTy pe",
    "TST_EMPLOYEE_T YPE"),
    new SchemaData("COM PANY", "company", "TST_COMPAN Y"),
    new SchemaData("SUP ERVISORNAME", "supervisorName ",
    "TST_SUPERVISOR _NAME"),
    new SchemaData("SUP ERVISOREMAIL", "supervisorEmai l",
    "TST_SUPERVISOR _EMAIL"),
    new SchemaData("BUS INESS_UNIT", "businessUn it",
    "TST_BUSINESS_U NIT"),
    new SchemaData("SOA F_LOAD_DATE", "soafLoadDa te",
    "TST_SOAF_LOAD_ DATE"),
    new SchemaData("LAS T_MOD_DATE", "lastModDat e",
    "TST_LAST_MOD_D ATE"),
    new SchemaData("SOA F_PROCESSED_YN" , "soafProcessed" ,
    "TST_SOAF_PROCE SSED"),
    new SchemaData("AD_ ACCESS_YN", "adAccess", "TST_AD_ACCESS" ),
    new SchemaData("AD_ GRANTED_YN", "adGranted" , "TST_AD_GRANTED "),
    new SchemaData("AD_ COMMENT", "adComment" , "TST_AD_COMMENT "),
    new SchemaData("AD_ SDID", "adSDID", "TST_AD_SDI D"),
    new SchemaData("AD_ HELPDESK", "adHelpdesk ", "TST_AD_HELPDES K"),
    new SchemaData("EX_ ACCESS_YN", "exAccess", "TST_EX_ACCESS" ),
    new SchemaData("EX_ GRANTED_YN", "exGranted" , "TST_EX_GRANTED "),
    new SchemaData("EX_ COMMENT", "exComment" , "TST_EX_COMMENT "),
    new SchemaData("EX_ SDID", "exSDID", "TST_EX_SDI D"),
    new SchemaData("EX_ HELPDESK", "exHelpdesk ", "TST_EX_HELPDES K"),
    new SchemaData("RAC F_ACCESS_YN", "racfAccess ",
    "TST_RACF_ACCES S"),
    new SchemaData("RAC F_GRANTED_YN", "racfGrante d", "TST_RACF_GRANT ED"),
    new SchemaData("RAC F_COMMENT", "racfCommen t", "TST_RACF_COMME NT"),
    new SchemaData("RAC F_SDID", "racfSDID", "TST_RACF_SDID" ),
    new SchemaData("RAC F_HELPDESK", "racfHelpde sk",
    "TST_RACF_HELPD ESK"),
    new SchemaData("AS4 00_ACCESS_YN", "as400Acces s",
    "TST_AS400_ACCE SS"),
    new SchemaData("AS4 00_GRANTED_YN", "as400Grant ed", "TST_AS400_GRAN TED"),
    new SchemaData("AS4 00_COMMENT", "as400Comme nt", "TST_AS400_COMM ENT"),
    new SchemaData("AS4 00_SDID", "as400SDID" , "TST_AS400_SDID "),
    new SchemaData("AS4 00_HELPDESK", "as400Helpdesk" ,
    "TST_AS400_HELP DESK"),
    new SchemaData("FOR M_NO", "formNumber ", "TST_FORM_NUMBE R")
    };

    static final List _colsList = Arrays.asList(_ cols);
    static final String basePrototypeXm l =
    "<Resource name='HRDatabas eActiveSync' " +
    " class='com.prop rietary.adapter .HRActiveSyncAd apter' " +
    " typeString='HR Database ActiveSync' typeDisplayStri ng='"+ "Active
    Sync Adapter" +"' " +
    " " + Attribute.SYNC_ SOURCE + "='true' >\n"+
    " <ResourceAttrib utes>\n"+
    " <ResourceAttrib ute name='"+RA_HOST +"'
    displayName='"+ Messages.RESATT R_HOST+"' type='string' multi='false' " +
    " value='" + DEFAULT_HOSTNAM E + "'\n"+
    " description='" + Messages.RESATT R_HELP_103 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_PORT +"'
    displayName='"+ Messages.RESATT R_PORT+"' type='string' multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_159 + "'\n"+
    " value='" + DEFAULT_PORT + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_DATA BASE+"'
    displayName='"+ Messages.RESATT R_DATABASE+"' type='string' multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_80 + "'\n"+
    " value='" + DEFAULT_DATABAS E + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_TABL E_NAME+"' type='string'
    multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_80 + "'\n"+
    " value='" + DEFAULT_TABLE_N AME + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_USER +"'
    displayName='"+ Messages.RESATT R_USER+"' type='string' multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_200 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_PASS WORD+"'
    displayName='"+ Messages.RESATT R_PASSWORD+"' type='encrypted '
    multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_154 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_DRIV ER+"'
    displayName='"+ Messages.RESATT R_DRIVER+"' type='string' multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_121 + "'\n"+
    " value='"+DEFAUL T_DRIVER+"'>\n" +
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_URL_ PREFIX+"'
    displayName='"+ Messages.RESATT R_URL_PREFIX+"' type='string'
    multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_123 + "'\n"+
    " value='"+DEFAUL T_PREFIX+"'>\n" +
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_PREH IRE_CREATE+"'
    displayName='"+ Messages.RESATT R_PREHIRE_CREAT E+"' type='string'
    multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_7 + "'\n"+
    " value='2'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_HIRE _SEARCH_WINDOW+ "'
    displayName='"+ Messages.RESATT R_HIRE_SEARCH_W INDOW+"' type='string'
    multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_3 + "'\n"+
    " value='15'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_HIRE _HISTORY+"'
    displayName='"+ Messages.RESATT R_HIRE_HISTORY+ "' type='string'
    multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_2 + "'\n"+
    " value='30'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_TERM _SEARCH_WINDOW+ "'
    displayName='"+ Messages.RESATT R_TERM_SEARCH_W INDOW+"' type='string'
    multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_11 + "'\n"+
    " value='30'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_TERM _HISTORY+"'
    displayName='"+ Messages.RESATT R_TERM_HISTORY+ "' type='string'
    multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_10 + "'\n"+
    " value='60'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_MOD_ HISTORY+"'
    displayName='"+ Messages.RESATT R_MOD_HISTORY+" ' type='string'
    multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_6 + "'\n"+
    " value='15'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_UPDA TE_IF_DELETE+"'
    displayName='"+ Messages.RESATT R_UPDATE_IF_DEL ETE+"' type='string'
    multi='false' value='1'\n"+
    " description='" + Messages.RESATT R_HELP_60 + "'>\n"+
    " </ResourceAttribu te>\n" +
    " <ResourceAttrib ute name='"+ActiveS ync.RA_PROXY_AD MINISTRATOR+"'
    displayName='"+ Messages.RESATT R_PROXY_ADMINIS TRATOR+"' type='string'
    multi='false' value='Configur ator'\n"+
    " description='" + Messages.RESATT R_HELP_30 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+ActiveS ync.RA_FORM+"'
    displayName='"+ Messages.RESATT R_FORM+"' type='string' multi='false'\n "+
    " description='" + Messages.RESATT R_HELP_26 + "'\n"+
    " value='HR Test Form 1'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_SCHE DULE_INTERVAL+" '
    displayName='"+ Messages.RESATT R_SCHEDULE_INTE RVAL+"' type='string'
    multi='false' \n"+
    " description='" + Messages.RESATT R_HELP_51 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_SCHE DULE_INTERVAL_C OUNT+"'
    displayName='"+ Messages.RESATT R_SCHEDULE_INTE RVAL_COUNT+"' type='string'
    multi='false' \n"+
    " description='" + Messages.RESATT R_HELP_52 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_SCHE DULE_START_TIME +"'
    displayName='"+ Messages.RESATT R_SCHEDULE_STAR T_TIME+"' type='string'
    multi='false' \n"+
    " description='" + Messages.RESATT R_HELP_56 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+RA_SCHE DULE_START_DATE +"'
    displayName='"+ Messages.RESATT R_SCHEDULE_STAR T_DATE+"' type='string'
    multi='false' \n"+
    " description='" + Messages.RESATT R_HELP_54 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+ActiveS ync.RA_LOG_LEVE L+"'
    displayName='"+ Messages.RESATT R_LOG_LEVEL+"' type='string' multi='false'
    value='2'\n"+
    " description='" + Messages.RESATT R_HELP_27 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+ActiveS ync.RA_LOG_PATH +"'
    displayName='"+ Messages.RESATT R_LOG_PATH+"' type='string' multi='false' \n"+
    " description='" + Messages.RESATT R_HELP_28 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " <ResourceAttrib ute name='"+ActiveS ync.RA_LOG_SIZE +"'
    displayName='"+ Messages.RESATT R_LOG_SIZE+"' type='string' multi='false' \n"+
    " description='" + Messages.RESATT R_HELP_29 + "'>\n"+
    " </ResourceAttribu te>\n"+
    " </ResourceAttribu tes>\n"+
    " <Template>\n" +
    " <AttrDef name='accountId ' type='string'/>\n"+
    " </Template>\n"+
    " <AccountAttribu teTypes>\n";
    static final String baseXmlEnd =
    " </AccountAttribut eTypes>\n"+
    "</Resource>\n";

    static String prototypeXml = null;

    /**
    * Build the prototype XML from the base defined above, and the schema
    * data defined before that.
    */
    static {
    StringBuffer sb = new StringBuffer(ba sePrototypeXml) ;
    for (int i=0; i< _cols.length; i++) {
    if (_cols[i]._lighthouseMap pedName != null) {
    sb.append(" <AccountAttribu teType name='");
    sb.append(_cols[i]._lighthouseMap pedName);
    sb.append("' mapName='");
    sb.append(_cols[i]._columnName);
    sb.append("' mapType='string ' type='string' required='false '
    />\n");
    } // if to be added to the schema
    }
    sb.append(baseX mlEnd);
    prototypeXml = sb.toString();
    };

    //////////////////////////////////////////////////////////////////////
    //
    // Constructors
    //
    //////////////////////////////////////////////////////////////////////

    /**
    * Create the prototype instance.
    */
    public static Resource staticCreatePro totypeResource( )
    throws proprietaryExce ption {

    Resource res = new Resource(protot ypeXml);
    return res;
    }

    /**
    * This adapter watches the table active_director y_data for items with
    * a LAST_HIRE_DATE between today and two days from now. When it finds
    * entries, it creates or updates the accounts.
    */
    public void init() throws Exception {
    _util = new ActiveSyncUtil( this.getResourc e(),this);
    _util.logString (IAPI.TRACE_LEV EL_INFO,
    "Done initializing HR ActiveSync adapter.\n");
    }

    public void shutdown() {
    _util.logString (IAPI.TRACE_LEV EL_INFO,
    "Shutting down HR ActiveSync adapter.\n");
    }

    /**
    * Query for rows with LAST_HIRE_DATE between today+RA_PREHIR E_CREATE
    and
    * today-RA_HIRE_SEARCH_ WINDOW. Filter against rows already processed
    * (in the createHistory Map). Handle the hire-terminate-rehire case
    * by comparing both the badge number and the hire date.
    *
    * This means that the tuple (LAST_HIRE_DATE ,BADGE) must be unique.
    */
    protected List getCreateReques ts() throws proprietaryExce ption,
    BadRowException {

    CallableStateme nt s = null;
    ResultSet rs = null;
    List list = null;

    try {

    list = new ArrayList();
    s = _connection.pre pareCall("{ call asd_pkg.get_lh_ data(?) }");
    s.registerOutPa rameter(1, OracleTypes.CUR SOR);

    s.execute();

    rs = (ResultSet) s.getObject(1);

    while (rs.next() && !Thread.current Thread().isInte rrupted())
    {
    UpdateRow row = rowToUpdateRow( rs,_colsList);

    Map m = row.getAuditMap ();

    Object o = m.get("LAN_ID") ;

    if (o != null)
    {

    String lanid = o.toString();

    list.add(row);

    }
    }

    } catch (SQLException e) {


    try {
    if (rs != null) rs.close();
    s.close();
    } catch (Exception closeEx) {


    }

    throw new com.proprietary .util.InternalE rror(e);

    } finally {

    try {
    if (rs != null) rs.close();
    s.close();
    } catch (Exception closeEx) {


    }

    }

    return list;
    }

    /**
    * Query for rows with TERMINATION_DAT E between today and
    * today-RA_TERMINATE_SE ARCH_WINDOW. Filter against rows already process
    ed
    * (in the history Map). Handle the terminate-hire-terminate case
    * by comparing both the badge number and the terminate date.
    *
    * This means that the tuple (TERMINATION_DA TE,BADGE) must be unique.
    */
    protected List getTermRequests (Map history) throws proprietaryExce ption,
    BadRowException {

    ResultSet rs = null;
    CallableStateme nt s = null;
    List list = null;

    try {

    list = new ArrayList();
    s = _connection.pre pareCall("{ call asd_pkg.get_lh_ data(?) }");
    s.registerOutPa rameter(1, OracleTypes.CUR SOR);

    s.execute();
    rs = (ResultSet) s.getObject(1);

    while (rs.next() && !Thread.current Thread().isInte rrupted()) {
    UpdateRow row = rowToUpdateRow( rs,_colsList);

    Map m = row.getAuditMap ();
    Object o = m.get("LAN_ID") ;
    String lanid = o.toString();

    if (o != null) {
    list.add(row);
    _util.logString (IAPI.TRACE_LEV EL_INFO, "-->lanid: " +
    lanid);
    }
    }

    } catch (SQLException e) {

    try {
    if (rs != null) rs.close();
    s.close();
    } catch (Exception closeEx) {


    }

    throw new com.proprietary .util.InternalE rror(e);
    } finally {
    try {
    if (rs != null) rs.close();
    s.close();
    } catch (Exception closeEx) {


    }
    }

    return list;
    }

    /**
    * Get the name of the hire date column for creating the processed row
    * history
    */
    protected String getHireDateColu mnName() { return COLUMN_HIRE_DAT E; }
    /**
    * Get the name of the hire date column for creating the processed row
    * history
    */
    protected String getTermDateColu mnName() { return COLUMN_TERM_DAT E; }

    class BadRowException extends Exception {
    }
    }


Working...