コード例 #1
0
  /**
   * Builds a list of {@link
   * edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector.StoredIDStore.PersistentIdEntry}s
   * from a result set.
   *
   * @param resultSet the result set
   * @return list of {@link
   *     edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector.StoredIDStore.PersistentIdEntry}s
   * @throws java.sql.SQLException thrown if there is a problem reading the information from the
   *     database
   */
  protected List<PersistentIdEntry> buildIdentifierEntries(ResultSet resultSet)
      throws SQLException {
    ArrayList<PersistentIdEntry> entries = new ArrayList<PersistentIdEntry>();

    PersistentIdEntry entry;
    while (resultSet.next()) {
      entry = new PersistentIdEntry();
      entry.setLocalEntityId(resultSet.getString(localEntityColumn));
      entry.setPeerEntityId(resultSet.getString(peerEntityColumn));
      entry.setPrincipalName(resultSet.getString(principalNameColumn));
      entry.setPersistentId(resultSet.getString(persistentIdColumn));
      entry.setLocalId(resultSet.getString(localIdColumn));
      entry.setPeerProvidedId(resultSet.getString(peerProvidedIdColumn));
      entry.setCreationTime(resultSet.getTimestamp(createTimeColumn));
      entry.setDeactivationTime(resultSet.getTimestamp(deactivationTimeColumn));
      entries.add(entry);

      log.trace("");
    }

    return entries;
  }
コード例 #2
0
  /**
   * Stores a persistent ID entry into the database.
   *
   * @param entry entry to persist
   * @throws java.sql.SQLException thrown is there is a problem writing to the database
   */
  public void storePersistentIdEntry(PersistentIdEntry entry) throws SQLException {

    StringBuilder sqlBuilder = new StringBuilder("INSERT INTO ");
    sqlBuilder.append(table).append(" (");
    sqlBuilder.append(localEntityColumn).append(", ");
    sqlBuilder.append(peerEntityColumn).append(", ");
    sqlBuilder.append(principalNameColumn).append(", ");
    sqlBuilder.append(localIdColumn).append(", ");
    sqlBuilder.append(persistentIdColumn).append(", ");
    sqlBuilder.append(peerProvidedIdColumn).append(", ");
    sqlBuilder.append(createTimeColumn);
    sqlBuilder.append(") VALUES (?, ?, ?, ?, ?, ?, ?)");

    String sql = sqlBuilder.toString();

    Connection dbConn = dataSource.getConnection();
    try {
      log.debug("Storing persistent ID entry based on prepared sql statement: {}", sql);
      PreparedStatement statement = dbConn.prepareStatement(sql);
      statement.setQueryTimeout(queryTimeout);

      log.debug("Setting prepared statement parameter {}: {}", 1, entry.getLocalEntityId());
      statement.setString(1, entry.getLocalEntityId());
      log.debug("Setting prepared statement parameter {}: {}", 2, entry.getPeerEntityId());
      statement.setString(2, entry.getPeerEntityId());
      log.debug("Setting prepared statement parameter {}: {}", 3, entry.getPrincipalName());
      statement.setString(3, entry.getPrincipalName());
      log.debug("Setting prepared statement parameter {}: {}", 4, entry.getLocalId());
      statement.setString(4, entry.getLocalId());
      log.debug("Setting prepared statement parameter {}: {}", 5, entry.getPersistentId());
      statement.setString(5, entry.getPersistentId());

      if (entry.getPeerProvidedId() == null) {
        log.debug("Setting prepared statement parameter {}: {}", 6, Types.VARCHAR);
        statement.setNull(6, Types.VARCHAR);
      } else {
        log.debug("Setting prepared statement parameter {}: {}", 6, entry.getPeerProvidedId());
        statement.setString(6, entry.getPeerProvidedId());
      }
      Timestamp timestamp = new Timestamp(System.currentTimeMillis());
      log.debug("Setting prepared statement parameter {}: {}", 7, timestamp.toString());
      statement.setTimestamp(7, timestamp);

      statement.executeUpdate();
    } finally {
      try {
        if (dbConn != null && !dbConn.isClosed()) {
          dbConn.close();
        }
      } catch (SQLException e) {
        log.error("Error closing database connection", e);
      }
    }
  }