Example #1
0
  /**
   * Gets elements depending on the format specified.
   *
   * @param format The format specification of the elements to be returned.
   * @return a List of all elements in MetaDB with the specified format.
   */
  public List<Element> getElementList(String format) {
    List<Element> elementList = new ArrayList<Element>();

    Connection conn = Conn.initialize();
    if (conn != null) {
      try {
        PreparedStatement getElementListQuery = conn.prepareStatement(GET_ELEMENT_LIST_BY_FORMAT);
        getElementListQuery.setString(1, format);

        ResultSet getElementListQueryResult = getElementListQuery.executeQuery();

        while (getElementListQueryResult.next())
          elementList.add(
              new Element(
                  getElementListQueryResult.getString(Global.ELEMENT),
                  getElementListQueryResult.getString(Global.ELEMENT_FORMAT)));

        getElementListQueryResult.close();
        getElementListQuery.close();
        conn.close();
      } catch (Exception e) {
        MetaDbHelper.logEvent(e);
      }
    }
    return elementList;
  }
Example #2
0
 /**
  * Check if an element exists in the system.
  *
  * @param elementName The element to be checked for existence.
  * @return true if the element exists, false otherwise.
  */
 public static boolean elementExists(String elementName) {
   try {
     ArrayList<String> elementList = (ArrayList<String>) getElementList();
     for (String element : elementList) {
       if (element.equals(elementName)) return true;
     }
   } catch (Exception e) {
     MetaDbHelper.logEvent(e);
   }
   return false;
 }
Example #3
0
  /**
   * Deletes an element from MetaDB.
   *
   * @param elementName The desired element name to be added
   * @return true if the element with name elementName was deleted, false otherwise
   */
  public static boolean deleteElement(String elementName) {
    Connection conn = Conn.initialize();
    if (conn != null) {
      try {
        PreparedStatement deleteElement = conn.prepareStatement(DELETE_ELEMENT);

        deleteElement.setString(1, elementName);
        deleteElement.executeUpdate();

        deleteElement.close();
        conn.close();

        return true;
      } catch (Exception e) {
        MetaDbHelper.logEvent(e);
      }
    }
    return false;
  }
Example #4
0
  /**
   * Returns all the elements in the database.
   *
   * @return a List of all elements in MetaDB.
   */
  public static ArrayList<String> getElementList() {
    ArrayList<String> elementList = new ArrayList<String>();

    Connection conn = Conn.initialize();
    if (conn != null) {
      try {

        PreparedStatement getElementListQuery = conn.prepareStatement(GET_ELEMENT_LIST);
        ResultSet getElementListQueryResult = getElementListQuery.executeQuery();

        while (getElementListQueryResult.next())
          elementList.add(getElementListQueryResult.getString(Global.ELEMENT));

        getElementListQueryResult.close();
        getElementListQuery.close();
        conn.close();
      } catch (Exception e) {
        MetaDbHelper.logEvent(e);
      }
    }
    return elementList;
  }