DbMarketDataSnapshotMaster extends AbstractDocumentDbMaster<MarketDataSnapshotDocument> implements MarketDataSnapshotMaster { public MarketDataSnapshotSearchResult search(final MarketDataSnapshotSearchRequest request) { ArgumentChecker.notNull(request, "request"); ArgumentChecker.notNull(request.getPagingRequest(), "request.pagingRequest"); ArgumentChecker.notNull(request.getVersionCorrection(), "request.versionCorrection"); s_logger.debug("search {}", request); final VersionCorrection vc = request.getVersionCorrection().withLatestFixed(now()); final MarketDataSnapshotSearchResult result = new MarketDataSnapshotSearchResult(vc); final List<ObjectId> snapshotIds = request.getSnapshotIds(); if (snapshotIds != null && snapshotIds.size() == 0) { result.setPaging(Paging.of(request.getPagingRequest(), 0)); return result; } final DbMapSqlParameterSource args = createParameterSource(); args.addTimestamp("version_as_of_instant", vc.getVersionAsOf()); args.addTimestamp("corrected_to_instant", vc.getCorrectedTo()); args.addValueNullIgnored("name", getDialect().sqlWildcardAdjustValue(request.getName())); args.addValueNullIgnored("snapshot_type", request.getType() == null ? null : request.getType().getName()); args.addValue("details", request.isIncludeData()); if (snapshotIds != null) { StringBuilder buf = new StringBuilder(snapshotIds.size() * 10); for (ObjectId snapshotId : snapshotIds) { checkScheme(snapshotId); buf.append(extractOid(snapshotId)).append(", "); } buf.setLength(buf.length() - 2); args.addValue("sql_search_object_ids", buf.toString()); } args.addValue("sort_order", ORDER_BY_MAP.get(request.getSortOrder())); args.addValue("paging_offset", request.getPagingRequest().getFirstItem()); args.addValue("paging_fetch", request.getPagingRequest().getPagingSize()); String[] sql = {getElSqlBundle().getSql("Search", args), getElSqlBundle().getSql("SearchCount", args)}; doSearch(request.getPagingRequest(), sql, args, new MarketDataSnapshotDocumentExtractor(request.isIncludeData()), result); return result; } DbMarketDataSnapshotMaster(DbConnector dbConnector); MarketDataSnapshotSearchResult search(final MarketDataSnapshotSearchRequest request); @Override MarketDataSnapshotDocument get(final UniqueId uniqueId); @Override MarketDataSnapshotDocument get(final ObjectIdentifiable objectId, final VersionCorrection versionCorrection); MarketDataSnapshotHistoryResult history(final MarketDataSnapshotHistoryRequest request); static final String IDENTIFIER_SCHEME_DEFAULT; }
@Test public void test_find_alternative_snapshot_by_name() throws Exception { NamedSnapshot snapshot1 = new MockNamedSnapshot(null, "Test 1", 42); MarketDataSnapshotDocument doc1 = new MarketDataSnapshotDocument(snapshot1); _snpMaster.add(doc1); NamedSnapshot snapshot2 = new MockNamedSnapshot(null, "Test 2", 84); MarketDataSnapshotDocument doc2 = new MarketDataSnapshotDocument(snapshot2); _snpMaster.add(doc2); MarketDataSnapshotSearchRequest request = new MarketDataSnapshotSearchRequest(); request.setName(doc1.getName()); MarketDataSnapshotSearchResult result = _snpMaster.search(request); assertTrue(result.getDocuments().size() > 0); }
@Test public void test_find_alternative_snapshot_by_name_and_type() throws Exception { NamedSnapshot snapshot1 = new MockAlternativeNamedSnapshot(null, "TestSameName", 42); MarketDataSnapshotDocument doc1 = new MarketDataSnapshotDocument(snapshot1); _snpMaster.add(doc1); NamedSnapshot snapshot2 = new MockNamedSnapshot(null, "TestSameName", 84); MarketDataSnapshotDocument doc2 = new MarketDataSnapshotDocument(snapshot2); _snpMaster.add(doc2); MarketDataSnapshotSearchRequest request1 = new MarketDataSnapshotSearchRequest(); request1.setType(MockNamedSnapshot.class); request1.setName("TestSameName"); MarketDataSnapshotSearchResult result1 = _snpMaster.search(request1); assertTrue(result1.getDocuments().size() == 1); MarketDataSnapshotSearchRequest request2 = new MarketDataSnapshotSearchRequest(); request2.setName("TestSameName"); MarketDataSnapshotSearchResult result2 = _snpMaster.search(request2); assertTrue(result2.getDocuments().size() == 2); }