Java tutorial
// Description: Java 8 MS SQL Server 2012 Express Advanced Edition 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.CFAsteriskMSSql; 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.*; /* * CFAsteriskMSSqlSecSessionTable PostgreSQL Jdbc DbIO implementation * for SecSession. */ public class CFAsteriskMSSqlSecSessionTable implements ICFAsteriskSecSessionTable { private CFAsteriskMSSqlSchema 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 CFAsteriskMSSqlSecSessionTable(CFAsteriskMSSqlSchema 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 = "exec sp_create_secsess ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"; 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++, CFAsteriskMSSqlSchema.getTimestampString(Start)); if (Finish != null) { stmtCreateByPKey.setString(argIdx++, CFAsteriskMSSqlSchema.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); } stmtCreateByPKey.execute(); boolean moreResults = true; resultSet = null; while (resultSet == null) { try { moreResults = stmtCreateByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtCreateByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtCreateByPKey.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } 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, " + "convert( varchar, sess.start_ts, 120 ) AS start_ts, " + "convert( varchar, sess.finish_ts, 120 ) 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(CFAsteriskMSSqlSchema.convertUuidString(resultSet.getString(idxcol))); idxcol++; buff.setRequiredSecUserId(CFAsteriskMSSqlSchema.convertUuidString(resultSet.getString(idxcol))); idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalSecDevName(null); } else { buff.setOptionalSecDevName(colVal); } } idxcol++; buff.setRequiredStart(CFAsteriskMSSqlSchema.convertTimestampString(resultSet.getString(idxcol))); idxcol++; { Calendar colVal = CFAsteriskMSSqlSchema.convertTimestampString(resultSet.getString(idxcol)); if (resultSet.wasNull()) { buff.setOptionalFinish(null); } else { buff.setOptionalFinish(colVal); } } idxcol++; { UUID colVal = CFAsteriskMSSqlSchema.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 = "CFAsteriskMSSqlSecSessionTable.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 = "CFAsteriskMSSqlSecSessionTable.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 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 != null) && 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(); 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()); stmtLockBuffByPKey.execute(); boolean moreResults = true; resultSet = null; while (resultSet == null) { try { moreResults = stmtLockBuffByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtLockBuffByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtLockBuffByPKey.getUpdateCount()) { break; } } if ((resultSet != null) && 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(); 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>(); if (resultSet != null) { 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(); 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 != null) && 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(); 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>(); if (resultSet != null) { 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(); 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>(); if (resultSet != null) { 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(); String sql = "{ call sp_read_secsess_by_startidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "convert( datetime2, ? )" + " ) }"; 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++, CFAsteriskMSSqlSchema.getTimestampString(Start)); resultSet = stmtReadBuffByStartIdx.executeQuery(); if ((resultSet != null) && 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(); String sql = "{ call sp_read_secsess_by_finishidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "convert( datetime2, ? )" + " ) }"; 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++, CFAsteriskMSSqlSchema.getTimestampString(Finish)); } else { stmtReadBuffByFinishIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } resultSet = stmtReadBuffByFinishIdx.executeQuery(); List<CFSecuritySecSessionBuff> buffList = new LinkedList<CFSecuritySecSessionBuff>(); if (resultSet != null) { 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(); 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>(); if (resultSet != null) { 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"; 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 = "exec sp_update_secsess ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"; 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++, CFAsteriskMSSqlSchema.getTimestampString(Start)); if (Finish != null) { stmtUpdateByPKey.setString(argIdx++, CFAsteriskMSSqlSchema.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); stmtUpdateByPKey.execute(); boolean moreResults = true; resultSet = null; while (resultSet == null) { try { moreResults = stmtUpdateByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { resultSet = stmtUpdateByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtUpdateByPKey.getUpdateCount()) { break; } } if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "resultSet"); } 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"; try { Connection cnx = schema.getCnx(); UUID SecSessionId = Buff.getRequiredSecSessionId(); String sql = "exec 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()); ; Object stuff = null; boolean moreResults = stmtDeleteByPKey.execute(); while (stuff == null) { try { moreResults = stmtDeleteByPKey.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { stuff = stmtDeleteByPKey.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtDeleteByPKey.getUpdateCount()) { break; } } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } } public void deleteSecSessionByIdIdx(CFSecurityAuthorization Authorization, UUID argSecSessionId) { final String S_ProcName = "deleteSecSessionByIdIdx"; // MSS TODO WORKING throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), S_ProcName); } public void deleteSecSessionByIdIdx(CFSecurityAuthorization Authorization, CFSecuritySecSessionPKey argKey) { deleteSecSessionByIdIdx(Authorization, argKey.getRequiredSecSessionId()); } public void deleteSecSessionBySecUserIdx(CFSecurityAuthorization Authorization, UUID argSecUserId) { final String S_ProcName = "deleteSecSessionBySecUserIdx"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "exec 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()); Object stuff = null; boolean moreResults = stmtDeleteBySecUserIdx.execute(); while (stuff == null) { try { moreResults = stmtDeleteBySecUserIdx.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { stuff = stmtDeleteBySecUserIdx.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtDeleteBySecUserIdx.getUpdateCount()) { break; } } } 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"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "exec 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); } Object stuff = null; boolean moreResults = stmtDeleteBySecDevIdx.execute(); while (stuff == null) { try { moreResults = stmtDeleteBySecDevIdx.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { stuff = stmtDeleteBySecDevIdx.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtDeleteBySecDevIdx.getUpdateCount()) { break; } } } 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"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "exec sp_delete_secsess_by_startidx ?, ?, ?, ?, ?" + ", " + "?" + ", " + "convert( datetime2, ? )"; 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++, CFAsteriskMSSqlSchema.getTimestampString(argStart)); Object stuff = null; boolean moreResults = stmtDeleteByStartIdx.execute(); while (stuff == null) { try { moreResults = stmtDeleteByStartIdx.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { stuff = stmtDeleteByStartIdx.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtDeleteByStartIdx.getUpdateCount()) { break; } } } 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"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "exec sp_delete_secsess_by_finishidx ?, ?, ?, ?, ?" + ", " + "?" + ", " + "convert( datetime2, ? )"; 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++, CFAsteriskMSSqlSchema.getTimestampString(argFinish)); } else { stmtDeleteByFinishIdx.setNull(argIdx++, java.sql.Types.VARCHAR); } Object stuff = null; boolean moreResults = stmtDeleteByFinishIdx.execute(); while (stuff == null) { try { moreResults = stmtDeleteByFinishIdx.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { stuff = stmtDeleteByFinishIdx.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtDeleteByFinishIdx.getUpdateCount()) { break; } } } 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"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "exec 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); } Object stuff = null; boolean moreResults = stmtDeleteBySecProxyIdx.execute(); while (stuff == null) { try { moreResults = stmtDeleteBySecProxyIdx.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { stuff = stmtDeleteBySecProxyIdx.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtDeleteBySecProxyIdx.getUpdateCount()) { break; } } } 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 CFAsteriskMSSqlCursor(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 CFAsteriskMSSqlCursor(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 = " + CFAsteriskMSSqlSchema.getQuotedString(SecDevName) + " ") + "ORDER BY " + "sess.SecSessionId ASC"; CFAsteriskCursor cursor = new CFAsteriskMSSqlCursor(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 = convert( datetime2, " + CFAsteriskMSSqlSchema.getTimestampString(Finish) + ", 120 ) ") + "ORDER BY " + "sess.SecSessionId ASC"; CFAsteriskCursor cursor = new CFAsteriskMSSqlCursor(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 CFAsteriskMSSqlCursor(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 (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 (stmtDeleteBySecUserIdx != null) { try { stmtDeleteBySecUserIdx.close(); } catch (SQLException e) { // throw CFLib.getDefaultExceptionFactory().newDbException( getClass(), // S_ProcName, // e ); } finally { stmtDeleteBySecUserIdx = null; } } if (stmtDeleteBySecDevIdx != null) { try { stmtDeleteBySecDevIdx.close(); } catch (SQLException e) { // throw CFLib.getDefaultExceptionFactory().newDbException( getClass(), // S_ProcName, // e ); } finally { stmtDeleteBySecDevIdx = null; } } if (stmtDeleteByStartIdx != null) { try { stmtDeleteByStartIdx.close(); } catch (SQLException e) { // throw CFLib.getDefaultExceptionFactory().newDbException( getClass(), // S_ProcName, // e ); } finally { stmtDeleteByStartIdx = null; } } if (stmtDeleteByFinishIdx != null) { try { stmtDeleteByFinishIdx.close(); } catch (SQLException e) { // throw CFLib.getDefaultExceptionFactory().newDbException( getClass(), // S_ProcName, // e ); } finally { stmtDeleteByFinishIdx = null; } } if (stmtDeleteBySecProxyIdx != null) { try { stmtDeleteBySecProxyIdx.close(); } catch (SQLException e) { // throw CFLib.getDefaultExceptionFactory().newDbException( getClass(), // S_ProcName, // e ); } finally { 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; } } }