有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java代码中的mongodb性能问题

我在mongodb中使用java。。我在下面的代码中遇到性能问题,你能优化这个代码吗

我需要提高这个函数的性能

//作为associationId接收参数的第一个函数。你们能帮我提高这个功能的性能吗

public ArrayList<ResidentAssociationMapEntity> listUsersByAssociation(String 
associationId) {

HashMap<String, Object> filterExpressions = new HashMap<String, Object>();
filterExpressions.put("associationId", associationId);
filterExpressions.put("residentStatus", 1);
List<ResidentAssociationMapEntity> residents = 
    DBManager.getInstance().getByMultipleFields(
            ResidentAssociationMapEntity.class, filterExpressions);
    if (residents != null && residents.size() > 0) {
        for (ResidentAssociationMapEntity map : residents ) {
            map.setUser(getUser(map.getUserId()));
        }
    } 

    return new ArrayList<ResidentAssociationMapEntity>(residents);
}

//获取用户函数

public UserEntity getUser(String userId) {

    UserEntity entity = DBManager.getInstance().getById(UserEntity.class, 
userId);
    ResidentAssociationMapEntity map = 
getResidentAssocaitionMap(entity.getUserId());
    if (map != null) {
        entity.setUnitNo(map.getUnitNumber() + "");
        entity.setAssociationId(map.getAssociationId());
entity.setAssociationName(CompanyDAO.getInstance().getCompany(map.getAssocia
tionId()).getName());

    }

    return entity;
}

//GetResidentassocationMap函数

 private ResidentAssociationMapEntity getResidentAssocaitionMap(String 
 residentId) {

HashMap<String, Object> filterExpressions = new HashMap<String, Object>();
    filterExpressions.put("userId", residentId);
    filterExpressions.put("residentStatus", 1);
    List<ResidentAssociationMapEntity> residents = 
     DBManager.getInstance().getByMultipleFields(
            ResidentAssociationMapEntity.class, filterExpressions);
    if (residents != null && residents.size() > 0) {
        return residents.get(0);
    }
    return null;
}

共 (0) 个答案