@Test public void testSaveMatches() throws Exception { final String pId = "save.p"; List<CanvasMatches> canvasMatchesList = new ArrayList<>(); for (int i = 1; i < 4; i++) { canvasMatchesList.add(new CanvasMatches(groupId, pId, groupId + i, "save.q", new Matches(new double[][]{{1, 2, 3}, {4, 5, 6},}, new double[][]{{11, 12, 13}, {14, 15, 16}}, new double[]{7, 8, 9}))); } dao.saveMatches(collectionId, canvasMatchesList); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024); dao.writeMatchesOutsideGroup(collectionId, null, groupId, false, outputStream); canvasMatchesList = getListFromStream(outputStream); Assert.assertEquals("invalid number of matches returned, matches=" + canvasMatchesList, 5, canvasMatchesList.size()); CanvasMatches lastSavedMatchPair = null; int savePCount = 0; for (final CanvasMatches canvasMatches : canvasMatchesList) { if (pId.equals(canvasMatches.getpId())) { savePCount++; lastSavedMatchPair = canvasMatches; } } Assert.assertEquals("invalid number of matches saved", 3, savePCount); if (lastSavedMatchPair != null) { final Integer wLength = lastSavedMatchPair.getMatches().getWs().length; Assert.assertEquals("invalid match count for last pair", wLength, lastSavedMatchPair.getMatchCount()); } }
public void saveMatches(final MatchCollectionId collectionId, final List<CanvasMatches> matchesList) throws IllegalArgumentException { MongoUtil.validateRequiredParameter("matchesList", matchesList); LOG.debug("saveMatches: entry, collectionId={}, matchesList.size()={}", collectionId, matchesList.size()); if (matchesList.size() > 0) { final MongoCollection<Document> collection = matchDatabase.getCollection(collectionId.getDbCollectionName()); ensureMatchIndexes(collection); final List<WriteModel<Document>> modelList = new ArrayList<>(matchesList.size()); final UpdateOptions upsertOption = new UpdateOptions().upsert(true); Document filter; Document matchesObject; for (final CanvasMatches canvasMatches : matchesList) { canvasMatches.normalize(); filter = new Document( "pGroupId", canvasMatches.getpGroupId()).append( "pId", canvasMatches.getpId()).append( "qGroupId", canvasMatches.getqGroupId()).append( "qId", canvasMatches.getqId()); matchesObject = Document.parse(canvasMatches.toJson()); modelList.add(new ReplaceOneModel<>(filter, matchesObject, upsertOption)); } final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION); if (LOG.isDebugEnabled()) { final String bulkResultMessage = MongoUtil.toMessage("matches", result, matchesList.size()); LOG.debug("saveMatches: {} using {}.initializeUnorderedBulkOp()", bulkResultMessage, MongoUtil.fullName(collection)); } } }
MatchDao { public void saveMatches(final MatchCollectionId collectionId, final List<CanvasMatches> matchesList) throws IllegalArgumentException { MongoUtil.validateRequiredParameter("matchesList", matchesList); LOG.debug("saveMatches: entry, collectionId={}, matchesList.size()={}", collectionId, matchesList.size()); if (matchesList.size() > 0) { final MongoCollection<Document> collection = matchDatabase.getCollection(collectionId.getDbCollectionName()); ensureMatchIndexes(collection); final List<WriteModel<Document>> modelList = new ArrayList<>(matchesList.size()); final UpdateOptions upsertOption = new UpdateOptions().upsert(true); Document filter; Document matchesObject; for (final CanvasMatches canvasMatches : matchesList) { canvasMatches.normalize(); filter = new Document( "pGroupId", canvasMatches.getpGroupId()).append( "pId", canvasMatches.getpId()).append( "qGroupId", canvasMatches.getqGroupId()).append( "qId", canvasMatches.getqId()); matchesObject = Document.parse(canvasMatches.toJson()); modelList.add(new ReplaceOneModel<>(filter, matchesObject, upsertOption)); } final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION); if (LOG.isDebugEnabled()) { final String bulkResultMessage = MongoUtil.toMessage("matches", result, matchesList.size()); LOG.debug("saveMatches: {} using {}.initializeUnorderedBulkOp()", bulkResultMessage, MongoUtil.fullName(collection)); } } } }
MatchDao { public void saveMatches(final MatchCollectionId collectionId, final List<CanvasMatches> matchesList) throws IllegalArgumentException { MongoUtil.validateRequiredParameter("matchesList", matchesList); LOG.debug("saveMatches: entry, collectionId={}, matchesList.size()={}", collectionId, matchesList.size()); if (matchesList.size() > 0) { final MongoCollection<Document> collection = matchDatabase.getCollection(collectionId.getDbCollectionName()); ensureMatchIndexes(collection); final List<WriteModel<Document>> modelList = new ArrayList<>(matchesList.size()); final UpdateOptions upsertOption = new UpdateOptions().upsert(true); Document filter; Document matchesObject; for (final CanvasMatches canvasMatches : matchesList) { canvasMatches.normalize(); filter = new Document( "pGroupId", canvasMatches.getpGroupId()).append( "pId", canvasMatches.getpId()).append( "qGroupId", canvasMatches.getqGroupId()).append( "qId", canvasMatches.getqId()); matchesObject = Document.parse(canvasMatches.toJson()); modelList.add(new ReplaceOneModel<>(filter, matchesObject, upsertOption)); } final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION); if (LOG.isDebugEnabled()) { final String bulkResultMessage = MongoUtil.toMessage("matches", result, matchesList.size()); LOG.debug("saveMatches: {} using {}.initializeUnorderedBulkOp()", bulkResultMessage, MongoUtil.fullName(collection)); } } } MatchDao(final MongoClient client); }
MatchDao { public void saveMatches(final MatchCollectionId collectionId, final List<CanvasMatches> matchesList) throws IllegalArgumentException { MongoUtil.validateRequiredParameter("matchesList", matchesList); LOG.debug("saveMatches: entry, collectionId={}, matchesList.size()={}", collectionId, matchesList.size()); if (matchesList.size() > 0) { final MongoCollection<Document> collection = matchDatabase.getCollection(collectionId.getDbCollectionName()); ensureMatchIndexes(collection); final List<WriteModel<Document>> modelList = new ArrayList<>(matchesList.size()); final UpdateOptions upsertOption = new UpdateOptions().upsert(true); Document filter; Document matchesObject; for (final CanvasMatches canvasMatches : matchesList) { canvasMatches.normalize(); filter = new Document( "pGroupId", canvasMatches.getpGroupId()).append( "pId", canvasMatches.getpId()).append( "qGroupId", canvasMatches.getqGroupId()).append( "qId", canvasMatches.getqId()); matchesObject = Document.parse(canvasMatches.toJson()); modelList.add(new ReplaceOneModel<>(filter, matchesObject, upsertOption)); } final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION); if (LOG.isDebugEnabled()) { final String bulkResultMessage = MongoUtil.toMessage("matches", result, matchesList.size()); LOG.debug("saveMatches: {} using {}.initializeUnorderedBulkOp()", bulkResultMessage, MongoUtil.fullName(collection)); } } } MatchDao(final MongoClient client); static MatchDao build(); List<MatchCollectionMetaData> getMatchCollectionMetaData(); List<String> getDistinctPGroupIds(final MatchCollectionId collectionId); List<String> getDistinctQGroupIds(final MatchCollectionId collectionId); List<String> getDistinctGroupIds(final MatchCollectionId collectionId); List<String> getMultiConsensusPGroupIds(final MatchCollectionId collectionId); Set<String> getMultiConsensusGroupIds(final MatchCollectionId collectionId); void writeMatchesWithPGroup(final MatchCollectionId collectionId,
                                       final List<MatchCollectionId> mergeCollectionIdList,
                                       final String pGroupId,
                                       final boolean excludeMatchDetails,
                                       final OutputStream outputStream); void writeMatchesWithinGroup(final MatchCollectionId collectionId,
                                        final List<MatchCollectionId> mergeCollectionIdList,
                                        final String groupId,
                                        final boolean excludeMatchDetails,
                                        final OutputStream outputStream); void writeMatchesOutsideGroup(final MatchCollectionId collectionId,
                                         final List<MatchCollectionId> mergeCollectionIdList,
                                         final String groupId,
                                         final boolean excludeMatchDetails,
                                         final OutputStream outputStream); List<CanvasMatches> getMatchesWithinGroup(final MatchCollectionId collectionId,
                                                     final String groupId,
                                                     final boolean excludeMatchDetails); List<CanvasMatches> getMatchesOutsideGroup(final MatchCollectionId collectionId,
                                                      final String groupId,
                                                      final boolean excludeMatchDetails); List<CanvasMatches> getMatchesBetweenGroups(final MatchCollectionId collectionId,
                                                       final String pGroupId,
                                                       final String qGroupId,
                                                       final boolean excludeMatchDetails); void writeMatchesBetweenGroups(final MatchCollectionId collectionId,
                                          final List<MatchCollectionId> mergeCollectionIdList,
                                          final String pGroupId,
                                          final String qGroupId,
                                          final boolean excludeMatchDetails,
                                          final OutputStream outputStream); void writeMatchesBetweenObjectAndGroup(final MatchCollectionId collectionId,
                                                  final List<MatchCollectionId> mergeCollectionIdList,
                                                  final String pGroupId,
                                                  final String pId,
                                                  final String qGroupId,
                                                  final boolean excludeMatchDetails,
                                                  final OutputStream outputStream); CanvasMatches getMatchesBetweenObjects(final MatchCollectionId collectionId,
                                                  final String pGroupId,
                                                  final String pId,
                                                  final String qGroupId,
                                                  final String qId); void writeMatchesBetweenObjects(final MatchCollectionId collectionId,
                                           final List<MatchCollectionId> mergeCollectionIdList,
                                           final String pGroupId,
                                           final String pId,
                                           final String qGroupId,
                                           final String qId,
                                           final OutputStream outputStream); void writeMatchesInvolvingObject(final MatchCollectionId collectionId,
                                            final List<MatchCollectionId> mergeCollectionIdList,
                                            final String groupId,
                                            final String id,
                                            final OutputStream outputStream); void removeMatchesInvolvingObject(final MatchCollectionId collectionId,
                                             final String groupId,
                                             final String id); void removeMatchesBetweenTiles(final MatchCollectionId collectionId,
                                          final String pGroupId,
                                          final String pId,
                                          final String qGroupId,
                                          final String qId); void removeMatchesBetweenGroups(final MatchCollectionId collectionId,
                                           final String pGroupId,
                                           final String qGroupId); void removeMatchesWithPGroup(final MatchCollectionId collectionId,
                                        final String pGroupId); void removeMatchesOutsideGroup(final MatchCollectionId collectionId,
                                          final String groupId); void saveMatches(final MatchCollectionId collectionId,
                            final List<CanvasMatches> matchesList); void removeAllMatches(final MatchCollectionId collectionId); void renameMatchCollection(final MatchCollectionId fromCollectionId,
                                      final MatchCollectionId toCollectionId); MatchTrial getMatchTrial(final String trialId); MatchTrial insertMatchTrial(final MatchTrial matchTrial); void updateMatchCountsForPGroup(final MatchCollectionId collectionId,
                                           final String pGroupId); }
