コード例 #1
0
 private static boolean deploymentHasPersistenceProvider(DeploymentUnit deploymentUnit) {
   deploymentUnit = DeploymentUtils.getTopDeploymentUnit(deploymentUnit);
   PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder =
       deploymentUnit.getAttachment(JpaAttachments.DEPLOYED_PERSISTENCE_PROVIDER);
   return (persistenceProviderDeploymentHolder != null
           && persistenceProviderDeploymentHolder.getProviders() != null
       ? persistenceProviderDeploymentHolder.getProviders().size() > 0
       : false);
 }
コード例 #2
0
 private static PersistenceUnitMetadata findPersistenceUnitSupplier(
     DeploymentUnit deploymentUnit, String persistenceUnitName) {
   PersistenceUnitMetadata name = findWithinDeployment(deploymentUnit, persistenceUnitName);
   if (name == null) {
     name =
         findWithinApplication(
             DeploymentUtils.getTopDeploymentUnit(deploymentUnit), persistenceUnitName);
   }
   return name;
 }
コード例 #3
0
  private static PersistenceUnitMetadata getPersistenceUnit(
      DeploymentUnit current, final String absolutePath, String puName) {
    final String path;
    if (absolutePath.startsWith("../")) {
      path = absolutePath.substring(3);
    } else {
      path = absolutePath;
    }
    final VirtualFile parent =
        current.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot().getParent();
    final VirtualFile resolvedPath = parent.getChild(path);

    List<ResourceRoot> resourceRoots =
        DeploymentUtils.allResourceRoots(DeploymentUtils.getTopDeploymentUnit(current));

    for (ResourceRoot resourceRoot : resourceRoots) {
      if (resourceRoot.getRoot().equals(resolvedPath)) {
        PersistenceUnitMetadataHolder holder =
            resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
        if (holder != null) {
          for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
            if (traceEnabled) {
              ROOT_LOGGER.tracef(
                  "getPersistenceUnit check '%s' against pu '%s'",
                  puName, pu.getPersistenceUnitName());
            }
            if (pu.getPersistenceUnitName().equals(puName)) {
              if (traceEnabled) {
                ROOT_LOGGER.tracef(
                    "getPersistenceUnit matched '%s' against pu '%s'",
                    puName, pu.getPersistenceUnitName());
              }
              return pu;
            }
          }
        }
      }
    }

    throw MESSAGES.persistenceUnitNotFound(absolutePath, puName, current);
  }