Package org.jboss.as.jpa.spi

Examples of org.jboss.as.jpa.spi.PersistenceProviderAdaptor


            final HashMap properties = new HashMap();
            if (!ValidationMode.NONE.equals(pu.getValidationMode())) {
                ValidatorFactory validatorFactory = SerializableValidatorFactory.validatorFactory();
                properties.put("javax.persistence.validation.factory", validatorFactory);
            }
            final PersistenceProviderAdaptor adaptor = getPersistenceProviderAdaptor(pu, persistenceProviderDeploymentHolder, deploymentUnit);


            PersistenceProvider provider = null;
            if (persistenceProviderDeploymentHolder != null &&
                persistenceProviderDeploymentHolder.getProvider() != null) {

                List<PersistenceProvider> providerList = persistenceProviderDeploymentHolder.getProvider();
                for (PersistenceProvider persistenceProvider : providerList) {
                    if (persistenceProvider.getClass().getName().equals(pu.getPersistenceProviderClassName())) {
                        provider = persistenceProvider;
                        JPA_LOGGER.tracef("deployment %s is using its own copy of %s", deploymentUnit.getName(), pu.getPersistenceProviderClassName());
                        break;
                    }
                }
            }
            //  look provider up if we didn't use the providers packaged with the application
            if (provider == null) {
                provider = lookupProvider(pu);
            }

            final PersistenceUnitServiceImpl service = new PersistenceUnitServiceImpl(classLoader, pu, adaptor, provider);

            phaseContext.getDeploymentUnit().addToAttachmentList(REMOVAL_KEY, new PersistenceAdaptorRemoval(pu, adaptor));

            // add persistence provider specific properties
            adaptor.addProviderProperties(properties, pu);


            final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu);
            // add the PU service as a dependency to all EE components in this scope
            this.addPUServiceDependencyToComponents(components, puServiceName);

            deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, puServiceName);

            ServiceBuilder<PersistenceUnitServiceImpl> builder = serviceTarget.addService(puServiceName, service);
            boolean useDefaultDataSource = true;
            final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName());
            final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());

            if (jtaDataSource != null && jtaDataSource.length() > 0) {
                if (jtaDataSource.startsWith("java:")) {
                    builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, jtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getJtaDataSourceInjector()));
                    useDefaultDataSource = false;
                } else {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(jtaDataSource), new CastingInjector<DataSource>(service.getJtaDataSourceInjector(), DataSource.class));
                    useDefaultDataSource = false;
                }
            }
            if (nonJtaDataSource != null && nonJtaDataSource.length() > 0) {
                if (nonJtaDataSource.startsWith("java:")) {
                    builder.addDependency(ContextNames.bindInfoForEnvEntry(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), false, nonJtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getNonJtaDataSourceInjector()));
                    useDefaultDataSource = false;
                } else {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(nonJtaDataSource), new CastingInjector<DataSource>(service.getNonJtaDataSourceInjector(), DataSource.class));
                    useDefaultDataSource = false;
                }
            }
            // JPA 2.0 8.2.1.5, container provides default JTA datasource
            if (useDefaultDataSource) {
                final String defaultJtaDataSource = adjustJndi(JPAService.getDefaultDataSourceName());
                if (defaultJtaDataSource != null &&
                    defaultJtaDataSource.length() > 0) {
                    builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(defaultJtaDataSource), new CastingInjector<DataSource>(service.getJtaDataSourceInjector(), DataSource.class));
                    JPA_LOGGER.tracef("%s is using the default data source '%s'", puServiceName, defaultJtaDataSource);
                }
            }

            adaptor.addProviderDependencies(phaseContext.getServiceRegistry(), serviceTarget, builder, pu);

            if (pu.getProperties().containsKey(JNDI_PROPERTY)) {
                String jndiName = pu.getProperties().get(JNDI_PROPERTY).toString();
                final ContextNames.BindInfo bindingInfo;
                if (jndiName.startsWith("java:")) {
View Full Code Here


        final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder,
        final DeploymentUnit deploymentUnit
    ) throws
        DeploymentUnitProcessingException {
        String adaptorModule = pu.getProperties().getProperty(Configuration.ADAPTER_MODULE);
        PersistenceProviderAdaptor adaptor = null;
        if (persistenceProviderDeploymentHolder != null) {
            adaptor = persistenceProviderDeploymentHolder.getAdapter();
        }
        if (adaptor == null) {
View Full Code Here

        if (deploymentUnit.getParent() != null) {
            deploymentUnit = deploymentUnit.getParent();
        }
        synchronized (deploymentUnit) {
            Map<String,PersistenceProviderAdaptor> map = deploymentUnit.getAttachment(providerAdaptorMapKey);
            PersistenceProviderAdaptor current = map.get(adaptorModule);
            // saved if not already set by another thread
            if (current == null) {
                map.put(adaptorModule, adaptor);
                current = adaptor;
            }
View Full Code Here

        if (adapterModule == null) {
            return noopAdaptor;
        }

        PersistenceProviderAdaptor persistenceProviderAdaptor=null;

        Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(adapterModule));
        final ServiceLoader<PersistenceProviderAdaptor> serviceLoader =
            module.loadService(PersistenceProviderAdaptor.class);
        if (serviceLoader != null) {
            for (PersistenceProviderAdaptor adaptor : serviceLoader) {
                if (persistenceProviderAdaptor != null) {
                    throw MESSAGES.multipleAdapters(adapterModule);
                }
                persistenceProviderAdaptor = adaptor;
                JPA_LOGGER.debugf("loaded persistence provider adapter %s", adapterModule);
            }
            if (persistenceProviderAdaptor != null) {
                persistenceProviderAdaptor.injectJtaManager(JtaManagerImpl.getInstance());
            }
        }

        return persistenceProviderAdaptor;
    }
View Full Code Here

            JPA_LOGGER.errorPreloadingDefaultProvider(e);
        }

        try {
            // load the default persistence provider adaptor
            PersistenceProviderAdaptor provider = PersistenceProviderAdaptorLoader.loadPersistenceAdapterModule(Configuration.ADAPTER_MODULE_DEFAULT);
            final ManagementAdaptor managementAdaptor = provider.getManagementAdaptor();
            if (managementAdaptor != null && context.isRuntimeOnlyRegistrationValid()) {
                DescriptionProvider JPA_SUBSYSTEM = new DescriptionProvider() {
                    @Override
                    public ModelNode getModelDescription(Locale locale) {
                        ModelNode subsystem = new ModelNode();
View Full Code Here

            }


            if (providerList.size() > 0) {
                final String adapterClass = deploymentUnit.getAttachment(JpaAttachments.ADAPTOR_CLASS_NAME);
                PersistenceProviderAdaptor adaptor;
                if (adapterClass != null) {
                    try {
                        adaptor = (PersistenceProviderAdaptor) deploymentModuleClassLoader.loadClass(adapterClass).newInstance();
                        adaptor.injectJtaManager(JtaManagerImpl.getInstance());
                        deploymentUnit.putAttachment(JpaAttachments.DEPLOYED_PERSISTENCE_PROVIDER, new PersistenceProviderDeploymentHolder(providerList, adaptor));
                    } catch (InstantiationException e) {
                        throw MESSAGES.cannotCreateAdapter(e, adapterClass);
                    } catch (IllegalAccessException e) {
                        throw MESSAGES.cannotCreateAdapter(e, adapterClass);
View Full Code Here

                }
            }

            if (provider != null) {
                final String adapterClass = deploymentUnit.getAttachment(JpaAttachments.ADAPTOR_CLASS_NAME);
                PersistenceProviderAdaptor adaptor = null;
                if (adapterClass != null) {
                    try {
                        adaptor = (PersistenceProviderAdaptor) deploymentModuleClassLoader.loadClass(adapterClass).newInstance();
                        adaptor.injectJtaManager(JtaManagerImpl.getInstance());
                    } catch (InstantiationException e) {
                        throw new DeploymentUnitProcessingException("could not create instance of adapter class '" +
                                adapterClass + "'", e);
                    } catch (IllegalAccessException e) {
                        throw new DeploymentUnitProcessingException("could not create instance of adapter class '" +
View Full Code Here

                        final HashMap properties = new HashMap();
                        if (!ValidationMode.NONE.equals(pu.getValidationMode())) {
                            ValidatorFactory validatorFactory = SerializableValidatorFactory.getINSTANCE();
                            properties.put("javax.persistence.validation.factory", validatorFactory);
                        }
                        final PersistenceProviderAdaptor adaptor = getPersistenceProviderAdaptor(pu, persistenceProviderDeploymentHolder);


                        final PersistenceProvider provider;
                        if (persistenceProviderDeploymentHolder != null &&
                                persistenceProviderDeploymentHolder.getProvider() != null &&
                                persistenceProviderDeploymentHolder.getProvider().getClass().getName().equals(pu.getPersistenceProviderClassName())) {
                            provider = persistenceProviderDeploymentHolder.getProvider();
                        } else {
                            provider = lookupProvider(pu);
                        }

                        final PersistenceUnitService service = new PersistenceUnitService(pu, adaptor, provider);

                        // add persistence provider specific properties
                        adaptor.addProviderProperties(properties, pu);


                        final ServiceName puServiceName = PersistenceUnitService.getPUServiceName(pu);
                        // add the PU service as a dependency to all EE components in this scope
                        this.addPUServiceDependencyToComponents(components, puServiceName);

                        deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, puServiceName);

                        ServiceBuilder builder = serviceTarget.addService(puServiceName, service);
                        boolean useDefaultDataSource = true;
                        final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName());
                        final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());

                        if (jtaDataSource != null && jtaDataSource.length() > 0) {
                            if (jtaDataSource.startsWith("java:")) {
                                builder.addDependency(ContextNames.bindInfoFor(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), jtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getJtaDataSourceInjector()));
                                useDefaultDataSource = false;
                            } else {
                                builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(jtaDataSource), new CastingInjector<DataSource>(service.getJtaDataSourceInjector(), DataSource.class));
                                useDefaultDataSource = false;
                            }
                        }
                        if (nonJtaDataSource != null && nonJtaDataSource.length() > 0) {
                            if (nonJtaDataSource.startsWith("java:")) {
                                builder.addDependency(ContextNames.bindInfoFor(eeModuleDescription.getApplicationName(), eeModuleDescription.getModuleName(), eeModuleDescription.getModuleName(), nonJtaDataSource).getBinderServiceName(), ManagedReferenceFactory.class, new ManagedReferenceFactoryInjector(service.getNonJtaDataSourceInjector()));
                                useDefaultDataSource = false;
                            } else {
                                builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(nonJtaDataSource), new CastingInjector<DataSource>(service.getNonJtaDataSourceInjector(), DataSource.class));
                                useDefaultDataSource = false;
                            }
                        }
                        // JPA 2.0 8.2.1.5, container provides default JTA datasource
                        if (useDefaultDataSource) {
                            final String defaultJtaDataSource = adjustJndi(JPAService.getDefaultDataSourceName());
                            if (defaultJtaDataSource != null &&
                                    defaultJtaDataSource.length() > 0) {
                                builder.addDependency(AbstractDataSourceService.SERVICE_NAME_BASE.append(defaultJtaDataSource), new CastingInjector<DataSource>(service.getJtaDataSourceInjector(), DataSource.class));
                                log.trace(puServiceName + " is using the default data source '" + defaultJtaDataSource + "'");
                            }
                        }

                        Iterable<ServiceName> providerDependencies = adaptor.getProviderDependencies(pu);
                        if (providerDependencies != null) {
                            builder.addDependencies(providerDependencies);
                        }

                        if (pu.getProperties().containsKey(JNDI_PROPERTY)) {
View Full Code Here

     *
     */
    private PersistenceProviderAdaptor getPersistenceProviderAdaptor(final PersistenceUnitMetadata pu, final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder) throws
            DeploymentUnitProcessingException {
        String adaptorModule = pu.getProperties().getProperty(Configuration.ADAPTER_MODULE);
        PersistenceProviderAdaptor adaptor = null;
        if (persistenceProviderDeploymentHolder != null) {
            adaptor = persistenceProviderDeploymentHolder.getAdapter();
        }
        if (adaptor == null) {
            adaptor = loadPersistenceAdapterModule(pu.getPersistenceProviderClassName(), adaptorModule);
View Full Code Here

     *
     */
    private PersistenceProviderAdaptor loadPersistenceAdapterModule(String persistenceProviderClass, String adapterModule) throws
            DeploymentUnitProcessingException {
        final ModuleLoader moduleLoader = Module.getBootModuleLoader();
        PersistenceProviderAdaptor persistenceProviderAdaptor = null;

        if (adapterModule == null) {
            adapterModule = Configuration.ADAPTER_MODULE_DEFAULT;
        }

        if (persistenceProviderClass == null) {
            persistenceProviderClass = Configuration.PROVIDER_CLASS_DEFAULT;
        }

        try {

            Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(adapterModule));
            final ServiceLoader<PersistenceProviderAdaptor> serviceLoader =
                    module.loadService(PersistenceProviderAdaptor.class);
            if (serviceLoader != null) {
                for (PersistenceProviderAdaptor adaptor : serviceLoader) {
                    if (persistenceProviderAdaptor != null) {
                        throw new DeploymentUnitProcessingException(
                                "persistence provider adapter module has more than one adapters "
                                        + adapterModule);
                    }
                    persistenceProviderAdaptor = adaptor;
                    log.debugf("loaded persistence provider adapter %s", adapterModule);
                }
                if (persistenceProviderAdaptor != null) {
                    persistenceProviderAdaptor.injectJtaManager(JtaManagerImpl.getInstance());
                }
            }
        } catch (ModuleLoadException e) {
            throw new DeploymentUnitProcessingException("persistence provider adapter module load error"
                    + adapterModule + "(class " + persistenceProviderClass + ")", e);
View Full Code Here

TOP

Related Classes of org.jboss.as.jpa.spi.PersistenceProviderAdaptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.