Ejemplo n.º 1
0
 public static void main(String[] args) {
   DBHelper helper = new DBHelper("databases/timeline.db");
   TLEvent event1 = new Atomic("one", "", new Date(((long) 1000) * 60 * 60 * 24));
   TLEvent event2 =
       new Duration(
           "two",
           "",
           new Date(((long) 1000) * 60 * 60 * 24),
           new Date(((long) 1000) * 60 * 60 * 24 * 2));
   Timeline test1 = new Timeline("Test1", 0);
   Timeline test2 = new Timeline("Test2", 2);
   test1.addEvent(event1);
   test1.addEvent(event2);
   helper.removeTimeline(test1);
   helper.removeTimeline(test2);
   helper.writeTimeline(test1);
   helper.writeTimeline(test2);
   helper.removeTimeline(test1);
   helper.changeTimeline(test2, test1);
   Timeline[] timelines = helper.getTimelines();
   for (Timeline timeline : timelines) {
     System.out.println("-----" + timeline.getName() + "-----");
     TLEvent[] events = timeline.getEvents();
     for (TLEvent event : events) {
       System.out.println(event.getName());
     }
   }
   System.out.println("Finished!");
 }
Ejemplo n.º 2
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;
 }