Search code examples
spring-datagemfireoqlspring-data-gemfire

How can you determine whether a Spring Data Gemfire query is using a Gemfire index?


I am trying to determine whether all of my Spring Data Gemfire queries are using the indexes defined on the Gemfire server.

With OQL, I know I can add "<trace>" and in the gemfire logs it will show whether an index is being used:

@Query("<trace> SELECT c FROM /customer c, c.emailAddresses email WHERE email.emailAddress = $1")
CustomerEntity findByEmailAddress(String emailAddress);

But what about methods where we don't have OQL defined, like this? (Assuming username is not the key of the Customer region):

CustomerEntity findByUsername(String username);

Solution

  • Great question. Unfortunately, the Repository method for generating GemFire OQL queries based on methods names and conventions used in the name does not support TRACE, or other OQL statements like IMPORT.

    As you are probably aware, Spring Data GemFire's Repository support builds on Spring Data Commons Repository infrastructure, which maintains the lowest common denominator for the widest range for data store support (relational, key-value, document, etc).

    Still, you can enable debugging for all GemFire OQL queries by setting the GemFire System property...

    -Dgemfire.Query.VERBOSE=true
    

    when launching your application. See GemFire's User Guide on Query Debugging for further details.

    Unfortunately, this a bit more verbose if you only wanted to TRACE one of your OQL queries, but will accomplish what you want.

    The only other way to TRACE in an individual OQL query based on a Repository method is by using the @Query annotation as you illustrated above.

    @Query("<trace> SELECT c FROM /customer c, c.emailAddresses email WHERE email.emailAddress = $1")
    CustomerEntity findByEmailAddress(String emailAddress);
    

    Your question did give me some ideas though. I am thinking to provide IMPORT and TRACE support via annotations like so...

    @Trace
    @Import("example.app.domain.CustomerEntity")
    CustomerEntity findByUsername(String username);
    

    This would be very elegant and useful.

    See the the new JIRA ticket (SGF-392) I filed to add support for this feature.

    Thank you!