Java tutorial
// Description: Java 8 DB/2 LUW 10.5 Jdbc DbIO implementation for SecSession. /* * Code Factory Asterisk 11 Configuration Model * * Copyright (c) 2014-2015 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. * */ package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskDb2LUW; import java.math.*; import java.sql.*; import java.text.*; import java.util.*; import org.apache.commons.codec.binary.Base64; import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*; import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*; import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*; import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*; import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*; import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*; import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*; /* * CFAsteriskDb2LUWSecSessionTable DB/2 LUW 10.5 Jdbc DbIO implementation * for SecSession. */ public class CFAsteriskDb2LUWSecSessionTable implements ICFAsteriskSecSessionTable { private CFAsteriskDb2LUWSchema 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 CFAsteriskDb2LUWSecSessionTable(CFAsteriskDb2LUWSchema argSchema) { schema = argSchema; } public void createSecSession(CFSecurityAuthorization Authorization, CFSecuritySecSessionBuff 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++, CFAsteriskDb2LUWSchema.getTimestampString(Start)); if (Finish != null) { stmtCreateByPKey.setString(argIdx++, CFAsteriskDb2LUWSchema.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()) { CFSecuritySecSessionBuff 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 CFSecuritySecSessionBuff unpackSecSessionResultSetToBuff(ResultSet resultSet) throws SQLException { final String S_ProcName = "unpackSecSessionResultSetToBuff"; int idxcol = 1; CFSecuritySecSessionBuff buff = schema.getFactorySecSession().newBuff(); buff.setRequiredSecSessionId(CFAsteriskDb2LUWSchema.convertUuidString(resultSet.getString(idxcol))); idxcol++; buff.setRequiredSecUserId(CFAsteriskDb2LUWSchema.convertUuidString(resultSet.getString(idxcol))); idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalSecDevName(null); } else { buff.setOptionalSecDevName(colVal); } } idxcol++; buff.setRequiredStart(CFAsteriskDb2LUWSchema.convertTimestampString(resultSet.getString(idxcol))); idxcol++; { Calendar colVal = CFAsteriskDb2LUWSchema.convertTimestampString(resultSet.getString(idxcol)); if (resultSet.wasNull()) { buff.setOptionalFinish(null); } else { buff.setOptionalFinish(colVal); } } idxcol++; { UUID colVal = CFAsteriskDb2LUWSchema.convertUuidString(resultSet.getString(idxcol)); if (resultSet.wasNull()) { buff.setOptionalSecProxyId(null); } else { buff.setOptionalSecProxyId(colVal); } } idxcol++; buff.setRequiredRevision(resultSet.getInt(idxcol)); return (buff); } public CFSecuritySecSessionBuff readDerived(CFSecurityAuthorization Authorization, CFSecuritySecSessionPKey PKey) { final String S_ProcName = "readDerived"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFSecuritySecSessionBuff buff; buff = readBuff(Authorization, PKey); return (buff); } public CFSecuritySecSessionBuff lockDerived(CFSecurityAuthorization Authorization, CFSecuritySecSessionPKey PKey) { final String S_ProcName = "lockDerived"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFSecuritySecSessionBuff buff; buff = lockBuff(Authorization, PKey); return (buff); } public CFSecuritySecSessionBuff[] readAllDerived(CFSecurityAuthorization Authorization) { final String S_ProcName = "readAllDerived"; CFSecuritySecSessionBuff[] buffArray; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } buffArray = readAllBuff(Authorization); return (buffArray); } public CFSecuritySecSessionBuff readDerivedByIdIdx(CFSecurityAuthorization Authorization, UUID SecSessionId) { final String S_ProcName = "CFAsteriskDb2LUWSecSessionTable.readDerivedByIdIdx() "; CFSecuritySecSessionBuff buff; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } buff = readBuffByIdIdx(Authorization, SecSessionId); return (buff); } public CFSecuritySecSessionBuff[] readDerivedBySecUserIdx(CFSecurityAuthorization Authorization, UUID SecUserId) { final String S_ProcName = "readDerivedBySecUserIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFSecuritySecSessionBuff[] buffList = readBuffBySecUserIdx(Authorization, SecUserId); return (buffList); } public CFSecuritySecSessionBuff[] readDerivedBySecDevIdx(CFSecurityAuthorization Authorization, UUID SecUserId, String SecDevName) { final String S_ProcName = "readDerivedBySecDevIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFSecuritySecSessionBuff[] buffList = readBuffBySecDevIdx(Authorization, SecUserId, SecDevName); return (buffList); } public CFSecuritySecSessionBuff readDerivedByStartIdx(CFSecurityAuthorization Authorization, UUID SecUserId, Calendar Start) { final String S_ProcName = "CFAsteriskDb2LUWSecSessionTable.readDerivedByStartIdx() "; CFSecuritySecSessionBuff buff; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } buff = readBuffByStartIdx(Authorization, SecUserId, Start); return (buff); } public CFSecuritySecSessionBuff[] readDerivedByFinishIdx(CFSecurityAuthorization Authorization, UUID SecUserId, Calendar Finish) { final String S_ProcName = "readDerivedByFinishIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFSecuritySecSessionBuff[] buffList = readBuffByFinishIdx(Authorization, SecUserId, Finish); return (buffList); } public CFSecuritySecSessionBuff[] readDerivedBySecProxyIdx(CFSecurityAuthorization Authorization, UUID SecProxyId) { final String S_ProcName = "readDerivedBySecProxyIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } CFSecuritySecSessionBuff[] buffList = readBuffBySecProxyIdx(Authorization, SecProxyId); return (buffList); } public CFSecuritySecSessionBuff readBuff(CFSecurityAuthorization Authorization, CFSecuritySecSessionPKey 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()) { CFSecuritySecSessionBuff 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 CFSecuritySecSessionBuff lockBuff(CFSecurityAuthorization Authorization, CFSecuritySecSessionPKey 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()) { CFSecuritySecSessionBuff 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 CFSecuritySecSessionBuff[] readAllBuff(CFSecurityAuthorization 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<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); while (resultSet.next()) { CFSecuritySecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFSecuritySecSessionBuff[] retBuff = new CFSecuritySecSessionBuff[buffList.size()]; Iterator<CFSecuritySecSessionBuff> 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 CFSecuritySecSessionBuff readBuffByIdIdx(CFSecurityAuthorization 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()) { CFSecuritySecSessionBuff 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 CFSecuritySecSessionBuff[] readBuffBySecUserIdx(CFSecurityAuthorization 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<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); while (resultSet.next()) { CFSecuritySecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFSecuritySecSessionBuff[] retBuff = new CFSecuritySecSessionBuff[buffList.size()]; Iterator<CFSecuritySecSessionBuff> 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 CFSecuritySecSessionBuff[] readBuffBySecDevIdx(CFSecurityAuthorization 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<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); while (resultSet.next()) { CFSecuritySecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFSecuritySecSessionBuff[] retBuff = new CFSecuritySecSessionBuff[buffList.size()]; Iterator<CFSecuritySecSessionBuff> 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 CFSecuritySecSessionBuff readBuffByStartIdx(CFSecurityAuthorization 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++, CFAsteriskDb2LUWSchema.getTimestampString(Start)); resultSet = stmtReadBuffByStartIdx.executeQuery(); if (resultSet.next()) { CFSecuritySecSessionBuff 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 CFSecuritySecSessionBuff[] readBuffByFinishIdx(CFSecurityAuthorization 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++, CFAsteriskDb2LUWSchema.getTimestampString(Finish)); } else { stmtReadBuffByFinishIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtReadBuffByFinishIdx.executeQuery(); List<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); while (resultSet.next()) { CFSecuritySecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFSecuritySecSessionBuff[] retBuff = new CFSecuritySecSessionBuff[buffList.size()]; Iterator<CFSecuritySecSessionBuff> 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 CFSecuritySecSessionBuff[] readBuffBySecProxyIdx(CFSecurityAuthorization 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<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); while (resultSet.next()) { CFSecuritySecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); buffList.add(buff); } int idx = 0; CFSecuritySecSessionBuff[] retBuff = new CFSecuritySecSessionBuff[buffList.size()]; Iterator<CFSecuritySecSessionBuff> 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(CFSecurityAuthorization Authorization, CFSecuritySecSessionBuff 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++, CFAsteriskDb2LUWSchema.getTimestampString(Start)); if (Finish != null) { stmtUpdateByPKey.setString(argIdx++, CFAsteriskDb2LUWSchema.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()) { CFSecuritySecSessionBuff 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(CFSecurityAuthorization Authorization, CFSecuritySecSessionBuff 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(CFSecurityAuthorization 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(CFSecurityAuthorization Authorization, CFSecuritySecSessionPKey argKey) { deleteSecSessionByIdIdx(Authorization, argKey.getRequiredSecSessionId()); } public void deleteSecSessionBySecUserIdx(CFSecurityAuthorization 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(CFSecurityAuthorization Authorization, CFSecuritySecSessionBySecUserIdxKey argKey) { deleteSecSessionBySecUserIdx(Authorization, argKey.getRequiredSecUserId()); } public void deleteSecSessionBySecDevIdx(CFSecurityAuthorization 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(CFSecurityAuthorization Authorization, CFSecuritySecSessionBySecDevIdxKey argKey) { deleteSecSessionBySecDevIdx(Authorization, argKey.getRequiredSecUserId(), argKey.getOptionalSecDevName()); } public void deleteSecSessionByStartIdx(CFSecurityAuthorization 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++, CFAsteriskDb2LUWSchema.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(CFSecurityAuthorization Authorization, CFSecuritySecSessionByStartIdxKey argKey) { deleteSecSessionByStartIdx(Authorization, argKey.getRequiredSecUserId(), argKey.getRequiredStart()); } public void deleteSecSessionByFinishIdx(CFSecurityAuthorization 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++, CFAsteriskDb2LUWSchema.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(CFSecurityAuthorization Authorization, CFSecuritySecSessionByFinishIdxKey argKey) { deleteSecSessionByFinishIdx(Authorization, argKey.getRequiredSecUserId(), argKey.getOptionalFinish()); } public void deleteSecSessionBySecProxyIdx(CFSecurityAuthorization 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(CFSecurityAuthorization Authorization, CFSecuritySecSessionBySecProxyIdxKey argKey) { deleteSecSessionBySecProxyIdx(Authorization, argKey.getOptionalSecProxyId()); } public CFSecurityCursor openSecSessionCursorAll(CFSecurityAuthorization Authorization) { String sql = getSqlSelectSecSessionBuff() + "ORDER BY " + "sess.SecSessionId ASC"; CFAsteriskCursor cursor = new CFAsteriskDb2LUWCursor(Authorization, schema, sql); return (cursor); } public CFSecurityCursor openSecSessionCursorBySecUserIdx(CFSecurityAuthorization Authorization, UUID SecUserId) { String sql = getSqlSelectSecSessionBuff() + "WHERE " + "sess.SecUserId = '" + SecUserId.toString() + "' " + "ORDER BY " + "sess.SecSessionId ASC"; CFAsteriskCursor cursor = new CFAsteriskDb2LUWCursor(Authorization, schema, sql); return (cursor); } public CFSecurityCursor openSecSessionCursorBySecDevIdx(CFSecurityAuthorization Authorization, UUID SecUserId, String SecDevName) { String sql = getSqlSelectSecSessionBuff() + "WHERE " + "sess.SecUserId = '" + SecUserId.toString() + "' " + "AND " + ((SecDevName == null) ? "sess.SecDevName is null " : "sess.SecDevName = " + CFAsteriskDb2LUWSchema.getQuotedString(SecDevName) + " ") + "ORDER BY " + "sess.SecSessionId ASC"; CFAsteriskCursor cursor = new CFAsteriskDb2LUWCursor(Authorization, schema, sql); return (cursor); } public CFSecurityCursor openSecSessionCursorByFinishIdx(CFSecurityAuthorization 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( " + CFAsteriskDb2LUWSchema.getTimestampString(Finish) + ", 'YYYY-MM-DD-HH24.MI.SS' ) ") + "ORDER BY " + "sess.SecSessionId ASC"; CFAsteriskCursor cursor = new CFAsteriskDb2LUWCursor(Authorization, schema, sql); return (cursor); } public CFSecurityCursor openSecSessionCursorBySecProxyIdx(CFSecurityAuthorization Authorization, UUID SecProxyId) { String sql = getSqlSelectSecSessionBuff() + "WHERE " + ((SecProxyId == null) ? "sess.SecProxyId is null " : "sess.SecProxyId = '" + SecProxyId.toString() + "' ") + "ORDER BY " + "sess.SecSessionId ASC"; CFAsteriskCursor cursor = new CFAsteriskDb2LUWCursor(Authorization, schema, sql); return (cursor); } public void closeSecSessionCursor(CFSecurityCursor Cursor) { try { Cursor.getResultSet().close(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "closeSecSessionCursor", e); } } public CFSecuritySecSessionBuff nextSecSessionCursor(CFSecurityCursor 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"); } CFSecuritySecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); return (buff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } } public CFSecuritySecSessionBuff prevSecSessionCursor(CFSecurityCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; CFSecuritySecSessionBuff buff = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { buff = nextSecSessionCursor(Cursor); } return (buff); } public CFSecuritySecSessionBuff firstSecSessionCursor(CFSecurityCursor Cursor) { int targetRowIdx = 1; CFSecuritySecSessionBuff buff = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { buff = nextSecSessionCursor(Cursor); } return (buff); } public CFSecuritySecSessionBuff lastSecSessionCursor(CFSecurityCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastSecSessionCursor"); } public CFSecuritySecSessionBuff nthSecSessionCursor(CFSecurityCursor Cursor, int Idx) { int targetRowIdx = Idx; CFSecuritySecSessionBuff 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; } } }