Revision 3d44d85c src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBStore.scala
b/src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBStore.scala | ||
---|---|---|
64 | 64 |
val database: String, |
65 | 65 |
val username: String, |
66 | 66 |
val password: String) |
67 |
extends ResourceEventStore with UserStateStore |
|
68 |
with WalletEntryStore with UserEventStore |
|
67 |
extends ResourceEventStore |
|
68 |
with UserStateStore |
|
69 |
with WalletEntryStore |
|
70 |
with UserEventStore |
|
69 | 71 |
with Loggable { |
70 | 72 |
|
71 | 73 |
private[store] lazy val rcEvents = getCollection(MongoDBStore.RESOURCE_EVENTS_COLLECTION) |
... | ... | |
212 | 214 |
def findUserWalletEntriesFromTo(userId: String, from: Date, to: Date) : List[WalletEntry] = { |
213 | 215 |
val q = new BasicDBObject() |
214 | 216 |
// TODO: Is this the correct way for an AND query? |
215 |
q.put(ResourceJsonNames.occurredMillis, new BasicDBObject("$gt", from.getTime))
|
|
216 |
q.put(ResourceJsonNames.occurredMillis, new BasicDBObject("$lt", to.getTime))
|
|
217 |
q.put(ResourceJsonNames.userId, userId)
|
|
217 |
q.put(WalletJsonNames.occurredMillis, new BasicDBObject("$gt", from.getTime))
|
|
218 |
q.put(WalletJsonNames.occurredMillis, new BasicDBObject("$lt", to.getTime))
|
|
219 |
q.put(WalletJsonNames.userId, userId)
|
|
218 | 220 |
|
219 | 221 |
MongoDBStore.runQuery[WalletEntry](q, walletEntries)(MongoDBStore.dbObjectToWalletEntry)(Some(_sortByTimestampAsc)) |
220 | 222 |
} |
221 | 223 |
|
222 | 224 |
def findWalletEntriesAfter(userId: String, from: Date) : List[WalletEntry] = { |
223 | 225 |
val q = new BasicDBObject() |
224 |
q.put(ResourceJsonNames.occurredMillis, new BasicDBObject("$gt", from.getTime))
|
|
225 |
q.put(ResourceJsonNames.userId, userId)
|
|
226 |
q.put(WalletJsonNames.occurredMillis, new BasicDBObject("$gt", from.getTime))
|
|
227 |
q.put(WalletJsonNames.userId, userId)
|
|
226 | 228 |
|
227 | 229 |
MongoDBStore.runQuery[WalletEntry](q, walletEntries)(MongoDBStore.dbObjectToWalletEntry)(Some(_sortByTimestampAsc)) |
228 | 230 |
} |
229 | 231 |
|
230 | 232 |
def findLatestUserWalletEntries(userId: String) = { |
231 | 233 |
Maybe { |
232 |
val orderBy = new BasicDBObject(ResourceJsonNames.occurredMillis, -1) // -1 is descending order
|
|
234 |
val orderBy = new BasicDBObject(WalletJsonNames.occurredMillis, -1) // -1 is descending order
|
|
233 | 235 |
val cursor = walletEntries.find().sort(orderBy) |
234 | 236 |
|
235 | 237 |
try { |
Also available in: Unified diff