Search in sources :

Example 16 with Pet

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

the class DAOTest method testDAO.

public void testDAO() {
    DAO dao = DAOFactory.getDAO(Pet.class);
    Pet pet = dao.clear().unfetch("user").selectAll().where().field("id").equal(5).queryOne();
    //System.out.println(pet);
    System.out.println("fck!");
}
Also used : DAO(org.eweb4j.orm.dao.DAO) Pet(test.po.Pet)

Example 17 with Pet

use of test.po.Pet 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 18 with Pet

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

the class TestPersistence method save.

public void save() {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPAPU");
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Pet pet = new Pet();
    pet.setNumber("weejkl");
    pet.setAge(2);
    pet.setName("非常小");
    pet.setType("dog");
    em.persist(pet);
    em.getTransaction().commit();
    emf.close();
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) Pet(test.po.Pet)

Example 19 with Pet

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

the class TestService method testTrans.

// 测试事务
public String testTrans(Pet _pet) {
    String error = null;
    // 事务模板
    Transaction.execute(new Trans() {

        @Override
        public void run(Object... args) throws Exception {
        // some eweb4j dao
        }
    }, 1, 2);
    List<Pet> pets;
    pets = DAOFactory.getSelectDAO().selectAll(Pet.class);
    if (pets != null) {
    }
    return error;
}
Also used : Trans(org.eweb4j.orm.jdbc.transaction.Trans) Pet(test.po.Pet)

Example 20 with Pet

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

the class TestDeleteSql 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();
    pet.setAge(30);
    delete = SqlFactory.getDeleteSql(pet);
}
Also used : Pet(test.po.Pet) BeforeClass(org.junit.BeforeClass)

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