Exemplo n.º 1
0
  public void setKeyCreatingIfNeeded(
      List<? extends IClientInfo> clients,
      List<IClientInfo> clientsNeedingSignalUpdate,
      Connection c)
      throws SQLException {

    PreparedStatement select = null;

    // Create lazily.
    PreparedStatement update = null;

    try {

      select = c.prepareStatement("SELECT secure_hash_key FROM dat_user_account WHERE object_id=?");

      for (IClientInfo client : clients) {
        int userId = client.getUserId();
        // ensure dat_user_account.secure_hash_key is filled.
        select.setInt(1, userId);
        ResultSet rs = select.executeQuery();
        if (!rs.next()) {
          LogMessageGen lmg = new LogMessageGen();
          lmg.setSubject("dat_user_account row not found");
          lmg.param(LoggingConsts.USER_ID, userId);
          // possible that the user simply disappeared by the time we got here.
          m_logCategory.warn(lmg.toString());
          continue;
        }
        boolean firstTimeCreate = false;
        byte[] key = rs.getBytes(1);
        if (key == null || key.length == 0) {
          if (update == null) {
            update =
                c.prepareStatement(
                    "UPDATE dat_user_account SET secure_hash_key=? WHERE object_id=?");
          }
          key = createNewRandomKey();
          update.setBytes(1, key);
          update.setInt(2, userId);
          int ct = update.executeUpdate();
          if (ct != 1) {
            LogMessageGen lmg = new LogMessageGen();
            lmg.setSubject("Unable to update dat_user_account.secure_hash_key");
            lmg.param(LoggingConsts.USER_ID, userId);
            m_logCategory.error(lmg.toString());
            continue;
          } else {
            firstTimeCreate = true;
          }
        } // no existing key.
        client.getHashSupport().setHashKey(key);
        if (firstTimeCreate) {
          if (clientsNeedingSignalUpdate != null) {
            // EMSDEV-7854.  Don't actually do
            // updateSignalFiles(client) right here; we want to avoid nfs usage in the middle of a
            // db
            // transaction.
            clientsNeedingSignalUpdate.add(client);
          }
        }
      } // each client.
    } finally {
      DbUtils.safeClose(select);
      DbUtils.safeClose(update);
    }
  }
Exemplo n.º 2
0
 public void updateSignalFiles(IClientInfo client) {
   if (client == null) {
     return;
   }
   updateSignalFiles(client.getHashSupport(), client.getState(), client.isDisabled());
 }