List of usage examples for javax.persistence EntityManager persist
public void persist(Object entity);
From source file:de.zib.gndms.logic.model.TaskAction.java
/** * Initializes a TaskAction by denoting an EntityManager and a model. * * The model is made persistent by the EntityManager. * The EntityManager and the model are stored, using {@code setOwnEntityManager()} and {@code setModelAndBackup()}. * A Backup of the model is done./*w w w . ja va 2s. c o m*/ * * * @param em an EntityManager, storing AbstractTasks * @param model an AbstractTask to be stored as model of {@code this} and to be stored in the database */ public void initFromModel(final EntityManager em, AbstractTask model) { boolean wasActive = em.getTransaction().isActive(); if (!wasActive) em.getTransaction().begin(); try { final boolean contained = em.contains(model); if (!contained) { try { em.persist(model); } catch (EntityExistsException e) { model = em.merge(model); } } if (!wasActive) em.getTransaction().commit(); setOwnEntityManager(em); setModelAndBackup(model); } finally { if (em.getTransaction().isActive()) em.getTransaction().rollback(); } }
From source file:com.jada.order.document.InvoiceEngine.java
public void saveHeader() throws Exception { EntityManager em = JpaConnection.getInstance().getCurrentEntityManager(); Date current = new Date(); if (isNew) {//from w w w. j a v a 2 s.c o m invoiceHeader.setInvoiceNum( generateNumber(orderHeader.getSiteDomain().getSite(), Constants.SEQUENCE_INVOICE)); invoiceHeader.setInvoiceDate(new Date()); invoiceHeader.setRecCreateBy(userId); invoiceHeader.setRecCreateDatetime(current); } invoiceHeader.setRecUpdateBy(userId); invoiceHeader.setRecUpdateDatetime(current); if (invoiceHeader.getInvoiceHeaderId() == null) { em.persist(invoiceHeader); } isNew = false; }
From source file:org.apache.juddi.v3.auth.jboss.JBossAuthenticator.java
/** */* ww w .ja v a 2 s . c om*/ */ public String authenticate(final String userID, final String credential) throws AuthenticationException { if (userID == null) { throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidUserId", userID)); } EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { // Create a principal for the userID Principal principal = new Principal() { public String getName() { return userID; } }; if (!authManager.isValid(principal, credential)) { throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidCredentials")); } else { tx.begin(); Publisher publisher = em.find(Publisher.class, userID); if (publisher == null) { publisher = new Publisher(); publisher.setAuthorizedName(userID); publisher.setIsAdmin("false"); publisher.setIsEnabled("true"); publisher.setMaxBindingsPerService(199); publisher.setMaxBusinesses(100); publisher.setMaxServicesPerBusiness(100); publisher.setMaxTmodels(100); publisher.setPublisherName("Unknown"); em.persist(publisher); tx.commit(); } } } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } return userID; }
From source file:portal.api.impl.PortalJpaController.java
public void saveMANOplatform(MANOplatform mp) { logger.info("Will save MANOplatform = " + mp.getName()); EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();//ww w .java 2 s . c o m entityManager.persist(mp); entityManager.flush(); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void saveMANOprovider(MANOprovider mprovider) { logger.info("Will save MANOprovider = " + mprovider.getName()); EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();//from www . ja v a 2 s.c o m entityManager.persist(mprovider); entityManager.flush(); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void saveVxFOnBoardedDescriptor(VxFOnBoardedDescriptor mprovider) { logger.info("Will save VxFOnBoardedDescriptor = " + mprovider.getDeployId()); EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/* w w w . ja va 2 s . c o m*/ entityManager.persist(mprovider); entityManager.flush(); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void saveExperimentOnBoardDescriptor(ExperimentOnBoardDescriptor mprovider) { logger.info("Will save ExperimentOnBoardDescriptors = " + mprovider.getDeployId()); EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();// w w w . ja v a 2s . c o m entityManager.persist(mprovider); entityManager.flush(); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void saveInfrastructure(Infrastructure c) { logger.info("Will save ExperimentOnBoardDescriptors = " + c.getName()); EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();//from w ww .j a v a 2s .c o m entityManager.persist(c); entityManager.flush(); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void saveProperty(PortalProperty p) { logger.info("Will PortalProperty = " + p.getName()); EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();//from w w w . java 2 s.c o m entityManager.persist(p); entityManager.flush(); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void saveInstalledVxF(InstalledVxF is) { logger.info("Will create InstalledVxF = " + is.getUuid()); EntityManager entityManager = entityManagerFactory.createEntityManager(); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();//from w w w.j a va 2 s . c o m entityManager.persist(is); entityManager.flush(); entityTransaction.commit(); }