com.versioneye.persistence.mongodb.ArtefactDao Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of versioneye-core-j Show documentation
Show all versions of versioneye-core-j Show documentation
This is the java implementation of the VersionEye core services. It contains
some buisiness logic and utility classes.
package com.versioneye.persistence.mongodb;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.versioneye.domain.Artefact;
import com.versioneye.persistence.IArtefactDao;
public class ArtefactDao implements IArtefactDao {
private MongoDB mongoDB;
private DBCollection getCollection(){
return mongoDB.getDb().getCollection(Artefact.ARTEFACTS);
}
public void create(Artefact artefact) {
DBCollection artefacts = getCollection();
artefacts.insert(artefact.getDBObject());
}
public Artefact getBySha(String sha) {
BasicDBObject match = new BasicDBObject();
match.put(Artefact.SHA_VALUE, sha);
DBCursor cursor = getCollection().find(match);
if (!cursor.hasNext())
return null;
DBObject artefactObj = cursor.next();
Artefact artefact = new Artefact();
artefact.updateFromDBObject(artefactObj);
return artefact;
}
public MongoDB getMongoDB() {
return mongoDB;
}
public void setMongoDB(MongoDB mongoDB) {
this.mongoDB = mongoDB;
}
}