JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
1.1 | Preparation | O/R Mapping | Runtime | Extensions | Developer
Extensions
Plugins

JPOX is an extensible persistence tool. The JPOX Core persistence engine allows the user to plug in many user extensions which will contribute to augment the numerous persistence aspects faced by the Object/Datastore mapping. Plugins are loaded by a plugin manager which uses a registry mechanism, inspecting jars in the CLASSPATH.

These plugins are defined in OSGi format. This format relies on there being a set of extension-points where JPOX can be extended, and then adding extensions for each of these points. The format means that with very little effort any user can provide their own JPOX plugins and have them available very quickly. In short, the three steps necessary for creating a JPOX plugin are

  1. Review the JPOX interface that you will need to implement to generate the plugin, and implement it
  2. Create a file plugin.xml at the top level of your JAR defining the plugin details (see below).
  3. Update the MANIFEST.MF file contained in the jar so that it includes necessary information for OSGi.

Below we describe the aspects of the persistence process that are currently pluggable using this mechanism.

If you write a JPOX plugin and you either want it to be included in the JPOX distribution, or want it to be listed here then please contact us via the JPOX Forum

Non managed environment

Non managed environment is a runtime environment where JPOX runs and plug-ins are not managed by a container. In this environment the plug-in discovery and lifecycle is managed by JPOX.

There is a 1 to N instance relationship from JPOX to a plug-in per PMF. More exactly, if only one PMF exists, there is only one Plug-in instance for a Connection Pool Plug-in, and if "N" PMF exist, there are "N" Plug-in instances for a Connection Pool Plug-in.

Standard Java runtimes and J2EE containers are considered non managed environments.

Managed environment

Managed environment is a runtime environment where JPOX plug-ins are managed by a container. The discovery, registry and lifecycle of plug-ins are controlled by the container. There is no plug-in instance relationship from JPOX to a plug-in regarding PMF instances. In managed environments, there is only one plug-in instance for one or "N" PMFs. Again, this is managed by the container.

JPOX supports OSGi containers as managed environment.

Lifecycle in non managed environments

In non managed environments there is no lifecycle itself of plug-ins. Extensions implemented by plug-ins are instantiated on demand and terminated on PMF closing, PM closing or in another form depending in what the extension is used for.

Lifecycle in managed environments

In OSGi managed environments plug-in lifecycle is determined by OSGi specification. Once activated, a plug-in is only stopped when the OSGi container finishes its execution, or the plug-in is stopped by an OSGi command.

Plug-ins Extension Points and Extensions

JPOX has mechanism that allows extending its persistence engine while not coupling the JPOX engine to the extensions. This mechanism is known as "Extension Points", which are well defined interfaces that allows the extension of certain aspects of JPOX in a dynamic and consistent model. The "Extensions" are the implementation of Extension Points that are registered in a PluginRegistry and used by JPOX Core or other JPOX Plug-ins.

A plug-in owns an Extension.

Extension Lifecycle

Each extension is created by a segment of code during the runtime execution, and destroyed/released whenever they are no longer needed. This have no influence with the plug-in lifecycle.

Plug-ins manageability

In non managed environments, the plug-ins are managed by JPOX and maintained with a composition relation to the PMF instance. This allows a plug-in "instance" per PMF. If multiple PMFs are created multiple extensions for an extension point are instantiated.

In managed environments, more precisely in OSGi containers, the plug-ins are managed by the OSGi framework. Each plug-in will mostly be a singleton inside the OSGi container.

Plug-ins registration

In non managed environments all plugins are registered using an instance of JDOClassLoaderResolver (so using the current ClassLoader of the PersistenceManagerFactory and the current thread). This means that the /plugin.xml and /META-INF/MANIFEST.MF files must be accessible to the classloader.

In managed environment this is handled by the container.

Plug-ins classloading

The classloading in non managed environments is usually made of one single ClassLoader, while in managed environments each plug-in has it's own ClassLoader.

Extensions Configuration

Some Extensions needs to retrieve a configuration that was set in the PMF. This means that Plug-ins should not hold singleton / static configurations if they want to serve to multiple PMFs at the same time.

Extension constructors / methods

In order of having consistent and avoid changes to extension-point interfaces, the Extension Constructors or Methods (either one) should have receive a PMFContext instance as argument. If by the time the Extension Point is designed clearly there is usage for a PMFContext, then the Extension-Point does not need to take the PMFContext as argument, but keep in mind that a 3rd Extension may need one due to different reasons.

Extension instantiation

