Package org.hibernate.test.domain

Examples of org.hibernate.test.domain.Item


        sessionFactory.getCache().evictEntityRegion(Item.class);

        Session s = sessionFactory.openSession();
        Transaction t = s.beginTransaction();
        Item i = new Item();
        i.setName("Widget");
        i.setDescription("A realy top-quality, full-featured widget.");
        s.persist(i);
        t.commit();
        s.close();


        SecondLevelCacheStatistics slcs = getSecondLevelCacheStatistics(Item.class);
        log.info(slcs.toString());

        Session session = sessionFactory.openSession();
        Item loaded = (Item) session.get(Item.class, i.getId());
        assertThat(loaded).isNotNull();
        session.close();

        log.info(slcs.toString());
        assertThat(slcs.getPutCount()).isEqualTo(1);
View Full Code Here


        sessionFactory.getCache().evictEntityRegion(Item.class);
        SecondLevelCacheStatistics slcs = getSecondLevelCacheStatistics(Item.class);
        Session session;

        log.debug("Item 저장 - #1");
        Item item = new Item();
        item.setName("redis");
        item.setDescription("redis cache item");

        session = sessionFactory.openSession();
        session.save(item);
        session.flush();
        session.close();

        log.debug("Item 조회 - #1");
        session = sessionFactory.openSession();
        Item loaded = (Item) session.get(Item.class, item.getId());
        assertThat(loaded).isNotNull();
        session.close();

        log.info(slcs.toString());
        // assertThat(slcs.getPutCount()).isEqualTo(1);
        // assertThat(slcs.getElementCountInMemory()).isEqualTo(1);


        log.debug("Item Update - #1");
        session = sessionFactory.openSession();
        // session.merge(loaded);
        loaded.setDescription("Update description...");
        session.saveOrUpdate(loaded);
        session.flush();
        session.close();

        log.debug("Item 조회 - #2");
        session = sessionFactory.openSession();
        loaded = (Item) session.get(Item.class, loaded.getId());
        assertThat(loaded).isNotNull();
        assertThat(loaded.getId()).isEqualTo(item.getId());
        assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
        session.close();

        log.debug("Item 조회 - #3");
        session = sessionFactory.openSession();
        loaded = (Item) session.get(Item.class, loaded.getId());
        assertThat(loaded).isNotNull();
        assertThat(loaded.getId()).isEqualTo(item.getId());
        assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
        session.close();

        log.debug("Item 조회 - #4");
        session = sessionFactory.openSession();
        loaded = (Item) session.get(Item.class, loaded.getId());
        assertThat(loaded).isNotNull();
        assertThat(loaded.getId()).isEqualTo(item.getId());
        assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
        session.close();

        log.info(slcs.toString());
        // assertThat(slcs.getPutCount()).isEqualTo(1);
        // assertThat(slcs.getElementCountInMemory()).isEqualTo(1);
View Full Code Here

        sessionFactory.getCache().evictEntityRegion(Item.class);
        SecondLevelCacheStatistics slcs = getSecondLevelCacheStatistics(Item.class);
        Session session;

        log.debug("Item 저장 - #1");
        Item item = new Item();
        item.setName("redis");
        item.setDescription("redis cache item");

        session = sessionFactory.openSession();
        session.save(item);
        session.flush();
        session.close();

        log.debug("Item 조회 - #1");
        session = sessionFactory.openSession();
        Query query = session.createQuery("select e from Item e where e.id=:id").setParameter("id", item.getId()).setCacheable(true);
        Item loaded = (Item) query.uniqueResult();
        assertThat(loaded).isNotNull();
        session.close();

        log.debug("Item 조회 - #2");
        session = sessionFactory.openSession();
View Full Code Here

        Transaction tx = session.beginTransaction();

        int count = 100;

        for (int i = 0; i < count; i++) {
            Item item = new Item();
            item.setName("redis - " + i);
            item.setDescription("redis cache item - " + i);
            session.save(item);
        }
        tx.commit();
        session.close();

        session = sessionFactory.openSession();
        tx = session.beginTransaction();
        List<Item> items = (List<Item>) session.createCriteria(Item.class).list();

        assertThat(items.size()).isEqualTo(count);

        items = (List<Item>) session.createCriteria(Item.class).list();

        for (Item item : items) {
            session.update(item);
        }
        tx.commit();
        session.close();

        SecondLevelCacheStatistics slcs = getSecondLevelCacheStatistics(Item.class);
        log.info(slcs.toString());
        assertThat(slcs.getPutCount()).isEqualTo(count);
        assertThat(slcs.getElementCountInMemory()).isEqualTo(count);

        session = sessionFactory.openSession();
        tx = session.beginTransaction();
        items = (List<Item>) session.createCriteria(Item.class).list();
        for (Item item : items) {
            item.getName();
        }
        tx.commit();
        session.close();

        session = sessionFactory.openSession();
