Java tutorial
// Description: Java 6 PostgreSQL Jdbc DbIO implementation for MSSBam. /* * MSS Code Factory 1.10 * * Copyright (c) 2012 Mark Sobkow * * This program is available as free software under the GNU GPL v3, or * under a commercial license from Mark Sobkow. For commercial licensing * details, please contact msobkow@sasktel.net. * * Under the terms of the GPL: * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * *********************************************************************** * * Code manufactured * by MSS Code Factory version 1.9.3294 * * $Revision: 26 $ */ package net.sourceforge.msscodefactory.v1_10.MSSBamPg8; import java.lang.reflect.*; import java.math.*; import java.sql.*; import java.text.*; import java.util.*; import javax.naming.*; import javax.sql.*; import net.sourceforge.msscodefactory.cflib.v1_9.CFLib.*; import org.apache.commons.codec.binary.Base64; import net.sourceforge.msscodefactory.v1_10.MSSBam.*; public class MSSBamPg8Schema extends MSSBamSchema { protected Connection cnx; protected boolean inTransaction; public MSSBamPg8Schema() { super(); cnx = null; inTransaction = false; } public MSSBamPg8Schema(MSSBamConfigurationFile conf) { super(conf); cnx = null; inTransaction = false; } public MSSBamPg8Schema(String argJndiName) { super(argJndiName); cnx = null; inTransaction = false; } public MSSBamPg8Schema(Connection argCnx) { super(); cnx = argCnx; inTransaction = false; try { cnx.setAutoCommit(false); cnx.rollback(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "MSSBamPg8Schema-constructor", e); } } public Connection getCnx() { return (cnx); } public boolean isConnected() { final String S_ProcName = "isConnected"; boolean retval; if (cnx == null) { retval = false; } else { try { if (cnx.isClosed()) { retval = false; cnx = null; } else { retval = true; } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } } return (retval); } public boolean connect() { final String S_ProcName = "connect"; if (cnx != null) { return (false); } if (configuration != null) { String dbServer = configuration.getDbServer(); int dbPort = configuration.getDbPort(); String dbDatabase = configuration.getDbDatabase(); String dbUserName = configuration.getDbUserName(); String dbPassword = configuration.getDbPassword(); String url = "jdbc:postgresql://" + dbServer + ":" + Integer.toString(dbPort) + "/" + dbDatabase; Properties props = new Properties(); props.setProperty("user", dbUserName); props.setProperty("password", dbPassword); try { cnx = DriverManager.getConnection(url, props); cnx.setAutoCommit(false); cnx.rollback(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } return (true); } if (jndiName != null) { try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(jndiName); if (ds == null) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Could not get resolve DataSource \"" + jndiName + "\""); } cnx = ds.getConnection(); if (cnx == null) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Could not get Connection from DataSource \"" + jndiName + "\""); } cnx.setAutoCommit(false); cnx.rollback(); } catch (NamingException e) { cnx = null; throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "NamingException " + e.getMessage(), e); } catch (SQLException e) { cnx = null; inTransaction = false; throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } return (true); } throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Neither configurationFile nor jndiName found, do not know how to connect to database"); } public void disconnect(boolean doCommit) { final String S_ProcName = "disconnect"; if (cnx != null) { try { if (!cnx.isClosed()) { if (doCommit) { cnx.commit(); } else { cnx.rollback(); } cnx.close(); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { cnx = null; } } } public boolean isTransactionOpen() { return (inTransaction); } public boolean beginTransaction() { if (inTransaction) { return (false); } try { String sql = "begin transaction"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.execute(sql); inTransaction = true; } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "beginTransaction", e); } return (inTransaction); } public void commit() { try { cnx.commit(); inTransaction = false; } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "commit", e); } } public void rollback() { try { cnx.rollback(); inTransaction = false; } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "rollback", e); } } public short nextISOTimezoneIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextISOTimezoneIdGen", "Not in a transaction"); } try { String sql = "SELECT cast( " + "nextval( 'mssbam110.ISOTimezoneIdGen' ) " + "as smallint )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); short nextId; if (resultSet.next()) { nextId = resultSet.getShort(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextISOTimezoneIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextISOTimezoneIdGen", e); } } public short nextISOCountryIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextISOCountryIdGen", "Not in a transaction"); } try { String sql = "SELECT cast( " + "nextval( 'mssbam110.ISOCountryIdGen' ) " + "as smallint )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); short nextId; if (resultSet.next()) { nextId = resultSet.getShort(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextISOCountryIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextISOCountryIdGen", e); } } public short nextISOCurrencyIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextISOCurrencyIdGen", "Not in a transaction"); } try { String sql = "SELECT cast( " + "nextval( 'mssbam110.ISOCurrencyIdGen' ) " + "as smallint )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); short nextId; if (resultSet.next()) { nextId = resultSet.getShort(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextISOCurrencyIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextISOCurrencyIdGen", e); } } public short nextISOLanguageIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextISOLanguageIdGen", "Not in a transaction"); } try { String sql = "SELECT cast( " + "nextval( 'mssbam110.ISOLanguageIdGen' ) " + "as smallint )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); short nextId; if (resultSet.next()) { nextId = resultSet.getShort(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextISOLanguageIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextISOLanguageIdGen", e); } } public short nextURLProtocolIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextURLProtocolIdGen", "Not in a transaction"); } try { String sql = "SELECT cast( " + "nextval( 'mssbam110.URLProtocolIdGen' ) " + "as smallint )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); short nextId; if (resultSet.next()) { nextId = resultSet.getShort(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextURLProtocolIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextURLProtocolIdGen", e); } } public short nextMimeTypeIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextMimeTypeIdGen", "Not in a transaction"); } try { String sql = "SELECT cast( " + "nextval( 'mssbam110.MimeTypeIdGen' ) " + "as smallint )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); short nextId; if (resultSet.next()) { nextId = resultSet.getShort(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextMimeTypeIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextMimeTypeIdGen", e); } } public int nextSecAppIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextSecAppIdGen", "Not in a transaction"); } try { String sql = "SELECT cast( " + "nextval( 'mssbam110.SecAppIdGen' ) " + "as int )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); int nextId; if (resultSet.next()) { nextId = resultSet.getInt(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextSecAppIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextSecAppIdGen", e); } } public int nextSecFormIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextSecFormIdGen", "Not in a transaction"); } try { String sql = "SELECT cast( " + "nextval( 'mssbam110.SecFormIdGen' ) " + "as int )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); int nextId; if (resultSet.next()) { nextId = resultSet.getInt(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextSecFormIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextSecFormIdGen", e); } } public int nextSecGroupIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextSecGroupIdGen", "Not in a transaction"); } try { String sql = "SELECT cast( " + "nextval( 'mssbam110.SecGroupIdGen' ) " + "as int )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); int nextId; if (resultSet.next()) { nextId = resultSet.getInt(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextSecGroupIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextSecGroupIdGen", e); } } public int nextServiceTypeIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextServiceTypeIdGen", "Not in a transaction"); } try { String sql = "SELECT cast( " + "nextval( 'mssbam110.ServiceTypeIdGen' ) " + "as int )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); int nextId; if (resultSet.next()) { nextId = resultSet.getInt(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextServiceTypeIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextServiceTypeIdGen", e); } } public long nextSecGroupMemberIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextSecGroupMemberIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.SecGroupMemberIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextSecGroupMemberIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextSecGroupMemberIdGen", e); } } public long nextSecGroupIncludeIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextSecGroupIncludeIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.SecGroupIncludeIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextSecGroupIncludeIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextSecGroupIncludeIdGen", e); } } public long nextSecGroupFormIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextSecGroupFormIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.SecGroupFormIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextSecGroupFormIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextSecGroupFormIdGen", e); } } public long nextClusterIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextClusterIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.ClusterIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextClusterIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextClusterIdGen", e); } } public long nextTenantIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextTenantIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.TenantIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextTenantIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextTenantIdGen", e); } } public long nextMemoIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextMemoIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.MemoIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextMemoIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextMemoIdGen", e); } } public long nextPhoneIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextPhoneIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.PhoneIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextPhoneIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextPhoneIdGen", e); } } public long nextContactURLIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextContactURLIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.ContactURLIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextContactURLIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextContactURLIdGen", e); } } public long nextAttachmentIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextAttachmentIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.AttachmentIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextAttachmentIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextAttachmentIdGen", e); } } public long nextAddressIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextAddressIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.AddressIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextAddressIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextAddressIdGen", e); } } public long nextContactIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextContactIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.ContactIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextContactIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextContactIdGen", e); } } public long nextContactListIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextContactListIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.ContactListIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextContactListIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextContactListIdGen", e); } } public long nextServiceIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextServiceIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.ServiceIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextServiceIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextServiceIdGen", e); } } public long nextHostNodeIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextHostNodeIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.HostNodeIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextHostNodeIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextHostNodeIdGen", e); } } public long nextSecSessionIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextSecSessionIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.SecSessionIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextSecSessionIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextSecSessionIdGen", e); } } public long nextSecUserIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextSecUserIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.SecUserIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextSecUserIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextSecUserIdGen", e); } } public long nextTagIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextTagIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.TagIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextTagIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextTagIdGen", e); } } public long nextAnyObjIdGen() { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "nextAnyObjIdGen", "Not in a transaction"); } try { String sql = "SELECT nextval( 'mssbam110.AnyObjIdGen' )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); long nextId; if (resultSet.next()) { nextId = resultSet.getLong(1); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "nextAnyObjIdGen", "Query did not return a result row"); } resultSet.close(); stmt.close(); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextAnyObjIdGen", e); } } public static String getQuotedString(String val) { if (val == null) { return ("null"); } else { char c; StringBuilder quoted = new StringBuilder(); quoted.append("'"); int len = val.length(); for (int i = 0; i < len; i++) { if (val.charAt(i) == '\'') { quoted.append("''"); } else if (val.charAt(i) == '\\') { quoted.append("'||E'\\\\'||'"); } else { c = val.charAt(i); if ((c == '0') || (c == '1') || (c == '2') || (c == '3') || (c == '4') || (c == '5') || (c == '6') || (c == '7') || (c == '8') || (c == '9') || (c == 'a') || (c == 'b') || (c == 'c') || (c == 'd') || (c == 'e') || (c == 'f') || (c == 'g') || (c == 'h') || (c == 'i') || (c == 'j') || (c == 'k') || (c == 'l') || (c == 'm') || (c == 'n') || (c == 'o') || (c == 'p') || (c == 'q') || (c == 'r') || (c == 's') || (c == 't') || (c == 'u') || (c == 'v') || (c == 'w') || (c == 'x') || (c == 'y') || (c == 'z') || (c == 'A') || (c == 'B') || (c == 'C') || (c == 'D') || (c == 'E') || (c == 'F') || (c == 'G') || (c == 'H') || (c == 'I') || (c == 'J') || (c == 'K') || (c == 'L') || (c == 'M') || (c == 'N') || (c == 'O') || (c == 'P') || (c == 'Q') || (c == 'R') || (c == 'S') || (c == 'T') || (c == 'U') || (c == 'V') || (c == 'W') || (c == 'X') || (c == 'Y') || (c == 'Z') || (c == ' ') || (c == '\t') || (c == '\r') || (c == '\n') || (c == '`') || (c == '~') || (c == '!') || (c == '@') || (c == '#') || (c == '$') || (c == '%') || (c == '^') || (c == '&') || (c == '*') || (c == '(') || (c == ')') || (c == '-') || (c == '_') || (c == '=') || (c == '+') || (c == '[') || (c == ']') || (c == '{') || (c == '}') || (c == '|') || (c == ';') || (c == ':') || (c == '"') || (c == '<') || (c == '>') || (c == ',') || (c == '.') || (c == '/') || (c == '?')) { quoted.append(c); } else { // Syslog.warn("\t\t\tReplacing invalid character '" + c + "' with space"); quoted.append(' '); } } } quoted.append("'"); return (quoted.toString()); } } public static String getNullableString(ResultSet reader, int colidx) { try { String val = reader.getString(colidx); if (reader.wasNull()) { return (null); } else { return (val); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(MSSBamPg8Schema.class, "getNullableString", e); } } public static String getBlobString(byte[] val) { if (val == null) { return ("null"); } else { return ("'" + Base64.encodeBase64(val).toString() + "'"); } } public static String getBoolString(Boolean val) { if (val == null) { return ("null"); } else { if (val) { return ("true"); } else { return ("false"); } } } public static String getBoolString(boolean val) { if (val) { return ("true"); } else { return ("false"); } } public static String getInt16String(Short val) { if (val == null) { return ("null"); } else { return (val.toString()); } } public static String getInt16String(short val) { return (Short.toString(val)); } public static String getInt32String(Integer val) { if (val == null) { return ("null"); } else { return (val.toString()); } } public static String getInt32String(int val) { return (Integer.toString(val)); } public static String getInt64String(Long val) { if (val == null) { return ("null"); } else { return (val.toString()); } } public static String getInt64String(long val) { return (Long.toString(val)); } public static String getUInt16String(Integer val) { if (val == null) { return ("null"); } else { return (val.toString()); } } public static String getUInt16String(int val) { return (Integer.toString(val)); } public static String getUInt32String(Long val) { if (val == null) { return ("null"); } else { return (val.toString()); } } public static String getUInt32String(long val) { return (Long.toString(val)); } public static String getUInt64String(BigInteger val) { if (val == null) { return ("null"); } else { return (val.toString()); } } public static String getFloatString(Float val) { if (val == null) { return ("null"); } else { return (val.toString()); } } public static String getFloatString(float val) { return (Float.toString(val)); } public static String getDoubleString(Double val) { if (val == null) { return ("null"); } else { return (val.toString()); } } public static String getDoubleString(double val) { return (Double.toString(val)); } public static String getNumberString(BigDecimal val) { if (val == null) { return ("null"); } else { return (val.toString()); } } public static Integer getNullableInt32(ResultSet reader, int colidx) { try { int val = reader.getInt(colidx); if (reader.wasNull()) { return (null); } else { return (new Integer(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(MSSBamPg8Schema.class, "getNullableInt32", e); } } public static Short getNullableInt16(ResultSet reader, int colidx) { try { short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(MSSBamPg8Schema.class, "getNullableInt64", e); } } public static Integer getNullableUInt16(ResultSet reader, int colidx) { try { int val = reader.getInt(colidx); if (reader.wasNull()) { return (null); } else { return (new Integer(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(MSSBamPg8Schema.class, "getNullableUInt16", e); } } public static Long getNullableUInt32(ResultSet reader, int colidx) { try { long val = reader.getLong(colidx); if (reader.wasNull()) { return (null); } else { return (new Long(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(MSSBamPg8Schema.class, "getNullableUInt32", e); } } public static BigInteger getNullableUInt64(ResultSet reader, int colidx) { try { String strval = reader.getString(colidx); if (reader.wasNull() || (strval == null) || (strval.length() <= 0)) { return (null); } else { BigInteger retval = new BigInteger(strval); return (retval); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(MSSBamPg8Schema.class, "getNullableUInt64", e); } } public static Byte getNullableByte(ResultSet reader, int colidx) { try { byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(MSSBamPg8Schema.class, "getNullableByte", e); } } public static String getDateString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append("'"); return (buff.toString()); } } public static String getTimeString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append("'"); return (buff.toString()); } } public static String getTimestampString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append("'"); return (buff.toString()); } } public static String getTZDateString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append(" CST"); buff.append("'"); return (buff.toString()); } } public static String getTZTimeString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append(" CST"); buff.append("'"); return (buff.toString()); } } public static String getTZTimestampString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append(" CST"); buff.append("'"); return (buff.toString()); } } public static String getUuidString(UUID val) { if (val == null) { return ("null"); } else { return ("'" + val.toString() + "'"); } } public static Calendar convertDateString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9')) && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-') && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1')) && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-') && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3')) && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9'))) { /* * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int year = Integer.parseInt(val.substring(0, 3)); int month = Integer.parseInt(val.substring(5, 7)); int day = Integer.parseInt(val.substring(8, 10)); return new GregorianCalendar(year, month - 1, day); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(MSSBamPg8Schema.class, "convertDateString", "Value must be in YYYY-MM-DD format"); } } public static Calendar convertTimeString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '2')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && (val.charAt(2) == ':') && ((val.charAt(3) >= '0') && (val.charAt(3) <= '5')) && ((val.charAt(4) >= '0') && (val.charAt(4) <= '9')) && (val.charAt(5) == ':') && ((val.charAt(6) >= '0') && (val.charAt(6) <= '5')) && ((val.charAt(7) >= '0') && (val.charAt(7) <= '9'))) { /* * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int hour = Integer.parseInt(val.substring(0, 2)); int minute = Integer.parseInt(val.substring(3, 5)); int second = Integer.parseInt(val.substring(6, 8)); return new GregorianCalendar(0, 0, 0, hour, minute, second); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(MSSBamPg8Schema.class, "convertTimeString", "Value must be in HH24:MI:SS format"); } } public static Calendar convertTimestampString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9')) && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-') && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1')) && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-') && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3')) && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9')) && (val.charAt(10) == ' ') && ((val.charAt(11) >= '0') && (val.charAt(11) <= '2')) && ((val.charAt(12) >= '0') && (val.charAt(12) <= '9')) && (val.charAt(13) == ':') && ((val.charAt(14) >= '0') && (val.charAt(14) <= '5')) && ((val.charAt(15) >= '0') && (val.charAt(15) <= '9')) && (val.charAt(16) == ':') && ((val.charAt(17) >= '0') && (val.charAt(17) <= '5')) && ((val.charAt(18) >= '0') && (val.charAt(18) <= '9'))) { /* * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int year = Integer.parseInt(val.substring(0, 4)); int month = Integer.parseInt(val.substring(5, 7)); int day = Integer.parseInt(val.substring(8, 10)); int hour = Integer.parseInt(val.substring(11, 13)); int minute = Integer.parseInt(val.substring(14, 16)); int second = Integer.parseInt(val.substring(17, 19)); return new GregorianCalendar(year, month - 1, day, hour, minute, second); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(MSSBamPg8Schema.class, "convertTimestampString", "Value must be in YYYY-MM-DD HH24:MI:SS format"); } } public static Calendar convertTZDateString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9')) && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-') && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1')) && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-') && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3')) && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9'))) { /* * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int year = Integer.parseInt(val.substring(0, 4)); int month = Integer.parseInt(val.substring(5, 7)); int day = Integer.parseInt(val.substring(8, 10)); /* TODO: Parse and apply TZ */ return new GregorianCalendar(year, month - 1, day); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(MSSBamPg8Schema.class, "convertTZDateString", "Value must be in YYYY-MM-DD format"); } } public static Calendar convertTZTimeString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '2')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && (val.charAt(2) == ':') && ((val.charAt(3) >= '0') && (val.charAt(3) <= '5')) && ((val.charAt(4) >= '0') && (val.charAt(4) <= '9')) && (val.charAt(5) == ':') && ((val.charAt(6) >= '0') && (val.charAt(6) <= '5')) && ((val.charAt(7) >= '0') && (val.charAt(7) <= '9'))) { /* * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int hour = Integer.parseInt(val.substring(0, 2)); int minute = Integer.parseInt(val.substring(3, 5)); int second = Integer.parseInt(val.substring(6, 8)); /* TODO: Parse and apply TZ */ return new GregorianCalendar(0, 0, 0, hour, minute, second); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(MSSBamPg8Schema.class, "convertTZTimeString", "Value must be in HH24:MI:SS format"); } } public static Calendar convertTZTimestampString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9')) && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-') && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1')) && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-') && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3')) && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9')) && (val.charAt(10) == ' ') && ((val.charAt(11) >= '0') && (val.charAt(11) <= '2')) && ((val.charAt(12) >= '0') && (val.charAt(12) <= '9')) && (val.charAt(13) == ':') && ((val.charAt(14) >= '0') && (val.charAt(14) <= '5')) && ((val.charAt(15) >= '0') && (val.charAt(15) <= '9')) && (val.charAt(16) == ':') && ((val.charAt(17) >= '0') && (val.charAt(17) <= '5')) && ((val.charAt(18) >= '0') && (val.charAt(18) <= '9'))) { /* * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int year = Integer.parseInt(val.substring(0, 4)); int month = Integer.parseInt(val.substring(5, 7)); int day = Integer.parseInt(val.substring(8, 10)); int hour = Integer.parseInt(val.substring(11, 13)); int minute = Integer.parseInt(val.substring(14, 16)); int second = Integer.parseInt(val.substring(17, 19)); /* TODO: Parse and apply TZ */ return new GregorianCalendar(year, month - 1, day, hour, minute, second); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(MSSBamPg8Schema.class, "convertTZTimestampString", "Value must be in YYYY-MM-DD HH24:MI:SS TZ format"); } } public static UUID convertUuidString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else { return (UUID.fromString(val)); } } }