Search in sources :

Example 1 with XMLEntityMappings

use of org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings in project eclipselink by eclipse-ee4j.

the class MetadataProcessor method setClassLoader.

/**
 * INTERNAL:
 * Use this method to set the correct class loader that should be used
 * during processing. Currently, the class loader should only change
 * once, from preDeploy to deploy.
 */
public void setClassLoader(ClassLoader loader) {
    m_loader = loader;
    m_factory.setLoader(loader);
    // Update the loader on all the entity mappings for this project.
    for (XMLEntityMappings entityMappings : m_project.getEntityMappings()) {
        entityMappings.setLoader(m_loader);
    }
}
Also used : XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings)

Example 2 with XMLEntityMappings

use of org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings in project eclipselink by eclipse-ee4j.

the class MetadataProcessor method loadMappingFiles.

/**
 * INTERNAL:
 * This method is responsible for figuring out list of mapping files to
 * read into XMLEntityMappings objects and store on the project. Note,
 * the order the files are discovered and read is very important so do
 * not change the order of invocation.
 */
public void loadMappingFiles(boolean throwExceptionOnFail) {
    // Read all the standard XML mapping files first.
    loadStandardMappingFiles(MetadataHelper.JPA_ORM_FILE);
    // Read all the explicitly specified mapping files second.
    loadSpecifiedMappingFiles(throwExceptionOnFail);
    // Read all the standard eclipselink files last (if the user hasn't
    // explicitly excluded them). The eclipselink orm files will be
    // processed last therefore allowing them to override and merge
    // metadata where necessary. Note: we want the eclipselink orm
    // metadata to merge into standard jpa files and not vice versa.
    // Loading them last will ensure this happens.
    Boolean excludeEclipseLinkORM = Boolean.valueOf((String) m_project.getPersistenceUnitInfo().getProperties().get(PersistenceUnitProperties.EXCLUDE_ECLIPSELINK_ORM_FILE));
    if (!excludeEclipseLinkORM) {
        loadStandardMappingFiles(MetadataHelper.ECLIPSELINK_ORM_FILE);
    }
    if (m_metadataSource != null) {
        XMLEntityMappings entityMappings = m_metadataSource.getEntityMappings(this.m_predeployProperties, m_loader, m_session.getSessionLog());
        if (entityMappings != null) {
            m_project.addEntityMappings(entityMappings);
        }
    }
}
Also used : XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings)

Example 3 with XMLEntityMappings

use of org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings in project eclipselink by eclipse-ee4j.

the class PLSQLRecordTypeTestSuite method testJPAPLSQLRecordMetadata.

@Test
@SuppressWarnings({ "unchecked" })
public void testJPAPLSQLRecordMetadata() {
    if (dbProcedures == null || dbProcedures.isEmpty()) {
        fail("No types were generated.");
    }
    XMLEntityMappings mappings = null;
    try {
        JPAMetadataGenerator gen = new JPAMetadataGenerator(DEFAULT_PACKAGE_NAME, databasePlatform);
        mappings = gen.generateXmlEntityMappings(dbProcedures);
    } catch (Exception x) {
        x.printStackTrace();
        fail("An unexpected exception occurred: " + x.getMessage());
    }
    if (mappings == null) {
        fail("No JPA metadata was generated");
    }
    ByteArrayOutputStream metadata = new ByteArrayOutputStream();
    XMLEntityMappingsWriter.write(mappings, metadata);
    Document testDoc = xmlParser.parse(new StringReader(metadata.toString()));
    removeEmptyTextNodes(testDoc);
    Document controlDoc = xmlParser.parse(new StringReader(typemetadata));
    removeEmptyTextNodes(controlDoc);
    assertTrue("Metadata comparison failed.  Expected:\n" + documentToString(controlDoc) + "\nActual\n" + documentToString(testDoc), comparer.isNodeEqual(controlDoc, testDoc));
}
Also used : JPAMetadataGenerator(org.eclipse.persistence.tools.metadata.generation.JPAMetadataGenerator) XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) SQLException(java.sql.SQLException) ParseException(org.eclipse.persistence.tools.oracleddl.parser.ParseException) Test(org.junit.Test)

