@Override
  public QueryResult next(String chromosome, int position, QueryOptions options) {

    String featureType = options.getString("featureType", null);
    String featureClass = options.getString("featureClass", null);

    BasicDBList chunksId = new BasicDBList();
    String chunkId =
        chromosome
            + "_"
            + getChunkId(position, regulatoryRegionChunkSize)
            + "_"
            + regulatoryRegionChunkSize / 1000
            + "k";
    chunksId.add(chunkId);

    // TODO: Add query to find next item considering next chunk
    // db.regulatory_region.find({ "chromosome" : "19" , "start" : { "$gt" : 62005} , "featureType"
    // : "TF_binding_site_motif"}).sort({start:1}).limit(1)

    QueryBuilder builder;
    if (options.getString("strand") == null
        || (options.getString("strand").equals("1") || options.getString("strand").equals("+"))) {
      // db.core.find({chromosome: "1", start: {$gt: 1000000}}).sort({start: 1}).limit(1)
      builder =
          QueryBuilder.start("_chunkIds")
              .in(chunksId)
              .and("chromosome")
              .is(chromosome)
              .and("start")
              .greaterThan(position);
      options.put("sort", new BasicDBObject("start", 1));
      options.put("limit", 1);
    } else {
      builder =
          QueryBuilder.start("_chunkIds")
              .in(chunksId)
              .and("chromosome")
              .is(chromosome)
              .and("end")
              .lessThan(position);
      options.put("sort", new BasicDBObject("end", -1));
      options.put("limit", 1);
    }

    if (featureType != null) {
      builder.and("featureType").is(featureType);
    }
    if (featureClass != null) {
      builder.and("featureClass").is(featureClass);
    }
    System.out.println(builder.get());
    return executeQuery("result", builder.get(), options);
  }
Beispiel #2
0
  public static void main(String[] args) throws UnknownHostException {
    MongoClient client = new MongoClient();
    DB db = client.getDB("course");
    DBCollection collection = db.getCollection("findCriteriaTest");
    collection.drop();

    for (int i = 0; i < 10; i++) {
      collection.insert(
          new BasicDBObject("x", new Random().nextInt(2)).append("y", new Random().nextInt(100)));
    }

    QueryBuilder builder = QueryBuilder.start("x").is(0).and("y").greaterThan(10).lessThan(90);
    // DBObject query = new BasicDBObject("x", 0).append("y", new BasicDBObject("$gt",
    // 10).append("$lt", 90));

    System.out.println("\nCount:");
    long count = collection.count(builder.get());
    System.out.println(count);

    System.out.println("\nFind all:");
    DBCursor cursor = collection.find(builder.get());
    try {
      while (cursor.hasNext()) {
        DBObject cur = cursor.next();
        System.out.println(cur);
      }
    } finally {
      cursor.close();
    }
  }
  public static void main(String[] args) throws UnknownHostException {
    MongoClient client = new MongoClient();
    DB db = client.getDB("course");
    DBCollection lines = db.getCollection("DotNotationTest");
    lines.drop();
    Random rand = new Random();

    // insert 10 lines with random start and end points
    for (int i = 0; i < 10; i++) {
      lines.insert(
          new BasicDBObject("_id", i)
              .append(
                  "start",
                  new BasicDBObject("x", rand.nextInt(90) + 10).append("y", rand.nextInt(90) + 10))
              .append("end", new BasicDBObject("x", rand.nextInt(90) + 10))
              .append("y", rand.nextInt(90) + 10));
    }

    // Filter by x coordinate using . notation
    QueryBuilder builder = QueryBuilder.start("start.x").greaterThan(50);

    // Dot notation is also available for field selection
    DBCursor cursor = lines.find(builder.get(), new BasicDBObject("start.y", true));
    try {
      while (cursor.hasNext()) {
        DBObject cur = cursor.next();
        System.out.println(cur);
      }
    } finally {
      cursor.close();
    }
  }
