Example usage for javax.persistence EntityManager persist

List of usage examples for javax.persistence EntityManager persist

Introduction

In this page you can find the example usage for javax.persistence EntityManager persist.

Prototype

public void persist(Object entity);

Source Link

Document

Make an instance managed and persistent.

Usage

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
@Transactional//from   ww w .  j  a va 2  s .com
public int createCacheCity(CacheCity cacheCity) {
    int retCode = 0;
    EntityManager em = getEm();
    try {
        em.persist(cacheCity);
        retCode = 1;
    } catch (Exception ex) {
        retCode = -1;
        logger.error(ex.getMessage());
    }
    return retCode;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
@Transactional//from   w w w.j a  v a  2s .  co m
public int createCacheRatePlan(CacheRatePlan cacheRatePlan) {
    int retCode = 0;
    EntityManager em = getEm();
    try {
        em.persist(cacheRatePlan);
        retCode = 1;
    } catch (Exception ex) {
        retCode = -1;
        logger.error(ex.getMessage());
    }
    return retCode;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
@Transactional//w  ww. j a  va2 s.c  om
public int createZone(Zone zone) {
    int retCode = 0;
    EntityManager em = getEm();
    try {
        em.persist(zone);
        retCode = 1;
    } catch (Exception ex) {
        retCode = -1;
        logger.error(ex.getMessage());
    }
    return retCode;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
@Transactional/*from  w  w w. ja va2 s  .  c  o m*/
public int createCacheHotelCacheChange(CacheHotelCacheChange cacheHotelCacheChange) {
    int retCode = 0;
    EntityManager em = getEm();
    try {
        em.persist(cacheHotelCacheChange);
        return 1;
    } catch (Exception ex) {
        retCode = -1;
        logger.error(ex.getMessage());
    }
    return 0;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
@Transactional/* w  w  w .j  a v  a  2s.  com*/
public int createCacheHotel(CacheHotel cacheHotel) {
    int retCode = 0;
    EntityManager em = getEm();
    try {
        em.persist(cacheHotel);

        retCode = 1;
    } catch (Exception ex) {
        retCode = -1;
        logger.error(ex.getMessage());
    }
    return retCode;
}

From source file:cn.buk.hotel.dao.HotelDaoImpl.java

@Override
@Transactional/*from w  ww  . ja va  2 s.com*/
public int createDistrict(District district) {
    int retCode = 0;
    EntityManager em = getEm();
    try {
        em.persist(district);

        retCode = 1;
    } catch (Exception ex) {
        retCode = -1;
        logger.error(ex.getMessage());
    }
    return retCode;
}

From source file:server.Folder.java

public void addMetaset(Metaset metaset) {
    FolderMetaset om = new FolderMetaset(this, metaset);
    EntityManager em = HibernateSession.getLocalEntityManager();
    em.persist(om);
}

From source file:de.berlios.jhelpdesk.dao.jpa.TicketCategoryDAOJpa.java

@Transactional(readOnly = false)
public void insertCategory(final TicketCategory category, final TicketCategory parent) {
    final long nodeCount = getNodeCount();
    this.jpaTemplate.execute(new JpaCallback() {
        public Object doInJpa(EntityManager em) throws PersistenceException {
            Query q1 = em.createNativeQuery(
                    "UPDATE ticket_category SET t_right=t_right+2 WHERE t_right>=? AND t_right<=?");
            q1.setParameter(1, parent.getRight());
            q1.setParameter(2, nodeCount * 2);
            q1.executeUpdate();/*from w w w .ja  v  a  2  s.c  o  m*/

            Query q2 = em.createNativeQuery(
                    "UPDATE ticket_category SET t_left=t_left+2 WHERE t_left>? AND t_left<?");
            q2.setParameter(1, parent.getRight());
            q2.setParameter(2, (nodeCount + 1) * 2);
            q2.executeUpdate();

            category.setLeft(parent.getRight());
            category.setRight(parent.getRight() + 1);
            category.setDepth(parent.getDepth() + 1);

            em.persist(category);
            return null;
        }
    });
}

From source file:org.rhq.enterprise.server.resource.test.ResourceFactoryManagerBeanTest.java

/**
 * Creates a new child resource on the test class' parent resource.
 *
 * @return the newly created resource//from   ww w.j av a2s  . com
 *
 * @throws Exception if anything goes wrong
 */
private Resource addResourceToParent() throws Exception {
    Resource resource = null;

    getTransactionManager().begin();
    EntityManager em = getEntityManager();

    try {
        try {
            resource = new Resource("child" + System.currentTimeMillis(), "name", parentResourceType);
            resource.setUuid("" + new Random().nextInt());
            resource.setParentResource(parentResource);
            resource.setInventoryStatus(InventoryStatus.COMMITTED);
            em.persist(resource);
        } catch (Exception e) {
            System.out.println(e);
            getTransactionManager().rollback();
        }

        getTransactionManager().commit();
    } finally {
        em.close();
    }

    return resource;
}

From source file:org.opencastproject.adminui.usersettings.UserSettingsService.java

/**
 * Create a new user setting key value pair.
 *
 * @param key//from  w w  w  .  j  a  va2  s  .  co  m
 *          The key to use for the current user setting.
 * @param value
 *          The value of the user setting.
 * @return A new user setting object
 * @throws UserSettingsServiceException
 */
public UserSetting addUserSetting(String key, String value) throws UserSettingsServiceException {
    EntityManager em = null;
    EntityTransaction tx = null;
    String orgId = "";
    String username = "";
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        orgId = securityService.getOrganization().getId();
        username = securityService.getUser().getUsername();
        UserSettingDto userSettingDto = new UserSettingDto();
        userSettingDto.setKey(key);
        userSettingDto.setValue(value);
        userSettingDto.setUsername(username);
        userSettingDto.setOrganization(orgId);
        em.persist(userSettingDto);
        tx.commit();
        return userSettingDto.toUserSetting();
    } catch (Exception e) {
        logger.error("Could not update user setting username '%s' org:'%s' key:'%s' value:'%s':%s", username,
                orgId, key, value, ExceptionUtils.getStackTrace(e));
        if (tx.isActive()) {
            tx.rollback();
        }
        throw new UserSettingsServiceException(e);
    } finally {
        if (em != null) {
            em.close();
        }
    }
}