Example 4 with XMLEntityMappings

use of org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings in project eclipselink by eclipse-ee4j.

the class ProcedureOverloadTestSuite method testProcedureOverload.

@Test
@SuppressWarnings({ "unchecked" })
public void testProcedureOverload() {
    if (dbProcedures == null || dbProcedures.isEmpty()) {
        fail("No types were generated.");
    }
    XMLEntityMappings mappings = null;
    try {
        JPAMetadataGenerator gen = new JPAMetadataGenerator(DEFAULT_PACKAGE_NAME, databasePlatform);
        mappings = gen.generateXmlEntityMappings(dbProcedures);
    } catch (Exception x) {
        fail("An unexpected exception occurred: " + x.getMessage());
    }
    if (mappings == null) {
        fail("No JPA metadata was generated");
    }
    ByteArrayOutputStream metadata = new ByteArrayOutputStream();
    XMLEntityMappingsWriter.write(mappings, metadata);
    Document testDoc = xmlParser.parse(new StringReader(metadata.toString()));
    removeEmptyTextNodes(testDoc);
    Document controlDoc = xmlParser.parse(new StringReader(procedureMetadata));
    removeEmptyTextNodes(controlDoc);
    assertTrue("Metadata comparison failed.  Expected:\n" + documentToString(controlDoc) + "\nActual\n" + documentToString(testDoc), comparer.isNodeEqual(controlDoc, testDoc));
}
Also used : JPAMetadataGenerator(org.eclipse.persistence.tools.metadata.generation.JPAMetadataGenerator) XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) SQLException(java.sql.SQLException) ParseException(org.eclipse.persistence.tools.oracleddl.parser.ParseException) Test(org.junit.Test)

Example 5 with XMLEntityMappings

use of org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings in project eclipselink by eclipse-ee4j.

the class ProcedureTypeTestSuite method testJPAProcedureMetadata.

@Test
@SuppressWarnings({ "unchecked" })
public void testJPAProcedureMetadata() {
    if (dbProcedures == null || dbProcedures.isEmpty()) {
        fail("No types were generated.");
    }
    XMLEntityMappings mappings = null;
    try {
        JPAMetadataGenerator gen = new JPAMetadataGenerator(DEFAULT_PACKAGE_NAME, databasePlatform);
        mappings = gen.generateXmlEntityMappings(dbProcedures);
    } catch (Exception x) {
        fail("An unexpected exception occurred: " + x.getMessage());
    }
    if (mappings == null) {
        fail("No JPA metadata was generated");
    }
    ByteArrayOutputStream metadata = new ByteArrayOutputStream();
    XMLEntityMappingsWriter.write(mappings, metadata);
    Document testDoc = xmlParser.parse(new StringReader(metadata.toString()));
    removeEmptyTextNodes(testDoc);
    Document controlDoc = xmlParser.parse(new StringReader(procedureMetadata));
    removeEmptyTextNodes(controlDoc);
    assertTrue("Metadata comparison failed.  Expected:\n" + documentToString(controlDoc) + "\nActual\n" + documentToString(testDoc), comparer.isNodeEqual(controlDoc, testDoc));
}
Also used : JPAMetadataGenerator(org.eclipse.persistence.tools.metadata.generation.JPAMetadataGenerator) XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) SQLException(java.sql.SQLException) ParseException(org.eclipse.persistence.tools.oracleddl.parser.ParseException) Test(org.junit.Test)

Aggregations

XMLEntityMappings (org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings)23 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 StringReader (java.io.StringReader)13 SQLException (java.sql.SQLException)13 JPAMetadataGenerator (org.eclipse.persistence.tools.metadata.generation.JPAMetadataGenerator)13 ParseException (org.eclipse.persistence.tools.oracleddl.parser.ParseException)13 Test (org.junit.Test)13 Document (org.w3c.dom.Document)13 EntityAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)4 HashMap (java.util.HashMap)3 EmbeddableAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor)3 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 XMLAttributes (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes)2 BasicAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor)2 EntityNotFoundException (jakarta.persistence.EntityNotFoundException)1 JAXBContext (jakarta.xml.bind.JAXBContext)1