Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

Enable Query Cache, but selectively

$
0
0
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);

Viewing all articles
Browse latest Browse all 5648

Trending Articles