Package javax.persistence.spi

Examples of javax.persistence.spi.PersistenceUnitInfo


                }
                postProcessPersistenceUnitInfo((MutablePersistenceUnitInfo) pui);
                String name = mPui.getPersistenceUnitName();
                persistenceUnitInfoNames.add(name);

                PersistenceUnitInfo puiToStore = mPui;
                if (jpa2ApiPresent) {
                    puiToStore = this.createPersistenceUnit(mPui);
                }
                persistenceUnitInfos.put(name, puiToStore);
            }
View Full Code Here


    protected void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo newPU) {
        super.postProcessPersistenceUnitInfo(newPU);
        ConfigurationOnlyState state = ConfigurationOnlyState.getState();
        String persistenceUnitName = newPU.getPersistenceUnitName();
        MutablePersistenceUnitInfo temp;
        PersistenceUnitInfo pui = getMergedUnit(persistenceUnitName, newPU);
        if (pui != null && Proxy.isProxyClass(pui.getClass())) {
            // JPA 2.0 PersistenceUnitInfo decorator with a SpringPersistenceUnitInfo as target
            InvocationHandler dec = Proxy.getInvocationHandler(pui);
            temp = (MutablePersistenceUnitInfo) this.getDeclaredFieldValue(dec, "target");
        }
        else {
View Full Code Here

                }
                break;
            }
        }

        PersistenceUnitInfo puiToStore = (PersistenceUnitInfo) Proxy.newProxyInstance(SmartPersistenceUnitInfo.class.getClassLoader(),
                new Class[] { SmartPersistenceUnitInfo.class }, jpa2PersistenceUnitInfoDecorator);
        return puiToStore;
    }
View Full Code Here

            embeddable.getEntityMappings().processEntityMappingsDefaults(embeddable);
        }
       
        // 4 - Iterate through the classes that are referenced from the
        // persistence.xml file.
        PersistenceUnitInfo persistenceUnitInfo = m_project.getPersistenceUnitInfo();
        List<String> classNames = new ArrayList<String>();
       
        // Add all the <class> specifications.
        classNames.addAll(persistenceUnitInfo.getManagedClassNames());

        // Add all the classes from the <jar> specifications.
        for (URL url : persistenceUnitInfo.getJarFileUrls()) {
            classNames.addAll(PersistenceUnitProcessor.getClassNamesFromURL(url, m_loader, null));
        }

        // Add all the classes off the classpath at the persistence unit root url.
        Set<String> unlistedClasses = Collections.EMPTY_SET;
        if (! persistenceUnitInfo.excludeUnlistedClasses()) {
            unlistedClasses = PersistenceUnitProcessor.getClassNamesFromURL(persistenceUnitInfo.getPersistenceUnitRootUrl(), m_loader, m_predeployProperties);
        }
       
        // 5 - Go through all the class names we found and add those classes
        // that have not yet been added. Be sure to check that the accessor
        // does not already exist since adding an accessor will merge its