MatchDao { public void saveMatches(final MatchCollectionId collectionId, final List<CanvasMatches> matchesList) throws IllegalArgumentException { MongoUtil.validateRequiredParameter("matchesList", matchesList); LOG.debug("saveMatches: entry, collectionId={}, matchesList.size()={}", collectionId, matchesList.size()); if (matchesList.size() > 0) { final MongoCollection<Document> collection = matchDatabase.getCollection(collectionId.getDbCollectionName()); ensureMatchIndexes(collection); final List<WriteModel<Document>> modelList = new ArrayList<>(matchesList.size()); final UpdateOptions upsertOption = new UpdateOptions().upsert(true); Document filter; Document matchesObject; for (final CanvasMatches canvasMatches : matchesList) { canvasMatches.normalize(); filter = new Document( "pGroupId", canvasMatches.getpGroupId()).append( "pId", canvasMatches.getpId()).append( "qGroupId", canvasMatches.getqGroupId()).append( "qId", canvasMatches.getqId()); matchesObject = Document.parse(canvasMatches.toJson()); modelList.add(new ReplaceOneModel<>(filter, matchesObject, upsertOption)); } final BulkWriteResult result = collection.bulkWrite(modelList, MongoUtil.UNORDERED_OPTION); if (LOG.isDebugEnabled()) { final String bulkResultMessage = MongoUtil.toMessage("matches", result, matchesList.size()); LOG.debug("saveMatches: {} using {}.initializeUnorderedBulkOp()", bulkResultMessage, MongoUtil.fullName(collection)); } } } MatchDao(final MongoClient client); static MatchDao build(); List<MatchCollectionMetaData> getMatchCollectionMetaData(); List<String> getDistinctPGroupIds(final MatchCollectionId collectionId); List<String> getDistinctQGroupIds(final MatchCollectionId collectionId); List<String> getDistinctGroupIds(final MatchCollectionId collectionId); List<String> getMultiConsensusPGroupIds(final MatchCollectionId collectionId); Set<String> getMultiConsensusGroupIds(final MatchCollectionId collectionId); void writeMatchesWithPGroup(final MatchCollectionId collectionId,
                                       final List<MatchCollectionId> mergeCollectionIdList,
                                       final String pGroupId,
                                       final boolean excludeMatchDetails,
                                       final OutputStream outputStream); void writeMatchesWithinGroup(final MatchCollectionId collectionId,
                                        final List<MatchCollectionId> mergeCollectionIdList,
                                        final String groupId,
                                        final boolean excludeMatchDetails,
                                        final OutputStream outputStream); void writeMatchesOutsideGroup(final MatchCollectionId collectionId,
                                         final List<MatchCollectionId> mergeCollectionIdList,
                                         final String groupId,
                                         final boolean excludeMatchDetails,
                                         final OutputStream outputStream); List<CanvasMatches> getMatchesWithinGroup(final MatchCollectionId collectionId,
                                                     final String groupId,
                                                     final boolean excludeMatchDetails); List<CanvasMatches> getMatchesOutsideGroup(final MatchCollectionId collectionId,
                                                      final String groupId,
                                                      final boolean excludeMatchDetails); List<CanvasMatches> getMatchesBetweenGroups(final MatchCollectionId collectionId,
                                                       final String pGroupId,
                                                       final String qGroupId,
                                                       final boolean excludeMatchDetails); void writeMatchesBetweenGroups(final MatchCollectionId collectionId,
                                          final List<MatchCollectionId> mergeCollectionIdList,
                                          final String pGroupId,
                                          final String qGroupId,
                                          final boolean excludeMatchDetails,
                                          final OutputStream outputStream); void writeMatchesBetweenObjectAndGroup(final MatchCollectionId collectionId,
                                                  final List<MatchCollectionId> mergeCollectionIdList,
                                                  final String pGroupId,
                                                  final String pId,
                                                  final String qGroupId,
                                                  final boolean excludeMatchDetails,
                                                  final OutputStream outputStream); CanvasMatches getMatchesBetweenObjects(final MatchCollectionId collectionId,
                                                  final String pGroupId,
                                                  final String pId,
                                                  final String qGroupId,
                                                  final String qId); void writeMatchesBetweenObjects(final MatchCollectionId collectionId,
                                           final List<MatchCollectionId> mergeCollectionIdList,
                                           final String pGroupId,
                                           final String pId,
                                           final String qGroupId,
                                           final String qId,
                                           final OutputStream outputStream); void writeMatchesInvolvingObject(final MatchCollectionId collectionId,
                                            final List<MatchCollectionId> mergeCollectionIdList,
                                            final String groupId,
                                            final String id,
                                            final OutputStream outputStream); void removeMatchesInvolvingObject(final MatchCollectionId collectionId,
                                             final String groupId,
                                             final String id); void removeMatchesBetweenTiles(final MatchCollectionId collectionId,
                                          final String pGroupId,
                                          final String pId,
                                          final String qGroupId,
                                          final String qId); void removeMatchesBetweenGroups(final MatchCollectionId collectionId,
                                           final String pGroupId,
                                           final String qGroupId); void removeMatchesWithPGroup(final MatchCollectionId collectionId,
                                        final String pGroupId); void removeMatchesOutsideGroup(final MatchCollectionId collectionId,
                                          final String groupId); void saveMatches(final MatchCollectionId collectionId,
                            final List<CanvasMatches> matchesList); void removeAllMatches(final MatchCollectionId collectionId); void renameMatchCollection(final MatchCollectionId fromCollectionId,
                                      final MatchCollectionId toCollectionId); MatchTrial getMatchTrial(final String trialId); MatchTrial insertMatchTrial(final MatchTrial matchTrial); void updateMatchCountsForPGroup(final MatchCollectionId collectionId,
                                           final String pGroupId);  }