Search in sources :

Example 1 with MetadataProject

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

the class MetadataMirrorFactory method getMetadataProject.

/**
 * INTERNAL:
 * We preserve state from each processor run by holding static references
 * to projects.
 */
public MetadataProject getMetadataProject(SEPersistenceUnitInfo puInfo) {
    if (!metadataProjects.containsKey(puInfo.getPersistenceUnitName())) {
        AbstractSession session = new ServerSession(new Project(new DatabaseLogin()));
        session.setSessionLog(getLogger().getSession().getSessionLog());
        MetadataProject project = new MetadataProject(puInfo, session, false, false, false, false, false);
        metadataProjects.put(puInfo.getPersistenceUnitName(), project);
        return project;
    } else {
        return metadataProjects.get(puInfo.getPersistenceUnitName());
    }
}
Also used : MetadataProject(org.eclipse.persistence.internal.jpa.metadata.MetadataProject) Project(org.eclipse.persistence.sessions.Project) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) MetadataProject(org.eclipse.persistence.internal.jpa.metadata.MetadataProject) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 2 with MetadataProject

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

the class RelationshipAccessor method getReferenceDescriptor.

/**
 * INTERNAL:
 * Return the reference metadata descriptor for this accessor.
 * This method does additional checks to make sure that the target
 * entity is indeed an entity class.
 */
@Override
public MetadataDescriptor getReferenceDescriptor() {
    MetadataDescriptor referenceDescriptor;
    // @see MetadataAnnotatedElement getRawClass(MetadataDescriptor)
    if (getDescriptor().isMappedSuperclass() && getReferenceClassName().equals(MetadataAnnotatedElement.DEFAULT_RAW_CLASS) || getReferenceClass().isVoid()) {
        MappingAccessor childMappingAccessor = getDescriptor().getMetamodelMappedSuperclassChildDescriptor().getMappingAccessor(getAttributeName());
        referenceDescriptor = childMappingAccessor.getReferenceDescriptor();
        if (referenceDescriptor.isInheritanceSubclass()) {
            referenceDescriptor = referenceDescriptor.getInheritanceRootDescriptor();
        }
    } else {
        ClassAccessor accessor = getProject().getAccessor(getReferenceClassName());
        referenceDescriptor = (accessor != null) ? accessor.getDescriptor() : null;
        if (referenceDescriptor == null) {
            MetadataProcessor compositeProcessor = getProject().getCompositeProcessor();
            if (compositeProcessor != null) {
                for (MetadataProject pearProject : compositeProcessor.getPearProjects(getProject())) {
                    accessor = pearProject.getAccessor(getReferenceClassName());
                    if (accessor != null) {
                        referenceDescriptor = accessor.getDescriptor();
                        break;
                    }
                }
            }
        }
    }
    // Validate the reference descriptor is valid.
    if (referenceDescriptor == null || referenceDescriptor.isEmbeddable() || referenceDescriptor.isEmbeddableCollection()) {
        throw ValidationException.nonEntityTargetInRelationship(getJavaClass(), getReferenceClass(), getAnnotatedElement());
    }
    return referenceDescriptor;
}
Also used : ClassAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor) MetadataDescriptor(org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor) MetadataProcessor(org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor) MetadataProject(org.eclipse.persistence.internal.jpa.metadata.MetadataProject)

Example 3 with MetadataProject

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

the class CanonicalModelProcessor method writeImportStatements.

/**
 * INTERNAL:
 */
protected String writeImportStatements(HashMap<String, String> typeImports, ClassAccessor accessor, Writer writer, PersistenceUnit persistenceUnit, String childCanonicalpackage) throws IOException {
    String parentCanonicalName = null;
    // Get the import list ready to be sorted.
    ArrayList<String> imps = new ArrayList<>();
    imps.addAll(typeImports.values());
    // Add the standard canonical model generator imports.
    imps.add("jakarta.persistence.metamodel.StaticMetamodel");
    // Import the parent canonical class if need be.
    MetadataClass parentCls = accessor.getJavaClass().getSuperclass();
    MetadataProject project = accessor.getProject();
    if (project.hasEntity(parentCls) || project.hasEmbeddable(parentCls) || project.hasMappedSuperclass(parentCls)) {
        String qualifiedParentCanonicalName = persistenceUnit.getQualifiedCanonicalName(parentCls.getName());
        parentCanonicalName = getName(qualifiedParentCanonicalName);
        String parentCanonicalPackage = getPackage(qualifiedParentCanonicalName);
        if (!parentCanonicalPackage.equals(childCanonicalpackage)) {
            imps.add(qualifiedParentCanonicalName);
        }
    }
    // Sort the list of imports before writing them.
    Collections.sort(imps);
    // Write out the imports.
    for (String typeImport : imps) {
        writer.append("import " + typeImport + ";\n");
    }
    writer.append("\n");
    return parentCanonicalName;
}
Also used : MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass) ArrayList(java.util.ArrayList) MetadataProject(org.eclipse.persistence.internal.jpa.metadata.MetadataProject)

Aggregations

MetadataProject (org.eclipse.persistence.internal.jpa.metadata.MetadataProject)3 ArrayList (java.util.ArrayList)1 MetadataDescriptor (org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor)1 MetadataProcessor (org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor)1 ClassAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor)1 MetadataClass (org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)1 Project (org.eclipse.persistence.sessions.Project)1 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)1