Add servlets for queries with IP
[proteocache.git] / datadb / compbio / cassandra / readers / CassandraReaderExecutionTime.java
1 package compbio.cassandra.readers;
2
3
4 import java.util.Calendar;
5 import java.util.List;
6 import java.util.ArrayList;
7
8 import org.apache.log4j.Logger;
9
10 import com.datastax.driver.core.Row;
11 import com.datastax.driver.core.Session;
12 import com.datastax.driver.core.ResultSet;
13 import com.datastax.driver.core.PreparedStatement;
14 import com.datastax.driver.core.BoundStatement;
15
16 import compbio.cassandra.CassandraReader;
17 import compbio.cassandra.Pair;
18 import compbio.engine.ProteoCachePropertyHelperManager;
19 import compbio.util.PropertyHelper;
20
21 public class CassandraReaderExecutionTime {
22         private Session session;
23
24         public static String CASSANDRA_HOSTNAME = "localhost";
25         public static boolean READ_WEB_JPRED = false;
26         public static boolean READ_LOCALFILE_JPRED = false;
27
28         public void setSession(Session s) {
29                 assert s != null;
30                 session = s;
31         }
32
33         private void setConditions() {
34
35         }
36
37         public boolean JobisNotInsterted(String jobid) {
38                 ResultSet results1 = session.execute("SELECT * FROM ProteinLog WHERE JobID = '" + jobid + "';");
39                 if (results1.isExhausted()) {
40                         return true;
41                 }
42                 return false;
43         }
44
45         public boolean JobisNotArchived(String jobid) {
46                 ResultSet results1 = session.execute("SELECT * FROM JpredArchive WHERE JobID = '" + jobid + "';");
47                 if (results1.isExhausted()) {
48                         return true;
49                 }
50                 return false;
51         }
52
53         /*
54          * getting data from the db
55          */
56         public List<Pair<String, String>> ReadProteinDataTable() {
57                 final long startTime = System.currentTimeMillis();
58                 String com = "SELECT DataBegin,DataEnd FROM ProteinKeyspace.ProteinLog;";
59                 System.out.println("Command: " + com);
60                 ResultSet results = session.execute(com);
61                 final long queryTime = System.currentTimeMillis();
62                 List<Row> rows = results.all();
63                 System.out.println("Query time is " + (queryTime - startTime) + " msec");
64
65                 List<Pair<String, String>> res = new ArrayList<Pair<String, String>>();
66                 int c = 0;
67                 for (Row r : rows) {
68                         Pair<String, String> pair = new Pair<String, String>(r.getString("DataBegin"), r.getString("DataEnd"));
69                         res.add(pair);
70                         ++c;
71                 }
72                 final long endTime = System.currentTimeMillis();
73                 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
74                 return res;
75         }
76
77         /*
78          * getting earlest date of jobs from the db
79          */
80         public long getEarliestDateInDB() {
81                 final long startTime = System.currentTimeMillis();
82                 String com = "SELECT jobtime FROM ProteinKeyspace.ProteinData;";
83                 System.out.println("Command: " + com);
84                 ResultSet results = session.execute(com);
85                 final long queryTime = System.currentTimeMillis();
86                 System.out.println("Query time is " + (queryTime - startTime) + " msec");
87
88                 Calendar cal = Calendar.getInstance();
89                 long res = cal.getTimeInMillis();
90                 int c = 0;
91                 while (!results.isExhausted()) {
92                         Row r = results.one();
93                         long d1 = r.getLong("jobtime");
94                         if (res > d1) {
95                                 res = d1;
96                         }
97                         ++c;
98                 }
99                 final long endTime = System.currentTimeMillis();
100                 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
101                 return res;
102         }
103
104 }