public DbRef<?> ref(Method method) { String name = method.getName(); DbRef<?> res = refs.get(name); if (res == null) { DbRef<Object> value = DB.ref(proxy, rel(method).value()); DbRef<?> old = refs.putIfAbsent(name, value); return old != null ? old : value; } return res; }
public DbSet<?> set(Method method) { String name = method.getName(); DbSet<?> res = sets.get(name); if (res == null) { DbSet<Object> value = DB.set(proxy, rel(method).value()); DbSet<?> old = sets.putIfAbsent(name, value); return old != null ? old : value; } return res; }
public DbList<?> list(Method method) { String name = method.getName(); DbList<?> res = lists.get(name); if (res == null) { DbList<Object> value = DB.list(proxy, rel(method).value()); DbList<?> old = lists.putIfAbsent(name, value); return old != null ? old : value; } return res; }
public static void initRelations(Object target) { for (Prop prop : Beany.propertiesOf(target.getClass()).select(ANNOTATED_DB_REL_PROPS)) { Rel rel = prop.getAnnotation(Rel.class); U.must(!U.isEmpty(rel.value()), "Relation name must be specified!"); Object value = prop.getRaw(target); if (value == null && !prop.isReadOnly()) { Class<?> type = prop.getType(); if (DbList.class.equals(type)) { prop.setRaw(target, DB.list(target, rel.value())); } else if (DbSet.class.equals(type)) { prop.setRaw(target, DB.set(target, rel.value())); } else if (DbRef.class.equals(type)) { prop.setRaw(target, DB.ref(target, rel.value())); } } } }
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; }
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; }