当前位置: 首页>>代码示例>>Java>>正文


Java Mapper.getMappedClass方法代码示例

本文整理汇总了Java中org.mongodb.morphia.mapping.Mapper.getMappedClass方法的典型用法代码示例。如果您正苦于以下问题:Java Mapper.getMappedClass方法的具体用法?Java Mapper.getMappedClass怎么用?Java Mapper.getMappedClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mongodb.morphia.mapping.Mapper的用法示例。


在下文中一共展示了Mapper.getMappedClass方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prePersist

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Override
public void prePersist(final Object entity, final DBObject dbObj, final Mapper mapper) {
  MappedClass mclass = mapper.getMappedClass(entity);
  Field id = mclass.getIdField();
  if (id != null && id.getAnnotation(GeneratedValue.class) != null) {
    try {
      id.setAccessible(true);
      final String collName = gen.value(mclass.getClazz());
      final Query<StoredId> q = db.find(StoredId.class, "_id", collName);
      final UpdateOperations<StoredId> uOps = db.createUpdateOperations(StoredId.class)
          .inc("value");
      StoredId newId = db.findAndModify(q, uOps);
      if (newId == null) {
        newId = new StoredId(collName);
        db.save(newId);
      }
      id.set(entity, newId.value);
    } catch (Exception ex) {
      throw new IllegalStateException("Can't generate ID on " + mclass, ex);
    }
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:23,代码来源:AutoIncID.java

示例2: maps

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Test
public void maps() {
    getMorphia().map(Student.class, Article.class);
    Mapper mapper = getMorphia().getMapper();
    MappedClass mappedClass = mapper.getMappedClass(Student.class);

    PathTarget pathTarget = new PathTarget(mapper, mappedClass, "grades.$.data.name");
    Assert.assertEquals("grades.$.d.name", pathTarget.translatedPath());
    Assert.assertEquals(mapper.getMappedClass(Grade.class).getMappedFieldByJavaField("data"), pathTarget.getTarget());

    pathTarget = new PathTarget(mapper, mappedClass, "grades.$.d.name");
    Assert.assertEquals("grades.$.d.name", pathTarget.translatedPath());
    Assert.assertEquals(mapper.getMappedClass(Grade.class).getMappedField("d"), pathTarget.getTarget());

    pathTarget = new PathTarget(mapper, mapper.getMappedClass(Article.class), "translations");
    Assert.assertEquals("translations", pathTarget.translatedPath());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:18,代码来源:PathTargetTest.java

示例3: testExternalMapping

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Test
public void testExternalMapping() throws Exception {
    final Mapper mapper = getMorphia().getMapper();
    final CloneMapper helper = new CloneMapper(mapper);
    helper.map(Skeleton.class, EntityWithNoAnnotations.class);
    final MappedClass mc = mapper.getMappedClass(EntityWithNoAnnotations.class);
    mc.update();
    assertNotNull(mc.getIdField());
    assertNotNull(mc.getEntityAnnotation());
    assertEquals("special", mc.getEntityAnnotation().value());

    EntityWithNoAnnotations ent = new EntityWithNoAnnotations();
    ent.id = "test";
    final Key<EntityWithNoAnnotations> k = getDs().save(ent);
    assertNotNull(k);
    ent = getDs().get(EntityWithNoAnnotations.class, "test");
    assertNotNull(ent);
    assertEquals("test", ent.id);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:20,代码来源:ExternalMapperExtTest.java

示例4: simpleResolution

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Test
public void simpleResolution() {
    getMorphia().map(ParentType.class, EmbeddedType.class);
    Mapper mapper = getMorphia().getMapper();
    MappedClass mappedClass = mapper.getMappedClass(ParentType.class);

    PathTarget pathTarget = new PathTarget(mapper, mappedClass, "name");
    Assert.assertEquals("n", pathTarget.translatedPath());
    Assert.assertEquals(mappedClass.getMappedFieldByJavaField("name"), pathTarget.getTarget());

    pathTarget = new PathTarget(mapper, mappedClass, "n");
    Assert.assertEquals("n", pathTarget.translatedPath());
    Assert.assertEquals(mappedClass.getMappedField("n"), pathTarget.getTarget());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:15,代码来源:PathTargetTest.java

示例5: dottedPath

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Test
public void dottedPath() {
    getMorphia().map(ParentType.class, EmbeddedType.class);
    Mapper mapper = getMorphia().getMapper();

    PathTarget pathTarget = new PathTarget(mapper, mapper.getMappedClass(ParentType.class), "embedded.number");
    Assert.assertEquals("embedded.number", pathTarget.translatedPath());
    Assert.assertEquals(mapper.getMappedClass(EmbeddedType.class).getMappedFieldByJavaField("number"), pathTarget.getTarget());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:10,代码来源:PathTargetTest.java

示例6: subClasses

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Test
public void subClasses() {
    getMorphia().map(ParentType.class, EmbeddedType.class, EmbeddedSubtype.class);
    Mapper mapper = getMorphia().getMapper();

    PathTarget pathTarget = new PathTarget(mapper, mapper.getMappedClass(ParentType.class), "embedded.flag");
    Assert.assertEquals("embedded.flag", pathTarget.translatedPath());
    Assert.assertEquals(mapper.getMappedClass(EmbeddedSubtype.class).getMappedFieldByJavaField("flag"), pathTarget.getTarget());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:10,代码来源:PathTargetTest.java

示例7: arrays

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Test
public void arrays() {
    getMorphia().map(EntityWithListsAndArrays.class, EmbeddedType.class, Student.class);
    Mapper mapper = getMorphia().getMapper();
    MappedClass mappedClass = mapper.getMappedClass(EntityWithListsAndArrays.class);

    PathTarget pathTarget = new PathTarget(mapper, mappedClass, "listEmbeddedType.1.number");
    Assert.assertEquals("listEmbeddedType.1.number", pathTarget.translatedPath());
    Assert.assertEquals(mapper.getMappedClass(EmbeddedType.class).getMappedFieldByJavaField("number"), pathTarget.getTarget());

    assertEquals("listEmbeddedType.$", new PathTarget(mapper, mappedClass, "listEmbeddedType.$").translatedPath());
    assertEquals("listEmbeddedType.1", new PathTarget(mapper, mappedClass, "listEmbeddedType.1").translatedPath());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:14,代码来源:PathTargetTest.java

示例8: interfaces

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Test
public void interfaces() {
    getMorphia().map(WithNested.class, Nested.class, NestedImpl.class, AnotherNested.class);
    Mapper mapper = getMorphia().getMapper();
    MappedClass mappedClass = mapper.getMappedClass(WithNested.class);

    PathTarget pathTarget = new PathTarget(mapper, mappedClass, "nested.value");
    Assert.assertEquals("nested.value", pathTarget.translatedPath());
    Assert.assertEquals(mapper.getMappedClass(AnotherNested.class).getMappedFieldByJavaField("value"), pathTarget.getTarget());

    pathTarget = new PathTarget(mapper, mappedClass, "nested.field");
    Assert.assertEquals("nested.field", pathTarget.translatedPath());
    Assert.assertEquals(mapper.getMappedClass(NestedImpl.class).getMappedFieldByJavaField("field"), pathTarget.getTarget());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:15,代码来源:PathTargetTest.java

示例9: disableValidation

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Test
public void disableValidation() {
    getMorphia().map(WithNested.class, Nested.class, NestedImpl.class, AnotherNested.class);
    Mapper mapper = getMorphia().getMapper();
    MappedClass mappedClass = mapper.getMappedClass(WithNested.class);

    final PathTarget pathTarget = new PathTarget(mapper, mappedClass, "nested.field.fail");
    pathTarget.disableValidation();
    Assert.assertEquals("nested.field.fail", pathTarget.translatedPath());
    Assert.assertNull(pathTarget.getTarget());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:12,代码来源:PathTargetTest.java

示例10: prePersist

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Override
public void prePersist(final Object ent, final DBObject dbObj, final Mapper mapper) {
    final MappedClass mc = mapper.getMappedClass(ent);
    final List<MappedField> fieldsToTest = mc.getFieldsAnnotatedWith(NonNull.class);
    for (final MappedField mf : fieldsToTest) {
        if (mf.getFieldValue(ent) == null) {
            throw new NonNullValidationException(mf);
        }
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:11,代码来源:TestSimpleValidationViaInterceptor.java

示例11: prePersist

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@Override
public void prePersist(final Object ent, final DBObject dbObj, final Mapper mapper) {
    final MappedClass mc = mapper.getMappedClass(ent);
    final List<MappedField> toLowercase = mc.getFieldsAnnotatedWith(Lowercase.class);
    for (final MappedField mf : toLowercase) {
        try {
            final Object fieldValue = mf.getFieldValue(ent);
            dbObj.put(mf.getNameToStore() + "_lowercase", fieldValue.toString().toLowerCase());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:14,代码来源:NewAnnotationTest.java

示例12: FieldCriteria

import org.mongodb.morphia.mapping.Mapper; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
FieldCriteria(final QueryImpl<?> query, final String fieldName, final FilterOperator op, final Object value, final boolean not) {
    //validate might modify prop string to translate java field name to db field name
    final StringBuilder sb = new StringBuilder(fieldName);
    final Mapper mapper = query.getDatastore().getMapper();
    final MappedField mf = validateQuery(query.getEntityClass(),
                                         mapper,
                                         sb,
                                         op,
                                         value,
                                         query.isValidatingNames(),
                                         query.isValidatingTypes());


    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());
            } else {
                mc = mapper.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 = mapper.toMongoObject(mf, mc, value);

    final 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)) {
        mappedValue = Collections.singletonList(mappedValue);
    }

    if (value != null && type == null && (op == FilterOperator.IN || op == FilterOperator.NOT_IN)
        && Iterable.class.isAssignableFrom(value.getClass())) {
        mappedValue = Collections.emptyList();
    }

    this.field = sb.toString();
    this.operator = op;
    this.value = mappedValue;
    this.not = not;
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:51,代码来源:FieldCriteria.java


注:本文中的org.mongodb.morphia.mapping.Mapper.getMappedClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。