Пример #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;
  }
Пример #2
0
  private void resolveDoubleFileInconsistency() {
    String file1 = currentFile().getName();
    String file2 = otherFile().getName();

    Log.warn(
        "The database was left in inconsistent state, both files exist!",
        "file1",
        file1,
        "file2",
        file2);

    long modif1, modif2;
    try {
      modif1 = (Long) loadMetadata(new FileInputStream(currentFile())).get(META_TIMESTAMP);
      modif2 = (Long) loadMetadata(new FileInputStream(otherFile())).get(META_TIMESTAMP);
    } catch (FileNotFoundException e) {
      throw new RuntimeException(e);
    }

    U.must(
        modif1 != modif2,
        "Cannot determine which database file to remove, please remove the incorrect file manually!");

    // delete the most recent file, since it wasn't written completely
    File recent = modif1 > modif2 ? currentFile() : otherFile();

    Log.warn(
        "The more recent database file is assumed incomplete, so it will be deleted!",
        "file",
        recent);

    recent.delete();
  }
Пример #3
0
  private RelPair getRelPair(Object entity, Prop prop, String rel, boolean inverse) {

    Class<?> cls = prop.getRawTypeArg(0);
    Class<? extends Object> entCls = Cls.unproxy(entity.getClass());

    Class<?> srcType = inverse ? cls : entCls;
    Class<?> destType = inverse ? entCls : cls;

    Tuple key = new Tuple(rel, srcType, destType);
    RelPair relPair = data.relPairs.get(key);

    Prop srcProp, destProp;

    if (relPair != null) {
      srcProp = relPair.srcProp;
      destProp = relPair.destProp;
    } else {
      String invRel = inverse ? rel : "^" + rel;
      Prop p = findRelProperty(cls, invRel, entCls);
      srcProp = inverse ? p : prop;
      destProp = inverse ? prop : p;

      relPair = new RelPair(rel, srcType, destType, srcProp, destProp);
      data.relPairs.putIfAbsent(key, relPair);

      if (srcType == null || srcProp == null || destType == null || destProp == null) {
        Log.warn("Incomplete relation pair!", "relation", relPair);
      }
    }

    return relPair;
  }