+ Model.Manager.factoryFor((Class<? extends Model>) field.relationType).keyName(), resolvedIds); } else {
idCache.put(tType.getName() + "-" + id, Model.Manager.factoryFor(cType).keyValue(model)); tType = tType.getSuperclass();
final List<play.db.Model.Property> modelFields = Model.Manager.factoryFor(type).listProperties(); resolvedYml.put("object." + field.name + "." + play.db.Model.Manager.factoryFor((Class<? extends play.db.Model>)field.relationType).keyName(), resolvedIds); } else {
String keyName = Model.Manager.factoryFor(c).keyName(); if (multiple && Collection.class.isAssignableFrom(field.getType())) { Collection l = new ArrayList(); Model.Manager.factoryFor((Class<Model>) Play.classloader.loadClass(relation)).keyType(), null)); try { l.add(q.getSingleResult()); Model.Manager.factoryFor((Class<Model>) Play.classloader.loadClass(relation)).keyType(), null)); try { Object to = q.getSingleResult();
String keyName = Model.Manager.factoryFor(c).keyName(); if (multiple && Collection.class.isAssignableFrom(field.getType())) { Collection l = new ArrayList(); q.filter(keyName, Binder.directBind(rootParamNode.getOriginalKey(), annotations, _id, Model.Manager.factoryFor((Class<Model>) Play.classloader.loadClass(relation)).keyType(), null)); Object to = q.get(); if (to != null) { q.filter(keyName, Binder.directBind(rootParamNode.getOriginalKey(), annotations, ids[0], Model.Manager.factoryFor((Class<Model>) Play.classloader.loadClass(relation)).keyType(), null)); Object to = q.get(); if (to != null) {
idCache.put(tType.getName() + "-" + id, play.db.Model.Manager.factoryFor(cType).keyValue((play.db.Model)model)); tType = tType.getSuperclass();
value = factory.keyValue((Model) value);
@Override @SuppressWarnings("unchecked") public Object bind(String name, @SuppressWarnings("rawtypes") Class clazz, java.lang.reflect.Type type, Annotation[] annotations, Map<String, String[]> params) { if (Model.class.isAssignableFrom(clazz)) { String keyName = modelFactory(clazz).keyName(); String idKey = name + "." + keyName; if (params.containsKey(idKey) && params.get(idKey).length > 0 && params.get(idKey)[0] != null && params.get(idKey)[0].trim().length() > 0) { String id = params.get(idKey)[0]; try { Object o = ds().createQuery(clazz) .filter(keyName, new ObjectId(id)).get(); return Model.edit(o, name, params, annotations); } catch (Exception e) { return null; } } return Model.create(clazz, name, params, annotations); } return super.bind(name, clazz, type, annotations, params); }
protected static <T extends Model> T findById(Class<T> cls, Object id, boolean useFactory, boolean useCache, String expiration) { T e = null; String k = null; if (useCache) { k = cacheKey(cls, id); e = play.cache.Cache.get(k, cls); } if (null == e) { if (useFactory) { e = (T)MorphiaPlugin.MorphiaModelLoader.getFactory(cls).findById(id); } else { e = q(cls).filter("_id", processId_(id)).get(); } } if (useCache && null != e) { play.cache.Cache.set(k, e, expiration); } return e; }
/** * Delete all Model instances for the given types using the underlying persistence mechanisms * * @param types * Types to delete */ public static void delete(Class<? extends Model>... types) { idCache.clear(); disableForeignKeyConstraints(); for (Class<? extends Model> type : types) { try { Model.Manager.factoryFor(type).deleteAll(); } catch (Exception e) { Logger.error(e, "While deleting " + type + " instances"); } } enableForeignKeyConstraints(); Play.pluginCollection.afterFixtureLoad(); }
@Override public Object _key() { return Model.Manager.factoryFor(this.getClass()).keyValue(this); }