Java tutorial
// Description: Java 8 MySQL 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.CFAsteriskMySql; 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.*; /* * CFAsteriskMySqlSecSessionTable MySQL Jdbc DbIO implementation * for SecSession. */ public class CFAsteriskMySqlSecSessionTable implements ICFAsteriskSecSessionTable { private CFAsteriskMySqlSchema 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 CFAsteriskMySqlSecSessionTable(CFAsteriskMySqlSchema 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".sp_create_secsess( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "timestamp( ? )" + ", " + "timestamp( ? )" + ", " + "?" + " )"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); 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++, CFAsteriskMySqlSchema.getTimestampString(Start)); if (Finish != null) { stmtCreateByPKey.setString(argIdx++, CFAsteriskMySqlSchema.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); } try { resultSet = stmtCreateByPKey.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } if ((resultSet != null) && resultSet.next()) { CFSecuritySecSessionBuff createdBuff = unpackSecSessionResultSetToBuff(resultSet); if ((resultSet != null) && 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, " + "date_format( sess.start_ts, '%Y-%m-%d %H:%i:%S' ) as start_ts, " + "date_format( sess.finish_ts, '%Y-%m-%d %H:%i:%S' ) 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(CFAsteriskMySqlSchema.convertUuidString(resultSet.getString(idxcol))); idxcol++; buff.setRequiredSecUserId(CFAsteriskMySqlSchema.convertUuidString(resultSet.getString(idxcol))); idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalSecDevName(null); } else { buff.setOptionalSecDevName(colVal); } } idxcol++; buff.setRequiredStart(CFAsteriskMySqlSchema.convertTimestampString(resultSet.getString(idxcol))); idxcol++; { Calendar colVal = CFAsteriskMySqlSchema.convertTimestampString(resultSet.getString(idxcol)); if (resultSet.wasNull()) { buff.setOptionalFinish(null); } else { buff.setOptionalFinish(colVal); } } idxcol++; { UUID colVal = CFAsteriskMySqlSchema.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 = "CFAsteriskMySqlSecSessionTable.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 = "CFAsteriskMySqlSecSessionTable.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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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()); try { resultSet = stmtReadBuffByPKey.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } if ((resultSet != null) && resultSet.next()) { CFSecuritySecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); if ((resultSet != null) && 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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()); try { resultSet = stmtLockBuffByPKey.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } if ((resultSet != null) && resultSet.next()) { CFSecuritySecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); if ((resultSet != null) && 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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()); try { resultSet = stmtReadAllBuff.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } List<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); while ((resultSet != null) && 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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()); try { resultSet = stmtReadBuffByIdIdx.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } if ((resultSet != null) && resultSet.next()) { CFSecuritySecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); if ((resultSet != null) && 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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()); try { resultSet = stmtReadBuffBySecUserIdx.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } List<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); while ((resultSet != null) && 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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); } try { resultSet = stmtReadBuffBySecDevIdx.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } List<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); while ((resultSet != null) && 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_secsess_by_startidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "timestamp( ? )" + " )"; 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++, CFAsteriskMySqlSchema.getTimestampString(Start)); try { resultSet = stmtReadBuffByStartIdx.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } if ((resultSet != null) && resultSet.next()) { CFSecuritySecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet); if ((resultSet != null) && 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_secsess_by_finishidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "timestamp( ? )" + " )"; 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++, CFAsteriskMySqlSchema.getTimestampString(Finish)); } else { stmtReadBuffByFinishIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } try { resultSet = stmtReadBuffByFinishIdx.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } List<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); while ((resultSet != null) && 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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); } try { resultSet = stmtReadBuffBySecProxyIdx.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } List<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); while ((resultSet != null) && 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"; 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".sp_update_secsess( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "timestamp( ? )" + ", " + "timestamp( ? )" + ", " + "?" + ", " + "?" + " )"; 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++, CFAsteriskMySqlSchema.getTimestampString(Start)); if (Finish != null) { stmtUpdateByPKey.setString(argIdx++, CFAsteriskMySqlSchema.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); try { resultSet = stmtUpdateByPKey.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } if ((resultSet != null) && resultSet.next()) { CFSecuritySecSessionBuff updatedBuff = unpackSecSessionResultSetToBuff(resultSet); if ((resultSet != null) && 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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()); ; stmtDeleteByPKey.executeUpdate(); } 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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()); stmtDeleteByIdIdx.executeUpdate(); } 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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()); stmtDeleteBySecUserIdx.executeUpdate(); } 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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); } stmtDeleteBySecDevIdx.executeUpdate(); } 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".sp_delete_secsess_by_startidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "timestamp( ? )" + " )"; 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++, CFAsteriskMySqlSchema.getTimestampString(argStart)); stmtDeleteByStartIdx.executeUpdate(); } 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".sp_delete_secsess_by_finishidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "timestamp( ? )" + " )"; 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++, CFAsteriskMySqlSchema.getTimestampString(argFinish)); } else { stmtDeleteByFinishIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtDeleteByFinishIdx.executeUpdate(); } 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(); String sql = "call " + schema.getLowerDbSchemaName() + ".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); } stmtDeleteBySecProxyIdx.executeUpdate(); } 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 CFAsteriskMySqlCursor(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 CFAsteriskMySqlCursor(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 = " + CFAsteriskMySqlSchema.getQuotedString(SecDevName) + " ") + "ORDER BY " + "sess.SecSessionId ASC"; CFAsteriskCursor cursor = new CFAsteriskMySqlCursor(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( " + CFAsteriskMySqlSchema.getTimestampString(Finish) + " ) ") + "ORDER BY " + "sess.SecSessionId ASC"; CFAsteriskCursor cursor = new CFAsteriskMySqlCursor(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 CFAsteriskMySqlCursor(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() { S_sqlSelectSecSessionDistinctClassCode = null; S_sqlSelectSecSessionBuff = null; if (stmtReadBuffByPKey != null) { try { stmtReadBuffByPKey.close(); } catch (SQLException e) { } stmtReadBuffByPKey = 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; } } }