Example #1
0
 /** Test of insert method, of class Flight. */
 @Test
 public void testInsert() throws Exception {
   f1.insert(db);
   ResultSet rs = db.execute("SELECT * FROM Flights ORDER BY id ASC");
   rs.last();
   assertEquals(rs.getString("startdestination"), "Copenhagen");
   assertEquals(rs.getString("enddestination"), "London");
   assertEquals(rs.getInt("numberofseats"), 100);
   assertEquals(rs.getString("timestamp"), "14:00");
 }
Example #2
0
  /** Test of delete method, of class Flight. */
  @Test
  public void testDelete() throws Exception {
    System.out.println("delete");
    ResultSet rs = db.execute("SELECT * FROM Flights");
    rs.last();
    int id = rs.getInt("id");
    rs.close();

    ResultSet rs2 = db.execute("SELECT COUNT(*) AS rowcount FROM Flights");
    rs2.next();
    int rc = rs2.getInt("rowcount");
    rs2.close();

    f1.delete(db, id);

    ResultSet rs3 = db.execute("SELECT COUNT(*) AS rowcount2 FROM Flights");
    rs3.next();
    int rc2 = rs3.getInt("rowcount2");

    assertEquals(rc - 1, rc2);
  }
 @Before
 public void setUp() {
   database.execute("delete from receipts");
 }
 /** Creates the required mysql tables and updates the db if needed. */
 private void createTables() {
   int ver = NameLayerPlugin.getVersionNum(plugin.getName());
   long begin_time = System.currentTimeMillis();
   if (ver == 0) {
     db.execute(
         String.format(
             "update db_version set plugin_name = '%s' " + "where plugin_name is null",
             plugin.getName()));
     ver = NameLayerPlugin.getVersionNum(plugin.getName());
     if (ver == 0) {
       Citadel.Log("Creating tables from scratch, this is a new " + "instance of citadel.");
     } else {
       Citadel.Log(
           "Detected previous version of Citadel, "
               + "updating to new db.\n"
               + "You should have backed up your data, "
               + "if you havent already you have ten seconds to"
               + " shut down the server and perform a backup.");
       try {
         Thread.sleep(10000);
       } catch (InterruptedException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
       }
       long first_time = System.currentTimeMillis();
       db.execute(
           "alter table reinforcement drop security_level, drop version, add group_id int not null;");
       /*
       Citadel.Log("Remapping from material id to material name " +
       		"in process.");
       db.execute("create table if not exists material_mapping("
       		+ "" +
       		"material varchar(40) not null," +
       		"material_id int not null);");
       db.execute("create index x on material_mapping (material_id);");
       for (Material mat: Material.values()){
       	PreparedStatement insert = db.prepareStatement
       			("insert into material_mapping(" +
       			"material, material_id) values(?,?);");
       	try {
       		insert.setString(1, mat.name());
       		insert.setInt(2, mat.getId());
       		insert.execute();
       	} catch (SQLException e) {
       		// TODO Auto-generated catch block
       		e.printStackTrace();
       	}
       }
       db.execute("alter table reinforcement add " +
       		"material varchar(10)");
       db.execute("update reinforcement r " +
       		"inner join material_mapping m on m.material_id = r.material_id " +
       		"set r.material = m.material;");
       db.execute("alter table reinforcement drop material_id;");
       db.execute("drop table material_mapping;");
       */
       db.execute(
           "insert into faction_id (group_name) values (null);"); // For natural reinforcements
       db.execute("delete from reinforcement where `name` is null;");
       db.execute(
           "update ignore reinforcement r inner join faction_id f on f.group_name = r.`name` "
               + "set r.group_id = f.group_id;");
       db.execute(
           "alter table reinforcement drop `name`, add rein_type_id int not null default 1, "
               + "add lore varchar(255);");
       db.execute("drop table citadel_account_id_map;");
       Citadel.Log(
           "The update to new format took "
               + (System.currentTimeMillis() - first_time) / 1000
               + " seconds.");
     }
   }
   if (ver == 5 || ver == 0) {
     long first_time = System.currentTimeMillis();
     Citadel.Log("Updating to Citadel Version 6.");
     db.execute(
         "create table if not exists reinforcement("
             + "x int not null,"
             + "y int not null,"
             + "z int not null,"
             + "world varchar(10) not null,"
             + "material_id int not null,"
             + "durability varchar(10) not null,"
             + "chunk_id varchar(255) not null,"
             + "insecure tinyint(1) not null,"
             + "group_id int not null,"
             + "maturation_time int not null,"
             + "rein_type_id int not null,"
             + "lore varchar(255),"
             + "primary key (x,y,z,world));");
     db.execute(
         "create table if not exists reinforcement_type("
             + "rein_type_id int not null auto_increment,"
             + "rein_type varchar(30) not null,"
             + "primary key rein_type_key (rein_type_id));");
     String[] types = {"PlayerReinforcement", "NaturalReinforcement", "MultiBlockReinforcement"};
     for (String x : types)
       db.execute(String.format("insert into reinforcement_type(rein_type)" + "values('%s');", x));
     NameLayerPlugin.insertVersionNum(5, plugin.getName());
     ver = NameLayerPlugin.getVersionNum(plugin.getName());
     Citadel.Log(
         "The update to Version 6 took "
             + (System.currentTimeMillis() - first_time) / 1000
             + " seconds.");
   }
   if (ver == 6) {
     long first_time = System.currentTimeMillis();
     Citadel.Log("Updating to version 7. No fun message for you :(");
     db.execute(
         "create table if not exists reinforcement_id("
             + "rein_id int not null auto_increment,"
             + "x int not null,"
             + "y int not null,"
             + "z int not null,"
             + "chunk_id varchar(255),"
             + "world varchar (255) not null,"
             + "primary key rein_id_key (rein_id),"
             + "unique key x_y_z_world(x,y,z,world));-- Your mother is a w***e and sleeps with banjos");
     // I like turtles mother f****r. Never program because then you get turtles.
     db.execute(
         "insert into reinforcement_id (x, y, z, chunk_id, world) select x, y, z, chunk_id, world from reinforcement;"); // populate that bitch.
     db.execute("alter table reinforcement add rein_id int not null, drop chunk_id;");
     db.execute(
         "update reinforcement r inner join reinforcement_id ri on "
             + "ri.x = r.x and ri.y = r.y and ri.z = r.z and ri.world = r.world "
             + "set r.rein_id = ri.rein_id");
     db.execute(
         "alter table reinforcement DROP PRIMARY KEY, "
             + "add primary key rein_id_key(rein_id), "
             + "drop x,"
             + "drop y,"
             + "drop z,"
             + "drop world;");
     db.execute("alter table reinforcement_id add index `chunk_id_index` (chunk_id);");
     NameLayerPlugin.insertVersionNum(ver, plugin.getName());
     ver = NameLayerPlugin.getVersionNum(plugin.getName());
     Citadel.Log(
         "The update to Version 7 took "
             + (System.currentTimeMillis() / first_time) / 1000
             + " seconds.");
   }
   Citadel.Log(
       "The total time it took Citadel to update was "
           + (System.currentTimeMillis() - begin_time) / 1000
           + " seconds.");
 }