本文整理汇总了Java中javax.transaction.Transactional.TxType类的典型用法代码示例。如果您正苦于以下问题:Java TxType类的具体用法?Java TxType怎么用?Java TxType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TxType类属于javax.transaction.Transactional包,在下文中一共展示了TxType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@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
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@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: updateStatus
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@Override
@Transactional(TxType.NEVER)
public void updateStatus(Long stackId, StatusRequest statusRequest) {
Stack stack = stackService.getByIdWithLists(stackId);
Cluster cluster = stack.getCluster();
if (cluster == null) {
throw new BadRequestException(String.format("There is no cluster installed on stack '%s'.", stack.getName()));
}
switch (statusRequest) {
case SYNC:
sync(stack);
break;
case STOPPED:
stop(stack, cluster);
break;
case STARTED:
start(stack, cluster);
break;
default:
throw new BadRequestException("Cannot update the status of cluster because status request not valid");
}
}
示例4: updateClusterStatusByStackId
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@Override
@Transactional(TxType.NEVER)
public Cluster updateClusterStatusByStackId(Long stackId, Status status, String statusReason) {
LOGGER.debug("Updating cluster status. stackId: {}, status: {}, statusReason: {}", stackId, status, statusReason);
StackStatus stackStatus = stackService.getCurrentStatusByStackId(stackId);
Cluster cluster = retrieveClusterByStackId(stackId);
if (cluster != null) {
cluster.setStatus(status);
cluster.setStatusReason(statusReason);
cluster = clusterRepository.save(cluster);
if (status.isRemovableStatus()) {
InMemoryStateStore.deleteCluster(cluster.getId());
if (stackStatus.getStatus().isRemovableStatus()) {
InMemoryStateStore.deleteStack(stackId);
}
} else {
InMemoryStateStore.putCluster(cluster.getId(), statusToPollGroupConverter.convert(status));
if (InMemoryStateStore.getStack(stackId) == null) {
InMemoryStateStore.putStack(stackId, statusToPollGroupConverter.convert(stackStatus.getStatus()));
}
}
}
return cluster;
}
示例5: getKey
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@Override
@Transactional(value = TxType.NOT_SUPPORTED)
public String getKey() {
return KEY;
}
示例6: save
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@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;
}
示例7: read
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@Override
@Transactional(value = TxType.SUPPORTS)
public E read(final E transientInstance) throws MessageLabelException {
log.trace("Read entity {}", transientInstance);
if (transientInstance == null || transientInstance.getPrimaryKey() == null) {
throw new NullPrimaryKeyException();
}
return findByPk(transientInstance.getPrimaryKey());
}
示例8: findByPk
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@Override
@Transactional(TxType.SUPPORTS)
public E findByPk(final P pk) throws MessageLabelException {
log.trace("Get entity {} for pk {}", getModelClass().getName(), pk);
if (pk == null) {
throw new NullPrimaryKeyException();
}
final E entity = getEntityManager().find(getModelClass(), pk);
if (entity == null) {
log.trace("Object {} is not found for pk {}", getModelClass().getName(), pk);
} else {
log.trace("Object {} is found for pk {}", getModelClass().getName(), pk);
}
return entity;
}
示例9: findAllByPk
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
@Transactional(TxType.SUPPORTS)
public Collection<E> findAllByPk(final Collection<P> primaryKeys, final E eagerLoading) throws MessageLabelException {
if (primaryKeys == null) {
return null;
}
E eager = eagerLoading;
if (eagerLoading == null) {
eager = ObjectUtil.newInstance(getModelClass());
}
if (CollectionUtil.isEmpty(primaryKeys)) {
return ObjectUtil.newInstance(primaryKeys.getClass());
}
if (primaryKeys.size() >= MAX_ELEMENTS) {
throw new TooMuchDataException(MAX_ELEMENTS);
}
log.trace("Get entities {} for {} pk with eager loading ", getModelClass().getName(), primaryKeys.size());
final JpqlEntityQueryBuilder<E> queryBuilder = getQueryBuilder(eager);
queryBuilder.getWhere().in(queryBuilder.getAlias(eager) + StringUtil.DOT + EntityUtil.getPrimaryKeyField(getModelClass()).getName(),
primaryKeys);
final List<E> entities = queryBuilder.getResultList();
log.trace("Found {} entities {}", entities.size(), getModelClass().getName());
if (primaryKeys.getClass().equals(entities.getClass())) {
return entities;
} else {
return CollectionUtil.toCollection(entities, primaryKeys.getClass());
}
}
示例10: findAll
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@Override
@Transactional(TxType.SUPPORTS)
public List<E> findAll() throws MessageLabelException {
log.trace("Find all entities {}", getModelClass().getName());
final JpqlEntityQueryBuilder<E> queryBuilder = getQueryBuilder(null);
final List<E> entities = queryBuilder.getResultList();
log.trace("Found {} elements for entities {}", entities.size(), getModelClass().getName());
return entities;
}
示例11: update
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@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;
}
示例12: save
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@Override
@Transactional(TxType.REQUIRED)
public E save(final E detachedInstance) throws MessageLabelException {
if (EntityUtil.isNullPk(detachedInstance)) {
return create(detachedInstance);
} else {
return update(detachedInstance);
}
}
示例13: getConcert
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@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);
}
示例14: getSportsEvent
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@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);
}
示例15: getItem
import javax.transaction.Transactional.TxType; //导入依赖的package包/类
@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);
}