Java 类javax.persistence.ValidationMode 实例源码

项目:bookManager    文件:RootApplicationContextConfig.java   
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
    Map<String, Object> properties = new Hashtable<>();
    properties.put("javax.persistence.schema-generation.database.action", "none");
    properties.put("hibernate.connection.characterEncoding", "utf8");
    properties.put("hibernate.connection.useUnicode", "true");
    properties.put("hibernate.connection.charSet", "utf8");
    properties.put("hibernate.search.default.directory_provider", "filesystem");
    properties.put("hibernate.search.default.indexBase", context.getInitParameter("indexDir"));

    HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setDatabasePlatform("org.hibernate.dialect.MySQL5InnoDBDialect");

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(adapter);
    factory.setDataSource(this.bookManagerDataSource());
    factory.setPackagesToScan("net.viperfish.bookManager");
    factory.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);
    factory.setValidationMode(ValidationMode.NONE);
    factory.setJpaPropertyMap(properties);
    return factory;
}
项目:devicehive-java-server    文件:RdbmsPersistenceConfig.java   
@Bean
@DependsOn(value = {"simpleApplicationContextHolder"})
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
    factoryBean.setDataSource(dataSource);
    factoryBean.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);
    factoryBean.setValidationMode(ValidationMode.CALLBACK);
    factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
    factoryBean.setPackagesToScan("com.devicehive.model");

    final Properties props = new Properties();
    props.putAll(this.properties.getHibernateProperties(this.dataSource));
    if (useNativeClient) {
        props.put("hibernate.cache.hazelcast.native_client_group", groupName);
        props.put("hibernate.cache.hazelcast.native_client_password", groupPassword);
        if (!CollectionUtils.isEmpty(clusterMembers)) {
            props.put("hibernate.cache.hazelcast.native_client_address", clusterMembers.get(0));
        }
    }

    factoryBean.setJpaProperties(props);
    return factoryBean;
}
项目:aries-jpa    文件:JPAHandler.java   
@Override
public void endElement(String uri, String localName, String name) throws SAXException {
    String s = builder.toString().trim();
    // This step is VERY important, otherwise we pollute subsequent
    // elements
    builder = new StringBuilder();

    if ("".equals(s))
        return;

    PersistenceUnit pu = persistenceUnits.peek();

    if ("provider".equals(elementName))
        pu.setProviderClassName(s);
    else if ("jta-data-source".equals(elementName))
        pu.setJtaDataSourceName(s);
    else if ("non-jta-data-source".equals(elementName))
        pu.setNonJtaDataSourceName(s);
    else if ("class".equals(elementName))
        pu.addClassName(s);
    else if("mapping-file".equals(elementName))
        pu.addMappingFile(s);
    else if ("exclude-unlisted-classes".equals(elementName))
        pu.setExcludeUnlisted(Boolean.parseBoolean(s));
    else if ("shared-cache-mode".equals(elementName))
        pu.setSharedCacheMode(SharedCacheMode.valueOf(s));
    else if ("validation-mode".equals(elementName))
        pu.setValidationMode(ValidationMode.valueOf(s));
}
项目:amanda    文件:RootContextConfiguration.java   
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
    Map<String, Object> properties = new HashMap<>();
    // properties.put("javax.persistence.schema-generation.database.action", "none"); // 没有update选项,只有:none、create、drop-and-create、drop,不满足开发需求
    // properties.put("hibernate.hbm2ddl.auto", "update"); // 使用adapter.setGenerateDdl(true),避免拼写错误;
    properties.put("hibernate.ejb.use_class_enhancer", "true");
    properties.put("hibernate.search.default.directory_provider", "filesystem");
    properties.put("hibernate.search.lucene_version", "5.3.1"); // 避免控制台警告,默认使用LUCENE_CURRENT
    properties.put("hibernate.search.default.indexBase", "../amanda/searchIndexes");

    // properties.put("hibernate.show_sql", "true");
    // properties.put("hibernate.format_sql", "true");
    properties.put("hibernate.use_sql_comments", "true");
    properties.put("hibernate.physical_naming_strategy", "com.timeyang.amanda.core.jpa.naming.PhysicalNamingStrategyImpl");

    LocalContainerEntityManagerFactoryBean factory =
            new LocalContainerEntityManagerFactoryBean();
    factory.setDataSource(this.dataSource);
    factory.setJpaVendorAdapter(jpaVendorAdapter());
    factory.setPackagesToScan(AmandaApplication.class.getPackage().getName());
    factory.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);
    factory.setValidationMode(ValidationMode.NONE);
    factory.setLoadTimeWeaver(this.loadTimeWeaver()); // TODO: remove when SPR-10856 fixed
    factory.setJpaPropertyMap(properties);
    return factory;
}
项目:jpasecurity    文件:SecurePersistenceProviderTest.java   
private PersistenceUnitInfo createPersistenceUnitInfo() {
    PersistenceUnitInfo persistenceUnitInfo = mock(PersistenceUnitInfo.class);
    when(persistenceUnitInfo.getPersistenceUnitRootUrl()).thenReturn(createPersistenceUnitRootUrl());
    when(persistenceUnitInfo.getPersistenceUnitName()).thenReturn("annotation-based-field-access");
    when(persistenceUnitInfo.getTransactionType())
        .thenReturn(PersistenceUnitTransactionType.RESOURCE_LOCAL);
    when(persistenceUnitInfo.getValidationMode()).thenReturn(ValidationMode.AUTO);
    when(persistenceUnitInfo.getSharedCacheMode()).thenReturn(SharedCacheMode.UNSPECIFIED);
    when(persistenceUnitInfo.getJtaDataSource()).thenReturn(null);
    when(persistenceUnitInfo.getNonJtaDataSource()).thenReturn(null);
    when(persistenceUnitInfo.getNewTempClassLoader()).thenReturn(null);
    when(persistenceUnitInfo.getMappingFileNames()).thenReturn(Collections.<String>emptyList());
    when(persistenceUnitInfo.getJarFileUrls()).thenReturn(Collections.<URL>emptyList());
    when(persistenceUnitInfo.getPersistenceProviderClassName())
        .thenReturn(SecurePersistenceProvider.class.getName());
    when(persistenceUnitInfo.getClassLoader())
        .thenReturn(Thread.currentThread().getContextClassLoader());
    when(persistenceUnitInfo.getManagedClassNames()).thenReturn(Arrays.asList(
        FieldAccessAnnotationTestBean.class.getName(),
        FieldAccessMapKey.class.getName(),
        FieldAccessMapValue.class.getName()
    ));
    when(persistenceUnitInfo.excludeUnlistedClasses()).thenReturn(true);
    Properties properties = new Properties();
    properties.put("org.jpasecurity.persistence.provider", "org.hibernate.ejb.HibernatePersistence");
    properties.put("org.jpasecurity.security.context",
                   "org.jpasecurity.security.authentication.TestSecurityContext");
    properties.put("org.jpasecurity.security.rules.provider",
                   "org.jpasecurity.security.rules.XmlAccessRulesProvider");
    properties.put("hibernate.hbm2ddl.auto", "create-drop");
    properties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    properties.put("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
    properties.put("hibernate.connection.url", "jdbc:hsqldb:mem:test");
    properties.put("hibernate.connection.username", "sa");
    properties.put("hibernate.connection.password", "");
    when(persistenceUnitInfo.getProperties()).thenReturn(properties);
    return persistenceUnitInfo;
}
项目:LSChatServer    文件:ApplicationRootContext.java   
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean()
        throws ConfigurationException, IOException {
    Map<String, Object> properties = new Hashtable<>();
    String indexPath = this.configuration().getString(GlobalConfig.INDEX_PATH);
    if (indexPath == null) {
        indexPath = GlobalConfig.INDEX_PATH_DEFAULT;
    }
    properties.put("javax.persistence.schema-generation.database.action", "none");
    properties.put("hibernate.connection.characterEncoding", "utf8");
    properties.put("hibernate.connection.useUnicode", "true");
    properties.put("hibernate.connection.charSet", "utf8");
    properties.put("hibernate.search.default.directory_provider", "filesystem");
    properties.put("hibernate.search.default.indexBase", indexPath);

    HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setDatabasePlatform("org.hibernate.dialect.MySQL5InnoDBDialect");

    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(adapter);
    factory.setDataSource(this.chatDataSource());
    factory.setPackagesToScan("net.viperfish.chatapplication");
    factory.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);
    factory.setValidationMode(ValidationMode.NONE);
    factory.setJpaPropertyMap(properties);
    return factory;
}
项目:SpringBootMagicEightBallProject    文件:PersistenceConfiguration.java   
@Override
protected Map<String, Object> getVendorProperties() {
    LOGGER.info("PersistenceConfiguration.getVendorProperties()");
    HashMap<String, Object> vendorProperties = new HashMap<>();
    vendorProperties.put(PersistenceUnitProperties.WEAVING, detectWeavingMode());
    vendorProperties.put(PersistenceUnitProperties.VALIDATION_MODE, ValidationMode.NONE.toString());
    return vendorProperties;
}
项目:osgi.ee    文件:PersistenceUnitInfoImpl.java   
@Override
public ValidationMode getValidationMode() {
    if (definition.validationMode.isEmpty()) {
        return ValidationMode.AUTO;
    }
    return ValidationMode.valueOf(definition.validationMode);
}
项目:wisdom-jdbc    文件:PersistenceUnitComponent.java   
@Override
public ValidationMode getValidationMode() {
    PersistenceUnitValidationModeType validationMode = persistenceUnitXml.getValidationMode();
    if (validationMode == null) {
        return null;
    }

    return ValidationMode.valueOf(validationMode.name());
}
项目:bundles    文件:PersistenceUnitInfoImpl.java   
@Override
public ValidationMode getValidationMode() {
    PersistenceUnitValidationModeType validationMode = persistenceUnitXml.getValidationMode();
    if (validationMode == null)
        return null;

    return ValidationMode.valueOf(validationMode.name());
}
项目:debop4j    文件:JpaTestBase.java   
@Before
public void createFactory() throws MalformedURLException {
    GetterPersistenceUnitInfo info = new GetterPersistenceUnitInfo();
    info.setClassLoader(Thread.currentThread().getContextClassLoader());
    //we explicitly list them to avoid scanning
    info.setExcludeUnlistedClasses(true);
    info.setJtaDataSource(new NoopDatasource());
    List<String> classNames = new ArrayList<String>();
    for (Class<?> clazz : getEntities()) {
        classNames.add(clazz.getName());
    }
    info.setManagedClassNames(classNames);
    info.setNonJtaDataSource(null);
    info.setPersistenceProviderClassName(HibernateOgmPersistence.class.getName());
    info.setPersistenceUnitName("default");
    final URL persistenceUnitRootUrl = new File("").toURL();
    info.setPersistenceUnitRootUrl(persistenceUnitRootUrl);
    info.setPersistenceXMLSchemaVersion("2.0");
    info.setProperties(new Properties());
    info.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);
    info.setTransactionType(PersistenceUnitTransactionType.JTA);
    info.setValidationMode(ValidationMode.AUTO);
    info.getProperties().setProperty(Environment.JTA_PLATFORM,
                                     JBossStandAloneJtaPlatform.class.getName()
    );

    // MassIndexerFactoryIntegrator is defined at 4.3.0
    // info.getProperties().setProperty(MassIndexerFactoryIntegrator.MASS_INDEXER_FACTORY_CLASSNAME, OgmMassIndexerFactory.class.getName());
    for (Map.Entry<String, String> entry : TestHelper.getEnvironmentProperties().entrySet()) {
        info.getProperties().setProperty(entry.getKey(), entry.getValue());
    }
    refineInfo(info);

    factory = new HibernateOgmPersistence().createContainerEntityManagerFactory(info, Collections.EMPTY_MAP);
    transactionManager = extractJBossTransactionManager(factory);
}
项目:tomee    文件:PersistenceUnit.java   
public ValidationMode getValidationMode() {
    if (validationMode == null) {
        final String propConfig = getProperty("javax.persistence.validation.mode");
        if (propConfig != null) {
            try {
                validationMode = ValidationMode.valueOf(propConfig.toUpperCase());
            } catch (final IllegalArgumentException iae) { // can happen since some provider allow more than the enum
                // no-op
            }
        }
    }
    return (validationMode == null) ? ValidationMode.AUTO : validationMode;
}
项目:tomee    文件:ReloadableEntityManagerFactory.java   
public synchronized void setValidationMode(final ValidationMode mode) {
    final PersistenceUnitInfoImpl info = entityManagerFactoryCallable.getUnitInfo();
    info.setValidationMode(mode);

    final Properties properties = entityManagerFactoryCallable.getUnitInfo().getProperties();
    if (properties.containsKey(JAVAX_PERSISTENCE_VALIDATION_MODE)) {
        properties.setProperty(JAVAX_PERSISTENCE_VALIDATION_MODE, mode.name());
    }
}
项目:tomee    文件:ReloadableEntityManagerFactory.java   
@ManagedOperation
@Description("change the validation mode if possible (value is ok)")
public void setValidationMode(final String value) {
    try {
        final ValidationMode mode = ValidationMode.valueOf(value.trim().toUpperCase());
        reloadableEntityManagerFactory.setValidationMode(mode);
    } catch (final Exception iae) {
        LOGGER.warning("Can't set validation mode " + value, iae);
        reloadableEntityManagerFactory.setProperty(JAVAX_PERSISTENCE_VALIDATION_MODE, value);
    }
}
项目:osgi-jpa-container    文件:PersistenceUnitInfoImpl.java   
@Override
public ValidationMode getValidationMode() {
    String s = (String) parsedPersistenceUnit.getPersistenceXmlMetadata()
            .get(ParsedPersistenceUnit.VALIDATION_MODE);

    if (s == null) {
        return ValidationMode.AUTO;
    } else {
        return ValidationMode.valueOf(s);
    }
}
项目:testee.fi    文件:PersistenceUnitInfoImpl.java   
@Override
public ValidationMode getValidationMode() {
    return null;
}
项目:aries-jpa    文件:PersistenceUnit.java   
@Override
public ValidationMode getValidationMode() {
    return this.validationMode;
}
项目:aries-jpa    文件:PersistenceUnit.java   
public void setValidationMode(ValidationMode validationMode) {
    this.validationMode = validationMode;
}
项目:aries-jpa    文件:PersistenceUnitProxyWithTargetServer.java   
@Override
public ValidationMode getValidationMode() {
    return delegate.getValidationMode();
}
项目:lams    文件:PersistenceUnitReader.java   
/**
 * Parse the unit info DOM element.
 */
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, URL rootUrl)
        throws IOException {

    SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();

    // set JPA version (1.0 or 2.0)
    unitInfo.setPersistenceXMLSchemaVersion(version);

    // set persistence unit root URL
    unitInfo.setPersistenceUnitRootUrl(rootUrl);

    // set unit name
    unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim());

    // set transaction type
    String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim();
    if (StringUtils.hasText(txType)) {
        unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
    }

    // evaluate data sources
    String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE);
    if (StringUtils.hasText(jtaDataSource)) {
        unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim()));
    }

    String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE);
    if (StringUtils.hasText(nonJtaDataSource)) {
        unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim()));
    }

    // provider
    String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER);
    if (StringUtils.hasText(provider)) {
        unitInfo.setPersistenceProviderClassName(provider.trim());
    }

    // exclude unlisted classes
    Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES);
    if (excludeUnlistedClasses != null) {
        String excludeText = DomUtils.getTextValue(excludeUnlistedClasses);
        unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText));
    }

    // set JPA 2.0 shared cache mode
    String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
    if (StringUtils.hasText(cacheMode)) {
        unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode));
    }

    // set JPA 2.0 validation mode
    String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
    if (StringUtils.hasText(validationMode)) {
        unitInfo.setValidationMode(ValidationMode.valueOf(validationMode));
    }

    parseProperties(persistenceUnit, unitInfo);
    parseManagedClasses(persistenceUnit, unitInfo);
    parseMappingFiles(persistenceUnit, unitInfo);
    parseJarFiles(persistenceUnit, unitInfo);

    return unitInfo;
}
项目:lams    文件:MutablePersistenceUnitInfo.java   
public void setValidationMode(ValidationMode validationMode) {
    this.validationMode = validationMode;
}
项目:lams    文件:MutablePersistenceUnitInfo.java   
@Override
public ValidationMode getValidationMode() {
    return this.validationMode;
}
项目:vertx-jpa    文件:DefaultPersistenceUnitInfoImpl.java   
public ValidationMode getValidationMode() {
  return validationMode;
}
项目:vertx-jpa    文件:DefaultPersistenceUnitInfoImpl.java   
public void setValidationMode(ValidationMode validationMode) {
  this.validationMode = validationMode;
}
项目:hibernate-types    文件:PersistenceUnitInfoImpl.java   
@Override
public ValidationMode getValidationMode() {
    return ValidationMode.AUTO;
}
项目:hibernate-types    文件:PersistenceUnitInfoImpl.java   
@Override
public ValidationMode getValidationMode() {
    return ValidationMode.AUTO;
}
项目:hibernate-types    文件:PersistenceUnitInfoImpl.java   
@Override
public ValidationMode getValidationMode() {
    return ValidationMode.AUTO;
}
项目:hibernate-types    文件:PersistenceUnitInfoImpl.java   
@Override
public ValidationMode getValidationMode() {
    return ValidationMode.AUTO;
}
项目:jk-db    文件:JKPersistenceUnitInfoImpl.java   
@Override
public ValidationMode getValidationMode() {
    return ValidationMode.AUTO;
}
项目:spring4-understanding    文件:PersistenceUnitReader.java   
/**
 * Parse the unit info DOM element.
 */
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, URL rootUrl)
        throws IOException {

    SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();

    // set JPA version (1.0 or 2.0)
    unitInfo.setPersistenceXMLSchemaVersion(version);

    // set persistence unit root URL
    unitInfo.setPersistenceUnitRootUrl(rootUrl);

    // set unit name
    unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim());

    // set transaction type
    String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim();
    if (StringUtils.hasText(txType)) {
        unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
    }

    // evaluate data sources
    String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE);
    if (StringUtils.hasText(jtaDataSource)) {
        unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim()));
    }

    String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE);
    if (StringUtils.hasText(nonJtaDataSource)) {
        unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim()));
    }

    // provider
    String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER);
    if (StringUtils.hasText(provider)) {
        unitInfo.setPersistenceProviderClassName(provider.trim());
    }

    // exclude unlisted classes
    Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES);
    if (excludeUnlistedClasses != null) {
        String excludeText = DomUtils.getTextValue(excludeUnlistedClasses);
        unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText));
    }

    // set JPA 2.0 shared cache mode
    String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
    if (StringUtils.hasText(cacheMode)) {
        unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode));
    }

    // set JPA 2.0 validation mode
    String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
    if (StringUtils.hasText(validationMode)) {
        unitInfo.setValidationMode(ValidationMode.valueOf(validationMode));
    }

    parseProperties(persistenceUnit, unitInfo);
    parseManagedClasses(persistenceUnit, unitInfo);
    parseMappingFiles(persistenceUnit, unitInfo);
    parseJarFiles(persistenceUnit, unitInfo);

    return unitInfo;
}
项目:spring4-understanding    文件:MutablePersistenceUnitInfo.java   
public void setValidationMode(ValidationMode validationMode) {
    this.validationMode = validationMode;
}
项目:spring4-understanding    文件:MutablePersistenceUnitInfo.java   
@Override
public ValidationMode getValidationMode() {
    return this.validationMode;
}
项目:carbon    文件:DefaultPersistenceUnitInfo.java   
@Override
public ValidationMode getValidationMode() {
    return ValidationMode.AUTO;
}
项目:jspare-container    文件:DefaultPersistenceUnitInfoImpl.java   
public ValidationMode getValidationMode() {
  return validationMode;
}
项目:jspare-container    文件:DefaultPersistenceUnitInfoImpl.java   
public void setValidationMode(ValidationMode validationMode) {
  this.validationMode = validationMode;
}
项目:cibet    文件:DefaultPersistenceUnitInfo.java   
public ValidationMode getValidationMode() {
   return validationMode;
}
项目:cibet    文件:DefaultPersistenceUnitInfo.java   
public void setValidationMode(ValidationMode mode) {
   validationMode = mode;
}
项目:cibet    文件:DelegatingPersistenceUnitInfo.java   
public ValidationMode getValidationMode() {
    return delegate.getValidationMode();
}
项目:jpasecurity    文件:DelegatingPersistenceUnitInfo.java   
public ValidationMode getValidationMode() {
    return delegate.getValidationMode();
}
项目:rise    文件:PersistenceUnitManagerHelper.java   
public MutablePersistenceUnitInfo createUnit(Class<? extends Annotation> qualifier, String unitName) {
    ClassLoader classLoader = holder.getCurrentReloadableClassLoader();
    MutablePersistenceUnitInfo result = new MutablePersistenceUnitInfo();
    result.setExcludeUnlistedClasses(true);
    result.setValidationMode(ValidationMode.NONE);
    result.setPersistenceUnitName(unitName);
    result.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);

    try {
        result.setPersistenceUnitRootUrl(new URL("http://foo.foo"));
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }

    result.addProperty(PersistenceUnitProperties.SESSION_CUSTOMIZER, CompositeSessionCustomizer.class.getName());

    // search for entities
    {
        Set<Class<?>> jpaAnnotations = new HashSet<>(
                Arrays.asList(Entity.class, MappedSuperclass.class, Embeddable.class));
        for (ClassNode classNode : index.getAllNodes()) {
            String className = Type.getObjectType(classNode.name).getClassName();

            if (classNode.visibleAnnotations == null)
                continue;

            boolean jpaAnnotationFound = false;
            for (AnnotationNode annotation : classNode.visibleAnnotations) {
                Class<?> annotationClass = AsmUtil.loadClass(Type.getType(annotation.desc), classLoader);

                // test if the annotation is one of the jpa annotations
                if (jpaAnnotations.contains(annotationClass))
                    jpaAnnotationFound = true;

            }

            if (jpaAnnotationFound && isPartOfPU(classNode, qualifier, classLoader)) {
                result.addManagedClassName(className);
            }
        }
    }

    // search converters
    {
        index.getAllChildren(AttributeConverter.class).stream()
                .filter(node -> isPartOfPU(node, qualifier, classLoader))
                .map(node -> AsmUtil.loadClass(Type.getObjectType(node.name), classLoader)).forEach(cls -> {
                    Converter converter = cls.getAnnotation(Converter.class);
                    if (converter != null && converter.autoApply())
                        result.addManagedClassName(cls.getName());
                });
    }
    return result;
}