/*******************************************************************************
$Source: /cvs/repositories/openii3/project/java/examples/org/any_openeai_enterprise/services/i2s/repository/RdbmsI2sRepository.java,v $
$Revision: 1.2 $
*******************************************************************************/
/**********************************************************************
This file is part of the OpenEAI Application Foundation or
OpenEAI Message Object API created by Tod Jackson
(tod@openeai.org) and Steve Wheat (steve@openeai.org) at
the University of Illinois Urbana-Champaign.
Copyright (C) 2002 The OpenEAI Software Foundation
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For specific licensing details and examples of how this software
can be used to build commercial integration software or to implement
integrations for your enterprise, visit http://www.OpenEai.org/licensing.
*/
package org.any_openeai_enterprise.services.i2s.repository;
// Core Java and Utilities
import java.util.*;
import java.sql.*;
import javax.jms.*;
// Log4j
import org.apache.log4j.Category;
import org.apache.log4j.PropertyConfigurator;
// JDOM
import org.jdom.Element;
// General OpenEAI Foundation
import org.openeai.config.*;
import org.openeai.dbpool.*;
import org.openeai.jms.producer.*;
import org.openeai.moa.*;
import org.openeai.uuid.RandomUuid;
// OpenEAI Utilities
import org.openeai.utils.sequence.*;
// OpenEAI Implementation Objects and Message Objects
import org.any_openeai_enterprise.moa.jmsobjects.coreapplication.v1_0.InstitutionalIdentity;
import org.any_openeai_enterprise.moa.objects.resources.v1_0.UnknownPerson;
import org.any_openeai_enterprise.moa.objects.resources.v1_0.Identifier;
import org.any_openeai_enterprise.moa.objects.resources.v1_0.Name;
import org.any_openeai_enterprise.moa.objects.resources.v1_0.Date;
/**
* This is an I2sRepository implementation that uses a simple relational
* database management system as a data store.
* <P>
* @author Steve Wheat (steve@openeai.org)
* @version 1.0 - 24 July 2003
*/
public class RdbmsI2sRepository extends I2sRepositoryImpl
implements I2sRepository {
private boolean m_isInitialized = false;
private ProducerPool m_pubSubProducerPool = null;
private EnterpriseConnectionPool m_connPool = null;
private Sequence m_instIdSequence = null;
private boolean m_publishSyncMessages = true;
private boolean m_allowPurge = false;
private static String PURGE_ACTION = "Purge";
private static String DELETE_ACTION = "Delete";
public RdbmsI2sRepository () {
}
/**
*
*<P>
* @param Properties, the initialization properties.
*<P>
* @throws I2sRepositoryException with details of the initialization error.
*/
public void init (Properties props) throws I2sRepositoryException {
if (m_isInitialized == true) {
logger.debug("[RdbmsI2sRepository] Initialization requested, but " +
"the repository is already initialized.");
return;
}
logger = org.openeai.OpenEaiObject.logger;
logger.info("[RdbmsI2sRepository] Initializing...");
// Initialize an AppConfig and set it for this repository.
try {
setAppConfig(new AppConfig(props));
}
catch (EnterpriseConfigurationObjectException e) {
String errMsg = "Error initializing AppConfig for the I2sRepository.";
logger.fatal("[RdbmsI2sRepository.init] " + errMsg);
throw new I2sRepositoryException(errMsg);
}
// Reinitialize the logger to get the logger configuration specified with
// this repository.
try {
logger.info("[RdbmsI2sRepository.init] Configuring a logger for the " +
"repository. If no logger configuration is specified with this " +
"repository, the repository will set its logger to be that of " +
"org.openeai.OpenEaiObject.");
LoggerConfig lConfig = new LoggerConfig();
lConfig = (LoggerConfig)getAppConfig()
.getObjectByType(lConfig.getClass().getName());
logger = Category.getInstance(getClass().getName());
PropertyConfigurator.configure(lConfig.getProperties());
}
catch (Exception e) {
logger.warn("[RdbmsI2sRepository.init] No logger specified or there was "
+ "an error reconfiguring logger, using org.openeai.OpenEaiObject." +
"logger.");
}
// Get and set the general properties for this repository.
PropertyConfig pConfig = new PropertyConfig();
try {
pConfig = (PropertyConfig)getAppConfig()
.getObject("Properties");
}
catch (EnterpriseConfigurationObjectException eoce) {
String errMsg = "Error retrieving a PropertyConfig object from " +
"AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.init] " + errMsg);
throw new I2sRepositoryException(errMsg);
}
setProperties(pConfig.getProperties());
// Initialize a pub/sub producer pool.
try {
m_pubSubProducerPool = (ProducerPool)getAppConfig().
getObject("I2sPubSubProducerPool");
}
catch (EnterpriseConfigurationObjectException eoce) {
String errMsg = "Error retrieving a ProducerPool object " +
"from AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.init] " + errMsg);
throw new I2sRepositoryException(errMsg);
}
// Initialize a database connection pool.
try {
m_connPool = (EnterpriseConnectionPool)getAppConfig().
getObject("I2sRepositoryDbPool");
}
catch (EnterpriseConfigurationObjectException eoce) {
String errMsg = "Error retrieving an EnterpriseConnectionPool object " +
"from AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.init] " + errMsg);
throw new I2sRepositoryException(errMsg);
}
// Initialize a sequence to use for InstitutionalId numbers.
try {
Sequence instIdSequence = (Sequence)getAppConfig().
getObject("InstitutionalIdSequence");
setInstIdSequence(instIdSequence);
}
catch (EnterpriseConfigurationObjectException eoce) {
String errMsg = "Error retrieving a Sequence object " +
"from AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.init] " + errMsg);
throw new I2sRepositoryException(errMsg);
}
// Set the publish sync messages indicator from the properties.
String sPublishSyncMessages = getProperties()
.getProperty("publishSyncMessages");
if (sPublishSyncMessages == null) {
String errMsg = "publishSyncMessages property value is null. It must " +
"be present in the deployment descriptor, and it must have a value " +
"of 'true' or 'false'. Can't continue.";
logger.fatal("[RdbmsI2sRepository.init] " + errMsg);
throw new I2sRepositoryException(errMsg);
}
if (sPublishSyncMessages.equalsIgnoreCase("true") ||
sPublishSyncMessages.equalsIgnoreCase("false")) {
m_publishSyncMessages = Boolean.valueOf(sPublishSyncMessages)
.booleanValue();
logger.info("[RdbmsI2sRepository.init] publishSyncMessages " +
"is " + m_publishSyncMessages + ".");
}
else {
String errMsg = "publishSyncMessages property value is present in the " +
"deployment descriptor, but it has an invalid value. It must have a " +
"value of 'true' or 'false'. Can't continue.";
logger.fatal("[RdbmsI2sRepository.init] " + errMsg);
throw new I2sRepositoryException(errMsg);
}
// Set the allow purge indicator from the properties.
String sAllowPurge = getProperties().getProperty("allowPurge");
if (sAllowPurge == null) {
String errMsg = "allowPurge property value is null. It must be present " +
"in the deployment descriptor, and it must have a value of 'true' or " +
"'false'. Can't continue.";
logger.fatal("[RdbmsI2sRepository.init] " + errMsg);
throw new I2sRepositoryException(errMsg);
}
if (sAllowPurge.equalsIgnoreCase("true") ||
sAllowPurge.equalsIgnoreCase("false")) {
m_allowPurge = Boolean.valueOf(sAllowPurge)
.booleanValue();
logger.info("[RdbmsI2sRepository.init] allowPurge " +
"is " + m_allowPurge + ".");
}
else {
String errMsg = "allowPurge property value is present in the " +
"deployment descriptor, but it has an invalid value. It must have a " +
"value of 'true' or 'false'. Can't continue.";
logger.fatal("[RdbmsI2sRepository.init] " + errMsg);
throw new I2sRepositoryException(errMsg);
}
// Verify that all message objects required are in AppConfig.
// Get a configured NetId object out of AppConfig.
try {
InstitutionalIdentity instIdent = (InstitutionalIdentity)getAppConfig()
.getObject("InstitutionalIdentity");
UnknownPerson uPerson = (UnknownPerson)getAppConfig()
.getObject("UnknownPerson");
Name aName = (Name)getAppConfig().getObject("Name");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving a required object from AppConfig. Log it
// and throw an exception.
String errMsg = "An error occurred retrieving a required object from " +
"AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.init] " + errMsg);
throw new I2sRepositoryException(errMsg);
}
// Set isInitialized to indicate that the repository is ready for use.
m_isInitialized = true;
logger.debug("[RdbmsI2sRepository] Initialization complete.");
return;
}
/**
*
*<P>
* @param UnknownPerson, an unknown person for whom to retrieve an
* InstitutionalIdentity.
*<P>
* @throws I2sRepositoryException with details of the retrieval error.
*/
public final InstitutionalIdentity retrieveInstitutionalIdentity(UnknownPerson
uPerson) throws I2sRepositoryException {
EnterprisePooledConnection epc = null;
java.sql.Connection conn = null;
try {
// Get a database connection to use in this transaction.
epc = m_connPool.getExclusiveConnection();
conn = epc.getConnection();
conn.setAutoCommit(true);
// Retrieve the InstitutionalIdentity.
InstitutionalIdentity instIdent = new InstitutionalIdentity();
instIdent = retrieveInstitutionalIdentity(conn, uPerson);
return instIdent;
}
catch (SQLException se) {
// There was an error retrieving a database connection from the pool to
// use in the transaction. Log it and throw an exception.
String errMsg = "Error retrieving a database connection from the pool " +
"to use in the transaction. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
se.printStackTrace();
throw new I2sRepositoryException(se.getMessage());
}
finally {
// Make sure the database connection we retrieved exclusively from the
// database connection pool for this transaction is released back to the
// pool.
try { m_connPool.releaseExclusiveConnection(epc); }
catch (SQLException se) {
String errMsg = "Error releasing exclusive connection back to the " +
"database pool. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
}
}
}
/**
*
*<P>
* @param java.sql.Connection, a database connection to use.
* @param UnknownPerson, an unknown person for whom to retrieve an
* InstitutionalIdentity.
*<P>
* @throws I2sRepositoryException with details of the retrieval error.
*/
private final InstitutionalIdentity retrieveInstitutionalIdentity
(java.sql.Connection conn, UnknownPerson uPerson) throws
I2sRepositoryException {
// If a social security number is provided, retrieve the
// InstitutionalIdentity using that identifier.
InstitutionalIdentity instIdent = new InstitutionalIdentity();
if (uPerson.getSocialSecurityNumber() != null) {
Identifier id = new Identifier();
try {
id.setType("SocialSecurityNumber");
id.setValue(uPerson.getSocialSecurityNumber());
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values on the identifier object.
// Log it and throw an exception.
String errMsg = "An error occurred setting field values on the " +
"identifier object. The exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity]" +
" " + errMsg);
throw new I2sRepositoryException(errMsg);
}
instIdent = retrieveInstitutionalIdentity(conn, id);
}
// Otherwise, retrieve the InstitutionalIdentity using the Name,
// Birthdate, and Gender.
else {
instIdent =
retrieveInstitutionalIdentityByNameBirthdateAndGender(conn, uPerson);
}
return instIdent;
}
/**
*
*<P>
* @param Identifier, an identifier with which to retrieve an
* InstitutionalIdentity.
*<P>
* @throws I2sRepositoryException with details of the retrieval error.
*/
public final InstitutionalIdentity retrieveInstitutionalIdentity
(Identifier id) throws I2sRepositoryException {
EnterprisePooledConnection epc = null;
java.sql.Connection conn = null;
try {
// Get a database connection to use in this transaction.
epc = m_connPool.getExclusiveConnection();
conn = epc.getConnection();
conn.setAutoCommit(true);
// Retrieve the InstitutionalIdentity.
InstitutionalIdentity instIdent = new InstitutionalIdentity();
instIdent = retrieveInstitutionalIdentity(conn, id);
return instIdent;
}
catch (SQLException se) {
// There was an error retrieving a database connection from the pool to
// use in the transaction. Log it and throw an exception.
String errMsg = "Error retrieving a database connection from the pool " +
"to use in the transaction. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
se.printStackTrace();
throw new I2sRepositoryException(se.getMessage());
}
finally {
// Make sure the database connection we retrieved exclusively from the
// database connection pool for this transaction is released back to the
// pool.
try { m_connPool.releaseExclusiveConnection(epc); }
catch (SQLException se) {
String errMsg = "Error releasing exclusive connection back to the " +
"database pool. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
}
}
}
/**
*
*<P>
* @param java.sql.Connection, a database connection to use.
* @param Identifier, an identifier with which to retrieve an
* InstitutionalIdentity.
*<P>
* @throws I2sRepositoryException with details of the retrieval error.
*/
private final InstitutionalIdentity retrieveInstitutionalIdentity
(java.sql.Connection conn, Identifier id) throws I2sRepositoryException {
// Verify that the Identifier is not null.
if (id == null) {
// The identifier is null. Log it and throw an exception.
String errMsg = "The identifier is null. Cannot retrieve an " +
"institutional identity with a null identifier.";
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Verify that the Identifier type is not null.
if (id.getType() == null) {
// The identifier type is null. Log it and throw an exception.
String errMsg = "The identifier type is null. Cannot retrieve an " +
"institutional identity with a null identifier type.";
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Verify that the Identifier value is not null.
if (id.getValue() == null) {
// The identifier value is null. Log it and throw an exception.
String errMsg = "The identifier value is null. Cannot retrieve an " +
"institutional identity with a null identifier value.";
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
boolean foundSupportedIdentifierType = false;
// If the Identifier type is SocialSecurityNumber, retrieve the
// InstitutionalIdentity by SSN.
InstitutionalIdentity instIdent = new InstitutionalIdentity();
if (id.getType().equalsIgnoreCase("SocialSecurityNumber")) {
foundSupportedIdentifierType = true;
instIdent = retrieveInstitutionalIdentityBySsn(conn, id.getValue());
}
// If the Identifier type is InstitutionalId, retrieve the
// InstitutionalIdentity by InstitutionalId.
if (id.getType().equalsIgnoreCase("InstitutionalId")) {
foundSupportedIdentifierType = true;
instIdent = retrieveInstitutionalIdentityByInstId(conn, id.getValue());
}
// If no supported identifier type was found, log it an throw an exception.
if (foundSupportedIdentifierType == false) {
String errMsg = "Invalid identifier type. '" + id.getType() + "' is not "
+ " a valid identifier type. The supported identifier types are '" +
"SocialSecurityNumber' and 'InstitutionalId'.";
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
return instIdent;
}
/**
*
*<P>
* @param java.sql.Connection, a database connection to use.
* @param String, a social security number with which to retrieve an
* InstitutionalIdentity.
*<P>
* @throws I2sRepositoryException with details of the retrieval error.
*/
private final InstitutionalIdentity retrieveInstitutionalIdentityBySsn
(java.sql.Connection conn, String ssn) throws I2sRepositoryException {
logger.debug("[RdbmsI2sRepository] Retrieving InstitutionalIdentity for " +
"SSN: " + ssn + ".");
// Get a configured InstitutionalIdentity object out of AppConfig.
InstitutionalIdentity instIdent = new InstitutionalIdentity();
try {
instIdent = (InstitutionalIdentity)getAppConfig()
.getObject("InstitutionalIdentity");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving an InstitutionalIdentity object from
// AppConfig. Log it and throw an exception.
String errMsg = "An error occurred retrieving an InstitutionalIdentity " +
"object from AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdBySsn] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Get a configured UnknownPerson object out of AppConfig.
UnknownPerson uPerson = new UnknownPerson();
try {
uPerson = (UnknownPerson)getAppConfig().getObject("UnknownPerson");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving an UnknownPerson object from
// AppConfig. Log it and throw an exception.
String errMsg = "An error occurred retrieving an UnknownPerson " +
"object from AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdBySsn] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Get a configured Name object out of AppConfig.
Name name = new Name();
try {
name = (Name)getAppConfig().getObject("Name");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving a Name object from AppConfig. Log it and
// throw an exception.
String errMsg = "An error occurred retrieving a Name object from " +
"AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdBySsn] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Initialize a query string to retrieve the InstitutionalIdentity.
String getString1 = "SELECT INST_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, " +
"SSN, BIRTH_DATE, GENDER FROM T_INST_IDENT WHERE SSN = ? AND " +
"TERMINATED_DATE IS NULL";
try {
PreparedStatement getStmt1 = conn.prepareStatement(getString1);
getStmt1.clearParameters();
getStmt1.setString(1, ssn);
ResultSet r1 = getStmt1.executeQuery();
if (r1.next()) {
// The InstitutionalIdentity exists. Log a message and build the
// InstitutionalIdentity object.
logger.debug("[RdbmsI2sRepository.retrieveInstitutionalIdentityBySsn] "
+ "Found an InstitutionalIdentity in the database for SSN: " + ssn +
".");
// Set the values of the Name object.
try {
name.setFirstName(r1.getString(2));
name.setMiddleName(r1.getString(3));
name.setLastName(r1.getString(4));
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values for the Name. Log it,
// close the statement, and throw an exception.
String errMsg = "An error occurred seeting field values for the " +
"Name. the exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentityBySsn]"
+ " " + errMsg);
getStmt1.close();
throw new I2sRepositoryException(errMsg);
}
// Set the values of the UnknownPerson object.
try {
uPerson.setName(name);
uPerson.setSocialSecurityNumber(r1.getString(5));
org.any_openeai_enterprise.moa.objects.resources.v1_0.Date xeoStartDate =
toXeoDate("BirthDate", r1.getDate(6));
uPerson.setBirthDate(xeoStartDate);
uPerson.setGender(r1.getString(7));
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values for the UnknownPerson.
// Log it, close the statement, and throw an exception.
String errMsg = "An error occurred seeting field values for the " +
"UnknownPerson. the exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentityBySsn]"
+ " " + errMsg);
getStmt1.close();
throw new I2sRepositoryException(errMsg);
}
// Set the values of the InstitutionalIdentity object.
try {
instIdent.setInstitutionalId(r1.getString(1));
instIdent.setUnknownPerson(uPerson);
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values for the
// InstitutionalIdentity. Log it, close the statement, and throw an
// exception.
String errMsg = "An error occurred seeting field values for the " +
"InstitutionalIdentity. the exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentityBySsn]"
+ errMsg);
getStmt1.close();
throw new I2sRepositoryException(errMsg);
}
}
else {
// The InstitutionalIdentity does not exist. Log this fact and set the
// InstitutionalIdentity to null.
String msg = "Did not find an InstitutionalIdentity in the database " +
"for SSN: " + ssn + ".";
logger.debug("[RdbmsI2sRepository.retrieveInstitutionalIdentityBySsn] "
+ msg);
instIdent = null;
}
// Close the statement and return the InstitutionalIdentity.
getStmt1.close();
return instIdent;
}
catch (SQLException se) {
// There was an error querying the database to retrieve the
// InstitutionalIdentity. Log it and throw an exception.
String errMsg = "Error querying the database to retrieve the " +
"InstitutionalIdentity. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentityBySsn] " +
errMsg);
se.printStackTrace();
throw new I2sRepositoryException(se.getMessage());
}
}
/**
*
*<P>
* @param java.sql.Connection, a database connection to use.
* @param String, an institutional ID number with which to retrieve an
* InstitutionalIdentity.
*<P>
* @throws I2sRepositoryException with details of the retrieval error.
*/
private final InstitutionalIdentity retrieveInstitutionalIdentityByInstId
(java.sql.Connection conn, String instId) throws I2sRepositoryException {
logger.debug("[RdbmsI2sRepository] Retrieving InstitutionalIdentity for " +
"InstitutionalId: " + instId + ".");
// Get a configured InstitutionalIdentity object out of AppConfig.
InstitutionalIdentity instIdent = new InstitutionalIdentity();
try {
instIdent = (InstitutionalIdentity)getAppConfig()
.getObject("InstitutionalIdentity");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving an InstitutionalIdentity object from
// AppConfig. Log it and throw an exception.
String errMsg = "An error occurred retrieving an InstitutionalIdentity " +
"object from AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdByInstId] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Get a configured UnknownPerson object out of AppConfig.
UnknownPerson uPerson = new UnknownPerson();
try {
uPerson = (UnknownPerson)getAppConfig().getObject("UnknownPerson");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving an UnknownPerson object from
// AppConfig. Log it and throw an exception.
String errMsg = "An error occurred retrieving an UnknownPerson " +
"object from AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdByIndtId] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Get a configured Name object out of AppConfig.
Name name = new Name();
try {
name = (Name)getAppConfig().getObject("Name");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving a Name object from AppConfig. Log it and
// throw an exception.
String errMsg = "An error occurred retrieving a Name object from " +
"AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdByInstId] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Initialize a query string to retrieve the InstitutionalIdentity.
String getString1 = "SELECT INST_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, " +
"SSN, BIRTH_DATE, GENDER FROM T_INST_IDENT WHERE INST_ID = ? AND " +
"TERMINATED_DATE IS NULL";
try {
PreparedStatement getStmt1 = conn.prepareStatement(getString1);
getStmt1.clearParameters();
getStmt1.setString(1, instId);
ResultSet r1 = getStmt1.executeQuery();
if (r1.next()) {
// The InstitutionalIdentity exists. Log a message and build the
// InstitutionalIdentity object.
logger.debug("[RdbmsI2sRepository.retrieveInstitutionalIdentityByInst" +
"Id] Found an InstitutionalIdentity in the database for " +
"InstitutionalId: " + instId + ".");
// Set the values of the Name object.
try {
name.setFirstName(r1.getString(2));
name.setMiddleName(r1.getString(3));
name.setLastName(r1.getString(4));
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values for the Name. Log it,
// close the statement, and throw an exception.
String errMsg = "An error occurred seeting field values for the " +
"Name. the exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentityBy" +
"InstId] " + errMsg);
getStmt1.close();
throw new I2sRepositoryException(errMsg);
}
// Set the values of the UnknownPerson object.
try {
uPerson.setName(name);
uPerson.setSocialSecurityNumber(r1.getString(5));
org.any_openeai_enterprise.moa.objects.resources.v1_0.Date xeoStartDate =
toXeoDate("BirthDate", r1.getDate(6));
uPerson.setBirthDate(xeoStartDate);
uPerson.setGender(r1.getString(7));
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values for the UnknownPerson.
// Log it, close the statement, and throw an exception.
String errMsg = "An error occurred seeting field values for the " +
"UnknownPerson. the exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentityBy" +
"InstId] " + errMsg);
getStmt1.close();
throw new I2sRepositoryException(errMsg);
}
// Set the values of the InstitutionalIdentity object.
try {
instIdent.setInstitutionalId(r1.getString(1));
instIdent.setUnknownPerson(uPerson);
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values for the
// InstitutionalIdentity. Log it, close the statement, and throw an
// exception.
String errMsg = "An error occurred seeting field values for the " +
"InstitutionalIdentity. the exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdByInst" +
"Id] " + errMsg);
getStmt1.close();
throw new I2sRepositoryException(errMsg);
}
}
else {
// The InstitutionalIdentity does not exist. Log this fact and set the
// InstitutionalIdentity to null.
String msg = "Did not find an InstitutionalIdentity in the database " +
"for InstitutionalId: " + instId + ".";
logger.debug("[RdbmsI2sRepository.retrieveInstitutionalIdentityByInst" +
"Id] " + msg);
instIdent = null;
}
// Close the statement and return the InstitutionalIdentity.
getStmt1.close();
return instIdent;
}
catch (SQLException se) {
// There was an error querying the database to retrieve the
// InstitutionalIdentity. Log it and throw an exception.
String errMsg = "Error querying the database to retrieve the " +
"InstitutionalIdentity. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentityByInst" +
"Id] " + errMsg);
se.printStackTrace();
throw new I2sRepositoryException(se.getMessage());
}
}
/**
*
*<P>
* @param java.sql.Connection, a database connection to use.
* @param UnknownPerson, an unknown person for whom to retrieve an
* InstitutionalIdentity.
*<P>
* @throws I2sRepositoryException with details of the retrieval error.
*/
private final InstitutionalIdentity retrieveInstitutionalIdentityByNameBirthdateAndGender
(java.sql.Connection conn, UnknownPerson queryPerson) throws
I2sRepositoryException {
logger.debug("[RdbmsI2sRepository] Retrieving InstitutionalIdentity for " +
"UnknownPerson: " + queryPerson.toString() + ".");
// Get a configured InstitutionalIdentity object out of AppConfig.
InstitutionalIdentity instIdent = new InstitutionalIdentity();
try {
instIdent = (InstitutionalIdentity)getAppConfig()
.getObject("InstitutionalIdentity");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving an InstitutionalIdentity object from
// AppConfig. Log it and throw an exception.
String errMsg = "An error occurred retrieving an InstitutionalIdentity " +
"object from AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Get a configured UnknownPerson object out of AppConfig.
UnknownPerson uPerson = new UnknownPerson();
try {
uPerson = (UnknownPerson)getAppConfig().getObject("UnknownPerson");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving an UnknownPerson object from
// AppConfig. Log it and throw an exception.
String errMsg = "An error occurred retrieving an UnknownPerson " +
"object from AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Get a configured Name object out of AppConfig.
Name name = new Name();
try {
name = (Name)getAppConfig().getObject("Name");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving a Name object from AppConfig. Log it and
// throw an exception.
String errMsg = "An error occurred retrieving a Name object from " +
"AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Initialize a query string to retrieve the InstitutionalIdentity.
String getString1 = "SELECT INST_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, " +
"SSN, BIRTH_DATE, GENDER FROM T_INST_IDENT WHERE LAST_NAME = ? " +
"AND BIRTH_DATE = ? AND GENDER = ? AND TERMINATED_DATE IS NULL";
// If the UnknownPerson in the query has a FirstName, then add it to the
// where clause and indicate that we must set this parameter of the
// subsequent prepared statement.
boolean hasFirstName = false;
if (queryPerson.getName().getFirstName() != null) {
getString1 = getString1 + " AND FIRST_NAME = ?";
hasFirstName = true;
}
// If the UnknownPerson in the query has a MiddleName, then add it to the
// where clause and indicate that we must set this parameter of the
// subsequent prepared statement.
boolean hasMiddleName = false;
if (queryPerson.getName().getMiddleName() != null) {
getString1 = getString1 + " AND MIDDLE_NAME = ?";
hasMiddleName = true;
}
try {
PreparedStatement getStmt1 = conn.prepareStatement(getString1);
getStmt1.clearParameters();
getStmt1.setString(1, queryPerson.getName().getLastName());
java.sql.Date birthDate = null;
try { birthDate = toSqlDate(queryPerson.getBirthDate()); }
catch(InvalidFormatException ife) {
// An error occurred formatting the birth date. Log it and throw an
// exception.
String errMsg = "An error occurred formatting the birth date. The " +
"excception is: " + ife.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
}
getStmt1.setDate(2, birthDate);
getStmt1.setString(3, queryPerson.getGender());
if (hasFirstName == true) {
getStmt1.setString(4, queryPerson.getName().getFirstName());
}
if (hasMiddleName == true) {
getStmt1.setString(5, queryPerson.getName().getMiddleName());
}
ResultSet r1 = getStmt1.executeQuery();
if (r1.next()) {
// The InstitutionalIdentity exists. Log a message and build the
// InstitutionalIdentity object.
logger.debug("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
"Found an InstitutionalIdentity in the database for the " +
"UnknownPerson: " + queryPerson.toString());
// Set the values of the Name object.
logger.debug("InstId: " + r1.getString(1));
logger.debug("FirstName: " + r1.getString(2));
logger.debug("MiddleName: " + r1.getString(3));
logger.debug("LastName: " + r1.getString(4));
logger.debug("SSN: " + r1.getString(5));
logger.debug("BirthDate (date): " + r1.getDate(6).toString());
// Note: uncommenting the next line with break this gateway for MySQL.
// logger.debug("BirthDate (timestamp): " + r1.getTimestamp(6).toString());
logger.debug("Gender: " + r1.getString(7));
try {
name.setFirstName(r1.getString(2));
name.setMiddleName(r1.getString(3));
name.setLastName(r1.getString(4));
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values for the Name. Log it,
// close the statement, and throw an exception.
String errMsg = "An error occurred setting field values for the " +
"Name. the exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
getStmt1.close();
throw new I2sRepositoryException(errMsg);
}
// Set the values of the UnknownPerson object.
try {
uPerson.setName(name);
uPerson.setSocialSecurityNumber(r1.getString(5));
org.any_openeai_enterprise.moa.objects.resources.v1_0.Date xeoStartDate =
toXeoDate("BirthDate", r1.getDate(6));
uPerson.setBirthDate(xeoStartDate);
uPerson.setGender(r1.getString(7));
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values for the UnknownPerson.
// Log it, close the statement, and throw an exception.
String errMsg = "An error occurred seeting field values for the " +
"UnknownPerson. the exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity]"
+ " " + errMsg);
getStmt1.close();
throw new I2sRepositoryException(errMsg);
}
// Set the values of the InstitutionalIdentity object.
try {
instIdent.setInstitutionalId(r1.getString(1));
instIdent.setUnknownPerson(uPerson);
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values for the
// InstitutionalIdentity. Log it, close the statement, and throw an
// exception.
String errMsg = "An error occurred seeting field values for the " +
"InstitutionalIdentity. the exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity]"
+ errMsg);
getStmt1.close();
throw new I2sRepositoryException(errMsg);
}
}
else {
// The InstitutionalIdentity does not exist. Log this fact and set the
// InstitutionalIdentity to null.
String msg = "Did not find an InstitutionalIdentity in the database " +
"for UnknownPerson: " + queryPerson.toString();
logger.debug("[RdbmsI2sRepository.retrieveInstitutionalIdentity] "
+ msg);
instIdent = null;
}
// Close the statement and return the InstitutionalIdentity.
getStmt1.close();
return instIdent;
}
catch (SQLException se) {
// There was an error querying the database to retrieve the
// InstitutionalIdentity. Log it and throw an exception.
String errMsg = "Error querying the database to retrieve the " +
"InstitutionalIdentity. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.retrieveInstitutionalIdentity] " +
errMsg);
se.printStackTrace();
throw new I2sRepositoryException(se.getMessage());
}
}
/**
*
*<P>
* @param UnknownPerson, an unknown person for whom to generate an
* institutional identity.
*<P>
* @throws I2sRepositoryException with details of the generate error.
*/
public final InstitutionalIdentity generateInstitutionalIdentity(UnknownPerson
uPerson) throws I2sRepositoryException {
PubSubProducer pub = null;
EnterprisePooledConnection epc = null;
java.sql.Connection conn = null;
try {
// Get a pub/sub producer to use in this transaction.
pub = (PubSubProducer)m_pubSubProducerPool.getExclusiveProducer();
// Get a database connection to use in this transaction.
epc = m_connPool.getExclusiveConnection();
conn = epc.getConnection();
conn.setAutoCommit(false);
// Generate the InstitutionalIdentity.
InstitutionalIdentity instIdent = new InstitutionalIdentity();
instIdent = generateInstitutionalIdentity(pub, conn, uPerson);
return instIdent;
}
catch (JMSException jmse) {
// There was an error retrieving a pub/sub producer from the pool to
// use in the transaction. Log it and throw an exception.
String errMsg = "Error retrieving a pub/sub producer from the pool " +
"to use in the transaction. The exception is: " + jmse.getMessage();
logger.fatal("[RdbmsI2sRepository.generateInstitutionalIdentity] " +
errMsg);
jmse.printStackTrace();
throw new I2sRepositoryException(errMsg);
}
catch (SQLException se) {
// There was an error retrieving a database connection from the pool to
// use in the transaction. Log it and throw an exception.
String errMsg = "Error retrieving a database connection from the pool " +
"to use in the transaction. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.generateInstitutionalIdentity] " +
errMsg);
se.printStackTrace();
throw new I2sRepositoryException(se.getMessage());
}
finally {
// Make sure the pub/sub producer we retrieved exclusively from the
// producer pool for this transaction is released back to the pool.
m_pubSubProducerPool.releaseProducer(pub);
// Make sure the database connection we retrieved exclusively from the
// database connection pool for this transaction is released back to the
// pool.
try { m_connPool.releaseExclusiveConnection(epc); }
catch (SQLException se) {
String errMsg = "Error releasing exclusive connection back to the " +
"database pool. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.generateInsitutionalIdentity] " +
errMsg);
}
}
}
/**
*
*<P>
* @param PubSubProducer, a pub/sub producer to use.
* @param java.sql.Connection, a database connection to use.
* @param UnknownPerson, an unknown person for whom to generate an
* institutional identity.
*<P>
* @throws I2sRepositoryException with details of the generate error.
*/
private final InstitutionalIdentity generateInstitutionalIdentity
(PubSubProducer pub, java.sql.Connection conn, UnknownPerson uPerson) throws
I2sRepositoryException {
logger.debug("[RdbmsI2sRepository] Generating InstitutionalIdentity for " +
"UnknownPerson: " + uPerson.toString());
// Verify that the UnknownPerson is not null. If it is null, log it and
// throw an exception.
if (uPerson == null) {
String errMsg = "The UnknownPerson object is null. Cannot generate " +
"an InstitutionalIdentity with a null UnknownPerson object.";
logger.fatal("[RdbmsI2sRepository.generateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Determine whether the UnknownPerson is complete; that is, has a name,
// birth date, and gender.
boolean hasName = false;
boolean hasBirthDate = false;
boolean hasGender = false;
// -- Determine if the UnknownPerson has a name.
if (uPerson.getName() != null) {
if (uPerson.getName().getLastName() != null) {
hasName = true;
}
}
// -- Determine if the UnknownPerson has a BirthDate.
if (uPerson.getBirthDate() != null) {
hasBirthDate = true;
}
// -- Determine if the UnknwonPerson has a Gender.
if (uPerson.getGender() != null) {
hasGender = true;
}
if (hasName == false || hasBirthDate == false || hasGender == false) {
// The UnknownPerson is incomplete. Log it, and throw an exception.
String errMsg = "The UnknownPerson is missing required data. Name, " +
"BirthDate, and Gender are required.";
logger.fatal("[RdbmsI2sRepository.generateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Determine if the UnknownPerson has already been assigned an
// InstitutionalId. If so, log it and throw an exception.
InstitutionalIdentity existingInstIdent = new InstitutionalIdentity();
existingInstIdent = retrieveInstitutionalIdentity(conn, uPerson);
if (existingInstIdent != null) {
String errMsg = "An InstitutionalId has already been assigned to this " +
"UnknownPerson. Cannot generate a new InstitutionalIdentity fot this " +
"UnknownPerson.";
logger.fatal("[RdbmsI2sRepository.generateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Retrieve the next InstitutionalId to use for this person.
String instId = null;
try { instId = getInstIdSequence().next(); }
catch (SequenceException se) {
// An error occurred getting the next value from the institutional ID
// sequence. Log it and throw an exception.
String errMsg = "An error occurred getting the next value from the " +
"institutional ID sequence. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.generateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Get a configured InstitutionalIdentity object out of AppConfig.
InstitutionalIdentity instIdent = new InstitutionalIdentity();
try {
instIdent = (InstitutionalIdentity)getAppConfig()
.getObject("InstitutionalIdentity");
}
catch (EnterpriseConfigurationObjectException eoce) {
// An error occurred retrieving an InstitutionalIdentity object from
// AppConfig. Log it and throw an exception.
String errMsg = "An error occurred retrieving an InstitutionalIdentity " +
"object from AppConfig. The exception is: " + eoce.getMessage();
logger.fatal("[RdbmsI2sRepository.generateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Set the values of the InstitutionalIdentity.
try {
instIdent.setInstitutionalId(instId);
instIdent.setUnknownPerson(uPerson);
}
catch (EnterpriseFieldException efe) {
// An error occurred setting field values for the InstitutionalIdentity.
// Log it and throw an exception.
String errMsg = "An error occurred setting field values for the " +
"InstitutionalIdentity. The exception is: " + efe.getMessage();
logger.fatal("[RdbmsI2sRepository.generateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Set the TestId.
instIdent.setTestId(uPerson.getTestId());
// Create the InstitutionalIdentity.
createInstitutionalIdentity(pub, conn, instIdent);
return instIdent;
}
/**
*
*<P>
* @param PubSubProducer, a pub/sub producer to use.
* @param java.sql.Connection, a database connection to use.
* @param InstitutionalIdentity, an institutional identity to create.
*<P>
* @throws I2sRepositoryException with details of the generate error.
*/
private final void createInstitutionalIdentity(PubSubProducer pub,
java.sql.Connection conn, InstitutionalIdentity instIdent) throws
I2sRepositoryException {
logger.debug("[RdbmsI2sRepository] Creating InstitutionalIdentity.");
// Verify that the InstitutionalIdentity is not null. If it is, log it and
// throw an exception.
if(instIdent == null) {
String errMsg = "The InstitutionalIdentity is null. Cannot create a " +
"null InstitutionalIdentity.";
logger.fatal("[RdbmsI2sRepository.createInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Initialize a insert string with which to create the
// InstitutionalIdentity.
String insString1 = "INSERT INTO T_INST_IDENT (INST_ID, FIRST_NAME, " +
"MIDDLE_NAME, LAST_NAME, SSN, BIRTH_DATE, GENDER, CREATE_USER, " +
"CREATE_DATE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
logger.debug("[RdbmsI2sRepository.createInstitutionalIdentity] " +
"Inserting InstitutionalIdentity record into T_INST_IDENT.");
try {
// Perform the insert.
PreparedStatement insStmt1 = conn.prepareStatement(insString1);
insStmt1.clearParameters();
insStmt1.setString(1, instIdent.getInstitutionalId());
insStmt1.setString(2, instIdent.getUnknownPerson().getName()
.getFirstName());
insStmt1.setString(3, instIdent.getUnknownPerson().getName()
.getMiddleName());
insStmt1.setString(4, instIdent.getUnknownPerson().getName()
.getLastName());
insStmt1.setString(5, instIdent.getUnknownPerson()
.getSocialSecurityNumber());
java.sql.Date birthDate = null;
try {
birthDate = toSqlDate(instIdent.getUnknownPerson().getBirthDate());
}
catch(InvalidFormatException ife) {
// An error occurred formatting the birth date. Log it and throw an
// exception.
String errMsg = "An error occurred formatting the birth date. The " +
"exception is: " + ife.getMessage();
logger.fatal("[RdbmsI2sRepository.createInstitutionalIdentity] " +
errMsg);
}
insStmt1.setDate(6, birthDate);
insStmt1.setString(7, instIdent.getUnknownPerson().getGender());
insStmt1.setString(8, m_connPool.getConnectUserId());
Timestamp ts = new Timestamp(System.currentTimeMillis());
insStmt1.setTimestamp(9, ts);
int insRc = insStmt1.executeUpdate();
insStmt1.close();
logger.debug("[RdbmsI2sRepository.createInstitutionalIdentity] Inserted "
+ "InstitutionalIdentity record into T_INST_IDENT.");
// If publishSyncMessages is toggled on, then publish the
// InstitutionalIdentity.Create-Sync message.
if (m_publishSyncMessages == true) {
try {
logger.debug("[RdbmsI2sRepository.createInstitutionalIdentity] " +
"Publishing the InstitutionalIdentity.Create-Sync message.");
instIdent.createSync(pub);
logger.debug("[RdbmsI2sRepository.createInstitutionalIdentity] " +
"Published the InstitutionalIdentity.Create-Sync message.");
}
catch (EnterpriseObjectSyncException eose){
// An error occurred publishing the InstitutionalIdentity.Create-Sync
// message. Log it, rollback the database transaction, and throw
// an exception.
String errMsg = "An error occurred publishing the Institutional" +
"Identity.Create-Sync message. The exception is: " +
eose.getMessage();
logger.fatal("[RdbmsI2sRepository.createInstitutionalIdentity] " +
errMsg);
rollbackDatabaseTransaction(conn);
throw new I2sRepositoryException(errMsg);
}
}
// If publishSyncMessages is toggled on, then commit the sync message
// that was previously published.
if (m_publishSyncMessages == true) {
try {
logger.debug("[RdbmsI2sRepository.createInstitutionalIdentity] " +
"Committing the sync message published...");
pub.commit();
logger.debug("[RdbmsI2sRepository.createInstitutionalIdentity] " +
"Committed the sync message published.");
}
catch (JMSException jmse) {
// An error occurred committing the message transaction. Log it,
// rollback the database transaction, rollback the message,
// transaction, and throw an exception.
String errMsg = "An error occurred committing the message " +
"transaction. The exception is: " + jmse.getMessage();
logger.fatal("[RdbmsI2sRepository.createInstitutionalIdentity] " +
errMsg);
rollbackDatabaseTransaction(conn);
rollbackMessageTransaction(pub);
throw new I2sRepositoryException(errMsg);
}
}
// Commit the database insert transaction.
logger.debug("[RdbmsI2sRepository.createInstitutionalIdentity] " +
"Committing the database insert transaction...");
conn.commit();
logger.debug("[RdbmsI2sRepository.createInstitutionalIdentity] " +
"Committed the database insert transaction.");
}
catch (SQLException se) {
// There was a database error inserting the InstitutionalIdentity record.
// Log it, rollback the database tranaction, and throw an exception.
String errMsg = "A database error occurred inserting the " +
"InstitutionalIdentity record. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.createInstitutionalIdentity] " +
errMsg);
se.printStackTrace();
rollbackDatabaseTransaction(conn);
throw new I2sRepositoryException(se.getMessage());
}
return;
}
/**
*
*<P>
* @param InstitutionalIdentity, a baseline version of the institutional
* identity prior to the proposed changes.
* @param InstitutionalIdentity, a new version of the institutional identity
* with proposed changes.
*<P>
* @throws I2sRepositoryException with details of the update error.
*/
public final void updateInstitutionalIdentity(InstitutionalIdentity
baselineInstIdent, InstitutionalIdentity newInstIdent) throws
I2sRepositoryException {
PubSubProducer pub = null;
EnterprisePooledConnection epc = null;
java.sql.Connection conn = null;
try {
// Get a PubSubProducer to use in this transaction.
pub = (PubSubProducer)m_pubSubProducerPool.getExclusiveProducer();
// Get a database connection to use in this transaction.
epc = m_connPool.getExclusiveConnection();
conn = epc.getConnection();
conn.setAutoCommit(false);
// Update the InstitutionalIdentity.
updateInstitutionalIdentity(pub, conn, baselineInstIdent,
newInstIdent);
return;
}
catch (JMSException jmse) {
// There was an error retrieving a pub/sub producer from the pool to
// use in the transaction. Log it and throw an exception.
String errMsg = "Error retrieving a pub/sub producer from the pool " +
"to use in the transaction. The exception is: " + jmse.getMessage();
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
jmse.printStackTrace();
throw new I2sRepositoryException(jmse.getMessage());
}
catch (SQLException se) {
// There was an error retrieving a database connection from the pool to
// use in the transaction. Log it and throw an exception.
String errMsg = "Error retrieving a database connection from the pool " +
"to use in the transaction. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
se.printStackTrace();
throw new I2sRepositoryException(se.getMessage());
}
finally {
// Make sure the pub/sub producer we retrieved exclusively from the
// producer pool for this transaction is released back to the pool.
m_pubSubProducerPool.releaseProducer(pub);
// Make sure the database connection we retrieved exclusively from the
// database connection pool for this transaction is released back to the
// pool.
try { m_connPool.releaseExclusiveConnection(epc); }
catch (SQLException se) {
String errMsg = "Error releasing exclusive connection back to the " +
"database pool. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
}
}
}
/**
*
*<P>
* @param PubSubProducer, a PubSub producer to use for this transaction.
* @param java.sql.Connection, a database connection to use for this
* transaction.
* @param InstitutionalIdentity, the baseline InstitutionalIdentity.
* @param InstitutionalIdentity, the new InstitutionalIdentity.
*<P>
* @throws I2sRepositoryException if an error occurs updating the
* InstitutionalIdentity.
*/
private final void updateInstitutionalIdentity (PubSubProducer pub,
java.sql.Connection conn, InstitutionalIdentity baselineInstIdent,
InstitutionalIdentity newInstIdent)
throws I2sRepositoryException {
logger.debug("[RdbmsI2sRepository] Updating an InstitutionalIdentity.");
// Verify that the baseline and new InstitutionalIdentities are not
// identical. If they are, throw an exception.
try {
if (newInstIdent.equals(baselineInstIdent)) {
String errMsg = "The baseline and new InstitutionalIdentity objects " +
"are identical. An update will not be performed." ;
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
}
catch (XmlEnterpriseObjectException xeoe) {
// An error occurred comparing the baseline InstitutionalIdentity and the
// new InstitutionalIdentity. Log it, and throw an exception.
String errMsg = "An error occurred comparing the baseline " +
"and the new InstitutionalIdentity. The exception is: " +
xeoe.getMessage();
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Verify that the baseline matches the current state of the
// InstitutionalIdentity.
// --- Retrieve the current state of the InstitutionalIdentity.
Identifier id = new Identifier();
try {
id.setType("InstitutionalId");
id.setValue(baselineInstIdent.getInstitutionalId());
}
catch (EnterpriseFieldException efe) {
// An error occurred setting the values of the identifier to use to
// retrieve the current state of the InstitutionalIdentity. Log it
// and throw an exception.
String errMsg = "An error occurred setting the values of the " +
"identifier to use to retrieve the current state of the " +
"InstitutionalIdentity.";
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
InstitutionalIdentity currentInstIdent = new InstitutionalIdentity();
currentInstIdent = retrieveInstitutionalIdentity(conn, id);
// --- Compare the baseline to the current state of the
// InstitutionalIdentity.
try {
if (baselineInstIdent.equals(currentInstIdent) == false) {
String errMsg = "The baseline is stale. This InstitutionalIdentity " +
"has been updated since you queried for the baseline. You must " +
"query for the InstitutionalIdentity to retrieve a current baseline "
+ "before an update can be performed.";
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
}
catch (XmlEnterpriseObjectException xeoe) {
// An error occurred comparing the baseline InstitutionalIdentity and the
// current state of the InstitutionalIdentity. Log it, and throw an
// exception.
String errMsg = "An error occurred comparing the baseline " +
"and the current state of the InstitutionalIdentity. The exception is: "
+ xeoe.getMessage();
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Prepare to perform the update.
try {
// Get the values of BirthDate.
java.sql.Date birthDate = null;
try {
birthDate = toSqlDate(newInstIdent.getUnknownPerson().getBirthDate());
}
catch (InvalidFormatException ife) {
// An error occurred formatting a date. Log it and throw an exception.
String errMsg = "An error occurred formatting a date. The exception " +
"is: " + ife.getMessage();
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
// Initialize a statement for the update statement to update the
// InstitutionalIdentity.
String updString1 = "UPDATE T_INST_IDENT SET INST_ID = ?, FIRST_NAME = " +
"?, MIDDLE_NAME = ?, LAST_NAME = ?, SSN = ?, BIRTH_DATE = ?, GENDER =" +
" ?, MOD_USER = ?, MOD_DATE = ? WHERE INST_ID = ?";
logger.debug("[RdbmsI2sRepository.updateInstitutionalIdentity] Updating "
+ "InstitutionalIdentity record.");
// Perform the update.
PreparedStatement updStmt1 = conn.prepareStatement(updString1);
updStmt1.clearParameters();
updStmt1.setString(1, newInstIdent.getInstitutionalId());
updStmt1.setString(2, newInstIdent.getUnknownPerson().getName()
.getFirstName());
updStmt1.setString(3, newInstIdent.getUnknownPerson().getName()
.getMiddleName());
updStmt1.setString(4, newInstIdent.getUnknownPerson().getName()
.getLastName());
updStmt1.setString(5, newInstIdent.getUnknownPerson()
.getSocialSecurityNumber());
updStmt1.setDate(6, birthDate);
updStmt1.setString(7, newInstIdent.getUnknownPerson().getGender());
updStmt1.setString(8, m_connPool.getConnectUserId());
Timestamp ts = new Timestamp(System.currentTimeMillis());
updStmt1.setTimestamp(9, ts);
updStmt1.setString(10, baselineInstIdent.getInstitutionalId());
int updRc = updStmt1.executeUpdate();
updStmt1.close();
logger.debug("[RdbmsI2sRepository.updateInstitutionalIdentity] Updated " +
"InstitutionalIdentity record.");
// If publishSyncMessages is toggled on, then publish the
// InstitutionalIdentity.Update-Sync message.
if (m_publishSyncMessages == true) {
try {
logger.debug("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
"Publishing the InstitutionalIdentity.Update-Sync message.");
newInstIdent.setBaseline(baselineInstIdent);
newInstIdent.updateSync(pub);
logger.debug("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
"Published the InstitutionalIdentity.Update-Sync message.");
}
catch (EnterpriseObjectSyncException eose){
// An error occurred publishing the sync message. Log it, rollback
// the database transaction, and throw an exception.
String errMsg = "An error occurred publishing the Institutional" +
"Identity.Update-Sync message. Rolling back the database update " +
"transaction. The exception is: " + eose.getMessage();
logger.debug("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
rollbackDatabaseTransaction(conn);
throw new I2sRepositoryException(eose.getMessage());
}
}
// If publishSyncMessages is toggled on, then commit the sync message
// that has been published.
if (m_publishSyncMessages == true) {
try {
logger.debug("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
"Committing the sync message that was published...");
pub.commit();
logger.debug("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
"Committed the sync message that was published.");
}
catch (JMSException jmse) {
// An error occurred committing the message transaction. Log it,
// rollback the message transaction, rollback the database
// transaction, and throw an exception.
String errMsg = "An error occurred committing the message " +
"transaction. The exception is: " + jmse.getMessage();
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
rollbackMessageTransaction(pub);
rollbackDatabaseTransaction(conn);
throw new I2sRepositoryException(jmse.getMessage());
}
}
// Commit the database update transaction
logger.debug("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
"Committing the database update transaction to update the " +
"InstitutionalIdentity");
conn.commit();
logger.debug("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
"Committed the database update transaction to update the " +
"InstitutionalIdentity.");
}
catch (SQLException se) {
// There was a database error updating the InstitutionalIdentity. Log it,
// rollback the database tranaction, and throw an exception.
String errMsg = "A database error occurred updating the " +
"InstitutionalIdentity. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.updateInstitutionalIdentity] " +
errMsg);
se.printStackTrace();
rollbackDatabaseTransaction(conn);
throw new I2sRepositoryException(se.getMessage());
}
return;
}
/**
*
*<P>
* @param String, the delete action to perform.
* @param InstitutionalIdentity, the InstitutionalIdentity to delete.
*<P>
* @throws I2sRepositoryException if an error occurs deleting the
* InstitutionalIdentity
*/
public final void deleteInstitutionalIdentity(String deleteAction,
InstitutionalIdentity instIdent) throws I2sRepositoryException {
PubSubProducer pub = null;
EnterprisePooledConnection epc = null;
java.sql.Connection conn = null;
try {
// Get a pub/sub producer to use in this transaction.
pub = (PubSubProducer)m_pubSubProducerPool.getExclusiveProducer();
// Get a database connection to use in this transaction.
epc = m_connPool.getExclusiveConnection();
conn = epc.getConnection();
conn.setAutoCommit(false);
// If the delete action is the DELETE_ACTION then terminate the
// InstitutionalIdentity.
if (deleteAction.equals(DELETE_ACTION)) {
terminateInstitutionalIdentity(pub, conn, instIdent);
}
// If the delete action is the PURGE_ACTION then purge the
// InstitutionalIdentity.
if (deleteAction.equals(PURGE_ACTION)) {
purgeInstitutionalIdentity(pub, conn, instIdent);
}
// Otherwise, the delete action is invalid. Log the error an throw an
// exception.
if (deleteAction.equals(DELETE_ACTION) == false &&
deleteAction.equals(PURGE_ACTION) == false) {
String errMsg = "Invalid delete action: " + deleteAction + ".";
logger.fatal("[RdbmsI2sRepository.deleteInstitutionalIdentity] " +
errMsg);
throw new I2sRepositoryException(errMsg);
}
return;
}
catch (JMSException jmse) {
// There was an error retrieving a pub/sub producer from the pool to
// use in the transaction. Log it and throw an exception.
String errMsg = "Error retrieving a pub/sub producer from the pool " +
"to use in the transaction. The exception is: " + jmse.getMessage();
logger.fatal("[RdbmsI2sRepository.deleteInstitutionalIdentity] " +
errMsg);
jmse.printStackTrace();
throw new I2sRepositoryException(errMsg);
}
catch (SQLException se) {
// There was an error retrieving a database connection from the pool to
// use in the transaction. Log it and throw an exception.
String errMsg = "Error retrieving a database connection from the pool " +
"to use in the transaction. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.deleteInstitutionalIdentity] " +
errMsg);
se.printStackTrace();
throw new I2sRepositoryException(se.getMessage());
}
finally {
// Make sure the pub/sub producer we retrieved exclusively from the
// producer pool for this transaction is released back to the pool.
m_pubSubProducerPool.releaseProducer(pub);
// Make sure the database connection we retrieved exclusively from the
// database connection pool for this transaction is released back to the
// pool.
try { m_connPool.releaseExclusiveConnection(epc); }
catch (SQLException se) {
String errMsg = "Error releasing exclusive connection back to the " +
"database pool. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.deleteInstitutionalIdentity] " +
errMsg);
}
}
}
/**
*
*<P>
* @param PubSubProducer, a pub/sub producer to use.
* @param java.sql.Connection, a database connection to use.
* @param InstitutionalIdentity, the InstitutionalIdentity to terminate.
*<P>
* @throws I2sRepositoryException if an error occurs terminating the
* InstitutionalIdentity
*/
private final void terminateInstitutionalIdentity (PubSubProducer pub,
java.sql.Connection conn, InstitutionalIdentity instIdent) throws
I2sRepositoryException {
logger.debug("[RdbmsI2sRepository] Terminating the InstitutionalIdentity.");
try {
// Initialize an update string with which to terminate the
// InstitutionalIdentity.
String updString1 = "UPDATE T_INST_IDENT SET TERMINATED_DATE = ?, "
+ "MOD_USER = ?, MOD_DATE = ? WHERE INST_ID = ? AND TERMINATED_DATE " +
"IS NULL";
// Get the current date to serve as the termination date for the
// InstitutionalIdentity.
Calendar cal = Calendar.getInstance();
java.sql.Date terminatedDate =
new java.sql.Date(System.currentTimeMillis());
logger.debug("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
"Updating InstitutionalIdentity record in T_INST_IDENT to terminate " +
"the InstitutionalIdentity effective today.");
// Perform the update.
PreparedStatement updStmt1 = conn.prepareStatement(updString1);
updStmt1.clearParameters();
updStmt1.setDate(1, terminatedDate);
updStmt1.setString(2, m_connPool.getConnectUserId());
updStmt1.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
updStmt1.setString(4, instIdent.getInstitutionalId());
int updRc = updStmt1.executeUpdate();
updStmt1.close();
logger.debug("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
"Updated the InstitutionalIdentity record in T_INST_IDENT to " +
"terminate the InstitutionalIdentity effective today.");
// If publishSyncMessages is toggled on, then publish the
// InstitutionalIdentity.Delete-Sync message.
if (m_publishSyncMessages == true) {
try {
logger.debug("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
"Publishing the InstitutionalIdentity.Delete-Sync message.");
instIdent.deleteSync(DELETE_ACTION, pub);
logger.debug("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
"Published the InstitutionalIdentity.Delete-Sync message.");
}
catch (EnterpriseObjectSyncException eose){
// An error occurred publishing the InstitutionalIdentity.Delete-Sync
// message. Log it, rollback the database transaction, and throw an
// exception.
String errMsg = "An error occurred publishing the Institutional" +
"Identity. Delete-Sync message. The exception is: " +
eose.getMessage();
logger.debug("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
errMsg);
rollbackDatabaseTransaction(conn);
throw new I2sRepositoryException(errMsg);
}
}
// If publishSyncMessages is toggled on, then commit the sync message
// that has been published.
if (m_publishSyncMessages == true) {
try {
logger.debug("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
"Committing the sync message published...");
pub.commit();
logger.debug("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
"Committed the sync message published.");
}
catch (JMSException jmse) {
// An error occurred committing the message transaction. Log it,
// rollback the database transaction, rollback the message,
// transaction, and throw an exception.
String errMsg = "An error occurred committing the message " +
"transaction. The exception is: " + jmse.getMessage();
logger.fatal("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
errMsg);
rollbackDatabaseTransaction(conn);
rollbackMessageTransaction(pub);
throw new I2sRepositoryException(errMsg);
}
}
// Commit the database update transaction.
logger.debug("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
"Committing the database update transaction...");
conn.commit();
logger.debug("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
"Committed the database update transaction.");
}
catch (SQLException se) {
// There was a database error updating the InstitutionalIdentity to
// terminate it. Log it, rollback the database tranaction, and throw
// an exception.
String errMsg = "A database error occurred updating the " +
"InstitutionalIdentity record to terminate the InstitutionalIdentity. "
+ "The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.terminateInstitutionalIdentity] " +
errMsg);
se.printStackTrace();
rollbackDatabaseTransaction(conn);
throw new I2sRepositoryException(errMsg);
}
return;
}
/**
*
*<P>
* @param PubSubProducer, a pub/sub producer to use.
* @param java.sql.Connection, a database connection to use.
* @param InstitutionalIdentity, the InstitutionalIdentity to purge.
*<P>
* @throws I2sRepositoryException if an error occurs purging the
* InsitutionalIdentity
*/
private final void purgeInstitutionalIdentity (PubSubProducer pub,
java.sql.Connection conn, InstitutionalIdentity instIdent) throws
I2sRepositoryException {
logger.debug("[RdbmsI2sRepository] Purging the InstitutionalIdentity.");
try {
// Initialize a delete string with which to delete the
// InstitutionalIdentity.
String delString1 = "DELETE FROM T_INST_IDENT WHERE INST_ID = ?";
logger.debug("[RdbmsI2sRepository.purgeInstitutionalIdentity] Deleting " +
"InstitutionalIdentity record in T_INST_IDENT to purge the " +
"InstitutionalIdentity.");
// Perform the delete.
PreparedStatement delStmt1 = conn.prepareStatement(delString1);
delStmt1.clearParameters();
delStmt1.setString(1, instIdent.getInstitutionalId());
int delRc1 = delStmt1.executeUpdate();
delStmt1.close();
logger.debug("[RdbmsI2sRepository.purgeInstitutionalIdentity] Deleted " +
"InstitutionalIdentity record in T_INST_IDENT to purge the " +
"InstitutionalIdentity.");
// If publishSyncMessages is toggled on, then publish the
// InstitutionalIdentity.Delete-Sync message.
if (m_publishSyncMessages == true) {
try {
logger.debug("[RdbmsI2sRepository.purgeInstitutionalIdentity] " +
"Publishing the InstitutionalIdentity.Delete-Sync message.");
instIdent.deleteSync(PURGE_ACTION, pub);
logger.debug("[RdbmsI2sRepository.purgeInstitutionalIdentity] " +
"Published the InstitutionalIdentity.Delete-Sync message.");
}
catch (EnterpriseObjectSyncException eose){
// An error occurred publishing the InstitutionalIdentity.Delete-Sync
// message. Log it, rollback the database transaction, and throw an
// exception.
String errMsg = "An error occurred publishing the " +
"InstitutionalIdentity.Delete-Sync message. The exception is: " +
eose.getMessage();
logger.debug("[RdbmsI2sRepository.purgeInstitutionalIdentity] " +
errMsg);
rollbackDatabaseTransaction(conn);
throw new I2sRepositoryException(errMsg);
}
}
// If publishSyncMessages is toggled on, then commit the sync message
// that has been published.
if (m_publishSyncMessages == true) {
try {
logger.debug("[RdbmsI2sRepository.purgeInstitutionalIdentity] " +
"Committing the sync message published...");
pub.commit();
logger.debug("[RdbmsI2sRepository.purgeInstitutionalIdentity] " +
"Committed the sync message published.");
}
catch (JMSException jmse) {
// An error occurred committing the message transaction. Log it,
// rollback the database transaction, rollback the message,
// transaction, and throw an exception.
String errMsg = "An error occurred committing the message " +
"transaction. The exception is: " + jmse.getMessage();
logger.fatal("[RdbmsI2sRepository.purgeInstitutionalIdentity] " +
errMsg);
rollbackDatabaseTransaction(conn);
rollbackMessageTransaction(pub);
throw new I2sRepositoryException(errMsg);
}
}
// Commit the database delete transaction.
logger.debug("[RdbmsI2sRepository.purgeInstitutionalIdentity] " +
"Committing the database delete transaction to purge the " +
"InstitutionalIdentity...");
conn.commit();
logger.debug("[RdbmsI2sRepository.purgeInstitutionalIdentity] " +
"Committed the database delete transaction to purge the " +
"InstitutionalIdentity.");
}
catch (SQLException se) {
// There was a database error deleting the InstitutionalIdentity to
// purge it. Log it, rollback the database tranaction, and throw
// an exception.
String errMsg = "A database error occurred deleting the " +
"InstitutionalIdentity record to purge the InstitutionalIdentity. " +
"The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.purgeInstitutionalIdentity] " +
errMsg);
se.printStackTrace();
rollbackDatabaseTransaction(conn);
throw new I2sRepositoryException(errMsg);
}
return;
}
/**
*
*<P>
* @param java.sql.Timestamp, a timestamp to convert to an XeoDate.
*<P>
* @throws EnterpriseFieldException with details of the conversion error.
*/
private final org.any_openeai_enterprise.moa.objects.resources.v1_0.Date
toXeoDate (String dateType, java.sql.Timestamp ts) throws
EnterpriseFieldException {
// Instatiate an Xeo Date to work with.
org.any_openeai_enterprise.moa.objects.resources.v1_0.Date xeoDate =
new org.any_openeai_enterprise.moa.objects.resources.v1_0.Date(dateType);
// Set a calendar's time.
Calendar cal = Calendar.getInstance();
cal.setTime(ts);
// Set the appropriate fields of the Xeo Date.
xeoDate.setDay(Integer.toString(cal.get(cal.DAY_OF_MONTH)));
xeoDate.setMonth(Integer.toString(cal.get(cal.MONTH)+1));
xeoDate.setYear(Integer.toString(cal.get(cal.YEAR)));
return xeoDate;
}
/**
*
*<P>
* @param java.sql.Date, a date to convert to an XeoDate.
*<P>
* @throws EnterpriseFieldException with details of the conversion error.
*/
private final org.any_openeai_enterprise.moa.objects.resources.v1_0.Date
toXeoDate (String dateType, java.sql.Date date) throws
EnterpriseFieldException {
// Instatiate an Xeo Date to work with.
org.any_openeai_enterprise.moa.objects.resources.v1_0.Date xeoDate =
new org.any_openeai_enterprise.moa.objects.resources.v1_0.Date(dateType);
// Set a calendar's time.
Calendar cal = Calendar.getInstance();
cal.setTime(date);
// Set the appropriate fields of the Xeo Date.
xeoDate.setDay(Integer.toString(cal.get(cal.DAY_OF_MONTH)));
xeoDate.setMonth(Integer.toString(cal.get(cal.MONTH)+1));
xeoDate.setYear(Integer.toString(cal.get(cal.YEAR)));
return xeoDate;
}
/**
*
*<P>
* @param XeoDate, an XeoDate to converto to a java.sql.Date.
*<P>
* @throws InvalidFormatException with details of the conversion error.
*/
private final java.sql.Date toSqlDate
(org.any_openeai_enterprise.moa.objects.resources.v1_0.Date xeoDate)
throws InvalidFormatException {
if (xeoDate != null) {
java.sql.Date s = new java.sql.Date(xeoDate.toDate().getTime());
return s;
}
else {
return null;
}
}
/**
*
*<P>
* @param java.sql.Connection, a database connection upon which to perform
* a rollback.
*/
private final void rollbackDatabaseTransaction(java.sql.Connection conn) {
try { conn.rollback(); }
catch (SQLException se) {
// An error occurred rolling back the database transaction. Log it.
String errMsg = "An error occurred rolling back the database " +
"transaction. The exception is: " + se.getMessage();
logger.fatal("[RdbmsI2sRepository.rollbackDatabaseTransaction] " +
errMsg);
}
return;
}
/**
*
*<P>
* @param PubSubProducer, a pub/sub producer upon which to perform a
* rollback.
*/
private final void rollbackMessageTransaction(PubSubProducer pub) {
try { pub.rollback(); }
catch (JMSException jmse) {
// An error occurred rolling back the message transaction. Log it.
String errMsg = "An error occurred rolling back the message " +
"transaction. The exception is: " + jmse.getMessage();
logger.fatal("[RdbmsI2sRepository.rollbackMessageTransaction] " +
errMsg);
}
}
/**
* @param Sequence, the sequence for the repository to use to increment
* InstitutionalId numbers.
* <P>
* Sets the sequence for the repository to use to increment InstitutionalId
* numbers.
*/
private void setInstIdSequence(Sequence instIdSequence) {
m_instIdSequence = instIdSequence;
}
/**
* @return Sequence, the sequence for the repository to use to increment
* InstitutionalId numbers.
* <P>
* Returns the sequence for the repository to use to increment InstitutionalId
* numbers.
*/
public Sequence getInstIdSequence() {
return m_instIdSequence;
}
}