本文整理汇总了Java中org.springframework.data.mongodb.core.index.CompoundIndex类的典型用法代码示例。如果您正苦于以下问题:Java CompoundIndex类的具体用法?Java CompoundIndex怎么用?Java CompoundIndex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompoundIndex类属于org.springframework.data.mongodb.core.index包,在下文中一共展示了CompoundIndex类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCriteria
import org.springframework.data.mongodb.core.index.CompoundIndex; //导入依赖的package包/类
/**
* 使用唯一索引且有数值的属性作为检索条件
*
* @return
* @throws JSONException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws NoSuchMethodException
* @throws InvocationTargetException
*/
public static <T extends AbstractNaviBaseDto> Criteria buildCriteria(T dto)
throws JSONException, InstantiationException,
IllegalAccessException, ClassNotFoundException, SecurityException,
IllegalArgumentException, NoSuchMethodException,
InvocationTargetException {
CompoundIndexes compIndexes = dto.getClass().getAnnotation(CompoundIndexes.class);
AbstractNaviBaseDto initDto = (AbstractNaviBaseDto) Class.forName(
dto.getClass().getName(), true, dto.getClass().getClassLoader()
).newInstance();
Criteria c = null;
for (CompoundIndex compIndex : compIndexes.value()) {
if (!compIndex.unique()) {
continue;
}
JSONObject fields = JSON.parseObject(compIndex.def());
for (String fnm : fields.keySet()) {
Object conditionValue = dto.getValue(fnm);
if (conditionValue == null || conditionValue.equals(initDto.getValue(fnm))) {
break;
}
if (c == null) {
c = new Criteria();
}
c.and(fnm).is(conditionValue);
}
if (c != null) {
return c;
}
}
return c;
}