JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
1.2 | Persistence | JDO ORM | JPA ORM | Runtime | JDO Runtime | JPA Runtime | Extensions | Developer
Extensions
Plugins : Level 2 Cache

JPOX is developed as a plugin-driven framework and one of the components that is pluggable is the Level 2 caching of objects (between PersistenceManagers for the same PersistenceManagerFactory). JPOX provides a large selection of Level 2 caches (builtin, Tangosol, EHCache, OSCache, SwarmCache) but is structured so that you can easily add your own variant and have it usable within your JPOX usage. This is available in JPOX from version 1.1.2

JPOX is able to support third party Level 2 Cache products. There are JPOX-provided plugins for EHCache, SwarmCache, OSCache, and Tangosol Coherence. You can extend JPOX's capabilities using the plugin extension org.jpox.cache_level2.

Plugin extension-pointKeyDescriptionLocation
org.jpox.cache_level2defaultLevel 2 Cache (default)jpox-core
org.jpox.cache_level2softLevel 2 Cache using Soft mapsjpox-core
org.jpox.cache_level2ehcacheLevel 2 Cache using EHCachejpox-ehcache
org.jpox.cache_level2ehcacheclassbasedLevel 2 Cache using EHCache (based on classes)jpox-ehcache
org.jpox.cache_level2oscacheLevel 2 Cache using OSCachejpox-oscache
org.jpox.cache_level2swarmcacheLevel 2 Cache using SwarmCachejpox-swarmcache
org.jpox.cache_level2tangosolLevel 2 Cache using Tangosol Coherencejpox-tangosol

The following sections describe how to create your own Level 2 cache plugin for JPOX.

Interface

If you have your own Level2 cache you can easily use it with JPOX. JPOX defines a Level2Cache interface and you need to implement this.

package javax.jdo.datastore;
public interface DataStoreCache
{
    void evict (Object oid);

    void evictAll ();

    void evictAll (Object[] oids);

    void evictAll (Collection oids);

    void evictAll (Class pcClass, boolean subclasses);

    void pin (Object oid);

    void pinAll (Collection oids);

    void pinAll (Object[] oids);

    void pinAll (Class pcClass, boolean subclasses);

    void unpin(Object oid);

    void unpinAll(Collection oids);

    void unpinAll(Object[] oids);

    void unpinAll(Class pcClass, boolean subclasses);
}

package org.jpox.cache;
public interface Level2Cache extends javax.jdo.datastore.DataStoreCache
{
    int getNumberOfPinnedObjects();

    int getNumberOfUnpinnedObjects();

    int getSize();

    CachedPC get(Object oid);

    CachedPC put(Object oid, CachedPC pc);

    boolean isEmpty();

    void clear();
}


Implementation

Let's suppose your want to implement your own Level 2 cache MyLevel2Cache

package mydomain;

import org.jpox.cache.Level2Cache;

public class MyLevel2Cache implements Level2Cache
{
    /**
     * Constructor.
     * @param omfCtx OMF Context
     */
    public DefaultLevel2Cache(OMFContext omfCtx)
    {
        ...
    }

    ... (implement the interface)
}
Plugin Specification

Once you have this implementation you then need to make the class available as a JPOX plugin. You do this by putting a file plugin.xml in your JAR at the root of the CLASSPATH. The file plugin.xml will look like this

<?xml version="1.0"?>
<plugin id="mydomain" name="JPOX plug-ins" provider-name="My Company">
    <extension point="org.jpox.cache_level2">
	    <cache name="MyCache" class-name="mydomain.MyLevel2Cache"/>
    </extension>
</plugin>
Plugin Usage

The only thing remaining is to use your L2 Cache plugin. To do this you specify the PersistenceManagerFactory property org.jpox.cache.level2.type as MyCache (the "name" in plugin.xml). In JPOX 1.1.2 the "extension point" was "org.jpox.cache", but in 1.1.3 and later it is changed to "org.jpox.cache_level2"