cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Cayenne Documentation > Extended Types
Date Sun, 13 Feb 2011 20:15:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2036/9/1/_/styles/combined.css?spaceKey=CAYDOC&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAYDOC/Extended+Types">Extended
Types</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~andrus">Andrus
Adamchik</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-changed-lines" >JDBC specification defines a set
of &quot;standard&quot; database column types (defined in java.sql.Types class) and
a very specific mapping of these types to Java Object Types, such as java.lang.String, java.math.BigDecimal,
etc. Sometimes there is a need to use a custom Java type not known to JDBC driver. CayenneModeler
allows to configure an arbitrary Java class as an {{org.apache.cayenne.map.ObjAttribute}}
type by simply entering a fully-qualified name such class in the type column of an ObjAttribute.
However there is more to it than just that. Cayenne needs to know how to instantiate this
type from a database &quot;primitive&quot; value, and <span class="diff-changed-words">convers<span
class="diff-added-chars"style="background-color: #dfd;">e</span>ly,</span>
how to transform an object of the custom type to a JDBC-compatible object. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h3. Supporting Non-Standard
Types <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>JDBC specification defines a set of "standard" database column types (defined
in java.sql.Types class) and a very specific mapping of these types to Java Object Types,
such as java.lang.String, java.math.BigDecimal, etc. Sometimes there is a need to use a custom
Java type not known to JDBC driver. CayenneModeler allows to configure an arbitrary Java class
as an <tt>org.apache.cayenne.map.ObjAttribute</tt> type by simply entering a fully-qualified
name such class in the type column of an ObjAttribute. However there is more to it than just
that. Cayenne needs to know how to instantiate this type from a database "primitive" value,
and conversely, how to transform an object of the custom type to a JDBC-compatible object.</p>

<h3><a name="ExtendedTypes-SupportingNonStandardTypes"></a>Supporting Non-Standard
Types</h3>

<p><tt>org.apache.cayenne.access.types.ExtendedType</tt> interface serves
to integrate a custom attribute type to Cayenne. An implementation must provide <tt>ExtendedType.getClassName()</tt>
method that returns a fully qualified Java class name for the supported custom type, and a
number of methods that convert data between JDBC and custom type. Configuring an ExtendedType
is has in the code, some time during Cayenne startup. The following code sample demonstrates
this procedure:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// create custom ExtendedType instance
</span>ExtendedType customType = <span class="code-keyword">new</span> MyCustomType();

<span class="code-comment">// Find DataNode
</span>DataDomain domain = Configuration.getSharedConfiguration().getDomain();
<span class="code-comment">// replace 'node_name' with the name of the DataNode you've
entered in the Modeler.
</span>DataNode node = domain.getNode(<span class="code-quote">"node_name"</span>);

<span class="code-comment">// install ExtendedType
</span>node.getAdapter().getExtendedTypes().registerType(customType);</pre>
</div></div>

<h3><a name="ExtendedTypes-DbAdaptersandExtendedTypes"></a>DbAdapters and
Extended Types</h3>

<p>As shown in the example above, ExtendedTypes are stored by <a href="/confluence/display/CAYDOC/DbAdapter"
title="DbAdapter">DbAdapter</a>. In fact DbAdapters often install their own extended
types to address incompatibilities, incompleteness and differences between JDBC drivers in
handling "standard" JDBC types. For instance some drivers support reading large character
columns (CLOB) as java.sql.Clob, but some other - as "character stream", etc. Adapters provided
with Cayenne override <tt>configureExtendedTypes()</tt> method to install their
own types, possibly substituting Cayenne defaults. Custom DbAdapters can use the same technique.</p>

<h3><a name="ExtendedTypes-ROPConsiderations"></a>ROP Considerations</h3>

<p>If you are using Cayenne in a three tier (ROP) environment, serialization of the
extended type becomes important. More information can be found <a href="/confluence/display/CAYDOC/Remote+Object+Persistence+Customization"
title="Remote Object Persistence Customization">here.</a></p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAYDOC/Extended+Types">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=10656&revisedVersion=16&originalVersion=15">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAYDOC/Extended+Types?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message