package compbio.cassandra.readers; import org.apache.log4j.Logger; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Session; import com.datastax.driver.core.exceptions.QueryExecutionException; import com.datastax.driver.core.exceptions.QueryValidationException; import compbio.cassandra.CassandraNativeConnector; public class CassandraReader { protected static long earlestDate = 0; protected Session session; protected static Logger log = Logger.getLogger(CassandraNativeConnector.class); public CassandraReader() { Session inis = CassandraNativeConnector.getSession(); setSession(inis); } public void setSession(Session s) { assert s != null; session = s; } protected ResultSet CassandraQuery(String command) { try { ResultSet results = session.execute(command); return results; } catch (QueryExecutionException e) { String mess = "ProteoCache Cassandra DB interface: query execution exception...\n Command: " + command; System.out.println(mess); log.error(mess); log.error(e.getLocalizedMessage(), e.getCause()); return null; } catch (QueryValidationException e) { String mess = "CProteoCache Cassandra DB interface: query validation exception...\n Command: " + command; System.out.println(mess); log.error(mess); log.error(e.getLocalizedMessage(), e.getCause()); return null; } } /* * find the earliest date in the database */ public static long earliestDate() { earlestDate = CassandraNativeConnector.getEarliestDateInDB(); return earlestDate; } /** * prepares an example of either job id or IP for the DB * * @param exampletype * defines which example you need (an existing job from the DB - * jobid, an IP - "ip") * @return a string representation of the requested example, if the example * type is not known empty string is returned */ public String getExample(String exampletype) { if (exampletype.equals("jobid")) { return "jp_NzBOJKo"; } else if (exampletype.equals("ip")) { return "127.0.0.1"; } return ""; } }