Java tutorial
// Description: Java 7 DB/2 LUW 10.5 Jdbc DbIO implementation for SecSession. /* * CF Customer Relations Management model * * Copyright (c) 2014 Mark Sobkow * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * *********************************************************************** * * Code manufactured by MSS Code Factory */ package net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW; import java.math.*; import java.sql.*; import java.text.*; import java.util.*; import net.sourceforge.msscodefactory.cflib.v2_1.CFLib.*; import org.apache.commons.codec.binary.Base64; import net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrm.*; /* * CFCrmDb2LUWSecSessionTable DB/2 LUW 10.5 Jdbc DbIO implementation * for SecSession. */ public class CFCrmDb2LUWSecSessionTable implements ICFCrmSecSessionTable { private CFCrmDb2LUWSchema schema; protected PreparedStatement stmtReadBuffByPKey = null; protected PreparedStatement stmtLockBuffByPKey = null; protected PreparedStatement stmtCreateByPKey = null; protected PreparedStatement stmtUpdateByPKey = null; protected PreparedStatement stmtDeleteByPKey = null; protected PreparedStatement stmtReadAllBuff = null; protected PreparedStatement stmtReadBuffByIdIdx = null; protected PreparedStatement stmtReadBuffBySecUserIdx = null; protected PreparedStatement stmtReadBuffBySecDevIdx = null; protected PreparedStatement stmtReadBuffByStartIdx = null; protected PreparedStatement stmtReadBuffByFinishIdx = null; protected PreparedStatement stmtReadBuffBySecProxyIdx = null; protected PreparedStatement stmtDeleteByIdIdx = null; protected PreparedStatement stmtDeleteBySecUserIdx = null; protected PreparedStatement stmtDeleteBySecDevIdx = null; protected PreparedStatement stmtDeleteByStartIdx = null; protected PreparedStatement stmtDeleteByFinishIdx = null; protected PreparedStatement stmtDeleteBySecProxyIdx = null; public CFCrmDb2LUWSecSessionTable(CFCrmDb2LUWSchema argSchema) { schema = argSchema; } public void createSecSession(CFCrmAuthorization Authorization, CFCrmSecSessionBuff Buff) { final String S_ProcName = "createSecSession"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { UUID SecUserId = Buff.getRequiredSecUserId(); String SecDevName = Buff.getOptionalSecDevName(); Calendar Start = Buff.getRequiredStart(); Calendar Finish = Buff.getOptionalFinish(); UUID SecProxyId = Buff.getOptionalSecProxyId(); UUID SecSessionId = UUID.randomUUID(); Connection cnx = schema.getCnx(); final String sql = "CALL sp_create_secsess( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "TIMESTAMP_FORMAT( ?, 'YYYY-MM-DD-HH24.MI.SS' )" + ", " + "TIMESTAMP_FORMAT( ?, 'YYYY-MM-DD-HH24.MI.SS' )" + ", " + "?" + " )"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, "SESS"); stmtCreateByPKey.setString(argIdx++, SecSessionId.toString()); stmtCreateByPKey.setString(argIdx++, SecUserId.toString()); if (SecDevName != null) { stmtCreateByPKey.setString(argIdx++, SecDevName); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtCreateByPKey.setString(argIdx++, CFCrmDb2LUWSchema.getTimestampString(Start)); if (Finish != null) { stmtCreateByPKey.setString(argIdx++, CFCrmDb2LUWSchema.getTimestampString(Finish)); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } if (SecProxyId != null) { stmtCreateByPKey.setString(argIdx++, SecProxyId.toString()); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtCreateByPKey.executeQuery(); if (resultSet.next()) { CFCrmSecSessionBuff createdBuff = unpackSecSessionResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredSecSessionId(createdBuff.getRequiredSecSessionId()); Buff.setRequiredSecUserId(createdBuff.getRequiredSecUserId()); Buff.setOptionalSecDevName(createdBuff.getOptionalSecDevName()); Buff.setRequiredStart(createdBuff.getRequiredStart()); Buff.setOptionalFinish(createdBuff.getOptionalFinish()); Buff.setOptionalSecProxyId(createdBuff.getOptionalSecProxyId()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } protected static String S_sqlSelectSecSessionDistinctClassCode = null; public String getSqlSelectSecSessionDistinctClassCode() { if (S_sqlSelectSecSessionDistinctClassCode == null) { S_sqlSelectSecSessionDistinctClassCode = "SELECT " + "DISTINCT sess.ClassCode " + "FROM " + schema.getLowerDbSchemaName() + ".SecSess AS sess "; } return (S_sqlSelectSecSessionDistinctClassCode); } protected static String S_sqlSelectSecSessionBuff = null; public String getSqlSelectSecSessionBuff() { if (S_sqlSelectSecSessionBuff == null) { S_sqlSelectSecSessionBuff = "SELECT " + "sess.SecSessionId, " + "sess.SecUserId, " + "sess.SecDevName, " + "TO_CHAR( sess.start_ts, 'YYYY-MM-DD-HH24.MI.SS' ) AS start_ts, " + "TO_CHAR( sess.finish_ts, 'YYYY-MM-DD-HH24.MI.SS' ) AS finish_ts, " + "sess.SecProxyId, " + "sess.Revision " + "FROM " + schema.getLowerDbSchemaName() + ".SecSess AS sess "; } return (S_sqlSelectSecSessionBuff); } protected CFCrmSecSessionBuff unpackSecSessionResultSetToBuff(ResultSet resultSet) throws SQLException { final String S_ProcName = "unpackSecSessionResultSetToBuff"; int idxcol = 1; CFCrmSecSessionBuff buff = schema.getFactorySecSession().newBuff(); buff.setRequiredSecSessionId(CFCrmDb2LUWSchema.convertUuidString(resultSet.getString(idxcol))); idxcol++; buff.setRequiredSecUserId(CFCrmDb2LUWSchema.convertUuidString(resultSet.getString(idxcol))); idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalSecDevName(null); } else { buff.setOptionalSecDevName(colVal); } } idxcol++; buff.setRequiredStart(CFCrmDb2LUWSchema.convertTimestampString(resultSet.getString(idxcol))); idxcol++; { Calendar colVal = CFCrmDb2LUWSchema.convertTimestampString(resultSet.getString(idxcol)); if (resultSet.wasNull()) { buff.setOptionalFinish(null); } else { buff.setOptionalFinish(colVal); } } idxcol++; { UUID colVal = CFCrmDb2LUWSchema.convertUuidString(resultSet.getString(idxcol)); if (resultSet.wasNull()) { buff.setOptionalSecProxyId(null); } else { buff.setOptionalSecProxyId(colVal); } } idxcol++; buff.setRequiredRevision(resultSet.getInt(idxcol)); return (buff); } public CFCrmSecSessionBuff readDerived(CFCrmAuthorization Authorization, CFCrmSecSessionPKey PKey) { final String S_ProcName = "readDerived"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFCrmSecSessionBuff buff; buff = readBuff(Authorization, PKey); return (buff); } public CFCrmSecSessionBuff lockDerived(CFCrmAuthorization Authorization, CFCrmSecSessionPKey PKey) { final String S_ProcName = "lockDerived"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFCrmSecSessionBuff buff; buff = lockBuff(Authorization, PKey); return (buff); } public CFCrmSecSessionBuff[] readAllDerived(CFCrmAuthorization Authorization) { final String S_ProcName = "readAllDerived"; CFCrmSecSessionBuff[] buffArray; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } buffArray = readAllBuff(Authorization); return (buffArray); } public CFCrmSecSessionBuff readDerivedByIdIdx(CFCrmAuthorization Authorization, UUID SecSessionId) { final String S_ProcName = "CFCrmDb2LUWSecSessionTable.readDerivedByIdIdx() "; CFCrmSecSessionBuff buff; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } buff = readBuffByIdIdx(Authorization, SecSessionId); return (buff); } public CFCrmSecSessionBuff[] readDerivedBySecUserIdx(CFCrmAuthorization Authorization, UUID SecUserId) { final String S_ProcName = "readDerivedBySecUserIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFCrmSecSessionBuff[] buffList = readBuffBySecUserIdx(Authorization, SecUserId); return (buffList); } public CFCrmSecSessionBuff[] readDerivedBySecDevIdx(CFCrmAuthorization Authorization, UUID SecUserId, String SecDevName) { final String S_ProcName = "readDerivedBySecDevIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFCrmSecSessionBuff[] buffList = readBuffBySecDevIdx(Authorization, SecUserId, SecDevName); return (buffList); } public CFCrmSecSessionBuff readDerivedByStartIdx(CFCrmAuthorization Authorization, UUID SecUserId, Calendar Start) { final String S_ProcName = "CFCrmDb2LUWSecSessionTable.readDerivedByStartIdx() "; CFCrmSecSessionBuff buff; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } buff = readBuffByStartIdx(Authorization, SecUserId, Start); return (buff); } public CFCrmSecSessionBuff[] readDerivedByFinishIdx(CFCrmAuthorization Authorization, UUID SecUserId, Calendar Finish) { final String S_ProcName = "readDerivedByFinishIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFCrmSecSessionBuff[] buffList = readBuffByFinishIdx(Authorization, SecUserId, Finish); return (buffList); } public CFCrmSecSessionBuff[] readDerivedBySecProxyIdx(CFCrmAuthorization Authorization, UUID SecProxyId) { final String S_ProcName = "readDerivedBySecProxyIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFCrmSecSessionBuff[] buffList = readBuffBySecProxyIdx(Authorization, SecProxyId); return (buffList); } public CFCrmSecSessionBuff readBuff(CFCrmAuthorization Authorization, CFCrmSecSessionPKey PKey) { final String S_ProcName = "readBuff"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); UUID SecSessionId = PKey.getRequiredSecSessionId(); final String sql = "CALL sp_read_secsess( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtReadBuffByPKey == null) { stmtReadBuffByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffByPKey.setString(argIdx++, SecSessionId.toString()); resultSet = stmtReadBuffByPKey.executeQuery(); if (resultSet.next()) { CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } return (buff); } else { return (null); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public CFCrmSecSessionBuff lockBuff(CFCrmAuthorization Authorization, CFCrmSecSessionPKey PKey) { final String S_ProcName = "lockBuff"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); UUID SecSessionId = PKey.getRequiredSecSessionId(); final String sql = "CALL sp_lock_secsess( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtLockBuffByPKey == null) { stmtLockBuffByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtLockBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtLockBuffByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtLockBuffByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtLockBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtLockBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtLockBuffByPKey.setString(argIdx++, SecSessionId.toString()); resultSet = stmtLockBuffByPKey.executeQuery(); if (resultSet.next()) { CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } return (buff); } else { return (null); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public CFCrmSecSessionBuff[] readAllBuff(CFCrmAuthorization Authorization) { final String S_ProcName = "readAllBuff"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_read_secsess_all( ?, ?, ?, ?, ? )"; if (stmtReadAllBuff == null) { stmtReadAllBuff = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadAllBuff.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadAllBuff.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); resultSet = stmtReadAllBuff.executeQuery(); List<CFCrmSecSessionBuff> buffList = new LinkedList<CFCrmSecSessionBuff>(); while (resultSet.next()) { CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFCrmSecSessionBuff[] retBuff = new CFCrmSecSessionBuff[buffList.size()]; Iterator<CFCrmSecSessionBuff> iter = buffList.iterator(); while (iter.hasNext()) { retBuff[idx++] = iter.next(); } return (retBuff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public CFCrmSecSessionBuff readBuffByIdIdx(CFCrmAuthorization Authorization, UUID SecSessionId) { final String S_ProcName = "readBuffByIdIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_read_secsess_by_ididx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtReadBuffByIdIdx == null) { stmtReadBuffByIdIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffByIdIdx.setString(argIdx++, SecSessionId.toString()); resultSet = stmtReadBuffByIdIdx.executeQuery(); if (resultSet.next()) { CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } return (buff); } else { return (null); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public CFCrmSecSessionBuff[] readBuffBySecUserIdx(CFCrmAuthorization Authorization, UUID SecUserId) { final String S_ProcName = "readBuffBySecUserIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_read_secsess_by_secuseridx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtReadBuffBySecUserIdx == null) { stmtReadBuffBySecUserIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffBySecUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffBySecUserIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffBySecUserIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffBySecUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffBySecUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffBySecUserIdx.setString(argIdx++, SecUserId.toString()); resultSet = stmtReadBuffBySecUserIdx.executeQuery(); List<CFCrmSecSessionBuff> buffList = new LinkedList<CFCrmSecSessionBuff>(); while (resultSet.next()) { CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFCrmSecSessionBuff[] retBuff = new CFCrmSecSessionBuff[buffList.size()]; Iterator<CFCrmSecSessionBuff> iter = buffList.iterator(); while (iter.hasNext()) { retBuff[idx++] = iter.next(); } return (retBuff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public CFCrmSecSessionBuff[] readBuffBySecDevIdx(CFCrmAuthorization Authorization, UUID SecUserId, String SecDevName) { final String S_ProcName = "readBuffBySecDevIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_read_secsess_by_secdevidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )"; if (stmtReadBuffBySecDevIdx == null) { stmtReadBuffBySecDevIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffBySecDevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffBySecDevIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffBySecDevIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffBySecDevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffBySecDevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffBySecDevIdx.setString(argIdx++, SecUserId.toString()); if (SecDevName != null) { stmtReadBuffBySecDevIdx.setString(argIdx++, SecDevName); } else { stmtReadBuffBySecDevIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtReadBuffBySecDevIdx.executeQuery(); List<CFCrmSecSessionBuff> buffList = new LinkedList<CFCrmSecSessionBuff>(); while (resultSet.next()) { CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFCrmSecSessionBuff[] retBuff = new CFCrmSecSessionBuff[buffList.size()]; Iterator<CFCrmSecSessionBuff> iter = buffList.iterator(); while (iter.hasNext()) { retBuff[idx++] = iter.next(); } return (retBuff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public CFCrmSecSessionBuff readBuffByStartIdx(CFCrmAuthorization Authorization, UUID SecUserId, Calendar Start) { final String S_ProcName = "readBuffByStartIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_read_secsess_by_startidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "TIMESTAMP_FORMAT( ?, 'YYYY-MM-DD-HH24.MI.SS' )" + " )"; if (stmtReadBuffByStartIdx == null) { stmtReadBuffByStartIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByStartIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByStartIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffByStartIdx.setString(argIdx++, SecUserId.toString()); stmtReadBuffByStartIdx.setString(argIdx++, CFCrmDb2LUWSchema.getTimestampString(Start)); resultSet = stmtReadBuffByStartIdx.executeQuery(); if (resultSet.next()) { CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } return (buff); } else { return (null); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public CFCrmSecSessionBuff[] readBuffByFinishIdx(CFCrmAuthorization Authorization, UUID SecUserId, Calendar Finish) { final String S_ProcName = "readBuffByFinishIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_read_secsess_by_finishidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "TIMESTAMP_FORMAT( ?, 'YYYY-MM-DD-HH24.MI.SS' )" + " )"; if (stmtReadBuffByFinishIdx == null) { stmtReadBuffByFinishIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByFinishIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByFinishIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByFinishIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByFinishIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByFinishIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffByFinishIdx.setString(argIdx++, SecUserId.toString()); if (Finish != null) { stmtReadBuffByFinishIdx.setString(argIdx++, CFCrmDb2LUWSchema.getTimestampString(Finish)); } else { stmtReadBuffByFinishIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtReadBuffByFinishIdx.executeQuery(); List<CFCrmSecSessionBuff> buffList = new LinkedList<CFCrmSecSessionBuff>(); while (resultSet.next()) { CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFCrmSecSessionBuff[] retBuff = new CFCrmSecSessionBuff[buffList.size()]; Iterator<CFCrmSecSessionBuff> iter = buffList.iterator(); while (iter.hasNext()) { retBuff[idx++] = iter.next(); } return (retBuff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public CFCrmSecSessionBuff[] readBuffBySecProxyIdx(CFCrmAuthorization Authorization, UUID SecProxyId) { final String S_ProcName = "readBuffBySecProxyIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_read_secsess_by_secproxyidx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtReadBuffBySecProxyIdx == null) { stmtReadBuffBySecProxyIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffBySecProxyIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffBySecProxyIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffBySecProxyIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffBySecProxyIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffBySecProxyIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); if (SecProxyId != null) { stmtReadBuffBySecProxyIdx.setString(argIdx++, SecProxyId.toString()); } else { stmtReadBuffBySecProxyIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtReadBuffBySecProxyIdx.executeQuery(); List<CFCrmSecSessionBuff> buffList = new LinkedList<CFCrmSecSessionBuff>(); while (resultSet.next()) { CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFCrmSecSessionBuff[] retBuff = new CFCrmSecSessionBuff[buffList.size()]; Iterator<CFCrmSecSessionBuff> iter = buffList.iterator(); while (iter.hasNext()) { retBuff[idx++] = iter.next(); } return (retBuff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public void updateSecSession(CFCrmAuthorization Authorization, CFCrmSecSessionBuff Buff) { final String S_ProcName = "updateSecSession"; if ("SESS".equals(Buff.getClassCode()) && (!schema.isSystemUser(Authorization))) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Permission denied -- only system user can modify SecSession data"); } ResultSet resultSet = null; try { UUID SecSessionId = Buff.getRequiredSecSessionId(); UUID SecUserId = Buff.getRequiredSecUserId(); String SecDevName = Buff.getOptionalSecDevName(); Calendar Start = Buff.getRequiredStart(); Calendar Finish = Buff.getOptionalFinish(); UUID SecProxyId = Buff.getOptionalSecProxyId(); int Revision = Buff.getRequiredRevision(); Connection cnx = schema.getCnx(); final String sql = "CALL sp_update_secsess( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "TIMESTAMP_FORMAT( ?, 'YYYY-MM-DD-HH24.MI.SS' )" + ", " + "TIMESTAMP_FORMAT( ?, 'YYYY-MM-DD-HH24.MI.SS' )" + ", " + "?" + ", " + "?" + " )"; if (stmtUpdateByPKey == null) { stmtUpdateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtUpdateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtUpdateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtUpdateByPKey.setString(argIdx++, "SESS"); stmtUpdateByPKey.setString(argIdx++, SecSessionId.toString()); stmtUpdateByPKey.setString(argIdx++, SecUserId.toString()); if (SecDevName != null) { stmtUpdateByPKey.setString(argIdx++, SecDevName); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtUpdateByPKey.setString(argIdx++, CFCrmDb2LUWSchema.getTimestampString(Start)); if (Finish != null) { stmtUpdateByPKey.setString(argIdx++, CFCrmDb2LUWSchema.getTimestampString(Finish)); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } if (SecProxyId != null) { stmtUpdateByPKey.setString(argIdx++, SecProxyId.toString()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtUpdateByPKey.setInt(argIdx++, Revision); resultSet = stmtUpdateByPKey.executeQuery(); if (resultSet.next()) { CFCrmSecSessionBuff updatedBuff = unpackSecSessionResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredSecUserId(updatedBuff.getRequiredSecUserId()); Buff.setOptionalSecDevName(updatedBuff.getOptionalSecDevName()); Buff.setRequiredStart(updatedBuff.getRequiredStart()); Buff.setOptionalFinish(updatedBuff.getOptionalFinish()); Buff.setOptionalSecProxyId(updatedBuff.getOptionalSecProxyId()); Buff.setRequiredRevision(updatedBuff.getRequiredRevision()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public void deleteSecSession(CFCrmAuthorization Authorization, CFCrmSecSessionBuff Buff) { final String S_ProcName = "deleteSecSession"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); UUID SecSessionId = Buff.getRequiredSecSessionId(); final String sql = "CALL sp_delete_secsess( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )"; if (stmtDeleteByPKey == null) { stmtDeleteByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByPKey.setString(argIdx++, SecSessionId.toString()); stmtDeleteByPKey.setInt(argIdx++, Buff.getRequiredRevision()); ; resultSet = stmtDeleteByPKey.executeQuery(); if (resultSet.next()) { int deleteFlag = 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"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public void deleteSecSessionByIdIdx(CFCrmAuthorization Authorization, UUID argSecSessionId) { final String S_ProcName = "deleteSecSessionByIdIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_delete_secsess_by_ididx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtDeleteByIdIdx == null) { stmtDeleteByIdIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByIdIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByIdIdx.setString(argIdx++, argSecSessionId.toString()); resultSet = stmtDeleteByIdIdx.executeQuery(); if (resultSet.next()) { int deleteFlag = 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"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public void deleteSecSessionByIdIdx(CFCrmAuthorization Authorization, CFCrmSecSessionPKey argKey) { deleteSecSessionByIdIdx(Authorization, argKey.getRequiredSecSessionId()); } public void deleteSecSessionBySecUserIdx(CFCrmAuthorization Authorization, UUID argSecUserId) { final String S_ProcName = "deleteSecSessionBySecUserIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_delete_secsess_by_secuseridx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtDeleteBySecUserIdx == null) { stmtDeleteBySecUserIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteBySecUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteBySecUserIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteBySecUserIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteBySecUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteBySecUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteBySecUserIdx.setString(argIdx++, argSecUserId.toString()); resultSet = stmtDeleteBySecUserIdx.executeQuery(); if (resultSet.next()) { int deleteFlag = 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"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public void deleteSecSessionBySecUserIdx(CFCrmAuthorization Authorization, CFCrmSecSessionBySecUserIdxKey argKey) { deleteSecSessionBySecUserIdx(Authorization, argKey.getRequiredSecUserId()); } public void deleteSecSessionBySecDevIdx(CFCrmAuthorization Authorization, UUID argSecUserId, String argSecDevName) { final String S_ProcName = "deleteSecSessionBySecDevIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_delete_secsess_by_secdevidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )"; if (stmtDeleteBySecDevIdx == null) { stmtDeleteBySecDevIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteBySecDevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteBySecDevIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteBySecDevIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteBySecDevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteBySecDevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteBySecDevIdx.setString(argIdx++, argSecUserId.toString()); if (argSecDevName != null) { stmtDeleteBySecDevIdx.setString(argIdx++, argSecDevName); } else { stmtDeleteBySecDevIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtDeleteBySecDevIdx.executeQuery(); if (resultSet.next()) { int deleteFlag = 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"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public void deleteSecSessionBySecDevIdx(CFCrmAuthorization Authorization, CFCrmSecSessionBySecDevIdxKey argKey) { deleteSecSessionBySecDevIdx(Authorization, argKey.getRequiredSecUserId(), argKey.getOptionalSecDevName()); } public void deleteSecSessionByStartIdx(CFCrmAuthorization Authorization, UUID argSecUserId, Calendar argStart) { final String S_ProcName = "deleteSecSessionByStartIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_delete_secsess_by_startidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "TIMESTAMP_FORMAT( ?, 'YYYY-MM-DD-HH24.MI.SS' )" + " )"; if (stmtDeleteByStartIdx == null) { stmtDeleteByStartIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByStartIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByStartIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByStartIdx.setString(argIdx++, argSecUserId.toString()); stmtDeleteByStartIdx.setString(argIdx++, CFCrmDb2LUWSchema.getTimestampString(argStart)); resultSet = stmtDeleteByStartIdx.executeQuery(); if (resultSet.next()) { int deleteFlag = 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"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public void deleteSecSessionByStartIdx(CFCrmAuthorization Authorization, CFCrmSecSessionByStartIdxKey argKey) { deleteSecSessionByStartIdx(Authorization, argKey.getRequiredSecUserId(), argKey.getRequiredStart()); } public void deleteSecSessionByFinishIdx(CFCrmAuthorization Authorization, UUID argSecUserId, Calendar argFinish) { final String S_ProcName = "deleteSecSessionByFinishIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_delete_secsess_by_finishidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "TIMESTAMP_FORMAT( ?, 'YYYY-MM-DD-HH24.MI.SS' )" + " )"; if (stmtDeleteByFinishIdx == null) { stmtDeleteByFinishIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByFinishIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByFinishIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByFinishIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByFinishIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByFinishIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByFinishIdx.setString(argIdx++, argSecUserId.toString()); if (argFinish != null) { stmtDeleteByFinishIdx.setString(argIdx++, CFCrmDb2LUWSchema.getTimestampString(argFinish)); } else { stmtDeleteByFinishIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtDeleteByFinishIdx.executeQuery(); if (resultSet.next()) { int deleteFlag = 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"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public void deleteSecSessionByFinishIdx(CFCrmAuthorization Authorization, CFCrmSecSessionByFinishIdxKey argKey) { deleteSecSessionByFinishIdx(Authorization, argKey.getRequiredSecUserId(), argKey.getOptionalFinish()); } public void deleteSecSessionBySecProxyIdx(CFCrmAuthorization Authorization, UUID argSecProxyId) { final String S_ProcName = "deleteSecSessionBySecProxyIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); final String sql = "CALL sp_delete_secsess_by_secproxyidx( ?, ?, ?, ?, ?" + ", " + "?" + " )"; if (stmtDeleteBySecProxyIdx == null) { stmtDeleteBySecProxyIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteBySecProxyIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteBySecProxyIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteBySecProxyIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteBySecProxyIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteBySecProxyIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); if (argSecProxyId != null) { stmtDeleteBySecProxyIdx.setString(argIdx++, argSecProxyId.toString()); } else { stmtDeleteBySecProxyIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtDeleteBySecProxyIdx.executeQuery(); if (resultSet.next()) { int deleteFlag = 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"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } public void deleteSecSessionBySecProxyIdx(CFCrmAuthorization Authorization, CFCrmSecSessionBySecProxyIdxKey argKey) { deleteSecSessionBySecProxyIdx(Authorization, argKey.getOptionalSecProxyId()); } public CFCrmCursor openSecSessionCursorAll(CFCrmAuthorization Authorization) { String sql = getSqlSelectSecSessionBuff() + "ORDER BY " + "sess.SecSessionId ASC"; CFCrmCursor cursor = new CFCrmDb2LUWCursor(Authorization, schema, sql); return (cursor); } public CFCrmCursor openSecSessionCursorBySecUserIdx(CFCrmAuthorization Authorization, UUID SecUserId) { String sql = getSqlSelectSecSessionBuff() + "WHERE " + "sess.SecUserId = '" + SecUserId.toString() + "' " + "ORDER BY " + "sess.SecSessionId ASC"; CFCrmCursor cursor = new CFCrmDb2LUWCursor(Authorization, schema, sql); return (cursor); } public CFCrmCursor openSecSessionCursorBySecDevIdx(CFCrmAuthorization Authorization, UUID SecUserId, String SecDevName) { String sql = getSqlSelectSecSessionBuff() + "WHERE " + "sess.SecUserId = '" + SecUserId.toString() + "' " + "AND " + ((SecDevName == null) ? "sess.SecDevName is null " : "sess.SecDevName = " + CFCrmDb2LUWSchema.getQuotedString(SecDevName) + " ") + "ORDER BY " + "sess.SecSessionId ASC"; CFCrmCursor cursor = new CFCrmDb2LUWCursor(Authorization, schema, sql); return (cursor); } public CFCrmCursor openSecSessionCursorByFinishIdx(CFCrmAuthorization Authorization, UUID SecUserId, Calendar Finish) { String sql = getSqlSelectSecSessionBuff() + "WHERE " + "sess.SecUserId = '" + SecUserId.toString() + "' " + "AND " + ((Finish == null) ? "sess.finish_ts is null " : "sess.finish_ts = TIMESTAMP_FORMAT( " + CFCrmDb2LUWSchema.getTimestampString(Finish) + ", 'YYYY-MM-DD-HH24.MI.SS' ) ") + "ORDER BY " + "sess.SecSessionId ASC"; CFCrmCursor cursor = new CFCrmDb2LUWCursor(Authorization, schema, sql); return (cursor); } public CFCrmCursor openSecSessionCursorBySecProxyIdx(CFCrmAuthorization Authorization, UUID SecProxyId) { String sql = getSqlSelectSecSessionBuff() + "WHERE " + ((SecProxyId == null) ? "sess.SecProxyId is null " : "sess.SecProxyId = '" + SecProxyId.toString() + "' ") + "ORDER BY " + "sess.SecSessionId ASC"; CFCrmCursor cursor = new CFCrmDb2LUWCursor(Authorization, schema, sql); return (cursor); } public void closeSecSessionCursor(CFCrmCursor Cursor) { try { Cursor.getResultSet().close(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "closeSecSessionCursor", e); } } public CFCrmSecSessionBuff nextSecSessionCursor(CFCrmCursor Cursor) { final String S_ProcName = "nextSecSessionCursor"; try { ResultSet resultSet = Cursor.getResultSet(); if (!resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "No more results available"); } CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); return (buff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } } public CFCrmSecSessionBuff prevSecSessionCursor(CFCrmCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; CFCrmSecSessionBuff buff = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { buff = nextSecSessionCursor(Cursor); } return (buff); } public CFCrmSecSessionBuff firstSecSessionCursor(CFCrmCursor Cursor) { int targetRowIdx = 1; CFCrmSecSessionBuff buff = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { buff = nextSecSessionCursor(Cursor); } return (buff); } public CFCrmSecSessionBuff lastSecSessionCursor(CFCrmCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastSecSessionCursor"); } public CFCrmSecSessionBuff nthSecSessionCursor(CFCrmCursor Cursor, int Idx) { int targetRowIdx = Idx; CFCrmSecSessionBuff buff = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { buff = nextSecSessionCursor(Cursor); } return (buff); } /** * 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"; S_sqlSelectSecSessionDistinctClassCode = null; S_sqlSelectSecSessionBuff = null; if (stmtReadBuffByPKey != null) { try { stmtReadBuffByPKey.close(); } catch (SQLException e) { } stmtReadBuffByPKey = null; } if (stmtReadAllBuff != null) { try { stmtReadAllBuff.close(); } catch (SQLException e) { } stmtReadAllBuff = null; } if (stmtLockBuffByPKey != null) { try { stmtLockBuffByPKey.close(); } catch (SQLException e) { } stmtLockBuffByPKey = null; } if (stmtCreateByPKey != null) { try { stmtCreateByPKey.close(); } catch (SQLException e) { } stmtCreateByPKey = null; } if (stmtUpdateByPKey != null) { try { stmtUpdateByPKey.close(); } catch (SQLException e) { } stmtUpdateByPKey = null; } if (stmtDeleteByPKey != null) { try { stmtDeleteByPKey.close(); } catch (SQLException e) { } stmtDeleteByPKey = null; } if (stmtDeleteByIdIdx != null) { try { stmtDeleteByIdIdx.close(); } catch (SQLException e) { } stmtDeleteByIdIdx = null; } if (stmtDeleteBySecUserIdx != null) { try { stmtDeleteBySecUserIdx.close(); } catch (SQLException e) { } stmtDeleteBySecUserIdx = null; } if (stmtDeleteBySecDevIdx != null) { try { stmtDeleteBySecDevIdx.close(); } catch (SQLException e) { } stmtDeleteBySecDevIdx = null; } if (stmtDeleteByStartIdx != null) { try { stmtDeleteByStartIdx.close(); } catch (SQLException e) { } stmtDeleteByStartIdx = null; } if (stmtDeleteByFinishIdx != null) { try { stmtDeleteByFinishIdx.close(); } catch (SQLException e) { } stmtDeleteByFinishIdx = null; } if (stmtDeleteBySecProxyIdx != null) { try { stmtDeleteBySecProxyIdx.close(); } catch (SQLException e) { } stmtDeleteBySecProxyIdx = null; } if (stmtReadAllBuff != null) { try { stmtReadAllBuff.close(); } catch (SQLException e) { } stmtReadAllBuff = null; } if (stmtReadBuffByIdIdx != null) { try { stmtReadBuffByIdIdx.close(); } catch (SQLException e) { } stmtReadBuffByIdIdx = null; } if (stmtReadBuffBySecUserIdx != null) { try { stmtReadBuffBySecUserIdx.close(); } catch (SQLException e) { } stmtReadBuffBySecUserIdx = null; } if (stmtReadBuffBySecDevIdx != null) { try { stmtReadBuffBySecDevIdx.close(); } catch (SQLException e) { } stmtReadBuffBySecDevIdx = null; } if (stmtReadBuffByStartIdx != null) { try { stmtReadBuffByStartIdx.close(); } catch (SQLException e) { } stmtReadBuffByStartIdx = null; } if (stmtReadBuffByFinishIdx != null) { try { stmtReadBuffByFinishIdx.close(); } catch (SQLException e) { } stmtReadBuffByFinishIdx = null; } if (stmtReadBuffBySecProxyIdx != null) { try { stmtReadBuffBySecProxyIdx.close(); } catch (SQLException e) { } stmtReadBuffBySecProxyIdx = null; } } }