コード例 #1
0
  protected JavaTypeDescriptor makeTypeDescriptor(Name typeName) {
    final String classNameToLoad = typeName.fullName();

    if (isSafeClass(typeName)) {
      return makeTypeDescriptor(typeName, classLoaderService.classForName(classNameToLoad));
    } else {
      if (jpaTempClassLoader == null) {
        log.debug(
            "Request to makeTypeDescriptor(%s) - but passed class is not known to be "
                + "safe (it might be, it might not be). However, there was no "
                + "temp ClassLoader provided; we will use the live ClassLoader");
        try {
          // this reference is "safe" because it was loaded from the live ClassLoader
          return makeTypeDescriptor(typeName, classLoaderService.classForName(classNameToLoad));
        } catch (ClassLoadingException e) {
          return new NoSuchClassTypeDescriptor(typeName);
        }
      } else {
        log.debug(
            "Request to makeTypeDescriptor(%s) - passed class is not known to be "
                + "safe (it might be, it might not be). There was a temp ClassLoader "
                + "provided, so we will use that");
        // this is the Class reference that is unsafe to keep around...
        final Class unSafeReference;
        try {
          unSafeReference = jpaTempClassLoader.loadClass(classNameToLoad);
        } catch (ClassNotFoundException e) {
          return new NoSuchClassTypeDescriptor(typeName);
        }

        return makeTypeDescriptor(typeName, unSafeReference);
      }
    }
  }
コード例 #2
0
 private Schema resolveLocalSchema(String schemaName, String schemaLanguage) {
   URL url = classLoaderService.locateResource(schemaName);
   if (url == null) {
     throw new XsdException(
         "Unable to locate schema [" + schemaName + "] via classpath", schemaName);
   }
   try {
     InputStream schemaStream = url.openStream();
     try {
       StreamSource source = new StreamSource(url.openStream());
       SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
       return schemaFactory.newSchema(source);
     } catch (SAXException e) {
       throw new XsdException("Unable to load schema [" + schemaName + "]", e, schemaName);
     } catch (IOException e) {
       throw new XsdException("Unable to load schema [" + schemaName + "]", e, schemaName);
     } finally {
       try {
         schemaStream.close();
       } catch (IOException e) {
         log.debugf("Problem closing schema stream [%s]", e.toString());
       }
     }
   } catch (IOException e) {
     throw new XsdException(
         "Stream error handling schema url [" + url.toExternalForm() + "]", schemaName);
   }
 }
コード例 #3
0
  private static BasicTypeRegistry handleTypes(MetadataBuildingOptions options) {
    final ClassLoaderService classLoaderService =
        options.getServiceRegistry().getService(ClassLoaderService.class);

    // ultimately this needs to change a little bit to account for HHH-7792
    final BasicTypeRegistry basicTypeRegistry = new BasicTypeRegistry();

    final TypeContributions typeContributions =
        new TypeContributions() {
          public void contributeType(BasicType type) {
            basicTypeRegistry.register(type);
          }

          public void contributeType(BasicType type, String... keys) {
            basicTypeRegistry.register(type, keys);
          }

          public void contributeType(UserType type, String... keys) {
            basicTypeRegistry.register(type, keys);
          }

          public void contributeType(CompositeUserType type, String... keys) {
            basicTypeRegistry.register(type, keys);
          }
        };

    // add Dialect contributed types
    final Dialect dialect =
        options.getServiceRegistry().getService(JdbcServices.class).getDialect();
    dialect.contributeTypes(typeContributions, options.getServiceRegistry());

    // add TypeContributor contributed types.
    for (TypeContributor contributor : classLoaderService.loadJavaServices(TypeContributor.class)) {
      contributor.contribute(typeContributions, options.getServiceRegistry());
    }

    // add explicit application registered types
    for (BasicTypeRegistration basicTypeRegistration : options.getBasicTypeRegistrations()) {
      basicTypeRegistry.register(
          basicTypeRegistration.getBasicType(), basicTypeRegistration.getRegistrationKeys());
    }

    return basicTypeRegistry;
  }
コード例 #4
0
ファイル: SimpleValue.java プロジェクト: lorzab/myProject
  public void setTypeName(String typeName) {
    if (typeName != null && typeName.startsWith(AttributeConverterTypeAdapter.NAME_PREFIX)) {
      final String converterClassName =
          typeName.substring(AttributeConverterTypeAdapter.NAME_PREFIX.length());
      final ClassLoaderService cls =
          getMetadata()
              .getMetadataBuildingOptions()
              .getServiceRegistry()
              .getService(ClassLoaderService.class);
      try {
        final Class<AttributeConverter> converterClass = cls.classForName(converterClassName);
        attributeConverterDefinition =
            new AttributeConverterDefinition(converterClass.newInstance(), false);
        return;
      } catch (Exception e) {
        log.logBadHbmAttributeConverterType(typeName, e.getMessage());
      }
    }

    this.typeName = typeName;
  }
