Search in sources :

Example 1 with OneToManyAccessor

use of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToManyAccessor in project eclipselink by eclipse-ee4j.

the class JPAMetadataGenerator method initializeXMLAttributeLists.

/**
 * XMLAttributes processing at runtime (i.e. PersistenceUnitProcessor.processORMetadata)
 * assumes that all lists are initialized.  We need to init all lists to avoid runtime
 * exceptions.
 *
 * @see org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes
 */
protected void initializeXMLAttributeLists(ClassAccessor accessor) {
    accessor.setAttributes(new XMLAttributes());
    accessor.getAttributes().setIds(new ArrayList<IdAccessor>());
    accessor.getAttributes().setBasics(new ArrayList<BasicAccessor>());
    accessor.getAttributes().setArrays(new ArrayList<ArrayAccessor>());
    accessor.getAttributes().setStructures(new ArrayList<StructureAccessor>());
    accessor.getAttributes().setEmbeddeds(new ArrayList<EmbeddedAccessor>());
    // initialize other various lists (to avoid exceptions)
    accessor.getAttributes().setBasicCollections(new ArrayList<BasicCollectionAccessor>());
    accessor.getAttributes().setBasicMaps(new ArrayList<BasicMapAccessor>());
    accessor.getAttributes().setElementCollections(new ArrayList<ElementCollectionAccessor>());
    accessor.getAttributes().setManyToManys(new ArrayList<ManyToManyAccessor>());
    accessor.getAttributes().setManyToOnes(new ArrayList<ManyToOneAccessor>());
    accessor.getAttributes().setOneToManys(new ArrayList<OneToManyAccessor>());
    accessor.getAttributes().setOneToOnes(new ArrayList<OneToOneAccessor>());
    accessor.getAttributes().setTransformations(new ArrayList<TransformationAccessor>());
    accessor.getAttributes().setTransients(new ArrayList<TransientAccessor>());
    accessor.getAttributes().setVariableOneToOnes(new ArrayList<VariableOneToOneAccessor>());
    accessor.getAttributes().setVersions(new ArrayList<VersionAccessor>());
}
Also used : TransientAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.TransientAccessor) VersionAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.VersionAccessor) ElementCollectionAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ElementCollectionAccessor) ManyToOneAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ManyToOneAccessor) VariableOneToOneAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.VariableOneToOneAccessor) BasicMapAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicMapAccessor) ManyToManyAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ManyToManyAccessor) OneToManyAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToManyAccessor) BasicAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor) TransformationAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.TransformationAccessor) ArrayAccessor(org.eclipse.persistence.internal.jpa.metadata.structures.ArrayAccessor) VariableOneToOneAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.VariableOneToOneAccessor) OneToOneAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToOneAccessor) BasicCollectionAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicCollectionAccessor) XMLAttributes(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes) IdAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor) StructureAccessor(org.eclipse.persistence.internal.jpa.metadata.structures.StructureAccessor) EmbeddedAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.EmbeddedAccessor)

Example 2 with OneToManyAccessor

use of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToManyAccessor in project eclipselink by eclipse-ee4j.

the class EntityMappingsAdvancedJUnitTestCase method testXMLEntityMappingsWriteOut.

