use of javax.persistence.spi.PersistenceUnitInfo in project spring-framework by spring-projects.
the class PersistenceXmlParsingTests method testExample2.
@Test
public void testExample2() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-example2.xml";
PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
assertNotNull(info);
assertEquals(1, info.length);
assertEquals("OrderManagement2", info[0].getPersistenceUnitName());
assertEquals(1, info[0].getMappingFileNames().size());
assertEquals("mappings.xml", info[0].getMappingFileNames().get(0));
assertEquals(0, info[0].getProperties().keySet().size());
assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses());
}
use of javax.persistence.spi.PersistenceUnitInfo in project spring-framework by spring-projects.
the class PersistenceXmlParsingTests method testMetaInfCase.
@Test
public void testMetaInfCase() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/META-INF/persistence.xml";
PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
assertNotNull(info);
assertEquals(1, info.length);
assertEquals("OrderManagement", info[0].getPersistenceUnitName());
assertEquals(2, info[0].getJarFileUrls().size());
assertEquals(new ClassPathResource("order.jar").getURL(), info[0].getJarFileUrls().get(0));
assertEquals(new ClassPathResource("order-supplemental.jar").getURL(), info[0].getJarFileUrls().get(1));
assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses());
}
use of javax.persistence.spi.PersistenceUnitInfo in project spring-framework by spring-projects.
the class PersistenceXmlParsingTests method testJpa1ExcludeUnlisted.
@Test
public void testJpa1ExcludeUnlisted() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-exclude-1.0.xml";
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());
}
use of javax.persistence.spi.PersistenceUnitInfo in project spring-framework by spring-projects.
the class DefaultPersistenceUnitManager method obtainDefaultPersistenceUnitInfo.
@Override
public PersistenceUnitInfo obtainDefaultPersistenceUnitInfo() {
if (this.persistenceUnitInfoNames.isEmpty()) {
throw new IllegalStateException("No persistence units parsed from " + ObjectUtils.nullSafeToString(this.persistenceXmlLocations));
}
if (this.persistenceUnitInfos.isEmpty()) {
throw new IllegalStateException("All persistence units from " + 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;
}
Aggregations