Interface OracleOperationBuilder
-
public interface OracleOperationBuilderAnOracleOperationBuilderbuilds and executes various read and write operations on theOracleCollection, in a chainable manner.An
OracleOperationBuilderis first obtained by calling aOracleCollection.find().OracleOperationBuilderprovides two types of methods: terminal and non-terminal.Non-terminal methods are used to build up the operation in a chainable manner. They return the same
OracleOperationBuilderobject, on which other non-terminal or terminal methods can be chained. Non-terminal methods do not cause operation creation or execution. Under the hood, they simply store additional state information in theOracleOperationBuilderobject, capturing the specified parts of the operation.Unlike non-terminal methods, terminal methods actually cause operation creation and execution.
For example:
OracleCollection ocollection = ...; OracleCursor ocursor = ocollection.find().keys(keys).skip(25).limit(25).getCursor();In this example,keys(Set),skip(long), andlimit(int)are non-terminal methods that specify parts of the operation. More concretely, they specify that documents matching provided keys should be returned, the first 25 of these results should be skipped,and the number of results should be limited to 25. ThegetCursor()method is a terminal, so it builds the operation from the specified parts and executes it.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description longcount()Counts the number of documents.OracleOperationBuilderfilter(String filterSpecification)Finds documents matching a filter specification (a query-by-example expressed in JSON).OracleOperationBuilderfilter(OracleDocument filterSpecification)Finds documents matching a filter specification (a query-by-example expressed in JSON).OracleCursorgetCursor()ReturnsOracleCursorwhich is an iterator over result documents.OracleDocumentgetOne()Returns a single document.OracleOperationBuilderheaderOnly()Specifies that the returned documents should contain only the the following: key, creation-on timestamp (if present in the collection), last-modified timestamp (if present in the collection), version (if present in the collection). The documents' contents will not be returned.OracleOperationBuilderhint(String hints)Adds execution hints to the operationOracleOperationBuilderkey(String key)Finds a document with a specific key.OracleOperationBuilderkeyLike(String pattern, String escape)Finds documents with keys matching a suppliedpattern.OracleOperationBuilderkeys(Set<String> keys)Finds documents with specific keys.OracleOperationBuilderlimit(int limit)Specifies an upper limit on the number of results.OracleOperationBuilderlock()Indicates that the operation should lock the documents.booleanmergeOne(OracleDocument document)Merges the specified document into an existing one.OracleDocumentmergeOneAndGet(OracleDocument document)Merges a document.OracleOperationBuilderorderByKey(boolean order)Specifies whether implicit order by should be included for operations involvingskip(long)orlimit(int).intremove()Removes documents.intreplace(OracleDocument document)Replaces target document(s) with supplied document.booleanreplaceOne(OracleDocument document)Replaces target document with supplied document.OracleDocumentreplaceOneAndGet(OracleDocument document)Replaces target document with supplied document.OracleOperationBuilderskip(long skip)Specifies the number of results to skip.OracleOperationBuilderstartKey(String startKey, Boolean ascending, Boolean inclusive)Specifies that only keys that come after (or alternatively before) the specified key.OracleOperationBuilderversion(String version)Finds a document with a specific version.
-
-
-
Method Detail
-
keys
OracleOperationBuilder keys(Set<String> keys) throws OracleException
Finds documents with specific keys.This is a non-terminal method, and, as such, it does not cause operation execution.
If this method is invoked in conjunction with
key(String)orkeyLike(String, String)on the sameOracleOperationBuilderobject, then only the method specified last will be honored, and the preceding ones will be ignored.Example:
// key(...) is ignored, because keys(...) is set last. col.find().key(...).keys(...).getCursor();- Parameters:
keys- a set of keys. Cannot benull- Returns:
OracleOperationBuilder- Throws:
OracleException- ifkeysisnull, or doesn't return any elements
-
key
OracleOperationBuilder key(String key) throws OracleException
Finds a document with a specific key.This is a non-terminal method, and, as such, it does not cause operation execution.
If this method is invoked in conjunction with
keys(Set)orkeyLike(String, String)on the sameOracleOperationBuilderobject, then only the method specified last will be honored, and the preceding ones will be ignored.Example:
// keys(...) is ignored, because key(...) is set last. col.find().keys(...).key(...).getOne();- Parameters:
key- the key. Cannot benull- Returns:
OracleOperationBuilder- Throws:
OracleException- if the key isnull
-
keyLike
OracleOperationBuilder keyLike(String pattern, String escape) throws OracleException
Finds documents with keys matching a suppliedpattern.This method is only supported on collections with client-assigned keys, and a key column of type varchar2.
The
patterncan contain special pattern matching characters _ (which matches any single character), or % (which matches zero or more characters). Theescapeparameter allows specifying an optional escape character, which is used to test for literal occurences of the special pattern matching characters _ and %.Example 1: passing "%mykey%" for
pattern, andnullforescapewill match documents with keys containing the string "mykey", e.g "mykey20" or "20mykey".Example 2: passing "key_1" for
pattern, andnullforescapewill match documents with keys that start with the string "key" followed by any single character, followed by "1", e.g. "keyA1" or "keyB1".Example 3: passing "mykey!_1" for
pattern, and ! forescapewill match a document with key "mykey_1". Since the _ is escaped in the supplied pattern, it is matched literally.The
patternandescapecharacter parameters correspond to the pattern and escape of the Oracle SQL LIKE condition.This is a non-terminal method, and, as such, it does not cause operation execution.
If this method is invoked in conjunction with
key(String)orkeys(Set)on the sameOracleOperationBuilderobject, then only the method specified last will be honored, and the preceding ones will be ignored.Example:
// keys(...) is ignored, because keyLike(...) is set last. col.find().keys(...).keyLike(...).getCursor();- Parameters:
pattern- pattern. Can contain special pattern matching characters _ and %. Cannot benullescape- escape character. Can benull, which means no escape character will be used- Returns:
OracleOperationBuilder- Throws:
OracleException- if pattern isnull, or if this method cannot be invoked on a particular collection, because the latter doesn't have client-assigned keys of type varchar2- See Also:
- LIKE Condition
-
filter
OracleOperationBuilder filter(OracleDocument filterSpecification) throws OracleException
Finds documents matching a filter specification (a query-by-example expressed in JSON).This is a non-terminal method, and, as such, it does not cause operation execution.
- Parameters:
filterSpecification- the filter specification. Cannot benull- Returns:
OracleOperationBuilder- Throws:
OracleException- if thefilterSpecificationisnullor invalid
-
filter
OracleOperationBuilder filter(String filterSpecification) throws OracleException
Finds documents matching a filter specification (a query-by-example expressed in JSON). Calling this method is equivalent to the following:filter(db.createDocumentFromString(filterSpecification));- Parameters:
filterSpecification- the filter specification. Cannot benull- Returns:
OracleOperationBuilder- Throws:
OracleException- if thefilterSpecificationisnullor invalid
-
version
OracleOperationBuilder version(String version) throws OracleException
Finds a document with a specific version.This method can be used in conjunction with the
key(...)method to match a document with a specific key and version:col.find().key("k1").version("v1"). This combination is useful for optimistic locking.For example, replace-if-version operation can be specified as follows:
col.find("k1").version("v1").replaceOne(d1)Similarly, remove-if-version operation can be specified as follows:
col.find().key("k1").version("v1").remove()This is a non-terminal method, and, as such, it does not cause operation execution.
- Parameters:
version- version. Cannot benull- Returns:
OracleOperationBuilder- Throws:
OracleException- if the provided version isnull
-
getCursor
OracleCursor getCursor() throws OracleException
ReturnsOracleCursorwhich is an iterator over result documents.This is a terminal method, and, as such, it causes operation execution.
- Returns:
OracleCursor- Throws:
OracleException- if there's an error creating the cursor
-
replaceOneAndGet
OracleDocument replaceOneAndGet(OracleDocument document) throws OracleException
Replaces target document with supplied document.This method is used in conjunction with
key()and (optionally)version()methods.For example:
// Replace a document with the key "k1" and version "v1", // with the input document 'd1'. OracleDocument doc = col.find().key("k1").version("v1").replaceOneAndGet(d1)Note that the key and version information (if any) in the input document
'd1'is ignored.This is a terminal method, and, as such, it causes operation execution.
- Parameters:
document- input document. Cannot benull- Returns:
- result document which contains the key and (if present) the created-on timestamp, last-modified timestamp, and version only. The input document's content is not returned as part of the result document
- Throws:
OracleException- if (1) the input document isnull, or (2) there's an error replacing the inputdocument
-
replace
int replace(OracleDocument document) throws OracleException
Replaces target document(s) with supplied document.Unlike
replaceOne()andreplaceOneAndGet()method, this method does not requirekey()method to be used in conjunction. Note also: unlike the two "replace one" methods mentioned above, this method can replace multiple target documents in the collection with the supplied document.For example:
// Replace content of documents having field "_id" with value 1, // with the content of supplied document d1 col.find().filter("{\"_id\" : 1}").replace(d1)Note that the key and version information (if any) in the input document 'd1' is ignored.
This is a terminal method, and, as such, it causes operation execution.
- Parameters:
document- input document. Cannot benull- Returns:
- number of documents replaced
- Throws:
OracleException- if (1) the input document isnull, or (2) there's an error replacing the inputdocument
-
replaceOne
boolean replaceOne(OracleDocument document) throws OracleException
Replaces target document with supplied document.This method is used in conjunction with
key()and (optionally)version()methods.For example:
// Replace a document with the key "k1" and version "v1" // with the input document 'd1'. col.find().key("k1").version("v1").replaceOne(d1)Note that the key and version information (if any) in the input document 'd1' is ignored.
This is a terminal method, and, as such, it causes operation execution.
- Parameters:
document- input document. Cannot benull- Returns:
trueif the document was replaced successfully,falseotherwise- Throws:
OracleException- if (1) the input document isnull, or (2) there's an error replacing the inputdocument
-
remove
int remove() throws OracleExceptionRemoves documents.For example, the following removes a document with a particular key and version:
col.find().key("k1").version("v1").remove()Documents matching specific keys can be removed as follows:
col.find().keys(keys).remove().Documents matching a filter specification can be removed as follows:
col.find().filter(filterSpec).remove()This is a terminal method, and, as such, it causes operation execution.
- Returns:
- number of documents removed
- Throws:
OracleException- if an error during removal occurs
-
limit
OracleOperationBuilder limit(int limit) throws OracleException
Specifies an upper limit on the number of results.This is a non-terminal method, and, as such, it does not cause operation execution.
This method requires that the results are ordered. If an order is not explicitly specified using the
filter()method, the documents will be ordered by the document key. See alsostartKey()This method should only be invoked as part of building a read operation. If it's invoked as part of building a write operation (e.g. with replace, remove, etc.), it will have no effect. It is an error to specify this method in conjunction with a
count()terminal.- Parameters:
limit- limit on the number of results. Must be positive- Returns:
- this
OracleOperationBuilder - Throws:
OracleException- if thelimitis not positive
-
orderByKey
OracleOperationBuilder orderByKey(boolean order)
Specifies whether implicit order by should be included for operations involvingskip(long)orlimit(int).Documents are implicitly ordered by key, when skip() or limit() are used. This ensures a deterministic order by, which is needed for pagination.
This function can be used to avoid this order by. This might be appropriate, for example, when
limit(int)is used by itself, to simply return a bounded number of results.This method should only be invoked as part of building a read operation. If it is invoked as part of building a write operation (e.g. replace, remove, etc), it will have no effect.
This is a non-terminal method, and, as such, it does not cause operation execution.
- Parameters:
order- iffalse, operations involvingskip(long)orlimit(int)will not include an implicit sort. Iftrue, operations involvingskip(long)orlimit(int)will include an implicit sort. Note that specifyingtrueis equivalent to default behavior, in effect if this method is not invoked- Returns:
- this
OracleOperationBuilder
-
skip
OracleOperationBuilder skip(long skip) throws OracleException
Specifies the number of results to skip.This is a non-terminal method, and, as such, it does not cause operation execution.
This interface assumes the results are ordered (e.g. by key).
This method should only be invoked as part of building a read operation. If it's invoked as part of building a write operation (e.g. with replace, remove, etc.), it will have no effect. It is an error to specify this method in conjunction with a
count()terminal.- Parameters:
skip- number of results to skip. Must be non-negative- Returns:
OracleOperationBuilder- Throws:
OracleException- if theskipis negative
-
headerOnly
OracleOperationBuilder headerOnly()
Specifies that the returned documents should contain only the the following:- key,
- creation-on timestamp (if present in the collection),
- last-modified timestamp (if present in the collection),
- version (if present in the collection).
This is a non-terminal method, and, as such, it does not cause operation execution.
This method should only be invoked as part of building a read operation. If it's invoked as part of building a write operation (e.g. replace, remove, etc), it will have no effect. Also, this method will have no effect if invoked as part of building a
count()operation.- Returns:
- this
OracleOperationBuilder
-
count
long count() throws OracleExceptionCounts the number of documents.This is a terminal method, and, as such, it causes operation execution.
- Returns:
- document count
- Throws:
OracleException- if there is an error getting the count
-
getOne
OracleDocument getOne() throws OracleException
Returns a single document. Use this method to get the document from theOracleOperationBuilderreturned bykey(String), for example:col.find().key(key).getOne()If this method is used as a terminal for an operation that returns multiple documents, the first document is returned.
This is a terminal method, and, as such, it causes operation execution.
For the Oracle RDBMS implementation of SODA, the current limit for the maximum size of document that can be read is 2GB. An exception will be thrown by this method if the document's size exceeds this limit.
- Returns:
- returns a single document.
nullif no document is available - Throws:
OracleException- if there is an error retrieving theOracleDocument
-
lock
OracleOperationBuilder lock() throws OracleException
Indicates that the operation should lock the documents.This is a non-terminal method, and, as such, it does not cause operation execution.
This method should only be invoked as part of building a read operation. If it's invoked as part of building a write operation (e.g. with replace, remove, etc.), it will have no effect. It is an error to specify this method in conjunction with a
count()terminal,skip(long)non-terminal, andlimit(int)non-terminal.In order to use this method, ensure that the JDBC connection associated with this operation builder object is not in auto-commit mode. Otherwise, the acquired lock will be immediately unlocked by the automatic commit performed after the read operation. In other words, locking will have no effect if the connection is in auto-commit mode.
- Returns:
OracleOperationBuilder- Throws:
OracleException- ifskip(long)orlimit(int)are already specified on thisOracleOperationBuilderobject
-
hint
OracleOperationBuilder hint(String hints) throws OracleException
Adds execution hints to the operation- Parameters:
hints- contains one or more hints, cannot benull- Returns:
OracleOperationBuilder- Throws:
OracleException- Ifhintis null or invalid
-
mergeOne
boolean mergeOne(OracleDocument document) throws OracleException
Merges the specified document into an existing one. The two documents are merged using the algorithm described in RFC7396 - JSON Merge Patch. For example, merging the document{"count":42, "color":"red"}into an existing document{"name":"apple", "count":12}produces a new merged document{"name":"apple", "count":42, "color":"red"}.This method is used in conjunction with
key(...), and (optionally)version(...)methods.For example:
// Replace a document with the key "k1" and version "v1" // with the input document 'd1'. col.find().key("k1").version("v1").mergeOne(d1)Note that the key and version information (if any) in the input document 'd1' is ignored.
This is a terminal method, and, as such, it causes operation execution.
- Parameters:
document- input document. Cannot benull- Returns:
trueif the document was replaced successfully,falseotherwise- Throws:
OracleException- if (1) the input document isnull, or (2) there's an error replacing the existingdocument- See Also:
- RFC7396 - JSON Merge Patch
-
mergeOneAndGet
OracleDocument mergeOneAndGet(OracleDocument document) throws OracleException
Merges a document.This method is the same as
mergeOne(OracleDocument)but additionally returns the modified document. ThemergeOne(OracleDocument)method may avoid the additional cost of transferring the document back to the caller.This is a terminal method, and, as such, it causes operation execution.
- Parameters:
document- input document. Cannot benull- Returns:
- result document which contains the key and (if present) the created-on timestamp, last-modified timestamp, and version only. The input document's content is not returned as part of the result document
- Throws:
OracleException- if (1) the input document isnull, or (2) there's an error replacing the inputdocument
-
startKey
OracleOperationBuilder startKey(String startKey, Boolean ascending, Boolean inclusive) throws OracleException
Specifies that only keys that come after (or alternatively before) the specified key. The total ordering over key values in a collection is guaranteed stable and consistent. The ordering may depend on the underlying key storage type and default the collation settings of the database.This method is expected to be used with the
limit(int)method to do pagination over a, possiblyfiltered, set of documents. Callinglimit(int)by itself will ensure that the documents are returned in key order. For example:// find the first 10 documents where the "count" property is greater than 20 String filter = "{\"count\": {\"$gt\" : 20}}"; OracleCursor cursor = col.find() .filter() .limit(10) .getCursor(); String key = null; while (cursor.hasNext()) { OracleDocument doc = cursor.next(); key = doc.getKey(); ... } ... // use startKey() to get the next 10 documents with count greater than 20 cursor = col.find() .filter(filter) .startKey(key, true, false) .limit(10) .getCursor();This is a non-terminal method, and, as such, it does not cause operation execution. This method should only be invoked as part of building a read operation. If it's invoked as part of building a write operation (e.g. with replace, remove, etc.), it will have no effect.
- Parameters:
startKey- the starting keyascending- when true, returns documents in ascending order following the startKey. When false, returns documents preceding the startKey in descending orderinclusive- when true, the document with the startKey value, if it exists, is included in the result- Returns:
- this
OracleOperationBuilder - Throws:
OracleException- if startKey is null
-
-