当前位置: 首页>>代码示例>>Java>>正文


Java Find类代码示例

本文整理汇总了Java中org.jongo.Find的典型用法代码示例。如果您正苦于以下问题:Java Find类的具体用法?Java Find怎么用?Java Find使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Find类属于org.jongo包,在下文中一共展示了Find类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
    }
}
 
开发者ID:craftercms,项目名称:profile,代码行数:18,代码来源:ProfileRepositoryImpl.java

示例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);
    }
}
 
开发者ID:craftercms,项目名称:profile,代码行数:19,代码来源:ProfileRepositoryImpl.java

示例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);
    }
}
 
开发者ID:craftercms,项目名称:profile,代码行数:18,代码来源:ProfileRepositoryImpl.java

示例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);
    }
}
 
开发者ID:craftercms,项目名称:profile,代码行数:19,代码来源:ProfileRepositoryImpl.java

示例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);
    }
}
 
开发者ID:craftercms,项目名称:profile,代码行数:20,代码来源:ProfileRepositoryImpl.java

示例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());
        }
    }
 
开发者ID:aninditamondal,项目名称:FireAnt,代码行数:33,代码来源:MongoHandler.java

示例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());
    }
}
 
开发者ID:aninditamondal,项目名称:FireAnt,代码行数:32,代码来源:MongoHandler.java

示例8: _updateByCriteria

import org.jongo.Find; //导入依赖的package包/类
@Override
public int _updateByCriteria(Table table) {
	Map<String, Object> coditon = new HashMap<String, Object>();
	try {
        QueryCriteria queryCriteria = table.getQueryCriteria();
        DB db = database.getDB();
        Jongo jongo = new Jongo(db);
		for(Criteria criteria:queryCriteria.getOredCriteria()){
			for(Criterion criterion:criteria.getAllCriteria()){
				coditon = buildCriteria(criterion, coditon);
			}
		}
		Find find = jongo.getCollection(queryCriteria.getTable()).find(JsonUtils.objToJson(coditon));
	    Iterator<Map> iterator = find.as(Map.class).iterator();  
		while (iterator.hasNext()) {
			Map<String, Object> map = iterator.next();
			if (null != map) {
				Iterator<String> iter = table.getParams().keySet().iterator();
				while (iter.hasNext()) {
					String key = iter.next();
					if (map.containsKey(key) && !"_id".equals(key)) {
						map.put(key, table.getParams().get(key));
					}
				}
			}
			jongo.getCollection(table.getTableName()).save(map);
		}
	} catch (MongoException e) {
		LOG.error("mongo update error", e);
	}
	return 1;
}
 
开发者ID:uncodecn,项目名称:uncode-dal-all,代码行数:33,代码来源:MongoDAL.java

示例9: _deleteByCriteria

import org.jongo.Find; //导入依赖的package包/类
@Override
public int _deleteByCriteria(Table table) {
	Map<String, Object> coditon = new HashMap<String, Object>();
	try {
        QueryCriteria queryCriteria = table.getQueryCriteria();
        DB db = database.getDB();
        Jongo jongo = new Jongo(db);
		for(Criteria criteria:queryCriteria.getOredCriteria()){
			for(Criterion criterion:criteria.getAllCriteria()){
				coditon = buildCriteria(criterion, coditon);
			}
		}
		Find find = jongo.getCollection(queryCriteria.getTable()).find(JsonUtils.objToJson(coditon));
	    Iterator<Map> iterator = find.as(Map.class).iterator();  
		while (iterator.hasNext()) {
			Map<String, Object> map = iterator.next();
			if (null != map) {
				if(map.containsKey("_id")){
					jongo.getCollection(table.getTableName()).remove(new ObjectId(String.valueOf(map.get("_id"))));
				}
			}
		}
	} catch (MongoException e) {
		LOG.error("mongo delete error", e);
	}
	return 1;
}
 
开发者ID:uncodecn,项目名称:uncode-dal-all,代码行数:28,代码来源:MongoDAL.java

示例10: addSort

import org.jongo.Find; //导入依赖的package包/类
protected Find addSort(Find find, String sortBy, SortOrder sortOrder) {
    if (StringUtils.isNotEmpty(sortBy)) {
        find = find.sort("{" + sortBy + ": " + (sortOrder == SortOrder.ASC? "1": "-1") + "}");
    }

    return find;
}
 
开发者ID:craftercms,项目名称:profile,代码行数:8,代码来源:ProfileRepositoryImpl.java

示例11: addRange

