Example usage for com.mongodb QueryBuilder get

List of usage examples for com.mongodb QueryBuilder get

Introduction

In this page you can find the example usage for com.mongodb QueryBuilder get.

Prototype

public DBObject get() 

Source Link

Document

Creates a DBObject query to be used for the driver's find operations

Usage

From source file:org.alfresco.contentstore.dao.mongo.MongoContentDAO.java

License:Open Source License

@Override
public NodeInfo getByNodeId(String nodeId, long nodeVersion, boolean isPrimary) {
    QueryBuilder queryBuilder = QueryBuilder.start("e").is(serverIdentity.getId()).and("n").is(nodeId).and("v")
            .is(nodeVersion).and("pri").is(isPrimary);
    DBObject query = queryBuilder.get();

    DBObject dbObject = contentData.findOne(query);
    NodeInfo nodeInfo = toNodeInfo(dbObject);
    if (nodeInfo == null) {
        throw new InvalidNodeException(nodeId, nodeVersion);
    }// w ww .ja  v  a2  s.  c  o  m
    return nodeInfo;
}

From source file:org.alfresco.contentstore.dao.mongo.MongoContentDAO.java

License:Open Source License

@Override
public NodeInfo getByNodeId(String nodeId, long nodeVersion, MimeType mimeType) {
    QueryBuilder queryBuilder = QueryBuilder.start("e").is(serverIdentity.getId()).and("n").is(nodeId).and("v")
            .is(nodeVersion).and("pri").is(false).and("mimeType").is(mimeType.getMimetype());
    DBObject query = queryBuilder.get();

    DBObject dbObject = contentData.findOne(query);
    NodeInfo nodeInfo = toNodeInfo(dbObject);
    if (nodeInfo == null) {
        throw new InvalidNodeException(nodeId, nodeVersion);
    }//  w ww  .  java 2 s .com
    return nodeInfo;
}

From source file:org.alfresco.contentstore.dao.mongo.MongoContentDAO.java

License:Open Source License

@Override
public NodeInfo getByNodeId(long nodeInternalId, String mimeType) {
    QueryBuilder queryBuilder = QueryBuilder.start("e").is(serverIdentity.getId()).and("ni").is(nodeInternalId)
            .and("m").is(mimeType);
    DBObject query = queryBuilder.get();

    DBObject dbObject = contentData.findOne(query);
    NodeInfo nodeInfo = toNodeInfo(dbObject);
    return nodeInfo;
}

From source file:org.alfresco.contentstore.dao.mongo.MongoContentDAO.java

License:Open Source License

@Override
public void updateNode(NodeInfo nodeInfo) {
    String cacheServerId = serverIdentity.getId();
    String nodeId = nodeInfo.getNode().getNodeId();
    // String versionLabel = nodeInfo.getNode().getVersionLabel();
    Long nodeInternalId = nodeInfo.getNode().getNodeInternalId();
    Long nodeVersion = nodeInfo.getNode().getNodeVersion();
    MimeType mimeType = nodeInfo.getMimeType();
    Long size = nodeInfo.getSize();
    String nodePath = nodeInfo.getNode().getNodePath();
    String contentPath = nodeInfo.getContentPath();
    boolean isPrimary = nodeInfo.isPrimary();

    QueryBuilder queryBuilder = QueryBuilder.start("e").is(cacheServerId).and("n").is(nodeId);
    if (nodeVersion != null) {
        queryBuilder.and("v").is(nodeVersion);
    }/*ww  w  . j  a va  2 s  .c om*/
    if (nodeInternalId != null) {
        queryBuilder.and("ni").is(nodeInternalId);
    }
    DBObject query = queryBuilder.get();

    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("$set",
            BasicDBObjectBuilder.start("m", mimeType.getMimetype()).add("s", size).add("ni", nodeInternalId)
                    .add("c", contentPath).add("p", nodePath).add("pri", isPrimary).get());
    DBObject update = builder.get();

    WriteResult result = contentData.update(query, update, true, false);
    checkResult(result);
}

