private void testSimpleUpdateWithCombinedPrimaryKey() {
    Order o = new Order();
    Order ourOrder = db.from(o).where(o.orderDate).is(valueOf("2007-01-02")).selectFirst();
    ourOrder.orderDate = valueOf("2007-01-03");
    db.update(ourOrder);

    Order ourUpdatedOrder = db.from(o).where(o.orderDate).is(valueOf("2007-01-03")).selectFirst();
    assertTrue("updated order not found", ourUpdatedOrder != null);

    // undo update
    ourOrder.orderDate = valueOf("2007-01-02");
    db.update(ourOrder);
  }
Exemple #2
0
 public static int addNullWarranty() {
   DBWrapper dbw = new DBWrapper();
   Db db = dbw.openConnection();
   Warranty w = new Warranty();
   w.Note = "неопределено";
   w.Warr = "нет";
   db.insert(w);
   w = db.from(w).orderByDesc(w.Kodwarr).selectFirst();
   return w.Kodwarr;
 }
  private void testSimpleMerge() {
    Product p = new Product();
    Product pChang = db.from(p).where(p.productName).is("Chang").selectFirst();
    // update unitPrice from 19.0 to 19.5
    pChang.unitPrice = 19.5;
    // update unitsInStock from 17 to 16
    pChang.unitsInStock = 16;
    db.merge(pChang);

    Product p2 = new Product();
    Product pChang2 = db.from(p2).where(p2.productName).is("Chang").selectFirst();
    assertEquals(19.5, pChang2.unitPrice);
    assertEquals(16, pChang2.unitsInStock.intValue());

    // undo update
    pChang.unitPrice = 19.0;
    pChang.unitsInStock = 17;
    db.merge(pChang);
  }
Exemple #4
0
 public static int addWarranty(String warr) {
   DBWrapper dbw = new DBWrapper();
   Db db = dbw.openConnection();
   Warranty w = new Warranty();
   if (warr.isEmpty()) {
     w.Warr = "нет";
   } else w.Warr = warr;
   db.insert(w);
   w = db.from(w).orderByDesc(w.Kodwarr).selectFirst();
   return w.Kodwarr;
 }
Exemple #5
0
 public void setTableItem(String pasport, int column, String text) {
   DBWrapper dbw = new DBWrapper();
   Db db = dbw.openConnection();
   Clients c = new Clients();
   switch (column) {
     case 0:
       db.from(c).set(c.Surname).to(text).where(c.Passport).is(pasport).update();
       break;
     case 1:
       db.from(c).set(c.Name).to(text).where(c.Passport).is(pasport).update();
       break;
     case 2:
       db.from(c).set(c.Ochestvo).to(text).where(c.Passport).is(pasport).update();
       break;
     case 3:
       db.from(c).set(c.Mphone).to(text).where(c.Passport).is(pasport).update();
       break;
     case 4:
       db.from(c).set(c.Passport).to(text).where(c.Passport).is(pasport).update();
       break;
     case 5:
       db.from(c).set(c.Prava).to(text).where(c.Passport).is(pasport).update();
       break;
     default:
   }
 }
Exemple #6
0
 public static Map<Integer, String> getClientCarsList(int clientId) {
   DBWrapper dbw = new DBWrapper();
   Db db = dbw.openConnection();
   Car c = new Car();
   Map<Integer, String> mp = new HashMap<Integer, String>();
   List<Car> ls = db.from(c).where(c.Kodclient).is(clientId).select();
   Iterator<Car> it = ls.iterator();
   while (it.hasNext()) {
     Car temp = (Car) it.next();
     mp.put(temp.Kodavto, temp.Mark);
   }
   return mp;
 }
Exemple #7
0
  public static Map<Integer, String> getClientsList() {
    DBWrapper dbw = new DBWrapper();
    Db db = dbw.openConnection();
    Clients c = new Clients();
    Map<Integer, String> mp = new HashMap<Integer, String>();
    List<Clients> ls = db.from(c).select();
    Iterator<Clients> it = ls.iterator();
    while (it.hasNext()) {
      Clients temp = (Clients) it.next();
      mp.put(temp.Kodclient, temp.Surname + " " + temp.Name + " " + temp.Ochestvo);
    }

    return mp;
  }
  private void testSetColumns() {
    Product p = new Product();
    Product original = db.from(p).where(p.productId).is(1).selectFirst();

    // update  string and double columns
    db.from(p)
        .set(p.productName)
        .to("updated")
        .increment(p.unitPrice)
        .by(3.14)
        .increment(p.unitsInStock)
        .by(2)
        .where(p.productId)
        .is(1)
        .update();

    // confirm the data was properly updated
    Product revised = db.from(p).where(p.productId).is(1).selectFirst();
    assertEquals("updated", revised.productName);
    assertEquals(original.unitPrice + 3.14, revised.unitPrice);
    assertEquals(original.unitsInStock + 2, revised.unitsInStock.intValue());

    // restore the data
    db.from(p)
        .set(p.productName)
        .to(original.productName)
        .set(p.unitPrice)
        .to(original.unitPrice)
        .increment(p.unitsInStock)
        .by(-2)
        .where(p.productId)
        .is(1)
        .update();

    // confirm the data was properly restored
    Product restored = db.from(p).where(p.productId).is(1).selectFirst();
    assertEquals(original.productName, restored.productName);
    assertEquals(original.unitPrice, restored.unitPrice);
    assertEquals(original.unitsInStock, restored.unitsInStock);

    double unitPriceOld = db.from(p).where(p.productId).is(1).selectFirst().unitPrice;
    // double the unit price
    db.from(p).increment(p.unitPrice).by(p.unitPrice).where(p.productId).is(1).update();
    double unitPriceNew = db.from(p).where(p.productId).is(1).selectFirst().unitPrice;
    assertEquals(unitPriceOld * 2, unitPriceNew);
  }
Exemple #9
0
 public void fillingTable(Table table) {
   DBWrapper dbw = new DBWrapper();
   Db db = dbw.openConnection();
   Clients c = new Clients();
   List<Clients> idd = db.from(c).select();
   Iterator<Clients> it1 = idd.iterator();
   while (it1.hasNext()) {
     Clients temp = (Clients) it1.next();
     TableItem item = new TableItem(table, SWT.NONE);
     item.setText(0, temp.Surname);
     item.setText(1, temp.Name);
     item.setText(2, temp.Ochestvo);
     item.setText(3, temp.Mphone);
     item.setText(4, temp.Passport);
     item.setText(5, temp.Prava);
   }
 }
Exemple #10
0
 public static void delWarranty(int id) {
   DBWrapper dbw = new DBWrapper();
   Db db = dbw.openConnection();
   Warranty w = new Warranty();
   db.from(w).where(w.Kodwarr).is(id).delete();
 }
Exemple #11
0
 public void deleteTableItem(String pasport) {
   DBWrapper dbw = new DBWrapper();
   Db db = dbw.openConnection();
   Clients cc = new Clients();
   db.from(cc).where(cc.Passport).is(pasport).delete();
 }