Examples of MappedClass


Examples of com.github.jmkgreen.morphia.mapping.MappedClass

    private <T> Iterable<Key<T>> insert(DBCollection dbColl, Iterable<T> entities, WriteConcern wc) {
        ArrayList<DBObject> ents = entities instanceof List ? new ArrayList<DBObject>(((List<T>) entities).size()) : new ArrayList<DBObject>();

        Map<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>();
        for (T ent : entities) {
            MappedClass mc = mapr.getMappedClass(ent);
            if (mc.getAnnotation(NotSaved.class) != null)
                throw new MappingException("Entity type: " + mc.getClazz().getName() + " is marked as NotSaved which means you should not try to save it!");
            ents.add(entityToDBObj(ent, involvedObjects));
        }

        WriteResult wr = null;
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.MappedClass

     * @param wc
     * @param <T>
     * @return
     */
    protected <T> Key<T> save(DBCollection dbColl, T entity, WriteConcern wc) {
        MappedClass mc = mapr.getMappedClass(entity);
        if (mc.getAnnotation(NotSaved.class) != null)
            throw new MappingException("Entity type: " + mc.getClazz().getName() + " is marked as NotSaved which means you should not try to save it!");

        WriteResult wr = null;

        //involvedObjects is used not only as a cache but also as a list of what needs to be called for life-cycle methods at the end.
        LinkedHashMap<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>();
        DBObject dbObj = entityToDBObj(entity, involvedObjects);

        //try to do an update if there is a @Version field
        if (mc.hasVersioning()) {
            wr = tryVersionedUpdate(dbColl, entity, dbObj, wc, db, mc);
        } else {
            if (wc == null)
                wr = dbColl.save(dbObj);
            else
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.MappedClass

     */
    public <T> UpdateResults<T> update(T ent, UpdateOperations<T> ops) {
        if (ent instanceof Query)
            return update((Query<T>) ent, ops);

        MappedClass mc = mapr.getMappedClass(ent);
        Query<T> q = (Query<T>) createQuery(mc.getClazz());
        q.disableValidation().filter(Mapper.ID_KEY, mapr.getId(ent));

        if (mc.getFieldsAnnotatedWith(Version.class).size() > 0) {
            MappedField versionMF = mc.getFieldsAnnotatedWith(Version.class).get(0);
            Long oldVer = (Long) versionMF.getFieldValue(ent);
            q.filter(versionMF.getNameToStore(), oldVer);
            ops.set(versionMF.getNameToStore(), VersionHelper.nextValue(oldVer));
        }

View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.MappedClass

        //remove (immutable) _id field for update.
        dbObj.removeField(Mapper.ID_KEY);

        WriteResult wr = null;

        MappedClass mc = mapr.getMappedClass(entity);
        DBCollection dbColl = getCollection(entity);

        //try to do an update if there is a @Version field
        if (mc.hasVersioning()) {
            wr = tryVersionedUpdate(dbColl, entity, dbObj, wc, db, mc);
        } else {
            Query<T> query = (Query<T>) createQuery(entity.getClass()).filter(Mapper.ID_KEY, id);
            wr = update(query, new BasicDBObject("$set", dbObj), false, false, wc).getWriteResult();
        }
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.MappedClass

        //call PostPersist on all involved entities (including the entity)
        for (Map.Entry<Object, DBObject> e : involvedObjects.entrySet()) {
            Object ent = e.getKey();
            DBObject dbO = e.getValue();
            MappedClass mc = mapr.getMappedClass(ent);
            mc.callLifecycleMethods(PostPersist.class, ent, dbO, mapr);
        }
    }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedClass

            final String[] parts = prop.split("\\.");
            if (clazz == null) {
                return null;
            }

            MappedClass mc = mapper.getMappedClass(clazz);
            //CHECKSTYLE:OFF
            for (int i = 0; ; ) {
                //CHECKSTYLE:ON
                final String part = parts[i];
                mf = mc.getMappedField(part);

                //translate from java field name to stored field name
                if (mf == null) {
                    mf = mc.getMappedFieldByJavaField(part);
                    if (mf == null) {
                        throw new ValidationException(format("The field '%s' could not be found in '%s' while validating - %s; if "
                                                             + "you wish to continue please disable validation.", part,
                                                             clazz.getName(), prop
                                                            ));
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedClass

        this.clazz = clazz;
        this.ds = ((DatastoreImpl) ds);
        dbColl = coll;
        cache = this.ds.getMapper().createEntityCache();

        final MappedClass mc = this.ds.getMapper().getMappedClass(clazz);
        final Entity entAn = mc == null ? null : mc.getEntityAnnotation();
        if (entAn != null) {
            readPref = this.ds.getMapper().getMappedClass(clazz).getEntityAnnotation().queryNonPrimary()
                       ? ReadPreference.secondaryPreferred()
                       : null;
        }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedClass

        fields = list;
        return this;
    }

    public Query<T> retrieveKnownFields() {
        final MappedClass mc = ds.getMapper().getMappedClass(clazz);
        final List<String> fields = new ArrayList<String>(mc.getPersistenceFields().size() + 1);
        for (final MappedField mf : mc.getPersistenceFields()) {
            fields.add(mf.getNameToStore());
        }
        retrievedFields(true, fields.toArray(new String[fields.size()]));
        return this;
    }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedClass

                                             validateNames,
                                             validateTypes);

        final Mapper mapper = query.getDatastore().getMapper();

        MappedClass mc = null;
        try {
            if (value != null && !ReflectionUtils.isPropertyType(value.getClass())
                && !ReflectionUtils.implementsInterface(value.getClass(), Iterable.class)) {
                if (mf != null && !mf.isTypeMongoCompatible()) {
                    mc = mapper.getMappedClass((mf.isSingleValue()) ? mf.getType() : mf.getSubClass());
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedClass

     * @return true if the validation was applied.
     */
    public boolean apply(final Mapper mapper, final Class<?> type, final Object value, final List<ValidationFailure> validationFailures) {
        if (appliesTo(mapper, type)) {
            Class<?> classOfValue = value.getClass();
            MappedClass mappedClassForType = mapper.getMappedClass(type);
            Class classOfIdFieldForType = mappedClassForType.getMappedIdField().getConcreteType();
            if (!type.equals(value.getClass()) && !classOfValue.equals(classOfIdFieldForType)) {
                validationFailures.add(new ValidationFailure(format("The value class needs to match the type of ID for the field. "
                                                                    + "Value was %s and was a %s and the ID of the type was %s",
                                                                    value, classOfValue, classOfIdFieldForType
                                                                   )));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.