use of com.mongodb.Block in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentCollectionManagerAsync method select.
@Override
public void select(DocumentQuery query, Consumer<List<DocumentEntity>> callBack) throws ExecuteAsyncQueryException, UnsupportedOperationException {
String collectionName = query.getDocumentCollection();
MongoCollection<Document> collection = asyncMongoDatabase.getCollection(collectionName);
Bson mongoDBQuery = query.getCondition().map(DocumentQueryConversor::convert).orElse(EMPTY);
List<DocumentEntity> entities = new CopyOnWriteArrayList<>();
FindIterable<Document> result = collection.find(mongoDBQuery);
Block<Document> documentBlock = d -> entities.add(createEntity(collectionName, d));
SingleResultCallback<Void> voidSingleResultCallback = (v, e) -> callBack.accept(entities);
result.forEach(documentBlock, voidSingleResultCallback);
}
use of com.mongodb.Block in project repairnator by Spirals-Team.
the class CheckIfFutureBuildIdWhereWellComputed method main.
public static void main(String[] args) throws IOException {
List<String> allIds = Files.readAllLines(new File(args[0]).toPath());
String dbCollectionUrl = args[1];
String dbName = args[2];
String collectionName = args[3];
final List<String> projectsNames = Files.readAllLines(new File(args[4]).toPath());
String githubLogin = args[5];
String githubToken = args[6];
RepairnatorConfig.getInstance().setGithubLogin(githubLogin);
RepairnatorConfig.getInstance().setGithubToken(githubToken);
MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
MongoDatabase database = mongoConnection.getMongoDatabase();
MongoCollection collection = database.getCollection(collectionName);
Calendar limitDateMay = Calendar.getInstance();
limitDateMay.set(2017, Calendar.MAY, 10);
HashMap<String, List<Integer>> results = new HashMap<>();
Block<Document> block = new Block<Document>() {
@Override
public void apply(Document document) {
Object pBuildId = document.get("previousBuildId");
if (pBuildId instanceof Integer) {
int previousBuildId = document.getInteger("previousBuildId", -1);
int nextBuildId = document.getInteger("buildId", -1);
if (previousBuildId != -1 && nextBuildId != -1) {
Build previousBuild = BuildHelper.getBuildFromId(previousBuildId, null);
Build nextBuild = BuildHelper.getNextBuildOfSameBranchOfStatusAfterBuild(previousBuild, null);
if (nextBuild.getId() != nextBuildId) {
String projectName = previousBuild.getRepository().getSlug();
if (projectsNames == null || projectsNames.contains(projectName)) {
if (!results.containsKey(projectName)) {
results.put(projectName, new ArrayList<>());
}
results.get(projectName).add(previousBuildId);
i++;
}
}
}
}
}
};
for (String s : allIds) {
int buildId = Integer.parseInt(s);
collection.find(and(gt("buildReproductionDate", limitDateMay.getTime()), eq("previousBuildId", buildId), eq("lastReproducedBuggyBuild", true))).forEach(block);
}
System.out.println(allIds.size() + " ids read, and got: " + i);
System.out.println(results.keySet().size() + " detected projects: (" + StringUtils.join(results.keySet(), ",") + ")");
System.out.println("Results:");
for (String s : results.keySet()) {
System.out.println("Project " + s + " : ");
System.out.println(StringUtils.join(results.get(s), "\n"));
System.out.println("\n");
}
}
use of com.mongodb.Block in project repairnator by Spirals-Team.
the class UpdateDataForSpecifyingLastReproduction method main.
public static void main(String[] args) {
String dbConnectionUrl = args[0];
String dbName = args[1];
String collectionName = args[2];
MongoConnection mongoConnection = new MongoConnection(dbConnectionUrl, dbName);
MongoDatabase database = mongoConnection.getMongoDatabase();
MongoCollection collection = database.getCollection(collectionName);
Calendar limitDateMay = Calendar.getInstance();
limitDateMay.set(2017, Calendar.MAY, 10);
final List<ObjectId> updatedDocs = new ArrayList<>();
Set<Integer> ids = new HashSet<>();
Block<Document> block = new Block<Document>() {
@Override
public void apply(Document document) {
ObjectId documentId = document.getObjectId("_id");
Object pBuildId = document.get("previousBuildId");
if (pBuildId instanceof Integer) {
int previousBuildId = document.getInteger("previousBuildId", -1);
if (previousBuildId != -1) {
boolean lastReproducedBuggyBuild = !ids.contains(previousBuildId);
ids.add(previousBuildId);
document.append("lastReproducedBuggyBuild", lastReproducedBuggyBuild);
collection.replaceOne(eq("_id", documentId), document, new UpdateOptions().upsert(true));
updatedDocs.add(documentId);
}
}
}
};
collection.find().sort(orderBy(descending("buildReproductionDate"))).forEach(block);
System.out.println("Updated docs: " + updatedDocs.size());
}
use of com.mongodb.Block in project repairnator by Spirals-Team.
the class CleanNopolCollection method main.
public static void main(String[] args) {
Map<Integer, Set<String>> presentInDb = new HashMap<>();
String dbCollectionUrl = args[0];
String dbName = args[1];
String collectionName = args[2];
MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
MongoDatabase database = mongoConnection.getMongoDatabase();
MongoCollection collection = database.getCollection(collectionName);
Block<Document> block = new Block<Document>() {
@Override
public void apply(Document document) {
int buildId = document.getInteger("buildId");
String location = document.getString("testClassLocation");
ObjectId id = document.getObjectId("_id");
if (presentInDb.containsKey(buildId)) {
Set<String> localSet = presentInDb.get(buildId);
if (localSet.contains(location)) {
collection.deleteOne(eq("_id", id));
counterDeleted++;
return;
} else {
localSet.add(location);
}
} else {
Set<String> localSet = new HashSet<>();
localSet.add(location);
presentInDb.put(buildId, localSet);
}
counterKept++;
}
};
collection.find().forEach(block);
System.out.println(counterDeleted + " entries deleted and " + counterKept + " kept.");
}
use of com.mongodb.Block in project repairnator by Spirals-Team.
the class RemoveDuplicatedBuildsId method main.
public static void main(String[] args) {
Set<Integer> buildIds = new HashSet<>();
String dbCollectionUrl = args[0];
String dbName = args[1];
String collectionName = args[2];
MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
MongoDatabase database = mongoConnection.getMongoDatabase();
MongoCollection collection = database.getCollection(collectionName);
Block<Document> block = new Block<Document>() {
@Override
public void apply(Document document) {
int buildId = document.getInteger("buildId");
ObjectId id = document.getObjectId("_id");
if (buildIds.contains(buildId)) {
collection.deleteOne(eq("_id", id));
counterDeleted++;
return;
} else {
buildIds.add(buildId);
counterKept++;
}
}
};
collection.find().sort(orderBy(descending("buildReproductionDate"))).forEach(block);
System.out.println(counterDeleted + " entries deleted and " + counterKept + " kept.");
}
Aggregations