-
Notifications
You must be signed in to change notification settings - Fork 1
/
DB_Queries.java
82 lines (64 loc) · 2.94 KB
/
DB_Queries.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.regex.Pattern;
import org.bson.Document;
import org.bson.conversions.Bson;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
// year = 'F'/'S'/'T'/'B'
public class DB_Queries {
DB_Init init = new DB_Init();
public DBCursor filter_by_prn(String prn, DBCollection dbc) {
return dbc.find(new BasicDBObject("PRN", prn));
}
public FindIterable<Document> filter_by_name(String name, MongoCollection<Document> filtered_collection) {
return filtered_collection.find(new BasicDBObject("Name", java.util.regex.Pattern
.compile("(.*?)" + name + "(.*?)", Pattern.CASE_INSENSITIVE)));
}
public FindIterable<Document> filter_by_roll(String roll, MongoCollection<Document> filtered_collection) {
roll = roll.toUpperCase();
return filtered_collection.find(new BasicDBObject(roll.charAt(0) + ".Roll", roll));
}
public FindIterable<Document> filter_by_branch(String branch, MongoCollection<Document> filtered_collection) {
return filtered_collection.find(new BasicDBObject("Branch", branch));
}
public DBCursor filter_by_class(char year, String result_class,
DBCollection dbc) {
return dbc.find(new BasicDBObject(year + ".Result", result_class));
}
public FindIterable<Document> filter_by_college(String college, MongoCollection<Document> original_table) {
// return dbc.find(new
// BasicDBObject("College",java.util.regex.Pattern.compile("(.*?)"+college+"(.*?)",
// Pattern.CASE_INSENSITIVE)));
return original_table.find(new BasicDBObject("College", college));
}
public FindIterable<Document> filter_by_year(String year, MongoCollection<Document> filtered_collection) {
DBObject query = new BasicDBObject(year, new BasicDBObject("$exists",
true));
FindIterable<Document> cursor = filtered_collection.find((Bson) query);
System.out.println("Inside filter_by_year : "
+ Integer.toString((int) ((DBCollection) cursor).count()));
return cursor;
}
public FindIterable<Document> filter_by_batch(String batch, MongoCollection<Document> filtered_collection) {
return filtered_collection.find(new BasicDBObject("Batch", batch));
}
public DBCursor sort_by_name(DBCollection dbc) {
return dbc.find().sort(new BasicDBObject("Name", 1));
}
public DBCursor sort_by_college(DBCollection dbc) {
return dbc.find().sort(new BasicDBObject("College", 1));
}
public DBCursor sort_by_roll(DBCollection dbc, char year) {
return dbc.find().sort(new BasicDBObject(year + ".Roll", 1));
}
public DBCursor sort_by_scored(DBCollection dbc, char year) {
return dbc.find().sort(new BasicDBObject(year + ".Scored", -1));
}
public DBCursor sort_by_subject(String sub_name, char year, DBCollection dbc) {
return dbc.find().sort(
new BasicDBObject(year + "." + sub_name + "." + "Scored", -1));
}
}