public HashSet<Integer> getDistributionsByObjectNS(String nsToSearch) { BasicDBObject query = new BasicDBObject(DistributionObjectNS0DB.NS, nsToSearch); DBCollection collection = DBSuperClass2.getDBInstance().getCollection(DistributionObjectNS0DB.COLLECTION_NAME); HashSet<Integer> hash = new HashSet<Integer>(); Cursor cursor = collection.find(query); while (cursor.hasNext()) { DBObject instance = cursor.next(); // DistributionDB distribution = new DistributionDB( // ((Number) instance.get(DistributionSubjectNS0DB.DISTRIBUTION_ID)).intValue()); // // if (distribution.getTriples() >= 1000) hash.add(((Number) instance.get(DistributionObjectNS0DB.DISTRIBUTION_ID)).intValue()); } return hash; }
@Override public ArrayList<Album> getAlbumsByTitle(String title) throws SQLException { ArrayList<Album> result = new ArrayList<Album>(); DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("Title", title); Pattern regex = Pattern.compile(title); query.put("Title", regex); /* --------------- ADDED MEDIATYPE LIMITER ---------------------- */ DBObject mediatype = new BasicDBObject("Mediatype", "Album"); BasicDBList and = new BasicDBList(); and.add(mediatype); and.add(query); query = new BasicDBObject("$and", and); /* -------------- END MEDIATYPE LIMITER ------------------------ */ Cursor cursor = collection.find(query); System.out.println("Searching by title " + title + " ..."); while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); Album a = Objectifier.cursorToAlbum(dbo); result.add(a); } return result; }
@Override public ArrayList<Album> getAlbumsByGenre(String genre) throws SQLException { ArrayList<Album> result = new ArrayList<Album>(); DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("Genre", genre); Pattern regex = Pattern.compile(genre); query.put("Genre", regex); /* --------------- ADDED MEDIATYPE LIMITER ---------------------- */ DBObject mediatype = new BasicDBObject("Mediatype", "Album"); BasicDBList and = new BasicDBList(); and.add(mediatype); and.add(query); query = new BasicDBObject("$and", and); /* -------------- END MEDIATYPE LIMITER ------------------------ */ Cursor cursor = collection.find(query); System.out.println("Searching by genre " + genre + " ..."); while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); Album a = Objectifier.cursorToAlbum(dbo); result.add(a); } System.out.println(result); return result; }
@Override public ArrayList<Movie> getMovieByTitle(String title) throws SQLException { ArrayList<Movie> result = new ArrayList<Movie>(); DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("Title", title); Pattern regex = Pattern.compile(title); query.put("Title", regex); /* --------------- ADDED MEDIATYPE LIMITER ---------------------- */ DBObject mediatype = new BasicDBObject("Mediatype", "Movie"); BasicDBList and = new BasicDBList(); and.add(mediatype); and.add(query); query = new BasicDBObject("$and", and); /* -------------- END MEDIATYPE LIMITER ------------------------ */ Cursor cursor = collection.find(query); System.out.println("Searching by title " + title + " ..."); while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); Movie a = Objectifier.cursorToMovie(dbo); result.add(a); } return result; }
@Override public ArrayList<Movie> getMovieByGenre(String genre) throws SQLException { ArrayList<Movie> result = new ArrayList<Movie>(); DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("Genre", genre); Pattern regex = Pattern.compile(genre); query.put("Genre", regex); /* --------------- ADDED MEDIATYPE LIMITER ---------------------- */ DBObject mediatype = new BasicDBObject("Mediatype", "Movie"); BasicDBList and = new BasicDBList(); and.add(mediatype); and.add(query); query = new BasicDBObject("$and", and); /* -------------- END MEDIATYPE LIMITER ------------------------ */ Cursor cursor = collection.find(query); System.out.println("Searching by genre " + genre + " ..."); while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); Movie a = Objectifier.cursorToMovie(dbo); result.add(a); } System.out.println(result); return result; }
@Override public Iterator<RyaStatement> fetchStatements() { final Cursor cur = db.getCollection(TRIPLES_COLLECTION).find().sort(new BasicDBObject(TIMESTAMP, 1)); final List<RyaStatement> statements = new ArrayList<>(); while(cur.hasNext()) { final RyaStatement statement = adapter.deserializeDBObject(cur.next()); statements.add(statement); } return statements.iterator(); }
@Override public Iterator<RyaStatement> fetchStatements() throws FetchStatementException { final DBObject timeObj = new BasicDBObjectBuilder() .add(SimpleMongoDBStorageStrategy.TIMESTAMP, new BasicDBObjectBuilder() .add("$gte", timestamp.getTime()).get()) .get(); final Cursor cur = db.getCollection(TRIPLES_COLLECTION).find(timeObj).sort(new BasicDBObject(TIMESTAMP, 1)); final List<RyaStatement> statements = new ArrayList<>(); while(cur.hasNext()) { final RyaStatement statement = adapter.deserializeDBObject(cur.next()); statements.add(statement); } return statements.iterator(); }
@Override public EnsemblTranscript findOneByHugoSymbolIgnoreCase(String hugoSymbol, String isoformOverrideSource) { BasicDBObject regexQuery = new BasicDBObject(); // case insensitive exact match query regexQuery.put("hgnc_symbol", new BasicDBObject("$regex", "^" + hugoSymbol + "$") .append("$options", "i")); Cursor transcriptCursor; Cursor canonicalCursor = mongoTemplate.getCollection(CANONICAL_TRANSCRIPTS_COLLECTION).find(regexQuery); if (canonicalCursor.hasNext()) { BasicDBObject canonicalTranscriptsPerSource = (BasicDBObject) canonicalCursor.next(); String transcriptId = (String) canonicalTranscriptsPerSource.get(isoformOverrideSource + "_canonical_transcript"); BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put(EnsemblTranscript.TRANSCRIPT_ID_FIELD_NAME, transcriptId); transcriptCursor = mongoTemplate.getCollection(TRANSCRIPTS_COLLECTION).find(whereQuery); if (transcriptCursor.hasNext()) { EnsemblTranscript transcript = mongoTemplate.getConverter().read(EnsemblTranscript.class, transcriptCursor.next()); if (transcript != null) { return transcript; } } } return null; }
@GET @Produces("application/json") @Path("/tags/{product}/{major}.{minor}.{servicePack}/{build}") public DBObject getTagList(@BeanParam final Coordinates coordinates) { final DB bdd = this.client.getDB("bdd"); final DBCollection features = bdd.getCollection("features"); List<BasicDBObject> objectList = new ArrayList<BasicDBObject>(); // Build objects for aggregation pipeline // id option: returns each tag with a list of associated feature ids objectList.add(new BasicDBObject("$match", coordinates.getReportCoordinatesQueryObject())); final DBObject fields = new BasicDBObject("tags.name", 1); fields.put("_id", 0); // comment out for id option objectList.add(new BasicDBObject("$project", fields)); objectList.add(new BasicDBObject("$unwind", "$tags")); final DBObject groupFields = new BasicDBObject("_id", "$tags.name"); // groupFields.put("features", new BasicDBObject("$addToSet", "$_id")); //comment in for id option groupFields.put("amount", new BasicDBObject("$sum", 1)); objectList.add(new BasicDBObject("$group", groupFields)); objectList.add(new BasicDBObject("$sort", new BasicDBObject("amount", -1))); AggregationOptions options = AggregationOptions.builder().build(); final Cursor output = features.aggregate(objectList, options); // get _ids from each entry of output.result final BasicDBList returns = new BasicDBList(); while(output.hasNext()) { returns.add(output.next().get("_id").toString()); } return returns; }
public void peek() { Cursor fetchAll = coll.find(); // rough peek while (fetchAll.hasNext()) { System.out.println(fetchAll.next()); } }
@Override public ArrayList<Album> getAllAlbums(ResultSet rsetAlbum) throws SQLException { ArrayList<Album> albums = new ArrayList<Album>(); Cursor cr = coll.find(); while (cr.hasNext()) { cr.next(); } return albums; }
@Override public ArrayList<Album> getAlbumsByYear(String year) throws SQLException { // TODO ADD TRYCATCH FOR CORRECT EXCEPTION researching API ArrayList<Album> result = new ArrayList<Album>(); DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("Year", year); Pattern regex = Pattern.compile(year); query.put("Year", regex); /* --------------- ADDED MEDIATYPE LIMITER ---------------------- */ DBObject mediatype = new BasicDBObject("Mediatype", "Album"); BasicDBList and = new BasicDBList(); and.add(mediatype); and.add(query); query = new BasicDBObject("$and", and); /* -------------- END MEDIATYPE LIMITER ------------------------ */ Cursor cursor = collection.find(query); System.out.println("Searching by year " + year + " ..."); while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); // Make Album from result of query Album a = Objectifier.cursorToAlbum(dbo); // System.out.println(a.toString()); // put in list result.add(a); } System.out.println("Done searching ..."); // DEBUG: print them out return result; }
@Override public ArrayList<Album> getAlbumsByUser(String user) throws SQLException { ArrayList<Album> result = new ArrayList<Album>(); try { DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("AddedBy", user); Pattern regex = Pattern.compile(user); query.put("AddedBy", regex); /* --------------- ADDED MEDIATYPE LIMITER ---------------------- */ DBObject mediatype = new BasicDBObject("Mediatype", "Album"); BasicDBList and = new BasicDBList(); and.add(mediatype); and.add(query); query = new BasicDBObject("$and", and); /* -------------- END MEDIATYPE LIMITER ------------------------ */ Cursor cursor = collection.find(query); System.out.println("Searching by user " + user + " ..."); while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); // Make Album from result of query Album a = Objectifier.cursorToAlbum(dbo); // System.out.println(a.toString()); // put in list result.add(a); } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return result; }
@Override public ArrayList<Movie> getMovieByUser(String user) throws SQLException { ArrayList<Movie> result = new ArrayList<Movie>(); try { DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("AddedBy", user); Pattern regex = Pattern.compile(user); query.put("AddedBy", regex); /* --------------- ADDED MEDIATYPE LIMITER ---------------------- */ DBObject mediatype = new BasicDBObject("Mediatype", "Movie"); BasicDBList and = new BasicDBList(); and.add(mediatype); and.add(query); query = new BasicDBObject("$and", and); /* -------------- END MEDIATYPE LIMITER ------------------------ */ Cursor cursor = collection.find(query); System.out.println("Searching by user " + user + " ..."); while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); // Make Album from result of query Movie m = Objectifier.cursorToMovie(dbo); // System.out.println(a.toString()); // put in list result.add(m); } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return result; }
@Override public ArrayList<Movie> getAllMovies(ResultSet rsetMovie) throws SQLException { ArrayList<Movie> movies = new ArrayList<Movie>(); Cursor cr = coll.find(); while (cr.hasNext()) { cr.next(); } return movies; }
@Override public ArrayList<Movie> getMovieByYear(String year) throws SQLException { // TODO ADD TRYCATCH FOR CORRECT EXCEPTION researching API ArrayList<Movie> result = new ArrayList<Movie>(); DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("Year", year); Pattern regex = Pattern.compile(year); query.put("Year", regex); /* --------------- ADDED MEDIATYPE LIMITER ---------------------- */ DBObject mediatype = new BasicDBObject("Mediatype", "Movie"); BasicDBList and = new BasicDBList(); and.add(mediatype); and.add(query); query = new BasicDBObject("$and", and); /* -------------- END MEDIATYPE LIMITER ------------------------ */ Cursor cursor = collection.find(query); System.out.println("Searching by year " + year + " ..."); while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); // Make Album from result of query Movie m = Objectifier.cursorToMovie(dbo); // System.out.println(a.toString()); // put in list result.add(m); } System.out.println("Done searching ..."); // DEBUG: print them out return result; }
@Override public void getReviewsByAny(String queryText) throws SQLException { queryText = queryText.replace("%", ""); ArrayList<Review> reviews = new ArrayList<Review>(); DBCollection collection = db.getCollection("Media"); Pattern regex = Pattern.compile(queryText); DBObject st1 = new BasicDBObject("Review.Title", regex); DBObject st2 = new BasicDBObject("Review.Text", regex); DBObject st3 = new BasicDBObject("Review.User", regex); DBObject st4 = new BasicDBObject("Mediatype", regex); DBObject st5 = new BasicDBObject("Title", regex); BasicDBList or = new BasicDBList(); or.add(st1); or.add(st2); or.add(st3); or.add(st4); or.add(st5); DBObject query = new BasicDBObject("$or", or); Cursor cursor = collection.find(query); System.out.println("Searching by Review " + queryText + " ..."); while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); reviews.addAll(Objectifier.cursorToReview(dbo, queryText)); } System.out.println("Searching by review..."); model.setBank(reviews.toArray()); }
@Override public <U> Iterator<U> aggregate(final String collectionName, final Class<U> target, final AggregationOptions options, final ReadPreference readPreference) { LOG.debug("stages = " + stages); Cursor cursor = collection.aggregate(stages, options, readPreference); return new MorphiaIterator<U, U>(datastore, cursor, mapper, target, collectionName, mapper.createEntityCache()); }
public CursorImpl(Cursor cursor) { this.cursor=cursor; }
public Cursor getCursor() { return cursor; }
public HashSet<Integer> getDistributionsBySubjectNS(String nsToSearch) { BasicDBObject query = new BasicDBObject(DistributionSubjectNS0DB.NS, nsToSearch); DBCollection collection = DBSuperClass2.getDBInstance().getCollection(DistributionSubjectNS0DB.COLLECTION_NAME); HashSet<Integer> hash = new HashSet<Integer>(); Cursor cursor = collection.find(query); while (cursor.hasNext()) { DBObject instance = cursor.next(); // DistributionDB distribution = new DistributionDB( // ((Number) instance.get(DistributionSubjectNS0DB.DISTRIBUTION_ID)).intValue()); // // if (distribution.getTriples() >= 1000) hash.add(((Number) instance.get(DistributionSubjectNS0DB.DISTRIBUTION_ID)).intValue()); } return hash; }
public ArrayList<DistributionDB> getDistributionsByOutdegree(ArrayList<String> nsToSearch, ConcurrentHashMap<Integer, DistributionBloomFilterContainer> distributionFilter) { ArrayList<DistributionDB> list = new ArrayList<DistributionDB>(); try { // query all NS BasicDBObject query = new BasicDBObject(DistributionSubjectNS0DB.NS, new BasicDBObject("$in", nsToSearch)); DBCollection collection = DBSuperClass2.getDBInstance() .getCollection(DistributionSubjectNS0DB.COLLECTION_NAME); // group by Cursor cursor = collection .aggregate(Arrays.asList( new BasicDBObject("$match", new BasicDBObject(DistributionSubjectNS0DB.NS, new BasicDBObject("$in", nsToSearch))), new BasicDBObject("$group", new BasicDBObject("_id", "$" + DistributionSubjectNS0DB.DISTRIBUTION_ID)) ), aggregationOptions); // save a list with distribution and fqdn while (cursor.hasNext()) { DBObject instance = cursor.next(); DistributionDB distribution = new DistributionDB(); distribution.setLodVaderID(((Number) instance.get("_id")).intValue()); if (distribution.find(true)) { list.add(distribution); if (!distributionFilter.containsKey(distribution.getLODVaderID())) { distributionFilter.put(distribution.getLODVaderID(), new DistributionBloomFilterContainer(distribution.getLODVaderID())); } } } } catch (Exception e) { e.printStackTrace(); } return list; }
@Override public ArrayList<Album> getAlbumsByArtist(String artist) throws SQLException { // TODO: fixit ArrayList<Album> result = new ArrayList<Album>(); DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("Creator", artist); System.out.println("QUERY" + query); Pattern regex = Pattern.compile(artist); query.put("Creator", regex); // TODO: let db decide how big rating is Cursor cursor = collection.find(); System.out.println("Entering search ..."); // TODO: more effective searches try { while (cursor.hasNext()) { System.out.println("Searching by artist " + artist + " ..."); BasicDBObject dbo = (BasicDBObject) cursor.next(); if (dbo.getString("Mediatype").equals("Album")) { // dbo.get("Score"); // Make Album from result of query Album a = Objectifier.cursorToAlbum(dbo); // TODO: aid by research ArrayList<Artist> tmp = a.getArtist(); // mm aj lajk de speed of this database for (Artist artists : tmp) { if (artists.getName().contains(artist)) { // put in list, if rating is greater than desired result.add(a); } } } } System.out.println(result); return result; } finally { cursor.close(); } }
@Override public ArrayList<Album> getAlbumsByRating(String rating) throws SQLException { // TODO: fixit ArrayList<Album> result = new ArrayList<Album>(); DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("Rating", new BasicDBObject("Score", rating)); System.out.println("QUERY" + query); Pattern regex = Pattern.compile(rating); query.put("Rating", regex); // TODO: let db decide how big rating is Cursor cursor = collection.find(); System.out.println("Entering search ..."); // TODO: 2 searches. // one to reach rating // one for right rating try { while (cursor.hasNext()) { System.out.println("Searching by rating " + rating + " ..."); BasicDBObject dbo = (BasicDBObject) cursor.next(); if (dbo.getString("Mediatype").equals("Album")) { // dbo.get("Score"); // Make Album from result of query Album a = Objectifier.cursorToAlbum(dbo); try { // TODO: aid by research if (a.getRating() >= (float) Integer.parseInt(rating)) { // put in list, if rating is greater than desired result.add(a); } } catch (NumberFormatException e) { } } } System.out.println(result); return result; } finally { cursor.close(); } }
@Override public ArrayList<Movie> getMovieByRating(String rating) throws SQLException { ArrayList<Movie> result = new ArrayList<Movie>(); DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("Rating", new BasicDBObject("Score", rating)); System.out.println("QUERY" + query); Pattern regex = Pattern.compile(rating); query.put("Rating", regex); // TODO: let db decide how big rating is Cursor cursor = collection.find(); System.out.println("Entering search ..."); // TODO: 2 searches. // one to reach rating // one for right rating try { while (cursor.hasNext()) { System.out.println("Searching by rating " + rating + " ..."); BasicDBObject dbo = (BasicDBObject) cursor.next(); if (dbo.getString("Mediatype").equals("Movie")) { // dbo.get("Score"); // Make Album from result of query Movie a = Objectifier.cursorToMovie(dbo); try { // TODO: aid by research if (a.getRating() >= (float) Integer.parseInt(rating)) { // put in list, if rating is greater than desired result.add(a); } } catch (NumberFormatException e) { } } } System.out.println(result); return result; } finally { cursor.close(); } }
@Override public ArrayList<Movie> getMovieByDirector(String director) throws SQLException { ArrayList<Movie> result = new ArrayList<Movie>(); DBCollection collection = db.getCollection("Media"); DBObject query = new BasicDBObject("Creator", "..."); System.out.println("QUERY" + query); Pattern regex = Pattern.compile(director); query.put("Creator", regex); // TODO: let db decide how big rating is Cursor cursor = collection.find(); System.out.println("Entering search ..."); // TODO: more effective searches try { while (cursor.hasNext()) { System.out.println("Searching by artist " + director + " ..."); BasicDBObject dbo = (BasicDBObject) cursor.next(); if (dbo.getString("Mediatype").equals("Movie")) { // dbo.get("Score"); // Make Album from result of query Movie d = Objectifier.cursorToMovie(dbo); // TODO: aid by research ArrayList<Director> tmp = d.getDirector(); // mm aj lajk de speed of this database for (Director directors : tmp) { if (directors.getName().contains(director)) { // put in list, if rating is greater than desired result.add(d); } } } } System.out.println(result); return result; } finally { cursor.close(); } }
/** * 条件查询, 列表, 限制pageSize * * @param dbName * @param collName * @param query * @param fields * @param limit * @return */ public static List<DBObject> find(String dbName, String collName, DBObject query, DBObject fields, int pageSize) { List<DBObject> list = new LinkedList<DBObject>(); Cursor cursor = getCollection(dbName, collName).find(query, fields).limit(pageSize); while (cursor.hasNext()) { list.add(cursor.next()); } return list.size() > 0 ? list : null; }
/** * 条件查询, 分页数据 * @param dbName * @param collName * @param query * @param fields * @param orderBy * @param pageNum * @param pageSize * @return */ public static List<DBObject> find(String dbName, String collName, DBObject query, DBObject fields, DBObject orderBy, int pageNum, int pageSize) { List<DBObject> list = new ArrayList<DBObject>(); Cursor cursor = getCollection(dbName, collName).find(query, fields).skip((pageNum - 1) * pageSize).limit(pageSize).sort(orderBy); while (cursor.hasNext()) { list.add(cursor.next()); } return list.size() > 0 ? list : null; }