use of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicCollectionAccessor 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>());
}
use of org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicCollectionAccessor 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());
}
}
Aggregations