Still not-working system for reading cassandra
authorSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Fri, 8 Nov 2013 12:11:41 +0000 (12:11 +0000)
committerSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Fri, 8 Nov 2013 12:11:41 +0000 (12:11 +0000)
datadb/compbio/cassandra/CassandraReader.java [new file with mode: 0644]
datadb/compbio/cassandra/readers/CassandraReaderExecutionTime.java [new file with mode: 0644]

diff --git a/datadb/compbio/cassandra/CassandraReader.java b/datadb/compbio/cassandra/CassandraReader.java
new file mode 100644 (file)
index 0000000..d2d2e1b
--- /dev/null
@@ -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 (file)
index 0000000..8648aeb
--- /dev/null
@@ -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<Pair<String, String>> 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<Row> rows = results.all();
+               System.out.println("Query time is " + (queryTime - startTime) + " msec");
+
+               List<Pair<String, String>> res = new ArrayList<Pair<String, String>>();
+               int c = 0;
+               for (Row r : rows) {
+                       Pair<String, String> pair = new Pair<String, String>(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;
+       }
+
+}