org.springframework.data.mongodb.core.index.Indexed Java Examples

The following examples show how to use org.springframework.data.mongodb.core.index.Indexed. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoMetadata.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
/**
 * 构造方法
 * 
 * @param metadata
 */
MongoMetadata(Class<?> clazz) {
    Document document = clazz.getAnnotation(Document.class);
    if (document == null) {
        throw new IllegalArgumentException();
    }
    ormName = document.collection();
    if (StringUtility.isBlank(ormName)) {
        ormName = clazz.getSimpleName();
        ormName = ormName.substring(0, 1).toLowerCase() + ormName.substring(1, ormName.length());
    }
    ormClass = clazz;
    ReflectionUtility.doWithFields(ormClass, (field) -> {
        if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) {
            return;
        }
        if (field.isAnnotationPresent(Version.class)) {
            versionName = field.getName();
            return;
        }
        Class<?> type = field.getType();
        fields.put(field.getName(), type);
        if (field.isAnnotationPresent(Id.class)) {
            primaryName = field.getName();
            primaryClass = type;
        }
        if (field.isAnnotationPresent(Indexed.class)) {
            indexNames.add(field.getName());
        }
    });
}