com.davisor.data
Class ObjectValue

java.lang.Object
  extended bycom.davisor.data.VoidData
      extended bycom.davisor.data.VoidValue
          extended bycom.davisor.data.GenericValue
              extended bycom.davisor.data.ObjectValue
All Implemented Interfaces:
java.sql.Blob, java.lang.Comparable, Data, DataValue, com.davisor.core.Dupable, java.io.Serializable, SerializableData

public class ObjectValue
extends GenericValue
implements java.sql.Blob

ObjectValue implements a data value class for generic Java objects.

Since:
JDK1.1, JDBC2.0
See Also:
Type, ObjectType, Serialized Form

Field Summary
protected  byte[] M_serialized
          Serialized value.
protected  java.io.Serializable M_value
          Serializable object value.
 
Fields inherited from class com.davisor.data.VoidData
M_type
 
Constructor Summary
  ObjectValue()
          Default constructor.
  ObjectValue(ObjectValue data, boolean deep)
          Deep or shallow copy constructor.
protected ObjectValue(Type type)
          Create a new data object.
  ObjectValue(Type type, java.io.Serializable value)
          Creates a new data object
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares the type of this object value data with the type of other object values.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 java.io.InputStream getBinaryStream()
          Returns the serialized object as input stream.
 byte[] getBytes(long pos, int length)
          Returns max length bytes starting at position pos.
 boolean isNull()
          Tests if this data object value is undetermined.
 long length()
          Returns the length of serialized value.
 long position(java.sql.Blob pattern, long start)
          Returns the postion where the given pattern starts.
 long position(byte[] pattern, long start)
          Returns the postion where the given pattern starts.
 java.io.OutputStream setBinaryStream(long pos)
          Retrieves a stream that can be used to write to the BLOB value that this Blob object represents.
 int setBytes(long pos, byte[] bytes)
          Writes the given array of bytes to the BLOB value that this Blob object represents, starting at position pos, and returns the number of bytes written.
 int setBytes(long pos, byte[] bytes, int offset, int len)
          Writes the given array of bytes to the BLOB value that this Blob object represents, starting at position pos, and returns the number of bytes written.
 void setValue(java.lang.String stringValue, java.text.ParsePosition status)
          Sets data value from a string value.
 void toStatement(java.sql.PreparedStatement statement, int parameter)
          Converts the data to a prepared statement input parameter.
 void truncate(long len)
          Truncates the BLOB value that this Blob object represents to be of given length.
 
Methods inherited from class com.davisor.data.GenericValue
max, min, toXML
 
Methods inherited from class com.davisor.data.VoidValue
abs, add, ceil, deinterpolate, div, floor, getFormat, interpolate, mul, negate, sub, unit
 
Methods inherited from class com.davisor.data.VoidData
equals, getDataValue, getType, hashCode, setType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.davisor.data.DataValue
toString
 
Methods inherited from interface com.davisor.data.Data
getType
 

Field Detail

M_value

protected java.io.Serializable M_value
Serializable object value.


M_serialized

protected byte[] M_serialized
Serialized value.

Constructor Detail

ObjectValue

public ObjectValue()
Default constructor.


ObjectValue

public ObjectValue(ObjectValue data,
                   boolean deep)
Deep or shallow copy constructor. If it is shallow, then the new object shares an underlying type with the original object. If it is deep, then the type is dupped.

Parameters:
data - source data (may be null)
deep - determines if the copying is deep or shallow
See Also:
VoidData.getType(), Type.dup()

ObjectValue

protected ObjectValue(Type type)
Create a new data object.

Parameters:
type - The type of data.

ObjectValue

public ObjectValue(Type type,
                   java.io.Serializable value)
Creates a new data object

Parameters:
type - the type of data.
value - the object value of data.
Method Detail

getBinaryStream

public java.io.InputStream getBinaryStream()
                                    throws java.sql.SQLException
Returns the serialized object as input stream.

Specified by:
getBinaryStream in interface java.sql.Blob
Throws:
java.sql.SQLException - if serialization fails.

getBytes

public byte[] getBytes(long pos,
                       int length)
                throws java.sql.SQLException
Returns max length bytes starting at position pos. The length of the returned array tells the number of returned bytes.

Specified by:
getBytes in interface java.sql.Blob
Parameters:
pos - the starting position. 1 denoted the first byte.
length - number of returned bytes
Returns:
the byte array.
Throws:
java.sql.SQLException - if serialization fails.

length

public long length()
            throws java.sql.SQLException
Returns the length of serialized value.

Specified by:
length in interface java.sql.Blob
Throws:
java.sql.SQLException - if serialization fails.

position

