Java tutorial
// Description: Java 7 MS SQL Server 2012 Express Advanced Edition Jdbc DbIO implementation for CFAcc. /* * MSS Code Factory Accounting Business Application Model * * Copyright (c) 2014 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/>. * * This source code incorporates modified modules originally licensed * under the Apache 2.0 license by MSS Code Factory including CFSecurity * (net-sourceforge-msscodefactory-2.0-cfsecurity.xml), * CFInternet (net-sourceforge-msscodefactory-2.0-cfinternet.xml), and * CFCrm 2.0 (net-sourceforge-msscodefactory-2.0-cfcrm.xml), with all of the * required models being available as part of the MSS Code Factory 1.11 * distribution source and install zips. * * You can download installations of MSS Code Factory 1.11 from * http://msscodefactory.sourceforge.net/ * * *********************************************************************** * * Code manufactured by MSS Code Factory */ package net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql; 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_11.CFLib.*; import org.apache.commons.codec.binary.Base64; import net.sourceforge.msscodefactory.cfacc.v2_0.CFAcc.*; public class CFAccMSSqlSchema extends CFAccSchema { protected Connection cnx; protected PreparedStatement stmtSelectNextServiceTypeIdGen = null; protected PreparedStatement stmtSelectNextMimeTypeIdGen = null; protected PreparedStatement stmtSelectNextClusterIdGen = null; protected PreparedStatement stmtSelectNextTenantIdGen = null; protected PreparedStatement stmtSelectNextAccountIdGen = null; protected boolean inTransaction; protected PreparedStatement stmtBeginTransaction = null; public CFAccMSSqlSchema() { super(); cnx = null; inTransaction = false; tableAccount = new CFAccMSSqlAccountTable(this); tableAccountConfig = new CFAccMSSqlAccountConfigTable(this); tableAccountContact = new CFAccMSSqlAccountContactTable(this); tableAccountEntry = new CFAccMSSqlAccountEntryTable(this); tableAddress = new CFAccMSSqlAddressTable(this); tableAddressTag = new CFAccMSSqlAddressTagTable(this); tableAttachment = new CFAccMSSqlAttachmentTable(this); tableAttachmentTag = new CFAccMSSqlAttachmentTagTable(this); tableAuditAction = new CFAccMSSqlAuditActionTable(this); tableCluster = new CFAccMSSqlClusterTable(this); tableContact = new CFAccMSSqlContactTable(this); tableContactList = new CFAccMSSqlContactListTable(this); tableContactTag = new CFAccMSSqlContactTagTable(this); tableContactURL = new CFAccMSSqlContactURLTable(this); tableDomain = new CFAccMSSqlDomainTable(this); tableDomainBase = new CFAccMSSqlDomainBaseTable(this); tableHostNode = new CFAccMSSqlHostNodeTable(this); tableISOCountry = new CFAccMSSqlISOCountryTable(this); tableISOCountryCurrency = new CFAccMSSqlISOCountryCurrencyTable(this); tableISOCountryLanguage = new CFAccMSSqlISOCountryLanguageTable(this); tableISOCurrency = new CFAccMSSqlISOCurrencyTable(this); tableISOLanguage = new CFAccMSSqlISOLanguageTable(this); tableISOTimezone = new CFAccMSSqlISOTimezoneTable(this); tableMajorVersion = new CFAccMSSqlMajorVersionTable(this); tableMemo = new CFAccMSSqlMemoTable(this); tableMemoTag = new CFAccMSSqlMemoTagTable(this); tableMimeType = new CFAccMSSqlMimeTypeTable(this); tableMinorVersion = new CFAccMSSqlMinorVersionTable(this); tablePhone = new CFAccMSSqlPhoneTable(this); tablePhoneTag = new CFAccMSSqlPhoneTagTable(this); tableProjectBase = new CFAccMSSqlProjectBaseTable(this); tableRealProject = new CFAccMSSqlRealProjectTable(this); tableSecApp = new CFAccMSSqlSecAppTable(this); tableSecForm = new CFAccMSSqlSecFormTable(this); tableSecGroup = new CFAccMSSqlSecGroupTable(this); tableSecGroupForm = new CFAccMSSqlSecGroupFormTable(this); tableSecGroupInclude = new CFAccMSSqlSecGroupIncludeTable(this); tableSecGroupMember = new CFAccMSSqlSecGroupMemberTable(this); tableSecSession = new CFAccMSSqlSecSessionTable(this); tableSecUser = new CFAccMSSqlSecUserTable(this); tableService = new CFAccMSSqlServiceTable(this); tableServiceType = new CFAccMSSqlServiceTypeTable(this); tableSubProject = new CFAccMSSqlSubProjectTable(this); tableTSecGroup = new CFAccMSSqlTSecGroupTable(this); tableTSecGroupInclude = new CFAccMSSqlTSecGroupIncludeTable(this); tableTSecGroupMember = new CFAccMSSqlTSecGroupMemberTable(this); tableTag = new CFAccMSSqlTagTable(this); tableTenant = new CFAccMSSqlTenantTable(this); tableTld = new CFAccMSSqlTldTable(this); tableTopDomain = new CFAccMSSqlTopDomainTable(this); tableTopProject = new CFAccMSSqlTopProjectTable(this); tableURLProtocol = new CFAccMSSqlURLProtocolTable(this); tableVersion = new CFAccMSSqlVersionTable(this); } public CFAccMSSqlSchema(CFAccConfigurationFile conf) { super(conf); cnx = null; inTransaction = false; tableAccount = new CFAccMSSqlAccountTable(this); tableAccountConfig = new CFAccMSSqlAccountConfigTable(this); tableAccountContact = new CFAccMSSqlAccountContactTable(this); tableAccountEntry = new CFAccMSSqlAccountEntryTable(this); tableAddress = new CFAccMSSqlAddressTable(this); tableAddressTag = new CFAccMSSqlAddressTagTable(this); tableAttachment = new CFAccMSSqlAttachmentTable(this); tableAttachmentTag = new CFAccMSSqlAttachmentTagTable(this); tableAuditAction = new CFAccMSSqlAuditActionTable(this); tableCluster = new CFAccMSSqlClusterTable(this); tableContact = new CFAccMSSqlContactTable(this); tableContactList = new CFAccMSSqlContactListTable(this); tableContactTag = new CFAccMSSqlContactTagTable(this); tableContactURL = new CFAccMSSqlContactURLTable(this); tableDomain = new CFAccMSSqlDomainTable(this); tableDomainBase = new CFAccMSSqlDomainBaseTable(this); tableHostNode = new CFAccMSSqlHostNodeTable(this); tableISOCountry = new CFAccMSSqlISOCountryTable(this); tableISOCountryCurrency = new CFAccMSSqlISOCountryCurrencyTable(this); tableISOCountryLanguage = new CFAccMSSqlISOCountryLanguageTable(this); tableISOCurrency = new CFAccMSSqlISOCurrencyTable(this); tableISOLanguage = new CFAccMSSqlISOLanguageTable(this); tableISOTimezone = new CFAccMSSqlISOTimezoneTable(this); tableMajorVersion = new CFAccMSSqlMajorVersionTable(this); tableMemo = new CFAccMSSqlMemoTable(this); tableMemoTag = new CFAccMSSqlMemoTagTable(this); tableMimeType = new CFAccMSSqlMimeTypeTable(this); tableMinorVersion = new CFAccMSSqlMinorVersionTable(this); tablePhone = new CFAccMSSqlPhoneTable(this); tablePhoneTag = new CFAccMSSqlPhoneTagTable(this); tableProjectBase = new CFAccMSSqlProjectBaseTable(this); tableRealProject = new CFAccMSSqlRealProjectTable(this); tableSecApp = new CFAccMSSqlSecAppTable(this); tableSecForm = new CFAccMSSqlSecFormTable(this); tableSecGroup = new CFAccMSSqlSecGroupTable(this); tableSecGroupForm = new CFAccMSSqlSecGroupFormTable(this); tableSecGroupInclude = new CFAccMSSqlSecGroupIncludeTable(this); tableSecGroupMember = new CFAccMSSqlSecGroupMemberTable(this); tableSecSession = new CFAccMSSqlSecSessionTable(this); tableSecUser = new CFAccMSSqlSecUserTable(this); tableService = new CFAccMSSqlServiceTable(this); tableServiceType = new CFAccMSSqlServiceTypeTable(this); tableSubProject = new CFAccMSSqlSubProjectTable(this); tableTSecGroup = new CFAccMSSqlTSecGroupTable(this); tableTSecGroupInclude = new CFAccMSSqlTSecGroupIncludeTable(this); tableTSecGroupMember = new CFAccMSSqlTSecGroupMemberTable(this); tableTag = new CFAccMSSqlTagTable(this); tableTenant = new CFAccMSSqlTenantTable(this); tableTld = new CFAccMSSqlTldTable(this); tableTopDomain = new CFAccMSSqlTopDomainTable(this); tableTopProject = new CFAccMSSqlTopProjectTable(this); tableURLProtocol = new CFAccMSSqlURLProtocolTable(this); tableVersion = new CFAccMSSqlVersionTable(this); setSchemaDbName(conf.getDbDatabase()); } public CFAccMSSqlSchema(String argJndiName) { super(argJndiName); cnx = null; inTransaction = false; tableAccount = new CFAccMSSqlAccountTable(this); tableAccountConfig = new CFAccMSSqlAccountConfigTable(this); tableAccountContact = new CFAccMSSqlAccountContactTable(this); tableAccountEntry = new CFAccMSSqlAccountEntryTable(this); tableAddress = new CFAccMSSqlAddressTable(this); tableAddressTag = new CFAccMSSqlAddressTagTable(this); tableAttachment = new CFAccMSSqlAttachmentTable(this); tableAttachmentTag = new CFAccMSSqlAttachmentTagTable(this); tableAuditAction = new CFAccMSSqlAuditActionTable(this); tableCluster = new CFAccMSSqlClusterTable(this); tableContact = new CFAccMSSqlContactTable(this); tableContactList = new CFAccMSSqlContactListTable(this); tableContactTag = new CFAccMSSqlContactTagTable(this); tableContactURL = new CFAccMSSqlContactURLTable(this); tableDomain = new CFAccMSSqlDomainTable(this); tableDomainBase = new CFAccMSSqlDomainBaseTable(this); tableHostNode = new CFAccMSSqlHostNodeTable(this); tableISOCountry = new CFAccMSSqlISOCountryTable(this); tableISOCountryCurrency = new CFAccMSSqlISOCountryCurrencyTable(this); tableISOCountryLanguage = new CFAccMSSqlISOCountryLanguageTable(this); tableISOCurrency = new CFAccMSSqlISOCurrencyTable(this); tableISOLanguage = new CFAccMSSqlISOLanguageTable(this); tableISOTimezone = new CFAccMSSqlISOTimezoneTable(this); tableMajorVersion = new CFAccMSSqlMajorVersionTable(this); tableMemo = new CFAccMSSqlMemoTable(this); tableMemoTag = new CFAccMSSqlMemoTagTable(this); tableMimeType = new CFAccMSSqlMimeTypeTable(this); tableMinorVersion = new CFAccMSSqlMinorVersionTable(this); tablePhone = new CFAccMSSqlPhoneTable(this); tablePhoneTag = new CFAccMSSqlPhoneTagTable(this); tableProjectBase = new CFAccMSSqlProjectBaseTable(this); tableRealProject = new CFAccMSSqlRealProjectTable(this); tableSecApp = new CFAccMSSqlSecAppTable(this); tableSecForm = new CFAccMSSqlSecFormTable(this); tableSecGroup = new CFAccMSSqlSecGroupTable(this); tableSecGroupForm = new CFAccMSSqlSecGroupFormTable(this); tableSecGroupInclude = new CFAccMSSqlSecGroupIncludeTable(this); tableSecGroupMember = new CFAccMSSqlSecGroupMemberTable(this); tableSecSession = new CFAccMSSqlSecSessionTable(this); tableSecUser = new CFAccMSSqlSecUserTable(this); tableService = new CFAccMSSqlServiceTable(this); tableServiceType = new CFAccMSSqlServiceTypeTable(this); tableSubProject = new CFAccMSSqlSubProjectTable(this); tableTSecGroup = new CFAccMSSqlTSecGroupTable(this); tableTSecGroupInclude = new CFAccMSSqlTSecGroupIncludeTable(this); tableTSecGroupMember = new CFAccMSSqlTSecGroupMemberTable(this); tableTag = new CFAccMSSqlTagTable(this); tableTenant = new CFAccMSSqlTenantTable(this); tableTld = new CFAccMSSqlTldTable(this); tableTopDomain = new CFAccMSSqlTopDomainTable(this); tableTopProject = new CFAccMSSqlTopProjectTable(this); tableURLProtocol = new CFAccMSSqlURLProtocolTable(this); tableVersion = new CFAccMSSqlVersionTable(this); } public CFAccMSSqlSchema(Connection argCnx) { super(); cnx = argCnx; inTransaction = false; tableAccount = new CFAccMSSqlAccountTable(this); tableAccountConfig = new CFAccMSSqlAccountConfigTable(this); tableAccountContact = new CFAccMSSqlAccountContactTable(this); tableAccountEntry = new CFAccMSSqlAccountEntryTable(this); tableAddress = new CFAccMSSqlAddressTable(this); tableAddressTag = new CFAccMSSqlAddressTagTable(this); tableAttachment = new CFAccMSSqlAttachmentTable(this); tableAttachmentTag = new CFAccMSSqlAttachmentTagTable(this); tableAuditAction = new CFAccMSSqlAuditActionTable(this); tableCluster = new CFAccMSSqlClusterTable(this); tableContact = new CFAccMSSqlContactTable(this); tableContactList = new CFAccMSSqlContactListTable(this); tableContactTag = new CFAccMSSqlContactTagTable(this); tableContactURL = new CFAccMSSqlContactURLTable(this); tableDomain = new CFAccMSSqlDomainTable(this); tableDomainBase = new CFAccMSSqlDomainBaseTable(this); tableHostNode = new CFAccMSSqlHostNodeTable(this); tableISOCountry = new CFAccMSSqlISOCountryTable(this); tableISOCountryCurrency = new CFAccMSSqlISOCountryCurrencyTable(this); tableISOCountryLanguage = new CFAccMSSqlISOCountryLanguageTable(this); tableISOCurrency = new CFAccMSSqlISOCurrencyTable(this); tableISOLanguage = new CFAccMSSqlISOLanguageTable(this); tableISOTimezone = new CFAccMSSqlISOTimezoneTable(this); tableMajorVersion = new CFAccMSSqlMajorVersionTable(this); tableMemo = new CFAccMSSqlMemoTable(this); tableMemoTag = new CFAccMSSqlMemoTagTable(this); tableMimeType = new CFAccMSSqlMimeTypeTable(this); tableMinorVersion = new CFAccMSSqlMinorVersionTable(this); tablePhone = new CFAccMSSqlPhoneTable(this); tablePhoneTag = new CFAccMSSqlPhoneTagTable(this); tableProjectBase = new CFAccMSSqlProjectBaseTable(this); tableRealProject = new CFAccMSSqlRealProjectTable(this); tableSecApp = new CFAccMSSqlSecAppTable(this); tableSecForm = new CFAccMSSqlSecFormTable(this); tableSecGroup = new CFAccMSSqlSecGroupTable(this); tableSecGroupForm = new CFAccMSSqlSecGroupFormTable(this); tableSecGroupInclude = new CFAccMSSqlSecGroupIncludeTable(this); tableSecGroupMember = new CFAccMSSqlSecGroupMemberTable(this); tableSecSession = new CFAccMSSqlSecSessionTable(this); tableSecUser = new CFAccMSSqlSecUserTable(this); tableService = new CFAccMSSqlServiceTable(this); tableServiceType = new CFAccMSSqlServiceTypeTable(this); tableSubProject = new CFAccMSSqlSubProjectTable(this); tableTSecGroup = new CFAccMSSqlTSecGroupTable(this); tableTSecGroupInclude = new CFAccMSSqlTSecGroupIncludeTable(this); tableTSecGroupMember = new CFAccMSSqlTSecGroupMemberTable(this); tableTag = new CFAccMSSqlTagTable(this); tableTenant = new CFAccMSSqlTenantTable(this); tableTld = new CFAccMSSqlTldTable(this); tableTopDomain = new CFAccMSSqlTopDomainTable(this); tableTopProject = new CFAccMSSqlTopProjectTable(this); tableURLProtocol = new CFAccMSSqlURLProtocolTable(this); tableVersion = new CFAccMSSqlVersionTable(this); try { cnx.setAutoCommit(false); cnx.rollback(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "CFAccMSSqlSchema-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; releasePreparedStatements(); } 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) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "connect", "Could not load MS SQL Server 2012 Express Advanced Edition driver", e); } String dbServer = configuration.getDbServer(); int dbPort = configuration.getDbPort(); String dbDatabase = configuration.getDbDatabase(); String dbUserName = configuration.getDbUserName(); String dbPassword = configuration.getDbPassword(); String url = "jdbc:sqlserver://" + dbServer + ":" + Integer.toString(dbPort) + ";"; Properties props = new Properties(); props.setProperty("user", dbUserName); props.setProperty("password", dbPassword); try { cnx = DriverManager.getConnection(url, props); cnx.setAutoCommit(false); cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); cnx.rollback(); setSchemaDbName(dbDatabase); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<connect>>", e); } Statement stmtUseDatabase = null; try { stmtUseDatabase = cnx.createStatement(); stmtUseDatabase.executeUpdate("use " + dbDatabase); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<useDatabase>>", e); } finally { if (stmtUseDatabase != null) { try { stmtUseDatabase.close(); } catch (SQLException e) { } stmtUseDatabase = null; } } 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.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); cnx.rollback(); } catch (NamingException e) { cnx = null; throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName + "<<jndiGetConnection>>", "NamingException " + e.getMessage(), e); } catch (SQLException e) { cnx = null; inTransaction = false; throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<jndiGetConnection>>", e); } return (true); } throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Neither configurationFile nor jndiName found, do not know how to connect to database"); } public boolean connect(String username, String password) { final String S_ProcName = "connect"; if (cnx != null) { return (false); } if ((username == null) || (username.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "username"); } if (password == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "password"); } if (configuration != null) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "connect", "Could not load MS SQL Server 2012 Express Advanced Edition driver", e); } String dbServer = configuration.getDbServer(); int dbPort = configuration.getDbPort(); String dbDatabase = configuration.getDbDatabase(); String dbUserName = username; String dbPassword = password; String url = "jdbc:sqlserver://" + dbServer + ":" + Integer.toString(dbPort) + ";"; Properties props = new Properties(); props.setProperty("user", dbUserName); props.setProperty("password", dbPassword); try { cnx = DriverManager.getConnection(url, props); cnx.setAutoCommit(false); cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); cnx.rollback(); setSchemaDbName(dbDatabase); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<connect>>", e); } Statement stmtUseDatabase = null; try { stmtUseDatabase = cnx.createStatement(); stmtUseDatabase.executeUpdate("use " + dbDatabase); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<useDatabase>>", e); } finally { if (stmtUseDatabase != null) { try { stmtUseDatabase.close(); } catch (SQLException e) { } stmtUseDatabase = null; } } return (true); } throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "configurationFile not found, do not know how to connect to database"); } public boolean connect(String clustername, String tenantname, String secUserName, String dbUserName, String dbPassword) { boolean retval = connect(dbUserName, dbPassword); return (retval); } public void disconnect(boolean doCommit) { final String S_ProcName = "disconnect"; if (cnx != null) { try { if (!cnx.isClosed()) { if (doCommit) { cnx.commit(); } else { cnx.rollback(); } releasePreparedStatements(); cnx.close(); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { cnx = null; } } releasePreparedStatements(); } public boolean isTransactionOpen() { return (inTransaction); } public boolean beginTransaction() { if (inTransaction) { return (false); } try { final String sql = "begin transaction"; if (stmtBeginTransaction == null) { stmtBeginTransaction = cnx.prepareStatement(sql); } stmtBeginTransaction.execute(); 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 boolean isSystemUser(CFAccAuthorization Authorization) { final String S_ProcName = "isSystemUser"; if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); } CallableStatement stmtSecurityCheck = null; try { final String sql = "exec sp_is_system_user ?, ?"; stmtSecurityCheck = cnx.prepareCall(sql); stmtSecurityCheck.registerOutParameter(1, java.sql.Types.INTEGER); stmtSecurityCheck.setString(2, Authorization.getSecUserId().toString()); stmtSecurityCheck.execute(); int isAuthorized = stmtSecurityCheck.getInt(1); if (isAuthorized == 0) { return (false); } else { return (true); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSecurityCheck != null) { try { stmtSecurityCheck.close(); } catch (SQLException e) { } stmtSecurityCheck = null; } } } public boolean isClusterUser(CFAccAuthorization Authorization, long clusterId, String secGroupName) { final String S_ProcName = "isClusterUser"; if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); } CallableStatement stmtSecurityCheck = null; try { final String sql = "exec sp_is_cluster_user ?, ?, ?, ?"; stmtSecurityCheck = cnx.prepareCall(sql); stmtSecurityCheck.registerOutParameter(1, java.sql.Types.INTEGER); stmtSecurityCheck.setLong(2, clusterId); stmtSecurityCheck.setString(3, secGroupName); stmtSecurityCheck.setString(4, Authorization.getSecUserId().toString()); stmtSecurityCheck.execute(); int isAuthorized = stmtSecurityCheck.getInt(1); if (isAuthorized == 0) { return (false); } else { return (true); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSecurityCheck != null) { try { stmtSecurityCheck.close(); } catch (SQLException e) { } stmtSecurityCheck = null; } } } public boolean isTenantUser(CFAccAuthorization Authorization, long tenantId, String secGroupName) { final String S_ProcName = "isTenantUser"; if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); } CallableStatement stmtSecurityCheck = null; try { final String sql = "exec sp_is_tenant_user ?, ?, ?, ?"; stmtSecurityCheck = cnx.prepareCall(sql); stmtSecurityCheck.registerOutParameter(1, java.sql.Types.INTEGER); stmtSecurityCheck.setLong(2, tenantId); stmtSecurityCheck.setString(3, secGroupName); stmtSecurityCheck.setString(4, Authorization.getSecUserId().toString()); stmtSecurityCheck.execute(); int isAuthorized = stmtSecurityCheck.getInt(1); if (isAuthorized == 0) { return (false); } else { return (true); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSecurityCheck != null) { try { stmtSecurityCheck.close(); } catch (SQLException e) { } stmtSecurityCheck = null; } } } public int nextServiceTypeIdGen() { final String S_ProcName = "nextServiceTypeIdGen"; if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); } int nextId = -1; Statement stmtNext = null; ResultSet resultSet = null; try { final String sql = "exec sp_selnext_servicetypeidgen"; if (stmtSelectNextServiceTypeIdGen == null) { stmtSelectNextServiceTypeIdGen = cnx.prepareStatement(sql); } stmtSelectNextServiceTypeIdGen.execute(); boolean moreResults = true; while (resultSet == null) { try { moreResults = stmtSelectNextServiceTypeIdGen.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtSelectNextServiceTypeIdGen.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtSelectNextServiceTypeIdGen.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { nextId = resultSet.getInt(1); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } } return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextServiceTypeIdGen", e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public int nextMimeTypeIdGen() { final String S_ProcName = "nextMimeTypeIdGen"; if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); } int nextId = -1; Statement stmtNext = null; ResultSet resultSet = null; try { final String sql = "exec sp_selnext_mimetypeidgen"; if (stmtSelectNextMimeTypeIdGen == null) { stmtSelectNextMimeTypeIdGen = cnx.prepareStatement(sql); } stmtSelectNextMimeTypeIdGen.execute(); boolean moreResults = true; while (resultSet == null) { try { moreResults = stmtSelectNextMimeTypeIdGen.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtSelectNextMimeTypeIdGen.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtSelectNextMimeTypeIdGen.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { nextId = resultSet.getInt(1); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } } return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextMimeTypeIdGen", e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public long nextClusterIdGen() { final String S_ProcName = "nextClusterIdGen"; if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); } long nextId = -1; Statement stmtNext = null; ResultSet resultSet = null; try { final String sql = "exec sp_selnext_clusteridgen"; if (stmtSelectNextClusterIdGen == null) { stmtSelectNextClusterIdGen = cnx.prepareStatement(sql); } stmtSelectNextClusterIdGen.execute(); boolean moreResults = true; while (resultSet == null) { try { moreResults = stmtSelectNextClusterIdGen.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtSelectNextClusterIdGen.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtSelectNextClusterIdGen.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { nextId = resultSet.getLong(1); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } } return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextClusterIdGen", e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public long nextTenantIdGen() { final String S_ProcName = "nextTenantIdGen"; if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); } long nextId = -1; Statement stmtNext = null; ResultSet resultSet = null; try { final String sql = "exec sp_selnext_tenantidgen"; if (stmtSelectNextTenantIdGen == null) { stmtSelectNextTenantIdGen = cnx.prepareStatement(sql); } stmtSelectNextTenantIdGen.execute(); boolean moreResults = true; while (resultSet == null) { try { moreResults = stmtSelectNextTenantIdGen.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtSelectNextTenantIdGen.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtSelectNextTenantIdGen.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { nextId = resultSet.getLong(1); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } } return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextTenantIdGen", e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public long nextAccountIdGen() { final String S_ProcName = "nextAccountIdGen"; if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); } long nextId = -1; Statement stmtNext = null; ResultSet resultSet = null; try { final String sql = "exec sp_selnext_accountidgen"; if (stmtSelectNextAccountIdGen == null) { stmtSelectNextAccountIdGen = cnx.prepareStatement(sql); } stmtSelectNextAccountIdGen.execute(); boolean moreResults = true; while (resultSet == null) { try { moreResults = stmtSelectNextAccountIdGen.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtSelectNextAccountIdGen.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtSelectNextAccountIdGen.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } if (resultSet.next()) { nextId = resultSet.getLong(1); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } } return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "nextAccountIdGen", e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public UUID nextSecSessionIdGen() { UUID retval = UUID.randomUUID(); return (retval); } public UUID nextSecUserIdGen() { UUID retval = UUID.randomUUID(); return (retval); } public UUID nextAccountEntryIdGen() { UUID retval = UUID.randomUUID(); return (retval); } /** * Release the prepared statements. * <p> * When the schema changes connections, the prepared statements * have to be released because they contain connection-specific * information for most databases. */ public void releasePreparedStatements() { final String S_ProcName = "releasePreparedStatements"; if (stmtBeginTransaction != null) { try { stmtBeginTransaction.close(); } catch (SQLException e) { } stmtBeginTransaction = null; } if (stmtSelectNextServiceTypeIdGen != null) { try { stmtSelectNextServiceTypeIdGen.close(); } catch (SQLException e) { } stmtSelectNextServiceTypeIdGen = null; } if (stmtSelectNextMimeTypeIdGen != null) { try { stmtSelectNextMimeTypeIdGen.close(); } catch (SQLException e) { } stmtSelectNextMimeTypeIdGen = null; } if (stmtSelectNextClusterIdGen != null) { try { stmtSelectNextClusterIdGen.close(); } catch (SQLException e) { } stmtSelectNextClusterIdGen = null; } if (stmtSelectNextTenantIdGen != null) { try { stmtSelectNextTenantIdGen.close(); } catch (SQLException e) { } stmtSelectNextTenantIdGen = null; } if (stmtSelectNextAccountIdGen != null) { try { stmtSelectNextAccountIdGen.close(); } catch (SQLException e) { } stmtSelectNextAccountIdGen = null; } if ((tableAccount != null) && (tableAccount instanceof CFAccMSSqlAccountTable)) { CFAccMSSqlAccountTable table = (CFAccMSSqlAccountTable) tableAccount; table.releasePreparedStatements(); } if ((tableAccountConfig != null) && (tableAccountConfig instanceof CFAccMSSqlAccountConfigTable)) { CFAccMSSqlAccountConfigTable table = (CFAccMSSqlAccountConfigTable) tableAccountConfig; table.releasePreparedStatements(); } if ((tableAccountContact != null) && (tableAccountContact instanceof CFAccMSSqlAccountContactTable)) { CFAccMSSqlAccountContactTable table = (CFAccMSSqlAccountContactTable) tableAccountContact; table.releasePreparedStatements(); } if ((tableAccountEntry != null) && (tableAccountEntry instanceof CFAccMSSqlAccountEntryTable)) { CFAccMSSqlAccountEntryTable table = (CFAccMSSqlAccountEntryTable) tableAccountEntry; table.releasePreparedStatements(); } if ((tableAddress != null) && (tableAddress instanceof CFAccMSSqlAddressTable)) { CFAccMSSqlAddressTable table = (CFAccMSSqlAddressTable) tableAddress; table.releasePreparedStatements(); } if ((tableAddressTag != null) && (tableAddressTag instanceof CFAccMSSqlAddressTagTable)) { CFAccMSSqlAddressTagTable table = (CFAccMSSqlAddressTagTable) tableAddressTag; table.releasePreparedStatements(); } if ((tableAttachment != null) && (tableAttachment instanceof CFAccMSSqlAttachmentTable)) { CFAccMSSqlAttachmentTable table = (CFAccMSSqlAttachmentTable) tableAttachment; table.releasePreparedStatements(); } if ((tableAttachmentTag != null) && (tableAttachmentTag instanceof CFAccMSSqlAttachmentTagTable)) { CFAccMSSqlAttachmentTagTable table = (CFAccMSSqlAttachmentTagTable) tableAttachmentTag; table.releasePreparedStatements(); } if ((tableAuditAction != null) && (tableAuditAction instanceof CFAccMSSqlAuditActionTable)) { CFAccMSSqlAuditActionTable table = (CFAccMSSqlAuditActionTable) tableAuditAction; table.releasePreparedStatements(); } if ((tableCluster != null) && (tableCluster instanceof CFAccMSSqlClusterTable)) { CFAccMSSqlClusterTable table = (CFAccMSSqlClusterTable) tableCluster; table.releasePreparedStatements(); } if ((tableContact != null) && (tableContact instanceof CFAccMSSqlContactTable)) { CFAccMSSqlContactTable table = (CFAccMSSqlContactTable) tableContact; table.releasePreparedStatements(); } if ((tableContactList != null) && (tableContactList instanceof CFAccMSSqlContactListTable)) { CFAccMSSqlContactListTable table = (CFAccMSSqlContactListTable) tableContactList; table.releasePreparedStatements(); } if ((tableContactTag != null) && (tableContactTag instanceof CFAccMSSqlContactTagTable)) { CFAccMSSqlContactTagTable table = (CFAccMSSqlContactTagTable) tableContactTag; table.releasePreparedStatements(); } if ((tableContactURL != null) && (tableContactURL instanceof CFAccMSSqlContactURLTable)) { CFAccMSSqlContactURLTable table = (CFAccMSSqlContactURLTable) tableContactURL; table.releasePreparedStatements(); } if ((tableDomain != null) && (tableDomain instanceof CFAccMSSqlDomainTable)) { CFAccMSSqlDomainTable table = (CFAccMSSqlDomainTable) tableDomain; table.releasePreparedStatements(); } if ((tableDomainBase != null) && (tableDomainBase instanceof CFAccMSSqlDomainBaseTable)) { CFAccMSSqlDomainBaseTable table = (CFAccMSSqlDomainBaseTable) tableDomainBase; table.releasePreparedStatements(); } if ((tableHostNode != null) && (tableHostNode instanceof CFAccMSSqlHostNodeTable)) { CFAccMSSqlHostNodeTable table = (CFAccMSSqlHostNodeTable) tableHostNode; table.releasePreparedStatements(); } if ((tableISOCountry != null) && (tableISOCountry instanceof CFAccMSSqlISOCountryTable)) { CFAccMSSqlISOCountryTable table = (CFAccMSSqlISOCountryTable) tableISOCountry; table.releasePreparedStatements(); } if ((tableISOCountryCurrency != null) && (tableISOCountryCurrency instanceof CFAccMSSqlISOCountryCurrencyTable)) { CFAccMSSqlISOCountryCurrencyTable table = (CFAccMSSqlISOCountryCurrencyTable) tableISOCountryCurrency; table.releasePreparedStatements(); } if ((tableISOCountryLanguage != null) && (tableISOCountryLanguage instanceof CFAccMSSqlISOCountryLanguageTable)) { CFAccMSSqlISOCountryLanguageTable table = (CFAccMSSqlISOCountryLanguageTable) tableISOCountryLanguage; table.releasePreparedStatements(); } if ((tableISOCurrency != null) && (tableISOCurrency instanceof CFAccMSSqlISOCurrencyTable)) { CFAccMSSqlISOCurrencyTable table = (CFAccMSSqlISOCurrencyTable) tableISOCurrency; table.releasePreparedStatements(); } if ((tableISOLanguage != null) && (tableISOLanguage instanceof CFAccMSSqlISOLanguageTable)) { CFAccMSSqlISOLanguageTable table = (CFAccMSSqlISOLanguageTable) tableISOLanguage; table.releasePreparedStatements(); } if ((tableISOTimezone != null) && (tableISOTimezone instanceof CFAccMSSqlISOTimezoneTable)) { CFAccMSSqlISOTimezoneTable table = (CFAccMSSqlISOTimezoneTable) tableISOTimezone; table.releasePreparedStatements(); } if ((tableMajorVersion != null) && (tableMajorVersion instanceof CFAccMSSqlMajorVersionTable)) { CFAccMSSqlMajorVersionTable table = (CFAccMSSqlMajorVersionTable) tableMajorVersion; table.releasePreparedStatements(); } if ((tableMemo != null) && (tableMemo instanceof CFAccMSSqlMemoTable)) { CFAccMSSqlMemoTable table = (CFAccMSSqlMemoTable) tableMemo; table.releasePreparedStatements(); } if ((tableMemoTag != null) && (tableMemoTag instanceof CFAccMSSqlMemoTagTable)) { CFAccMSSqlMemoTagTable table = (CFAccMSSqlMemoTagTable) tableMemoTag; table.releasePreparedStatements(); } if ((tableMimeType != null) && (tableMimeType instanceof CFAccMSSqlMimeTypeTable)) { CFAccMSSqlMimeTypeTable table = (CFAccMSSqlMimeTypeTable) tableMimeType; table.releasePreparedStatements(); } if ((tableMinorVersion != null) && (tableMinorVersion instanceof CFAccMSSqlMinorVersionTable)) { CFAccMSSqlMinorVersionTable table = (CFAccMSSqlMinorVersionTable) tableMinorVersion; table.releasePreparedStatements(); } if ((tablePhone != null) && (tablePhone instanceof CFAccMSSqlPhoneTable)) { CFAccMSSqlPhoneTable table = (CFAccMSSqlPhoneTable) tablePhone; table.releasePreparedStatements(); } if ((tablePhoneTag != null) && (tablePhoneTag instanceof CFAccMSSqlPhoneTagTable)) { CFAccMSSqlPhoneTagTable table = (CFAccMSSqlPhoneTagTable) tablePhoneTag; table.releasePreparedStatements(); } if ((tableProjectBase != null) && (tableProjectBase instanceof CFAccMSSqlProjectBaseTable)) { CFAccMSSqlProjectBaseTable table = (CFAccMSSqlProjectBaseTable) tableProjectBase; table.releasePreparedStatements(); } if ((tableRealProject != null) && (tableRealProject instanceof CFAccMSSqlRealProjectTable)) { CFAccMSSqlRealProjectTable table = (CFAccMSSqlRealProjectTable) tableRealProject; table.releasePreparedStatements(); } if ((tableSecApp != null) && (tableSecApp instanceof CFAccMSSqlSecAppTable)) { CFAccMSSqlSecAppTable table = (CFAccMSSqlSecAppTable) tableSecApp; table.releasePreparedStatements(); } if ((tableSecForm != null) && (tableSecForm instanceof CFAccMSSqlSecFormTable)) { CFAccMSSqlSecFormTable table = (CFAccMSSqlSecFormTable) tableSecForm; table.releasePreparedStatements(); } if ((tableSecGroup != null) && (tableSecGroup instanceof CFAccMSSqlSecGroupTable)) { CFAccMSSqlSecGroupTable table = (CFAccMSSqlSecGroupTable) tableSecGroup; table.releasePreparedStatements(); } if ((tableSecGroupForm != null) && (tableSecGroupForm instanceof CFAccMSSqlSecGroupFormTable)) { CFAccMSSqlSecGroupFormTable table = (CFAccMSSqlSecGroupFormTable) tableSecGroupForm; table.releasePreparedStatements(); } if ((tableSecGroupInclude != null) && (tableSecGroupInclude instanceof CFAccMSSqlSecGroupIncludeTable)) { CFAccMSSqlSecGroupIncludeTable table = (CFAccMSSqlSecGroupIncludeTable) tableSecGroupInclude; table.releasePreparedStatements(); } if ((tableSecGroupMember != null) && (tableSecGroupMember instanceof CFAccMSSqlSecGroupMemberTable)) { CFAccMSSqlSecGroupMemberTable table = (CFAccMSSqlSecGroupMemberTable) tableSecGroupMember; table.releasePreparedStatements(); } if ((tableSecSession != null) && (tableSecSession instanceof CFAccMSSqlSecSessionTable)) { CFAccMSSqlSecSessionTable table = (CFAccMSSqlSecSessionTable) tableSecSession; table.releasePreparedStatements(); } if ((tableSecUser != null) && (tableSecUser instanceof CFAccMSSqlSecUserTable)) { CFAccMSSqlSecUserTable table = (CFAccMSSqlSecUserTable) tableSecUser; table.releasePreparedStatements(); } if ((tableService != null) && (tableService instanceof CFAccMSSqlServiceTable)) { CFAccMSSqlServiceTable table = (CFAccMSSqlServiceTable) tableService; table.releasePreparedStatements(); } if ((tableServiceType != null) && (tableServiceType instanceof CFAccMSSqlServiceTypeTable)) { CFAccMSSqlServiceTypeTable table = (CFAccMSSqlServiceTypeTable) tableServiceType; table.releasePreparedStatements(); } if ((tableSubProject != null) && (tableSubProject instanceof CFAccMSSqlSubProjectTable)) { CFAccMSSqlSubProjectTable table = (CFAccMSSqlSubProjectTable) tableSubProject; table.releasePreparedStatements(); } if ((tableTSecGroup != null) && (tableTSecGroup instanceof CFAccMSSqlTSecGroupTable)) { CFAccMSSqlTSecGroupTable table = (CFAccMSSqlTSecGroupTable) tableTSecGroup; table.releasePreparedStatements(); } if ((tableTSecGroupInclude != null) && (tableTSecGroupInclude instanceof CFAccMSSqlTSecGroupIncludeTable)) { CFAccMSSqlTSecGroupIncludeTable table = (CFAccMSSqlTSecGroupIncludeTable) tableTSecGroupInclude; table.releasePreparedStatements(); } if ((tableTSecGroupMember != null) && (tableTSecGroupMember instanceof CFAccMSSqlTSecGroupMemberTable)) { CFAccMSSqlTSecGroupMemberTable table = (CFAccMSSqlTSecGroupMemberTable) tableTSecGroupMember; table.releasePreparedStatements(); } if ((tableTag != null) && (tableTag instanceof CFAccMSSqlTagTable)) { CFAccMSSqlTagTable table = (CFAccMSSqlTagTable) tableTag; table.releasePreparedStatements(); } if ((tableTenant != null) && (tableTenant instanceof CFAccMSSqlTenantTable)) { CFAccMSSqlTenantTable table = (CFAccMSSqlTenantTable) tableTenant; table.releasePreparedStatements(); } if ((tableTld != null) && (tableTld instanceof CFAccMSSqlTldTable)) { CFAccMSSqlTldTable table = (CFAccMSSqlTldTable) tableTld; table.releasePreparedStatements(); } if ((tableTopDomain != null) && (tableTopDomain instanceof CFAccMSSqlTopDomainTable)) { CFAccMSSqlTopDomainTable table = (CFAccMSSqlTopDomainTable) tableTopDomain; table.releasePreparedStatements(); } if ((tableTopProject != null) && (tableTopProject instanceof CFAccMSSqlTopProjectTable)) { CFAccMSSqlTopProjectTable table = (CFAccMSSqlTopProjectTable) tableTopProject; table.releasePreparedStatements(); } if ((tableURLProtocol != null) && (tableURLProtocol instanceof CFAccMSSqlURLProtocolTable)) { CFAccMSSqlURLProtocolTable table = (CFAccMSSqlURLProtocolTable) tableURLProtocol; table.releasePreparedStatements(); } if ((tableVersion != null) && (tableVersion instanceof CFAccMSSqlVersionTable)) { CFAccMSSqlVersionTable table = (CFAccMSSqlVersionTable) tableVersion; table.releasePreparedStatements(); } } 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(CFAccMSSqlSchema.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 ("'Y'"); } else { return ("'N'"); } } } public static String getBoolString(boolean val) { if (val) { return ("'Y'"); } else { return ("'N'"); } } 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(BigDecimal 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(CFAccMSSqlSchema.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(CFAccMSSqlSchema.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(CFAccMSSqlSchema.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(CFAccMSSqlSchema.class, "getNullableUInt32", e); } } public static BigDecimal getNullableUInt64(ResultSet reader, int colidx) { try { String strval = reader.getString(colidx); if (reader.wasNull() || (strval == null) || (strval.length() <= 0)) { return (null); } else { BigDecimal retval = new BigDecimal(strval); return (retval); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAccMSSqlSchema.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(CFAccMSSqlSchema.class, "getNullableByte", e); } } public static String getQuotedDateString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); Calendar db = CFLibDbUtil.getDbServerCalendar(val); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append("'"); fmt.close(); return (buff.toString()); } } public static String getQuotedTimeString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); Calendar db = CFLibDbUtil.getDbServerCalendar(val); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } } public static String getQuotedTimestampString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); Calendar db = CFLibDbUtil.getDbServerCalendar(val); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } } public static String getQuotedTZDateString(Calendar val) { if (val == null) { return ("null"); } else { Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } } public static String getQuotedTZTimeString(Calendar val) { if (val == null) { return ("null"); } else { Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } } public static String getQuotedTZTimestampString(Calendar val) { if (val == null) { return ("null"); } else { Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } } public static String getDateString(Calendar val) { if (val == null) { return ("null"); } else { Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); fmt.close(); return (buff.toString()); } } public static String getTimeString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); Calendar db = CFLibDbUtil.getDbServerCalendar(val); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } } public static String getTimestampString(Calendar val) { if (val == null) { return ("null"); } else { StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); Calendar db = CFLibDbUtil.getDbServerCalendar(val); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } } public static String getTZDateString(Calendar val) { if (val == null) { return ("null"); } else { Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } } public static String getTZTimeString(Calendar val) { if (val == null) { return ("null"); } else { Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } } public static String getTZTimestampString(Calendar val) { if (val == null) { return ("null"); } else { Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); fmt.close(); 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.length() != 8) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertDateString", "Value must be in YYYYMMDD format, \"" + val + "\" is invalid"); } 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) >= '0') && (val.charAt(4) <= '1')) && ((val.charAt(5) >= '0') && (val.charAt(5) <= '9')) && ((val.charAt(6) >= '0') && (val.charAt(6) <= '3')) && ((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 year = Integer.parseInt(val.substring(0, 4)); int month = Integer.parseInt(val.substring(4, 6)); int day = Integer.parseInt(val.substring(6, 8)); Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone()); retval.set(Calendar.YEAR, year); retval.set(Calendar.MONTH, month - 1); retval.set(Calendar.DAY_OF_MONTH, day); retval.set(Calendar.HOUR_OF_DAY, 0); retval.set(Calendar.MINUTE, 0); retval.set(Calendar.SECOND, 0); Calendar local = new GregorianCalendar(); local.setTimeInMillis(retval.getTimeInMillis()); return (local); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertDateString", "Value must be in YYYYMMDD format, \"" + val + "\" is invalid"); } } public static Calendar convertTimeString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 8) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertTimeString", "Value must be in HH24:MI:SS format, \"" + val + "\" is invalid"); } 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)); Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone()); retval.set(Calendar.YEAR, 2000); retval.set(Calendar.MONTH, 0); retval.set(Calendar.DAY_OF_MONTH, 1); retval.set(Calendar.HOUR_OF_DAY, hour); retval.set(Calendar.MINUTE, minute); retval.set(Calendar.SECOND, second); Calendar local = new GregorianCalendar(); local.setTimeInMillis(retval.getTimeInMillis()); return (local); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertTimeString", "Value must be in HH24:MI:SS format \"" + val + "\" is invalid"); } } public static Calendar convertTimestampString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 19) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertTimestampString", "Value must be in YYYY-MM-DD HH24:MI:SS format \"" + val + "\" is invalid"); } 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)); Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone()); retval.set(Calendar.YEAR, year); retval.set(Calendar.MONTH, month - 1); retval.set(Calendar.DAY_OF_MONTH, day); retval.set(Calendar.HOUR_OF_DAY, hour); retval.set(Calendar.MINUTE, minute); retval.set(Calendar.SECOND, second); Calendar local = new GregorianCalendar(); local.setTimeInMillis(retval.getTimeInMillis()); return (local); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertTimestampString", "Value must be in YYYY-MM-DD HH24:MI:SS format \"" + val + "\" is invalid"); } } public static Calendar convertTZDateString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 19) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertTZDateString", "Value must be in YYYY-MM-DD HH24:MI:SS format \"" + val + "\" is invalid"); } 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)); Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone()); retval.set(Calendar.YEAR, year); retval.set(Calendar.MONTH, month - 1); retval.set(Calendar.DAY_OF_MONTH, day); retval.set(Calendar.HOUR_OF_DAY, hour); retval.set(Calendar.MINUTE, minute); retval.set(Calendar.SECOND, second); Calendar utc = CFLibDbUtil.getUTCCalendar(retval); return (utc); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertTZDateString", "Value must be in YYYY-MM-DD HH24:MI:SS format \"" + val + "\" is invalid"); } } public static Calendar convertTZTimeString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 19) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertTZTimeString", "Value must be in YYYY-MM-DD HH24.MI.SS format \"" + val + "\" is invalid"); } 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)); Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone()); retval.set(Calendar.YEAR, year); retval.set(Calendar.MONTH, month - 1); retval.set(Calendar.DAY_OF_MONTH, day); retval.set(Calendar.HOUR_OF_DAY, hour); retval.set(Calendar.MINUTE, minute); retval.set(Calendar.SECOND, second); Calendar utc = CFLibDbUtil.getUTCCalendar(retval); return (utc); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertTZTimeString", "Value must be in YYYY-MM-DD HH24:MI:SS format \"" + val + "\" is invalid"); } } public static Calendar convertTZTimestampString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 19) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertTZTimestampString", "Value must be in YYYY-MM-DD-HH24.MI.SS format \"" + val + "\" is invalid"); } 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)); Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone()); retval.set(Calendar.YEAR, year); retval.set(Calendar.MONTH, month - 1); retval.set(Calendar.DAY_OF_MONTH, day); retval.set(Calendar.HOUR_OF_DAY, hour); retval.set(Calendar.MINUTE, minute); retval.set(Calendar.SECOND, second); Calendar utc = CFLibDbUtil.getUTCCalendar(retval); return (utc); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAccMSSqlSchema.class, "convertTZTimestampString", "Value must be in YYYY-MM-DD HH24:MI:SS format \"" + val + "\" is invalid"); } } public static UUID convertUuidString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else { return (UUID.fromString(val)); } } }