Inside the JPOX Core, regardless if the runtime is OSGi managed or non managed, extension instances are created per PMF. JPOX Extensions should always be created through a PluginManager, regardless if the managed environment would allow you to instantiate using their own interfaces. This allows JPOX and

JPOX Plug-ins to run in non managed environments.

PMF Configuration guidelines

In order to avoid conflicts between different property names that can be set in the PMF and to have a consistent naming schema for properties, the following recommendations should be applied.

If a plug-in defines a new PMF configuration, the property name should be prefixed by the plug-in id. Example:

Plugin: org.jpox.myplugin1
Property: myprop1

The PMF property should look like org.jpox.myplugin1.myprop1.

If an extension point defines a new PMF configuration, the property name should be prefixed by the extension-point id. Example:

Extension-Point id: org.jpox.myplugin2.myextensionpoint2
Property: myprop2

The PMF property should look like org.jpox.myplugin2.myextensionpoint2.myprop2.

Another form of PMF configuration could happen if multiple Extension-Points uses the same information. In this case an abstraction of the plug-in id and extension point id could be used, as the following example. However, make sure to use this naming schema only when absolutelly necessary.

Extension-Point id: org.jpox.myplugin3.myextensionpoint3
Extension-Point id: org.jpox.yourplugin3.yourextensionpoint4
Extension-Point id: org.jpox.theirplugin4.theirextensionpoint5
Property: myprop345

The PMF property should look like org.jpox.somepluginXXXX.someextensionpointYYYY.myprop345. Alternativelly, the PMF property could also look like org.jpox.myplugin3.myextensionpoint3.myprop345



Store Managers (org.jpox.store_manager)

JPOX provides support for persisting objects to particular datastores. It provides this capability via a "Store Manager". It provides a Store Manager plugin for RDBMS datastores. You can extend JPOX's capabilities using the plugin extension org.jpox.store_manager.

Plugin extension-pointKeyDescriptionLocation
org.jpox.store_managerjdbcStore Manager for RDBMS datastoresjpox




Java Types (org.jpox.store_mapping)

JPOX supports a very large range of Java types for persistence out of the box. It is occasionally required to persist other Java types not supported internally. You can extend JPOX's capabilities using the plugin extension org.jpox.store_mapping. The capability to support arbitrary java types is described here.





Datastore types (org.jpox.store_datastoremapping)

JPOX supports all of the main datastore types for RDBMS datastores (using JDBC). Occasionally one particular RDBMS may support some little used JDBC type or support an existing supported JDBC type but in a strange way. You can extend JPOX's capabilities using the plugin extension org.jpox.store_datastoremapping





RDBMS Adapter Support (org.jpox.store_datastoreadapter)

JPOX supports many RDBMS databases, and by default, ALL RDBMS are supported without the need to extend JPOX. Due to incompabilities, or specifics of each RDBMS database, it's allowed to extend JPOX to make the support to a specific database fit better to JPOX and your needs. The RDBMS page lists all RDBMS databases that have been tested with JPOX, and some of these databases has been adapted internally to get a good fit. You can extend JPOX's capabilities using the plugin extension org.jpox.store_datastoreadapter. This extension is described here.

Plugin extension-pointKeyDescriptionLocation
org.jpox.store_datastoreadapterderbyAdapter for Apache Derby/Cloudscapejpox
org.jpox.store_datastoreadapterdb2Adapter for IBM DB2jpox
org.jpox.store_datastoreadapteras/400Adapter for IBM DB2 AS/400jpox
org.jpox.store_datastoreadapterfirebirdAdapter for Firebird/Interbasejpox
org.jpox.store_datastoreadaptermicrosoftAdapter for MSSQL serverjpox
org.jpox.store_datastoreadapterh2Adapter for H2jpox
org.jpox.store_datastoreadapterhsqlAdapter for HSQLDBjpox
org.jpox.store_datastoreadaptermckoiAdapter for McKoi DBjpox
org.jpox.store_datastoreadaptermysqlAdapter for MySQLjpox
org.jpox.store_datastoreadaptersybaseAdapter for Sybasejpox
org.jpox.store_datastoreadapteroracleAdapter for Oraclejpox
org.jpox.store_datastoreadapterpointbaseAdapter for Pointbasejpox
org.jpox.store_datastoreadapterpostgresqlAdapter for PostgreSQLjpox
org.jpox.store_datastoreadaptersapdbAdapter for SAPDB/MaxDBjpox
org.jpox.store_datastoreadapterinformixAdapter for Informixjpox




