public CFCrmContactTagBuff readBuffByIdIdx( CFSecurityAuthorization Authorization, long TenantId, long ContactId, long TagId) { final String S_ProcName = "readBuffByIdIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "{ call sp_read_ctc_tag_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.setLong(argIdx++, TenantId); stmtReadBuffByIdIdx.setLong(argIdx++, ContactId); stmtReadBuffByIdIdx.setLong(argIdx++, TagId); resultSet = stmtReadBuffByIdIdx.executeQuery(); if ((resultSet != null) && resultSet.next()) { CFCrmContactTagBuff buff = unpackContactTagResultSetToBuff(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 void deleteContactTag(CFSecurityAuthorization Authorization, CFCrmContactTagBuff Buff) { final String S_ProcName = "deleteContactTag"; try { Connection cnx = schema.getCnx(); long TenantId = Buff.getRequiredTenantId(); long ContactId = Buff.getRequiredContactId(); long TagId = Buff.getRequiredTagId(); String sql = "exec sp_delete_ctc_tag ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"; 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.setLong(argIdx++, TenantId); stmtDeleteByPKey.setLong(argIdx++, ContactId); stmtDeleteByPKey.setLong(argIdx++, TagId); 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 deleteMemoDataByMemoDataCtcIdx( CFSecurityAuthorization Authorization, long argTenantId, long argContactId) { final String S_ProcName = "deleteMemoDataByMemoDataCtcIdx"; 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_memodata_by_memodatactcidx ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?"; if (stmtDeleteByMemoDataCtcIdx == null) { stmtDeleteByMemoDataCtcIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByMemoDataCtcIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByMemoDataCtcIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByMemoDataCtcIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByMemoDataCtcIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByMemoDataCtcIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByMemoDataCtcIdx.setLong(argIdx++, argTenantId); stmtDeleteByMemoDataCtcIdx.setLong(argIdx++, argContactId); Object stuff = null; boolean moreResults = stmtDeleteByMemoDataCtcIdx.execute(); while (stuff == null) { try { moreResults = stmtDeleteByMemoDataCtcIdx.getMoreResults(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } if (moreResults) { try { stuff = stmtDeleteByMemoDataCtcIdx.getResultSet(); } catch (SQLException e) { } } else if (-1 == stmtDeleteByMemoDataCtcIdx.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 CFCrmMemoDataBuff[] readBuffByMemoDataCtcIdx( CFSecurityAuthorization Authorization, long TenantId, long ContactId) { final String S_ProcName = "readBuffByMemoDataCtcIdx"; ResultSet resultSet = null; try { Connection cnx = schema.getCnx(); String sql = "{ call sp_read_memodata_by_memodatactcidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " ) }"; if (stmtReadBuffByMemoDataCtcIdx == null) { stmtReadBuffByMemoDataCtcIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtReadBuffByMemoDataCtcIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByMemoDataCtcIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtReadBuffByMemoDataCtcIdx.setString( argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtReadBuffByMemoDataCtcIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtReadBuffByMemoDataCtcIdx.setLong( argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtReadBuffByMemoDataCtcIdx.setLong(argIdx++, TenantId); stmtReadBuffByMemoDataCtcIdx.setLong(argIdx++, ContactId); resultSet = stmtReadBuffByMemoDataCtcIdx.executeQuery(); List<CFCrmMemoDataBuff> buffList = new LinkedList<CFCrmMemoDataBuff>(); if (resultSet != null) { while (resultSet.next()) { CFCrmMemoDataBuff buff = unpackMemoDataResultSetToBuff(resultSet); buffList.add(buff); } } int idx = 0; CFCrmMemoDataBuff[] retBuff = new CFCrmMemoDataBuff[buffList.size()]; Iterator<CFCrmMemoDataBuff> 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 CFCrmMemoDataBuff readBuff(CFSecurityAuthorization Authorization, CFCrmMemoDataPKey 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(); long TenantId = PKey.getRequiredTenantId(); long MemoId = PKey.getRequiredMemoId(); String sql = "{ call sp_read_memodata( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " ) }"; 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.setLong(argIdx++, TenantId); stmtReadBuffByPKey.setLong(argIdx++, MemoId); resultSet = stmtReadBuffByPKey.executeQuery(); if ((resultSet != null) && resultSet.next()) { CFCrmMemoDataBuff buff = unpackMemoDataResultSetToBuff(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 CFCrmTagBuff[] 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_tag_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<CFCrmTagBuff> buffList = new LinkedList<CFCrmTagBuff>(); if (resultSet != null) { while (resultSet.next()) { CFCrmTagBuff buff = unpackTagResultSetToBuff(resultSet); buffList.add(buff); } } int idx = 0; CFCrmTagBuff[] retBuff = new CFCrmTagBuff[buffList.size()]; Iterator<CFCrmTagBuff> 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 updateTag(CFSecurityAuthorization Authorization, CFCrmTagBuff Buff) { final String S_ProcName = "updateTag"; ResultSet resultSet = null; try { long TenantId = Buff.getRequiredTenantId(); long Id = Buff.getRequiredId(); String Name = Buff.getRequiredName(); String Descr = Buff.getOptionalDescr(); int Revision = Buff.getRequiredRevision(); Connection cnx = schema.getCnx(); String sql = "exec sp_update_tag ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"; 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++, "CTAG"); stmtUpdateByPKey.setLong(argIdx++, TenantId); stmtUpdateByPKey.setLong(argIdx++, Id); stmtUpdateByPKey.setString(argIdx++, Name); if (Descr != null) { stmtUpdateByPKey.setString(argIdx++, Descr); } 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()) { CFCrmTagBuff updatedBuff = unpackTagResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredName(updatedBuff.getRequiredName()); Buff.setOptionalDescr(updatedBuff.getOptionalDescr()); 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 CFCrmTagBuff lockBuff(CFSecurityAuthorization Authorization, CFCrmTagPKey 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(); long TenantId = PKey.getRequiredTenantId(); long Id = PKey.getRequiredId(); String sql = "{ call sp_lock_tag( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " ) }"; 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.setLong(argIdx++, TenantId); stmtLockBuffByPKey.setLong(argIdx++, Id); 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()) { CFCrmTagBuff buff = unpackTagResultSetToBuff(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 void updateMemoData(CFSecurityAuthorization Authorization, CFCrmMemoDataBuff Buff) { final String S_ProcName = "updateMemoData"; if ("MMOD".equals(Buff.getClassCode()) && (!schema.isTenantUser(Authorization, Buff.getRequiredTenantId(), "UpdateMemoData"))) { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Permission denied -- User not part of TSecGroup UpdateMemoData"); } try { Connection cnx = schema.getCnx(); long TenantId = Buff.getRequiredTenantId(); long MemoId = Buff.getRequiredMemoId(); long ContactId = Buff.getRequiredContactId(); String Memo = Buff.getRequiredMemo(); int Revision = Buff.getRequiredRevision(); CFCrmMemoDataPKey pkey = schema.getFactoryMemoData().newPKey(); pkey.setRequiredTenantId(Buff.getRequiredTenantId()); pkey.setRequiredMemoId(Buff.getRequiredMemoId()); CFCrmMemoDataBuff readBuff = lockBuff(Authorization, pkey); if (readBuff == null) { throw CFLib.getDefaultExceptionFactory() .newStaleCacheDetectedException( getClass(), S_ProcName, "Attempted to update record which could not be locked/found", schema.getLowerDbSchemaName() + "..memodata", pkey); } int oldRevision = readBuff.getRequiredRevision(); if (oldRevision != Revision) { throw CFLib.getDefaultExceptionFactory() .newCollisionDetectedException(getClass(), S_ProcName, Buff); } int newRevision = Revision + 1; String sql = "UPDATE " + schema.getLowerDbSchemaName() + "..MemoData " + "SET " + "tenantid = ?" + ", " + "memoid = ?" + ", " + "contactid = ?" + ", " + "memo = ?" + ", " + "updatedby = ?, " + "updatedat = sysdatetime() " + ", revision = ? " + " WHERE " + "tenantid = ? " + "AND " + "memoid = ? " + "AND " + "revision = ? "; if (stmtUpdateByPKey == null) { stmtUpdateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtUpdateByPKey.setLong(argIdx++, TenantId); stmtUpdateByPKey.setLong(argIdx++, MemoId); stmtUpdateByPKey.setLong(argIdx++, ContactId); stmtUpdateByPKey.setString(argIdx++, Memo); stmtUpdateByPKey.setString(argIdx++, Authorization.getSecUserId().toString()); stmtUpdateByPKey.setInt(argIdx++, newRevision); stmtUpdateByPKey.setLong(argIdx++, TenantId); stmtUpdateByPKey.setLong(argIdx++, MemoId); stmtUpdateByPKey.setInt(argIdx++, Revision); ; int rowsAffected = stmtUpdateByPKey.executeUpdate(); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Expected 1 row to be affected by update, not " + rowsAffected); } Buff.setRequiredRevision(newRevision); String sqlAuditUpdated = "INSERT INTO " + schema.getLowerDbSchemaName() + "..MemoData_h( auditclusterid, " + " auditsessionid, " + " auditstamp" + ", " + "tenantid" + ", " + "memoid" + ", " + "contactid" + ", " + "memo" + ", " + " revision, " + " auditaction ) " + "SELECT ?, ?, sysdatetime()" + ", " + "mmod.tenantid" + ", " + "mmod.memoid" + ", " + "mmod.contactid" + ", " + "mmod.memo" + ", " + " mmod.revision, " + " 1 " + "FROM " + schema.getLowerDbSchemaName() + "..MemoData AS mmod " + " WHERE " + "mmod.tenantid = ? " + "AND mmod.memoid = ? "; if (stmtAuditUpdatedByPKey == null) { stmtAuditUpdatedByPKey = cnx.prepareStatement(sqlAuditUpdated); } argIdx = 1; stmtAuditUpdatedByPKey.setLong(argIdx++, Authorization.getSecClusterId()); stmtAuditUpdatedByPKey.setString(argIdx++, Authorization.getSecSessionId().toString()); stmtAuditUpdatedByPKey.setLong(argIdx++, TenantId); stmtAuditUpdatedByPKey.setLong(argIdx++, MemoId); int rowsAudited = stmtAuditUpdatedByPKey.executeUpdate(); if (rowsAudited != 1) { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Expected 1 row to be affected by audit via insert-selected, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
public void createMemoData(CFSecurityAuthorization Authorization, CFCrmMemoDataBuff Buff) { final String S_ProcName = "createMemoData"; if ("MMOD".equals(Buff.getClassCode()) && (!schema.isTenantUser(Authorization, Buff.getRequiredTenantId(), "CreateMemoData"))) { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Permission denied -- User not part of TSecGroup CreateMemoData"); } if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory() .newUsageException(getClass(), S_ProcName, "Transaction not open"); } try { Connection cnx = schema.getCnx(); long TenantId = Buff.getRequiredTenantId(); long MemoId = Buff.getRequiredMemoId(); long ContactId = Buff.getRequiredContactId(); String Memo = Buff.getRequiredMemo(); int Revision = 1; String sql = "INSERT INTO " + schema.getLowerDbSchemaName() + "..MemoData( " + "forcesynclock, " + "createdby, " + "createdat, " + "updatedby, " + "updatedat, " + "tenantid, " + "memoid, " + "contactid, " + "memo" + ", revision )" + "VALUES ( " + "0, " + " ?, " + " getdate(), " + " ?, " + " getdate(), " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "1 )"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setString(argIdx++, Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, Authorization.getSecUserId().toString()); stmtCreateByPKey.setLong(argIdx++, TenantId); stmtCreateByPKey.setLong(argIdx++, MemoId); stmtCreateByPKey.setLong(argIdx++, ContactId); stmtCreateByPKey.setString(argIdx++, Memo); int rowsAffected = stmtCreateByPKey.executeUpdate(); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Expected 1 row to be affected by insert, not " + rowsAffected); } Buff.setRequiredRevision(Revision); String sqlAuditCreated = "INSERT INTO " + schema.getLowerDbSchemaName() + "..MemoData_h( auditclusterid, " + " auditsessionid, " + " auditstamp" + ", " + "tenantid" + ", " + "memoid" + ", " + "contactid" + ", " + "memo" + ", " + " revision, " + " auditaction ) " + "SELECT ?, ?, sysdatetime()" + ", " + "mmod.tenantid" + ", " + "mmod.memoid" + ", " + "mmod.contactid" + ", " + "mmod.memo" + ", " + " mmod.revision, " + " 0" + "FROM " + schema.getLowerDbSchemaName() + "..MemoData AS mmod " + " WHERE " + "mmod.tenantid = ? " + "AND mmod.memoid = ? "; if (stmtAuditCreatedByPKey == null) { stmtAuditCreatedByPKey = cnx.prepareStatement(sqlAuditCreated); } argIdx = 1; stmtAuditCreatedByPKey.setLong(argIdx++, Authorization.getSecClusterId()); stmtAuditCreatedByPKey.setString(argIdx++, Authorization.getSecSessionId().toString()); stmtAuditCreatedByPKey.setLong(argIdx++, TenantId); stmtAuditCreatedByPKey.setLong(argIdx++, MemoId); int rowsAudited = stmtAuditCreatedByPKey.executeUpdate(); if (rowsAudited != 1) { throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Expected 1 row to be affected by audit via insert-selected, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
public void createContactTag(CFSecurityAuthorization Authorization, CFCrmContactTagBuff Buff) { final String S_ProcName = "createContactTag"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory() .newUsageException(getClass(), S_ProcName, "Transaction not open"); } ResultSet resultSet = null; try { long TenantId = Buff.getRequiredTenantId(); long ContactId = Buff.getRequiredContactId(); long TagId = Buff.getRequiredTagId(); String TagValue = Buff.getRequiredTagValue(); Connection cnx = schema.getCnx(); String sql = "exec sp_create_ctc_tag ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"; 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++, "CTTG"); stmtCreateByPKey.setLong(argIdx++, TenantId); stmtCreateByPKey.setLong(argIdx++, ContactId); stmtCreateByPKey.setLong(argIdx++, TagId); stmtCreateByPKey.setString(argIdx++, TagValue); 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()) { CFCrmContactTagBuff createdBuff = unpackContactTagResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory() .newRuntimeException( getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredTenantId(createdBuff.getRequiredTenantId()); Buff.setRequiredContactId(createdBuff.getRequiredContactId()); Buff.setRequiredTagId(createdBuff.getRequiredTagId()); Buff.setRequiredTagValue(createdBuff.getRequiredTagValue()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setCreatedByUserId(createdBuff.getCreatedByUserId()); Buff.setCreatedAt(createdBuff.getCreatedAt()); Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId()); Buff.setUpdatedAt(createdBuff.getUpdatedAt()); } 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; } } }