List of usage examples for com.mongodb BasicDBObject equals
@Override public boolean equals(final Object o)
From source file:com.avanza.ymer.FakeDocumentCollection.java
License:Apache License
@Override public void delete(BasicDBObject dbObject) { BasicDBObject idOBject = new BasicDBObject(); idOBject.put("_id", dbObject.get("_id")); if (idOBject.equals(dbObject)) { removeById(idOBject);//from w w w. j a v a 2 s . c o m } else { removeByTemplate(dbObject); } }
From source file:com.ikanow.infinit.e.api.knowledge.federated.SimpleFederatedQueryEngine.java
License:Open Source License
public void test_CheckIfDocAdded(String testName, List<BasicDBObject> docs) { // 1) Did a doc get added? if (2 != docs.size()) { System.out.println("*** " + testName + ": didn't add doc? " + docs.size()); System.exit(-1);//ww w . j a va 2 s.c om } // 2) Was it the right doc? BasicDBObject doc = docs.get(0); doc.remove(DocumentPojo._id_); doc.remove(DocumentPojo.created_); doc.remove(DocumentPojo.modified_); doc.remove(DocumentPojo.publishedDate_); String docToCheck = "{ \"displayUrl\" : \"http://test3_1\" , \"url\" : \"inf://federated/fakeendpoint.123/test3_1/testentityin\" , \"sourceKey\" : [ \"fakeendpoint.123\"] , \"source\" : [ \"fakeendpoint\"] , \"communityId\" : [ \"4c927585d591d31d7b37097a\"] , \"mediaType\" : [ \"Report\"] , \"metadata\" : { \"json\" : [ { \"test\" : { \"field\" : [ \"test3_1\" , \"test3_1\"] , \"field2\" : \"http://test3_1\"}}]} , \"title\" : \"fake endpoint: : test3_1: test3_1\" , \"entities\" : [ { \"disambiguated_name\" : \"test3_1\" , \"type\" : \"TestEntityOut\" , \"dimension\" : \"What\" , \"relevance\" : 1.0 , \"doccount\" : 1 , \"averageFreq\" : 1.0 , \"datasetSignificance\" : 10.0 , \"significance\" : 10.0 , \"frequency\" : 1.0 , \"index\" : \"test3_1/testentityout\" , \"queryCoverage\" : 100.0 , \"totalfrequency\" : 1.0}] , \"description\" : \"[\\n {\\n \\\"test\\\": {\\n \\\"field\\\": [\\n \\\"test3_1\\\",\\n \\\"test3_1\\\"\\n ],\\n \\\"field2\\\": \\\"http://test3_1\\\"\\n }\\n }\\n]\" , \"aggregateSignif\" : 115.0 , \"queryRelevance\" : 105.0 , \"score\" : 110.0}"; if (!docToCheck.equals(doc.toString())) { System.out.println( "*** " + testName + ": document incorrect:\n" + docToCheck + "\nVS\n" + doc.toString()); System.exit(-1); } // 3) Did the doc get cached? DBCollection endpointCacheCollection = getCacheCollection(); String hardwiredCacheId = "http://localhost:8186/test/test3_1/?param1=test3_1"; BasicDBObject cachedVal = (BasicDBObject) endpointCacheCollection .findOne(new BasicDBObject(SimpleFederatedCache._id_, hardwiredCacheId)); if (null == cachedVal) { System.out.println( "*** " + testName + ": no cache for: " + doc.get(DocumentPojo.url_) + " / " + hardwiredCacheId); System.exit(-1); } else { Date expiryDate = cachedVal.getDate(SimpleFederatedCache.expiryDate_, null); if ((null == expiryDate) || ((new Date().getTime() - expiryDate.getTime()) > 10 * 1000L)) { System.out.println("*** " + testName + ": expiry date for: " + doc.get(DocumentPojo.url_) + ": " + expiryDate + " vs now= " + new Date()); System.exit(-1); } BasicDBObject cachedJson = (BasicDBObject) cachedVal.get(SimpleFederatedCache.cachedJson_); Object docVal = null; try { Object[] docVals = (Object[]) ((BasicDBObject) doc.get(DocumentPojo.metadata_)).get("json"); docVal = docVals[0]; } catch (Exception e) { @SuppressWarnings("rawtypes") Collection docVals = (Collection) ((BasicDBObject) doc.get(DocumentPojo.metadata_)).get("json"); docVal = docVals.iterator().next(); } if ((null == cachedJson) || !cachedJson.equals(docVal)) { System.out.println("*** " + testName + ": cache: " + doc.get(DocumentPojo.url_) + ": cached val incorrect:\n" + docVal + "\nVS\n" + cachedJson); System.exit(-1); } } }
From source file:com.ikanow.infinit.e.data_model.custom.InfiniteMongoSplitter.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) private static int compareFields(int direction, BasicDBObject query, BasicDBObject minOrMax, BasicDBObject maxOrMin, Map<String, TreeSet<Comparable>> orderedArraySet, Map<String, NavigableSet<Comparable>> orderedArraySet_afterMin) { for (String field : minOrMax.keySet()) { //DEBUG//from w w w.j av a 2 s. c o m //System.out.println("1] Compare: " + field + ": " + direction); try { Object queryOfThisField = query.get(field); Object minField = minOrMax.get(field); if ((null != queryOfThisField) && (minField instanceof Comparable)) { int result = 0; Comparable comparableMinOrMaxElement = (Comparable) minField; if (queryOfThisField instanceof BasicDBObject) { result = compareComplexObject(field, direction, (BasicDBObject) queryOfThisField, comparableMinOrMaxElement, orderedArraySet, orderedArraySet_afterMin); } //TESTED else { // -1 if comparableQueryElement < comparableMinOrMaxElement Comparable comparableQueryElement = (Comparable) queryOfThisField; result = comparableQueryElement.compareTo(comparableMinOrMaxElement); //DEBUG //System.out.println("3] Vals: " + comparableQueryElement + " vs " + comparableMinOrMaxElement + " = " + result); } //TESTED if (result != 0) { // if we ever get a strict inequality then stop checking fields.. if ((result == direction) || !minOrMax.equals(maxOrMin)) { // (fail) (pass but min/max keys different so not point checking any more) return result; } //TESTED } // else equality, pass but keep checking fields } } catch (Exception e) { //DEBUG //e.printStackTrace(); } // do nothing probably some odd comparable issue } return -direction; // (ie pass by default) }
From source file:info.bunji.mongodb.synces.CollectionExtractor.java
License:Apache License
/** **********************************//from w ww. ja v a 2 s . com * * @param filter * @param id * @return ********************************** */ private BasicDBObject getFilterForInitialImport(BasicDBObject filter, Object id) { if (id == null) { return filter; } BasicDBObject idFilter = new BasicDBObject("_id", new BasicBSONObject(QueryOperators.GT, id)); if (filter == null || filter.equals(new BasicDBObject())) { return idFilter; } return new BasicDBObject(QueryOperators.AND, ImmutableList.of(filter, idFilter)); }