Examples of MappedField


Examples of org.mongodb.morphia.mapping.MappedField

    @Test
    public void shouldNotAllowStringValueWithTypeThatIsNotString() {
        // expect
        MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
        MappedField mappedField = mappedClass.getMappedField("name");
        assertThat(QueryValidator.isCompatibleForOperator(mappedField, Integer.class, EQUAL, "value", new ArrayList<ValidationFailure>()),
                   is(false));
    }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedField

    @Test
    public void shouldNotAllowValueWithoutEntityAnnotationAndTypeOfKey() {
        // expect
        MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
        MappedField mappedField = mappedClass.getMappedField("name");
        assertThat(QueryValidator.isCompatibleForOperator(mappedField, Key.class, EQUAL, "value", new ArrayList<ValidationFailure>()),
                   is(false));
    }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedField

    @Test
    public void shouldAllowTypeThatMatchesKeyTypeValue() {
        // expect
        MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
        MappedField mappedField = mappedClass.getMappedField("integer");
        assertThat(QueryValidator.isCompatibleForOperator(mappedField, Integer.class, EQUAL,
                                                          new Key<Number>(Integer.class, new ObjectId()),
                                                          new ArrayList<ValidationFailure>()), is(true));
    }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedField

    @Test
    public void shouldNotAllowTypeThatDoesNotMatchKeyTypeValue() {
        // expect
        MappedClass mappedClass = new MappedClass(SimpleEntity.class, new Mapper());
        MappedField mappedField = mappedClass.getMappedField("name");
        assertThat(QueryValidator.isCompatibleForOperator(mappedField, String.class, EQUAL,
                                                          new Key<Number>(Integer.class, new ObjectId()),
                                                          new ArrayList<ValidationFailure>()), is(false));
    }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedField

    @Test
    public void shouldNotAllowNonKeyTypeWithKeyValue() {
        // expect
        MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
        MappedField mappedField = mappedClass.getMappedField("listOfIntegers");
        assertThat(QueryValidator.isCompatibleForOperator(mappedField, SimpleEntity.class, EQUAL, new Key<String>("kind", new ObjectId()),
                                                          new ArrayList<ValidationFailure>()), is(false));
    }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedField

        getDs().merge(a);
    }

    @Test
    public void testVersionFieldNameContribution() throws Exception {
        final MappedField mappedFieldByJavaField = getMorphia().getMapper().getMappedClass(ALong.class).getMappedFieldByJavaField("v");
        Assert.assertEquals("versionNameContributedByAnnotation", mappedFieldByJavaField.getNameToStore());
    }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedField

        WriteResult wr;
        if (mc.getFieldsAnnotatedWith(Version.class).isEmpty()) {
            return null;
        }

        final MappedField mfVersion = mc.getFieldsAnnotatedWith(Version.class).get(0);
        final String versionKeyName = mfVersion.getNameToStore();

        Long oldVersion = (Long) mfVersion.getFieldValue(entity);
        long newVersion = nextValue(oldVersion);

        dbObj.put(versionKeyName, newVersion);
        mfVersion.setFieldValue(entity, newVersion);

        if (idValue != null && newVersion != 1) {
            final UpdateResults res = update(find(dbColl.getName(), entity.getClass()).filter(Mapper.ID_KEY, idValue)
                                                                                      .filter(versionKeyName, oldVersion),
                                             dbObj,
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedField

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

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

        return update(q, ops);
    }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedField

        final DatastoreImpl dsi = (DatastoreImpl) getDs();
        for (final MappedClass mc : dsi.getMapper().getMappedClasses()) {
            final IgnoreFields ignores = (IgnoreFields) mc.getAnnotation(IgnoreFields.class);
            if (ignores != null) {
                for (final String field : ignores.value().split(",")) {
                    final MappedField mf = mc.getMappedFieldByJavaField(field);
                    mc.getPersistenceFields().remove(mf);
                }
            }
        }
    }
View Full Code Here

Examples of org.mongodb.morphia.mapping.MappedField

                }
            }
            //copy the fields.
            for (final MappedField mf : sourceMC.getPersistenceFields()) {
                final Map<Class<? extends Annotation>, Annotation> annMap = mf.getAnnotations();
                final MappedField destMF = destMC.getMappedFieldByJavaField(mf.getJavaFieldName());
                if (destMF != null && annMap != null && !annMap.isEmpty()) {
                    for (final Entry<Class<? extends Annotation>, Annotation> e : annMap.entrySet()) {
                        destMF.addAnnotation(e.getKey(), e.getValue());
                    }
                }
            }

        }
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.