Package oracle.soda
Interface OracleDocument
-
public interface OracleDocumentRepresents a document with (typically) JSON content.The content can also be another MIME type: image, audio, video, etc.
The document has the following components:
- key
- content
- created-on timestamp
- last-modified timestamp
- version or checksum (suitable for ETag)
- media type ("application/json" for JSON documents)
created-on and last-modified timestamps are not tracked for collections based on JSON Collection Tables and Duality Views (introduced in Oracle Database 23ai). For such collections these values are null.
It is valid for any of the above components to be missing in a given
OracleDocument.Some examples:
OracleCollection.insert(OracleDocument)andOracleCollection.insertAndGet(OracleDocument)input documents may contain content only. Key is automatically generated by the insert operation. If the collection is configured with client-assigned keys, the input document needs to contain the key as well.- Documents returned by
OracleCursorobtained by callingcol.find().getCursor()may contain key, content, created-on timestamp, last-modified timestamp, and version. - Result documents returned by
OracleCollection.insertAndGet(OracleDocument)orOracleOperationBuilder.replaceOneAndGet(OracleDocument)may contain key, created-on timestamp, last-modified timestamp, and version. These documents will not have any content.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> TgetContentAs(Class<T> type)Returns the content as the specified type.byte[]getContentAsByteArray()Returns the content as a byte array.StringgetContentAsString()Returns the content as aString.intgetContentLength()Returns the length of content if know.StringgetCreatedOn()Returns the timestamp of creation of this document in ISO format.StringgetKey()Returns the key.StringgetLastModified()Returns the timestamp of the last modification to this document in ISO format.StringgetMediaType()Returns the media type.StringgetVersion()Returns a string suitable for use as a version of the document.booleanisJSON()Returnstrueis this document has media type"application/json".
-
-
-
Method Detail
-
getKey
String getKey()
Returns the key.- Returns:
- the key as a
String.nullif the key is not available
-
getContentAsByteArray
byte[] getContentAsByteArray() throws OracleExceptionReturns the content as a byte array.- Returns:
- content as a
byte[], ornullif the content is not available. - Throws:
OracleException- if there's an error returning content asbyte[]
-
getContentAsString
String getContentAsString() throws OracleException
Returns the content as aString.- Returns:
- content as a
String, ornullif the content is not available - Throws:
OracleException- if there's an error returning content asString
-
getContentAs
<T> T getContentAs(Class<T> type) throws OracleException
Returns the content as the specified type. The following types are supported:
Deprecation Notice: support forClass Description javax.json.JsonValue
jakarta.json.JsonValue
oracle.sql.json.OracleJsonValueThe JSON type value is returned as JsonValueorOracleJsonValue. Any derived interface, such asJsonObjectmay also be used.JsonObject obj = doc.getContentAs(JsonObject.class);javax.json.stream.JsonParser
jakarta.json.stream.JsonParser
oracle.sql.json.OracleJsonParserThe JSON type value is returned as an event stream. java.lang.String
java.io.ReaderThe JSON type value is returned as JSON text. javax.jsonwill be removed in an upcoming release.- Type Parameters:
T- the type of the returned content- Parameters:
type- the type of the returned content- Returns:
- content as an instance of the specified type
or
nullif the content is not available - Throws:
OracleException- if there's an error returning content as the specified type or if a mapping to the specified type is not supported
-
getMediaType
String getMediaType()
Returns the media type. JSON objects have media type"application/json".- Returns:
- media type as a
String, ornullif the media type is not available
-
getLastModified
String getLastModified()
Returns the timestamp of the last modification to this document in ISO format.nullfor collections based on JSON Collection Tables and Duality Views (introduced in Oracle Database 23ai).- Returns:
- a
Stringrepresentation of the timestamp, ornullif the timestamp is not available
-
getCreatedOn
String getCreatedOn()
Returns the timestamp of creation of this document in ISO format.nullfor collections based on JSON Collection Tables and Duality Views (introduced in Oracle Database 23ai).- Returns:
- a
Stringrepresentation of the timestamp, ornullif the timestamp is not available
-
getVersion
String getVersion()
Returns a string suitable for use as a version of the document. This is typically a version number, precise timestamp, or checksum of the actual content.- Returns:
- a
Stringrepresentation of the version, ornullif the version is not available
-
getContentLength
int getContentLength()
Returns the length of content if know.-1is not known.- Returns:
- length of content, in bytes.
-1if not known.
-
isJSON
boolean isJSON()
Returnstrueis this document has media type"application/json".- Returns:
trueif this document has media type "application/json",falseotherwise
-
-