From 6097c3a4b7510ced14696c7ec98981b0cd0cea01 Mon Sep 17 00:00:00 2001 From: Sasha Sherstnev Date: Fri, 8 Nov 2013 12:11:41 +0000 Subject: [PATCH] Still not-working system for reading cassandra --- datadb/compbio/cassandra/CassandraReader.java | 16 +++ .../readers/CassandraReaderExecutionTime.java | 104 ++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 datadb/compbio/cassandra/CassandraReader.java create mode 100644 datadb/compbio/cassandra/readers/CassandraReaderExecutionTime.java diff --git a/datadb/compbio/cassandra/CassandraReader.java b/datadb/compbio/cassandra/CassandraReader.java new file mode 100644 index 0000000..d2d2e1b --- /dev/null +++ b/datadb/compbio/cassandra/CassandraReader.java @@ -0,0 +1,16 @@ +package compbio.cassandra; + +import com.datastax.driver.core.Session; + +public interface CassandraReader { + + /* + * Defines a source file with metainformation of Jpred Jobs + **/ + void setSession (Session s); + + /* + * Makes real parsing of the source file + **/ + /*void getResults();*/ +} diff --git a/datadb/compbio/cassandra/readers/CassandraReaderExecutionTime.java b/datadb/compbio/cassandra/readers/CassandraReaderExecutionTime.java new file mode 100644 index 0000000..8648aeb --- /dev/null +++ b/datadb/compbio/cassandra/readers/CassandraReaderExecutionTime.java @@ -0,0 +1,104 @@ +package compbio.cassandra.readers; + + +import java.util.Calendar; +import java.util.List; +import java.util.ArrayList; + +import org.apache.log4j.Logger; + +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.PreparedStatement; +import com.datastax.driver.core.BoundStatement; + +import compbio.cassandra.CassandraReader; +import compbio.cassandra.Pair; +import compbio.engine.ProteoCachePropertyHelperManager; +import compbio.util.PropertyHelper; + +public class CassandraReaderExecutionTime implements CassandraReader { + private Session session; + + public static String CASSANDRA_HOSTNAME = "localhost"; + public static boolean READ_WEB_JPRED = false; + public static boolean READ_LOCALFILE_JPRED = false; + + public void setSession(Session s) { + assert s != null; + session = s; + } + + private void setConditions() { + + } + + public boolean JobisNotInsterted(String jobid) { + ResultSet results1 = session.execute("SELECT * FROM ProteinLog WHERE JobID = '" + jobid + "';"); + if (results1.isExhausted()) { + return true; + } + return false; + } + + public boolean JobisNotArchived(String jobid) { + ResultSet results1 = session.execute("SELECT * FROM JpredArchive WHERE JobID = '" + jobid + "';"); + if (results1.isExhausted()) { + return true; + } + return false; + } + + /* + * getting data from the db + */ + public List> ReadProteinDataTable() { + final long startTime = System.currentTimeMillis(); + String com = "SELECT DataBegin,DataEnd FROM ProteinKeyspace.ProteinLog;"; + System.out.println("Command: " + com); + ResultSet results = session.execute(com); + final long queryTime = System.currentTimeMillis(); + List rows = results.all(); + System.out.println("Query time is " + (queryTime - startTime) + " msec"); + + List> res = new ArrayList>(); + int c = 0; + for (Row r : rows) { + Pair pair = new Pair(r.getString("DataBegin"), r.getString("DataEnd")); + res.add(pair); + ++c; + } + final long endTime = System.currentTimeMillis(); + System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec"); + return res; + } + + /* + * getting earlest date of jobs from the db + */ + public long getEarliestDateInDB() { + final long startTime = System.currentTimeMillis(); + String com = "SELECT jobtime FROM ProteinKeyspace.ProteinData;"; + System.out.println("Command: " + com); + ResultSet results = session.execute(com); + final long queryTime = System.currentTimeMillis(); + System.out.println("Query time is " + (queryTime - startTime) + " msec"); + + Calendar cal = Calendar.getInstance(); + long res = cal.getTimeInMillis(); + int c = 0; + while (!results.isExhausted()) { + Row r = results.one(); + long d1 = r.getLong("jobtime"); + if (res > d1) { + res = d1; + } + ++c; + } + final long endTime = System.currentTimeMillis(); + System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec"); + return res; + } + +} -- 1.7.10.2