|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> [ types overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.iapi.types
Class XML

java.lang.Objectorg.apache.derby.iapi.types.DataType
org.apache.derby.iapi.types.XML
- All Implemented Interfaces:
- CloneableObject, DataValueDescriptor, java.io.Externalizable, org.apache.derby.iapi.services.io.Formatable, Orderable, java.io.Serializable, org.apache.derby.iapi.services.io.Storable, org.apache.derby.iapi.services.io.StreamStorable, org.apache.derby.iapi.services.io.TypedFormat, XMLDataValue
- public class XML
- extends DataType
- implements XMLDataValue, org.apache.derby.iapi.services.io.StreamStorable
- extends DataType
This type implements the XMLDataValue interface and thus is the type on which all XML related operations are executed. The first and simplest XML store implementation is a UTF-8 based one--all XML data is stored on disk as a UTF-8 string, just like the other Derby string types. In order to make it possible for smarter XML implementations to exist in the future, this class always writes an "XML implementation id" to disk before writing the rest of its data. When reading the data, the impl id is read first and serves as an indicator of how the rest of the data should be read. So long as there's only one implementation (UTF-8) the impl id can be ignored; but when smarter implementations are written, the impl id will be the key to figuring out how an XML value should be read, written, and processed.
| Nested Class Summary | |
private class |
XML.ExistsHandler
|
private class |
XML.XMLErrorHandler
|
| Field Summary | |
private static int |
BASE_MEMORY_USAGE
|
private static java.lang.String |
QUERY_MATCH_STRING
|
protected org.xml.sax.XMLReader |
saxReader
|
private org.apache.xalan.processor.TransformerFactoryImpl |
saxTFactory
|
protected static short |
UTF8_IMPL_ID
|
protected static java.lang.String |
XML_PARSER_CLASS
|
private SQLChar |
xmlStringValue
|
private static java.lang.String |
XPATH_PLACEHOLDER
|
private org.xml.sax.XMLReader |
xsltReader
|
private static java.lang.String |
xsltStylesheet
|
| Fields inherited from interface org.apache.derby.iapi.types.Orderable |
ORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN |
| Constructor Summary | |
|
XML()
Default constructor. |
private |
XML(SQLChar val)
Private constructor used for the getClone() method. |
| Method Summary | |
int |
compare(DataValueDescriptor other)
Compare two XML DataValueDescriptors. |
int |
estimateMemoryUsage()
Estimate the memory usage in bytes of the data value and the overhead of the class. |
boolean |
exists(java.lang.String xExpr)
Helper method for XMLExists. |
DataValueDescriptor |
getClone()
Clone this DataValueDescriptor. |
int |
getLength()
Gets the length of the data value. |
DataValueDescriptor |
getNewNull()
Get a new null value of the same type as this data value. |
java.lang.String |
getString()
Gets the value in the data value descriptor as a String. |
int |
getTypeFormatId()
Get a universally unique identifier for the type of this object. |
java.lang.String |
getTypeName()
Get the SQL name of the datatype |
boolean |
isNull()
Return whether the value is null or not. |
protected void |
loadSAXReader()
Load an XMLReader for SAX events that can be used for parsing XML data. |
void |
loadStream()
sets the stream state for the object. |
private void |
loadXSLTObjects()
Prepare for an XSLT query by loading the objects required for such a query. |
void |
parseAndLoadXML(java.lang.String text,
boolean preserveWS)
Method to parse an XML string and, if it's valid, store the _parsed_ version for subsequent use. |
void |
readExternal(java.io.ObjectInput in)
Read an XML value from an input stream. |
void |
readExternalFromArray(org.apache.derby.iapi.services.io.ArrayInputStream in)
Read the DataValueDescriptor from the stream. |
private java.lang.String |
replaceDoubleQuotes(java.lang.String queryText)
Takes a string (which is an XPath query specified by the user) and replaces any double quotes with single quotes. |
void |
restoreToNull()
Restore this object to its (SQL)null value. |
java.io.InputStream |
returnStream()
Return the stream state of the object. |
protected void |
setFrom(DataValueDescriptor theValue)
|
void |
setStream(java.io.InputStream newStream)
sets the stream state for the object. |
void |
setValueFromResultSet(java.sql.ResultSet resultSet,
int colNumber,
boolean isNullable)
Set the value based on the value for the specified DataValueDescriptor from the specified ResultSet. |
int |
typePrecedence()
Each built-in type in JSQL has a precedence. |
void |
writeExternal(java.io.ObjectOutput out)
Write an XML value. |
BooleanDataValue |
XMLExists(StringDataValue xExpr,
XMLDataValue xml)
The SQL/XML XMLExists operator. |
StringDataValue |
XMLSerialize(StringDataValue result,
int targetType,
int targetWidth)
The SQL/XML XMLSerialize operator. |
| Methods inherited from class org.apache.derby.iapi.types.DataType |
checkHostVariable, cloneObject, coalesce, compare, dataTypeConversion, equals, equals, flip, genericSetObject, getBoolean, getByte, getBytes, getDate, getDouble, getFloat, getInt, getLong, getNationalString, getObject, getShort, getStream, getTime, getTimestamp, greaterOrEquals, greaterThan, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, outOfRange, setBigDecimal, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, throwLangSetMismatch, typeToBigDecimal |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.apache.derby.iapi.types.DataValueDescriptor |
checkHostVariable, coalesce, compare, equals, getBoolean, getByte, getBytes, getDate, getDouble, getFloat, getInt, getLong, getObject, getShort, getStream, getTime, getTimestamp, greaterOrEquals, greaterThan, in, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, setBigDecimal, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, typeToBigDecimal |
| Field Detail |
UTF8_IMPL_ID
protected static final short UTF8_IMPL_ID
- See Also:
- Constant Field Values
XML_PARSER_CLASS
protected static final java.lang.String XML_PARSER_CLASS
- See Also:
- Constant Field Values
BASE_MEMORY_USAGE
private static final int BASE_MEMORY_USAGE
xmlStringValue
private SQLChar xmlStringValue
saxReader
protected org.xml.sax.XMLReader saxReader
XPATH_PLACEHOLDER
private static final java.lang.String XPATH_PLACEHOLDER
- See Also:
- Constant Field Values
QUERY_MATCH_STRING
private static final java.lang.String QUERY_MATCH_STRING
- See Also:
- Constant Field Values
xsltStylesheet
private static java.lang.String xsltStylesheet
xsltReader
private org.xml.sax.XMLReader xsltReader
saxTFactory
private org.apache.xalan.processor.TransformerFactoryImpl saxTFactory
| Constructor Detail |
XML
public XML()
- Default constructor.
XML
private XML(SQLChar val)
- Private constructor used for the getClone() method.
Takes a SQLChar and clones it.
| Method Detail |
getClone
public DataValueDescriptor getClone()
- Description copied from interface:
DataValueDescriptor - Clone this DataValueDescriptor. Results in a new object
that has the same value as this but can be modified independently.
- Specified by:
getClonein interfaceDataValueDescriptor
getNewNull
public DataValueDescriptor getNewNull()
- Description copied from interface:
DataValueDescriptor - Get a new null value of the same type as this data value.
- Specified by:
getNewNullin interfaceDataValueDescriptor
getTypeName
public java.lang.String getTypeName()
- Description copied from interface:
DataValueDescriptor - Get the SQL name of the datatype
- Specified by:
getTypeNamein interfaceDataValueDescriptor
typePrecedence
public int typePrecedence()
- Description copied from interface:
DataValueDescriptor - Each built-in type in JSQL has a precedence. This precedence determines
how to do type promotion when using binary operators. For example, float
has a higher precedence than int, so when adding an int to a float, the
result type is float.
The precedence for some types is arbitrary. For example, it doesn't
matter what the precedence of the boolean type is, since it can't be
mixed with other types. But the precedence for the number types is
critical. The SQL standard requires that exact numeric types be
promoted to approximate numeric when one operator uses both. Also,
the precedence is arranged so that one will not lose precision when
promoting a type.
- Specified by:
typePrecedencein interfaceDataValueDescriptor- Overrides:
typePrecedencein classDataType
getString
public java.lang.String getString() throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
DataValueDescriptor - Gets the value in the data value descriptor as a String.
Throws an exception if the data value is not a string.
- Specified by:
getStringin interfaceDataValueDescriptor
getLength
public int getLength()
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
DataValueDescriptor - Gets the length of the data value. The meaning of this is
implementation-dependent. For string types, it is the number of
characters in the string. For numeric types, it is the number of
bytes used to store the number. This is the actual length
of this value, not the length of the type it was defined as.
For example, a VARCHAR value may be shorter than the declared
VARCHAR (maximum) length.
- Specified by:
getLengthin interfaceDataValueDescriptor
estimateMemoryUsage
public int estimateMemoryUsage()
- Description copied from interface:
DataValueDescriptor - Estimate the memory usage in bytes of the data value and the overhead of the class.
- Specified by:
estimateMemoryUsagein interfaceDataValueDescriptor
readExternalFromArray
public void readExternalFromArray(org.apache.derby.iapi.services.io.ArrayInputStream in) throws java.io.IOException
- Description copied from interface:
DataValueDescriptor - Read the DataValueDescriptor from the stream.
Initialize the data value by reading it's values from the ArrayInputStream. This interface is provided as a way to achieve possible performance enhancement when reading an array can be optimized over reading from a generic stream from readExternal().
- Specified by:
readExternalFromArrayin interfaceDataValueDescriptor
setFrom
protected void setFrom(DataValueDescriptor theValue) throws org.apache.derby.iapi.error.StandardException
setValueFromResultSet
public final void setValueFromResultSet(java.sql.ResultSet resultSet, int colNumber, boolean isNullable) throws java.sql.SQLException
- Description copied from interface:
DataValueDescriptor - Set the value based on the value for the specified DataValueDescriptor
from the specified ResultSet.
- Specified by:
setValueFromResultSetin interfaceDataValueDescriptor
compare
public int compare(DataValueDescriptor other) throws org.apache.derby.iapi.error.StandardException
- Compare two XML DataValueDescriptors. NOTE: This method
should only be used by the database store for the purpose of
index positioning--comparisons of XML type are not allowed
from the language side of things. That said, all store
wants to do is order the NULLs, so we don't actually
have to do a full comparison. Just return an order
value based on whether or not this XML value and the
other XML value are null. As mentioned in the "compare"
method of DataValueDescriptor, nulls are considered
equal to other nulls and less than all other values.
An example of when this method might be used is if the
user executed a query like:
select i from x_table where x_col is not null
- Specified by:
comparein interfaceDataValueDescriptor
getTypeFormatId
public int getTypeFormatId()
- Description copied from interface:
org.apache.derby.iapi.services.io.TypedFormat - Get a universally unique identifier for the type of
this object.
- Specified by:
getTypeFormatIdin interfaceorg.apache.derby.iapi.services.io.TypedFormat
isNull
public boolean isNull()
- Description copied from interface:
org.apache.derby.iapi.services.io.Storable - Return whether the value is null or not.
- Specified by:
isNullin interfaceorg.apache.derby.iapi.services.io.Storable
restoreToNull
public void restoreToNull()
- Description copied from interface:
org.apache.derby.iapi.services.io.Storable - Restore this object to its (SQL)null value.
- Specified by:
restoreToNullin interfaceorg.apache.derby.iapi.services.io.Storable
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
- Read an XML value from an input stream.
- Specified by:
readExternalin interfacejava.io.Externalizable
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Write an XML value.
- Specified by:
writeExternalin interfacejava.io.Externalizable
returnStream
public java.io.InputStream returnStream()
- Description copied from interface:
org.apache.derby.iapi.services.io.StreamStorable - Return the stream state of the object.
- Specified by:
returnStreamin interfaceorg.apache.derby.iapi.services.io.StreamStorable
setStream
public void setStream(java.io.InputStream newStream)
- Description copied from interface:
org.apache.derby.iapi.services.io.StreamStorable - sets the stream state for the object.
- Specified by:
setStreamin interfaceorg.apache.derby.iapi.services.io.StreamStorable
loadStream
public void loadStream()
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
org.apache.derby.iapi.services.io.StreamStorable - sets the stream state for the object.
- Specified by:
loadStreamin interfaceorg.apache.derby.iapi.services.io.StreamStorable
parseAndLoadXML
public void parseAndLoadXML(java.lang.String text, boolean preserveWS) throws org.apache.derby.iapi.error.StandardException
- Method to parse an XML string and, if it's valid,
store the _parsed_ version for subsequent use.
- Specified by:
parseAndLoadXMLin interfaceXMLDataValue
XMLSerialize
public StringDataValue XMLSerialize(StringDataValue result, int targetType, int targetWidth) throws org.apache.derby.iapi.error.StandardException
- The SQL/XML XMLSerialize operator.
Converts this XML value into a string with a user-specified
type, and returns that string via the received StringDataValue
(if the received StringDataValue is non-null; else a new
StringDataValue is returned).
- Specified by:
XMLSerializein interfaceXMLDataValue
XMLExists
public BooleanDataValue XMLExists(StringDataValue xExpr, XMLDataValue xml) throws org.apache.derby.iapi.error.StandardException
- The SQL/XML XMLExists operator.
Takes an XML query expression (as a string) and an XML
value and checks if at least one node in the XML
value matches the query expression. NOTE: For now,
the query expression must be XPath only (XQuery not
supported).
- Specified by:
XMLExistsin interfaceXMLDataValue
exists
public boolean exists(java.lang.String xExpr) throws org.apache.derby.iapi.error.StandardException
- Helper method for XMLExists.
See if the received XPath expression returns at least
one node when evaluated against _this_ XML value.
- Specified by:
existsin interfaceXMLDataValue
loadSAXReader
protected void loadSAXReader()
throws java.lang.Exception
- Load an XMLReader for SAX events that can be used
for parsing XML data.
This method is currently only used for XMLPARSE, and
the SQL/XML[2003] spec says that XMLPARSE should NOT
perform validation -- Seciont 6.11:
"Perform a non-validating parse of a character string to
produce an XML value."
Thus, we make sure to disable validation on the XMLReader
loaded here. At some point in the future we will probably
want to add support for the XMLVALIDATE function--but until
then, user is unable to validate the XML values s/he inserts.
Note that, even with validation turned off, XMLPARSE
_will_ still check the well-formedness of the values,
and it _will_ still process DTDs to get default values,
etc--but that's it; no validation errors will be thrown.
For future reference: the features needed to perform
validation (with Xerces) are:
http://apache.org/xml/features/validation/schema
http://apache.org/xml/features/validation/dynamic
loadXSLTObjects
private void loadXSLTObjects()
throws org.xml.sax.SAXException
- Prepare for an XSLT query by loading the objects
required for such a query. We should only have
to do this once per XML object.
replaceDoubleQuotes
private java.lang.String replaceDoubleQuotes(java.lang.String queryText)
- Takes a string (which is an XPath query specified by
the user) and replaces any double quotes with single
quotes. We have to do this because a double quote
in the XSLT stylesheet (which is where the user's
query ends up) will be parsed as a query terminator
thus will cause XSLT execution errors.
|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> [ types overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC