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 " +