public void testXMLEntityMappingsWriteOut() {
    try {
        XMLEntityMappings mappings = new XMLEntityMappings();
        mappings.setPersistenceUnitMetadata(new XMLPersistenceUnitMetadata());
        mappings.getPersistenceUnitMetadata().setPersistenceUnitDefaults(new XMLPersistenceUnitDefaults());
        XMLPersistenceUnitMetadata persistenceUnitMetadata = new XMLPersistenceUnitMetadata();
        persistenceUnitMetadata.setPersistenceUnitDefaults(new XMLPersistenceUnitDefaults());
        mappings.setPersistenceUnitMetadata(persistenceUnitMetadata);
        EntityAccessor entity = new EntityAccessor();
        mappings.setEntities(new ArrayList<EntityAccessor>());
        entity.setAttributes(new XMLAttributes());
        entity.getAttributes().setBasicCollections(new ArrayList<BasicCollectionAccessor>());
        entity.getAttributes().getBasicCollections().add(new BasicCollectionAccessor());
        entity.getAttributes().setOneToManys(new ArrayList<OneToManyAccessor>());
        OneToManyAccessor oneToMany = new OneToManyAccessor();
        oneToMany.setCascade(new CascadeMetadata());
        entity.getAttributes().getOneToManys().add(oneToMany);
        entity.getAttributes().setBasics(new ArrayList<BasicAccessor>());
        entity.getAttributes().getBasics().add(new BasicAccessor());
        mappings.getEntities().add(entity);
        XMLEntityMappingsWriter writer = new XMLEntityMappingsWriter();
        FileOutputStream fileOut = new FileOutputStream("XMLWriteOutTest.xml");
        XMLEntityMappingsWriter.write(mappings, fileOut);
        fileOut.close();
        FileInputStream fileIn = new FileInputStream(fileOut.getFD());
        BufferedReader in = new BufferedReader(new InputStreamReader(fileIn));
        HashSet<String> readStrings = new HashSet<String>();
        while (in.ready()) {
            readStrings.add(in.readLine());
        }
        in.close();
        // Now look for those empty types that we should not see when not explicitly set ...
        assertFalse("Found cascade on delete element", readStrings.contains("<cascade-on-delete"));
        assertFalse("Found non cacheable element", readStrings.contains("<noncacheable"));
        assertFalse("Found private owned element", readStrings.contains("<private-owned"));
        assertFalse("Found xml mapping metadata complete element", readStrings.contains("<xml-mapping-metadata-complete"));
        assertFalse("Found exclude default mappings element", readStrings.contains("<exclude-default-mappings"));
        assertFalse("Found delimeted identifiers element", readStrings.contains("<delimited-identifiers"));
        assertFalse("Found exclude default listeners element", readStrings.contains("<exclude-default-listeners"));
        assertFalse("Found exclude superclass listeners element", readStrings.contains("<exclude-superclass-listeners"));
        assertFalse("Found return update element", readStrings.contains("<return-update"));
        assertFalse("Found cascade all element", readStrings.contains("<cascade-all"));
        assertFalse("Found cascade persist element", readStrings.contains("<cascade-persist"));
        assertFalse("Found cascade merge element", readStrings.contains("<cascade-merge"));
        assertFalse("Found cascade remove element", readStrings.contains("<cascade-remove"));
        assertFalse("Found cascade refresh element", readStrings.contains("<cascade-refresh"));
        assertFalse("Found cascade detach element", readStrings.contains("<cascade-detach"));
    } catch (Exception e) {
        e.printStackTrace();
        fail("An error occurred: " + e.getMessage());
    }
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor) OneToManyAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToManyAccessor) BasicAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor) XMLEntityMappingsWriter(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappingsWriter) InputStreamReader(java.io.InputStreamReader) XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings) XMLPersistenceUnitMetadata(org.eclipse.persistence.internal.jpa.metadata.xml.XMLPersistenceUnitMetadata) CascadeMetadata(org.eclipse.persistence.internal.jpa.metadata.mappings.CascadeMetadata) XMLPersistenceUnitDefaults(org.eclipse.persistence.internal.jpa.metadata.xml.XMLPersistenceUnitDefaults) FileInputStream(java.io.FileInputStream) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) BasicCollectionAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicCollectionAccessor) XMLAttributes(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) HashSet(java.util.HashSet)

Aggregations

XMLAttributes (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes)2 BasicAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor)2 BasicCollectionAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicCollectionAccessor)2 OneToManyAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToManyAccessor)2 EntityNotFoundException (jakarta.persistence.EntityNotFoundException)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 HashSet (java.util.HashSet)1 EntityAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)1 BasicMapAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicMapAccessor)1 ElementCollectionAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ElementCollectionAccessor)1 EmbeddedAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.EmbeddedAccessor)1 IdAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor)1 ManyToManyAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ManyToManyAccessor)1 ManyToOneAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ManyToOneAccessor)1 OneToOneAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToOneAccessor)1 TransformationAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.TransformationAccessor)1 TransientAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.TransientAccessor)1