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));
}
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));
}
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);
}
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));
}
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);
}
Aggregations