本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
}
}
示例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();
}
}
}
示例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;
}
示例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();
}
}
示例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);
}