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


Java Transactional类代码示例

本文整理汇总了Java中com.google.inject.persist.Transactional的典型用法代码示例。如果您正苦于以下问题:Java Transactional类的具体用法?Java Transactional怎么用?Java Transactional使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: updateEndPointWithLock

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Transactional
protected void updateEndPointWithLock(final EndPoint endPoint) {
    checkEndPointNameDoesNotExist(endPoint);

    final EndPoint existingEndPoint = findEndPoint(endPoint.getId());

    if (!existingEndPoint.getVersion().equals(endPoint.getVersion())) {
        throw new EndPointHealthException("End point has been updated somewhere else, please refresh");
    }

    existingEndPoint.setName(endPoint.getName());
    existingEndPoint.setHost(endPoint.getHost());
    existingEndPoint.setPath(endPoint.getPath());
    existingEndPoint.setPort(endPoint.getPort());
    existingEndPoint.setProtocol(endPoint.getProtocol());

    clearAttributesIfNeeded(existingEndPoint);
}
 
开发者ID:spypunk,项目名称:endpoint-health,代码行数:19,代码来源:EndPointServiceImpl.java

示例2: dispatchOtp

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Transactional
@Override
public boolean dispatchOtp(String inviteCode) {
    return inviteDao.findByCode(inviteCode)
            .map(inviteEntity -> {
                inviteEntity.setTelephoneNumber(inviteOtpRequest.getTelephoneNumber());
                inviteEntity.setPassword(passwordHasher.hash(inviteOtpRequest.getPassword()));
                inviteDao.merge(inviteEntity);
                int newPassCode = secondFactorAuthenticator.newPassCode(inviteEntity.getOtpKey());
                String passcode = format(Locale.ENGLISH, SIX_DIGITS_WITH_LEADING_ZEROS, newPassCode);
                notificationService.sendSecondFactorPasscodeSms(inviteOtpRequest.getTelephoneNumber(), passcode)
                        .thenAcceptAsync(notificationId -> LOGGER.info("sent 2FA token successfully for invite code [{}], notification id [{}]",
                                inviteCode, notificationId))
                        .exceptionally(exception -> {
                            LOGGER.error(format("error sending 2FA token for invite code [%s]", inviteCode), exception);
                            return null;
                        });
                LOGGER.info("New 2FA token generated for invite code [{}]", inviteCode);
                return true;
            }).orElseGet(() -> {
                LOGGER.info("New 2FA token generated for invite code [{}]", inviteCode);
                return false;
            });
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:25,代码来源:UserOtpDispatcher.java

示例3: reGenerateOtp

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Deprecated // Refactor to adopt UserOtpDispatcher. And Avoid using generic InviteOtpRequest object to avoid having to use optional fields
@Transactional
public void reGenerateOtp(InviteOtpRequest inviteOtpRequest) {
    Optional<InviteEntity> inviteOptional = inviteDao.findByCode(inviteOtpRequest.getCode());
    if (inviteOptional.isPresent()) {
        InviteEntity invite = inviteOptional.get();
        invite.setTelephoneNumber(inviteOtpRequest.getTelephoneNumber());
        inviteDao.merge(invite);
        int newPassCode = secondFactorAuthenticator.newPassCode(invite.getOtpKey());
        String passcode = String.format(Locale.ENGLISH, SIX_DIGITS_WITH_LEADING_ZEROS, newPassCode);
        notificationService.sendSecondFactorPasscodeSms(inviteOtpRequest.getTelephoneNumber(), passcode)
                .thenAcceptAsync(notificationId -> LOGGER.info("sent 2FA token successfully for invite code [{}], notification id [{}]",
                        inviteOtpRequest.getCode(), notificationId))
                .exceptionally(exception -> {
                    LOGGER.error(format("error sending 2FA token for invite code [%s]", inviteOtpRequest.getCode()), exception);
                    return null;
                });
        LOGGER.info("New 2FA token generated for invite code [{}]", inviteOtpRequest.getCode());
    } else {
        throw notFoundInviteException(inviteOtpRequest.getCode());
    }
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:23,代码来源:InviteService.java

示例4: doCreate

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Transactional
public Service doCreate(Optional<String> serviceName, Optional<List<String>> gatewayAccountIdsOptional) {
    Service service = serviceName
            .map(name -> Service.from(name))
            .orElseGet(() -> Service.from());

    ServiceEntity serviceEntity = ServiceEntity.from(service);
    if (gatewayAccountIdsOptional.isPresent()) {
        List<String> gatewayAccountsIds = gatewayAccountIdsOptional.get();
        if (serviceDao.checkIfGatewayAccountsUsed(gatewayAccountsIds)) {
            throw conflictingServiceGatewayAccounts(gatewayAccountsIds);
        }
        serviceEntity.addGatewayAccountIds(gatewayAccountsIds.toArray(new String[0]));
    }
    serviceDao.persist(serviceEntity);
    return linksBuilder.decorate(serviceEntity.toService());
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:18,代码来源:ServiceCreator.java

示例5: doCreate

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Transactional
public User doCreate(CreateUserRequest userRequest, String roleName) {
    return roleDao.findByRoleName(roleName)
            .map(roleEntity -> {
                UserEntity userEntity = UserEntity.from(userRequest);
                userEntity.setPassword(passwordHasher.hash(userRequest.getPassword()));
                if (!userRequest.getServiceExternalIds().isEmpty()) {
                    addServiceRoleToUser(userEntity, roleEntity, userRequest.getServiceExternalIds());
                }
                //Deprecated, leaving for backward compatibility
                else if (userRequest.getGatewayAccountIds() != null && userRequest.getGatewayAccountIds().size() > 0) {
                    addServiceFromGatewayAccountsToUser(userEntity, roleEntity, userRequest.getGatewayAccountIds());
                }
                userDao.persist(userEntity);
                return linksBuilder.decorate(userEntity.toUser());
            })
            .orElseThrow(() -> undefinedRoleException(roleName));
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:19,代码来源:UserCreator.java

示例6: configure

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Override
protected final void configure() {
	configurePersistence();

	requireBinding(PersistService.class);
	requireBinding(UnitOfWork.class);
/*if[AOP]*/
	// wrapping in an if[AOP] just to allow this to compile in NO_AOP -- it won't be used

	// class-level @Transacational
	bindInterceptor(annotatedWith(Transactional.class),
			new TransactionalClassMethodMatcher(),
			getTransactionInterceptor());
	// method-level @Transacational
	bindInterceptor(any(), new TransactionalMethodMatcher(), getTransactionInterceptor());
   /*end[AOP]*/
}
 
开发者ID:mangrish,项目名称:guice-persist-neo4j,代码行数:18,代码来源:Neo4jPersistModule.java

示例7: readTransactionMetadata

import com.google.inject.persist.Transactional; //导入依赖的package包/类
private Transactional readTransactionMetadata(MethodInvocation methodInvocation)
{
    Transactional transactional;
    Method method = methodInvocation.getMethod();
    Class<?> targetClass = methodInvocation.getThis().getClass();

    transactional = method.getAnnotation(Transactional.class);
    if (null == transactional)
    {
        // If none on method, try the class.
        transactional = targetClass.getAnnotation(Transactional.class);
    }
    if (null == transactional)
    {
        // If there is no transactional annotation present, use the default
        transactional = Neo4jLocalTxnInterceptor.Internal.class.getAnnotation(Transactional.class);
    }

    return transactional;
}
 
开发者ID:mangrish,项目名称:guice-persist-neo4j,代码行数:21,代码来源:Neo4jLocalTxnInterceptor.java

示例8: store

import com.google.inject.persist.Transactional; //导入依赖的package包/类
/**
 * Stores (create or updates) invite.
 *
 * <p>It also send email invite on initial invite creation.
 *
 * @param invite invite to store
 * @throws ConflictException when user is specified email is already registered
 * @throws ServerException when any other error occurs during invite storing
 */
@Transactional(rollbackOn = {RuntimeException.class, ServerException.class})
public void store(Invite invite) throws NotFoundException, ConflictException, ServerException {
  requireNonNull(invite, "Required non-null invite");
  String domainId = invite.getDomainId();
  if (!OrganizationDomain.DOMAIN_ID.equals(domainId)
      && !WorkspaceDomain.DOMAIN_ID.equals(domainId)) {
    throw new ConflictException("Invitations for specified domain are not supported");
  }
  permissionsManager.checkActionsSupporting(domainId, invite.getActions());

  try {
    userManager.getByEmail(invite.getEmail());
    throw new ConflictException("User with specified id is already registered");
  } catch (NotFoundException ignored) {
  }

  Optional<InviteImpl> existingInvite = inviteDao.store(new InviteImpl(invite));
  if (!existingInvite.isPresent()) {
    Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
    eventService.publish(
        new InviteCreatedEvent(
            currentSubject.isAnonymous() ? null : currentSubject.getUserId(), invite));
  }
}
 
开发者ID:codenvy,项目名称:codenvy,代码行数:34,代码来源:InviteManager.java

示例9: doCreate

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Transactional
protected Optional<InviteImpl> doCreate(InviteImpl invite) throws ServerException {
  EntityManager manager = managerProvider.get();
  InviteImpl existing = null;
  try {
    final InviteImpl result =
        getEntity(invite.getDomainId(), invite.getInstanceId(), invite.getEmail());
    existing = new InviteImpl(result);
    result.getActions().clear();
    result.getActions().addAll(invite.getActions());
  } catch (NotFoundException n) {
    manager.persist(invite);
  }
  manager.flush();
  return Optional.ofNullable(existing);
}
 
开发者ID:codenvy,项目名称:codenvy,代码行数:17,代码来源:JpaInviteDao.java

示例10: create

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Transactional
public Issue create(RepositoryPK repositoryPK, PullRequestForm form) {
  Repository repository = emProvider.get().find(Repository.class, repositoryPK);
  Issue issue = issueService.createIssueAndComment(repository, form.getTitle(), form.getContent(), null);

  PullRequest pullRequest = new PullRequest();
  pullRequest.setPk(issue.getPk());
  form.applyTo(pullRequest);
  pullRequest.setCommitId(ObjectId.zeroId().name());
  pullRequest.setBaseCommitId(ObjectId.zeroId().name());
  pullRequest.setRequestCommitId(ObjectId.zeroId().name());
  emProvider.get().persist(pullRequest);

  RepositoryPK reqRepoPK = new RepositoryPK(form.getRequestUserName(), form.getRequestRepoName());
  gitOperation.updatePullRequestRefSpec(issue.getPk(), reqRepoPK, form.getRequestBranch());

  updateCommitIds(pullRequest);

  return issue;
}
 
开发者ID:kamegu,项目名称:git-webapp,代码行数:21,代码来源:PullRequestService.java

示例11: createRepository

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Transactional
public Result<Repository> createRepository(String userName, RepositoryForm repositoryForm) {
  if (!repositoryForm.getOwner().equals(userName)) {
    throw new ForbiddenException();
  }
  Repository check = emProvider.get().find(Repository.class, new RepositoryPK(userName, repositoryForm.getName()));
  if (check != null) {
    return Result.error("already exists");
  }

  Repository repository = new Repository();
  repository.setPk(new RepositoryPK(userName, repositoryForm.getName()));
  repository.setPrivateRepo(repositoryForm.isPrivateRepo());
  repository.setDescription(repositoryForm.getDescription());
  emProvider.get().persist(repository);

  gitOperation.init(userName, repository.getPk().getRepositoryName(), repository.getDefaultBranch());

  return Result.success(repository);
}
 
开发者ID:kamegu,项目名称:git-webapp,代码行数:21,代码来源:RepositoryService.java

示例12: getMeargeable

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Transactional
public MergeableType getMeargeable(PullRequestEndpoint baseEndpoint, PullRequestEndpoint requestEndpoint) {
  ObjectId commitId = gitOperation.getCommitId(baseEndpoint.getRepositoryPK(), baseEndpoint.getBranchName());
  ObjectId requestCommitId = gitOperation.getCommitId(requestEndpoint.getRepositoryPK(), requestEndpoint.getBranchName());

  MergeableHistoryPK pk = new MergeableHistoryPK(baseEndpoint.getRepositoryPK(), commitId.getName(), requestCommitId.getName());
  MergeableHistory history = emProvider.get().find(MergeableHistory.class, pk);
  if (history != null) {
    return history.getMergeableType();
  }

  boolean canMerge = gitOperation.canMerge(baseEndpoint.getRepositoryPK(), baseEndpoint.getBranchName(), requestEndpoint.getRepositoryPK(), requestEndpoint.getBranchName());
  history = new MergeableHistory();
  history.setPk(pk);
  history.setMergeableType(MergeableType.of(canMerge));
  emProvider.get().persist(history);

  return history.getMergeableType();
}
 
开发者ID:kamegu,项目名称:git-webapp,代码行数:20,代码来源:MergeService.java

示例13: registerMailSettings

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Transactional
public Result<Boolean> registerMailSettings(MailJson mailJson) {
  getAppProperties().forEach(prop -> {
    emProvider.get().remove(prop);
  });

  List<AppProperty> appProperties = mailJson.createAppProperties();
  appProperties.stream()
  .filter(prop -> Objects.nonNull(prop.getValue()))
  .forEach(prop -> {
    emProvider.get().persist(prop);
  });

  // reset
  mailSender.initProperties(true);

  return Result.success(true);
}
 
开发者ID:kamegu,项目名称:git-webapp,代码行数:19,代码来源:MailService.java

示例14: doCreate

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Transactional
protected Optional<T> doCreate(T permissions) throws ServerException {
  EntityManager manager = managerProvider.get();
  try {
    final T result =
        getEntity(wildcardToNull(permissions.getUserId()), permissions.getInstanceId());
    final T existing =
        getDomain().newInstance(result.getUserId(), result.getInstanceId(), result.getActions());
    result.getActions().clear();
    result.getActions().addAll(permissions.getActions());
    manager.flush();
    return Optional.of(existing);
  } catch (NotFoundException n) {
    manager.persist(permissions);
    manager.flush();
    return Optional.empty();
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:AbstractJpaPermissionsDao.java

示例15: getAll

import com.google.inject.persist.Transactional; //导入依赖的package包/类
@Override
@Transactional
public Page<FreeResourcesLimitImpl> getAll(int maxItems, int skipCount) throws ServerException {
  try {
    final List<FreeResourcesLimitImpl> list =
        managerProvider
            .get()
            .createNamedQuery("FreeResourcesLimit.getAll", FreeResourcesLimitImpl.class)
            .setMaxResults(maxItems)
            .setFirstResult(skipCount)
            .getResultList()
            .stream()
            .map(FreeResourcesLimitImpl::new)
            .collect(Collectors.toList());
    return new Page<>(list, skipCount, maxItems, getTotalCount());
  } catch (RuntimeException e) {
    throw new ServerException(e.getMessage(), e);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:JpaFreeResourcesLimitDao.java


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