1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
<!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_60) on Tue Feb 17 12:25:55 EST 2015 -->
<title>PrimaryKey (Oracle - Berkeley DB Java API)</title>
<meta name="date" content="2015-02-17">
<link rel="stylesheet" type="text/css" href="../../../../style.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="PrimaryKey (Oracle - Berkeley DB Java API)";
}
//-->
</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="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"><em><b>Berkeley DB</b><br><font size="-1"> version 6.1.23</font></em></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="strong">Prev Class</span></a></li>
<li><a href="../../../../com/sleepycat/persist/model/PrimaryKeyMetadata.html" title="class 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/PrimaryKey.html" target="_top">Frames</a></li>
<li><a href="PrimaryKey.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>Required | </li>
<li><a href="#annotation_type_optional_element_summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail: </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="strong">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.</p>
<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>
<br>
<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>
</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="overviewSummary" 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"> </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><strong><a href="../../../../com/sleepycat/persist/model/PrimaryKey.html#sequence()">sequence</a></strong></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 java.lang.String 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/db/Sequence.html" title="class in com.sleepycat.db"><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,%20com.sleepycat.db.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>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><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="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"><em><b>Berkeley DB</b><br><font size="-1"> version 6.1.23</font></em></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="strong">Prev Class</span></a></li>
<li><a href="../../../../com/sleepycat/persist/model/PrimaryKeyMetadata.html" title="class 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/PrimaryKey.html" target="_top">Frames</a></li>
<li><a href="PrimaryKey.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>Required | </li>
<li><a href="#annotation_type_optional_element_summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail: </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) 1996, 2015 Oracle and/or its affiliates. All rights reserved.</font></small></p>
</body>
</html>
|