當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。