View Full Code Here

    /**
     * INTERNAL:
     */
    protected void loadSpecifiedMappingFiles(boolean throwExceptionOnFail) {
        PersistenceUnitInfo puInfo = m_project.getPersistenceUnitInfo();
       
        for (String mappingFileName : puInfo.getMappingFileNames()) {
            try {
                Enumeration<URL> mappingFileURLs = m_loader.getResources(mappingFileName);
               
                if (!mappingFileURLs.hasMoreElements()){
                    mappingFileURLs = m_loader.getResources("/./" + mappingFileName);
                }
               
                if (mappingFileURLs.hasMoreElements()) {
                    URL nextURL = mappingFileURLs.nextElement();

                    if (mappingFileURLs.hasMoreElements()) {
                        // Switched to warning, same file can be on the classpath twice in some deployments,
                        // should not be an error.
                        logThrowable(ValidationException.nonUniqueMappingFileName(puInfo.getPersistenceUnitName(), mappingFileName));
                    }
                   
                    // Read the document through OX and add it to the project.
                    m_project.addEntityMappings(XMLEntityMappingsReader.read(nextURL, m_loader, m_project.getPersistenceUnitInfo().getProperties()));
                } else {
                    handleORMException(ValidationException.mappingFileNotFound(puInfo.getPersistenceUnitName(), mappingFileName), mappingFileName, throwExceptionOnFail);
                }
            } catch (IOException e) {
                handleORMException(PersistenceUnitLoadingException.exceptionLoadingORMXML(mappingFileName, e), mappingFileName, throwExceptionOnFail);
            }
        }
View Full Code Here

   
    /**
     * INTERNAL:
     */
    protected void loadStandardMappingFiles(String ormXMLFile) {
        PersistenceUnitInfo puInfo = m_project.getPersistenceUnitInfo();
        Collection<URL> rootUrls = new HashSet<URL>(puInfo.getJarFileUrls());
        rootUrls.add(puInfo.getPersistenceUnitRootUrl());
       
        for (URL rootURL : rootUrls) {
            logMessage("Searching for default mapping file in " + rootURL);
            URL ormURL = null;

View Full Code Here

        .setPassword( password )
        .setTimeout( 0 ) //infinite transaction
        .createDataSource();

    PersistenceUnitInfoBuilder pub = new PersistenceUnitInfoBuilder();
    final PersistenceUnitInfo unitInfo = pub
        .setExcludeUnlistedClasses( true )
        .setJtaDataSource( ds )
        .setPersistenceProviderClassName( HibernatePersistence.class.getName() )
        .setPersistenceUnitName( "jbossjta" )
        .setPersistenceXMLSchemaVersion( "2.0" )
View Full Code Here

        newPU.addJarFileUrl(newPU.getPersistenceUnitRootUrl());
        newPU.setPersistenceUnitRootUrl(null);

        final String persistenceUnitName = newPU.getPersistenceUnitName();
       
        final PersistenceUnitInfo oldPU = getPersistenceUnitInfo(persistenceUnitName);
        if (oldPU != null) {
            // merge jar file url's
            for (URL url : oldPU.getJarFileUrls()) {
                newPU.addJarFileUrl(url);
            }
            // merge mapping class names
            for (String managedClassName : oldPU.getManagedClassNames()) {
                newPU.addManagedClassName(managedClassName);
            }
            // merge mapping file names
            for (String mappingFileName : oldPU.getMappingFileNames()) {
                newPU.addMappingFileName(mappingFileName);
            }

            // merge properties
            newPU.getProperties().putAll(oldPU.getProperties());
           
            if (oldPU.getPersistenceProviderClassName() != null) {
                if (newPU.getPersistenceProviderClassName() == null) {
                    newPU.setPersistenceProviderClassName(oldPU.getPersistenceProviderClassName());
                } else if (!newPU.getPersistenceProviderClassName().equals(oldPU.getPersistenceProviderClassName())) {
                    throw new IllegalStateException("Different PersistenceProviderClassName specified for persistence unit name [" + newPU.getPersistenceUnitName() + "]");
                }
            }

            // merge attributes
            if (oldPU.getJtaDataSource() != null) {
                if (newPU.getJtaDataSource() == null) {
                    newPU.setJtaDataSource(oldPU.getJtaDataSource());
                } else if (!newPU.getJtaDataSource().equals(oldPU.getJtaDataSource())) {
                    throw new IllegalStateException("Different JTA datasources specified for persistence unit name [" + newPU.getPersistenceUnitName() + "]");
                }
            }
           
            if (oldPU.getNonJtaDataSource() != null) {
                if (newPU.getNonJtaDataSource() == null) {
                    newPU.setNonJtaDataSource(oldPU.getNonJtaDataSource());
                } else if (!newPU.getNonJtaDataSource().equals(oldPU.getNonJtaDataSource())) {
                    throw new IllegalStateException("Different non-JTA datasources specified for persistence unit name [" + newPU.getPersistenceUnitName() + "]");
                }
            }
           
            checkAttributeByReflection(oldPU, newPU, "transactionType", PersistenceUnitTransactionType.RESOURCE_LOCAL, "transaction type");
View Full Code Here

            Class.forName(jpaProperties.getProperty("javax.persistence.jdbc.driver"));
        } catch (ClassNotFoundException ex) {
            log.error("Cannot load JDBC Driver for persistence unit", ex);
        }
       
        PersistenceUnitInfo persistenceUnitInfo = null;
        try {
            persistenceUnitInfo = getPersistenceUnitInfo(persistenceUnitName, jpaProperties);
        }
        catch(IOException e) {
            throw new PersistenceException("Cannot load PersistenceUnit named "+persistenceUnitName, e);           
        }
        if( persistenceUnitInfo == null ) {
            throw new PersistenceException("Cannot find PersistenceUnit named "+persistenceUnitName);
        }

        EntityManagerFactory emf = null;
        PersistenceProviderResolver resolver = PersistenceProviderResolverHolder.getPersistenceProviderResolver();

        List<PersistenceProvider> providers = resolver.getPersistenceProviders();
       
        // check if we have the requested provider
        if( persistenceUnitInfo.getPersistenceProviderClassName() != null ) {
            log.info("Looking for specific JPA provider: {}", persistenceUnitInfo.getPersistenceProviderClassName());
            for(PersistenceProvider provider : providers) {
                log.info("Looking at provider: {}", provider.getClass().getName());
                if( provider.getClass().getName().equals(persistenceUnitInfo.getPersistenceProviderClassName()) ) {
                    emf = provider.createContainerEntityManagerFactory(persistenceUnitInfo, persistenceUnitInfo.getProperties()); // important: must use the properties as returned by the persistenceUnitInfo because it may have altered them... specifically:  remove user and password entries after creating datasource to force eclipselink to call getConnection() instead of getConnection(user,password)
                    if( emf != null ) {
                        log.info("Found requested persistence provider");
                        return emf;
                    }
                }
            }
        }
        // check if any other provider can accomodate the persistence unit
        log.info("Looking for any compatible JPA provider");
        for (PersistenceProvider provider : providers) {
            log.info("Looking at provider: {}", provider.getClass().getName());
            emf = provider.createContainerEntityManagerFactory(persistenceUnitInfo, persistenceUnitInfo.getProperties()); // important: must use the properties as returned by the persistenceUnitInfo because it may have altered them... specifically:  remove user and password entries after creating datasource to force eclipselink to call getConnection() instead of getConnection(user,password)
            if (emf != null) {
                log.info("Found compatible persistence provider");
                return emf;
            }
        }
View Full Code Here

  @Autowired
  private LocalContainerEntityManagerFactoryBean entityManagerFactory;

  @Test
  public void exportDatabaseSchema() throws IOException {
    PersistenceUnitInfo persistenceUnitInfo = entityManagerFactory.getPersistenceUnitInfo();
    for (Database each : Database.values()) {
      Map<?, ?> jpaPropertyMap = entityManagerFactory.getJpaPropertyMap();
      Configuration configuration = new Ejb3Configuration().configure(persistenceUnitInfo, jpaPropertyMap)
              .getHibernateConfiguration();
      configuration.setProperty(Environment.DIALECT, each.getDialect());
View Full Code Here

TOP

Related Classes of javax.persistence.spi.PersistenceUnitInfo

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.