public long position(byte[] pattern,
                     long start)
              throws java.sql.SQLException
Returns the postion where the given pattern starts.

Specified by:
position in interface java.sql.Blob
Parameters:
pattern - the searched pattern.
start - the starting position for search. 1 denotes the first byte.
Returns:
the found starting position or -1. 1 denotes the first byte.
Throws:
java.sql.SQLException - if serialization or search fails.

position

public long position(java.sql.Blob pattern,
                     long start)
              throws java.sql.SQLException
Returns the postion where the given pattern starts.

Specified by:
position in interface java.sql.Blob
Parameters:
pattern - the searched pattern.
start - the starting position for search. 1 denotes the first byte.
Returns:
the found starting position or -1. 1 denotes the first byte.
Throws:
java.sql.SQLException - if serialization or search fails.

setBinaryStream

public java.io.OutputStream setBinaryStream(long pos)
                                     throws java.sql.SQLException
Retrieves a stream that can be used to write to the BLOB value that this Blob object represents. The stream begins at position pos.

This method is new to JDK 1.4, and not yet implemented.

Specified by:
setBinaryStream in interface java.sql.Blob
Parameters:
pos - the position in the BLOB value at which to start writing
Returns:
a stream to which data can be written
Throws:
java.sql.SQLException - always

setBytes

public int setBytes(long pos,
                    byte[] bytes)
             throws java.sql.SQLException
Writes the given array of bytes to the BLOB value that this Blob object represents, starting at position pos, and returns the number of bytes written.

Specified by:
setBytes in interface java.sql.Blob
Parameters:
pos - the position in the BLOB object at which to start writing
bytes - the array of bytes to be written to the BLOB value that this Blob object represents
Returns:
the number of bytes written
Throws:
java.sql.SQLException - if there is an error accessing the BLOB value
See Also:
setBytes(long,byte[],int,int)

setBytes

public int setBytes(long pos,
                    byte[] bytes,
                    int offset,
                    int len)
             throws java.sql.SQLException
Writes the given array of bytes to the BLOB value that this Blob object represents, starting at position pos, and returns the number of bytes written.

Specified by:
setBytes in interface java.sql.Blob
Parameters:
pos - the position in the BLOB object at which to start writing
bytes - the array of bytes to be written to the BLOB value that this Blob object represents
offset - the offset into the array bytes at which to start reading the bytes to be set
len - the number of bytes to be written to the BLOB value from the array of bytes bytes
Returns:
the number of bytes written
Throws:
java.sql.SQLException - if there is an error accessing the BLOB value
See Also:
setBytes(long,byte[])

truncate

public void truncate(long len)
              throws java.sql.SQLException
Truncates the BLOB value that this Blob object represents to be of given length.

This method is new to JDK 1.4, and not yet implemented.

Specified by:
truncate in interface java.sql.Blob
Parameters:
len - the length, in bytes, to which the BLOB value that this Blob object represents should be truncated
Returns:
a stream to which data can be written
Throws:
java.sql.SQLException - always

compareTo

public int compareTo(java.lang.Object o)
Compares the type of this object value data with the type of other object values.

Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class GenericValue
Throws:
java.lang.ClassCastException - if the given object is not a ObjectValue
java.lang.NullPointerException - if the given object is null
See Also:
GenericValue.max(com.davisor.data.DataValue), GenericValue.min(com.davisor.data.DataValue), Data.getType(), Compare.compareTo(Object,Object)

isNull

public boolean isNull()
Tests if this data object value is undetermined.

Specified by:
isNull in interface SerializableData
Overrides:
isNull in class VoidValue
Returns:
always true

setValue

public void setValue(java.lang.String stringValue,
                     java.text.ParsePosition status)
              throws InvalidDataException
Sets data value from a string value.

Specified by:
setValue in interface DataValue
Overrides:
setValue in class VoidValue
Parameters:
stringValue - string value to be parsed (may be null)
status - parse status (may be null)
Throws:
InvalidDataException - if string value could not be parser

toStatement

public void toStatement(java.sql.PreparedStatement statement,
                        int parameter)
                 throws java.sql.SQLException
Converts the data to a prepared statement input parameter. The value is inserted as blob through a binary stream.

Specified by:
toStatement in interface DataValue
Overrides:
toStatement in class GenericValue
Parameters:
statement - statement to be updated
parameter - index of the statement parameter to be updated
Throws:
java.sql.SQLException - if a SQL error occurs.
See Also:
VoidData.toString()

dup

public com.davisor.core.Dupable dup()
Makes a deep copy of this object.

Specified by:
dup in interface com.davisor.core.Dupable
Overrides:
dup in class VoidValue


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.