Exemplo n.º 1
1
  private Prop findRelProperty(Class<?> fromCls, String rel, Class<?> toCls) {
    Object entity = !fromCls.isInterface() ? data.constructor.create(fromCls) : null;

    for (Prop prop : Beany.propertiesOf(fromCls).select(data.relPropSelector)) {

      String relName = null;

      if (!fromCls.isInterface()) {
        Object value = prop.getRaw(entity);
        if (hasEntityLinks(value)) {
          EntityLinks links = entityLinks(value);
          relName = links.relationName();
        }
      } else {
        Rel relation = prop.getAnnotation(Rel.class);
        if (relation != null) {
          relName = relation.value();
        }
      }

      if (relName != null && relName.equals(rel)) {
        if (prop.getRawTypeArg(0).equals(toCls)) {
          return prop;
        }
      }
    }

    Log.warn(
        "Didn't find inverse relation property!", "relation", rel, "from", fromCls, "to", toCls);
    return null;
  }
Exemplo n.º 2
0
 private void relUnlink(String relation, Prop srcProp, long fromId, Prop destProp, long toId) {
   if (srcProp != null && destProp != null) {
     Object from = get_(fromId, true);
     EntityLinks srcRels = entityLinks(srcProp.getRaw(from));
     srcRels.removeRelTo(toId);
     update_(fromId, from, false, false);
   }
 }
Exemplo n.º 3
0
  private void deleteRelsFor(Object entity) {
    for (Prop prop : Beany.propertiesOf(entity).select(data.relPropSelector)) {
      Object value = prop.getRaw(entity);

      if (hasEntityLinks(value)) {
        EntityLinks links = entityLinks(value);
        long fromId = links.fromId();
        propageteRelChanges(entity, prop, links, fromId, null, links.allRelIds());
      }
    }
  }