Beispiel #4
0
  public static void main(String[] args) throws UnknownHostException {
    MongoClient client = new MongoClient();
    DB db = client.getDB("course");
    DBCollection lines = db.getCollection("dotNotationTest");
    lines.drop();
    Random rand = new Random();

    for (int i = 0; i < 10; i++) {
      lines.insert(
          new BasicDBObject("_id", i)
              .append(
                  "start",
                  new BasicDBObject("x", rand.nextInt(90) + 10).append("y", rand.nextInt(90) + 10))
              .append(
                  "end",
                  new BasicDBObject("x", rand.nextInt(90) + 10)
                      .append("y", rand.nextInt(90) + 10)));
    }

    QueryBuilder builder = QueryBuilder.start("start.x").greaterThan(50);

    DBCursor cursor =
        lines.find(builder.get(), new BasicDBObject("start.y", true).append("_id", false));

    try {
      while (cursor.hasNext()) {
        DBObject cur = cursor.next();
        System.out.println(cur);
      }
    } finally {
      cursor.close();
    }
  }
  @Override
  public QueryResponse getAllByPositionList(List<Position> positionList, QueryOptions options) {
    //  db.regulatory_region.find({"chunkIds": {$in:["1_200", "1_300"]}, "start": 601156})

    String featureType = options.getString("featureType", null);
    String featureClass = options.getString("featureClass", null);

    List<DBObject> queries = new ArrayList<>();
    for (Position position : positionList) {
      String chunkId =
          position.getChromosome() + "_" + getChunkId(position.getPosition(), CHUNKSIZE);
      BasicDBList chunksId = new BasicDBList();
      chunksId.add(chunkId);
      QueryBuilder builder =
          QueryBuilder.start("chunkIds").in(chunksId).and("start").is(position.getPosition());
      if (featureType != null) {
        builder.and("featureType").is(featureType);
      }
      if (featureClass != null) {
        builder.and("featureClass").is(featureClass);
      }

      //        System.out.println("Query: " + builder.get());
      queries.add(builder.get());
    }

    System.out.println("Query: " + queries);

    options = addExcludeReturnFields("chunkIds", options);
    return executeQueryList(positionList, queries, options);
  }
Beispiel #6
0
 @Test
 public void testCountOnCursor() {
   DBCollection collection = newCollection();
   collection.insert(new BasicDBObject("n", 1));
   collection.insert(new BasicDBObject("n", 2));
   collection.insert(new BasicDBObject("n", 2));
   assertEquals(3, collection.find(QueryBuilder.start("n").exists(true).get()).count());
 }
Beispiel #7
0
  protected DBObject transformFieldFilter(
      final SingleFieldValueFilter<K, T> fieldFilter, final MongoStore<K, T> store) {
    MongoMapping mapping = store.getMapping();
    String dbFieldName = mapping.getDocumentField(fieldFilter.getFieldName());

    FilterOp filterOp = fieldFilter.getFilterOp();
    List<Object> operands = fieldFilter.getOperands();

    QueryBuilder builder = QueryBuilder.start(dbFieldName);
    builder = appendToBuilder(builder, filterOp, operands);
    if (!fieldFilter.isFilterIfMissing()) {
      // If false, the find query will pass if the column is not found.
      DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get();
      builder = QueryBuilder.start().or(notExist, builder.get());
    }
    return builder.get();
  }
  public List<DBObject> getSince(String login, Long since) {
    Date minDate = new Date(since);

    DBCursor notifications =
        collection.find(
            QueryBuilder.start("date").greaterThan(minDate).and("login").notEquals(login).get());

    return notifications.toArray();
  }
  public List<T> findByAttributes(Map<String, String> attributes) {

    QueryBuilder qb = QueryBuilder.start();

    for (String k : attributes.keySet()) {
      qb.and("attributes." + k).is(attributes.get(k));
    }

    return makeList(null, getDbCollection().find(qb.get()));
  }
  // DTS
  public static CtsWorkflowDB getById(String id) {

    QueryBuilder query = QueryBuilder.start("id").is(id); // Equals	
    List<CtsWorkflowDB> results = new CtsWorkflowDB().getDocumentsByQuery(query.get());

    if (results != null && results.size() == 1) {
      return results.get(0);
    }

    return null;
  }
 @Override
 public List<QueryResult> getAllByIdList(List<String> idList, QueryOptions options) {
   List<DBObject> queries = new ArrayList<>();
   for (String id : idList) {
     QueryBuilder builder = QueryBuilder.start("name").is(id);
     //          System.out.println("Query: " + builder.get());
     queries.add(builder.get());
   }
   //        options = addExcludeReturnFields("chunkIds", options);
   return executeQueryList2(idList, queries, options);
 }
  @Override
  public List<QueryResult> getAllByRegionList(List<Region> regionList, QueryOptions options) {
    //  db.regulatory_region.find({"chunkIds": {$in:["1_200", "1_300"]}, "start": 601156})
    QueryBuilder builder = new QueryBuilder();

    List<Object> featureType = options.getList("featureType", null);
    List<Object> featureClass = options.getList("featureClass", null);

    //        options = addExcludeReturnFields("chunkIds", options);

    List<DBObject> queries = new ArrayList<>();
    for (Region region : regionList) {
      int firstChunkId = getChunkId(region.getStart(), regulatoryRegionChunkSize);
      int lastChunkId = getChunkId(region.getEnd(), regulatoryRegionChunkSize);
      BasicDBList chunksId = new BasicDBList();
      for (int j = firstChunkId; j <= lastChunkId; j++) {
        String chunkId =
            region.getChromosome() + "_" + j + "_" + regulatoryRegionChunkSize / 1000 + "k";
        chunksId.add(chunkId);
      }

      //            logger.info(chunksId.toString());

      builder =
          builder
              .start("_chunkIds")
              .in(chunksId)
              .and("start")
              .lessThanEquals(region.getEnd())
              .and("end")
              .greaterThanEquals(region.getStart());

      if (featureType != null && featureType.size() > 0) {
        BasicDBList featureTypeDBList = new BasicDBList();
        featureTypeDBList.addAll(featureType);
        builder = builder.and("featureType").in(featureTypeDBList);
      }

      if (featureClass != null && featureClass.size() > 0) {
        BasicDBList featureClassDBList = new BasicDBList();
        featureClassDBList.addAll(featureClass);
        builder = builder.and("featureClass").in(featureClassDBList);
      }

      queries.add(builder.get());
    }
    //        System.out.println(">>"+regionList);
    //        System.out.println(">>"+builder.get().toString());
    return executeQueryList2(regionList, queries, options);
  }
