本文整理汇总了Java中org.jongo.Find.as方法的典型用法代码示例。如果您正苦于以下问题:Java Find.as方法的具体用法?Java Find.as怎么用?Java Find.as使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jongo.Find
的用法示例。
在下文中一共展示了Find.as方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findByQuery
import org.jongo.Find; //导入方法依赖的package包/类
@Override
public Iterable<Profile> findByQuery(String query, String sortBy, SortOrder sortOrder, Integer start,
Integer count, String... attributesToReturn) throws MongoDataException {
try {
Find find = getCollection().find(query);
addSort(find, sortBy, sortOrder);
addRange(find, start, count);
addProjection(find, attributesToReturn);
return find.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find profiles by query " + query;
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
示例2: findRange
import org.jongo.Find; //导入方法依赖的package包/类
@Override
public Iterable<Profile> findRange(String tenantName, String sortBy, SortOrder sortOrder, Integer start,
Integer count, String... attributesToReturn) throws MongoDataException {
try {
String query = getQueryFor(KEY_FIND_BY_TENANT_QUERY);
Find find = getCollection().find(query, tenantName);
addSort(find, sortBy, sortOrder);
addRange(find, start, count);
addProjection(find, attributesToReturn);
return find.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find range of profiles for tenant '" + tenantName + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
示例3: findByTenantAndRole
import org.jongo.Find; //导入方法依赖的package包/类
@Override
public Iterable<Profile> findByTenantAndRole(String tenantName, String role, String sortBy, SortOrder sortOrder,
String... attributesToReturn) throws MongoDataException {
try {
String query = getQueryFor(KEY_FIND_BY_TENANT_AND_ROLE_QUERY);
Find find = getCollection().find(query, tenantName, role);
addSort(find, sortBy, sortOrder);
addProjection(find, attributesToReturn);
return find.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find profiles for role '" + role + " and tenant '" + tenantName + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
示例4: findByTenantAndExistingAttribute
import org.jongo.Find; //导入方法依赖的package包/类
@Override
public Iterable<Profile> findByTenantAndExistingAttribute(String tenantName, String attributeName, String sortBy,
SortOrder sortOrder,
String... attributesToReturn) throws MongoDataException {
try {
String query = getQueryFor(KEY_FIND_BY_TENANT_AND_EXISTING_ATTRIB_QUERY);
Find find = getCollection().find(query, tenantName, attributeName);
addSort(find, sortBy, sortOrder);
addProjection(find, attributesToReturn);
return find.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find profiles with attribute " + attributeName + " and tenant '" + tenantName + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
示例5: findByTenantAndAttributeValue
import org.jongo.Find; //导入方法依赖的package包/类
@Override
public Iterable<Profile> findByTenantAndAttributeValue(String tenantName, String attributeName,
String attributeValue, String sortBy, SortOrder sortOrder,
String... attributesToReturn) throws MongoDataException {
try {
String query = getQueryFor(KEY_FIND_BY_TENANT_AND_ATTRIB_VALUE_QUERY);
Find find = getCollection().find(query, tenantName, attributeName, attributeValue);
addSort(find, sortBy, sortOrder);
addProjection(find, attributesToReturn);
return find.as(Profile.class);
} catch (MongoException ex) {
String msg = "Unable to find profiles for attribute " + attributeName + " = " + attributeValue +
" and tenant '" + tenantName + "'";
logger.error(msg, ex);
throw new MongoDataException(msg, ex);
}
}
示例6: selectOne
import org.jongo.Find; //导入方法依赖的package包/类
private void selectOne(){
Jongo jongo = new Jongo(dbconn.getDB(database));
org.jongo.MongoCollection mc = jongo.getCollection(collection);
JSONObject findField = (JSONObject)data.get("findField");
JSONObject sortField = (JSONObject)data.get("sortField");
JSONObject projectionField = (JSONObject)data.get("projectionField");
Find result = null;
if(findField != null){
result = mc.find(findField.toJSONString());
}
if(sortField != null){
result = result.sort(sortField.toString());
}
if(projectionField != null){
result = result.projection(projectionField.toString());
}
String resultJson = "";
org.jongo.MongoCursor cursor = result.as(Object.class);
if(cursor.hasNext()){
resultJson += cursor.next();
}
System.out.println(resultJson);
Response res= new Response(200, resultJson);
try {
res.writeData(client);
}
catch(IOException ioe){
System.out.println("[Error]" + ioe.getMessage());
}
}
示例7: selectMany
import org.jongo.Find; //导入方法依赖的package包/类
private void selectMany(){
Jongo jongo = new Jongo(dbconn.getDB(database));
org.jongo.MongoCollection mc = jongo.getCollection(collection);
JSONObject findField = (JSONObject)data.get("findField");
JSONObject sortField = (JSONObject)data.get("sortField");
JSONObject projectionField = (JSONObject)data.get("projectionField");
Find result = null;
if(findField != null){
result = mc.find(findField.toJSONString());
}
if(sortField != null){
result = result.sort(sortField.toString());
}
if(projectionField != null){
result = result.projection(projectionField.toString());
}
String resultJson = "";
org.jongo.MongoCursor cursor = result.as(Object.class);
while(cursor.hasNext()){
resultJson += cursor.next();
}
System.out.println(resultJson);
Response res= new Response(200, resultJson);
try {
res.writeData(client);
}
catch(IOException ioe){
System.out.println("[Error]" + ioe.getMessage());
}
}