blob: dfbeaefeaff7e330a6b039f061cd69179c518ae5 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>4.&nbsp; Plugin Configuration</title><link rel="stylesheet" href="css/docbook.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.72.0"><link rel="start" href="manual.html" title="Apache OpenJPA User's Guide"><link rel="up" href="ref_guide_conf.html" title="Chapter&nbsp;2.&nbsp; Configuration"><link rel="prev" href="ref_guide_conf_devtools.html" title="3.&nbsp; Command Line Configuration"><link rel="next" href="ref_guide_conf_openjpa.html" title="5.&nbsp; OpenJPA Properties"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4.&nbsp;
Plugin Configuration
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_conf_devtools.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;2.&nbsp;
Configuration
</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ref_guide_conf_openjpa.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ref_guide_conf_plugins"></a>4.&nbsp;
Plugin Configuration
</h2></div></div></div><a class="indexterm" name="d0e12359"></a><a class="indexterm" name="d0e12364"></a><p>
Because OpenJPA is a highly customizable environment, many configuration
properties relate to the creation and configuration of system plugins. Plugin
properties have a syntax very similar to that of Java 5 annotations. They allow
you to specify both what class to use for the plugin and how to configure the
public fields or bean properties of the instantiated plugin instance. The
easiest way to describe the plugin syntax is by example:
</p><p>
OpenJPA has a pluggable L2 caching mechanism that is controlled by the <code class="literal">
openjpa.DataCache</code> configuration property. Suppose that you have
created a new class, <code class="classname">com.xyz.MyDataCache</code>, that you want
OpenJPA to use for caching. You've made instances of <code class="literal">MyDataCache
</code> configurable via two methods, <code class="methodname">setCacheSize(int size)
</code> and <code class="methodname">setRemoteHost(String host)</code>. The
sample below shows how you would tell OpenJPA to use an instance of your custom
plugin with a max size of 1000 and a remote host of <code class="literal">cacheserver
</code>.
</p><pre class="programlisting">
&lt;property name="openjpa.DataCache"
value="com.xyz.MyDataCache(CacheSize=1000, RemoteHost=cacheserver)"/&gt;
</pre><p>
As you can see, plugin properties take a class name, followed by a
comma-separated list of values for the plugin's public fields or bean properties
in parentheses. OpenJPA will match each named property to a field or setter
method in the instantiated plugin instance, and set the field or invoke the
method with the given value (after converting the value to the right type, of
course). The first letter of the property names can be in either upper or lower
case. The following would also have been valid:
</p><pre class="programlisting">
com.xyz.MyDataCache(cacheSize=1000, remoteHost=cacheserver)
</pre><p>
If you do not need to pass any property settings to a plugin, you can just name
the class to use:
</p><pre class="programlisting">
com.xyz.MyDataCache
</pre><p>
Similarly, if the plugin has a default class that you do not want to change, you
can simply specify a list of property settings, without a class name. For
example, OpenJPA's query cache companion to the data cache has a default
implementation suitable to most users, but you still might want to change the
query cache's size. It has a <code class="literal">CacheSize</code> property for this
purpose:
</p><pre class="programlisting">
CacheSize=1000
</pre><p>
Finally, many of OpenJPA's built-in options for plugins have short alias names
that you can use in place of the full class name. The data cache property, for
example, has an available alias of <code class="literal">true</code> for the standard
cache implementation. The property value simply becomes:
</p><pre class="programlisting">
true
</pre><p>
The standard cache implementation class also has a <code class="literal">CacheSize</code>
property, so to use the standard implementation and configure the size, specify:
</p><pre class="programlisting">
true(CacheSize=1000)
</pre><p>
The remainder of this chapter reviews the set of configuration properties
OpenJPA recognizes.
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ref_guide_conf_devtools.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ref_guide_conf.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ref_guide_conf_openjpa.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3.&nbsp;
Command Line Configuration
&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;5.&nbsp;
OpenJPA Properties
</td></tr></table></div></body></html>