/** * * @param clazz * @param dbObj * @return */ public Object createInstance(final Class clazz, final DBObject dbObj) { if (injectOnConstructor(clazz)) { return this.injector.getInstance(clazz); } return injectMembers(this.delegate.createInstance(clazz, dbObj)); }
/** * Converts a DBObject back to a type-safe java object (POJO) * * @param entityClass The type to return, or use; can be overridden by the @see Mapper.CLASS_NAME_FIELDNAME in the DBObject */ public Object fromDBObject(final Class entityClass, final DBObject dbObject, EntityCache cache) { if (dbObject == null) { Throwable t = new Throwable(); log.error("Somebody passed in a null dbObject; bad client!", t); return null; } Object entity = null; entity = opts.objectFactory.createInstance(entityClass, dbObject); entity = fromDBObject(dbObject, entity, cache); return entity; }
/** * * @param mapr * @param mf * @param dbObj * @return */ public Object createInstance(final Mapper mapr, final MappedField mf, final DBObject dbObj) { final Class clazz = mf.getType(); if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { // there is no good way to find the clazz to use, yet, so delegate return injectMembers(this.delegate.createInstance(mapr, mf, dbObj)); } if (injectOnConstructor(clazz)) { return this.injector.getInstance(clazz); } return injectMembers(this.delegate.createInstance(mapr, mf, dbObj)); }
public TypeConverter addConverter(Class<? extends TypeConverter> clazz) { return addConverter((TypeConverter) this.mapr.getOptions().objectFactory.createInstance(clazz)); }
/** * * @param clazz * @return */ public Object createInstance(final Class clazz) { Assert.parameterNotNull(clazz, "clazz"); if (injectOnConstructor(clazz)) { return this.injector.getInstance(clazz); } return injectMembers(this.delegate.createInstance(clazz)); }
private Object readMapOrCollectionOrEntity(DBObject dbObj, MappedField mf, EntityCache cache, Mapper mapr) { if (Map.class.isAssignableFrom(mf.getSubClass()) || Iterable.class.isAssignableFrom(mf.getSubClass())) { MapOrCollectionMF mocMF = new MapOrCollectionMF((ParameterizedType) mf.getSubType()); mapr.fromDBObject(dbObj, mocMF, cache); return mocMF.getValue(); } else { Object newEntity = mapr.getOptions().objectFactory.createInstance(mapr, mf, dbObj); return mapr.fromDBObject(dbObj, newEntity, cache); } }
private Object getOrCreateInstance(Class<?> clazz) { if (mapr.isCached(clazz)) return mapr.getCachedClass(clazz); Object o = mapr.getOptions().objectFactory.createInstance(clazz); try { mapr.cacheClass(clazz, o); } catch (ConcurrentModificationException duplicate) { if (log.isErrorEnabled()) log.error("Race-condition",duplicate); } return o; }
Object resolveObject(final DBRef dbRef, final MappedField mf, EntityCache cache, Mapper mapr) { if (dbRef == null) return null; Key key = mapr.createKey(mf.isSingleValue() ? mf.getType() : mf.getSubClass(), dbRef.getId()); Object cached = cache.getEntity(key); if (cached != null) return cached; //TODO: if _db is null, set it? DBObject refDbObject = (DBObject) dbRef.fetch(); if (refDbObject != null) { Object refObj = mapr.getOptions().objectFactory.createInstance(mapr, mf, refDbObject); refObj = mapr.fromDBObject(refDbObject, refObj, cache); cache.putEntity(key, refObj); return refObj; } boolean ignoreMissing = mf.getAnnotation(Reference.class) != null && mf.getAnnotation(Reference.class).ignoreMissing(); if (!ignoreMissing) { throw new MappingException("The reference(" + dbRef.toString() + ") could not be fetched for " + mf.getFullName()); } else { return null; } }
refObj = mapr.getConverters().decode(mf.getType(), dbVal, mf); else { refObj = mapr.getOptions().objectFactory.createInstance(mapr, mf, ((DBObject) dbVal)); refObj = mapr.fromDBObject(((DBObject) dbVal), refObj, cache);