Example usage for org.springframework.data.mongodb.core.query Query Query

List of usage examples for org.springframework.data.mongodb.core.query Query Query

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query Query Query.

Prototype

public Query(CriteriaDefinition criteriaDefinition) 

Source Link

Document

Creates a new Query using the given CriteriaDefinition .

Usage

From source file:tetrad.rrd.TestSpringMongo.java

/**
 * @param args/*  w ww.  j av a  2  s  .  c  o m*/
 */
public static void main(String[] args) {
    String[] configLocations = new String[] { "applicationContext_rrd.xml" };
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configLocations);

    Operations operations = (Operations) context.getBean("operations");

    Query query = new Query(Criteria.where("key").is("1"));

    Update update = new Update();
    update.set("id", "A");

    WriteResult wr = operations.updateMulti(query, update, "test", true);
    System.out.println(wr);
}

From source file:ezbake.example.ezmongo.EzMongoSpringDataSampleClient.java

public static void main(String[] args)
        throws VisibilityParseException, ClassificationConversionException, EzMongoBaseException {

    // For XML//from w w  w  .ja  v a 2  s .  c  o  m
    ApplicationContext ctx = new GenericXmlApplicationContext("springDataConfig.xml");

    // For Annotation
    //ApplicationContext ctx =
    //        new AnnotationConfigApplicationContext(SpringMongoConfig.class);
    MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");

    User user = new User("mkyong", "password123");

    // Here, we would insert the security tagging fields into the DBObject by calling a utility class (RedactHelper.java).
    Visibility vis = new Visibility();
    // Convert CAPCO to Accumulo-style boolean expression string and set it in the Visibility object.
    String booleanExpressionString = ClassificationUtils.getAccumuloVisibilityStringFromCAPCO("SECRET");
    vis.setFormalVisibility(booleanExpressionString);
    RedactHelper.setSecurityFieldsInDBObject(user, vis, "testAppId");

    // Also set the Name field in the User
    Name name = new Name("testFirstName", "testLastName");
    Visibility nameVis = new Visibility();
    nameVis.setFormalVisibility(booleanExpressionString);
    RedactHelper.setSecurityFieldsInDBObject(name, nameVis, "testAppId");

    user.setName(name);

    // Call the Provenance service to get a unique ID for the document -
    //   the unique ID would be used for the Purge feature.

    // save
    mongoOperation.save(user);

    // now user object got the created id.
    System.out.println("1. user : " + user);

    // query to search user
    Query searchUserQuery = new Query(Criteria.where("username").is("mkyong"));

    // find the saved user again.
    User savedUser = mongoOperation.findOne(searchUserQuery, User.class);
    System.out.println("2. find - savedUser : " + savedUser);

}

From source file:com.exia.web.CustomerDAO.java

public static void deleteCustomer(String id) {
    Query firstNameQuery = new Query(Criteria.where("id").is(id));
    mongoOp.remove(firstNameQuery, Customers.class);

}

From source file:com.epam.ta.reportportal.database.dao.ShareableRepositoryUtils.java

/**
 * Create {@link Query} for loading shared to specified project and not owned by specified user
 * entities./*from w ww. j  av a 2  s .  co  m*/
 * 
 * @param projectName
 * @param owner
 * @return
 */
public static Query createSharedEntityQuery(String owner, String projectName) {
    return Query.query(Criteria.where("acl.entries.projectId").is(projectName))
            .addCriteria(Criteria.where("acl.entries.permissions").is(AclPermissions.READ.name()))
            .addCriteria(Criteria.where("acl.ownerUserId").ne(owner));
}

From source file:com.zxy.commons.mongodb.MongodbUtils.java

/**
 * ?/*  www . ja  v a 2  s  . co m*/
 *
 * @param params params
 * @return Query
 */
public static Query getQuery(Map<String, Object> params) {
    if (params == null || params.isEmpty()) {
        return null;
    }
    List<Criteria> criterias = new ArrayList<>();
    for (Map.Entry<String, Object> entry : params.entrySet()) {
        criterias.add(Criteria.where(entry.getKey()).is(entry.getValue()));
    }
    return new Query(new Criteria().andOperator(criterias.toArray(new Criteria[params.size()])));

}

From source file:com.epam.ta.reportportal.database.search.ModifiableQueryBuilder.java

/**
 * Query for entities modified later than provided date
 * /*from  w  w w.jav  a  2  s  . c  om*/
 * @param date
 * @return
 */
public static Query findModifiedLaterThan(final Date date) {
    return Query.query(Criteria.where(Modifiable.LAST_MODIFIED).lt(date));
}

From source file:com.epam.ta.reportportal.database.dao.ShareableRepositoryUtils.java

/**
 * Create {@link Query} for loading entities owned by specified user.
 * /* w  w w  .  j  a v a  2s  .c  o  m*/
 * @param owner
 * @param projectName
 * @return
 */
public static Query createOwnedEntityQuery(String owner) {
    return Query.query(Criteria.where("acl.ownerUserId").is(owner));
}

From source file:quanlyhocvu.api.mongodb.DAO.HocSinhDAO.java

@SuppressWarnings("empty-statement")
public long Count() {
    return mongoOperations.count(Query.query(Criteria.where("ID").lt("500000000")), HocSinhDTO.class);
}

From source file:br.com.ezequieljuliano.argos.persistence.LevelDAO.java

public List<Level> findByName(String name) {
    Query query = new Query(Criteria.where("name").regex(name, "i"));
    return getMongoOperations().find(query, Level.class);
}

From source file:br.com.ezequieljuliano.argos.persistence.MarkerDAO.java

public List<Marker> findByName(String name) {
    Query query = new Query(Criteria.where("name").regex(name, "i"));
    return getMongoOperations().find(query, Marker.class);
}