View Full Code Here

    }

    @Test
    @Rollback(false)
    public void queryCacheInvalidation() throws Exception {
        Item i = new Item();
        i.setName("Widget");
        i.setDescription("A realy top-quality, full-featured widget.");
        em.persist(i);
        em.flush();
        em.clear();

        Item loaded = (Item) em.find(Item.class, i.getId());
        assertThat(loaded).isNotNull();

        em.clear();

        loaded = (Item) em.find(Item.class, i.getId());
View Full Code Here

    @Test
    @Rollback(false)
    public void simpleEntityCaching() {

        log.debug("Item 저장 - #1");
        Item item = new Item();
        item.setName("redis");
        item.setDescription("redis cache item");
        em.persist(item);
        em.flush();
        em.clear();

        log.debug("Item 조회 - #1");
        Item loaded = (Item) em.find(Item.class, item.getId());
        assertThat(loaded).isNotNull();

        log.debug("Item Update - #1");
        // session.merge(loaded);
        loaded.setDescription("Update description...");
        em.persist(loaded);
        em.flush();
        em.clear();

        log.debug("Item 조회 - #2");
        loaded = (Item) em.find(Item.class, item.getId());
        assertThat(loaded).isNotNull();
        assertThat(loaded.getId()).isEqualTo(item.getId());
        assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
        em.clear();

        log.debug("Item 조회 - #3");
        loaded = (Item) em.find(Item.class, item.getId());
        assertThat(loaded).isNotNull();
        assertThat(loaded.getId()).isEqualTo(item.getId());
        assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
        em.clear();

        log.debug("Item 조회 - #4");
        loaded = (Item) em.find(Item.class, item.getId());
        assertThat(loaded).isNotNull();
        assertThat(loaded.getId()).isEqualTo(item.getId());
        assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
        em.clear();
    }
View Full Code Here

    @Rollback(false)
    public void hqlLoad() throws Exception {

        log.debug("Item 저장 - #1");

        Item item = new Item();
        item.setName("redis");
        item.setDescription("redis cache item");
        em.persist(item);
        em.flush();
        em.clear();

        log.debug("Item 조회 - #1");

        //NOTE: http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/objectstate.html#d0e1215

        Query query = em.createQuery("select e from Item e where e.id=:id").setParameter("id", item.getId()).setHint("org.hibernate.cacheable", true);
        Item loaded = (Item) query.getSingleResult();
        assertThat(loaded).isNotNull();
        em.clear();

        log.debug("Item 조회 - #2");
        query = em.createQuery("select e from Item e where e.id=:id").setParameter("id", item.getId()).setHint("org.hibernate.cacheable", true);
View Full Code Here

    @Test
    public void springRepositoryTest() throws Exception {

        log.debug("Item 저장 - #1");

        Item item = new Item();
        item.setName("redis");
        item.setDescription("redis cache item");
        em.persist(item);
        em.flush();
        em.clear();

        log.debug("Item 조회 - #1");
View Full Code Here

    }

    @Test
    @Rollback(false)
    public void queryCacheInvalidation() throws Exception {
        Item i = new Item();
        i.setName("Widget");
        i.setDescription("A realy top-quality, full-featured widget.");
        em.persist(i);
        em.flush();
        em.clear();

        Item loaded = (Item) em.find(Item.class, i.getId());
        assertThat(loaded).isNotNull();

        em.clear();

        loaded = (Item) em.find(Item.class, i.getId());
View Full Code Here

    @Test
    @Rollback(false)
    public void simpleEntityCaching() {

        log.debug("Item 저장 - #1");
        Item item = new Item();
        item.setName("redis");
        item.setDescription("redis cache item");
        em.persist(item);
        em.flush();
        em.clear();

        log.debug("Item 조회 - #1");
        Item loaded = (Item) em.find(Item.class, item.getId());
        assertThat(loaded).isNotNull();

        log.debug("Item Update - #1");
        // session.merge(loaded);
        loaded.setDescription("Update description...");
        em.persist(loaded);
        em.flush();
        em.clear();

        log.debug("Item 조회 - #2");
        loaded = (Item) em.find(Item.class, item.getId());
        assertThat(loaded).isNotNull();
        assertThat(loaded.getId()).isEqualTo(item.getId());
        assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
        em.clear();

        log.debug("Item 조회 - #3");
        loaded = (Item) em.find(Item.class, item.getId());
        assertThat(loaded).isNotNull();
        assertThat(loaded.getId()).isEqualTo(item.getId());
        assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
        em.clear();

        log.debug("Item 조회 - #4");
        loaded = (Item) em.find(Item.class, item.getId());
        assertThat(loaded).isNotNull();
        assertThat(loaded.getId()).isEqualTo(item.getId());
        assertThat(loaded.getDescription()).isNotEqualTo(item.getDescription());
        em.clear();
    }
View Full Code Here

TOP

Related Classes of org.hibernate.test.domain.Item

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.