use of org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping in project eclipselink by eclipse-ee4j.
the class DynamicTestProject method addPhoneNumberDescriptor.
private void addPhoneNumberDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClassName("org.eclipse.persistence.testing.oxm.dynamic.XPhoneNumber");
XMLDirectMapping num = new XMLDirectMapping();
num.setAttributeName("number");
num.setXPath("text()");
descriptor.addMapping(num);
XMLInverseReferenceMapping owningEmployee = new XMLInverseReferenceMapping();
owningEmployee.setReferenceClassName("org.eclipse.persistence.testing.oxm.dynamic.XEmployee");
owningEmployee.setMappedBy("phoneNumbers");
owningEmployee.setAttributeName("owningEmployee");
owningEmployee.setSetMethodName("setOwningEmployee");
owningEmployee.setGetMethodName("getOwningEmployee");
descriptor.addMapping(owningEmployee);
this.addDescriptor(descriptor);
}
use of org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping in project eclipselink by eclipse-ee4j.
the class EmployeeInvalidContainerAttributeProject method addAddressDescriptor.
public void addAddressDescriptor(boolean methodAccess) {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Address.class);
XMLDirectMapping streetMapping = new XMLDirectMapping();
streetMapping.setAttributeName("street");
streetMapping.setXPath("street/text()");
descriptor.addMapping(streetMapping);
XMLDirectMapping cityMapping = new XMLDirectMapping();
cityMapping.setAttributeName("city");
cityMapping.setXPath("city/text()");
descriptor.addMapping(cityMapping);
XMLDirectMapping stateMapping = new XMLDirectMapping();
stateMapping.setAttributeName("state");
stateMapping.setXPath("state/text()");
descriptor.addMapping(stateMapping);
XMLDirectMapping countryMapping = new XMLDirectMapping();
countryMapping.setAttributeName("country");
countryMapping.setXPath("country/text()");
descriptor.addMapping(countryMapping);
XMLInverseReferenceMapping owningEmployee = new XMLInverseReferenceMapping();
owningEmployee.setReferenceClass(Employee.class);
owningEmployee.setMappedBy("address");
owningEmployee.setAttributeName("invalidAttribute");
if (methodAccess) {
owningEmployee.setSetMethodName("invalidAttributeGet");
owningEmployee.setGetMethodName("invalidAttributeSet");
}
descriptor.addMapping(owningEmployee);
this.addDescriptor(descriptor);
}
use of org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping in project eclipselink by eclipse-ee4j.
the class JAXBValueStore method setDeclaredProperty.
/**
* Set the value on the underlying POJO, unwrapping values as necessary.
*/
@Override
public void setDeclaredProperty(int propertyIndex, Object value) {
SDOProperty declaredProperty = (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
if (declaredProperty.getType().isChangeSummaryType()) {
return;
}
Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);
Object newValue = value;
Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
if (declaredProperty.getType().isDataType()) {
if (!declaredProperty.isMany()) {
AbstractSession session = ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
XMLDirectMapping directMapping = (XMLDirectMapping) mapping;
if (directMapping.hasConverter()) {
newValue = directMapping.getConverter().convertDataValueToObjectValue(newValue, session);
} else {
CoreField field = mapping.getField();
newValue = session.getDatasourcePlatform().getConversionManager().convertObject(newValue, descriptor.getObjectBuilder().getFieldClassification((XMLField) field));
}
}
mapping.setAttributeValueInObject(entity, newValue);
} else if (declaredProperty.isMany()) {
// Get a ListWrapper and set it's current elements
ListWrapper listWrapper = (ListWrapper) getDeclaredProperty(propertyIndex);
listWrapper.addAll((List) newValue);
} else {
// OLD VALUE
if (mapping.isAbstractCompositeObjectMapping()) {
XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
XMLInverseReferenceMapping inverseReferenceMapping = compositeMapping.getInverseReferenceMapping();
if (oldValue != null && inverseReferenceMapping != null && inverseReferenceMapping.getAttributeAccessor() != null) {
inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(oldValue, null);
}
}
// NEW VALUE
newValue = jaxbHelperContext.unwrap((DataObject) value);
mapping.getAttributeAccessor().setAttributeValueInObject(entity, newValue);
if (mapping.isAbstractCompositeObjectMapping()) {
XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
XMLInverseReferenceMapping inverseReferenceMapping = compositeMapping.getInverseReferenceMapping();
if (value != null && inverseReferenceMapping != null && inverseReferenceMapping.getAttributeAccessor() != null) {
inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(newValue, entity);
}
}
}
}
use of org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping in project eclipselink by eclipse-ee4j.
the class ReferenceAdapter method unmarshal.
/*
* (non-Javadoc)
*
* @see
* jakarta.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
*/
@SuppressWarnings("unchecked")
@Override
public T unmarshal(Object object) throws Exception {
if (object == null) {
return null;
}
PersistenceWeavedRest persistenceWeavedRest = null;
Link link;
if (object instanceof PersistenceWeavedRest) {
persistenceWeavedRest = (PersistenceWeavedRest) object;
link = persistenceWeavedRest._persistence_getHref();
} else if (object instanceof Link) {
link = (Link) object;
} else {
return null;
}
if (null == link || link.getHref() == null) {
if (persistenceWeavedRest != null) {
ClassDescriptor descriptor = context.getJAXBDescriptorForClass(persistenceWeavedRest.getClass());
if (persistenceWeavedRest instanceof FetchGroupTracker && JpaHelper.getDatabaseSession(context.getEmf()).doesObjectExist(persistenceWeavedRest)) {
if (context.doesExist(null, persistenceWeavedRest)) {
FetchGroup fetchGroup = new FetchGroup();
for (DatabaseMapping mapping : descriptor.getMappings()) {
if (!(mapping instanceof XMLInverseReferenceMapping)) {
fetchGroup.addAttribute(mapping.getAttributeName());
}
}
(new FetchGroupManager()).setObjectFetchGroup(persistenceWeavedRest, fetchGroup, null);
}
}
return (T) persistenceWeavedRest;
}
}
// Construct object from the href
if ((link != null) && (link.getHref() != null)) {
String uri = link.getHref().replace("\\/", "/");
String entityType = uri.substring(uri.indexOf("/entity/"), uri.lastIndexOf('/'));
entityType = entityType.substring(entityType.lastIndexOf('/') + 1);
String entityId = uri.substring(uri.lastIndexOf('/') + 1);
ClassDescriptor descriptor = context.getDescriptor(entityType);
Object id = IdHelper.buildId(context, descriptor.getAlias(), entityId);
T foundEntity = (T) getObjectById(entityType, id);
return foundEntity;
}
return null;
}
use of org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping in project eclipselink by eclipse-ee4j.
the class PersistenceContext method wrap.
/**
* Make adjustments to an unmarshalled entity based on what is found in the weaved fields
*/
protected Object wrap(Object entity) {
if ((entity != null) && (PersistenceWeavedRest.class.isAssignableFrom(entity.getClass()))) {
if (!doesExist(null, entity)) {
return entity;
}
ClassDescriptor descriptor = getJAXBDescriptorForClass(entity.getClass());
if (entity instanceof FetchGroupTracker) {
FetchGroup fetchGroup = new FetchGroup();
for (DatabaseMapping mapping : descriptor.getMappings()) {
if (!(mapping instanceof XMLInverseReferenceMapping)) {
fetchGroup.addAttribute(mapping.getAttributeName());
}
}
(new FetchGroupManager()).setObjectFetchGroup(entity, fetchGroup, null);
((FetchGroupTracker) entity)._persistence_setSession(JpaHelper.getDatabaseSession(getEmf()));
} else if (descriptor.hasRelationships()) {
for (DatabaseMapping mapping : descriptor.getMappings()) {
if (mapping instanceof XMLInverseReferenceMapping) {
// we require Fetch groups to handle relationships
JPARSLogger.error(getSessionLog(), "weaving_required_for_relationships", new Object[] {});
throw JPARSException.invalidConfiguration();
}
}
}
}
return entity;
}
Aggregations