Using annotated methods for queries over in-memory Java collections

You can query in-memory Java™ collections in pureQuery with annotated methods.

Follow these steps to use annotated methods that query in-memory Java collections:

  1. Create an interface that defines the methods that you want to use when querying an in-memory Java collection. You must use the @Select annotation to contain the SELECT statements for each method.
  2. Generate an implementation class for that interface.
  3. In your application, when you create an instance of the implementation class, do not pass a Connection or DataSource object to the constructor.

For example, suppose that you have an interface named CustomerQuery that defines the methods to run against a database, and an interface named RegionReport that defines the methods to run against an in-memory Java collection. In your application, you might use code like this to create instances of implementations of those interfaces.

Connection con = DriverManager.getConnection(...);     1 
 CustomerQuery cQuery = 
    DataFactory.getData( CustomerQuery.class, con );   2 

 RegionReport inMem =
    DataFactory.getData( RegionReport.class );         3 

The code performs these steps:

  1. Create a connection to the database.
  2. Create an instance of the implementation of the CustomerQuery interface. Because a connection object is passed to the constructor, you can use the methods in the implementation for running SQL against a database.
  3. Create an instance of the implementation of the RegionReport interface. Because no Connection or DataSource object is passed to the constructor, you can use the methods in this implementation only for queries over in-memory Java collections.

    The implementation is not threadsafe. Use it only in the thread in which you created it.


Feedback