use of com.mongodb.DBCursor in project sling by apache.
the class MongoDBResourceProvider method delete.
/**
* TODO - we should handle delete different and not put all child resources into the
* deleted set.
* Instead when getting resources, the parents of the resource should be checked
* first.
* This minimizes concurrency issues.
* @see org.apache.sling.api.resource.ModifyingResourceProvider#delete(org.apache.sling.api.resource.ResourceResolver, java.lang.String)
*/
public void delete(final ResourceResolver resolver, final String path) throws PersistenceException {
final String[] info = this.extractResourceInfo(path);
if (info != null) {
boolean deletedResource = false;
if (!deletedResources.contains(path)) {
final Resource rsrc = this.getResource(resolver, path, info);
if (rsrc instanceof MongoDBResource) {
this.deletedResources.add(path);
this.changedResources.remove(path);
final DBCollection col = this.getCollection(info[0]);
final String pattern = "^" + Pattern.quote(info[1]) + "/";
final DBObject query = QueryBuilder.start(getPROP_PATH()).regex(Pattern.compile(pattern)).get();
final DBCursor cur = col.find(query);
while (cur.hasNext()) {
final DBObject dbObj = cur.next();
final String childPath = info[0] + '/' + dbObj.get(getPROP_PATH());
this.deletedResources.add(childPath);
this.changedResources.remove(childPath);
}
deletedResource = true;
}
} else {
deletedResource = true;
}
if (deletedResource) {
final String prefix = path + "/";
final Iterator<Map.Entry<String, MongoDBResource>> i = this.changedResources.entrySet().iterator();
while (i.hasNext()) {
final Map.Entry<String, MongoDBResource> entry = i.next();
if (entry.getKey().startsWith(prefix)) {
i.remove();
}
}
return;
}
}
throw new PersistenceException("Unable to delete resource at {}" + path, null, path, null);
}
use of com.mongodb.DBCursor in project felix by apache.
the class MongoDBStore method getRole.
@Override
public Role getRole(String name) {
DBCollection coll = getCollection();
DBCursor cursor = coll.find(getTemplateObject(name));
try {
if (cursor.hasNext()) {
return m_helper.deserialize(cursor.next());
}
} finally {
cursor.close();
}
return null;
}
use of com.mongodb.DBCursor in project incubator-rya by apache.
the class SimpleMongoDBNamespaceManager method iterateNamespace.
@Override
public CloseableIteration<? extends Namespace, RyaDAOException> iterateNamespace() throws RyaDAOException {
final DBObject query = new BasicDBObject();
final DBCursor cursor = nsColl.find(query);
return new MongoCursorIteration(cursor);
}
use of com.mongodb.DBCursor in project Twister by NicolasBizzozzero.
the class MessagesTools method getTousLesMessages.
/**
* Permet d'obtenir tous les messages contenus dans la collection "Messages"
* Utilisee seulement a des fins de debugage
* @return Un JSONObject contenant tous les messages
* @throws UnknownHostException
*/
public static JSONObject getTousLesMessages() throws UnknownHostException {
// On se connecte a la BDD puis on recupere les messages
DBCollection messages = getCollectionMessages();
// On itere sur les resultats
DBCursor curseur = messages.find();
JSONObject reponse = new JSONObject();
while (curseur.hasNext()) {
reponse.accumulate("Messages", curseur.next());
}
return reponse;
}
use of com.mongodb.DBCursor in project Twister by NicolasBizzozzero.
the class CommentairesTools method commentaireExistant.
/**
* Verifie si un commentaire existe dans un message
* @param id_message : L'ID du message contenant le commentaire
* @param id_commentaire : L'ID du commentaire a supprimer
* @return -1 si le message n'existe pas, son index dans la liste sinon.
* @throws UnknownHostException
*/
public static boolean commentaireExistant(String id_message, String id_commentaire) throws UnknownHostException {
// On se connecte a la BDD puis on recupere les messages
DBCollection messages = bd.tools.MessagesTools.getCollectionMessages();
// Creation du message
BasicDBObject message = new BasicDBObject();
message.put(Noms.CHAMP_ID_MESSAGE, Integer.parseInt(id_message));
// On verifie si le message existe
DBCursor curseur = messages.find(message);
if (!curseur.hasNext()) {
// Le message n'existe pas, donc le commentaire non plus
return false;
}
// On recupere la liste des commentaires
JSONObject reponse_message = new JSONObject(JSON.serialize(curseur.next()));
JSONArray commentaires = reponse_message.getJSONArray(Noms.CHAMP_COMMENTAIRES);
// On itere dessus jusqu'au bout ou jusqu'a trouver le commentaire
for (int i = 0; i < commentaires.length(); i++) {
JSONObject commentaire = commentaires.getJSONObject(i);
if (commentaire.getInt(Noms.CHAMP_ID_COMMENTAIRE) == (Integer.parseInt(id_commentaire))) {
return true;
}
}
return false;
}
Aggregations