<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!--NewPage--> <HTML> <HEAD> <!-- Generated by javadoc (build 1.6.0_0) on Wed Dec 30 04:50:33 EST 2009 --> <TITLE> KeyField </TITLE> <META NAME="date" CONTENT="2009-12-30"> <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style"> <SCRIPT type="text/javascript"> function windowTitle() { if (location.href.indexOf('is-external=true') == -1) { parent.document.title="KeyField"; } } </SCRIPT> <NOSCRIPT> </NOSCRIPT> </HEAD> <BODY BGCOLOR="white" onload="windowTitle();"> <HR> <!-- ========= START OF TOP NAVBAR ======= --> <A NAME="navbar_top"><!-- --></A> <A HREF="#skip-navbar_top" title="Skip navigation links"></A> <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> <TR> <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A NAME="navbar_top_firstrow"><!-- --></A> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR> </TABLE> </TD> <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> </EM> </TD> </TR> <TR> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../com/sleepycat/persist/model/FieldMetadata.html" title="class in com.sleepycat.persist.model"><B>PREV CLASS</B></A> <A HREF="../../../../com/sleepycat/persist/model/ModelInternal.html" title="class in com.sleepycat.persist.model"><B>NEXT CLASS</B></A></FONT></TD> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../index.html?com/sleepycat/persist/model/KeyField.html" target="_top"><B>FRAMES</B></A> <A HREF="KeyField.html" target="_top"><B>NO FRAMES</B></A> <SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> </SCRIPT> <NOSCRIPT> <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A> </NOSCRIPT> </FONT></TD> </TR> <TR> <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: <A HREF="#annotation_type_required_element_summary">REQUIRED</A> | OPTIONAL</FONT></TD> <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> DETAIL: <A HREF="#annotation_type_element_detail">ELEMENT</A></FONT></TD> </TR> </TABLE> <A NAME="skip-navbar_top"></A> <!-- ========= END OF TOP NAVBAR ========= --> <HR> <!-- ======== START OF CLASS DATA ======== --> <H2> <FONT SIZE="-1"> com.sleepycat.persist.model</FONT> <BR> Annotation Type KeyField</H2> <HR> <DL> <DT><PRE><FONT SIZE="-1">@Documented @Retention(value=RUNTIME) @Target(value=FIELD) </FONT>public @interface <B>KeyField</B></DL> </PRE> <P> Indicates the sorting position of a key field in a composite key class when the <code>Comparable</code> interface is not implemented. The <code>KeyField</code> integer value specifies the sort order of this field within the set of fields in the composite key. <p>If the field type of a <A HREF="../../../../com/sleepycat/persist/model/PrimaryKey.html" title="annotation in com.sleepycat.persist.model"><CODE>PrimaryKey</CODE></A> or <A HREF="../../../../com/sleepycat/persist/model/SecondaryKey.html" title="annotation in com.sleepycat.persist.model"><CODE>SecondaryKey</CODE></A> is a composite key class containing more than one key field, then a <code>KeyField</code> annotation must be present on each non-transient instance field of the composite key class. The <code>KeyField</code> value must be a number between one and the number of non-transient instance fields declared in the composite key class.</p> <p>Note that a composite key class is a flat container for one or more simple type fields. All non-transient instance fields in the composite key class are key fields, and the composite key class may not have superclasses containing non-transient instance fields.</p> <p>For example:</p> <pre class="code"> @Entity class Animal { @PrimaryKey Classification classification; ... } @Persistent class Classification { @KeyField(1) String kingdom; @KeyField(2) String phylum; @KeyField(3) String clazz; @KeyField(4) String order; @KeyField(5) String family; @KeyField(6) String genus; @KeyField(7) String species; @KeyField(8) String subspecies; ... }</pre> <p>This causes entities to be sorted first by <code>kingdom</code>, then by <code>phylum</code> within <code>kingdom</code>, and so on.</p> <p>The fields in a composite key class may not be null.</p> <p><a name="comparable"><strong>Custom Sort Order</strong></a></p> <p>To override the default sort order, a composite key class may implement the <CODE>Comparable</CODE> interface. This allows overriding the sort order and is therefore useful even when there is only one key field in the composite key class. For example, the following class sorts Strings using a Canadian collator:</p> <pre class="code"> import java.text.Collator; import java.util.Locale; @Entity class Animal { ... @SecondaryKey(relate=ONE_TO_ONE) CollatedString canadianName; ... } @Persistent class CollatedString implements Comparable<CollatedString> { static Collator collator = Collator.getInstance(Locale.CANADA); @KeyField(1) String value; CollatedString(String value) { this.value = value; } private CollatedString() {} public int compareTo(CollatedString o) { return collator.compare(value, o.value); } }</pre> <p>Several important rules should be considered when implementing a custom comparison method. Failure to follow these rules may result in the primary or secondary index becoming unusable; in other words, the store will not be able to function.</p> <ol> <li>The comparison method must always return the same result, given the same inputs. The behavior of the comparison method must not change over time.</li> <br> <li>A corollary to the first rule is that the behavior of the comparison method must not be dependent on state which may change over time. For example, if the above collation method used the default Java locale, and the default locale is changed, then the sort order will change.</li> <br> <li>The comparison method must not assume that it is called after the store has been opened. With Berkeley DB Java Edition, the comparison method is called during database recovery, which occurs in the <A HREF="../../../../com/sleepycat/db/Environment.html" title="class in com.sleepycat.db"><CODE>Environment</CODE></A> constructor.</li> <br> <li>The comparison method must not assume that it will only be called with keys that are currently present in the database. The comparison method will occasionally be called with deleted keys or with keys for records that were not part of a committed transaction.</li> </ol> <P> <P> <HR> <P> <!-- =========== ANNOTATION TYPE REQUIRED MEMBER SUMMARY =========== --> <A NAME="annotation_type_required_element_summary"><!-- --></A> <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> <B>Required Element Summary</B></FONT></TH> </TR> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> int</CODE></FONT></TD> <TD><CODE><B><A HREF="../../../../com/sleepycat/persist/model/KeyField.html#value()">value</A></B></CODE> <BR> </TD> </TR> </TABLE> <P> <!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== --> <A NAME="annotation_type_element_detail"><!-- --></A> <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> <B>Element Detail</B></FONT></TH> </TR> </TABLE> <A NAME="value()"><!-- --></A><H3> value</H3> <PRE> public abstract int <B>value</B></PRE> <DL> <DD><DL> </DL> </DD> <DD><DL> </DL> </DL> <!-- ========= END OF CLASS DATA ========= --> <HR> <!-- ======= START OF BOTTOM NAVBAR ====== --> <A NAME="navbar_bottom"><!-- --></A> <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A> <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> <TR> <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A NAME="navbar_bottom_firstrow"><!-- --></A> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR> </TABLE> </TD> <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> </EM> </TD> </TR> <TR> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../com/sleepycat/persist/model/FieldMetadata.html" title="class in com.sleepycat.persist.model"><B>PREV CLASS</B></A> <A HREF="../../../../com/sleepycat/persist/model/ModelInternal.html" title="class in com.sleepycat.persist.model"><B>NEXT CLASS</B></A></FONT></TD> <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../index.html?com/sleepycat/persist/model/KeyField.html" target="_top"><B>FRAMES</B></A> <A HREF="KeyField.html" target="_top"><B>NO FRAMES</B></A> <SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> </SCRIPT> <NOSCRIPT> <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A> </NOSCRIPT> </FONT></TD> </TR> <TR> <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: <A HREF="#annotation_type_required_element_summary">REQUIRED</A> | OPTIONAL</FONT></TD> <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> DETAIL: <A HREF="#annotation_type_element_detail">ELEMENT</A></FONT></TD> </TR> </TABLE> <A NAME="skip-navbar_bottom"></A> <!-- ======== END OF BOTTOM NAVBAR ======= --> <HR> </BODY> </HTML>