use of org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor in project eclipselink by eclipse-ee4j.
the class MappingAccessor method processEntityMapKeyClass.
/**
* INTERNAL:
* Process the map key to be an entity class.
*/
protected OneToOneMapping processEntityMapKeyClass(MappedKeyMapAccessor mappedKeyMapAccessor) {
String mapKeyClassName = mappedKeyMapAccessor.getMapKeyClass().getName();
// Create the one to one map key mapping.
OneToOneMapping keyMapping = new OneToOneMapping();
keyMapping.setReferenceClassName(mapKeyClassName);
keyMapping.dontUseIndirection();
keyMapping.setDescriptor(getDescriptor().getClassDescriptor());
// Process the map key join columns.
EntityAccessor mapKeyAccessor = getProject().getEntityAccessor(mapKeyClassName);
MetadataDescriptor mapKeyClassDescriptor = mapKeyAccessor.getDescriptor();
// If the fk field (name) is not specified, it defaults to the
// concatenation of the following: the name of the referencing
// relationship property or field of the referencing entity or
// embeddable; "_"; "KEY"
String defaultFKFieldName = getAttributeName() + DEFAULT_MAP_KEY_COLUMN_SUFFIX;
// Get the join columns (directly or through an association override),
// init them and validate.
List<JoinColumnMetadata> joinColumns = getJoinColumns(mappedKeyMapAccessor.getMapKeyJoinColumns(), mapKeyClassDescriptor);
// Get the foreign key (directly or through an association override) and
// make sure it is initialized for processing.
ForeignKeyMetadata foreignKey = getForeignKey(mappedKeyMapAccessor.getMapKeyForeignKey(), mapKeyClassDescriptor);
// Now process the foreign key relationship metadata.
processForeignKeyRelationship(keyMapping, joinColumns, foreignKey, mapKeyClassDescriptor, defaultFKFieldName, getDefaultTableForEntityMapKey());
return keyMapping;
}
use of org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor in project eclipselink by eclipse-ee4j.
the class MetadataProcessor method addEntityListeners.
/**
* INTERNAL:
* Method to place EntityListener's on the descriptors from the given
* session. This call is made from the EntityManagerSetup deploy call.
*/
public void addEntityListeners() {
// should have changed changed.
for (EntityAccessor accessor : m_project.getEntityAccessors()) {
accessor.setJavaClass(accessor.getDescriptor().getJavaClass());
accessor.processListeners(m_loader);
}
}
use of org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor in project eclipselink by eclipse-ee4j.
the class ORMetadata method reloadEntity.
/**
* INTERNAL:
* This method should be called to reload an entity (that was either
* loaded from XML or an annotation) as a way of cloning it. This is needed
* when we process TABLE_PER_CLASS inheritance. We must process the parent
* classes for every subclasses descriptor. The processing is similar to
* that of processing a mapped superclass, in that we process the parents
* with the subclasses context (that is, the descriptor we are given).
*/
protected EntityAccessor reloadEntity(EntityAccessor entity, MetadataDescriptor descriptor) {
if (entity.loadedFromAnnotation()) {
// Create a new EntityAccesor.
EntityAccessor entityAccessor = new EntityAccessor(entity.getAnnotation(), entity.getJavaClass(), entity.getProject());
// Things we care about ...
descriptor.setDefaultAccess(entity.getDescriptor().getDefaultAccess());
entityAccessor.setDescriptor(descriptor);
return entityAccessor;
} else {
return entity.getEntityMappings().reloadEntity(entity, descriptor);
}
}
use of org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor in project eclipselink by eclipse-ee4j.
the class JPAMetadataGenerator method generateXmlEntityMappings.
/**
* Generate an XMLEntityMappings instance based on a given list of meta-model database types.
*
* @param databaseTypes the list of meta-model database types to be used to generate an XMLEntityMappings
* @see org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType
*/
public XMLEntityMappings generateXmlEntityMappings(List<CompositeDatabaseType> databaseTypes) {
List<ProcedureType> procedures = new ArrayList<ProcedureType>();
List<TableType> tables = new ArrayList<TableType>();
// populate lists of TableTypes and ProcedureTypes
for (CompositeDatabaseType dbType : databaseTypes) {
if (dbType.isTableType()) {
tables.add((TableType) dbType);
} else if (dbType.isProcedureType()) {
procedures.add((ProcedureType) dbType);
}
}
// handle stored procedure overloading
handleOverloading(procedures);
// process TableTypes
for (TableType table : tables) {
EntityAccessor entity = processTableType(table);
xmlEntityMappings.getEntities().add(entity);
}
// process ProcedureTypes
for (ProcedureType procedure : procedures) {
// PL/SQL stored procedures and functions will have a PLSQLPackageType as its parent
PLSQLPackageType pkgType = procedure.getParentType();
if (pkgType != null) {
// handle PL/SQL
if (procedure.isFunctionType()) {
xmlEntityMappings.getNamedPLSQLStoredFunctionQueries().add(processPLSQLFunctionType((FunctionType) procedure, pkgType));
} else {
xmlEntityMappings.getNamedPLSQLStoredProcedureQueries().add(processPLSQLProcedureType(procedure, pkgType));
}
} else {
// handle top-level (non-PL/SQL) functions and procedures
if (procedure.isFunctionType()) {
xmlEntityMappings.getNamedStoredFunctionQueries().add(processFunctionType((FunctionType) procedure));
} else {
xmlEntityMappings.getNamedStoredProcedureQueries().add(processProcedureType(procedure));
}
}
}
return xmlEntityMappings;
}
use of org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor 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