From source file:org.alfresco.contentstore.dao.mongo.MongoContentDAO.java

License:Open Source License

@Override
public boolean nodeExists(String nodeId, long nodeVersion, boolean isPrimary) {
    QueryBuilder queryBuilder = QueryBuilder.start("e").is(serverIdentity.getId()).and("n").is(nodeId).and("v")
            .is(nodeVersion).and("pri").is(isPrimary);
    DBObject query = queryBuilder.get();

    DBObject dbObject = contentData.findOne(query);
    return dbObject != null;
}

From source file:org.alfresco.semantics.MongoSemantics.java

License:Open Source License

public void addRelation(String fromId, String toId, String category) {
    QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId).and("t").is(toId);
    DBObject query = queryBuilder.get();

    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("f", fromId).add("t", toId).add("c", category)
            .add("w", 1.0);
    DBObject insert = builder.get();// ww w . j  a v  a2 s  . c o m

    WriteResult result = relations.update(query, insert, true, false);
    checkResult(result, 1);
}

From source file:org.alfresco.semantics.MongoSemantics.java

License:Open Source License

public void deleteRelation(String fromId, String toId) {
    QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId).and("t").is(toId);
    DBObject query = queryBuilder.get();

    WriteResult result = relations.remove(query);
    checkResult(result, 1);/*  w  w  w .j  a v  a  2  s . c o  m*/
}

From source file:org.alfresco.semantics.MongoSemantics.java

License:Open Source License

public void increaseWeight(String fromId, String toId, double weight) {
    QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId).and("t").is(toId);
    DBObject query = queryBuilder.get();

    BasicDBObjectBuilder updateBuilder = BasicDBObjectBuilder.start("$inc",
            BasicDBObjectBuilder.start("w", weight).get());
    DBObject update = updateBuilder.get();

    WriteResult result = relations.update(query, update, false, false);
    checkResult(result, 1);//  ww w . j av a 2  s . com
}

From source file:org.alfresco.semantics.MongoSemantics.java

License:Open Source License

public List<Relation> relationsFrom(String fromId, Set<String> categories, int skip, int maxItems) {
    List<Relation> ret = new LinkedList<>();

    QueryBuilder queryBuilder = QueryBuilder.start("f").is(fromId);
    if (categories != null && categories.size() > 0) {
        queryBuilder.and("c").in(categories);
    }//from  w  ww.ja  v a2s  . c o  m
    DBObject query = queryBuilder.get();

    BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("t", 1).add("w", 1);
    DBObject orderBy = orderByBuilder.get();

    DBCursor cursor = relations.find(query).sort(orderBy).skip(skip).limit(maxItems);
    try {
        for (DBObject dbObject : cursor) {
            String toId = (String) dbObject.get("t");
            double weight = (Double) dbObject.get("w");
            Relation r = new Relation(fromId, toId, weight);
            ret.add(r);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return ret;
}

From source file:org.alfresco.semantics.MongoSemantics.java

License:Open Source License

public List<Relation> relationsTo(String toId, Set<String> categories, int skip, int maxItems) {
    List<Relation> ret = new LinkedList<>();

    QueryBuilder queryBuilder = QueryBuilder.start("t").is(toId);
    if (categories != null && categories.size() > 0) {
        queryBuilder.and("c").in(categories);
    }/* w w  w . ja  va2 s  . c  om*/
    DBObject query = queryBuilder.get();

    BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("f", 1).add("w", 1);
    DBObject orderBy = orderByBuilder.get();

    DBCursor cursor = relations.find(query).sort(orderBy).skip(skip).limit(maxItems);
    try {
        for (DBObject dbObject : cursor) {
            String fromId = (String) dbObject.get("f");
            double weight = (Double) dbObject.get("w");
            Relation r = new Relation(fromId, toId, weight);
            ret.add(r);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return ret;
}