Search in sources :

Example 11 with Master

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

the class TestDb method testOrmUtil.

public void testOrmUtil() throws Exception {
    String[] fields = new ReflectUtil(Master.class).getFieldsName();
    System.out.println(Arrays.asList(fields));
    Master m = DAOFactory.getDAO(Master.class).fetch("pets").selectAll().queryOne();
    System.out.println(m);
}
Also used : Master(test.po.Master) ReflectUtil(org.eweb4j.util.ReflectUtil)

Example 12 with Master

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

the class DAOTest method testCol.

public void testCol() throws Exception {
    Assert.assertEquals("pet.master_id", ORMConfigBeanUtil.getColumn(Master.class, "pets.master"));
    //		Collection<Object> ms = DAOFactory.getDAO(Master.class).enableExpress(false).select("*").join("pets").where().field("pet.name").equal("xiaohei").groupBy("pet.name").query();
    //		System.out.println(ms);
    DAO dao = DAOFactory.getDAO(Pet.class).alias("p");
    Pet pet = dao.join("master", "m").join("user", "u").unfetch("user").fetch("master").select(Pet.class).where().field("m.name").like("wei").and("p.name").likeLeft("xiao").and("u.account").equal("admin").groupBy("u.account").queryOne();
    System.out.println("pet -> " + pet);
    if (pet != null) {
        System.out.println("master->" + pet.getMaster());
        System.out.println("count->" + dao.count());
    }
    String sql = dao.toSql();
    List<Map> maps = DAOFactory.getSelectDAO().selectBySQL(Map.class, sql);
    if (maps != null) {
        for (Map<String, Object> map : maps) {
            for (String key : map.keySet()) {
                System.out.println(key + "=>" + map.get(key));
            }
        }
    }
}
Also used : Master(test.po.Master) DAO(org.eweb4j.orm.dao.DAO) Map(java.util.Map) Pet(test.po.Pet)

Example 13 with Master

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

the class TestSelectSql method prepare.

@BeforeClass
public static void prepare() throws Exception {
    String err = EWeb4JConfig.start("start.eweb.xml");
    if (err != null) {
        System.out.println(">>>EWeb4J Start Error --> " + err);
        System.exit(-1);
    }
    pet = new Pet();
    master = new Master();
    master.setId(5L);
    pet.setMaster(master);
    pet.setName("xiaobai");
    select = SqlFactory.getSelectSql(pet, "mysql");
    fieldAdd = "+0";
}
Also used : Master(test.po.Master) Pet(test.po.Pet) BeforeClass(org.junit.BeforeClass)

Example 14 with Master

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

the class TestUpdateSql method testUpdateByField.

/**
	 * 修改给定字段
	 * 
	 * @param t
	 *            给定的对象
	 * @param fields
	 *            给定的字段
	 * @return 返回布尔
	 */
@Test
public <T> void testUpdateByField() {
    pet.setName("xiaohuang");
    pet.setAge(3);
    pet.setPetId(12L);
    Master master = new Master();
    master.setId(5L);
    pet.setMaster(master);
    String[] fields = { "name", "age", "master" };
    Sql sql = update.update(fields)[0];
    Assert.assertEquals("UPDATE t_pet SET name = ? , age = ? , master_id = ?  WHERE id = ?  ;", sql.sql);
    Assert.assertEquals("xiaohuang", sql.args.get(0));
    Assert.assertEquals(3, sql.args.get(1));
    Assert.assertEquals(5l, sql.args.get(2));
    Assert.assertEquals(12l, sql.args.get(3));
}
Also used : Master(test.po.Master) Sql(org.eweb4j.orm.sql.Sql) Test(org.junit.Test)

Example 15 with Master

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

the class CascadeTest method testOneRel.

@Test
public void testOneRel() throws Exception {
    Master master = new Master();
    master.setId(1L);
    master.getPets().add(new Pet());
    master.getPets().add(new Pet());
    master.getPets().add(new Pet());
    //DAOFactory.getCascadeDAO().insert(master, "pets");
    Assert.assertEquals(true, true);
}
Also used : Master(test.po.Master) Pet(test.po.Pet) Test(org.junit.Test)

Aggregations

Master (test.po.Master)18 Pet (test.po.Pet)8 Test (org.junit.Test)6 DAOException (org.eweb4j.orm.dao.DAOException)4 Sql (org.eweb4j.orm.sql.Sql)4 Map (java.util.Map)1 DAO (org.eweb4j.orm.dao.DAO)1 ReflectUtil (org.eweb4j.util.ReflectUtil)1 BeforeClass (org.junit.BeforeClass)1