本文整理汇总了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);
}
}
示例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"));
}
}
}
示例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);
}
示例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;
}
示例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))));
}
}
示例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)"));
}
}
}
示例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();
}
}
示例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;
}
示例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);
}