Search in sources :

Example 1 with EntityAccessor

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;
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor) ForeignKeyMetadata(org.eclipse.persistence.internal.jpa.metadata.columns.ForeignKeyMetadata) MetadataDescriptor(org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor) JoinColumnMetadata(org.eclipse.persistence.internal.jpa.metadata.columns.JoinColumnMetadata) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 2 with EntityAccessor

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);
    }
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)

Example 3 with EntityAccessor

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);
    }
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)

Example 4 with EntityAccessor

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;
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor) ProcedureType(org.eclipse.persistence.tools.oracleddl.metadata.ProcedureType) TableType(org.eclipse.persistence.tools.oracleddl.metadata.TableType) ObjectTableType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType) PLSQLPackageType(org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType) FunctionType(org.eclipse.persistence.tools.oracleddl.metadata.FunctionType) ArrayList(java.util.ArrayList) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType)

Example 5 with EntityAccessor

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());
    }
}
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

EntityAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)17 EmbeddableAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor)5 ArrayList (java.util.ArrayList)4 MetadataDescriptor (org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor)4 MappedSuperclassAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor)4 MetadataClass (org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass)4 XMLEntityMappings (org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings)4 HashMap (java.util.HashMap)3 BasicAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor)3 ClassAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor)2 ConverterAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ConverterAccessor)2 XMLAttributes (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes)2 IdAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.IdAccessor)2 TenantDiscriminatorColumnMetadata (org.eclipse.persistence.internal.jpa.metadata.columns.TenantDiscriminatorColumnMetadata)2 PLSQLTableMetadata (org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata)2 TableMetadata (org.eclipse.persistence.internal.jpa.metadata.tables.TableMetadata)2 EntityNotFoundException (jakarta.persistence.EntityNotFoundException)1 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1