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:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionRecordingDaoImpl.java

@Override
@Transactional//  w  w  w  .  j  a  v  a2s .  co  m
public void deleteRecording(SessionRecording recording) {
    final SessionRecordingImpl sessionRecording = this.getSessionRecording(recording.getRecordingId());

    //Remove the reference from the session to the recording
    final SessionImpl session = sessionRecording.getSession();
    session.getSessionRecordings().remove(sessionRecording);

    final EntityManager entityManager = this.getEntityManager();
    entityManager.remove(sessionRecording);
    entityManager.persist(session);
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionTelephonyDaoImpl.java

@Override
@Transactional/*from w  w w .  j  a  va2  s .c  om*/
public void deleteTelephony(long sessionId) {
    final SessionImpl session = sessionDao.getSession(sessionId);
    final SessionTelephonyImpl sessionTelephony = DataAccessUtils.singleResult(session.getSessionTelephony());

    //Remove the reference from the session to the recording

    session.getSessionTelephony().remove(sessionTelephony);

    final EntityManager entityManager = this.getEntityManager();
    entityManager.remove(sessionTelephony);
    entityManager.persist(session);
}

From source file:com.appdynamics.loan.persistence.BasePersistenceImpl.java

@Transactional
public void save(final Serializable object) {
    EntityManager entityManager = getEntityManager();
    EntityTransaction txn = entityManager.getTransaction();
    txn.begin();/*  w w  w .  jav  a2  s . c o m*/
    try {
        entityManager.persist(object);
    } catch (Exception ex) {
        txn.rollback();
    } finally {
        if (!txn.getRollbackOnly()) {
            txn.commit();
        }
    }

}

From source file:com.epam.training.taranovski.web.project.repository.implementation.UserSkillRepositoryImplementation.java

@Override
public boolean create(UserSkill userSkill) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    try {/*  w  ww .  j  a v  a 2  s.co  m*/
        em.getTransaction().begin();
        em.persist(userSkill);
        em.getTransaction().commit();
        success = true;
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
            success = false;
        }
        em.close();
    }

    return success;
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.VacancySkillRepositoryImplementation.java

@Override
public boolean create(VacancySkill vacancySkill) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    try {//from  w  w  w  .  j  a  va 2 s . c o m
        em.getTransaction().begin();
        em.persist(vacancySkill);
        em.getTransaction().commit();
        success = true;
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
            success = false;
        }
        em.close();
    }

    return success;
}

From source file:com.enioka.jqm.tools.Helpers.java

/**
 * Checks if a parameter exists. If it exists, it is updated. If it doesn't, it is created. Only works for parameters which key is
 * unique. Will create a transaction on the given entity manager.
 *///  w  w  w. j  a  v a  2s  .c  o m
static void setSingleParam(String key, String value, EntityManager em) {
    try {
        em.getTransaction().begin();
        GlobalParameter prm = em
                .createQuery("SELECT n from GlobalParameter n WHERE n.key = :key", GlobalParameter.class)
                .setParameter("key", key).getSingleResult();
        prm.setValue(value);
        em.getTransaction().commit();
    } catch (NoResultException e) {
        GlobalParameter gp = new GlobalParameter();
        gp.setKey(key);
        gp.setValue(value);
        em.persist(gp);
        em.getTransaction().commit();
    }
}

From source file:nl.b3p.viewer.admin.stripes.CycloramaConfigurationActionBean.java

public Resolution save() throws KeyStoreException {
    try {/*from w  w w  . j  av a 2  s .c  om*/
        if (key != null) {
            String privateBase64Key = getBase64EncodedPrivateKeyFromPfxUpload(key.getInputStream(),
                    account.getPassword());
            account.setPrivateBase64Key(privateBase64Key);
            account.setFilename(key.getFileName());
            key.delete();
        } else {
            if (account.getPrivateBase64Key() == null) {
                context.getValidationErrors().add("Key", new SimpleError(
                        getBundle().getString("viewer_admin.cycloramaconfigurationactionbean.pfx")));
            }
        }
        EntityManager em = Stripersist.getEntityManager();
        em.persist(account);
        em.getTransaction().commit();

    } catch (Exception ex) {
        context.getValidationErrors().add("Key", new SimpleError(
                getBundle().getString("viewer_admin.cycloramaconfigurationactionbean.keywrong")));
        log.error("Something went wrong with reading the key", ex);
    }
    return view();
}

From source file:controllers.AuthController.java

@UnitOfWork
@FilterWith(CTCheck.class)
public Result signup(Context context, Session session, @JSR303Validation User u, Validation validation) {
    if (validation.hasBeanViolations()) {
        ArrayList map = new ArrayList();
        for (Iterator<FieldViolation> i = validation.getBeanViolations().listIterator(); i.hasNext();) {
            FieldViolation elem = i.next();
            map.add(elem.field + " " + elem.constraintViolation.getMessageKey());
        }//from   www.  j a  va2 s  . c om
        return Results.json().status(400).render(new JSendResp(400, map));
    }

    try {
        EntityManager entitymanager = entitiyManagerProvider.get();
        entitymanager.getTransaction().begin();
        entitymanager.persist(u);
        entitymanager.getTransaction().commit();
        String token = SessionIdentifierGenerator.nextSessionId();
        context.addCookie(Cookie.builder("token", token).build());
        ninjaCache.set(token, u.getId());
        session.put("token", token);
        session.put("email", u.getEmail());
        session.put("id", String.valueOf(u.getId()));
        return Results.json().render(new RespAuth(u.getId(), token, u.getEmail()));
    } catch (Exception e) {
        return Results.json().status(400).render(new JSendResp(400, e));
    }
}

From source file:com.webbfontaine.valuewebb.action.tt.TtLogger.java

private void persistLog(TtLog ttLog) {
    EntityManager entityManager = null;
    try {// w w w.j av  a 2s  . c  o m
        entityManager = Utils.createEntityManager();
        entityManager.persist(ttLog);
        entityManager.flush();
    } finally {
        if (entityManager != null) {
            entityManager.close();
        }
    }
}

From source file:net.anthonychaves.bookmarks.service.UserService.java

public User addBookmark(User user, Bookmark bookmark) {
    EntityManager em = emf.createEntityManager();

    em.getTransaction().begin();//w w w. j ava  2s  .c om
    User u = findUser(user.getEmailAddress());
    bookmark.setUser(u);
    em.persist(bookmark);
    u.getBookmarks().add(bookmark);
    em.getTransaction().commit();

    return u;
}