use of jakarta.persistence.spi.PersistenceUnitInfo in project spring-framework by spring-projects.
the class PersistenceXmlParsingTests method testExample6.
@Test
public void testExample6() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-example6.xml";
PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
assertThat(info.length).isEqualTo(1);
assertThat(info[0].getPersistenceUnitName()).isEqualTo("pu");
assertThat(info[0].getProperties().keySet().size()).isEqualTo(0);
assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
}
use of jakarta.persistence.spi.PersistenceUnitInfo in project spring-framework by spring-projects.
the class PersistenceXmlParsingTests method testExample4.
@Test
public void testExample4() throws Exception {
SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
DataSource ds = new DriverManagerDataSource();
builder.bind("java:comp/env/jdbc/MyDB", ds);
PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
String resource = "/org/springframework/orm/jpa/persistence-example4.xml";
PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
assertThat(info).isNotNull();
assertThat(info.length).isEqualTo(1);
assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement4");
assertThat(info[0].getMappingFileNames().size()).isEqualTo(1);
assertThat(info[0].getMappingFileNames().get(0)).isEqualTo("order-mappings.xml");
assertThat(info[0].getManagedClassNames().size()).isEqualTo(3);
assertThat(info[0].getManagedClassNames().get(0)).isEqualTo("com.acme.Order");
assertThat(info[0].getManagedClassNames().get(1)).isEqualTo("com.acme.Customer");
assertThat(info[0].getManagedClassNames().get(2)).isEqualTo("com.acme.Item");
assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should be true when no value.").isTrue();
assertThat(info[0].getTransactionType()).isSameAs(PersistenceUnitTransactionType.RESOURCE_LOCAL);
assertThat(info[0].getProperties().keySet().size()).isEqualTo(0);
builder.clear();
}
use of jakarta.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 && this.defaultPersistenceUnitName != null) {
return obtainPersistenceUnitInfo(this.defaultPersistenceUnitName);
}
PersistenceUnitInfo pui = this.persistenceUnitInfos.values().iterator().next();
this.persistenceUnitInfos.clear();
return pui;
}
use of jakarta.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);
assertThat(info).isNotNull();
assertThat(info.length).as("The number of persistence units is incorrect.").isEqualTo(4);
PersistenceUnitInfo noExclude = info[0];
assertThat(noExclude).as("noExclude should not be null.").isNotNull();
assertThat(noExclude.getPersistenceUnitName()).as("noExclude name is not correct.").isEqualTo("NoExcludeElement");
assertThat(noExclude.excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
PersistenceUnitInfo emptyExclude = info[1];
assertThat(emptyExclude).as("emptyExclude should not be null.").isNotNull();
assertThat(emptyExclude.getPersistenceUnitName()).as("emptyExclude name is not correct.").isEqualTo("EmptyExcludeElement");
assertThat(emptyExclude.excludeUnlistedClasses()).as("emptyExclude should be true.").isTrue();
PersistenceUnitInfo trueExclude = info[2];
assertThat(trueExclude).as("trueExclude should not be null.").isNotNull();
assertThat(trueExclude.getPersistenceUnitName()).as("trueExclude name is not correct.").isEqualTo("TrueExcludeElement");
assertThat(trueExclude.excludeUnlistedClasses()).as("trueExclude should be true.").isTrue();
PersistenceUnitInfo falseExclude = info[3];
assertThat(falseExclude).as("falseExclude should not be null.").isNotNull();
assertThat(falseExclude.getPersistenceUnitName()).as("falseExclude name is not correct.").isEqualTo("FalseExcludeElement");
assertThat(falseExclude.excludeUnlistedClasses()).as("falseExclude should be false.").isFalse();
}
use of jakarta.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);
assertThat(info).isNotNull();
assertThat(info.length).isEqualTo(1);
assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement2");
assertThat(info[0].getMappingFileNames().size()).isEqualTo(1);
assertThat(info[0].getMappingFileNames().get(0)).isEqualTo("mappings.xml");
assertThat(info[0].getProperties().keySet().size()).isEqualTo(0);
assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
}
Aggregations