public interface RequestResult extends AutoCloseable
Request
.
For multi-threading on a single RequestResult
instance, the method
nextAdaptation()
is not synchronized. If multiple threads invoke
it concurrently on the same instance, they must be synchronized externally.
If the table is concurrently updated, the general rules regarding Concurrency and isolation levels apply.
Request
,
Concurrency and isolation levelsModifier and Type | Method and Description |
---|---|
void |
close()
This method must be invoked after having invoked the methods
nextAdaptation()
to ensure that underlying resources are released. |
boolean |
contains(Adaptation aRecord)
Returns
true if the specified record belongs to the result of this request
(even if the record is obsolete). |
Request |
getRequest()
Returns the request that created this result.
|
int |
getSize()
Returns the total number of records held by this result.
|
AdaptationTable |
getTable() |
boolean |
isEmpty()
Returns
true if the result is empty (that is, size is 0). |
boolean |
isObsolete()
Returns
true if this result may have changed since last computation. |
boolean |
isSizeEqual(int aSize)
Verifies the number of records contained in this result.
|
boolean |
isSizeGreaterOrEqual(int minimalSize)
Verifies the number of records contained in this result.
|
Adaptation |
nextAdaptation()
Moves the cursor to the next record in the result
and returns it.
|
void |
refresh()
Forces a full re-computation of this result.
|
boolean |
refreshIfNeeded()
Performs a refresh of the result if it may have changed.
|
Adaptation nextAdaptation() throws RepositoryAccessException
null
if the result
has no more elements.
After the retrieved records have been processed, it is mandatory to invoke
the close()
method. Otherwise, some system resources will fail to be released.
This code sample demonstrates an iteration over the entire result:
try (RequestResult result = ...) { for (Adaptation record; (record = result.nextAdaptation()) != null;) { ... } }
An alternate implementation of the iteration:
try (RequestResult result = ...) { while (true) { Adaptation record = result.nextAdaptation(); if (record == null) break; ... } }
See Concurrency for information.
In mapped mode, on PostgreSQL, cursors are invalidated at transaction commit. This means
that this method can no longer be called after the transaction is committed.
The same restriction applies when a commit threshold
is specified.
null
if there are no more elements.RepositoryAccessException
void close() throws RepositoryAccessException
nextAdaptation()
to ensure that underlying resources are released.
This method is idempotent: calling close
on a RequestResult
object that is already closed is a no-op.
close
in interface AutoCloseable
RepositoryAccessException
nextAdaptation()
boolean contains(Adaptation aRecord) throws RepositoryAccessException
true
if the specified record belongs to the result of this request
(even if the record is obsolete).RepositoryAccessException
Request getRequest()
AdaptationTable getTable()
boolean isEmpty() throws RepositoryAccessException
true
if the result is empty (that is, size is 0).RepositoryAccessException
isSizeGreaterOrEqual(int)
boolean isSizeGreaterOrEqual(int minimalSize) throws RepositoryAccessException
This method returns as soon as it has fetched the
specified number of records.
Thus, it has a lower computational cost than getSize()
,
and is intended as an optimization for cases when the full
computation of the request is not necessary.
minimalSize
- the minimal size required.IllegalArgumentException
- if specified size is negative.RepositoryAccessException
isSizeEqual(int)
boolean isSizeEqual(int aSize)
This method returns as soon as it has fetched the
specified number of records.
Thus, it has a lower computational cost than getSize()
,
and is intended as an optimization for cases when the full
computation of the request is not necessary.
IllegalArgumentException
- if specified size is negative.isSizeGreaterOrEqual(int)
int getSize() throws RepositoryAccessException
Warning: As this method must perform the full computation
of the result, it may be costly for large numbers of records.
For an iteration, it is preferable to use the method nextAdaptation()
than a loop from 0 to getSize()
.
If the client application only needs to check that the result has a minimum
size, it is recommended to invoke the method isSizeGreaterOrEqual(int)
;
for an exact size, invoke isSizeEqual(int)
.
RepositoryAccessException
isEmpty()
,
isSizeEqual(int)
,
isSizeGreaterOrEqual(int)
boolean isObsolete()
true
if this result may have changed since last computation.
This may happens if the table has been updated or if the request has been modified
(via a set...
method).
refreshIfNeeded()
void refresh() throws IncompatibleChangeError, RepositoryAccessException
IncompatibleChangeError
- if the underlying data model has become unavailable or table node has
been removed from the data model.RepositoryAccessException
boolean refreshIfNeeded() throws IncompatibleChangeError, RepositoryAccessException
true
if a refresh has been performed, false
otherwise.IncompatibleChangeError
RepositoryAccessException
isObsolete()
,
Adaptation.getUpToDateInstance()