Example #1
0
 @Override
 public Timeline[] getTimelines() { // this could probably be split up into methods
   open();
   try {
     resultSet =
         statement.executeQuery(
             "select name from sqlite_master where type = \"table\" "
                 + "and name != \"sqlite_sequence\" and name != \"timeline_info\";");
     ArrayList<String> timelineNames = new ArrayList<String>();
     int numTimelines = 0;
     while (resultSet.next()) { // Get all timeline names
       numTimelines++;
       timelineNames.add(resultSet.getString(1));
     }
     Timeline[] timelines = new Timeline[numTimelines];
     for (int j = 0; j < numTimelines; j++) { // Get all timelines event arrays
       resultSet = statement.executeQuery("select * from " + timelineNames.get(j) + ";");
       ArrayList<TLEvent> events = new ArrayList<TLEvent>();
       int numEvents = 0;
       while (resultSet.next()) { // Get all events for the event
         numEvents++;
         String name = resultSet.getString("eventName");
         String type = resultSet.getString("type");
         TLEvent event = null;
         if (type.equals("atomic")) {
           String category = resultSet.getString("Category");
           Date startDate = resultSet.getDate("startDate");
           event = new Atomic(name, category, startDate); // TODO Get category from database.
         } else if (type.equals("duration")) {
           String category = resultSet.getString("Category");
           Date startDate = resultSet.getDate("startDate");
           Date endDate = resultSet.getDate("endDate");
           event =
               new Duration(
                   name, category, startDate, endDate); // TODO Get category from database.
         } else {
           System.out.println("YOU DONE MESSED UP.");
         }
         events.add(event);
       }
       int label = getAxisLabel(timelineNames.get(j));
       Timeline timeline =
           new Timeline(timelineNames.get(j), events.toArray(new TLEvent[numEvents]), label);
       timelines[j] = timeline;
     }
     close();
     return timelines;
   } catch (SQLException e) {
     e.printStackTrace();
   }
   close();
   return null;
 }
Example #2
0
 /**
  * Initializes the timeline_info database. This can store various timeline attributes though
  * currently only has 1, axisLabel
  */
 private void init() {
   open();
   try {
     statement.executeUpdate(
         "CREATE TABLE timeline_info (" + ID + ", timelineName TEXT, axisLabel TEXT);");
   } catch (SQLException e) {
     if (e.getMessage().contains("already exists")) {
       // it has already been created, no issues
     } else e.printStackTrace();
   }
   close();
 }
Example #3
0
 @Override
 public boolean removeTimeline(Timeline timeline) {
   open();
   try {
     statement.executeUpdate("DROP TABLE IF EXISTS'" + timeline.getName() + "';");
     removeAxisLabel(timeline.getName());
   } catch (SQLException e) {
     e.printStackTrace();
   }
   close();
   return true;
 }
Example #4
0
 @Override
 public boolean writeTimeline(Timeline timeline) {
   String tlName = timeline.getName();
   open();
   try {
     statement.executeUpdate(
         "CREATE TABLE "
             + tlName
             + " ("
             + ID
             + ",eventName TEXT, type TEXT, startDate DATETIME, endDate DATETIME, category TEXT);");
     writeAxisLabel(tlName, timeline.getAxisLabel());
   } catch (SQLException e) {
     if (e.getMessage().contains("already exists")) {
       System.out.println("A timeline with that name already exists!");
       return false;
     }
     e.printStackTrace();
   }
   if (timeline.getEvents() == null) return false;
   for (TLEvent event : timeline.getEvents()) {
     try {
       if (event instanceof Atomic) {
         writeEvent((Atomic) event, tlName);
       } else if (event instanceof Duration) {
         writeEvent((Duration) event, tlName);
       }
     } catch (SQLException e) {
       e.printStackTrace();
     } catch (NullPointerException e) {
       System.out.println("Nothing!");
     }
   }
   close();
   return true;
 }