Examples of RelationshipMapping


Examples of org.chromattic.core.mapping.value.RelationshipMapping

            } else if (jcrMember instanceof JCRNodeAttributeMapping) {
              JCRNodeAttributeMapping nam = (JCRNodeAttributeMapping)jcrMember;
              propertyMappers.add(new JCRNodeAttributePropertyMapper((SingleValuedPropertyInfo<SimpleValueInfo>)pm.getInfo(), nam.getType()));
            }
          } else if (pmvm instanceof RelationshipMapping) {
            RelationshipMapping pmhm = (RelationshipMapping)pmvm;

            //
            if (pmhm.getType() == RelationshipType.HIERARCHIC) {
              if (pmhm instanceof ManyToOneMapping) {
                JCRChildNodePropertyMapper bilto = new JCRAnyChildCollectionPropertyMapper((SingleValuedPropertyInfo<BeanValueInfo>)pm.getInfo());
                relatedProperties.get(pmhm.getRelatedType()).add(bilto);
                propertyMappers.add(bilto);
              } if (pmhm instanceof NamedOneToOneMapping) {
                NamedOneToOneMapping ncpmpm = (NamedOneToOneMapping)pmhm;
                if (ncpmpm.isOwner()) {
                  JCRNamedChildParentPropertyMapper bilto = new JCRNamedChildParentPropertyMapper((SingleValuedPropertyInfo<BeanValueInfo>)pm.getInfo(), ncpmpm.getName());
                  relatedProperties.get(pmhm.getRelatedType()).add(bilto);
                  propertyMappers.add(bilto);
                } else {
                  JCRChildNodePropertyMapper bilto = new JCRNamedChildPropertyMapper((SingleValuedPropertyInfo<BeanValueInfo>)pm.getInfo(), ncpmpm.getName());
                  relatedProperties.get(ncpmpm.getRelatedType()).add(bilto);
                  propertyMappers.add(bilto);
                }
              }
            }
          }

          //
          if (pmvm instanceof ManyToOneMapping) {
            if (pmvm instanceof NamedManyToOneMapping) {
              NamedManyToOneMapping nmtovm = (NamedManyToOneMapping)pmvm;
              LinkType linkType = relationshipToLinkMapping.get(nmtovm.getType());
              if (linkType != null) {
                JCRNamedReferentPropertyMapper blah = new JCRNamedReferentPropertyMapper(
                  (SingleValuedPropertyInfo<BeanValueInfo>)pm.getInfo(),
                  nmtovm.getRelatedName(),
                  linkType
                  );
                propertyMappers.add(blah);
                relatedProperties.get(nmtovm.getRelatedType()).add(blah);
              }
            }
          }
        } else if (pm.getInfo() instanceof MultiValuedPropertyInfo) {
          ValueMapping pmvm = pm.getValueMapping();

          //
          if (pmvm instanceof RelationshipMapping) {
            RelationshipMapping pmhm = (RelationshipMapping)pmvm;

            //
            if (pmhm instanceof OneToManyMapping) {

              //
              if (pmhm instanceof NamedOneToManyMapping) {
                LinkType linkType = relationshipToLinkMapping.get(pmhm.getType());
                if (linkType != null) {
                  NamedOneToManyMapping fff = (NamedOneToManyMapping)pmhm;
                  JCRReferentCollectionPropertyMapper bilto = new JCRReferentCollectionPropertyMapper(
                    (CollectionPropertyInfo<BeanValueInfo>)pm.getInfo(),
                    fff.getName(),
                    linkType);
                  relatedProperties.get(pmhm.getRelatedType()).add(bilto);
                  propertyMappers.add(bilto);
                }
              } else {
                if (pmhm.getType() == RelationshipType.HIERARCHIC) {

                  MultiValuedPropertyInfo<BeanValueInfo> mpi = (MultiValuedPropertyInfo<BeanValueInfo>)pm.getInfo();
                  AnyChildMultiValueMapper valueMapper;
                  if (mpi instanceof MapPropertyInfo) {
                    valueMapper = new AnyChildMultiValueMapper.Map();
                  } else if (mpi instanceof CollectionPropertyInfo) {
                    if (mpi instanceof ListPropertyInfo) {
                      valueMapper = new AnyChildMultiValueMapper.List();
                    } else {
                      valueMapper = new AnyChildMultiValueMapper.Collection();
                    }
                  } else {
                    throw new IllegalStateException();
                  }
                  JCRAnyChildParentPropertyMapper bilto = new JCRAnyChildParentPropertyMapper(mpi, valueMapper);
                  relatedProperties.get(pmhm.getRelatedType()).add(bilto);
                  propertyMappers.add(bilto);
                }
              }
            }
          } else if (pmvm instanceof SimpleMapping) {
View Full Code Here

Examples of org.chromattic.core.mapping.value.RelationshipMapping

          BeanValueInfo bvi = (BeanValueInfo)vi;
          ClassTypeInfo typeInfo = bvi.getTypeInfo();
          OneToOne oneToOneAnn = propertyInfo.getAnnotation(OneToOne.class);

          // The mapped by of a one to one mapping discrimines between the parent and the child
          RelationshipMapping hierarchyMapping;
          MappedBy mappedBy = propertyInfo.getAnnotation(MappedBy.class);
          if (mappedBy != null) {
            hierarchyMapping = new NamedOneToOneMapping(typeInfo, mappedBy.value(), RelationshipType.HIERARCHIC, true);
          } else {
            RelatedMappedBy relatedMappedBy = propertyInfo.getAnnotation(RelatedMappedBy.class);
            if (relatedMappedBy != null) {
              hierarchyMapping = new NamedOneToOneMapping(typeInfo, relatedMappedBy.value(), RelationshipType.HIERARCHIC, false);
            } else {
              throw new IllegalStateException("No related by mapping found for property " + propertyInfo + " when introspecting " + info);
            }
          }
          PropertyMapping<RelationshipMapping> oneToOneMapping = new PropertyMapping<RelationshipMapping>(propertyInfo, hierarchyMapping);
          propertyMappings.add(oneToOneMapping);
        } else {
          throw new IllegalStateException();
        }
      } else {
        throw new IllegalStateException();
      }
    }

    // One to many
    for (PropertyInfo propertyInfo : info.getProperties(OneToMany.class)) {
      OneToMany oneToManyAnn = propertyInfo.getAnnotation(OneToMany.class);
      if (propertyInfo instanceof MultiValuedPropertyInfo) {
        MultiValuedPropertyInfo multiValuedProperty = (MultiValuedPropertyInfo)propertyInfo;

        //
        if (multiValuedProperty instanceof MapPropertyInfo) {
          MapPropertyInfo mapProperty = (MapPropertyInfo)multiValuedProperty;
          if (!(mapProperty.getKeyValue() instanceof SimpleValueInfo)) {
            throw new IllegalStateException("Wrong key value type " + mapProperty.getKeyValue());
          }
          SimpleValueInfo svi = (SimpleValueInfo)mapProperty.getKeyValue();
          if (svi.getSimpleType() != SimpleType.STRING) {
            throw new IllegalStateException();
          }
        }

        //
        ValueInfo beanElementType = multiValuedProperty.getElementValue();
        if (beanElementType instanceof BeanValueInfo) {
          BeanValueInfo bvi = (BeanValueInfo)beanElementType;

          //
          OneToManyMapping mapping;
          RelationshipType type = oneToManyAnn.type();
          if (type == RelationshipType.HIERARCHIC) {
            MappedBy mappedBy = propertyInfo.getAnnotation(MappedBy.class);
            if (mappedBy != null) {
              throw new IllegalStateException();
            }
            mapping = new OneToManyMapping(bvi.getTypeInfo(), RelationshipType.HIERARCHIC);
          } else {
            RelatedMappedBy mappedBy = propertyInfo.getAnnotation(RelatedMappedBy.class);
            if (mappedBy == null) {
              throw new IllegalStateException();
            }
            mapping = new NamedOneToManyMapping(bvi.getTypeInfo(), mappedBy.value(), type);
          }

          //
          PropertyMapping<OneToManyMapping> oneToManyMapping = new PropertyMapping<OneToManyMapping>(propertyInfo, mapping);
          propertyMappings.add(oneToManyMapping);
        }
      }
    }

    // Many to one
    for (PropertyInfo propertyInfo : info.getProperties(ManyToOne.class)) {
      if (propertyInfo instanceof SingleValuedPropertyInfo) {
        SingleValuedPropertyInfo svpi = (SingleValuedPropertyInfo)propertyInfo;
        ValueInfo vi = svpi.getValue();
        if (vi instanceof BeanValueInfo) {
          BeanValueInfo bvi = (BeanValueInfo)vi;

          //
          ManyToOne manyToOneAnn = propertyInfo.getAnnotation(ManyToOne.class);
          RelationshipType type = manyToOneAnn.type();

          //
          if (type == RelationshipType.HIERARCHIC) {
            RelationshipMapping hierarchyMapping = new ManyToOneMapping(bvi.getTypeInfo(), RelationshipType.HIERARCHIC);
            PropertyMapping<RelationshipMapping> manyToOneMapping = new PropertyMapping<RelationshipMapping>(propertyInfo, hierarchyMapping);
            propertyMappings.add(manyToOneMapping);
          } else {
            MappedBy mappedBy = propertyInfo.getAnnotation(MappedBy.class);
            if (mappedBy == null) {
View Full Code Here

Examples of org.nxplanner.domain.RelationshipMapping

    protected void populateManyToOneIds(ActionForm form, DomainObject object) throws IllegalAccessException,
                                                                                   NoSuchMethodException,
            InvocationTargetException {
        Collection mappings = RelationshipMappingRegistry.getInstance().getMappings(object);
        for (Iterator iterator = mappings.iterator(); iterator.hasNext();) {
            RelationshipMapping mapping = (RelationshipMapping) iterator.next();
            mapping.populateAdapter(form, object);
        }
    }
View Full Code Here

Examples of org.nxplanner.domain.RelationshipMapping

    protected void populateManyToOneRelationships(DomainObject object, ActionForm form)
        throws Exception{
        Collection mappings = RelationshipMappingRegistry.getInstance().getMappings(object);
        for (Iterator iterator = mappings.iterator(); iterator.hasNext();) {
            RelationshipMapping mapping = (RelationshipMapping) iterator.next();
            mapping.populateDomainObject(object, form);
        }
    }
View Full Code Here

Examples of org.nxplanner.domain.RelationshipMapping

    protected void populateManyToOneIds(ActionForm form, DomainObject object) throws IllegalAccessException,
                                                                                   NoSuchMethodException,
            InvocationTargetException {
        Collection mappings = RelationshipMappingRegistry.getInstance().getMappings(object);
        for (Iterator iterator = mappings.iterator(); iterator.hasNext();) {
            RelationshipMapping mapping = (RelationshipMapping) iterator.next();
            mapping.populateAdapter(form, object);
        }
    }
View Full Code Here

Examples of org.nxplanner.domain.RelationshipMapping

    protected void populateManyToOneRelationships(DomainObject object, ActionForm form)
        throws Exception{
        Collection mappings = RelationshipMappingRegistry.getInstance().getMappings(object);
        for (Iterator iterator = mappings.iterator(); iterator.hasNext();) {
            RelationshipMapping mapping = (RelationshipMapping) iterator.next();
            mapping.populateDomainObject(object, form);
        }
    }
View Full Code Here

Examples of org.xorm.RelationshipMapping

         (lastColumn, Operator.IN, collectionToIDs((Collection) owner.evaluate(this))));
    return true;
      }

      String field = ((Expression.Member) owner).getName();
      RelationshipMapping rm = mapping.getRelationship(field);
      ClassMapping targetMapping = modelMapping.getClassMapping
    (rm.getSource().getElementClass());
      Selector s = null;
      Selector old = selector;
      if (operand instanceof Expression.Variable) {
    // This field is really the variable, using targetMapping
    selector = new Selector(targetMapping.getTable(),
          null);
      } else if (operand instanceof Expression.Parameter) {
    if (param != null) {
        param = XORM.extractPrimaryKey(JDOHelper.getObjectId(param));
    }
    selector = new Selector
        (rm.getTarget().getColumn().getTable(),
         new SimpleCondition
       (rm.getTarget().getColumn(),
        Operator.EQUAL, param));
    selector.setJoinColumn(rm.getTarget().getColumn());

    // If we have a parameter on a MToN mapping,
    // we can skip the target table
    selector.setJoinColumn(rm.getSource().getColumn());
    old.setCondition
        (new SimpleCondition(mapping.getTable().getPrimaryKey(),
           Operator.CONTAINS, selector));
    return true;
      }
      if (rm.isMToN()) {
    s = new Selector
        (rm.getTarget().getColumn().getTable(),
         new SimpleCondition
       (rm.getTarget().getColumn(),
        Operator.EQUAL,
        selector));
      } else {
    s = selector;
      }
      s.setJoinColumn(rm.getSource().getColumn());
      old.setCondition
    (new SimpleCondition(mapping.getTable().getPrimaryKey(),
             Operator.CONTAINS, s));
      if (operand instanceof Expression.Variable) {
    varToSelector.put(((Expression.Variable) operand).getName(),
          top);
    top = null;
      }
  } else if ("startsWith".equals(name)) {
      selector.setCondition
    (new SimpleCondition(column, Operator.STARTS_WITH,
             param));
  } else if ("endsWith".equals(name)) {
      selector.setCondition
    (new SimpleCondition(column, Operator.ENDS_WITH,
             param));
  } else if ("strstr".equals(name)) {
      selector.setCondition
    (new SimpleCondition(column, Operator.STR_CONTAINS,
             param));
  } else if ("isEmpty".equals(name)) {
      // model.model_id where model_id = model_platform
      //  .model_id where model_id is null
      String field = ((Expression.Member) exp.getOwner()).getName();
      RelationshipMapping rm = mapping.getRelationship(field);
      Selector s = new Selector
    (rm.getSource().getColumn().getTable(),
     new SimpleCondition(rm.getSource().getColumn(),
             Operator.EQUAL, null));
      s.setJoinColumn(rm.getSource().getColumn());
      s.setOuterJoin(true);
      selector.setCondition(new SimpleCondition
          (selector.getTable().getPrimaryKey(),
           Operator.CONTAINS, s));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.