1 package compbio.cassandra;
3 import java.util.Calendar;
7 import org.apache.log4j.Logger;
9 import com.datastax.driver.core.Row;
10 import com.datastax.driver.core.Session;
11 import com.datastax.driver.core.ResultSet;
12 import com.datastax.driver.core.exceptions.QueryExecutionException;
14 import compbio.cassandra.CassandraNativeConnector;
16 public class CassandraNewTableWriter {
17 private Session session;
18 private static Logger log = Logger.getLogger(CassandraNativeConnector.class);
20 public CassandraNewTableWriter() {
21 Session inis = CassandraNativeConnector.getSession();
25 public void setSession(Session s) {
30 public boolean JobisNotInsterted(String jobid) {
31 ResultSet results1 = session.execute("SELECT * FROM ProteinLog WHERE JobID = '" + jobid + "';");
32 if (results1.isExhausted()) {
38 public boolean JobisNotArchived(String jobid) {
39 ResultSet results1 = session.execute("SELECT * FROM JpredArchive WHERE JobID = '" + jobid + "';");
40 if (results1.isExhausted()) {
47 * update programme name and version
49 public void FillNewParameter() {
50 System.out.println("Updating....");
52 final long StartTime = System.currentTimeMillis();
53 long erldate = CassandraNativeConnector.getEarliestDateInDB();
54 Calendar runnicCal = Calendar.getInstance();
55 runnicCal.setTime(new Date(erldate));
56 Calendar endcal = Calendar.getInstance();
57 long endTime = endcal.getTime().getTime();
58 for (Date date = runnicCal.getTime(); date.getTime() < endTime; runnicCal.add(Calendar.DATE, 1), date = runnicCal.getTime()) {
60 String com = "SELECT JobID, Protein FROM ProteinData WHERE jobtime = " + date.getTime() + ";";
61 System.out.println(com);
62 ResultSet results = session.execute(com);
63 if (results == null || results.isExhausted())
65 List<Row> rows = results.all();
66 System.out.println(rows.size());
68 session.execute("UPDATE ProteinLog SET ProgramName = 'Jpred', ProgramVersion = '3.0.1' WHERE JobID = '"
69 + r.getString("JobID") + "';");
70 session.execute("UPDATE JpredArchive SET ProgramName = 'Jpred', ProgramVersion = '3.0.1' WHERE JobID = '"
71 + r.getString("JobID") + "';");
73 } catch (QueryExecutionException e) {
77 System.out.println("Table ProteinLog filled: total time is " + (System.currentTimeMillis() - StartTime) + " msec");
83 public void FillNewTable() {
84 final long StartTime = System.currentTimeMillis();
85 long erldate = CassandraNativeConnector.getEarliestDateInDB();
86 Calendar runnicCal = Calendar.getInstance();
87 runnicCal.setTime(new Date(erldate));
88 Calendar endcal = Calendar.getInstance();
89 long endTime = endcal.getTime().getTime();
90 for (Date date = runnicCal.getTime(); date.getTime() < endTime; runnicCal.add(Calendar.DATE, 1), date = runnicCal.getTime()) {
92 ResultSet results = session.execute("SELECT * FROM ProteinData WHERE jobtime = " + date.getTime() + ";");
93 session.execute("INSERT INTO JobDateInfo " + "(jobday, Total)" + " VALUES (" + date.getTime() + "," + results.all().size()
95 } catch (QueryExecutionException e) {
99 System.out.println("Table JobDateInfo filled: total time is " + (System.currentTimeMillis() - StartTime) + " msec");
103 * fill a table with the database global parameters
105 public void FillMainDBParameters() {
106 Date bubu = new Date(CassandraNativeConnector.getEarliestDateInDB());
107 System.out.println("Old EarliestJobDate is " + bubu.toString());
109 String query1 = "SELECT jobtime FROM ProteinData LIMIT 2000000;";
110 System.out.println("Query db: " + query1);
111 ResultSet results = session.execute(query1);
112 Calendar endcal = Calendar.getInstance();
113 long newearliestday = endcal.getTime().getTime();
114 while (!results.isExhausted()) {
115 Row r = results.one();
116 long day = r.getLong("jobtime");
117 if (day < newearliestday) {
118 newearliestday = day;
121 String com = "INSERT INTO MainParameters " + "(Name, Value)" + " VALUES ('EarliestJobDate','" + String.valueOf(newearliestday)
123 session.execute(com);
124 Date gaga = new Date(newearliestday);
125 System.out.println("New EarliestJobDate is " + gaga.toString());