예제 #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 add(int fk, Map<String, Dictionary> map) throws DAOException {

    // Add each instance of Dictionary in the map
    Set<String> keys = map.keySet();
    for (String key : keys) {
      Dictionary d = map.get(key);
      d.setFk(fk);

      add(d);
    }
  }
예제 #3
0
  public void delete(Dictionary d) throws DAOException {
    try {
      // Create the statement with the SQL query
      PreparedStatement pState = connection.prepareStatement(REQUEST_DELETE);

      pState.setInt(1, d.getFk());
      pState.setInt(2, d.getType().getValue());
      pState.setString(3, d.getLang());

      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());
    }
  }
예제 #4
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;
  }