Beispiel #13
0
  @Override
  public void addQuery(AdRequest request, QueryBuilder builder) {
    if (request.date() != null) {
      List<DBObject> condition_queries = new ArrayList<DBObject>();

      /*
       * Prefix der Indizieren beachten.
       */
      for (int i = 0; i < DateConditionDefinition.MAX_PERIOD_COUNT; i++) {

        QueryBuilder condition = QueryBuilder.start();

        // from part of the query
        BasicDBObject query_from_1 =
            new BasicDBObject(
                AdDBConstants.ADDB_AD_DATE_FROM + i, new BasicDBObject("$lte", request.date()));
        BasicDBObject query_from_2 =
            new BasicDBObject(AdDBConstants.ADDB_AD_DATE_FROM + i, AdDBConstants.ADDB_AD_DATE_ALL);

        List<BasicDBObject> queries = new ArrayList<BasicDBObject>();
        queries.add(query_from_1);
        queries.add(query_from_2);
        BasicDBObject query_from = new BasicDBObject("$or", queries);

        condition.and(query_from);

        // to part of the query
        BasicDBObject query_to_1 =
            new BasicDBObject(
                AdDBConstants.ADDB_AD_DATE_TO + i, new BasicDBObject("$gte", request.date()));
        BasicDBObject query_to_2 =
            new BasicDBObject(AdDBConstants.ADDB_AD_DATE_TO + i, AdDBConstants.ADDB_AD_DATE_ALL);

        queries = new ArrayList<BasicDBObject>();
        queries.add(query_to_1);
        queries.add(query_to_2);
        BasicDBObject query_to = new BasicDBObject("$or", queries);

        condition.and(query_to);

        condition_queries.add(condition.get());
      }
      builder.and(new BasicDBObject("$or", condition_queries));
    }
  }
  @Override
  public QueryResponse getAllByRegionList(List<Region> regionList, QueryOptions options) {
    //  db.regulatory_region.find({"chunkIds": {$in:["1_200", "1_300"]}, "start": 601156})

    String featureType = options.getString("featureType", null);
    String featureClass = options.getString("featureClass", null);

    List<DBObject> queries = new ArrayList<>();
    List<String> ids = new ArrayList<>(regionList.size());
    for (Region region : regionList) {
      int firstChunkId = getChunkId(region.getStart(), CHUNKSIZE);
      int lastChunkId = getChunkId(region.getEnd(), CHUNKSIZE);
      BasicDBList chunksId = new BasicDBList();
      for (int j = firstChunkId; j <= lastChunkId; j++) {
        String chunkId = region.getChromosome() + "_" + j;
        chunksId.add(chunkId);
      }

      QueryBuilder builder =
          QueryBuilder.start("chunkIds")
              .in(chunksId)
              .and("start")
              .lessThanEquals(region.getEnd())
              .and("end")
              .greaterThanEquals(region.getStart());
      if (featureType != null) {
        builder.and("featureType").is(featureType);
      }
      if (featureClass != null) {
        builder.and("featureClass").is(featureClass);
      }

      System.out.println("Query: " + builder.get());
      queries.add(builder.get());
      ids.add(region.toString());
    }
    options = addExcludeReturnFields("chunkIds", options);
    return executeQueryList(ids, queries, options);
  }
  public List<T> findByTags(EntityFilter<T> filter, String... tags) {

    return makeList(filter, getDbCollection().find(QueryBuilder.start("tags").all(tags).get()));
  }
 public List<T> findByNamePattern(String name) {
   return makeList(
       null,
       getDbCollection().find(QueryBuilder.start("name").regex(Pattern.compile(name)).get()));
 }
 /** @see rexos.HAL.libraries.blackboard_client.BlackboardSubscription#getQuery() */
 @Override
 public DBObject getQuery() {
   return QueryBuilder.start(OplogEntry.OPERATION_FIELD).is(operation.getOpCode()).get();
 }