je/docs/java/com/sleepycat/persist/model/PrimaryKey.html

377 lines
15 KiB
HTML
Raw Normal View History

2021-06-06 17:46:45 +00:00
<!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 (1.8.0_151) on Tue Oct 31 17:36:47 EDT 2017 -->
<title>PrimaryKey (Oracle - Berkeley DB Java Edition API)</title>
<meta name="date" content="2017-10-31">
<link rel="stylesheet" type="text/css" href="../../../../style.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="PrimaryKey (Oracle - Berkeley DB Java Edition API)";
}
}
catch(err) {
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<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="class-use/PrimaryKey.html">Use</a></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 class="aboutLanguage"><b>Berkeley DB Java Edition</b><br><font size=\"-1\"> version 7.5.11</font>
</div>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../com/sleepycat/persist/model/PersistentProxy.html" title="interface in com.sleepycat.persist.model"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../com/sleepycat/persist/model/PrimaryKeyMetadata.html" title="class in com.sleepycat.persist.model"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?com/sleepycat/persist/model/PrimaryKey.html" target="_top">Frames</a></li>
<li><a href="PrimaryKey.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../allclasses-noframe.html">All&nbsp;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:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.element.detail">Element</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="Annotation Type PrimaryKey" class="title">Annotation Type PrimaryKey</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>@Documented
@Retention(value=RUNTIME)
@Target(value=FIELD)
public @interface <span class="memberNameLabel">PrimaryKey</span></pre>
<div class="block">Indicates the primary key field of an entity class. The value of the
primary key field is the unique identifier for the entity in a <a href="../../../../com/sleepycat/persist/PrimaryIndex.html" title="class in com.sleepycat.persist"><code>PrimaryIndex</code></a>.
<p><a href="../../../../com/sleepycat/persist/model/PrimaryKey.html" title="annotation in com.sleepycat.persist.model"><code>PrimaryKey</code></a> may appear on at most one declared field per
class.</p>
<p>Primary key values may be automatically assigned as sequential integers
using a <a href="../../../../com/sleepycat/persist/model/PrimaryKey.html#sequence--"><code>sequence()</code></a>. In this case the type of the key field is
restricted to a simple integer type.</p>
<p>A primary key field may not be null, unless it is being assigned from a
sequence.</p>
<p><a name="keyTypes"><strong>Key Field Types</strong></a></p>
<p>The type of a key field must either be one of the following:</p>
<ul>
<li>Any of the <a href="Entity.html#simpleTypes">simple types</a>.</li>
<li>An enum type.</li>
<li>A composite key class containing one or more simple type or enum
fields.</li>
</ul>
<p>Array types are not allowed.</p>
<p>When using a composite key class, each field of the composite key class
must be annotated with <a href="../../../../com/sleepycat/persist/model/KeyField.html" title="annotation in com.sleepycat.persist.model"><code>KeyField</code></a> to identify the storage order and
default sort order. See <a href="../../../../com/sleepycat/persist/model/KeyField.html" title="annotation in com.sleepycat.persist.model"><code>KeyField</code></a> for an example and more
information on composite keys.</p>
<p><a name="sortOrder"><strong>Key Sort Order</strong></a></p>
<p>Key field types, being simple types, have a well defined and reasonable
default sort order, described below. This sort order is based on a storage
encoding that allows a fast byte-by-byte comparison.</p>
<ul>
<li>All simple types except for <code>String</code> are encoded so that they are
sorted as expected, that is, as if the <code>Comparable.compareTo(T)</code> method
of their class (or, for primitives, their wrapper class) is called.</li>
<li>Strings are encoded as UTF-8 byte arrays. Zero (0x0000) character
values are UTF encoded as non-zero values, and therefore embedded zeros in
the string are supported. The sequence {0xC0,0x80} is used to
encode a zero character. This UTF encoding is the same one used by native
Java UTF libraries. However, this encoding of zero does impact the
lexicographical ordering, and zeros will not be sorted first (the natural
order) or last. For all character values other than zero, the default UTF
byte ordering is the same as the Unicode lexicographical character
ordering.</li>
</ul>
<p>When using a composite key class with more than one field, the sorting
order among fields is determined by the <a href="../../../../com/sleepycat/persist/model/KeyField.html" title="annotation in com.sleepycat.persist.model"><code>KeyField</code></a> annotations. To
override the default sort order, you can use a composite key class that
implements <code>Comparable</code>. This allows overriding the sort order and is
therefore useful even when there is only one key field in the composite key
class. See <a href="KeyField.html#comparable">Custom Sort Order</a>
for more information on sorting of composite keys.</p>
<p><a name="inherit"><strong>Inherited Primary Key</strong></a></p>
<p>If it does not appear on a declared field in the entity class, <code>PrimaryKey</code> must appear on a field of an entity superclass. In the
following example, the primary key on the base class is used:</p>
<pre class="code">
@Persistent
class BaseClass {
@PrimaryKey
long id;
...
}
@Entity
class Employee extends BaseClass {
// inherits id primary key
...
}</pre>
<p>If more than one class with <code>PrimaryKey</code> is present in a class
hierarchy, the key in the most derived class is used. In this case, primary
key fields in superclasses are "shadowed" and are not persistent. In the
following example, the primary key in the base class is not used and is not
persistent:</p>
<pre class="code">
@Persistent
class BaseClass {
@PrimaryKey
long id;
...
}
@Entity
class Employee extends BaseClass {
// overrides id primary key
@PrimaryKey
String uuid;
...
}</pre>
<p>Note that a <code>PrimaryKey</code> is not allowed on entity subclasses. The
following is illegal and will cause an <code>IllegalArgumentException</code> when
trying to store an <code>Employee</code> instance:</p>
<pre class="code">
@Entity
class Person {
@PrimaryKey
long id;
...
}
@Persistent
class Employee extends Person {
@PrimaryKey
String uuid;
...
}</pre></div>
<dl>
<dt><span class="simpleTagLabel">Author:</span></dt>
<dd>Mark Hayes</dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.optional.element.summary">
<!-- -->
</a>
<h3>Optional Element Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Optional Element Summary table, listing optional elements, and an explanation">
<caption><span>Optional Elements</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Optional Element and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../com/sleepycat/persist/model/PrimaryKey.html#sequence--">sequence</a></span></code>
<div class="block">The name of a sequence from which to assign primary key values
automatically.</div>
</td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.element.detail">
<!-- -->
</a>
<h3>Element Detail</h3>
<a name="sequence--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>sequence</h4>
<pre>public abstract&nbsp;java.lang.String&nbsp;sequence</pre>
<div class="block">The name of a sequence from which to assign primary key values
automatically. If a non-empty string is specified, sequential integers
will be assigned from the named sequence.
<p>A single sequence may be used for more than one entity class by
specifying the same sequence name for each <code>PrimaryKey</code>. For
each named sequence, a <a href="../../../../com/sleepycat/je/Sequence.html" title="class in com.sleepycat.je"><code>Sequence</code></a> will be used to
assign key values. For more information on configuring sequences, see
<a href="../../../../com/sleepycat/persist/EntityStore.html#setSequenceConfig-java.lang.String-com.sleepycat.je.SequenceConfig-"><code>EntityStore.setSequenceConfig</code></a>.</p>
<p>To use a sequence, the type of the key field must be a primitive
integer type (<code>byte</code>, <code>short</code>, <code>int</code> or <code>long</code>)
or the primitive wrapper class for one of these types. A composite key
class may also be used to override sort order, but it may contain only a
single key field, and this field must have one of the types previously
mentioned.</p>
<p>When an entity with a primary key sequence is stored using one of the
<code>put</code> methods in the <a href="../../../../com/sleepycat/persist/PrimaryIndex.html" title="class in com.sleepycat.persist"><code>PrimaryIndex</code></a>, a new key will be
assigned if the primary key field in the entity instance is null (for a
reference type) or zero (for a primitive integer type). Specifying zero
for a primitive integer key field is allowed because the initial value
of the sequence is one (not zero) by default. If the sequence
configuration is changed such that zero is part of the sequence, then
the field type must be a primitive wrapper class and the field value
must be null to cause a new key to be assigned.</p>
<p>When one of the <code>put</code> methods in the <a href="../../../../com/sleepycat/persist/PrimaryIndex.html" title="class in com.sleepycat.persist"><code>PrimaryIndex</code></a>
is called and a new key is assigned, the assigned value is returned to
the caller via the key field of the entity object that is passed as a
parameter.</p></div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the sequence name or an empty string.</dd>
</dl>
<dl>
<dt>Default:</dt>
<dd>""</dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<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="class-use/PrimaryKey.html">Use</a></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 class="aboutLanguage"><b>Berkeley DB Java Edition</b><br><font size=\"-1\"> version 7.5.11</font>
</div>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../com/sleepycat/persist/model/PersistentProxy.html" title="interface in com.sleepycat.persist.model"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../com/sleepycat/persist/model/PrimaryKeyMetadata.html" title="class in com.sleepycat.persist.model"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?com/sleepycat/persist/model/PrimaryKey.html" target="_top">Frames</a></li>
<li><a href="PrimaryKey.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../allclasses-noframe.html">All&nbsp;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:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small><font size=1>Copyright (c) 2002, 2017 Oracle and/or its affiliates. All rights reserved.</font> </small></p>
</body>
</html>