use of org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping in project eclipselink by eclipse-ee4j.
the class PersistenceContext method setRelationshipInfo.
private void setRelationshipInfo(Object entity) {
if ((entity != null) && (entity instanceof PersistenceWeavedRest)) {
ClassDescriptor descriptor = getServerSession().getClassDescriptor(entity.getClass());
if (descriptor != null) {
((PersistenceWeavedRest) entity)._persistence_setRelationships(new ArrayList<>());
for (DatabaseMapping mapping : descriptor.getMappings()) {
if (mapping.isForeignReferenceMapping()) {
ForeignReferenceMapping frMapping = (ForeignReferenceMapping) mapping;
RelationshipInfo info = new RelationshipInfo();
info.setAttributeName(frMapping.getAttributeName());
info.setOwningEntity(entity);
info.setOwningEntityAlias(descriptor.getAlias());
info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity, (AbstractSession) getServerSession()));
((PersistenceWeavedRest) entity)._persistence_getRelationships().add(info);
} else if (mapping.isEISMapping()) {
if (mapping instanceof EISCompositeCollectionMapping) {
EISCompositeCollectionMapping eisMapping = (EISCompositeCollectionMapping) mapping;
RelationshipInfo info = new RelationshipInfo();
info.setAttributeName(eisMapping.getAttributeName());
info.setOwningEntity(entity);
info.setOwningEntityAlias(descriptor.getAlias());
info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity, (AbstractSession) getServerSession()));
((PersistenceWeavedRest) entity)._persistence_getRelationships().add(info);
}
}
}
}
}
}
use of org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping in project eclipselink by eclipse-ee4j.
the class DynamicXMLMetadataSource method createJAXBProperty.
/**
* Create a JAXB property for a particular mapping.
* This will only create JAXBProperties for mappings that are virtual - either because their
* parent object is a dynamic class, or because the owning static class has virtual properties
*/
private JAXBElement<XmlElement> createJAXBProperty(DatabaseMapping mapping, ObjectFactory objectFactory, JavaType owningType, boolean isDynamic) {
if (!mapping.getAttributeAccessor().isVirtualAttributeAccessor() && !isDynamic) {
return null;
}
XmlElement xmlElement = new XmlElement();
xmlElement.setJavaAttribute(mapping.getAttributeName());
if (mapping.isObjectReferenceMapping()) {
xmlElement.setType(((ObjectReferenceMapping) mapping).getReferenceClassName());
} else if (mapping.isCollectionMapping()) {
if (mapping.isEISMapping()) {
// It will be fine for simple collections
if (mapping instanceof EISCompositeDirectCollectionMapping) {
xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
} else if (mapping instanceof EISCompositeCollectionMapping) {
xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
xmlElement.setType(((EISCompositeCollectionMapping) mapping).getReferenceClassName());
}
} else {
xmlElement.setType(((CollectionMapping) mapping).getReferenceClassName());
xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
}
} else {
xmlElement.setType(mapping.getAttributeClassification().getName());
}
if (mapping.getAttributeAccessor().isVirtualAttributeAccessor()) {
VirtualAttributeAccessor jpaAccessor = (VirtualAttributeAccessor) mapping.getAttributeAccessor();
if (owningType.getXmlVirtualAccessMethods() == null) {
XmlVirtualAccessMethods virtualAccessMethods = new XmlVirtualAccessMethods();
virtualAccessMethods.setGetMethod(jpaAccessor.getGetMethodName());
virtualAccessMethods.setSetMethod(jpaAccessor.getSetMethodName());
owningType.setXmlVirtualAccessMethods(virtualAccessMethods);
} else if (!owningType.getXmlVirtualAccessMethods().getGetMethod().equals(jpaAccessor.getGetMethodName())) {
XmlAccessMethods accessMethods = new XmlAccessMethods();
accessMethods.setGetMethod(jpaAccessor.getGetMethodName());
accessMethods.setSetMethod(jpaAccessor.getSetMethodName());
xmlElement.setXmlAccessMethods(accessMethods);
}
}
return objectFactory.createXmlElement(xmlElement);
}
use of org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping in project eclipselink by eclipse-ee4j.
the class NestedForeignKeyProject method getTeamDescriptor.
private EISDescriptor getTeamDescriptor() {
EISDescriptor descriptor = new EISDescriptor();
descriptor.setJavaClass(Team.class);
descriptor.setDataTypeName("team");
descriptor.setPrimaryKeyFieldName("@id");
EISDirectMapping idMapping = new EISDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
descriptor.addMapping(idMapping);
EISCompositeCollectionMapping employeesMapping = new EISCompositeCollectionMapping();
employeesMapping.setAttributeName("employees");
employeesMapping.useCollectionClass(java.util.Vector.class);
employeesMapping.setReferenceClass(Employee.class);
employeesMapping.setXPath("employee");
descriptor.addMapping(employeesMapping);
// Insert
XQueryInteraction insertCall = new XQueryInteraction();
insertCall.setFunctionName("insert");
insertCall.setProperty("fileName", "team.xml");
insertCall.setXQueryString("team");
descriptor.getQueryManager().setInsertCall(insertCall);
// Read object
XQueryInteraction readObjectCall = new XQueryInteraction();
readObjectCall.setFunctionName("read");
readObjectCall.setProperty("fileName", "team.xml");
readObjectCall.setXQueryString("team[@id='#@id']");
readObjectCall.setOutputResultPath("result");
descriptor.getQueryManager().setReadObjectCall(readObjectCall);
// Read all
XQueryInteraction readAllCall = new XQueryInteraction();
readAllCall.setFunctionName("read-all");
readAllCall.setProperty("fileName", "team.xml");
readAllCall.setXQueryString("team");
readAllCall.setOutputResultPath("result");
descriptor.getQueryManager().setReadAllCall(readAllCall);
// Delete
XQueryInteraction deleteCall = new XQueryInteraction();
deleteCall.setFunctionName("delete");
deleteCall.setProperty("fileName", "team.xml");
deleteCall.setXQueryString("team[@id='#@id']");
descriptor.getQueryManager().setDeleteCall(deleteCall);
// Update
XQueryInteraction updateCall = new XQueryInteraction();
updateCall.setFunctionName("update");
updateCall.setProperty("fileName", "team.xml");
updateCall.setXQueryString("team[@id='#@id']");
descriptor.getQueryManager().setUpdateCall(updateCall);
return descriptor;
}
use of org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping in project eclipselink by eclipse-ee4j.
the class OwnedToExternalRootProject method getTeamDescriptor.
private EISDescriptor getTeamDescriptor() {
EISDescriptor descriptor = new EISDescriptor();
descriptor.setJavaClass(Team.class);
descriptor.setDataTypeName("team");
descriptor.setPrimaryKeyFieldName("@id");
EISDirectMapping idMapping = new EISDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
descriptor.addMapping(idMapping);
EISCompositeCollectionMapping employeesMapping = new EISCompositeCollectionMapping();
employeesMapping.setAttributeName("employees");
employeesMapping.useCollectionClass(java.util.Vector.class);
employeesMapping.setReferenceClass(Employee.class);
employeesMapping.setXPath("employee");
descriptor.addMapping(employeesMapping);
// Insert
XQueryInteraction insertCall = new XQueryInteraction();
insertCall.setFunctionName("insert");
insertCall.setProperty("fileName", "team.xml");
insertCall.setXQueryString("team");
descriptor.getQueryManager().setInsertCall(insertCall);
// Read object
XQueryInteraction readObjectCall = new XQueryInteraction();
readObjectCall.setFunctionName("read");
readObjectCall.setProperty("fileName", "team.xml");
readObjectCall.setXQueryString("team[@id='#@id']");
readObjectCall.setOutputResultPath("result");
descriptor.getQueryManager().setReadObjectCall(readObjectCall);
// Read all
XQueryInteraction readAllCall = new XQueryInteraction();
readAllCall.setFunctionName("read-all");
readAllCall.setProperty("fileName", "team.xml");
readAllCall.setXQueryString("team");
readAllCall.setOutputResultPath("result");
descriptor.getQueryManager().setReadAllCall(readAllCall);
// Delete
XQueryInteraction deleteCall = new XQueryInteraction();
deleteCall.setFunctionName("delete");
deleteCall.setProperty("fileName", "team.xml");
deleteCall.setXQueryString("team[@id='#@id']");
descriptor.getQueryManager().setDeleteCall(deleteCall);
// Update
XQueryInteraction updateCall = new XQueryInteraction();
updateCall.setFunctionName("update");
updateCall.setProperty("fileName", "team.xml");
updateCall.setXQueryString("team[@id='#@id']");
descriptor.getQueryManager().setUpdateCall(updateCall);
return descriptor;
}
use of org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping in project eclipselink by eclipse-ee4j.
the class NestedOwnedToExternalRootProject method getCompanyDescriptor.
private EISDescriptor getCompanyDescriptor() {
EISDescriptor descriptor = new EISDescriptor();
descriptor.setJavaClass(Company.class);
descriptor.setDataTypeName("company");
descriptor.setPrimaryKeyFieldName("name/text()");
EISDirectMapping nameMapping = new EISDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setXPath("name/text()");
descriptor.addMapping(nameMapping);
EISCompositeCollectionMapping departmentsMapping = new EISCompositeCollectionMapping();
departmentsMapping.setAttributeName("departments");
departmentsMapping.useCollectionClass(java.util.Vector.class);
departmentsMapping.setReferenceClass(Department.class);
departmentsMapping.setXPath("department");
descriptor.addMapping(departmentsMapping);
// Insert
XQueryInteraction insertCall = new XQueryInteraction();
insertCall.setFunctionName("insert");
insertCall.setProperty("fileName", "company.xml");
insertCall.setXQueryString("company");
descriptor.getQueryManager().setInsertCall(insertCall);
// Read object
XQueryInteraction readObjectCall = new XQueryInteraction();
readObjectCall.setFunctionName("read");
readObjectCall.setProperty("fileName", "company.xml");
readObjectCall.setXQueryString("company[name/text()='#name/text()']");
readObjectCall.setOutputResultPath("result");
descriptor.getQueryManager().setReadObjectCall(readObjectCall);
// Read all
XQueryInteraction readAllCall = new XQueryInteraction();
readAllCall.setFunctionName("read-all");
readAllCall.setProperty("fileName", "company.xml");
readAllCall.setXQueryString("company");
readAllCall.setOutputResultPath("result");
descriptor.getQueryManager().setReadAllCall(readAllCall);
// Delete
XQueryInteraction deleteCall = new XQueryInteraction();
deleteCall.setFunctionName("delete");
deleteCall.setProperty("fileName", "company.xml");
deleteCall.setXQueryString("company[name/text()='#name/text()']");
descriptor.getQueryManager().setDeleteCall(deleteCall);
// Update
XQueryInteraction updateCall = new XQueryInteraction();
updateCall.setFunctionName("update");
updateCall.setProperty("fileName", "company.xml");
updateCall.setXQueryString("company[name/text()='#name/text()']");
descriptor.getQueryManager().setUpdateCall(updateCall);
return descriptor;
}
Aggregations