1 package compbio.cassandra.readers;
3 import org.apache.log4j.Logger;
5 import com.datastax.driver.core.ResultSet;
6 import com.datastax.driver.core.Session;
7 import com.datastax.driver.core.exceptions.QueryExecutionException;
8 import com.datastax.driver.core.exceptions.QueryValidationException;
10 import compbio.cassandra.CassandraNativeConnector;
13 * basic reader of the ProteoCache database. It depends on open
14 * CassandraNativeConnector, which should provide an open session to the
15 * ProteoCache DB (in the default constructor)
20 public class CassandraReader {
21 protected static long earlestDate = 0;
22 protected Session session;
23 protected static Logger log = Logger.getLogger(CassandraNativeConnector.class);
26 * default constructor.
28 public CassandraReader() {
29 Session inis = CassandraNativeConnector.getSession();
33 public void setSession(Session s) {
39 * Basic query to the DB. The method throws exception if the input command
40 * is not valid or if there is a problem with execution of the command
42 * @param command - reading CQL command
43 * @return resulting outout of the command
45 protected ResultSet CassandraQuery(String command) {
47 ResultSet results = session.execute(command);
49 } catch (QueryExecutionException e) {
50 String mess = "ProteoCache Cassandra DB interface: query execution exception...\n Command: " + command;
51 System.out.println(mess);
53 log.error(e.getLocalizedMessage(), e.getCause());
55 } catch (QueryValidationException e) {
56 String mess = "CProteoCache Cassandra DB interface: query validation exception...\n Command: " + command;
57 System.out.println(mess);
59 log.error(e.getLocalizedMessage(), e.getCause());
66 * finds the earliest date in the database
68 * @return the earliest date (long)
70 public static long earliestDate() {
71 earlestDate = CassandraNativeConnector.getEarliestDateInDB();
76 * prepares an example of either job id or IP for the DB
79 * defines which example you need (an existing job from the DB -
80 * jobid, an IP - "ip")
81 * @return a string representation of the requested example, if the example
82 * type is not known empty string is returned
84 public String getExample(String exampletype) {
85 if (exampletype.equals("jobid")) {
87 } else if (exampletype.equals("ip")) {