package compbio.cassandra; import java.util.Calendar; import java.util.Date; 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 com.datastax.driver.core.exceptions.QueryExecutionException; import compbio.engine.ProteoCachePropertyHelperManager; import compbio.cassandra.CassandraNativeConnector; public class CassandraNewTableWriter { private Session session; private static Logger log = Logger.getLogger(CassandraNativeConnector.class); public CassandraNewTableWriter() { Session inis = CassandraNativeConnector.getSession(); setSession(inis); } public void setSession(Session s) { assert s != null; session = s; } 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; } /* * fill new table */ public void FillNewTable() { final long StartTime = System.currentTimeMillis(); long erldate = CassandraNativeConnector.getEarliestDateInDB(); Calendar runnicCal = Calendar.getInstance(); runnicCal.setTime(new Date(erldate)); Calendar endcal = Calendar.getInstance(); long endTime = endcal.getTime().getTime(); for (Date date = runnicCal.getTime(); date.getTime() < endTime; runnicCal.add(Calendar.DATE, 1), date = runnicCal.getTime()) { try { ResultSet results = session.execute("SELECT * FROM ProteinData WHERE jobtime = " + date.getTime() + ";"); session.execute("INSERT INTO JobDateInfo " + "(jobday, Total)" + " VALUES (" + date.getTime() + "," + results.all().size() + ");"); } catch (QueryExecutionException e) { e.printStackTrace(); } } System.out.println("Table JobDateInfo filled: total time is " + (System.currentTimeMillis() - StartTime) + " msec"); } /* * fill a table with the database global parameters */ public void FillMainDBParameters() { Date bubu = new Date(CassandraNativeConnector.getEarliestDateInDB()); System.out.println("Old EarliestJobDate is " + bubu.toString()); String query1 = "SELECT jobtime FROM ProteinData LIMIT 2000000;"; System.out.println("Query db: " + query1); ResultSet results = session.execute(query1); Calendar endcal = Calendar.getInstance(); long newearliestday = endcal.getTime().getTime(); while (!results.isExhausted()) { Row r = results.one(); long day = r.getLong("jobtime"); if (day < newearliestday) { newearliestday = day; } } String com = "INSERT INTO MainParameters " + "(Name, Value)" + " VALUES ('EarliestJobDate','" + String.valueOf(newearliestday) + "');"; session.execute(com); Date gaga = new Date(newearliestday); System.out.println("New EarliestJobDate is " + gaga.toString()); } }