Package org.hibernate.ogm.datastore.mongodb.query.impl

Examples of org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor


  public void shouldParseCountQuery() {
    NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
    ParsingResult<MongoDBQueryDescriptorBuilder> run =  new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() )
        .run( "db.Order.count()");

    MongoDBQueryDescriptor queryDescriptor = run.resultValue.build();

    assertThat( queryDescriptor.getCollectionName() ).isEqualTo( "Order" );
    assertThat( queryDescriptor.getOperation() ).isEqualTo( Operation.COUNT );
    assertThat( queryDescriptor.getCriteria() ).isNull();
    assertThat( queryDescriptor.getProjection() ).isNull();
    assertThat( queryDescriptor.getOrderBy() ).isNull();
  }
View Full Code Here


  public void shouldParseCountQueryWithCriteria() {
    NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
    ParsingResult<MongoDBQueryDescriptorBuilder> run =  new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() )
        .run( "db.Order.count( { 'foo' : true } )");

    MongoDBQueryDescriptor queryDescriptor = run.resultValue.build();

    assertThat( queryDescriptor.getCollectionName() ).isEqualTo( "Order" );
    assertThat( queryDescriptor.getOperation() ).isEqualTo( Operation.COUNT );
    assertThat( queryDescriptor.getCriteria() ).isEqualTo( JSON.parse( "{ 'foo' : true }" ) );
    assertThat( queryDescriptor.getProjection() ).isNull();
    assertThat( queryDescriptor.getOrderBy() ).isNull();
  }
View Full Code Here

    }
  }

  @Override
  public ClosableIterator<Tuple> executeBackendQuery(BackendQuery<MongoDBQueryDescriptor> backendQuery, QueryParameters queryParameters) {
    MongoDBQueryDescriptor queryDescriptor = backendQuery.getQuery();

    EntityKeyMetadata entityKeyMetadata = backendQuery.getSingleEntityKeyMetadataOrNull();
    String collectionName = getCollectionName( backendQuery, queryDescriptor, entityKeyMetadata );
    DBCollection collection = provider.getDatabase().getCollection( collectionName );

    switch( queryDescriptor.getOperation() ) {
      case FIND:
        return doFind( queryDescriptor, queryParameters, collection, entityKeyMetadata );
      case COUNT:
        return doCount( queryDescriptor, collection );
      default:
View Full Code Here

    }
  }

  @Override
  public ClosableIterator<Tuple> executeBackendQuery(BackendCustomQuery customQuery, QueryParameters queryParameters) {
    MongoDBQueryDescriptor query = null;

    // query already given in DBObject-representation (created by JP-QL parser)
    if ( customQuery.getQueryObject() != null ) {
      query = (MongoDBQueryDescriptor) customQuery.getQueryObject();
    }
    // a string-based native query; need to create the DBObject from that
    else {
      // TODO OGM-414 This should actually be cached in the native query plan
      NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
      ParsingResult<MongoDBQueryDescriptorBuilder> parseResult =  new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() ).run( customQuery.getQueryString() );
      if (parseResult.hasErrors() ) {
        throw new IllegalArgumentException( "Unsupported native query: " + ErrorUtils.printParseErrors( parseResult.parseErrors ) );
      }

      query = parseResult.resultValue.build();
    }

    EntityKeyMetadata entityKeyMetadata = customQuery.getSingleEntityKeyMetadataOrNull();
    String collectionName = getCollectionName( customQuery, query, entityKeyMetadata );
    DBCollection collection = provider.getDatabase().getCollection( collectionName );

    switch( query.getOperation() ) {
      case FIND:
        return doFind( query, queryParameters, collection, entityKeyMetadata );
      case COUNT:
        return doCount( query, collection );
      default:
View Full Code Here

        .getFactory() )
        .getEntityPersister( result.getEntityType().getName() ) )
        .getTableName();

    NoSQLQuery query = new NoSQLQueryImpl(
        new MongoDBQueryDescriptor(
            tableName,
            Operation.FIND, //so far only SELECT is supported
            result.getQuery(),
            result.getProjection(),
            result.getOrderBy()
View Full Code Here

    this.projection = projection;
    return true;
  }

  public MongoDBQueryDescriptor build() {
    return new MongoDBQueryDescriptor( collection, operation, (DBObject) JSON.parse( criteria ), (DBObject) JSON.parse( projection ), null );
  }
View Full Code Here

    }
  }

  @Override
  public ClosableIterator<Tuple> executeBackendQuery(BackendQuery<MongoDBQueryDescriptor> backendQuery, QueryParameters queryParameters) {
    MongoDBQueryDescriptor queryDescriptor = backendQuery.getQuery();

    EntityKeyMetadata entityKeyMetadata = backendQuery.getSingleEntityKeyMetadataOrNull();
    String collectionName = getCollectionName( backendQuery, queryDescriptor, entityKeyMetadata );
    DBCollection collection = provider.getDatabase().getCollection( collectionName );

    switch( queryDescriptor.getOperation() ) {
      case FIND:
        return doFind( queryDescriptor, queryParameters, collection, entityKeyMetadata );
      case COUNT:
        return doCount( queryDescriptor, collection );
      default:
View Full Code Here

    }
  }

  @Override
  public ClosableIterator<Tuple> executeBackendQuery(BackendCustomQuery customQuery, QueryParameters queryParameters) {
    MongoDBQueryDescriptor query = null;

    // query already given in DBObject-representation (created by JP-QL parser)
    if ( customQuery.getQueryObject() != null ) {
      query = (MongoDBQueryDescriptor) customQuery.getQueryObject();
    }
    // a string-based native query; need to create the DBObject from that
    else {
      // TODO OGM-414 This should actually be cached in the native query plan
      NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
      ParsingResult<MongoDBQueryDescriptorBuilder> parseResult =  new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() ).run( customQuery.getQueryString() );
      if (parseResult.hasErrors() ) {
        throw new IllegalArgumentException( "Unsupported native query: " + ErrorUtils.printParseErrors( parseResult.parseErrors ) );
      }

      query = parseResult.resultValue.build();
    }

    EntityKeyMetadata entityKeyMetadata = customQuery.getSingleEntityKeyMetadataOrNull();
    String collectionName = getCollectionName( customQuery, query, entityKeyMetadata );
    DBCollection collection = provider.getDatabase().getCollection( collectionName );

    switch( query.getOperation() ) {
      case FIND:
        return doFind( query, queryParameters, collection, entityKeyMetadata );
      case COUNT:
        return doCount( query, collection );
      default:
View Full Code Here

    }
  }

  @Override
  public ClosableIterator<Tuple> executeBackendQuery(BackendQuery<MongoDBQueryDescriptor> backendQuery, QueryParameters queryParameters) {
    MongoDBQueryDescriptor queryDescriptor = backendQuery.getQuery();

    EntityKeyMetadata entityKeyMetadata = backendQuery.getSingleEntityKeyMetadataOrNull();
    String collectionName = getCollectionName( backendQuery, queryDescriptor, entityKeyMetadata );
    DBCollection collection = provider.getDatabase().getCollection( collectionName );

    switch( queryDescriptor.getOperation() ) {
      case FIND:
        return doFind( queryDescriptor, queryParameters, collection, entityKeyMetadata );
      case COUNT:
        return doCount( queryDescriptor, collection );
      default:
View Full Code Here

TOP

Related Classes of org.hibernate.ogm.datastore.mongodb.query.impl.MongoDBQueryDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.