| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>4. Plugin Configuration</title><base href="display"><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="manual.html" title="Apache OpenJPA 2.4 User's Guide"><link rel="up" href="ref_guide_conf.html" title="Chapter 2. Configuration"><link rel="prev" href="ref_guide_conf_devtools.html" title="3. Command Line Configuration"><link rel="next" href="ref_guide_conf_openjpa.html" title="5. 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. |
| Plugin Configuration |
| </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_conf_devtools.html">Prev</a> </td><th width="60%" align="center">Chapter 2. |
| Configuration |
| </th><td width="20%" align="right"> <a accesskey="n" href="ref_guide_conf_openjpa.html">Next</a></td></tr></table><hr></div><div class="section" id="ref_guide_conf_plugins"><div class="titlepage"><div><div><h2 class="title" style="clear: both">4. |
| Plugin Configuration |
| </h2></div></div></div> |
| |
| <a class="indexterm" name="d5e6829"></a> |
| <a class="indexterm" name="d5e6832"></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 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"> |
| <property name="openjpa.DataCache" |
| value="com.xyz.MyDataCache(CacheSize=1000, RemoteHost=cacheserver)"/> |
| </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> </td><td width="20%" align="center"><a accesskey="u" href="ref_guide_conf.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ref_guide_conf_openjpa.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3. |
| Command Line Configuration |
| </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> 5. |
| OpenJPA Properties |
| </td></tr></table></div></body></html> |