コード例 #5
0
  public MetadataBuilderImpl(MetadataSources sources, StandardServiceRegistry serviceRegistry) {
    this.sources = sources;
    this.options = new MetadataBuildingOptionsImpl(serviceRegistry);

    for (MetadataSourcesContributor contributor :
        sources
            .getServiceRegistry()
            .getService(ClassLoaderService.class)
            .loadJavaServices(MetadataSourcesContributor.class)) {
      contributor.contribute(sources);
    }

    // todo : not so sure this is needed anymore.
    //		these should be set during the StandardServiceRegistryBuilder.configure call
    applyCfgXmlValues(serviceRegistry.getService(CfgXmlAccessService.class));

    final ClassLoaderService classLoaderService =
        serviceRegistry.getService(ClassLoaderService.class);
    for (MetadataBuilderInitializer contributor :
        classLoaderService.loadJavaServices(MetadataBuilderInitializer.class)) {
      contributor.contribute(this, serviceRegistry);
    }
  }
コード例 #6
0
 @Override
 @SuppressWarnings("unchecked")
 public Class<?> classForName(String name) {
   if (isSafeClass(name)) {
     return classLoaderService.classForName(name);
   } else {
     log.debugf("Not known whether passed class name [%s] is safe", name);
     if (jpaTempClassLoader == null) {
       log.debugf(
           "No temp ClassLoader provided; using live ClassLoader "
               + "for loading potentially unsafe class : %s",
           name);
       return classLoaderService.classForName(name);
     } else {
       log.debugf("Temp ClassLoader was provided, so we will use that : %s", name);
       try {
         return jpaTempClassLoader.loadClass(name);
       } catch (ClassNotFoundException e) {
         throw new ClassLoadingException(name);
       }
     }
   }
 }
コード例 #7
0
ファイル: SimpleValue.java プロジェクト: lorzab/myProject
  private void createParameterImpl() {
    try {
      String[] columnsNames = new String[columns.size()];
      for (int i = 0; i < columns.size(); i++) {
        Selectable column = columns.get(i);
        if (column instanceof Column) {
          columnsNames[i] = ((Column) column).getName();
        }
      }

      final XProperty xProperty =
          (XProperty) typeParameters.get(DynamicParameterizedType.XPROPERTY);
      // todo : not sure this works for handling @MapKeyEnumerated
      final Annotation[] annotations = xProperty == null ? null : xProperty.getAnnotations();

      final ClassLoaderService classLoaderService =
          getMetadata()
              .getMetadataBuildingOptions()
              .getServiceRegistry()
              .getService(ClassLoaderService.class);
      typeParameters.put(
          DynamicParameterizedType.PARAMETER_TYPE,
          new ParameterTypeImpl(
              classLoaderService.classForName(
                  typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS)),
              annotations,
              table.getCatalog(),
              table.getSchema(),
              table.getName(),
              Boolean.valueOf(typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY)),
              columnsNames));
    } catch (ClassLoadingException e) {
      throw new MappingException(
          "Could not create DynamicParameterizedType for type: " + typeName, e);
    }
  }
コード例 #8
0
  public IntegratorServiceImpl(
      LinkedHashSet<Integrator> providedIntegrators, ClassLoaderService classLoaderService) {
    // register standard integrators.  Envers and JPA, for example, need to be handled by discovery
    // because in
    // separate project/jars.
    addIntegrator(new BeanValidationIntegrator());
    addIntegrator(new JaccIntegrator());
    addIntegrator(new CollectionCacheInvalidator());

    // register provided integrators
    for (Integrator integrator : providedIntegrators) {
      addIntegrator(integrator);
    }

    for (Integrator integrator : classLoaderService.loadJavaServices(Integrator.class)) {
      addIntegrator(integrator);
    }
  }
コード例 #9
0
  /**
   * Builds the selector.
   *
   * @param classLoaderService The class loading service used to (attempt to) resolve any
   *     un-registered strategy implementations.
   * @return The selector.
   */
  public StrategySelector buildSelector(ClassLoaderService classLoaderService) {
    final StrategySelectorImpl strategySelector = new StrategySelectorImpl(classLoaderService);

    // build the baseline...
    addDialects(strategySelector);
    addJtaPlatforms(strategySelector);
    addTransactionFactories(strategySelector);
    addMultiTableBulkIdStrategies(strategySelector);

    // apply auto-discovered registrations
    for (AvailabilityAnnouncer announcer :
        classLoaderService.loadJavaServices(AvailabilityAnnouncer.class)) {
      for (Availability discoveredAvailability : announcer.getAvailabilities()) {
        applyFromAvailability(strategySelector, discoveredAvailability);
      }
    }

    // apply customizations
    for (Availability explicitAvailability : explicitAvailabilities) {
      applyFromAvailability(strategySelector, explicitAvailability);
    }

    return strategySelector;
  }
コード例 #10
0
 @Override
 public URL locateResource(String resourceName) {
   return classLoaderService.locateResource(resourceName);
 }