openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Curtis <curti...@gmail.com>
Subject Re: Enable Query Cache, but selectively
Date Mon, 10 Nov 2014 18:24:11 GMT
> However I wonder if there is an easier way to achieve this?
I thought there was an easier way... but after digging around a bit I
didn't come up with anything better. While what you are doing is completely
valid, I'd almost recommend the creation of a helper method that will
disable/enable the QueryReultsCache when you create a query. A custom
JDBCBrokerFactory seems like quite a lot of complexity when you could just
call .setQueryCacheEnabled(false) when you do/don't want caching... then
again, that is just my opinion.

I think the ideal solution would involve the addition of a new
configuration property to OpenJPAConfigurationImpl. Something similar to
openjpa.MaxFetchDepth[1].

Thanks,
Rick

[1]
http://ci.apache.org/projects/openjpa/trunk/docbook/manual.html#openjpa.MaxFetchDepth

On Mon, Nov 10, 2014 at 1:30 AM, Jörn Gersdorf <joern.gersdorf@gmail.com>
wrote:

> Hi,
>
> I´d like to enable OpenJPA´s query cache in a selective way, i. e. it
> should be disabled unless I enable it explicitly using
> query.getFetchPlan().setQueryResult(true).
>
> I´ve figured out that this requires
> FetchConfigurationImpl$ConfigurationState#queryCache to be set to false by
> default, however, there does not seem to be a configuration property for
> this.
>
> So I ended up subclassing JDBCBrokerFactory and configure this via property
> openjpa.BrokerFactory (see code below).
>
> However I wonder if there is an easier way to achieve this?
>
> Thanks and best regards,
> Jörn
>
> Code:
>
> <property name="openjpa.BrokerFactory"
> value="de.dwpbank.wp2d.wprecon.model.cache.CustomJDBCBrokerFactory" />
>
>
> public class CustomJDBCBrokerFactory extends JDBCBrokerFactory {
>
>     public CustomJDBCBrokerFactory(JDBCConfiguration conf) {
>         super(conf);
>     }
>
>     @Override
>     protected StoreManager newStoreManager() {
>         return new JDBCStoreManager() {
>             @Override
>             public FetchConfiguration newFetchConfiguration() {
>                 return
> super.newFetchConfiguration().setQueryCacheEnabled(false);
>             }
>         };
>     }
>
>     public static CustomJDBCBrokerFactory newInstance(ConfigurationProvider
> cp) {
>         JDBCConfigurationImpl conf = new JDBCConfigurationImpl();
>         cp.setInto(conf);
>         return new CustomJDBCBrokerFactory(conf);
>     }
> }
>



-- 
*Rick Curtis*

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message