Search in sources :

Example 1 with Pet

use of test.po.Pet in project eweb4j-framework by laiweiwei.

the class TestCascadeDAO method main.

public static void main(String[] args) throws Exception {
    String err = EWeb4JConfig.start("start.eweb.xml");
    if (err != null)
        throw new Exception(err);
    // TestCascadeDAO.testOneSelect();
    // TestCascadeDAO.testOneUpdate();
    // TestCascadeDAO.testManyInsert();
    // TestCascadeDAO.testManySelect();
    // TestCascadeDAO.testManyDelete();
    // TestCascadeDAO.testManyManyInsert();
    // TestCascadeDAO.testManyManySelect();
    // TestCascadeDAO.testManyManyDelete();
    // TestCascadeDAO.testManyManyUpdate();
    Master master = new Master().findById(1);
    System.out.println("=============== " + master);
    master.cascade().fetch("pets");
    System.out.println("===after==" + master);
    //		master.cascade().refresh(2, "pets");
    //		master = new Master();
    //		master.setId(1);
    //		Pet pet = new Pet();
    //		pet.setName("edit_fuck_name");
    //		pet.setNumber("testnumber");
    //		master.getPets().add(pet);
    //		master.cascade().persist("pets");
    Pet pet = new Pet().find().first();
    pet.setName("change_" + pet.getName());
    pet.save();
    System.out.println(pet);
//master.cascade().remove("pets");
}
Also used : Master(test.po.Master) DAOException(org.eweb4j.orm.dao.DAOException) Pet(test.po.Pet)

Example 2 with Pet

use of test.po.Pet in project eweb4j-framework by laiweiwei.

the class TestCascadeDAO method testManyManyInsert.

public static void testManyManyInsert() {
    // Pet pet = new Pet();
    // pet.setName("test");
    // pet.setType("dog");
    // pet.setAge(3);
    //
    // Master master = new Master();
    // master.setName("_test");
    // master.setGender("man");
    //
    // pet.getMasters().add(master);
    //
    // master = new Master();
    // master.setName("_test1");
    // master.setGender("man1");
    //
    // pet.getMasters().add(master);
    //
    // master = new Master();
    // master.setName("_test2");
    // master.setGender("man2");
    //
    // pet.getMasters().add(master);
    //
    // master = new Master();
    // master.setName("_test3");
    // master.setGender("man3");
    //
    // pet.getMasters().add(master);
    // boolean flag = DAOFactory.getCascadeDAO().insert(pet);
    // System.out.println(flag);
    Master master = new Master();
    // master.setId(36);
    master.setName("日本人");
    master.setGender("boy");
    Pet pet = new Pet();
    pet.setName("小日1");
    pet.setType("dog");
    pet.setPetId(6490L);
    master.getPets().add(pet);
    pet = new Pet();
    pet.setName("小日2");
    pet.setType("cat");
    master.getPets().add(pet);
    DAOFactory.getCascadeDAO().insert(master);
}
Also used : Master(test.po.Master) Pet(test.po.Pet)

Example 3 with Pet

use of test.po.Pet in project eweb4j-framework by laiweiwei.

the class TestCascadeDAO method testManyInsert.

public static void testManyInsert() {
    Master master = new Master();
    master.setName("小日主人1");
    master.setGender("boy");
    long id = (Integer) DAOFactory.getInsertDAO().insert(master);
    master.setId(id);
    Pet pet = new Pet();
    pet.setName("小日1");
    pet.setType("dog");
    master.getPets().add(pet);
    pet = new Pet();
    pet.setName("小日2");
    pet.setType("cat");
    master.getPets().add(pet);
    DAOFactory.getCascadeDAO().insert(master);
}
Also used : Master(test.po.Master) Pet(test.po.Pet)

Example 4 with Pet

use of test.po.Pet in project eweb4j-framework by laiweiwei.

the class TestCascadeDAO method testManyManyDelete.

public static void testManyManyDelete() {
    List<Master> masterList;
    try {
        masterList = DAOFactory.getSelectDAO().selectAll(Master.class);
        if (masterList != null) {
            for (Master m : masterList) {
                System.out.println(m + "|" + m.getPets());
                Pet p = new Pet();
                p.setPetId(5L);
                m.getPets().add(p);
                DAOFactory.getCascadeDAO().delete(m, "pets");
                break;
            }
        }
    } catch (DAOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Master(test.po.Master) DAOException(org.eweb4j.orm.dao.DAOException) Pet(test.po.Pet)

Example 5 with Pet

use of test.po.Pet in project eweb4j-framework by laiweiwei.

the class CRUDTest method testCreate.

public void testCreate() throws Exception {
    Pet pet = new Pet();
    pet.setAge(12);
    pet.setName("i'm laiweiwei");
    boolean flag = Models.inst(pet).create("age", "name");
    Assert.assertTrue(flag);
    Assert.assertTrue(pet.getPetId() > 0);
    Assert.assertEquals(12, pet.getAge());
    Assert.assertEquals("i'm laiweiwei", pet.getName());
}
Also used : Pet(test.po.Pet)

Aggregations

Pet (test.po.Pet)27 Master (test.po.Master)8 BeforeClass (org.junit.BeforeClass)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 DAOException (org.eweb4j.orm.dao.DAOException)3 Sql (org.eweb4j.orm.sql.Sql)3 DAO (org.eweb4j.orm.dao.DAO)2 Map (java.util.Map)1 EntityManager (javax.persistence.EntityManager)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 Trans (org.eweb4j.orm.jdbc.transaction.Trans)1