use of test.po.Pet in project eweb4j-framework by laiweiwei.
the class TestDeleteSql method testMap.
@Test
public void testMap() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("table", "t_pet");
map.put("idColumn", "id");
map.put("idValue", 7);
Pet pet = new Pet();
DeleteSqlCreator<?> delete = SqlFactory.getDeleteSql(map, pet);
Sql sql = delete.delete()[0];
Assert.assertEquals("DELETE FROM t_pet WHERE id = ? ;", sql.sql);
Assert.assertEquals(7, sql.args.get(0));
}
use of test.po.Pet in project eweb4j-framework by laiweiwei.
the class TestInsertSql method testMap.
@Test
public void testMap() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("table", "t_pet");
map.put("idColumn", "id");
map.put("columns", new String[] { "num", "name", "age", "cate" });
map.put("values", new Object[] { 123, "weiwei", 3, "dog" });
Pet pet = new Pet();
pet.setName("xxx");
pet.setNumber("4444");
pet.setAge(3);
pet.setType("cat");
final InsertSqlCreator<?> insert = SqlFactory.getInsertSql(map, pet);
Sql[] sql = insert.create();
Assert.assertEquals("INSERT INTO t_pet(num,name,age,cate) VALUES(?,?,?,?) ;", sql[0].sql);
Assert.assertEquals(123, sql[0].args.get(0));
Assert.assertEquals("weiwei", sql[0].args.get(1));
Assert.assertEquals(3, sql[0].args.get(2));
Assert.assertEquals("dog", sql[0].args.get(3));
Assert.assertEquals("INSERT INTO t_pet(num,name,age,cate) VALUES(?,?,?,?) ;", sql[1].sql);
Assert.assertEquals("4444", sql[1].args.get(0));
Assert.assertEquals("xxx", sql[1].args.get(1));
Assert.assertEquals(3, sql[1].args.get(2));
Assert.assertEquals("cat", sql[1].args.get(3));
}
use of test.po.Pet in project eweb4j-framework by laiweiwei.
the class TestUpdateSql method testMap.
@Test
public void testMap() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("table", "t_pet");
map.put("idColumn", "id");
map.put("idValue", 5);
map.put("columns", new String[] { "num", "name", "age", "type" });
map.put("values", new Object[] { 123, "weiwei", 3, "dog" });
Pet pet = new Pet();
pet.setName("xxx");
pet.setNumber("4444");
pet.setAge(3);
pet.setType("cat");
UpdateSqlCreator<?> update = SqlFactory.getUpdateSql(map, pet);
Sql sql = update.update()[0];
Assert.assertEquals("UPDATE t_pet SET num = ? ,name = ? ,age = ? ,type = ? WHERE id = ? ;", sql.sql);
Assert.assertEquals(123, sql.args.get(0));
Assert.assertEquals("weiwei", sql.args.get(1));
Assert.assertEquals(3, sql.args.get(2));
Assert.assertEquals("dog", sql.args.get(3));
Assert.assertEquals(5, sql.args.get(4));
}
use of test.po.Pet 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);
}
use of test.po.Pet in project eweb4j-framework by laiweiwei.
the class TestDb method test.
public void test() throws Exception {
String query = ORMConfigBeanUtil.parseQuery("master <= ? and user > ?", Pet.class);
System.out.println(query);
Pet p = Db.ar(Pet.class).find("master <= ? and user > ?", 1, 2).first();
System.out.println(p);
}
Aggregations