Search in sources :

Example 6 with Pet

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));
}
Also used : HashMap(java.util.HashMap) Pet(test.po.Pet) Sql(org.eweb4j.orm.sql.Sql) Test(org.junit.Test)

Example 7 with Pet

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));
}
Also used : HashMap(java.util.HashMap) Pet(test.po.Pet) Sql(org.eweb4j.orm.sql.Sql) Test(org.junit.Test)

Example 8 with Pet

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));
}
Also used : HashMap(java.util.HashMap) Pet(test.po.Pet) Sql(org.eweb4j.orm.sql.Sql) Test(org.junit.Test)

Example 9 with Pet

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);
}
Also used : Master(test.po.Master) Pet(test.po.Pet)

Example 10 with Pet

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