Package javax.persistence.spi

Examples of javax.persistence.spi.PersistenceUnitInfo


                    "Persistence units defined by the bundle will not be available until the bundle is refreshed");
            throw new InvalidPersistenceUnitException();
          }
     
          for(ManagedPersistenceUnitInfo info : persistenceUnits){
            PersistenceUnitInfo pUnitInfo = info.getPersistenceUnitInfo();
       
            emfs.put(pUnitInfo.getPersistenceUnitName(), new CountingEntityManagerFactory(
                providerService.createContainerEntityManagerFactory(
                    pUnitInfo, info.getContainerProperties()), pUnitInfo.getPersistenceUnitName()));
          }
        } finally {
          //Remember to unget the provider
          containerContext.ungetService(provider);
        }
View Full Code Here


            embeddable.getEntityMappings().processEntityMappingsDefaults(embeddable);
        }
       
        // 4 - Iterate through the classes that are references 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));
        }

        // Add all the classes off the classpath at the persistence unit root url.
        if (! persistenceUnitInfo.excludeUnlistedClasses()) {
            classNames.addAll(PersistenceUnitProcessor.getClassNamesFromURL(persistenceUnitInfo.getPersistenceUnitRootUrl()));
        }
       
        // 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()) {
                    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

   * detecting existing persistence units of the same name and potentially merging them.
   * @param persistenceUnitName the name of the desired persistence unit
   * @return the PersistenceUnitInfo in mutable form, or {@code null} if not available
   */
  protected final MutablePersistenceUnitInfo getPersistenceUnitInfo(String persistenceUnitName) {
    PersistenceUnitInfo pui = this.persistenceUnitInfos.get(persistenceUnitName);
    return (MutablePersistenceUnitInfo) pui;
  }
View Full Code Here

          ObjectUtils.nullSafeToString(this.persistenceXmlLocations) + " already obtained");
    }
    if (this.persistenceUnitInfos.size() > 1) {
      return obtainPersistenceUnitInfo(this.defaultPersistenceUnitName);
    }
    PersistenceUnitInfo pui = this.persistenceUnitInfos.values().iterator().next();
    this.persistenceUnitInfos.clear();
    return pui;
  }
View Full Code Here

    return pui;
  }

  @Override
  public PersistenceUnitInfo obtainPersistenceUnitInfo(String persistenceUnitName) {
    PersistenceUnitInfo pui = this.persistenceUnitInfos.remove(persistenceUnitName);
    if (pui == null) {
      if (!this.persistenceUnitInfoNames.contains(persistenceUnitName)) {
        throw new IllegalArgumentException(
            "No persistence unit with name '" + persistenceUnitName + "' found");
      }
View Full Code Here

        new PathMatchingResourcePatternResolver(), dataSourceLookup);
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);

    assertEquals(2, info.length);

    PersistenceUnitInfo pu1 = info[0];

    assertEquals("pu1", pu1.getPersistenceUnitName());

    assertEquals("com.acme.AcmePersistence", pu1.getPersistenceProviderClassName());

    assertEquals(1, pu1.getMappingFileNames().size());
    assertEquals("ormap2.xml", pu1.getMappingFileNames().get(0));

    assertEquals(1, pu1.getJarFileUrls().size());
    assertEquals(new ClassPathResource("order.jar").getURL(), pu1.getJarFileUrls().get(0));

    assertFalse(pu1.excludeUnlistedClasses());

    assertSame(PersistenceUnitTransactionType.RESOURCE_LOCAL, pu1.getTransactionType());

    Properties props = pu1.getProperties();
    assertEquals(2, props.keySet().size());
    assertEquals("on", props.getProperty("com.acme.persistence.sql-logging"));
    assertEquals("bar", props.getProperty("foo"));

    assertNull(pu1.getNonJtaDataSource());

    assertSame(ds, pu1.getJtaDataSource());

    assertFalse("Exclude unlisted should default false in 1.0.", pu1.excludeUnlistedClasses());

    PersistenceUnitInfo pu2 = info[1];

    assertSame(PersistenceUnitTransactionType.JTA, pu2.getTransactionType());
    assertEquals("com.acme.AcmePersistence", pu2.getPersistenceProviderClassName());

    assertEquals(1, pu2.getMappingFileNames().size());
    assertEquals("order2.xml", pu2.getMappingFileNames().get(0));

    // the following assertions fail only during coverage runs
    // assertEquals(1, pu2.getJarFileUrls().size());
    // assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), pu2.getJarFileUrls().get(0));

    assertTrue(pu2.excludeUnlistedClasses());

    assertNull(pu2.getJtaDataSource());
    assertEquals(ds, pu2.getNonJtaDataSource());

    assertTrue("Exclude unlisted should be true when no value.", pu2.excludeUnlistedClasses());
  }
View Full Code Here

    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);

    assertNotNull(info);
    assertEquals("The number of persistence units is incorrect.", 4, info.length);

    PersistenceUnitInfo noExclude = info[0];
    assertNotNull("noExclude should not be null.", noExclude);
    assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName());
    assertFalse("Exclude unlisted should default false in 1.0.", noExclude.excludeUnlistedClasses());

    PersistenceUnitInfo emptyExclude = info[1];
    assertNotNull("emptyExclude should not be null.", emptyExclude);
    assertEquals("emptyExclude name is not correct.", "EmptyExcludeElement", emptyExclude.getPersistenceUnitName());
    assertTrue("emptyExclude should be true.", emptyExclude.excludeUnlistedClasses());

    PersistenceUnitInfo trueExclude = info[2];
    assertNotNull("trueExclude should not be null.", trueExclude);
    assertEquals("trueExclude name is not correct.", "TrueExcludeElement", trueExclude.getPersistenceUnitName());
    assertTrue("trueExclude should be true.", trueExclude.excludeUnlistedClasses());

    PersistenceUnitInfo falseExclude = info[3];
    assertNotNull("falseExclude should not be null.", falseExclude);
    assertEquals("falseExclude name is not correct.", "FalseExcludeElement", falseExclude.getPersistenceUnitName());
    assertFalse("falseExclude should be false.", falseExclude.excludeUnlistedClasses());
  }
View Full Code Here

    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);

    assertNotNull(info);
    assertEquals("The number of persistence units is incorrect.", 4, info.length);

    PersistenceUnitInfo noExclude = info[0];
    assertNotNull("noExclude should not be null.", noExclude);
    assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName());
    assertFalse("Exclude unlisted still defaults to false in 2.0.", noExclude.excludeUnlistedClasses());

    PersistenceUnitInfo emptyExclude = info[1];
    assertNotNull("emptyExclude should not be null.", emptyExclude);
    assertEquals("emptyExclude name is not correct.", "EmptyExcludeElement", emptyExclude.getPersistenceUnitName());
    assertTrue("emptyExclude should be true.", emptyExclude.excludeUnlistedClasses());

    PersistenceUnitInfo trueExclude = info[2];
    assertNotNull("trueExclude should not be null.", trueExclude);
    assertEquals("trueExclude name is not correct.", "TrueExcludeElement", trueExclude.getPersistenceUnitName());
    assertTrue("trueExclude should be true.", trueExclude.excludeUnlistedClasses());

    PersistenceUnitInfo falseExclude = info[3];
    assertNotNull("falseExclude should not be null.", falseExclude);
    assertEquals("falseExclude name is not correct.", "FalseExcludeElement", falseExclude.getPersistenceUnitName());
    assertFalse("falseExclude should be false.", falseExclude.excludeUnlistedClasses());
  }
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.