List of usage examples for com.mongodb DBCursor close
@Override public void close()
From source file:fr.gouv.vitam.cases.DbRequest.java
License:Open Source License
/** * In MongoDB : <br/> // w w w. ja v a 2s . c o m * find(Query, Projection).sort(SortFilter).skip(SkipFilter).limit(LimitFilter);<br/> * In addition, one shall limit the scan by: <br/> * find(Query, Projection)._addSpecial( "$maxscan", highlimit) * .sort(SortFilter).skip(SkipFilter).limit(LimitFilter); * * @param query * @param result to be filtered using query * @return the new result or null if the same */ private ResultInterface lastFilter(final AbstractQueryParser query, final ResultInterface result) { if (simulate) { return null; } boolean filter = (query.getLimit() > 0 || query.getOffset() > 0); if (!filter) { return null; } ObjectNode orderBy = query.getOrderBy(); if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("Req1LevelMD Filter on: Limit {} Offset {} OrderBy {}", query.getLimit(), query.getOffset(), orderBy); } final ResultInterface subresult = CassandraAccess.createOneResult(); BasicDBObject inClause = getInClauseForField(DAip.ID, result.getCurrentDaip()); final DBCursor cursor = mdAccess.daips.collection.find(inClause, ID_NBCHILD); if (query.getLimit() > 0) { cursor.limit(query.getLimit()); } if (query.getOffset() > 0) { cursor.skip(query.getOffset()); } if (orderBy != null) { // orderBy is used only if limit and/or offset is set cursor.sort((DBObject) orderBy); } long tempCount = 0; while (cursor.hasNext()) { final DAip maip = (DAip) cursor.next(); final String mid = maip.getId(); subresult.getCurrentDaip().add(mid); tempCount += maip.getLong(DAip.NBCHILD); } cursor.close(); if (subresult.getCurrentDaip().containsAll(result.getCurrentDaip())) { // same so don't change it return null; } subresult.setNbSubNodes(tempCount); // Not updateMinMax since result is not "valid" path but node UUID and not needed subresult.setMinLevel(result.getMinLevel()); subresult.setMaxLevel(result.getMaxLevel()); subresult.setLoaded(true); if (GlobalDatas.PRINT_REQUEST) { subresult.putBeforeSave(); LOGGER.warn("Filtered: {}", subresult); } return subresult; }
From source file:fr.gouv.vitam.mdbes.DAip.java
License:Open Source License
/** * * @param dbvitam/*from www. j a va2 s . c o m*/ * @return the list of UUID of children (database access) */ public List<String> getChildrenDAipDBRefFromParent(final MongoDbAccess dbvitam) { final DBCursor cid = dbvitam.daips.collection.find( new BasicDBObject(MongoDbAccess.VitamLinks.DAip2DAip.field2to1, this.get(ID)), new BasicDBObject(ID, 1)); final List<String> ids = new ArrayList<>(); while (cid.hasNext()) { final String mid = (String) cid.next().get(ID); ids.add(mid); } cid.close(); return ids; }
From source file:fr.gouv.vitam.mdbes.DbRequest.java
License:Open Source License
private final ResultInterface getRequestDomain(final TypeRequest request, final ResultInterface previous, final boolean useStart) throws InvalidExecOperationException, InstantiationException, IllegalAccessException { // must be MD if (request.isOnlyES) { throw new InvalidExecOperationException("Expression is not valid for Domain"); }// w w w .ja v a 2 s . co m if (request.requestModel == null) { throw new InvalidExecOperationException( "Expression is not valid for Domain since no Request is available"); } final String srequest = request.requestModel.toString(); final BasicDBObject condition = (BasicDBObject) JSON.parse(srequest); final ResultInterface newResult = MongoDbAccess.createOneResult(); newResult.setMinLevel(1); newResult.setMaxLevel(1); if (simulate) { LOGGER.info("ReqDomain: {}\n\t{}", condition, ID_NBCHILD); return createFalseResult(null, 1); } LOGGER.debug("ReqDomain: {}\n\t{}", condition, ID_NBCHILD); if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("ReqDomain: {}\n\t{}", condition, ID_NBCHILD); } final DBCursor cursor = mdAccess.find(mdAccess.domains, condition, ID_NBCHILD); long tempCount = 0; while (cursor.hasNext()) { final Domain dom = (Domain) cursor.next(); final String mid = dom.getId(); if (useStart) { if (previous.getCurrentDaip().contains(mid)) { newResult.getCurrentDaip().add(mid); tempCount += dom.getLong(Domain.NBCHILD); } } else { newResult.getCurrentDaip().add(mid); tempCount += dom.getLong(Domain.NBCHILD); } } cursor.close(); newResult.setNbSubNodes(tempCount); // filter on Ancestor if (!useStart && !previous.checkAncestor(mdAccess, newResult)) { LOGGER.error("No ancestor"); return null; } // Compute of MinMax if valid since path = 1 length (root) newResult.updateMinMax(); if (GlobalDatas.PRINT_REQUEST) { newResult.putBeforeSave(); LOGGER.warn("Dom: {}", newResult); } return newResult; }
From source file:fr.gouv.vitam.mdbes.DbRequest.java
License:Open Source License
private final ResultInterface getRequest1LevelMaipFromMD(final TypeRequest request, final ResultInterface previous, final boolean useStart) throws InvalidExecOperationException, InstantiationException, IllegalAccessException { BasicDBObject query = null;/*from w w w . j ava 2 s.co m*/ if (request.requestModel == null) { throw new InvalidExecOperationException( "Expression is not valid for Daip Level 1 with MD only since no MD request is available"); } if (useStart) { query = getInClauseForField(DAip.ID, previous.getCurrentDaip()); } else { if (previous.getMinLevel() == 1) { query = getInClauseForField(MongoDbAccess.VitamLinks.Domain2DAip.field2to1, previous.getCurrentDaip()); } else { query = getInClauseForField(MongoDbAccess.VitamLinks.DAip2DAip.field2to1, previous.getCurrentDaip()); } } final String srequest = request.requestModel.toString(); final BasicDBObject condition = (BasicDBObject) JSON.parse(srequest); query.putAll((BSONObject) condition); final ResultInterface subresult = MongoDbAccess.createOneResult(); if (simulate) { LOGGER.info("Req1LevelMD: {}", query); return createFalseResult(previous, 1); } LOGGER.debug("Req1LevelMD: {}", query); if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("Req1LevelMD: {}", query); } final DBCursor cursor = mdAccess.find(mdAccess.daips, query, ID_NBCHILD); long tempCount = 0; while (cursor.hasNext()) { final DAip maip = (DAip) cursor.next(); final String mid = maip.getId(); if (useStart) { if (previous.getCurrentDaip().contains(mid)) { subresult.getCurrentDaip().add(mid); tempCount += maip.getLong(Domain.NBCHILD); } } else { subresult.getCurrentDaip().add(mid); tempCount += maip.getLong(Domain.NBCHILD); } } cursor.close(); subresult.setNbSubNodes(tempCount); // filter on Ancestor if (!useStart && !previous.checkAncestor(mdAccess, subresult)) { LOGGER.error("No ancestor for " + query + "\n" + previous.getCurrentDaip() + " not in " + subresult.getCurrentDaip()); return null; } // Not updateMinMax since result is not "valid" path but node UUID and not needed subresult.setMinLevel(previous.getMinLevel() + 1); subresult.setMaxLevel(previous.getMaxLevel() + 1); if (GlobalDatas.PRINT_REQUEST) { subresult.putBeforeSave(); LOGGER.warn("MetaAip2: {}", subresult); } return subresult; }
From source file:fr.gouv.vitam.mdbes.DbRequest.java
License:Open Source License
private final ResultInterface getRequestNegativeRelativeDepthFromMD(final TypeRequest request, final ResultInterface previous, final boolean useStart) throws InvalidExecOperationException, InstantiationException, IllegalAccessException { BasicDBObject query = null;//from ww w.j a va2 s. c om if (request.requestModel == null) { throw new InvalidExecOperationException("Expression is not valid for Daip Level " + request.relativedepth + " with MD only since no MD request is available"); } if (useStart) { throw new InvalidExecOperationException("Cannot make a negative path when starting up"); } if (simulate) { LOGGER.info("Req-xLevelMD"); return createFalseResult(previous, 1); } int distance = -request.relativedepth; Set<String> subset = new HashSet<String>(); for (String prev : previous.getCurrentDaip()) { DAip dprev = DAip.findOne(mdAccess, prev); Map<String, Integer> parents = dprev.getDomDepth(); for (Entry<String, Integer> elt : parents.entrySet()) { if (elt.getValue() == distance) { subset.add(elt.getKey()); } } } // Use ID and not graph dependencies query = getInClauseForField(DAip.ID, subset); final String srequest = request.requestModel.toString(); final BasicDBObject condition = (BasicDBObject) JSON.parse(srequest); query.putAll((BSONObject) condition); final ResultInterface subresult = MongoDbAccess.createOneResult(); LOGGER.debug("Req-xLevelMD: {}", query); if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("Req-xLevelMD: {}", query); } final DBCursor cursor = mdAccess.find(mdAccess.daips, query, ID_NBCHILD); long tempCount = 0; subresult.setMinLevel(previous.getMaxLevel()); subresult.setMaxLevel(0); while (cursor.hasNext()) { final DAip maip = (DAip) cursor.next(); final String mid = maip.getId(); subresult.getCurrentDaip().add(mid); maip.load(mdAccess); tempCount += maip.getLong(DAip.NBCHILD); // Not updateMinMax since result is not "valid" path but node UUID and not needed int max = maip.getMaxDepth(); if (subresult.getMaxLevel() < max) { subresult.setMaxLevel(max); } if (subresult.getMinLevel() > max) { subresult.setMinLevel(max); } } cursor.close(); subresult.setNbSubNodes(tempCount); if (GlobalDatas.PRINT_REQUEST) { subresult.putBeforeSave(); LOGGER.warn("MetaAip2: {}", subresult); } return subresult; }
From source file:fr.gouv.vitam.mdbes.DbRequest.java
License:Open Source License
/** * In MongoDB : <br/> //from www .ja v a 2 s . co m * find(Query, Projection).sort(SortFilter).skip(SkipFilter).limit(LimitFilter);<br/> * In addition, one shall limit the scan by: <br/> * find(Query, Projection)._addSpecial( "$maxscan", highlimit) * .sort(SortFilter).skip(SkipFilter).limit(LimitFilter); * * @param query * @param result to be filtered using query * @return the new result or null if the same */ private ResultInterface lastFilter(final AbstractQueryParser query, final ResultInterface result) { if (simulate) { return null; } boolean filter = (query.getLimit() > 0 || query.getOffset() > 0); if (!filter) { return null; } ObjectNode orderBy = query.getOrderBy(); if (GlobalDatas.PRINT_REQUEST) { LOGGER.warn("Req1LevelMD Filter on: Limit {} Offset {} OrderBy {}", query.getLimit(), query.getOffset(), orderBy); } final ResultInterface subresult = MongoDbAccess.createOneResult(); BasicDBObject inClause = getInClauseForField(DAip.ID, result.getCurrentDaip()); final DBCursor cursor = mdAccess.daips.collection.find(inClause, ID_NBCHILD); if (query.getLimit() > 0) { cursor.limit(query.getLimit()); } if (query.getOffset() > 0) { cursor.skip(query.getOffset()); } if (orderBy != null) { // orderBy is used only if limit and/or offset is set cursor.sort((DBObject) orderBy); } long tempCount = 0; while (cursor.hasNext()) { final DAip maip = (DAip) cursor.next(); final String mid = maip.getId(); subresult.getCurrentDaip().add(mid); tempCount += maip.getLong(DAip.NBCHILD); } cursor.close(); if (subresult.getCurrentDaip().containsAll(result.getCurrentDaip())) { // same so don't change it return null; } subresult.setNbSubNodes(tempCount); // Not updateMinMax since result is not "valid" path but node UUID and not needed subresult.setMinLevel(result.getMinLevel()); subresult.setMaxLevel(result.getMaxLevel()); subresult.setLoaded(true); if (GlobalDatas.PRINT_REQUEST) { subresult.putBeforeSave(); LOGGER.warn("Filtered: {}", subresult); } return subresult; }
From source file:fr.gouv.vitam.mdbes.MainSimpleRequest.java
License:Open Source License
protected static void oneShot(MongoDbAccess dbvitam) throws InvalidParseOperationException, InvalidExecOperationException, InstantiationException, IllegalAccessException { // Requesting String comdtree = request.toString(); BasicDBObject query = (BasicDBObject) JSON.parse(comdtree); if (ids != null) { BasicDBObject id = (BasicDBObject) JSON.parse(ids); DateTime date = new DateTime(-123456789012345L); query = new BasicDBObject("OldDate", date.toDate()); System.out.println("Date: " + date + " upd: " + query + " => " + date.getYear()); dbvitam.daips.collection.update(id, query); final DBCursor cursor = dbvitam.daips.collection.find(id); while (cursor.hasNext()) { final DAip maip = (DAip) cursor.next(); maip.load(dbvitam);//from w w w . ja v a 2 s . com System.out.println(maip); } cursor.close(); System.out.println("===="); date = date.plusYears(10); id.append("OldDate", new BasicDBObject("$lt", date.toDate())); System.out.println("Date: " + date + " find: " + id + " => " + date.getYear()); final DBCursor cursor2 = dbvitam.daips.collection.find(id); while (cursor2.hasNext()) { final DAip maip = (DAip) cursor2.next(); Date madate = maip.getDate("OldDate"); System.out.println("Madate: " + madate); System.out.println("Madate: " + madate.getTime()); System.out.println("Madate: " + new DateTime(madate)); maip.load(dbvitam); System.out.println(maip); } cursor2.close(); } else { final DBCursor cursor = dbvitam.find(dbvitam.daips, query, ID_NBCHILD); while (cursor.hasNext()) { final DAip maip = (DAip) cursor.next(); maip.load(dbvitam); System.out.println(maip); } cursor.close(); } }
From source file:framework.mod.settings.model.DAO.DAO_login.java
/**Search on mongo client collection for a client with usernam and password * gived on main login/*from w ww . j a v a 2 s .c o m*/ * * @return boolean */ public static boolean DAO_searchONclient() { boolean valid = false; DBCursor cursor = null; Client clt = new Client(); try { BasicDBObject query = new BasicDBObject(); query.put("user", singletonProfile.userName); cursor = singletonGen.collection.find(query); if (cursor.count() != 0) { while (cursor.hasNext()) { BasicDBObject document = (BasicDBObject) cursor.next(); clt = singletonProfile.clt.DB_to_Client(document); if (clt.getPassword().equals(singletonProfile.userPass)) { valid = true; System.out.println("ERROR Login for while!!!"); } } } else { System.out.println("NOT DATA"); } } finally { if (cursor != null) { cursor.close(); } } return valid; }
From source file:framework.mod.user.client.model.DAO.DAO_DB_Client.java
/**LOAD MONGO CLIENT DB * //from w w w .j a v a 2 s .c o m * Function that count the elements on singletonGen.table. * Reads his content one by one, saving client on document, * transform and saves it on singletonClient.ephemeralClient. * Finally adds singletonClient.ephemeralClient on singletonClient.ClienTableArray * * @return void */ public static void mongoDB_load_clientAL() { DBCursor index = null; try { index = singletonGen.collection.find(); if (index.count() != 0) { while (index.hasNext()) { BasicDBObject document = (BasicDBObject) index.next(); //singletonClient.ephemeralClient = singletonClient.ephemeralClient.DB_to_Client(document); singletonClient.ClienTableArray.add(singletonClient.ephemeralClient.DB_to_Client(document)); } } else { System.out.println("NOT DATA"); } } finally { if (index != null) { index.close(); } } }
From source file:framework.mod.user.client.model.DAO.DAO_DB_Client.java
/**Search on mongo client collection for a client with usernam gived * //from w ww. j a v a2 s.c om * @return boolean */ public static boolean DAO_searchONclientBYuserName() { boolean valid = false; DBCursor cursor = null; Client clt = new Client(); try { BasicDBObject query = new BasicDBObject(); query.put("user", singletonClient.userName); cursor = singletonGen.collection.find(query); if (cursor.count() != 0) { while (cursor.hasNext()) { BasicDBObject document = (BasicDBObject) cursor.next(); clt = singletonClient.ephemeralClient.DB_to_Client(document); if (clt.getPassword().equals(singletonClient.ephemeralClient)) { valid = true; System.out.println("ERROR Login for while!!!"); } } } else { System.out.println("NOT DATA"); } } finally { if (cursor != null) { cursor.close(); } } return valid; }