Class VECTOR
- All Implemented Interfaces:
Serializable
The VECTOR class provides conversions between the Oracle VECTOR
data type and Java classes:
-
double[] -
float[] -
long[] -
int[] -
short[] -
byte[] -
boolean[] -
VECTOR.SparseDoubleArray -
VECTOR.SparseFloatArray -
VECTOR.SparseByteArray -
String
Instances of the oracle.sql.VECTOR class may be passed to the
setObject methods of PreparedStatement, and
instances may be returned by the getObject methods of
ResultSet and CallableStatement.
Creating a VECTOR
Static factory methods convert a Java array into a VECTOR of
a specific dimension type:
Accessing Meta Data
The dimension type of a VECTOR can be obtained from
getType(), the number of dimensions can be obtained from
getVectorLength(), and the SPARSE encoding format can be checked
for with isSparse().
- Since:
- 23.4
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA representation of SPARSE VECTOR data in Oracle Database.static interfaceA byte-valued representation of SPARSE VECTOR data in Oracle Database.static interfaceA double-valued representation of SPARSE VECTOR data in Oracle Database.static interfaceA float-valued representation of SPARSE VECTOR data in Oracle Database. -
Field Summary
Fields inherited from class oracle.sql.Datum
ojiOracleDatumWithConnection, targetDatum -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if this VECTOR is equal to another VECTOR.static VECTORfromData(byte[] data) For most use cases, an of...Values method should be used when creating a VECTOR object, not this method.getType()Returns the type of this VECTOR, which is one of the following:intReturns the number of values in this VECTOR (ie: The dimension count).inthashCode()Returns a hash code computed from the type and values of this VECTOR.booleanisConvertibleTo(Class<?> cls) Determines if datum object can be converted to a particular classbooleanisSparse()Returnstrueif this VECTOR has a SPARSE encoding.makeJdbcArray(int arraySize) Returns a JDBC array representation of the datumstatic VECTORofBinaryValues(Object object) Converts anObjectinto aVECTORof the BINARY dimension type.static VECTORofFloat32Values(Object object) Converts anObjectinto aVECTORof the FLOAT32 dimension type.static VECTORofFloat64Values(Object object) Converts anObjectinto aVECTORof the FLOAT64 dimension type.static VECTORofInt8Values(Object object) Converts anObjectinto aVECTORof the INT8 dimension type.Class<?>Returns the preferred array class for this VECTOR.Converts this VECTOR into String.boolean[]Converts this VECTOR into an array of booleans.static boolean[]toBooleanArray(byte[] data) Converts Oracle's internal encoding of a VECTOR into an array of booleans.byte[]Converts this VECTOR into an array of bytes.static byte[]toByteArray(byte[] data) Converts Oracle's internal encoding of a VECTOR into an array of bytes.<T> TConvert this datum to an instance of the specified type if possible.double[]Converts this VECTOR into an array of doubles.static double[]toDoubleArray(byte[] data) Converts Oracle's internal encoding of a VECTOR into an array of doubles.float[]Converts this VECTOR into an array of floats.static float[]toFloatArray(byte[] data) Converts Oracle's internal encoding of a VECTOR into an array of floats.int[]Converts this VECTOR into an array of ints.static int[]toIntArray(byte[] data) Converts Oracle's internal encoding of a VECTOR into an array of ints.toJdbc()Returns the JDBC representation of the datum objectlong[]Converts this VECTOR into an array of longs.static long[]toLongArray(byte[] data) Converts Oracle's internal encoding of a VECTOR into an array of longs.short[]Converts this VECTOR into an array of shorts.static short[]toShortArray(byte[] data) Converts Oracle's internal encoding of a VECTOR into an array of shorts.Converts this VECTOR into a SparseByteArray.toSparseByteArray(byte[] data) Converts Oracle's internal encoding of a VECTOR into a SparseByteArray.Converts this VECTOR into a SparseDoubleArray.toSparseDoubleArray(byte[] data) Converts Oracle's internal encoding of a VECTOR into a SparseDoubleArray.Converts this VECTOR into a SparseFloatArray.toSparseFloatArray(byte[] data) Converts Oracle's internal encoding of a VECTOR into a SparseFloatArray.toString()Methods inherited from class oracle.sql.Datum
asciiStreamValue, bigDecimalValue, binaryStreamValue, booleanValue, bytesEqual, bytesHashCode, byteValue, characterStreamValue, compareBytes, dateValue, doubleValue, floatValue, getBytes, getConnectionDuringExceptionHandling, getLength, getStream, intValue, isNull, longValue, setBytes, setShareBytes, shareBytes, stringValue, timestampValue, timestampValue, timeValue, timeValue
-
Method Details
-
fromData
For most use cases, an of...Values method should be used when creating a VECTOR object, not this method.
Creates a
VECTORfrom Oracle's internal encoding of a VECTOR.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- A VECTOR that contains the encoded values. Not null.
- Throws:
NullPointerException- Ifdataisnull
-
ofFloat64Values
Converts an
Objectinto aVECTORof the FLOAT64 dimension type. Theobjectmay be an instance of any class listed in the "Java to SQL Conversions" section of the JavaDoc forOracleType.VECTOR_FLOAT64. Lossy conversions specified in that JavaDoc also apply to this method.- Parameters:
object- Object containing values of a VECTOR. Not null.- Returns:
- A VECTOR that contains the values. Not null.
- Throws:
NullPointerException- If theobjectisnull.SQLException- If theobjectcan not be converted into a VECTOR, for instance because its class is not recognized, or because the number of values exceeds the maximum length of a VECTOR.
-
ofFloat32Values
Converts an
Objectinto aVECTORof the FLOAT32 dimension type. Theobjectmay be an instance of any class listed in the "Java to SQL Conversions" section of the JavaDoc forOracleType.VECTOR_FLOAT32. Lossy conversions specified in that JavaDoc also apply to this method.- Parameters:
object- Object containing values of a VECTOR. Not null.- Returns:
- A VECTOR that contains the values. Not null.
- Throws:
NullPointerException- If theobjectisnull.SQLException- If theobjectcan not be converted into a VECTOR, for instance because its class is not recognized, or because the number of values exceeds the maximum length of a VECTOR.
-
ofInt8Values
Converts an
Objectinto aVECTORof the INT8 dimension type. Theobjectmay be an instance of any class listed in the "Java to SQL Conversions" section of the JavaDoc forOracleType.VECTOR_INT8. Lossy conversions specified in that JavaDoc also apply to this method.- Parameters:
object- Object containing values of a VECTOR. Not null.- Returns:
- A VECTOR that contains the values. Not null.
- Throws:
NullPointerException- If theobjectisnull.SQLException- If theobjectcan not be converted into a VECTOR, for instance because its class is not recognized, or because the number of values exceeds the maximum length of a VECTOR.
-
ofBinaryValues
Converts an
Objectinto aVECTORof the BINARY dimension type. Theobjectmay be an instance of any class listed in the "Java to SQL Conversions" section of the JavaDoc forOracleType.VECTOR_BINARY.- Parameters:
object- Object containing values of a VECTOR. Not null.- Returns:
- A VECTOR that contains the values. Not null.
- Throws:
NullPointerException- If theobjectisnull.SQLException- If theobjectcan not be converted into a VECTOR, for instance because its class is not recognized, or because the number of values exceeds the maximum length of a VECTOR.
-
getType
Returns the type of this VECTOR, which is one of the following:
This method will not return
OracleType.VECTOR, which is only applicable to columns and parameters. Individual VECTOR values always have a specific dimension type of FLOAT64, FLOAT32, INT8, or BINARY.- Returns:
- The type of this VECTOR. Not null.
- Throws:
SQLException- If the data this VECTOR was created with is not recognized as the binary encoding of a VECTOR.
-
toDoubleArray
Converts this VECTOR into an array of doubles.
This is a lossless conversion. The array returned by this method contains
doublevalues which store the same information as this VECTOR.- Returns:
- An array containing the values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toDoubleArray
Converts Oracle's internal encoding of a VECTOR into an array of doubles.
This method performs a lossless conversion. The array returned by this method contains
doublevalues which store the same information as the given VECTOR.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- An array containing the values (ie: "dimensions") of a VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.NullPointerException- Ifdataisnull.
-
toFloatArray
Converts this VECTOR into an array of floats.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Returns:
- An array containing the values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toFloatArray
Converts Oracle's internal encoding of a VECTOR into an array of floats.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- An array containing the values (ie: "dimensions") of a VECTOR. Not null.
- Throws:
NullPointerException- Ifdataisnull.SQLException- If the dimension type can not be converted to the returned type.
-
toLongArray
Converts this VECTOR into an array of longs.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Returns:
- An array containing the values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toLongArray
Converts Oracle's internal encoding of a VECTOR into an array of longs.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- An array containing the values (ie: "dimensions") of a VECTOR. Not null.
- Throws:
NullPointerException- Ifdataisnull.SQLException- If the dimension type can not be converted to the returned type.
-
toIntArray
Converts this VECTOR into an array of ints.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Returns:
- An array containing the values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toIntArray
Converts Oracle's internal encoding of a VECTOR into an array of ints.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- An array containing the values (ie: "dimensions") of a VECTOR. Not null.
- Throws:
NullPointerException- Ifdataisnull.SQLException- If the dimension type can not be converted to the returned type.
-
toShortArray
Converts this VECTOR into an array of shorts.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Returns:
- An array containing the values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toShortArray
Converts Oracle's internal encoding of a VECTOR into an array of shorts.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- An array containing the values (ie: "dimensions") of a VECTOR. Not null.
- Throws:
NullPointerException- Ifdataisnull.SQLException- If the dimension type can not be converted to the returned type.
-
toByteArray
Converts this VECTOR into an array of bytes.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.If the type of this VECTOR is
OracleType.VECTOR_BINARY, each byte returned by this method is 8 dimensions packed as bits in MSB order.- Returns:
- An array containing the values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toByteArray
Converts Oracle's internal encoding of a VECTOR into an array of bytes.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.If the type of this VECTOR is
OracleType.VECTOR_BINARY, each byte returned by this method contains up to 8 dimensions, packed as bits in MSB order. The last byte may contain less than 8 dimensions if the length of this VECTOR is not a multiple of 8.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- An array containing the values (ie: "dimensions") of a VECTOR. Not null.
- Throws:
NullPointerException- Ifdataisnull.SQLException- If the dimension type can not be converted to the returned type.
-
toBooleanArray
Converts this VECTOR into an array of booleans.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Returns:
- An array containing the values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the data this VECTOR was created with is not recognized as the binary encoding of a VECTOR.
-
toBooleanArray
Converts Oracle's internal encoding of a VECTOR into an array of booleans.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- An array containing the values (ie: "dimensions") of a VECTOR. Not null.
- Throws:
NullPointerException- Ifdataisnull.SQLException- If the dimension type can not be converted to the returned type.
-
stringValue
Converts this VECTOR into String.
This method returns a VARCHAR literal representation of this VECTOR, as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Overrides:
stringValuein classDatum- Returns:
- The VARCHAR literal representation of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toString
-
hashCode
public int hashCode()Returns a hash code computed from the type and values of this VECTOR. -
equals
Checks if this VECTOR is equal to another VECTOR. This method considers two vectors to be equal if both have the same type, and contain the same values (ie: "dimensions").
This method returns
falseif the data that either VECTOR was created with is not recognized as the binary encoding of a VECTOR. -
preferredArrayClass
Returns the preferred array class for this VECTOR.- Returns:
- The preferred array class. Not null.
- Throws:
SQLException- If the data this VECTOR was created with is not recognized as the binary encoding of a VECTOR.
-
getVectorLength
public int getVectorLength()Returns the number of values in this VECTOR (ie: The dimension count).- Returns:
- The number of values in this VECTOR.
- Throws:
IllegalStateException- If the data this VECTOR was created with is not recognized as the binary encoding of a VECTOR.
-
toClass
Description copied from class:DatumConvert this datum to an instance of the specified type if possible.- Overrides:
toClassin classDatum- Parameters:
type- targetDatum class- Returns:
- an instance of the targetDatum class corresponding to this datum.
- Throws:
SQLException- if the conversion is not possible.
-
isConvertibleTo
Description copied from class:DatumDetermines if datum object can be converted to a particular class- Specified by:
isConvertibleToin classDatum- Parameters:
cls- Class to convert to- Returns:
- true, if conversion to cls is permitted false, if conversion to cls is not permitted
-
toJdbc
Returns the JDBC representation of the datum objectTHE BEHAVIOR OF THIS METHOD MAY CHANGE IN A FUTURE RELEASE.
The behavior of this method may change if a future JDBC specification defines a mapping for VECTOR data. No such mapping is defined in JDBC 4.3, so this method is currently implemented to return this VECTOR.
- Specified by:
toJdbcin classDatum- Returns:
- an object containing the JDBC value
- Throws:
SQLException- if conversion to JDBC representation results in an error
-
makeJdbcArray
Returns a JDBC array representation of the datumTHE BEHAVIOR OF THIS METHOD MAY CHANGE IN A FUTURE RELEASE.
The behavior of this method may change if a future JDBC specification defines a mapping for VECTOR data. No such mapping is defined in JDBC 4.3, so this method is currently implemented to return an array with the component type of
oracle.sql.VECTOR.- Specified by:
makeJdbcArrayin classDatum- Parameters:
arraySize- size of the array- Returns:
- an object containing the JDBC array value
-
isSparse
Returnstrueif this VECTOR has a SPARSE encoding.- Returns:
- true if the data has a SPARSE encoding, or false if not.
- Throws:
SQLException- If the data this VECTOR was created with is not recognized as the binary encoding of a VECTOR.
-
toSparseDoubleArray
Converts this VECTOR into a SparseDoubleArray.
This is a lossless conversion. The array returned by this method contains
doublevalues which store the same information as this VECTOR.- Returns:
- A sparse array containing the non-zero values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toSparseDoubleArray
Converts Oracle's internal encoding of a VECTOR into a SparseDoubleArray.
This is a lossless conversion. The array returned by this method contains
doublevalues which store the same information as this VECTOR.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- A sparse array containing the non-zero values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toSparseFloatArray
Converts this VECTOR into a SparseFloatArray.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Returns:
- A sparse array containing the non-zero values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toSparseFloatArray
Converts Oracle's internal encoding of a VECTOR into a SparseFloatArray.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- A sparse array containing the non-zero values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toSparseByteArray
Converts this VECTOR into a SparseByteArray.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Returns:
- A sparse array containing the non-zero values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-
toSparseByteArray
Converts Oracle's internal encoding of a VECTOR into a SparseByteArray.
This method may perform lossy conversions as specified in the "SQL to Java Conversions" section of the JavaDoc for
OracleType.VECTOR.- Parameters:
data- Oracle's internal encoding of a VECTOR. Not null.- Returns:
- A sparse array containing the non-zero values (ie: "dimensions") of this VECTOR. Not null.
- Throws:
SQLException- If the dimension type can not be converted to the returned type.
-