Search in sources :

Example 1 with JaxbPersistenceUnitDefaults

use of org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults 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;
}
Also used : ArrayList(java.util.ArrayList) JaxbPersistenceUnitDefaults(org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults) JaxbPersistenceUnitMetadata(org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata)

Example 2 with JaxbPersistenceUnitDefaults

use of org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults 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) {
        }
    }
}
Also used : Origin(org.hibernate.boot.jaxb.Origin) InputStream(java.io.InputStream) JaxbEntityListener(org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListener) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) MappingBinder(org.hibernate.boot.jaxb.internal.MappingBinder) JaxbEntityMappings(org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings) JaxbPersistenceUnitDefaults(org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults) JaxbPersistenceUnitMetadata(org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity) Test(org.junit.jupiter.api.Test)

Example 3 with JaxbPersistenceUnitDefaults

use of org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults 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())));
    }
}
Also used : JaxbConverter(org.hibernate.boot.jaxb.mapping.spi.JaxbConverter) JaxbMappedSuperclass(org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclass) JaxbEmbeddable(org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddable) JaxbPersistenceUnitDefaults(org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults) JaxbPersistenceUnitMetadata(org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Aggregations

JaxbPersistenceUnitDefaults (org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults)3 JaxbPersistenceUnitMetadata (org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata)3 JaxbEntity (org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Origin (org.hibernate.boot.jaxb.Origin)1 MappingBinder (org.hibernate.boot.jaxb.internal.MappingBinder)1 JaxbConverter (org.hibernate.boot.jaxb.mapping.spi.JaxbConverter)1 JaxbEmbeddable (org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddable)1 JaxbEntityListener (org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListener)1 JaxbEntityMappings (org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings)1 JaxbMappedSuperclass (org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclass)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 Test (org.junit.jupiter.api.Test)1