Package org.jugile.daims

Source Code of org.jugile.daims.UpdateDBTest

package org.jugile.daims;

import java.util.List;

import org.jugile.proto2.domain.*;
import org.jugile.util.DBConnection;
import org.jugile.util.DBPool;
import org.jugile.util.HiLo;
import org.jugile.util.Jugile;
import org.jugile.util.JugileTestCase;

public class UpdateDBTest extends JugileTestCase {
 
  public void testUpdateObject() throws Exception {
    // check that db is updated into db
    if (!HiLo.hasdb()) return;
    DBTest.clearDatabase();
    Domain d = Domain.getDomain();
    Person p1 = d.createPerson().setName("Jukka");
    d.commit();
   
    p1 = d.getPerson(p1.getId());
    p1.setName("Jukka-Pekka");
    d.commit();
   
    Domain.reset();
    d = Domain.getDomain(); // reload
    d.loadFromDB();
    p1 = d.getPerson(p1.id());
    assertEquals("Jukka-Pekka",p1.getName());
    p1.setName("jukka-pekka");
    d.commit();
   
    Domain.reset();
    d = Domain.getDomain();
    d.loadFromDB();
    p1 = d.getPersons().q("==", "name", "jukka-pekka").unique();
    p1.setName("foo");
    d.commit();
   
    // check db directly
    DBPool db = DBPool.getPool();
    DBConnection c = db.getConnection();
    List<List> rows = c.select("select name_f,id_f,vers from person_t where id_f="+p1.id());
    c.free();
    assertEquals(1,rows.size());
    List row = rows.get(0);
    assertEquals("foo",row.get(0));
    assertEquals(""+p1.id(),""+row.get(1));
    assertEquals("4",""+row.get(2));
   
  }
 
}
TOP

Related Classes of org.jugile.daims.UpdateDBTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.