public class SJoinCursor
extends java.lang.Object
implements java.lang.AutoCloseable
A join cursor is returned when calling SDatabase.join(com.sleepycat.client.SCursor[], com.sleepycat.client.SJoinConfig).
To open a join cursor using two secondary cursors:
STransaction txn = ...
SDatabase primaryDb = ...
SSecondaryDatabase secondaryDb1 = ...
SSecondaryDatabase secondaryDb2 = ...
SSecondaryCursor cursor1 = null;
SSecondaryCursor cursor2 = null;
SJoinCursor joinCursor = null;
try {
SDatabaseEntry key = new SDatabaseEntry();
SDatabaseEntry data = new SDatabaseEntry();
cursor1 = secondaryDb1.openSecondaryCursor(txn, null);
cursor2 = secondaryDb2.openSecondaryCursor(txn, null);
key.setData(...); // initialize key for secondary index 1
SOperationStatus status1 =
cursor1.getSearchKey(key, data, SLockMode.DEFAULT);
key.setData(...); // initialize key for secondary index 2
OperationStatus status2 =
cursor2.getSearchKey(key, data, SLockMode.DEFAULT);
if (status1 == OperationStatus.SUCCESS &&
status2 == OperationStatus.SUCCESS) {
SSecondaryCursor[] cursors = {cursor1, cursor2};
joinCursor = primaryDb.join(cursors, null);
while (true) {
SOperationStatus joinStatus = joinCursor.getNext(key, data,
SLockMode.DEFAULT);
if (joinStatus == OperationStatus.SUCCESS) {
// Do something with the key and data.
} else {
break;
}
}
}
} finally {
if (cursor1 != null) {
cursor1.close();
}
if (cursor2 != null) {
cursor2.close();
}
if (joinCursor != null) {
joinCursor.close();
}
}
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the cursors that have been opened by this join cursor.
|
SJoinConfig |
getConfig()
Returns this object's configuration.
|
SDatabase |
getDatabase()
Returns the primary database handle associated with this cursor.
|
SOperationStatus |
getNext(SDatabaseEntry key,
SDatabaseEntry data,
SLockMode lockMode)
Returns the next primary key and data resulting from the join operation.
|
SOperationStatus |
getNext(SDatabaseEntry key,
SLockMode lockMode)
Returns the next primary key resulting from the join operation.
|
default <V> V |
handleRuntimeExceptions(com.sleepycat.client.RemoteServiceCallable<V> remote) |
default <V> V |
remoteCall(com.sleepycat.client.RemoteServiceCallable<V> remote) |
default <V> V |
remoteCallWithIOException(com.sleepycat.client.RemoteServiceCallable<V> remote) |
public void close()
throws SDatabaseException
The cursors passed to SDatabase.join(com.sleepycat.client.SCursor[], com.sleepycat.client.SJoinConfig) are not closed by this
method, and should be closed by the caller.
close in interface java.lang.AutoCloseableSDatabaseException - if any error occurspublic SJoinConfig getConfig()
public SDatabase getDatabase()
public SOperationStatus getNext(SDatabaseEntry key, SLockMode lockMode) throws SDatabaseException
An entry is returned by the join cursor for each primary key/data pair
having all secondary key values that were specified using the array of
secondary cursors passed to SDatabase.join(com.sleepycat.client.SCursor[], com.sleepycat.client.SJoinConfig).
key - the primary key returned as outputlockMode - the locking attributes; if null, default attributes are
usedSOperationStatus.NOTFOUND if no matching key/data pair is
found; SOperationStatus.KEYEMPTY if the database is a Queue or
Recno database and the specified key exists, but was never explicitly
created by the application or was later deleted; otherwise, SOperationStatus.SUCCESS.SDatabaseException - if any error occurspublic SOperationStatus getNext(SDatabaseEntry key, SDatabaseEntry data, SLockMode lockMode) throws SDatabaseException
An entry is returned by the join cursor for each primary key/data pair
having all secondary key values that were specified using the array of
secondary cursors passed to SDatabase.join(com.sleepycat.client.SCursor[], com.sleepycat.client.SJoinConfig).
key - the primary key returned as outputdata - the primary data returned as outputlockMode - the locking attributes; if null, default attributes are
usedSOperationStatus.NOTFOUND if no matching key/data pair is
found; SOperationStatus.KEYEMPTY if the database is a Queue or
Recno database and the specified key exists, but was never explicitly
created by the application or was later deleted; otherwise, SOperationStatus.SUCCESS.SDatabaseException - if any error occurspublic <V> V remoteCallWithIOException(com.sleepycat.client.RemoteServiceCallable<V> remote)
throws java.io.IOException
java.io.IOExceptionpublic <V> V remoteCall(com.sleepycat.client.RemoteServiceCallable<V> remote)
public <V> V handleRuntimeExceptions(com.sleepycat.client.RemoteServiceCallable<V> remote)
throws org.apache.thrift.TException
org.apache.thrift.TExceptionCopyright (c) 2016, 2019 Oracle and/or its affiliates. All rights reserved.