public CFCrmContactListBuff lockBuff(
     CFSecurityAuthorization Authorization, CFCrmContactListPKey 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 ContactListId = PKey.getRequiredContactListId();
     String sql =
         "SELECT * FROM "
             + schema.getLowerDbSchemaName()
             + ".sp_lock_ctclst( ?, ?, ?, ?, ?"
             + ", "
             + "?"
             + ", "
             + "?"
             + " )";
     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++, ContactListId);
     resultSet = stmtLockBuffByPKey.executeQuery();
     if (resultSet.next()) {
       CFCrmContactListBuff buff = unpackContactListResultSetToBuff(resultSet);
       if (resultSet.next()) {
         throw CFLib.getDefaultExceptionFactory()
             .newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response");
       }
       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 deleteContactListByUDescrIdx(
     CFSecurityAuthorization Authorization, long argTenantId, String argDescription) {
   final String S_ProcName = "deleteContactListByUDescrIdx";
   ResultSet resultSet = null;
   try {
     Connection cnx = schema.getCnx();
     String sql =
         "SELECT "
             + schema.getLowerDbSchemaName()
             + ".sp_delete_ctclst_by_udescridx( ?, ?, ?, ?, ?"
             + ", "
             + "?"
             + ", "
             + "?"
             + " ) as DeletedFlag";
     if (stmtDeleteByUDescrIdx == null) {
       stmtDeleteByUDescrIdx = cnx.prepareStatement(sql);
     }
     int argIdx = 1;
     stmtDeleteByUDescrIdx.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtDeleteByUDescrIdx.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString());
     stmtDeleteByUDescrIdx.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
     stmtDeleteByUDescrIdx.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtDeleteByUDescrIdx.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
     stmtDeleteByUDescrIdx.setLong(argIdx++, argTenantId);
     stmtDeleteByUDescrIdx.setString(argIdx++, argDescription);
     resultSet = stmtDeleteByUDescrIdx.executeQuery();
     if (resultSet.next()) {
       boolean deleteFlag = resultSet.getBoolean(1);
       if (resultSet.next()) {
         throw CFLib.getDefaultExceptionFactory()
             .newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response");
       }
     } else {
       throw CFLib.getDefaultExceptionFactory()
           .newRuntimeException(
               getClass(),
               S_ProcName,
               "Expected 1 record result set to be returned by delete, not 0 rows");
     }
   } catch (SQLException e) {
     throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
   } finally {
     if (resultSet != null) {
       try {
         resultSet.close();
       } catch (SQLException e) {
       }
       resultSet = null;
     }
   }
 }
  protected CFCrmContactListBuff unpackContactListResultSetToBuff(ResultSet resultSet)
      throws SQLException {
    final String S_ProcName = "unpackContactListResultSetToBuff";
    int idxcol = 1;
    CFCrmContactListBuff buff = schema.getFactoryContactList().newBuff();
    {
      String colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedByUserId(null);
      } else {
        buff.setCreatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setCreatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setCreatedAt(null);
      } else {
        buff.setCreatedAt(CFCrmPgSqlSchema.convertTimestampString(colString));
      }
      idxcol++;
      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedByUserId(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedByUserId(null);
      } else {
        buff.setUpdatedByUserId(UUID.fromString(colString));
      }
      idxcol++;

      colString = resultSet.getString(idxcol);
      if (resultSet.wasNull()) {
        buff.setUpdatedAt(null);
      } else if ((colString == null) || (colString.length() <= 0)) {
        buff.setUpdatedAt(null);
      } else {
        buff.setUpdatedAt(CFCrmPgSqlSchema.convertTimestampString(colString));
      }
      idxcol++;
    }
    buff.setRequiredContactListId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredTenantId(resultSet.getLong(idxcol));
    idxcol++;
    buff.setRequiredDescription(resultSet.getString(idxcol));
    idxcol++;

    buff.setRequiredRevision(resultSet.getInt(idxcol));
    return (buff);
  }
 public CFCrmContactListBuff readBuffByUDescrIdx(
     CFSecurityAuthorization Authorization, long TenantId, String Description) {
   final String S_ProcName = "readBuffByUDescrIdx";
   ResultSet resultSet = null;
   try {
     Connection cnx = schema.getCnx();
     String sql =
         "SELECT * FROM "
             + schema.getLowerDbSchemaName()
             + ".sp_read_ctclst_by_udescridx( ?, ?, ?, ?, ?"
             + ", "
             + "?"
             + ", "
             + "?"
             + " )";
     if (stmtReadBuffByUDescrIdx == null) {
       stmtReadBuffByUDescrIdx = cnx.prepareStatement(sql);
     }
     int argIdx = 1;
     stmtReadBuffByUDescrIdx.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtReadBuffByUDescrIdx.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString());
     stmtReadBuffByUDescrIdx.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
     stmtReadBuffByUDescrIdx.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtReadBuffByUDescrIdx.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
     stmtReadBuffByUDescrIdx.setLong(argIdx++, TenantId);
     stmtReadBuffByUDescrIdx.setString(argIdx++, Description);
     resultSet = stmtReadBuffByUDescrIdx.executeQuery();
     if (resultSet.next()) {
       CFCrmContactListBuff buff = unpackContactListResultSetToBuff(resultSet);
       if (resultSet.next()) {
         throw CFLib.getDefaultExceptionFactory()
             .newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response");
       }
       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 CFCrmContactListBuff[] readBuffByTenantIdx(
     CFSecurityAuthorization Authorization, long TenantId) {
   final String S_ProcName = "readBuffByTenantIdx";
   ResultSet resultSet = null;
   try {
     Connection cnx = schema.getCnx();
     String sql =
         "SELECT * FROM "
             + schema.getLowerDbSchemaName()
             + ".sp_read_ctclst_by_tenantidx( ?, ?, ?, ?, ?"
             + ", "
             + "?"
             + " )";
     if (stmtReadBuffByTenantIdx == null) {
       stmtReadBuffByTenantIdx = cnx.prepareStatement(sql);
     }
     int argIdx = 1;
     stmtReadBuffByTenantIdx.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtReadBuffByTenantIdx.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString());
     stmtReadBuffByTenantIdx.setString(
         argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
     stmtReadBuffByTenantIdx.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
     stmtReadBuffByTenantIdx.setLong(
         argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
     stmtReadBuffByTenantIdx.setLong(argIdx++, TenantId);
     resultSet = stmtReadBuffByTenantIdx.executeQuery();
     List<CFCrmContactListBuff> buffList = new LinkedList<CFCrmContactListBuff>();
     while (resultSet.next()) {
       CFCrmContactListBuff buff = unpackContactListResultSetToBuff(resultSet);
       buffList.add(buff);
     }
     int idx = 0;
     CFCrmContactListBuff[] retBuff = new CFCrmContactListBuff[buffList.size()];
     Iterator<CFCrmContactListBuff> 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 CFCrmContactListBuff[] readDerivedByTenantIdx(
     CFSecurityAuthorization Authorization, long TenantId) {
   final String S_ProcName = "readDerivedByTenantIdx";
   if (!schema.isTransactionOpen()) {
     throw CFLib.getDefaultExceptionFactory()
         .newUsageException(getClass(), S_ProcName, "Transaction not open");
   }
   CFCrmContactListBuff[] buffList = readBuffByTenantIdx(Authorization, TenantId);
   return (buffList);
 }
 public CFCrmContactListBuff[] readAllDerived(CFSecurityAuthorization Authorization) {
   final String S_ProcName = "readAllDerived";
   CFCrmContactListBuff[] buffArray;
   if (!schema.isTransactionOpen()) {
     throw CFLib.getDefaultExceptionFactory()
         .newUsageException(getClass(), S_ProcName, "Transaction not open");
   }
   buffArray = readAllBuff(Authorization);
   return (buffArray);
 }
 public CFCrmContactListBuff readDerivedByUDescrIdx(
     CFSecurityAuthorization Authorization, long TenantId, String Description) {
   final String S_ProcName = "CFCrmPgSqlContactListTable.readDerivedByUDescrIdx() ";
   CFCrmContactListBuff buff;
   if (!schema.isTransactionOpen()) {
     throw CFLib.getDefaultExceptionFactory()
         .newUsageException(getClass(), S_ProcName, "Transaction not open");
   }
   buff = readBuffByUDescrIdx(Authorization, TenantId, Description);
   return (buff);
 }
 public String getSqlSelectContactListDistinctClassCode() {
   if (S_sqlSelectContactListDistinctClassCode == null) {
     S_sqlSelectContactListDistinctClassCode =
         "SELECT "
             + "DISTINCT ctl.ClassCode "
             + "FROM "
             + schema.getLowerDbSchemaName()
             + ".CtcLst AS ctl ";
   }
   return (S_sqlSelectContactListDistinctClassCode);
 }
  public CFCrmContactListBuff lockDerived(
      CFSecurityAuthorization Authorization, CFCrmContactListPKey PKey) {
    final String S_ProcName = "lockDerived";
    if (!schema.isTransactionOpen()) {
      throw CFLib.getDefaultExceptionFactory()
          .newUsageException(getClass(), S_ProcName, "Transaction not open");
    }
    CFCrmContactListBuff buff;

    buff = lockBuff(Authorization, PKey);
    return (buff);
  }
 public CFSecurityCursor openContactListCursorAll(CFSecurityAuthorization Authorization) {
   String sql =
       getSqlSelectContactListBuff()
           + ((schema.isSystemUser(Authorization))
               ? ""
               : (" WHERE ctl.TenantId = " + Authorization.getSecTenantId()))
           + "ORDER BY "
           + "ctl.TenantId ASC"
           + ", "
           + "ctl.ContactListId ASC";
   CFCrmCursor cursor = new CFCrmPgSqlCursor(Authorization, schema, sql);
   return (cursor);
 }
 public String getSqlSelectContactListBuff() {
   if (S_sqlSelectContactListBuff == null) {
     S_sqlSelectContactListBuff =
         "SELECT "
             + "ctl.TenantId, "
             + "ctl.ContactListId, "
             + "ctl.Description, "
             + "ctl.Revision "
             + "FROM "
             + schema.getLowerDbSchemaName()
             + ".CtcLst AS ctl ";
   }
   return (S_sqlSelectContactListBuff);
 }
 public void updateContactList(CFSecurityAuthorization Authorization, CFCrmContactListBuff Buff) {
   final String S_ProcName = "updateContactList";
   ResultSet resultSet = null;
   try {
     long ContactListId = Buff.getRequiredContactListId();
     long TenantId = Buff.getRequiredTenantId();
     String Description = Buff.getRequiredDescription();
     int Revision = Buff.getRequiredRevision();
     Connection cnx = schema.getCnx();
     String sql =
         "select * from "
             + schema.getLowerDbSchemaName()
             + ".sp_update_ctclst( ?, ?, ?, ?, ?, ?"
             + ", "
             + "?"
             + ", "
             + "?"
             + ", "
             + "?"
             + ", "
             + "?"
             + " )";
     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++, "CTL");
     stmtUpdateByPKey.setLong(argIdx++, ContactListId);
     stmtUpdateByPKey.setLong(argIdx++, TenantId);
     stmtUpdateByPKey.setString(argIdx++, Description);
     stmtUpdateByPKey.setInt(argIdx++, Revision);
     resultSet = stmtUpdateByPKey.executeQuery();
     if (resultSet.next()) {
       CFCrmContactListBuff updatedBuff = unpackContactListResultSetToBuff(resultSet);
       if (resultSet.next()) {
         throw CFLib.getDefaultExceptionFactory()
             .newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response");
       }
       Buff.setRequiredDescription(updatedBuff.getRequiredDescription());
       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;
     }
   }
 }