当前位置: 首页>>代码示例>>Java>>正文


Java EntityManager.merge方法代码示例

本文整理汇总了Java中javax.persistence.EntityManager.merge方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.merge方法的具体用法?Java EntityManager.merge怎么用?Java EntityManager.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.EntityManager的用法示例。


在下文中一共展示了EntityManager.merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: merge

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static ReceivedTexts merge(ReceivedTexts text) {
    if (text != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            text = em.merge(text);
            trans.commit();
            return text;
        } catch (Exception e) {
            e.printStackTrace();
            trans.rollback();
        } finally {
            em.close();
        }
    }
    return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:19,代码来源:ReceivedTextDataAccessObject.java

示例2: merge

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static Candidates merge(Candidates candidate) {
    if (candidate != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            candidate = em.merge(candidate);
            trans.commit();
            return candidate;
        } catch (Exception e) {
            e.printStackTrace();
            trans.rollback();
        } finally {
            em.close();
        }
    }
    return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:19,代码来源:CandidatePersistence.java

示例3: merge

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static ProfileViews merge (ProfileViews view) {
    if (view != null) {
        EntityManager em = EMFUtil.getEMFactory().createEntityManager();
        EntityTransaction trans = em.getTransaction();
        try {
            trans.begin();
            view = em.merge(view);
            trans.commit();
            return view;
        } catch (Exception e) {
            e.printStackTrace();
            trans.rollback();
        } finally {
            em.close();
        }
    }
    return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:19,代码来源:ProfileViewDataAccessObject.java

示例4: merge

import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
 * @return The managed version of the provided entity (with set autogenerated values for example).
 */
@Nonnull
@CheckReturnValue
//returns a sauced entity
public <E extends SaucedEntity<I, E>, I extends Serializable> E merge(@Nonnull final E entity)
        throws DatabaseException {
    final EntityManager em = this.databaseConnection.getEntityManager();
    try {
        em.getTransaction().begin();
        final E managedEntity = em.merge(entity);
        em.getTransaction().commit();
        return managedEntity
                .setSauce(this);
    } catch (final PersistenceException e) {
        final String message = String.format("Failed to merge entity %s on DB %s",
                entity.toString(), this.databaseConnection.getName());
        throw new DatabaseException(message, e);
    } finally {
        em.close();
    }
}
 
开发者ID:napstr,项目名称:SqlSauce,代码行数:24,代码来源:DatabaseWrapper.java

示例5: executeTransaction

import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Override
public void executeTransaction(EntityManager em) throws Exception {
    this.securityGroup = em.find(SecurityGroup.class, this.securityGroup.getId());
    this.port = em.find(VMPort.class, this.port.getId());

    String inspectionHookId = this.port.getInspectionHookId();

    if (inspectionHookId != null) {
        try (SdnRedirectionApi redirApi = this.apiFactory
                .createNetworkRedirectionApi(this.securityGroup.getVirtualizationConnector())) {
            redirApi.removeInspectionHook(inspectionHookId);
            this.port.setInspectionHookId(null);
            em.merge(this.port);
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:17,代码来源:SfcFlowClassifierDeleteTask.java

示例6: merge

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static WeeklyStats merge (WeeklyStats stats) {
	if (stats != null) {
           EntityManager em = EMFUtil.getEMFactory().createEntityManager();
           EntityTransaction trans = em.getTransaction();
           try {
               trans.begin();
               stats = em.merge(stats);
               trans.commit();
               return stats;
           } catch (Exception e) {
               e.printStackTrace();
               trans.rollback();
           } finally {
               em.close();
           }
	}
	return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:19,代码来源:WeeklyStatsDataAccessObject.java

示例7: executeTransaction

import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Override
public void executeTransaction(EntityManager em) throws Exception {
	this.sfc = em.find(ServiceFunctionChain.class, this.sfc.getId());
	this.securityGroup = em.find(SecurityGroup.class, this.securityGroup.getId());

	List<SecurityGroup> existingSGList = SecurityGroupEntityMgr.listOtherSecurityGroupsWithSameSFC(em,
			this.securityGroup);

	if (existingSGList.isEmpty()) {

		try (SdnRedirectionApi sdnApi = this.apiFactory
				.createNetworkRedirectionApi(this.securityGroup.getVirtualizationConnector())) {

			NetworkElement sfcChain = sdnApi.registerNetworkElement(this.portPairGroups);
			this.securityGroup.setNetworkElementId(sfcChain.getElementId());
		}
	} else {
		this.securityGroup.setNetworkElementId(existingSGList.iterator().next().getNetworkElementId());
	}
	em.merge(this.securityGroup);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:22,代码来源:CreateServiceFunctionChainTask.java

示例8: acquire

import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
 * Acquire the lock object.
 *
 * @param em the em
 * @param lock the lock
 * @return true, if successful
 */
private boolean acquire(final EntityManager em, final Lock lock) {
    lock.setUniqueId(uniqueId);
    if (lockTimeout > 0) {
        final Calendar cal = Calendar.getInstance();
        cal.add(Calendar.SECOND, lockTimeout);
        lock.setExpirationDate(cal.getTime());
    } else {
        lock.setExpirationDate(null);
    }
    boolean success = false;
    try {
        if (lock.getApplicationId() != null) {
            em.merge(lock);
        } else {
            lock.setApplicationId(applicationId);
            em.persist(lock);
        }
        success = true;
    } catch (final PersistenceException e) {
        success = false;
        if (logger.isDebugEnabled()) {
            logger.debug("{} could not obtain {} lock.", uniqueId, applicationId, e);
        } else {
            logger.info("{} could not obtain {} lock.", uniqueId, applicationId);
        }
    }
    return success;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:36,代码来源:JpaLockingStrategy.java

示例9: jButton2ActionPerformed

import javax.persistence.EntityManager; //导入方法依赖的package包/类
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    Object[] selected = activeList.getSelectedValues();
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    for (Object plugin : selected) {
        Plugins p = (Plugins) plugin;
        p.setActive(false);
        activemodel.removeElement(p);
        inactivemodel.addElement(p);
        p = em.merge(p);
        em.persist(p);
    }
    em.getTransaction().commit();
    em.close();
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:16,代码来源:PluginManagerDialog.java

示例10: updateproduct

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void updateproduct(){
    //obtener el entitymanager
    EntityManager em = i.getEntityManager();
    //captura la transaccion realizada y la inicio
    em.getTransaction().begin();
    //guarda en la base de datos la entidad
    em.merge(i);
    //termina la transcaccion
    em.getTransaction().commit();
    //i = new Items();
    searchP();
}
 
开发者ID:Whistler092,项目名称:programacion4-final,代码行数:13,代码来源:ControllerProduct.java

示例11: edit

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void edit(Usuario _user) throws NonexistentEntityException, RollbackFailureException, Exception {
    EntityManager em = null;
    try {
        utx.begin();
        em = getEntityManager();
        _user = em.merge(_user);
        utx.commit();
    } catch (Exception ex) {
        try {
            utx.rollback();
        } catch (Exception re) {
            throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
        }
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            String id = _user.getId();
            if (findPersona(id) == null) {
                throw new NonexistentEntityException("The persona with id " + id + " no longer exists.");
            }
        }
        throw ex;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:28,代码来源:UsuarioJpaController.java

示例12: destroy

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void destroy(Integer id) throws NonexistentEntityException, RollbackFailureException, Exception {
    EntityManager em = null;
    try {
        utx.begin();
        em = getEntityManager();
        Telefono telefono;
        try {
            telefono = em.getReference(Telefono.class, id);
            telefono.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The telefono with id " + id + " no longer exists.", enfe);
        }
        Propietario propietarioId = telefono.getPropietarioId();
        if (propietarioId != null) {
            propietarioId.getTelefonoCollection().remove(telefono);
            propietarioId = em.merge(propietarioId);
        }
        em.remove(telefono);
        utx.commit();
    } catch (Exception ex) {
        try {
            utx.rollback();
        } catch (Exception re) {
            throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
        }
        throw ex;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:33,代码来源:TelefonoJpaController.java

示例13: acquire

import javax.persistence.EntityManager; //导入方法依赖的package包/类
private boolean acquire(final EntityManager em, final Lock lock) {
    lock.setUniqueId(uniqueId);
    if (lockTimeout > 0) {
        final Calendar cal = Calendar.getInstance();
        cal.add(Calendar.SECOND, lockTimeout);
        lock.setExpirationDate(cal.getTime());
    } else {
        lock.setExpirationDate(null);
    }
    boolean success = false;
    try {
        if (lock.getApplicationId() != null) {
            em.merge(lock);
        } else {
            lock.setApplicationId(applicationId);
            em.persist(lock);
        }
        success = true;
    } catch (final PersistenceException e) {
        success = false;
        if (logger.isDebugEnabled()) {
            logger.debug("{} could not obtain {} lock.", new Object[] {uniqueId, applicationId, e});
        } else {
            logger.info("{} could not obtain {} lock.", uniqueId, applicationId);
        }
    }
    return success;
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:29,代码来源:JpaLockingStrategy.java

示例14: update

import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Override
public void update(User po) {
	EntityManager entityManager = entityManagerFactory.createEntityManager();
	try {
		entityManager.getTransaction().begin();
		entityManager.merge(po);
		entityManager.getTransaction().commit();
	} catch (RuntimeException e) {
		entityManager.getTransaction().rollback();
	}
}
 
开发者ID:lf23617358,项目名称:training-sample,代码行数:12,代码来源:JPAUserDao.java

示例15: markDeleted

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static void markDeleted(EntityManager em, IscEntity entity,
        TransactionalBroadcastUtil txBroadcastUtil) {
    String contextUser = SessionUtil.getInstance().getCurrentUser();
    entity.setMarkedForDeletion(true);
    entity.setDeletedBy(contextUser);
    entity.setDeletedTimestamp(new Date());

    em.merge(entity);

    // Broadcasting changes to UI
    txBroadcastUtil.addMessageToMap(entity.getId(), entity.getClass().getSimpleName(),
            EventType.UPDATED);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:14,代码来源:OSCEntityManager.java


注:本文中的javax.persistence.EntityManager.merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。