本文整理匯總了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);
}