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

Examples of org.hibernate.ogm.datastore.mongodb.query.parsing.nativequery.impl.NativeQueryParser

@author Gunnar Morling

*/
public class NativeQueryParserTest {

  @Test
  public void shouldParseSimplifiedFindQuery() {
    NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
    ParsingResult<MongoDBQueryDescriptorBuilder> run =  new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() )
        .run( "{ \"foo\" : true }");

    MongoDBQueryDescriptor queryDescriptor = run.resultValue.build();

    assertThat( queryDescriptor.getCollectionName() ).isNull();
View Full Code Here


    assertThat( queryDescriptor.getOrderBy() ).isNull();
  }

  @Test
  public void shouldParseSimpleQuery() {
    NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
    ParsingResult<MongoDBQueryDescriptorBuilder> run =  new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() )
        .run( "db.Order.find({\"foo\":true})");

    MongoDBQueryDescriptor queryDescriptor = run.resultValue.build();

    assertThat( queryDescriptor.getCollectionName() ).isEqualTo( "Order" );
View Full Code Here

    assertThat( queryDescriptor.getOrderBy() ).isNull();
  }

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

    MongoDBQueryDescriptor queryDescriptor = run.resultValue.build();

    assertThat( queryDescriptor.getCollectionName() ).isEqualTo( "Order" );
View Full Code Here

    assertThat( queryDescriptor.getOrderBy() ).isNull();
  }

  @Test
  public void shouldParseQueryWithEmptyFind() {
    NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
    ParsingResult<MongoDBQueryDescriptorBuilder> run =  new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() )
        .run( "db.Order.find({})");

    MongoDBQueryDescriptor queryDescriptor = run.resultValue.build();
    assertThat( queryDescriptor.getCriteria() ).isEqualTo( new BasicDBObject() );
  }
View Full Code Here

    assertThat( queryDescriptor.getCriteria() ).isEqualTo( new BasicDBObject() );
  }

  @Test
  public void shouldParseQueryWithProjection() {
    NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
    ParsingResult<MongoDBQueryDescriptorBuilder> run =  new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() )
        .run( "db.Order.find( { \"foo\" : true }, { \"foo\" : 1 } )");

    MongoDBQueryDescriptor queryDescriptor = run.resultValue.build();

    assertThat( queryDescriptor.getCollectionName() ).isEqualTo( "Order" );
View Full Code Here

    assertThat( queryDescriptor.getOrderBy() ).isNull();
  }

  @Test
  public void shouldParseQueryWithWhitespace() {
    NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
    ParsingResult<MongoDBQueryDescriptorBuilder> run =  new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() )
        .run( "  db  .  Order  .  find  (  {  \"  foo  \"  :  true  }  ,  {  \"foo\"  :  1  }  )  ");

    MongoDBQueryDescriptor queryDescriptor = run.resultValue.build();
    assertThat( run.hasErrors() ).isFalse();
    assertThat( queryDescriptor.getCollectionName() ).isEqualTo( "Order" );
View Full Code Here

    assertThat( queryDescriptor.getOrderBy() ).isNull();
  }

  @Test
  public void shouldParseQueryWithSeveralConditions() {
    NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
    ReportingParseRunner<MongoDBQueryDescriptorBuilder> runner = new ReportingParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() );
    ParsingResult<MongoDBQueryDescriptorBuilder> run =  runner
        .run( "db.Order.find( { \"foo\" : true, \"bar\" : 42, \"baz\" : \"qux\" } )");

    assertThat( run.hasErrors() ).isFalse();
    MongoDBQueryDescriptor queryDescriptor = run.resultValue.build();
View Full Code Here

    assertThat( queryDescriptor.getOrderBy() ).isNull();
  }

  @Test
  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" );
View Full Code Here

    assertThat( queryDescriptor.getOrderBy() ).isNull();
  }

  @Test
  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" );
View Full Code Here

    }
  }

  @Override
  public MongoDBQueryDescriptor parseNativeQuery(String nativeQuery) {
    NativeQueryParser parser = Parboiled.createParser( NativeQueryParser.class );
    ParsingResult<MongoDBQueryDescriptorBuilder> parseResult = new RecoveringParseRunner<MongoDBQueryDescriptorBuilder>( parser.Query() )
        .run( nativeQuery );
    if (parseResult.hasErrors() ) {
      throw new IllegalArgumentException( "Unsupported native query: " + ErrorUtils.printParseErrors( parseResult.parseErrors ) );
    }
View Full Code Here

TOP

Related Classes of org.hibernate.ogm.datastore.mongodb.query.parsing.nativequery.impl.NativeQueryParser

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.