Revision 41768
Added by Claudio Atzori about 8 years ago
MDStoreDaoImpl.java | ||
---|---|---|
60 | 60 |
transactionManager.createMDStore(mdId); |
61 | 61 |
final String internalId = transactionManager.getMDStoreCollection(mdId); |
62 | 62 |
|
63 |
if (!Lists.newArrayList(db.listCollectionNames()).contains(internalId)) {
|
|
63 |
if (!Lists.newArrayList(getDB().listCollectionNames()).contains(internalId)) {
|
|
64 | 64 |
log.info(String.format("creating collection %s", internalId)); |
65 |
db.createCollection(internalId, new CreateCollectionOptions());
|
|
65 |
getDB().createCollection(internalId, new CreateCollectionOptions());
|
|
66 | 66 |
} |
67 |
final MongoCollection<DBObject> coll = db.getCollection(METADATA_NAME, DBObject.class);
|
|
67 |
final MongoCollection<DBObject> coll = getDB().getCollection(METADATA_NAME, DBObject.class);
|
|
68 | 68 |
final BasicDBObject obj = new BasicDBObject(); |
69 | 69 |
obj.put(MD_ID, mdId); |
70 | 70 |
obj.put(FORMAT, format); |
... | ... | |
79 | 79 |
*/ |
80 | 80 |
@Override |
81 | 81 |
public void deleteMDStore(final String mdId) throws MDStoreServiceException { |
82 |
final MongoCollection<DBObject> metadata = db.getCollection(METADATA_NAME, DBObject.class);
|
|
82 |
final MongoCollection<DBObject> metadata = getDB().getCollection(METADATA_NAME, DBObject.class);
|
|
83 | 83 |
if (metadata == null) throw new MDStoreServiceException("cannot find metadata collection"); |
84 | 84 |
transactionManager.dropMDStore(mdId); |
85 | 85 |
metadata.deleteOne(new BasicDBObject(MD_ID, mdId)); |
... | ... | |
92 | 92 |
@Override |
93 | 93 |
public MDStore getMDStore(final String mdId) throws MDStoreServiceException { |
94 | 94 |
final String internalId = transactionManager.getMDStoreCollection(mdId); |
95 |
return new MongoMDStore(mdId, db.getCollection(internalId, DBObject.class), getRecordParserFactory().newInstance(), isDiscardRecords(), getDb());
|
|
95 |
return new MongoMDStore(mdId, getDB().getCollection(internalId, DBObject.class), getRecordParserFactory().newInstance(), isDiscardRecords(), getDb());
|
|
96 | 96 |
} |
97 | 97 |
|
98 | 98 |
/** |
... | ... | |
101 | 101 |
@Override |
102 | 102 |
public MDStore readMDStore(final String mdId) throws MDStoreServiceException { |
103 | 103 |
final String internalId = transactionManager.readMdStore(mdId); |
104 |
return new MongoMDStore(mdId, db.getCollection(internalId, DBObject.class), getRecordParserFactory().newInstance(), isDiscardRecords(), getDb());
|
|
104 |
return new MongoMDStore(mdId, getDB().getCollection(internalId, DBObject.class), getRecordParserFactory().newInstance(), isDiscardRecords(), getDb());
|
|
105 | 105 |
} |
106 | 106 |
|
107 | 107 |
/** |
... | ... | |
110 | 110 |
@Override |
111 | 111 |
public MDStore startTransaction(final String mdId, final boolean refresh) throws MDStoreServiceException { |
112 | 112 |
final String transactionId = transactionManager.startTransaction(mdId, refresh); |
113 |
return new MongoMDStore(transactionId, db.getCollection(transactionId, DBObject.class), getRecordParserFactory().newInstance(), isDiscardRecords(),
|
|
113 |
return new MongoMDStore(transactionId, getDB().getCollection(transactionId, DBObject.class), getRecordParserFactory().newInstance(), isDiscardRecords(),
|
|
114 | 114 |
getDb()); |
115 | 115 |
} |
116 | 116 |
|
... | ... | |
119 | 119 |
*/ |
120 | 120 |
@Override |
121 | 121 |
public List<MDStoreDescription> listMDStores() { |
122 |
return MappedCollection.listMap(db.getCollection(METADATA_NAME, DBObject.class).find(), new UnaryFunction<MDStoreDescription, DBObject>() {
|
|
122 |
return MappedCollection.listMap(getDB().getCollection(METADATA_NAME, DBObject.class).find(), new UnaryFunction<MDStoreDescription, DBObject>() {
|
|
123 | 123 |
|
124 | 124 |
@Override |
125 | 125 |
public MDStoreDescription evaluate(final DBObject input) { |
... | ... | |
146 | 146 |
log.debug("Size not Found in metadata for mdId :" + mdId + " calling getCount "); |
147 | 147 |
size = currentMDStore.getSize(); |
148 | 148 |
input.put("size", size); |
149 |
db.getCollection(METADATA_NAME, DBObject.class).findOneAndReplace(new BasicDBObject(MD_ID, mdId), input);
|
|
149 |
getDB().getCollection(METADATA_NAME, DBObject.class).findOneAndReplace(new BasicDBObject(MD_ID, mdId), input);
|
|
150 | 150 |
} |
151 | 151 |
} |
152 | 152 |
if (currentMDStore != null) { |
... | ... | |
168 | 168 |
@Override |
169 | 169 |
public List<String> listMDStores(final String format, final String layout, final String interpretation) { |
170 | 170 |
return MappedCollection.listMap( |
171 |
FilteredCollection.listFilter(db.getCollection(METADATA_NAME, DBObject.class).find(), MDStoreUtils.dboFilter(format, layout, interpretation)),
|
|
171 |
FilteredCollection.listFilter(getDB().getCollection(METADATA_NAME, DBObject.class).find(), MDStoreUtils.dboFilter(format, layout, interpretation)),
|
|
172 | 172 |
MDStoreUtils.mdId()); |
173 | 173 |
} |
174 | 174 |
|
... | ... | |
178 | 178 |
@Override |
179 | 179 |
public int getCachedSize(final String id) throws MDStoreServiceException { |
180 | 180 |
log.debug("retrieve cached size for mdstore: " + id); |
181 |
final DBObject desc = db.getCollection(METADATA_NAME, DBObject.class).find(new BasicDBObject(MD_ID, id)).first();
|
|
181 |
final DBObject desc = getDB().getCollection(METADATA_NAME, DBObject.class).find(new BasicDBObject(MD_ID, id)).first();
|
|
182 | 182 |
if (!desc.containsField(SIZE)) { |
183 | 183 |
desc.put(SIZE, getMDStore(id).getSize()); |
184 | 184 |
} |
... | ... | |
202 | 202 |
*/ |
203 | 203 |
@Override |
204 | 204 |
public int refreshSize(final String mdStoreId) throws MDStoreServiceException { |
205 |
final int size = (int) db.getCollection(transactionManager.getMDStoreCollection(mdStoreId)).count();
|
|
206 |
final MongoCollection<DBObject> metadata = db.getCollection(METADATA_NAME, DBObject.class);
|
|
205 |
final int size = (int) getDB().getCollection(transactionManager.getMDStoreCollection(mdStoreId)).count();
|
|
206 |
final MongoCollection<DBObject> metadata = getDB().getCollection(METADATA_NAME, DBObject.class);
|
|
207 | 207 |
metadata.updateOne(new BasicDBObject(MD_ID, mdStoreId), new BasicDBObject("$set", new BasicDBObject(SIZE, size))); |
208 | 208 |
return size; |
209 | 209 |
} |
210 | 210 |
|
211 | 211 |
@Override |
212 | 212 |
public int getSumOfSizes(final String format, final String layout, final String interpretation) throws MDStoreServiceException { |
213 |
final MongoCollection<DBObject> metadata = db.getCollection(METADATA_NAME, DBObject.class);
|
|
213 |
final MongoCollection<DBObject> metadata = getDB().getCollection(METADATA_NAME, DBObject.class);
|
|
214 | 214 |
BasicDBObject matchObj = (BasicDBObject) BasicDBObjectBuilder.start("$match", |
215 | 215 |
BasicDBObjectBuilder.start("format", format).add("layout", layout).add("interpretation", interpretation).get()).get(); |
216 | 216 |
BasicDBObject groupObj = (BasicDBObject) BasicDBObjectBuilder.start("$group", |
... | ... | |
289 | 289 |
|
290 | 290 |
@Override |
291 | 291 |
public MDStoreDBStatus getDBStatus() { |
292 |
final int handledDatastructures = Ints.saturatedCast(db.getCollection(METADATA_NAME).count());
|
|
293 |
//final int usedDiskSpace = Ints.saturatedCast(db.getStats().getLong("storageSize") / (1024 * 1024)); // in MB
|
|
292 |
final int handledDatastructures = Ints.saturatedCast(getDB().getCollection(METADATA_NAME).count());
|
|
293 |
//final int usedDiskSpace = Ints.saturatedCast(getDB().getStats().getLong("storageSize") / (1024 * 1024)); // in MB
|
|
294 | 294 |
//{ dbStats: 1, scale: 1 } |
295 | 295 |
BasicDBObject statsQuery = new BasicDBObject("dbStats", 1); |
296 | 296 |
statsQuery.put("scale", 1024 * 1024); //storageSize in MB |
297 |
final Document statsRes = db.runCommand(statsQuery);
|
|
297 |
final Document statsRes = getDB().runCommand(statsQuery);
|
|
298 | 298 |
log.debug("DBStatus -- " + statsRes.toJson()); |
299 | 299 |
int usedDiskSpace = 0; |
300 | 300 |
//trying to handle different versions of the mongo server: old version returns storage size as long, new version as double |
... | ... | |
322 | 322 |
|
323 | 323 |
} |
324 | 324 |
|
325 |
public MongoDatabase getDB() { |
|
326 |
return db; |
|
327 |
} |
|
328 |
|
|
325 | 329 |
} |
Also available in: Unified diff
added getter for backing database