RDBMS Connection-Pooling (org.jpox.datasource)

JPOX requires a DataSource to define the datastore in use and consequently allows use of connection pooling. JPOX provides 3 plugins for different pooling products - DBCP, C3P0, and Proxool. You can easily define your own plugin for pooling. You can extend JPOX's capabilities using the plugin extension org.jpox.datasource. This extension is described here.

Plugin extension-pointKeyDescriptionLocation
org.jpox.datasourcec3p0RDBMS connection pool, using C3P0jpox-c3p0
org.jpox.datasourcedbcpRDBMS connection pool, using Apache DBCPjpox-dbcp
org.jpox.datasourceproxoolRDBMS connection pool, using Proxooljpox-proxool




AutoStart Mechanism (org.jpox.autostart)

JPOX can discover the classes that it is managing at runtime, or you can use an "autostart" mechanism to inform JPOX of what classes it will be managing. JPOX provides a selection of plugins for autostart mechanism. You can extend JPOX's capabilities using the plugin extension org.jpox.autostart. This extension is described here.

Plugin extension-pointKeyDescriptionLocation
org.jpox.autostartclassesAutoStart mechanism specifying the list of classes to be managedjpox
org.jpox.autostartxmlAutoStart mechanism using an XML file to store the managed classesjpox
org.jpox.autostartschematableAutoStart mechanism using a table in the RDBMS datastore to store the managed classesjpox




ClassLoader resolvers (org.jpox.classloader_resolver)

JPOX has to resolve classes at runtime. The JDO2 specification defines a strict process for resolving classes using specific class loaders. JPOX provides a plugin for this JDO2 process. You can extend JPOX's capabilities using the plugin extension org.jpox.classloader_resolver. This extension is described here.

Plugin extension-pointKeyDescriptionLocation
org.jpox.classloader_resolverjdoClassLoaderResolver using JDO2 definitionjpox




MetaData (org.jpox.metadata_handler)

JPOX has supported JDO metadata from the outset. More than this, it actually provides a pluggable framework whereby you can plug in your own MetaData support. JPOX provides JDO metadata support, and from version 1.1.3 provides an early version of support for JPA metadata. You can extend JPOX's capabilities using the plugin extension org.jpox.metadata_handler.

Plugin extension-pointKeyDescriptionLocation
org.jpox.metadata_handlerjdoJDO MetaData handlerjpox
org.jpox.metadata_handlerjpaJPA MetaData handlerjpox
org.jpox.metadata_handlerpersistence"persistence.xml" MetaData handlerjpox




Annotations (org.jpox.java5.annotations)

JPOX (from version 1.1.2 onwards) supports Java5 annotations. More than this, it actually provides a pluggable framework whereby you can plug in your own annotations support. The Java5 plugin provides plugins for JDO2 and JPA1 annotations. You can extend JPOX's capabilities using the plugin extension org.jpox.java5.annotations. This extension is described here.

Plugin extension-pointKeyDescriptionLocation
org.jpox.java5.annotations@PersistenceCapableJDO2 annotation readerjpox-java5
org.jpox.java5.annotations@PersistenceAwareJDO2 annotation readerjpox-java5
org.jpox.java5.annotations@EntityJPA1 annotation readerjpox-java5
org.jpox.java5.annotations@MappedSuperclassJPA1 annotation readerjpox-java5
org.jpox.java5.annotations@EmbeddableJPA1 annotation readerjpox-java5




Datastore Identifier Factory (org.jpox.store_identifierfactory)

JPOX provides the mechanism to generate datastore identifiers (table/column names) when none are defined by the users metadata/annotations. In addition to the default JDO factory there is also an identifier factory that generates identifiers consistent with the JPA1 specification. You can extend JPOX's capabilities using the plugin extension org.jpox.store_identifierfactory. This extension is described here.

Plugin extension-pointKeyDescriptionLocation
org.jpox.store_identifierfactoryjpoxIdentifier Factory providing JPOX 1.1 default namingsjpox
org.jpox.store_identifierfactoryjpox2Identifier Factory providing new JPOX namingsjpox
org.jpox.store_identifierfactoryjpaIdentifier Factory providing JPA-compliant namingsjpox




Value Generator (org.jpox.store_valuegenerator)

JPOX provides a series of generators for identities/values of fields. The JDO2 spec (and the JPA1 spec) define various that are required. JPOX provides plugins for many generators. You can extend JPOX's capabilities using the plugin extension org.jpox.store_valuegenerator. This extension is described here.

