summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorGul Onural2012-10-19 15:48:47 (EDT)
committer tware2012-10-22 09:18:33 (EDT)
commit2f3b2cd688eae33feffefc9820eed58012809ff5 (patch)
treea02911eac2adf5bc8fa9352c33bd562e8bd4bd84
parent10f83eb54b92c958c7c1b5617162a85b66ac376f (diff)
downloadeclipselink.runtime-2f3b2cd688eae33feffefc9820eed58012809ff5.zip
eclipselink.runtime-2f3b2cd688eae33feffefc9820eed58012809ff5.tar.gz
eclipselink.runtime-2f3b2cd688eae33feffefc9820eed58012809ff5.tar.bz2
Fix for Bug 392478
-rw-r--r--dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/PersistenceContext.java53
-rw-r--r--dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/util/PreLoginMappingAdapter.java53
2 files changed, 51 insertions, 55 deletions
diff --git a/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/PersistenceContext.java b/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/PersistenceContext.java
index a331ccd..cfb47b4 100644
--- a/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/PersistenceContext.java
+++ b/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/PersistenceContext.java
@@ -309,19 +309,19 @@ public class PersistenceContext {
em.close();
}
}
-
+
public boolean doesExist(Map<String, String> tenantId, Object entity){
DatabaseSession session = JpaHelper.getDatabaseSession(getEmf());
return session.doesObjectExist(entity);
}
-
+
@Override
public void finalize(){
this.emf.close();
this.emf = null;
this.context = null;
}
-
+
/**
* A part of the facade over the JPA API
* Find an entity with the given name and id in JPA
@@ -805,7 +805,7 @@ public class PersistenceContext {
}
return entity;
}
-
+
/**
* Marshall an entity to either JSON or XML
* Calling this method, will treat relationships as unfetched in the XML/JSON and marshall them as links
@@ -903,21 +903,16 @@ public class PersistenceContext {
if (mapping.isForeignReferenceMapping()){
ForeignReferenceMapping frMapping = (ForeignReferenceMapping)mapping;
- RelationshipInfo info = new RelationshipInfo();
+ RelationshipInfo info = new RelationshipInfo();
- info.setAttributeName(frMapping.getAttributeName());
- info.setOwningEntity(entity);
- info.setOwningEntityAlias(descriptor.getAlias());
- info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity, getJpaSession()));
- ((PersistenceWeavedRest)entity)._persistence_getRelationships().add(info);
-
- //String href = baseURI + this.name + "/entity/" + info.getOwningEntityAlias() + "/" +
- // IdHelper.stringifyId(info.getOwningEntity(), info.getOwningEntityAlias(), this) + "/" + frMapping.getAttributeName();
- // ((PersistenceWeavedRest)entity)._persistence_setHref(href);
+ info.setAttributeName(frMapping.getAttributeName());
+ info.setOwningEntity(entity);
+ info.setOwningEntityAlias(descriptor.getAlias());
+ info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity, getJpaSession()));
+ ((PersistenceWeavedRest)entity)._persistence_getRelationships().add(info);
}
}
}
-
}
}
@@ -960,22 +955,18 @@ public class PersistenceContext {
protected List<XmlAdapter> getAdapters() throws Exception {
if (adapters == null) {
adapters = new ArrayList<XmlAdapter>();
- for (ClassDescriptor desc : this.getJpaSession().getDescriptors()
- .values()) {
- Class clz = desc.getJavaClass();
- String referenceAdapterName = clz.getName() + "."
- + RestAdapterClassWriter.ADAPTER_INNER_CLASS_NAME;
- ClassLoader cl = getJpaSession().getDatasourcePlatform()
- .getConversionManager().getLoader();
- Class referenceAdaptorClass = Class.forName(
- referenceAdapterName, true, cl);
-
- Class[] argTypes = { String.class, PersistenceContext.class };
- Constructor referenceAdaptorConstructor = referenceAdaptorClass
- .getDeclaredConstructor(argTypes);
- Object[] args = new Object[] { getBaseURI().toString(), this };
- adapters.add((XmlAdapter) referenceAdaptorConstructor
- .newInstance(args));
+ for (ClassDescriptor desc : this.getJpaSession().getDescriptors().values()) {
+ // avoid embeddables
+ if (!desc.isAggregateCollectionDescriptor() && !desc.isAggregateDescriptor()) {
+ Class clz = desc.getJavaClass();
+ String referenceAdapterName = clz.getName() + "." + RestAdapterClassWriter.ADAPTER_INNER_CLASS_NAME;
+ ClassLoader cl = getJpaSession().getDatasourcePlatform().getConversionManager().getLoader();
+ Class referenceAdaptorClass = Class.forName(referenceAdapterName, true, cl);
+ Class[] argTypes = { String.class, PersistenceContext.class };
+ Constructor referenceAdaptorConstructor = referenceAdaptorClass.getDeclaredConstructor(argTypes);
+ Object[] args = new Object[] { getBaseURI().toString(), this };
+ adapters.add((XmlAdapter) referenceAdaptorConstructor.newInstance(args));
+ }
}
}
return adapters;
diff --git a/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/util/PreLoginMappingAdapter.java b/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/util/PreLoginMappingAdapter.java
index a167ccd..9407c91 100644
--- a/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/util/PreLoginMappingAdapter.java
+++ b/dbws/org.eclipse.persistence.dbws/src/org/eclipse/persistence/jpa/rs/util/PreLoginMappingAdapter.java
@@ -46,11 +46,11 @@ import org.eclipse.persistence.sessions.SessionEvent;
public class PreLoginMappingAdapter extends SessionEventListener {
protected AbstractSession jpaSession;
-
+
public PreLoginMappingAdapter(AbstractSession jpaSession){
this.jpaSession = jpaSession;
}
-
+
@SuppressWarnings({ "unchecked" })
public void preLogin(SessionEvent event) {
Project project = event.getSession().getProject();
@@ -82,7 +82,7 @@ public class PreLoginMappingAdapter extends SessionEventListener {
hrefMapping.setXPath(".");
descriptor.addMapping(hrefMapping);
}
-
+
ClassDescriptor jpaDescriptor = jpaSession.getDescriptorForAlias(descriptor.getAlias());
Vector<DatabaseMapping> descriptorMappings = (Vector<DatabaseMapping>) descriptor.getMappings().clone();
for (DatabaseMapping mapping: descriptorMappings){
@@ -100,40 +100,45 @@ public class PreLoginMappingAdapter extends SessionEventListener {
}
}
- if (jpaDescriptor != null){
- ForeignReferenceMapping jpaMapping = (ForeignReferenceMapping)jpaDescriptor.getMappingForAttributeName(mapping.getAttributeName());
-
- if (jpaMapping != null) {
- if (jpaMapping.getMappedBy() != null){
- ClassDescriptor inverseDescriptor = project.getDescriptorForAlias(jpaMapping.getReferenceDescriptor().getAlias());
- DatabaseMapping inverseMapping = inverseDescriptor.getMappingForAttributeName(jpaMapping.getMappedBy());
- convertMappingToXMLInverseReferenceMapping(inverseDescriptor, inverseMapping, jpaMapping.getAttributeName());
+ if (jpaDescriptor != null) {
+ DatabaseMapping dbMapping = jpaDescriptor.getMappingForAttributeName(mapping.getAttributeName());
+ if ((dbMapping != null) && (dbMapping instanceof ForeignReferenceMapping)) {
+ ForeignReferenceMapping jpaMapping = (ForeignReferenceMapping) dbMapping;
+ if (jpaMapping != null) {
+ if (jpaMapping.getMappedBy() != null) {
+ ClassDescriptor inverseDescriptor = project.getDescriptorForAlias(jpaMapping.getReferenceDescriptor().getAlias());
+ DatabaseMapping inverseMapping = inverseDescriptor.getMappingForAttributeName(jpaMapping.getMappedBy());
+ convertMappingToXMLInverseReferenceMapping(inverseDescriptor, inverseMapping, jpaMapping.getAttributeName());
+ }
}
}
}
}
}
}
-
+
ClassLoader cl = jpaSession.getPlatform().getConversionManager().getLoader();
descriptorMappings = (Vector<DatabaseMapping>) descriptor.getMappings().clone();
- for (DatabaseMapping mapping: descriptorMappings){
+ for (DatabaseMapping mapping : descriptorMappings) {
if (jpaDescriptor != null && mapping.isXMLMapping()){
- if (mapping.isAbstractCompositeObjectMapping() || mapping.isAbstractCompositeCollectionMapping()){
- ForeignReferenceMapping jpaMapping = (ForeignReferenceMapping)jpaDescriptor.getMappingForAttributeName(mapping.getAttributeName());
- if (jpaMapping != null) {
- // Convert all ForeignReferenceMappings that are visible in JPA
- // to ChoiceMapping to allow a link to be returned instead of the whole Object
- // XMLInverseMappings are ignored in JAXB, so we should not convert those
- convertMappingToXMLChoiceMapping(descriptor, jpaMapping, cl);
+ if (mapping.isAbstractCompositeObjectMapping() || mapping.isAbstractCompositeCollectionMapping()) {
+ DatabaseMapping dbMapping = jpaDescriptor.getMappingForAttributeName(mapping.getAttributeName());
+ if ((dbMapping != null) && (dbMapping instanceof ForeignReferenceMapping)) {
+ ForeignReferenceMapping jpaMapping = (ForeignReferenceMapping) dbMapping;
+ if (jpaMapping != null) {
+ // Convert all ForeignReferenceMappings that are visible in JPA
+ // to ChoiceMapping to allow a link to be returned instead of the whole Object
+ // XMLInverseMappings are ignored in JAXB, so we should not convert those
+ convertMappingToXMLChoiceMapping(descriptor, jpaMapping, cl);
+ }
}
}
- }
+ }
}
}
}
-
+
/**
* Update the targetMapping to have the same accessor as the originMapping
* @param originMapping
@@ -155,7 +160,7 @@ public class PreLoginMappingAdapter extends SessionEventListener {
targetMapping.setSetMethodName(originMapping.getSetMethodName());
}
}
-
+
/**
* Build an XMLInverseMapping based on a particular mapping and replace that mapping with
* the newly created XMLInverseMapping in jaxbDescriptor
@@ -181,7 +186,7 @@ public class PreLoginMappingAdapter extends SessionEventListener {
jaxbDescriptor.removeMappingForAttributeName(mapping.getAttributeName());
jaxbDescriptor.addMapping(jaxbInverseMapping);
}
-
+
/**
* Build an XMLChoiceObjectMapping based on a particular mapping and replace that mapping with
* the newly created XMLChoiceObjectMapping in jaxbDescriptor.