blob: de25ba75c09b899491e7604ecdde4b9d97e13f62 [file] [log] [blame]
Title: Custom DbAdapter
<H2><A name="CustomDbAdapter-HowdoIwriteanadaptertosupportadatabasethatisnotyetsupported%3F"></A>How do I write an adapter to support a database that is not yet supported?</H2>
<P>You need to implement a custom <A href="http://cayenne.apache.org/doc/api/org/apache/cayenne/dba/DbAdapter.html" class="external-link" rel="nofollow">DbAdapter</A>. Most likely you won't have to do it from scratch and can extend a JdbcAdapter or one of the existing db-specific adapters. </P>
<H3><A name="CustomDbAdapter-IftheadapterisforadatabasethatwecurrentlydonotsupportandyouareplanningtodonateittoCayenne%2Cyoucandothisfirst%3A"></A>If the adapter is for a database that we currently do not support and you are planning to donate it to Cayenne, you can do this first:</H3>
<UL>
<LI>Open a JIRA issue where all contributed code will go.</LI>
<LI><A href="http://cayenne.apache.org/mailing-lists.html" class="external-link" rel="nofollow">Subscribe</A> to the developer mailing list and introduce yourself to Cayenne developers.</LI>
</UL>
<H5><A name="CustomDbAdapter-Implementationprocedureisroughlythefollowing%3A"></A>Implementation procedure is roughly the following:</H5>
<UL>
<LI><A href="http://cayenne.apache.org/code-repository.html" class="external-link" rel="nofollow">Check out</A> the latest Cayenne source from SVN. If you use Eclipse, follow <A href="http://cayenne.apache.org/eclipse.html" class="external-link" rel="nofollow">these instructions</A> to setup the projects.</LI>
</UL>
<UL>
<LI>Create a barebone adapter that inherits from JdbcAdapter.</LI>
</UL>
<DIV class="panelMacro"><TABLE class="tipMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cayenne.apache.org/docs/3.0/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>It is a good idea to put all new adapter code in its own Java package, e.g. <TT>org.apache.cayenne.dba.mydb</TT>, as default resource loading depends on that.</TD></TR></TABLE></DIV>
<UL>
<LI>Copy <TT>types.xml</TT> file from org.apache.cayenne.dba package and edit it to map standard JDBC types to the target database native types.</LI>
</UL>
<DIV class="panelMacro"><TABLE class="tipMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cayenne.apache.org/docs/3.0/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD>Correct mapping is needed for the Modeler to do schema generation. Technically it is not required for the runtime. However <TT>types.xml</TT> should still be there.</TD></TR></TABLE></DIV>
<UL>
<LI><A href="http://cayenne.apache.org/running-unit-tests.html" class="external-link" rel="nofollow">Run existing Cayenne unit tests</A> with the new adapter, analyze the failures and change adapter code accordingly.</LI>
<LI>Repeat the last step until all tests pass.</LI>
<LI>Report success in JIRA and the dev list - one of the committers will integrate your code to Cayenne.</LI>
</UL>