Search in sources :

Example 6 with Master

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

the class TestDeleteSql method testDeleteByOneRelField.

/**
	 * 测试一(多)对一关系的删除sql语句生成
	 * 
	 * @throws Exception
	 */
@Test
public void testDeleteByOneRelField() throws Exception {
    Master master = new Master();
    master.setId(5L);
    pet.setMaster(master);
    String[] fields = { "master" };
    Sql sql = delete.delete(fields)[0];
    Assert.assertEquals("DELETE FROM t_pet WHERE master_id = ?  ;", sql.sql);
    Assert.assertEquals(5l, sql.args.get(0));
}
Also used : Master(test.po.Master) Sql(org.eweb4j.orm.sql.Sql) Test(org.junit.Test)

Example 7 with Master

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

the class TestInsertSql method testInsertWithOneRel.

/**
	 * 
	 * @throws Exception
	 */
@Test
public void testInsertWithOneRel() throws Exception {
    Master master = new Master();
    master.setId(5L);
    pet.setName("xiaohei");
    pet.setAge(2);
    pet.setMaster(master);
    String[] fields = { "name", "age", "master" };
    Sql sql = insert.createByFields(fields)[0];
    Assert.assertEquals("INSERT INTO t_pet(name,age,master_id) VALUES(?,?,?) ;", sql.sql);
    Assert.assertEquals("xiaohei", sql.args.get(0));
    Assert.assertEquals(2, sql.args.get(1));
    Assert.assertEquals(5l, sql.args.get(2));
}
Also used : Master(test.po.Master) Sql(org.eweb4j.orm.sql.Sql) Test(org.junit.Test)

Example 8 with Master

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

the class TestSelectSql method testDivPageByFieldIsValueByPOJO.

@Test
public void testDivPageByFieldIsValueByPOJO() {
    String[] fields = new String[] { "name", "age", "master" };
    pet.setName("小白");
    pet.setAge(19);
    Master master = new Master();
    master.setId(8L);
    pet.setMaster(master);
    String sql = select.selectWhere(fields, "age+0", 1, 2, 5);
    Assert.assertEquals("SELECT pet.id, pet.num, pet.name, pet.age, pet.cate, pet.master_id, pet.user_id FROM t_pet pet  WHERE name  =  '小白'  AND age  =  '19'  AND master_id  =  '8'  ORDER BY age" + fieldAdd + " ASC LIMIT 5, 5 ;", sql);
}
Also used : Master(test.po.Master) Test(org.junit.Test)

Example 9 with Master

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

the class TestUpdateSql method testUpdate.

/**
	 * 修改表记录所有不为null值的字段,通过主键值作为条件
	 * 
	 * @param ts
	 * @return
	 */
@Test
public void testUpdate() {
    pet.setPetId(5L);
    pet.setName("小黑");
    pet.setType("dog");
    pet.setAge(1111);
    Master master = new Master();
    master.setId(9L);
    pet.setMaster(master);
    Sql sql = update.update()[0];
    Assert.assertEquals("UPDATE t_pet SET name = ? ,age = ? ,cate = ? ,master_id = ?  WHERE id = ?  ;", sql.sql);
    Assert.assertEquals("小黑", sql.args.get(0));
    Assert.assertEquals(1111, sql.args.get(1));
    Assert.assertEquals("dog", sql.args.get(2));
    Assert.assertEquals(9l, sql.args.get(3));
    Assert.assertEquals(5l, sql.args.get(4));
}
Also used : Master(test.po.Master) Sql(org.eweb4j.orm.sql.Sql) Test(org.junit.Test)

Example 10 with Master

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

the class StartupListener method onStartup.

public void onStartup() {
    String sql = Model2Table.generateOne(MyEntity.class, false, false);
    System.out.println(sql);
    Db.createTableIfNotExist(MyEntity.class);
    Pet pet = new Pet();
    pet.setName("fuck you!");
    Master master = new Master();
    master.setName("weiwei");
    pet.setMaster(master);
    MyEntity en = new MyEntity();
    en.setData(CommonUtil.serialize(pet));
    Db.ar(en).create();
    MyEntity entity = Db.ar(MyEntity.class).findById(en.getId());
    System.out.println(entity);
    Pet aPet = CommonUtil.deserialize(entity.getData());
    System.out.println("aPet->" + aPet);
}
Also used : Master(test.po.Master) Pet(test.po.Pet)

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