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


Java Id类代码示例

本文整理汇总了Java中org.mongodb.morphia.annotations.Id的典型用法代码示例。如果您正苦于以下问题:Java Id类的具体用法?Java Id怎么用?Java Id使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: checkRecursivelyHasNoIdAnnotationPresent

import org.mongodb.morphia.annotations.Id; //导入依赖的package包/类
private void checkRecursivelyHasNoIdAnnotationPresent(final Set<Class<?>> classesToInspect,
                                                      final HashSet<Class<?>> alreadyInspectedClasses, final MappedClass mc,
                                                      final Set<ConstraintViolation> ve) {
    for (final Class<?> clazz : classesToInspect) {
        if (alreadyInspectedClasses.contains(clazz)) {
            continue;
        }
        if (hasTypeFieldAnnotation(clazz, Id.class)) {
            ve.add(new ConstraintViolation(Level.FATAL,
                                           mc,
                                           getClass(),
                                           "You cannot use @Id on any field of an Embedded/Property object"));
        }
        alreadyInspectedClasses.add(clazz);
        final Set<Class<?>> extraClassesToInspect = new HashSet<Class<?>>();
        for (final Field field : ReflectionUtils.getDeclaredAndInheritedFields(clazz, true)) {
            if (isFieldToInspect(field)) {
                extraClassesToInspect.add(field.getType());
            }
        }
        checkRecursivelyHasNoIdAnnotationPresent(extraClassesToInspect, alreadyInspectedClasses, mc, ve);
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:24,代码来源:ContainsEmbeddedWithId.java

示例2: check

import org.mongodb.morphia.annotations.Id; //导入依赖的package包/类
@Override
protected void check(final Mapper mapper, final MappedClass mc, final MappedField mf, final Set<ConstraintViolation> ve) {
    if (mf.hasAnnotation(Reference.class)) {
        final Class realType = (mf.isSingleValue()) ? mf.getType() : mf.getSubClass();

        if (realType == null) {
            throw new MappingException("Type is null for this MappedField: " + mf);
        }

        if ((!realType.isInterface() && mapper.getMappedClass(realType).getIdField() == null)) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, mf, getClass(),
                                           mf.getFullName() + " is annotated as a @" + Reference.class.getSimpleName() + " but the "
                                           + mf.getType().getName()
                                           + " class is missing the @" + Id.class.getSimpleName() + " annotation"));
        }
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:18,代码来源:ReferenceToUnidentifiable.java

示例3: check

import org.mongodb.morphia.annotations.Id; //导入依赖的package包/类
@Override
public void check(final Mapper mapper, final MappedClass mc, final Set<ConstraintViolation> ve) {
    final Set<Class<?>> classesToInspect = new HashSet<Class<?>>();
    for (final Field field : ReflectionUtils.getDeclaredAndInheritedFields(mc.getClazz(), true)) {
        if (isFieldToInspect(field) && !field.isAnnotationPresent(Id.class)) {
            classesToInspect.add(field.getType());
        }
    }
    checkRecursivelyHasNoIdAnnotationPresent(classesToInspect, new HashSet<Class<?>>(), mc, ve);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:11,代码来源:ContainsEmbeddedWithId.java

示例4: hasTypeFieldAnnotation

import org.mongodb.morphia.annotations.Id; //导入依赖的package包/类
private boolean hasTypeFieldAnnotation(final Class<?> type, final Class<Id> class1) {
    for (final Field field : ReflectionUtils.getDeclaredAndInheritedFields(type, true)) {
        if (field.getAnnotation(class1) != null) {
            return true;
        }
    }
    return false;
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:9,代码来源:ContainsEmbeddedWithId.java

示例5: check

import org.mongodb.morphia.annotations.Id; //导入依赖的package包/类
@Override
public void check(final Mapper mapper, final MappedClass mc, final Set<ConstraintViolation> ve) {

    final List<MappedField> idFields = mc.getFieldsAnnotatedWith(Id.class);

    if (idFields.size() > 1) {
        ve.add(new ConstraintViolation(Level.FATAL, mc, getClass(),
                                       String.format("More than one @%s Field found (%s).",
                                                     Id.class.getSimpleName(),
                                                     new FieldEnumString(idFields))));
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:13,代码来源:MultipleId.java

示例6: check

import org.mongodb.morphia.annotations.Id; //导入依赖的package包/类
@Override
protected void check(final Mapper mapper, final MappedClass mc, final MappedField mf, final Set<ConstraintViolation> ve) {
    // an @Id field can not be a Value, Reference, or Embedded
    if (mf.hasAnnotation(Id.class)) {
        if (mf.hasAnnotation(Reference.class) || mf.hasAnnotation(Embedded.class) || mf.hasAnnotation(Property.class)) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, mf, getClass(),
                                           mf.getFullName() + " is annotated as @" + Id.class.getSimpleName()
                                           + " and cannot be mixed with other annotations (like @Reference)"));
        }
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:12,代码来源:IdDoesNotMix.java

示例7: update

import org.mongodb.morphia.annotations.Id; //导入依赖的package包/类
/**
 * Update mappings based on fields/annotations.
 */
// TODO: Remove this and make these fields dynamic or auto-set some other way
public void update() {
    embeddedAn = (Embedded) getAnnotation(Embedded.class);
    entityAn = (Entity) getFirstAnnotation(Entity.class);
    // polymorphicAn = (Polymorphic) getAnnotation(Polymorphic.class);
    final List<MappedField> fields = getFieldsAnnotatedWith(Id.class);
    if (fields != null && !fields.isEmpty()) {
        idField = fields.get(0).getField();
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:14,代码来源:MappedClass.java

示例8: isPrimaryKey

import org.mongodb.morphia.annotations.Id; //导入依赖的package包/类
@Override
public boolean isPrimaryKey(String name) {
	PojoAttribute<?> a = model.getAttribute(name);
	if (a == null) return false;
	return a.getAnnotation(Id.class) != null;
}
 
开发者ID:mhus,项目名称:mhus-osgi-tools,代码行数:7,代码来源:MoXdbApi.java

示例9: getMappedIdField

import org.mongodb.morphia.annotations.Id; //导入依赖的package包/类
/**
 * @return the ID field for the class
 */
public MappedField getMappedIdField() {
    List<MappedField> fields = getFieldsAnnotatedWith(Id.class);
    return fields.isEmpty() ? null : fields.get(0);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:8,代码来源:MappedClass.java


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