public interface RequestResult extends AutoCloseable
Request
.
A RequestResult
instance must always be closed after its use.
Here is a code sample benefiting from the automatic closing provided by
AutoCloseable
and its associated try
-with-resources notation:
try (RequestResult result = ...)
{
for (Adaptation record; (record = result.nextAdaptation()) != null;)
{
...
}
}
Alternate implementation:
try (RequestResult result = ...)
{
while (true)
{
Adaptation record = result.nextAdaptation();
if (record == null)
break;
...
}
}
A RequestResult
instance is not thread-safe and
it must be used only by the thread that created it.
If the table is concurrently updated, the rules specified by Query snapshot isolation apply.
Request
,
QueryResult
,
Query snapshot isolationModifier and Type | Method and Description |
---|---|
void |
close()
This method must always be invoked once this result is no longer used,
so as 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()
Returns the underlying table.
|
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()
Deprecated.
This method does not do anything: in accordance to
Query snapshot isolation,
the result is frozen when
Request.execute() is called.
Close this RequestResult and
execute again the Request
to take into account the latest in-procedure changes. |
boolean |
refreshIfNeeded()
Deprecated.
This method does not do anything: in accordance to
Query snapshot isolation,
the result is frozen when
Request.execute() is called.
Close this RequestResult and
execute again the Request
to take into account the latest in-procedure changes. |
Adaptation nextAdaptation() throws RepositoryAccessException
null
if the result
has no more elements.
The client code must follow the rules specified by Closing the result and Concurrency.
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
This method is idempotent: calling close
on a RequestResult
object that is already closed is a no-op.
close
in interface AutoCloseable
RepositoryAccessException
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).
Warning: This method has an inherent cost and invoking it must be avoided if the result is then traversed.
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 or
if invoked many times.
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 happen if the table has been updated or if the request has been modified
(via a set...
method).
@Deprecated void refresh() throws IncompatibleChangeError, RepositoryAccessException
Request.execute()
is called.
Close this RequestResult
and
execute again the Request
to take into account the latest in-procedure changes.@Deprecated boolean refreshIfNeeded() throws IncompatibleChangeError, RepositoryAccessException
Request.execute()
is called.
Close this RequestResult
and
execute again the Request
to take into account the latest in-procedure changes.false
.IncompatibleChangeError
RepositoryAccessException