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