Package com.github.jmkgreen.morphia.mapping

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


       print(e);
  }

    @Test(expected=MappingException.class)
    public void getKeyWithNullThrowsException() throws MappingException {
        Mapper mapper = new DefaultMapper();
        Key<Employee> result = mapper.getKey(null);
    }
View Full Code Here


    protected FieldCriteria(QueryImpl<?> query, String field, FilterOperator op, Object value, boolean validateNames, boolean validateTypes, boolean not) {
        StringBuffer sb = new StringBuffer(field); //validate might modify prop string to translate java field name to db field name
        MappedField mf = DefaultMapper.validate(query.getEntityClass(), query.getDatastore().getMapper(), sb, op, value, validateNames, validateTypes);
        field = sb.toString();

        Mapper mapr = 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 = mapr.getMappedClass((mf.isSingleValue()) ? mf.getType() : mf.getSubClass());
                else
                    mc = mapr.getMappedClass(value);
        } catch (Exception e) {
            //Ignore these. It is likely they related to mapping validation that is unimportant for queries (the query will fail/return-empty anyway)
            log.debug("Error during mapping of filter criteria: ", e);
        }

        Object mappedValue = mapr.toMongoObject(mf, mc, value);

        Class<?> type = (mappedValue == null) ? null : mappedValue.getClass();

        //convert single values into lists for $in/$nin
        if (type != null && (op == FilterOperator.IN || op == FilterOperator.NOT_IN) && !type.isArray() && !Iterable.class.isAssignableFrom(type)) {
View Full Code Here

    }

  @Test
  public void testExternalMapping() throws Exception {
    Mapper mapr = morphia.getMapper();
    ExternalMapperExtTest.CloneMapper helper = new CloneMapper(mapr);
    helper.map(Skeleton.class, EntityWithNoAnnotations.class);
    MappedClass mc = mapr.getMappedClass(EntityWithNoAnnotations.class);
    mc.update();
    assertNotNull(mc.getIdField());
    assertNotNull(mc.getEntityAnnotation());
    Assert.assertEquals("special", mc.getEntityAnnotation().value());
View Full Code Here

TOP

Related Classes of com.github.jmkgreen.morphia.mapping.Mapper

Copyright © 2018 www.massapicom. 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.