wildflyeclipselinksecond-level-cachejboss-cli

Enable/Disable Eclipselink Shared Cache via jboss-cli


I'm looking to be able to enable or disable the eclipselink shared cache (second level cache) via the jboss-cli.

We generally have the shared-cache-mode set to DISABLE_SELECTIVE, but in certain deployments we would like to be able to disable it. It would be nice if we could do this via the jboss-cli and avoid editing our persistence.xml.

Anyone got any ideas or experience doing anything similar?

I've included our persistence.xml below. I'd be happy to provide anything else that might be helpful.

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
            http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">

    <persistence-unit name="AppPu">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>app.datasource</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode>

        <properties>
            <property name="eclipselink.persistence-context.flush-mode" value="commit" />
            <property name="eclipselink.jdbc.batch-writing" value="jdbc" />
            <property name="eclipselink.jdbc.batch-writing.size" value="500"/>
            <property name="eclipselink.session-event-listener" value="com.demo.app.common.eclipselink.GeometryInitializer"/>

            <property name="eclipselink.logging.logger" value="DefaultLogger"/>
            <property name="eclipselink.logging.file" value="sqldump.log"/>
            <property name="eclipselink.logging.parameters" value="true"/>


        </properties>
    </persistence-unit>

</persistence>

Solution

  • In case anyone else ever attempts to do this...

    Edit your persistence.xml, setting the shared-cache-mode to a variable as follows:

    <shared-cache-mode>${SHARED_CACHE_MODE}</shared-cache-mode>
    

    Then you can add this variable into your standalone.xml by sending the following command to your jboss-cli (substituting DISABLE_SELECTIVE as appropriate):

    /system-property=SHARED_CACHE_MODE:add(value=DISABLE_SELECTIVE)
    

    The following article helped us a lot with this: http://www.mastertheboss.com/jboss-frameworks/hibernate-jpa/jpa-configuration/how-to-use-an-env-variable-in-your-persistencexml