openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jörn Gersdorf <joern.gersd...@gmail.com>
Subject Enable Query Cache, but selectively
Date Mon, 10 Nov 2014 07:30:20 GMT
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);
    }
}

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