通过jboss-cli启用/禁用Eclipselink共享缓存

时间:2019-07-03 14:03:30

标签: wildfly eclipselink second-level-cache jboss-cli

我希望能够通过jboss-cli启用或禁用eclipselink共享缓存(二级缓存)。

我们通常将shared-cache-mode设置为DISABLE_SELECTIVE,但是在某些部署中,我们希望能够将其禁用。如果我们可以通过jboss-cli做到这一点,并且避免编辑我们的persistence.xml,那就太好了。

有人有类似的想法或经验吗?

我在下面包括了我们的persistence.xml。我很乐意提供其他可能有用的东西。

<?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>

1 个答案:

答案 0 :(得分:0)

万一其他人尝试这样做...

编辑您的persistence.xml,将shared-cache-mode设置为变量,如下所示:

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

然后,您可以通过将以下命令发送到standalone.xml(适当地替换为jboss-cli)来将此变量添加到DISABLE_SELECTIVE中:

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

以下文章对此提供了很多帮助:http://www.mastertheboss.com/jboss-frameworks/hibernate-jpa/jpa-configuration/how-to-use-an-env-variable-in-your-persistencexml