import org.jongo.Find; //导入依赖的package包/类
protected Find addRange(Find find, Integer start, Integer count) {
    if (start != null) {
        find = find.skip(start);

        if (count != null) {
            find = find.limit(count);
        }
    }

    return find;
}
 
开发者ID:craftercms,项目名称:profile,代码行数:12,代码来源:ProfileRepositoryImpl.java

示例12: addProjection

import org.jongo.Find; //导入依赖的package包/类
protected Find addProjection(Find find, String... attributesToReturn) {
    if (ArrayUtils.isNotEmpty(attributesToReturn)) {
        find = find.projection(buildProjectionWithAttributes(attributesToReturn));
    }

    return find;
}
 
开发者ID:craftercms,项目名称:profile,代码行数:8,代码来源:ProfileRepositoryImpl.java

示例13: createFind

import org.jongo.Find; //导入依赖的package包/类
private Find createFind(String query, String sort, String projection, Object... params) {
	Find find = this.collection.find(query, params);
	if ((sort != null) && !sort.isEmpty()) {
		find.sort(sort);
	}
	if ((projection != null) && !projection.isEmpty()) {
		find.projection(projection);
	}
	return find;
}
 
开发者ID:taimos,项目名称:spring-dao-mongo,代码行数:11,代码来源:AbstractMongoDAO.java

示例14: findFirstByQuery

import org.jongo.Find; //导入依赖的package包/类
/**
 * queries with the given string, sorts the result and returns the first element. <code>null</code> is returned if no element is found.
 * 
 * @param query the query string
 * @param sort the sort string
 * @param params the parameters to replace # symbols
 * @return the first element found or <code>null</code> if none is found
 */
protected final T findFirstByQuery(String query, String sort, Object... params) {
	Find find = this.collection.find(query, params);
	if ((sort != null) && !sort.isEmpty()) {
		find.sort(sort);
	}
	Iterable<T> as = find.limit(1).as(this.getEntityClass());
	Iterator<T> iterator = as.iterator();
	if (iterator.hasNext()) {
		return iterator.next();
	}
	return null;
}
 
开发者ID:taimos,项目名称:spring-dao-mongo,代码行数:21,代码来源:AbstractMongoDAO.java

示例15: _selectByCriteria

import org.jongo.Find; //导入依赖的package包/类
@Override
public List<Map<String, Object>> _selectByCriteria(Table table) {
	List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
	Map<String, Object> coditon = new HashMap<String, Object>();
	try {
		QueryCriteria queryCriteria = table.getQueryCriteria();
		DB db = database.getDB();
		Jongo jongo = new Jongo(db);
		for(Criteria criteria:queryCriteria.getOredCriteria()){
			for(Criterion criterion:criteria.getAllCriteria()){
				coditon = buildCriteria(criterion, coditon);
			}
		}
		Find find = jongo.getCollection(queryCriteria.getTable()).find(JsonUtils.objToJson(coditon));
	    if(StringUtils.isNotBlank(queryCriteria.getOrderByClause())){
	    	find.sort(queryCriteria.getOrderByClause());
	    }
	    if(queryCriteria.getSelectOne()){
	    	find.skip(0);
	        find.limit(1);
	    }else{
	    	if(queryCriteria.getPageIndex() >= 0){
	        	int pageSize = 20, pageIndex = 1;
	        	if(queryCriteria.getPageSize() > 0){
	        		pageSize = queryCriteria.getPageSize();
	        	}
	        	if(queryCriteria.getPageIndex() > 1){
	        		pageIndex = queryCriteria.getPageIndex();
	        	}
	        	
	        	find.skip((pageIndex - 1) * pageSize);
	            find.limit(pageSize);
	        }
	    }
	    StringBuffer sb = new StringBuffer();
	    if(null != table.getParams()){
	    	for(String fd : table.getParams().keySet()){
	        	sb.append(fd).append(",");
	        }
	    }
	    if(sb.length() > 0){
	    	find.projection(sb.deleteCharAt(sb.lastIndexOf(",")).toString());
	    }
	    Iterator<Map> iterator = find.as(Map.class).iterator();  
	    while(iterator.hasNext()){
	    	Map<String, Object> item = iterator.next();
	    	item.put("id", item.get("_id").toString());
	        result.add(item);
	    }
	} catch (MongoException e) {
		LOG.error("mongo find error", e);
	}
	return result;
}
 
开发者ID:uncodecn,项目名称:uncode-dal-all,代码行数:55,代码来源:MongoDAL.java


注:本文中的org.jongo.Find类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。