/** * 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; }
/** * 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; }
/** * 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; }