<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!-- NewPage --> <html lang="en"> <head> <!-- Generated by javadoc (version 1.7.0_45) on Thu Jan 09 22:45:27 GMT 2014 --> <title>PersistentProxy</title> <meta name="date" content="2014-01-09"> <link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style"> </head> <body> <script type="text/javascript"><!-- if (location.href.indexOf('is-external=true') == -1) { parent.document.title="PersistentProxy"; } //--> </script> <noscript> <div>JavaScript is disabled on your browser.</div> </noscript> <!-- ========= START OF TOP NAVBAR ======= --> <div class="topNav"><a name="navbar_top"> <!-- --> </a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow"> <!-- --> </a> <ul class="navList" title="Navigation"> <li><a href="../../../../overview-summary.html">Overview</a></li> <li><a href="package-summary.html">Package</a></li> <li class="navBarCell1Rev">Class</li> <li><a href="package-tree.html">Tree</a></li> <li><a href="../../../../deprecated-list.html">Deprecated</a></li> <li><a href="../../../../index-all.html">Index</a></li> <li><a href="../../../../help-doc.html">Help</a></li> </ul> </div> <div class="subNav"> <ul class="navList"> <li><a href="../../../../com/sleepycat/persist/model/Persistent.html" title="annotation in com.sleepycat.persist.model"><span class="strong">Prev Class</span></a></li> <li><a href="../../../../com/sleepycat/persist/model/PrimaryKey.html" title="annotation in com.sleepycat.persist.model"><span class="strong">Next Class</span></a></li> </ul> <ul class="navList"> <li><a href="../../../../index.html?com/sleepycat/persist/model/PersistentProxy.html" target="_top">Frames</a></li> <li><a href="PersistentProxy.html" target="_top">No Frames</a></li> </ul> <ul class="navList" id="allclasses_navbar_top"> <li><a href="../../../../allclasses-noframe.html">All Classes</a></li> </ul> <div> <script type="text/javascript"><!-- allClassesLink = document.getElementById("allclasses_navbar_top"); if(window==top) { allClassesLink.style.display = "block"; } else { allClassesLink.style.display = "none"; } //--> </script> </div> <div> <ul class="subNavList"> <li>Summary: </li> <li>Nested | </li> <li>Field | </li> <li>Constr | </li> <li><a href="#method_summary">Method</a></li> </ul> <ul class="subNavList"> <li>Detail: </li> <li>Field | </li> <li>Constr | </li> <li><a href="#method_detail">Method</a></li> </ul> </div> <a name="skip-navbar_top"> <!-- --> </a></div> <!-- ========= END OF TOP NAVBAR ========= --> <!-- ======== START OF CLASS DATA ======== --> <div class="header"> <div class="subTitle">com.sleepycat.persist.model</div> <h2 title="Interface PersistentProxy" class="title">Interface PersistentProxy<T></h2> </div> <div class="contentContainer"> <div class="description"> <ul class="blockList"> <li class="blockList"> <hr> <br> <pre>public interface <span class="strong">PersistentProxy<T></span></pre> <div class="block">Implemented by a proxy class to represent the persistent state of a (non-persistent) proxied class. Normally classes that are outside the scope of the developer's control must be proxied since they cannot be annotated, and because it is desirable to insulate the stored format from changes to the instance fields of the proxied class. This is useful for classes in the standard Java libraries, for example. <p><code>PersistentProxy</code> objects are not required to be thread-safe. A single thread will create and call the methods of a given <code>PersistentProxy</code> object.</p> <p>There are three requirements for a proxy class:</p> <ol> <li>It must implement the <code>PersistentProxy</code> interface.</li> <li>It must be specified as a persistent proxy class in the entity model. When using the <a href="../../../../com/sleepycat/persist/model/AnnotationModel.html" title="class in com.sleepycat.persist.model"><code>AnnotationModel</code></a>, a proxy class is indicated by the <a href="../../../../com/sleepycat/persist/model/Persistent.html" title="annotation in com.sleepycat.persist.model"><code>Persistent</code></a> annotation with the <a href="../../../../com/sleepycat/persist/model/Persistent.html#proxyFor()"><code>Persistent.proxyFor()</code></a> property.</li> <li>It must be explicitly registered by calling <a href="../../../../com/sleepycat/persist/model/EntityModel.html#registerClass(java.lang.Class)"><code>EntityModel.registerClass(java.lang.Class)</code></a> before opening the store.</li> </ol> <p>In order to serialize an instance of the proxied class before it is stored, an instance of the proxy class is created. The proxied instance is then passed to the proxy's <a href="../../../../com/sleepycat/persist/model/PersistentProxy.html#initializeProxy(T)"><code>initializeProxy</code></a> method. When this method returns, the proxy instance contains the state of the proxied instance. The proxy instance is then serialized and stored in the same way as for any persistent object.</p> <p>When an instance of the proxy object is deserialized after it is retrieved from storage, its <a href="../../../../com/sleepycat/persist/model/PersistentProxy.html#convertProxy()"><code>convertProxy()</code></a> method is called. The instance of the proxied class returned by this method is then returned as a field in the persistent instance.</p> <p>For example:</p> <pre class="code"> import java.util.Locale; @Persistent(proxyFor=Locale.class) class LocaleProxy implements PersistentProxy<Locale> { String language; String country; String variant; private LocaleProxy() {} public void initializeProxy(Locale object) { language = object.getLanguage(); country = object.getCountry(); variant = object.getVariant(); } public Locale convertProxy() { return new Locale(language, country, variant); } }</pre> <p>The above definition allows the <code>Locale</code> class to be used in any persistent class, for example:</p> <pre class="code"> @Persistent class LocalizedText { String text; Locale locale; }</pre> <p>A proxied class may not be used as a superclass for a persistent class or entity class. For example, the following is not allowed.</p> <pre class="code"> @Persistent class LocalizedText extends Locale { // NOT ALLOWED String text; }</pre> <p>A proxy for proxied class P does not handle instances of subclasses of P. To proxy a subclass of P, a separate proxy class is needed.</p> <p>Several <a href="Entity.html#proxyTypes">built in proxy types</a> are used implicitly. An application defined proxy will be used instead of a built-in proxy, if both exist for the same proxied class.</p> <p>With respect to class evolution, a proxy instance is no different than any other persistent instance. When using a <a href="../../../../com/sleepycat/persist/raw/RawStore.html" title="class in com.sleepycat.persist.raw"><code>RawStore</code></a> or <a href="../../../../com/sleepycat/persist/evolve/Converter.html" title="class in com.sleepycat.persist.evolve"><code>Converter</code></a>, only the raw data of the proxy instance will be visible. Raw data for the proxied instance never exists.</p> <p>Currently a proxied object may not contain a reference to itself. For simple proxied objects such as the Locale class shown above, this naturally won't occur. But for proxied objects that are containers -- the built-in Collection and Map classes for example -- this can occur if the container is added as an element of itself. This should be avoided. If an attempt to store such an object is made, an <code>IllegalArgumentException</code> will be thrown.</p> <p>Note that a proxy class may not be a subclass of an entity class.</p></div> </li> </ul> </div> <div class="summary"> <ul class="blockList"> <li class="blockList"> <!-- ========== METHOD SUMMARY =========== --> <ul class="blockList"> <li class="blockList"><a name="method_summary"> <!-- --> </a> <h3>Method Summary</h3> <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation"> <caption><span>Methods</span><span class="tabEnd"> </span></caption> <tr> <th class="colFirst" scope="col">Modifier and Type</th> <th class="colLast" scope="col">Method and Description</th> </tr> <tr class="altColor"> <td class="colFirst"><code><a href="../../../../com/sleepycat/persist/model/PersistentProxy.html" title="type parameter in PersistentProxy">T</a></code></td> <td class="colLast"><code><strong><a href="../../../../com/sleepycat/persist/model/PersistentProxy.html#convertProxy()">convertProxy</a></strong>()</code> <div class="block">Returns a new proxied class instance to which the state of this proxy instance has been copied.</div> </td> </tr> <tr class="rowColor"> <td class="colFirst"><code>void</code></td> <td class="colLast"><code><strong><a href="../../../../com/sleepycat/persist/model/PersistentProxy.html#initializeProxy(T)">initializeProxy</a></strong>(<a href="../../../../com/sleepycat/persist/model/PersistentProxy.html" title="type parameter in PersistentProxy">T</a> object)</code> <div class="block">Copies the state of a given proxied class instance to this proxy instance.</div> </td> </tr> </table> </li> </ul> </li> </ul> </div> <div class="details"> <ul class="blockList"> <li class="blockList"> <!-- ============ METHOD DETAIL ========== --> <ul class="blockList"> <li class="blockList"><a name="method_detail"> <!-- --> </a> <h3>Method Detail</h3> <a name="initializeProxy(java.lang.Object)"> <!-- --> </a><a name="initializeProxy(T)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>initializeProxy</h4> <pre>void initializeProxy(<a href="../../../../com/sleepycat/persist/model/PersistentProxy.html" title="type parameter in PersistentProxy">T</a> object)</pre> <div class="block">Copies the state of a given proxied class instance to this proxy instance.</div> </li> </ul> <a name="convertProxy()"> <!-- --> </a> <ul class="blockListLast"> <li class="blockList"> <h4>convertProxy</h4> <pre><a href="../../../../com/sleepycat/persist/model/PersistentProxy.html" title="type parameter in PersistentProxy">T</a> convertProxy()</pre> <div class="block">Returns a new proxied class instance to which the state of this proxy instance has been copied.</div> </li> </ul> </li> </ul> </li> </ul> </div> </div> <!-- ========= END OF CLASS DATA ========= --> <!-- ======= START OF BOTTOM NAVBAR ====== --> <div class="bottomNav"><a name="navbar_bottom"> <!-- --> </a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow"> <!-- --> </a> <ul class="navList" title="Navigation"> <li><a href="../../../../overview-summary.html">Overview</a></li> <li><a href="package-summary.html">Package</a></li> <li class="navBarCell1Rev">Class</li> <li><a href="package-tree.html">Tree</a></li> <li><a href="../../../../deprecated-list.html">Deprecated</a></li> <li><a href="../../../../index-all.html">Index</a></li> <li><a href="../../../../help-doc.html">Help</a></li> </ul> </div> <div class="subNav"> <ul class="navList"> <li><a href="../../../../com/sleepycat/persist/model/Persistent.html" title="annotation in com.sleepycat.persist.model"><span class="strong">Prev Class</span></a></li> <li><a href="../../../../com/sleepycat/persist/model/PrimaryKey.html" title="annotation in com.sleepycat.persist.model"><span class="strong">Next Class</span></a></li> </ul> <ul class="navList"> <li><a href="../../../../index.html?com/sleepycat/persist/model/PersistentProxy.html" target="_top">Frames</a></li> <li><a href="PersistentProxy.html" target="_top">No Frames</a></li> </ul> <ul class="navList" id="allclasses_navbar_bottom"> <li><a href="../../../../allclasses-noframe.html">All Classes</a></li> </ul> <div> <script type="text/javascript"><!-- allClassesLink = document.getElementById("allclasses_navbar_bottom"); if(window==top) { allClassesLink.style.display = "block"; } else { allClassesLink.style.display = "none"; } //--> </script> </div> <div> <ul class="subNavList"> <li>Summary: </li> <li>Nested | </li> <li>Field | </li> <li>Constr | </li> <li><a href="#method_summary">Method</a></li> </ul> <ul class="subNavList"> <li>Detail: </li> <li>Field | </li> <li>Constr | </li> <li><a href="#method_detail">Method</a></li> </ul> </div> <a name="skip-navbar_bottom"> <!-- --> </a></div> <!-- ======== END OF BOTTOM NAVBAR ======= --> </body> </html>