Plugin extension-pointKeyDescriptionLocation
org.jpox.store_valuegeneratorauidValue Generator using AUIDsjpox
org.jpox.store_valuegeneratoruuid-hexValue Generator using uuid-hexjpox
org.jpox.store_valuegeneratoruuid-stringValue Generator using uuid-stringjpox
org.jpox.store_valuegeneratorincrementValue Generator using increment strategyjpox
org.jpox.store_valuegeneratorsequenceValue Generator using datastore sequencesjpox
org.jpox.store_valuegeneratormaxValue Generator using max(COL)+1 strategyjpox
org.jpox.store_valuegeneratordatastore-uuid-hexValue Generator using uuid-hex attributed by the datastorejpox




Level 1 Cache (org.jpox.cache_level1)

JPOX is able to support third party Level 1 Cache products. There are JPOX-provided plugins for weak and soft referenced caches. You can extend JPOX's capabilities using the plugin extension org.jpox.cache_level1. This extension is described here.

Plugin extension-pointKeyDescriptionLocation
org.jpox.cache_level1weakWeak referenced cache (default)jpox
org.jpox.cache_level1softSoft referenced cachejpox
org.jpox.cache_level1hardHard-referenced cache (HashMap)jpox




Level 2 Cache (org.jpox.cache_level2)

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. This extension is described here.

Plugin extension-pointKeyDescriptionLocation
org.jpox.cache_level2defaultLevel 2 Cache (default)jpox
org.jpox.cache_level2softLevel 2 Cache using Soft mapsjpox
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




Query Languages (org.jpox.store_query_query)

JPOX provides support for query languages to allow access to the persisted objects. JPOX Core supports JDOQL, SQL and JPOXSQL for use with the "jdbc" StoreManager (see the "org.jpox.store_manager" extension point). You can extend JPOX's capabilities using the plugin extension org.jpox.store_query_query.

Plugin extension-pointKeyDatastoreDescriptionLocation
org.jpox.store_query_queryjavax.jdo.query.JDOQLjdbcQuery support for JDOQLjpox
org.jpox.store_query_queryjavax.jdo.query.SQLjdbcQuery support for SQLjpox
org.jpox.store_query_queryjavax.jdo.query.JPOXSQLjdbcQuery support for JPOXSQLjpox




JDOQL : Custom user defined methods (org.jpox.store_expression_scalarexpression)

JDOQL is defined by the JDO2 specification and is explicit about what is supported. You can extend JPOX's capabilities using the plugin extension org.jpox.store_expression_scalarexpression. The capability to extend the JDOQL query language is described here.

Plugin extension-pointKeyDescriptionLocation
org.jpox.store_expression_scalarexpressionjava.lang.MathUse of Math functions for JDO2jpox
org.jpox.store_expression_scalarexpressionjavax.jdo.JDOHelperUse of JDOHelper function for JDO2jpox
org.jpox.store_expression_scalarexpressionAnalysisUse of Analysis functionsjpox




Implementation Creator (org.jpox.implementation_creator)

Implementation Creator is an extension point that allows the persistence of interfaces. It is responsible to construct persistent classes out of interfaces at runtime. The JPOX Enhancer plug-in has an ImplementationCreator implementation, and to use persistence interfaces, it's enough to place the JPOX Enhancer in the classpath. The ImplementationCreator is declared via the extension point org.jpox.implementation_creator or via the PMF setting org.jpox.implementationCreatorName. If the org.jpox.implementationCreatorName is declared, it takes priority over the extension point declaration. If only the extension point is declared, the first found registered is the first that's gonna be used. You can extend JPOX's capabilities using the plugin extension org.jpox.implementation_creator.

Plugin extension-pointKeyDescriptionLocation
org.jpox.implementation_creatorjdoImplementation Creator for JDO2 compliancejpox-enhancer




Enhancer (org.jpox.enhancer.enhancer)

JPOX relies on byte-code enhancement of classes to implement the PersistenceCapable and Detachable interfaces. It provides a class enhancer plugin using Apache BCEL. You can extend JPOX's capabilities using the plugin extension org.jpox.enhancer.enhancer.

Plugin extension-pointKeyDescriptionLocation
org.jpox.store_expression_scalarexpressionbcelClass Enhancer using Apache BCELjpox-enhancer




Integrating with 3rd party products

It's a goal of the JPOX project to seamless integrate to all major 3rd party products used by the JPOX community. In addition to the plugins above it also provides plugins for the SpringFramework or the Eclipse IDE. All plugins can be downloaded here.