use of org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata in project hibernate-orm by hibernate.
the class XMLContext method addDocument.
/**
* @param entityMappings The xml document to add
* @return Add an xml document to this context and return the list of added class names.
*/
@SuppressWarnings("unchecked")
public List<String> addDocument(JaxbEntityMappings entityMappings) {
hasContext = true;
List<String> addedClasses = new ArrayList<>();
// global defaults
JaxbPersistenceUnitMetadata metadata = entityMappings.getPersistenceUnitMetadata();
if (metadata != null) {
if (globalDefaults == null) {
globalDefaults = new Default();
globalDefaults.setMetadataComplete(metadata.getXmlMappingMetadataComplete() != null ? Boolean.TRUE : null);
JaxbPersistenceUnitDefaults defaultElement = metadata.getPersistenceUnitDefaults();
if (defaultElement != null) {
globalDefaults.setSchema(defaultElement.getSchema());
globalDefaults.setCatalog(defaultElement.getCatalog());
globalDefaults.setAccess(defaultElement.getAccess());
globalDefaults.setCascadePersist(defaultElement.getCascadePersist() != null ? Boolean.TRUE : null);
globalDefaults.setDelimitedIdentifiers(defaultElement.getDelimitedIdentifiers() != null ? Boolean.TRUE : null);
defaultEntityListeners.addAll(addEntityListenerClasses(defaultElement.getEntityListeners(), null, addedClasses));
}
} else {
LOG.duplicateMetadata();
}
}
// entity mapping default
Default entityMappingDefault = new Default();
String packageName = entityMappings.getPackage();
entityMappingDefault.setPackageName(packageName);
entityMappingDefault.setSchema(entityMappings.getSchema());
entityMappingDefault.setCatalog(entityMappings.getCatalog());
entityMappingDefault.setAccess(entityMappings.getAccess());
defaultElements.add(entityMappings);
setLocalAttributeConverterDefinitions(entityMappings.getConverter(), packageName);
addClass(entityMappings.getEntity(), packageName, entityMappingDefault, addedClasses);
addClass(entityMappings.getMappedSuperclass(), packageName, entityMappingDefault, addedClasses);
addClass(entityMappings.getEmbeddable(), packageName, entityMappingDefault, addedClasses);
return addedClasses;
}
use of org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata in project hibernate-orm by hibernate.
the class JakartaXmlSmokeTests method testLoadingOrmXml.
@Test
public void testLoadingOrmXml(ServiceRegistryScope scope) {
final ClassLoaderService cls = scope.getRegistry().getService(ClassLoaderService.class);
final MappingBinder mappingBinder = new MappingBinder(cls, true);
final InputStream inputStream = cls.locateResourceStream("xml/jakarta/simple/orm.xml");
try {
final Binding<JaxbEntityMappings> binding = mappingBinder.bind(new StreamSource(inputStream), new Origin(SourceType.RESOURCE, "xml/jakarta/simple/orm.xml"));
assertThat(binding.getRoot().getEntity().stream().map(JaxbEntity::getClazz)).containsOnly("Lighter", "ApplicationServer");
final JaxbPersistenceUnitMetadata puMetadata = binding.getRoot().getPersistenceUnitMetadata();
final JaxbPersistenceUnitDefaults puDefaults = puMetadata.getPersistenceUnitDefaults();
final Stream<String> listenerNames = puDefaults.getEntityListeners().getEntityListener().stream().map(JaxbEntityListener::getClazz);
assertThat(listenerNames).containsOnly("org.hibernate.jpa.test.pack.defaultpar.IncrementListener");
} finally {
try {
inputStream.close();
} catch (IOException ignore) {
}
}
}
use of org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata in project quarkus by quarkusio.
the class JpaJandexScavenger method enlistOrmXmlMapping.
private void enlistOrmXmlMapping(Collector collector, JaxbEntityMappings mapping) {
String packageName = mapping.getPackage();
String packagePrefix = packageName == null ? "" : packageName + ".";
JaxbPersistenceUnitMetadata metadata = mapping.getPersistenceUnitMetadata();
JaxbPersistenceUnitDefaults defaults = metadata == null ? null : metadata.getPersistenceUnitDefaults();
if (defaults != null) {
enlistOrmXmlMappingListeners(collector, packagePrefix, defaults.getEntityListeners());
}
for (JaxbEntity entity : mapping.getEntity()) {
enlistOrmXmlMappingManagedClass(collector, packagePrefix, entity, "entity");
}
for (JaxbMappedSuperclass mappedSuperclass : mapping.getMappedSuperclass()) {
enlistOrmXmlMappingManagedClass(collector, packagePrefix, mappedSuperclass, "mapped-superclass");
}
for (JaxbEmbeddable embeddable : mapping.getEmbeddable()) {
String name = safeGetClassName(packagePrefix, embeddable, "embeddable");
enlistExplicitClass(collector, name);
}
for (JaxbConverter converter : mapping.getConverter()) {
collector.potentialCdiBeanTypes.add(DotName.createSimple(qualifyIfNecessary(packagePrefix, converter.getClazz())));
}
}
Aggregations