本文整理汇总了Java中javax.transaction.Transactional.TxType.REQUIRED属性的典型用法代码示例。如果您正苦于以下问题:Java TxType.REQUIRED属性的具体用法?Java TxType.REQUIRED怎么用?Java TxType.REQUIRED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.transaction.Transactional.TxType
的用法示例。
在下文中一共展示了TxType.REQUIRED属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
@SuppressWarnings("unchecked")
@Override
@Transactional(TxType.REQUIRED)
public E create(final E transientInstance) throws MessageLabelException {
log.trace("Create a new entity {}", getModelClass().getName());
if (transientInstance == null) {
log.warn("Try to create a null object !");
throw new NullDataException();
}
validateEntity((IEntity<Serializable>) transientInstance);
mapsId(transientInstance);
reSet(transientInstance);
getEntityManager().persist(transientInstance);
// rebuild Set fields because they are hashed with null entity pk.
reSet(transientInstance);
log.trace("New entity {} created", transientInstance);
return transientInstance;
}
示例2: delete
@Override
@Transactional(TxType.REQUIRED)
public boolean delete(final E detachedInstance) throws MessageLabelException {
log.trace("Delete one entity {}", getModelClass().getName());
if (detachedInstance == null) {
log.warn("Try to delete a null object !");
throw new NullDataException();
}
final E persistedInstance = findByPk(detachedInstance.getPrimaryKey());
if (persistedInstance == null) {
log.trace("Entity {} {} doesn't exist for deletion", getModelClass().getName(), detachedInstance.getPrimaryKey());
return false;
}
getEntityManager().remove(persistedInstance);
log.trace("Entity {} {} deleted", getModelClass().getName(), persistedInstance.getPrimaryKey());
return true;
}
示例3: save
@Override
@Transactional(TxType.REQUIRED)
public <S extends Office> S save(S entity) {
logger.info("Transaction should be started by Blueprint interceptor");
if (entity.isNew()) {
em.persist(entity);
} else {
em.merge(entity);
}
return entity;
}
示例4: update
@SuppressWarnings("unchecked")
@Override
@Transactional(TxType.REQUIRED)
public E update(final E detachedInstance) throws MessageLabelException {
log.trace("Update one entity {}", getModelClass().getName());
if (detachedInstance == null) {
log.warn("Try to update a null object !");
throw new NullDataException();
}
validateEntity((IEntity<Serializable>) detachedInstance);
mapsId(detachedInstance);
reSet(detachedInstance);
// Clear xxxToMany relationship before merging entity, and add their
// after merged.
final Map<Field, Collection<IEntity<?>>> map = oneToMany(detachedInstance);
// Merge the entity.
final E entity = getEntityManager().merge(detachedInstance);
// Recollection oneToMany relationship in the entity.
oneToMany(entity, map);
oneToMany(detachedInstance, map);
// Flush and reset Set object.
getEntityManager().flush();
reSet(detachedInstance);
reSet(entity);
log.trace("Entity {} updated", entity);
return entity;
}
示例5: save
@Override
@Transactional(TxType.REQUIRED)
public E save(final E detachedInstance) throws MessageLabelException {
if (EntityUtil.isNullPk(detachedInstance)) {
return create(detachedInstance);
} else {
return update(detachedInstance);
}
}
示例6: getConcert
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}")
@Transactional(value=TxType.REQUIRED)
public Event getConcert(@PathParam("id") long id) {
System.out.println("ConcertResource.getConcert(" + id + ")");
return emf.createEntityManager().find(Event.class, id);
}
示例7: getSportsEvent
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}")
@Transactional(value=TxType.REQUIRED)
public Event getSportsEvent(@PathParam("id") long id) {
System.out.println("ConcertResource.getConcert(" + id + ")");
return emf.createEntityManager().find(Event.class, id);
}
示例8: getItem
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}")
@Transactional(value=TxType.REQUIRED)
public Venue getItem(@PathParam("id") long id) {
System.out.println("VenueResource.getItem(" + id + ")");
return emf.createEntityManager().find(Venue.class, id);
}