コード例 #1
0
  private Dictionary resultToDictionary(ResultSet result) throws SQLException {
    Dictionary d = new Dictionary();

    d.setFk(result.getInt(COLUMN_FK));
    d.setType(DictionaryType.fromInt(result.getInt(COLUMN_TYPE)));
    d.setLang(result.getString(COLUMN_LANG));
    d.setValue(result.getString(COLUMN_VALUE));

    return d;
  }
コード例 #2
0
  public void deleteByFk(int fk, DictionaryType type) throws DAOException {
    try {
      // Create the statement with the SQL query
      PreparedStatement pState = connection.prepareStatement(REQUEST_DELETE_BY_FK);

      pState.setInt(1, fk);
      pState.setInt(2, type.getValue());

      if (log.isDebugEnabled()) {
        log.debug(pState.toString());
      }

      // Execute the SQL statement
      pState.execute();

      // Close the statement
      pState.close();
    } catch (SQLException e) {
      throw new DAOException("SQLException : " + e.getMessage());
    }
  }
コード例 #3
0
  public Map<String, Dictionary> selectByFk(int fk, DictionaryType type) throws DAOException {
    Map<String, Dictionary> map = new HashMap<String, Dictionary>();

    try {
      // Create the statement with the SQL query
      PreparedStatement pState = connection.prepareStatement(REQUEST_SELECT_BY_FK);

      pState.setInt(1, fk);
      pState.setInt(2, type.getValue());

      if (log.isDebugEnabled()) {
        log.debug(pState.toString());
      }

      // Execute the SQL statement
      ResultSet result = pState.executeQuery();

      // Put each result in the map
      while (result.next()) {
        Dictionary d = resultToDictionary(result);

        map.put(d.getLang(), d);
      }

      // Close the result and the statement
      try {
        result.close();
      } finally {
        pState.close();
      }
    } catch (SQLException e) {
      throw new DAOException("SQLException : " + e.getMessage());
    }

    return map;
  }