Saturday, November 10, 2007

Advanced Data Types:JAVA

discuss additions to the JDBC API that allow an application written in the Java
programming language to access SQL99 data types, such as binary large objects and
structured types. If a data source does not support an advanced data type described
in these two chapters, a driver for that data source is not required to implement the
methods and interfaces associated with that data type.

Taxonomy of SQL Types

The latest version of the ANSI/ISO SQL standard is commonly referred to as SQL99.
The JDBC API incorporates a model of the new SQL99 data types that includes only
those properties that are essential to exchanging data between a database and an
application written in the Java programming language.

SQL99 specifies these data types:

  • SQL92 built-in types—the familiar SQL ‘column types’
  • CHAR
  • FLOAT
  • DATE
  • and so on
  • New built-in types — new types added by SQL99
  • BOOLEAN — a truth value
  • BLOB — a Binary Large OBject
  • CLOB — a Character Large OBject
  • User Defined Types
  • Structured type — a user-defined type; for example:

CREATE TYPE PLANE_POINT AS (X FLOAT, Y FLOAT) NOT FINAL

  • DISTINCT type — a user-defined type based on a built-in type; for example:

CREATE TYPE MONEY AS NUMERIC(10,2) FINAL

  • Constructed types — new types based on a given base type
  • REF(structured-type) — a pointer that persistently denotes an instance of
  • structured type that resides in the database
  • base-type ARRAY[n] — an array of n base-type elements
  • Locators — new entities that are logical pointers to data that resides on the database server. A LOCATOR exists in the client environment and is a transient,logical pointer to data on the server. A locator typically refers to data that is toolarge to materialize on the client, such as images or audio. There are operators defined at the SQL level to retrieve random-access pieces of the data denoted by the locator.

  • LOCATOR(structured-type) — locator to a structured instance in server
  • LOCATOR(array) — locator to an array in server
  • LOCATOR(blob) — locator to a Binary Large Object in server
  • LOCATOR(clob) — locator to a Character Large Object in server
  • Type for managing data external to the data source
  • Datalink — a reference to data external to the data source that is managed by the data source. At the time of this writing, Datalink values are being standardized as part of SQL MED (Management of External Data), a part of the SQL ANSI/ISO standard specification. Having the data source manage the reference to external data has several advantages:
i. Referential integrity — the referenced data can no longer be deleted or
renamed directly through file system APIs

ii. Access control — access to the data may be configured such that it is
controlled by the data source instead of the file system

iii. Coordinated backup and recovery — fields referenced by Datalink values
may be included in the data source’s backup process

iv. Transaction consistency — changes that affect both relational and external
data are executed in a transactional context to preserve the integrity and consistency of the data

The remainder of this chapter discusses the default mechanism provided by the
JDBC API for accessing each of the new SQL data types mentioned above. The JDBC
API also provides a means of customizing the mapping of SQL DISTINCT and
structured types into Java classes. This mechanism is discussed in Chapter 17
“Customized Type Mapping”.

Mapping of SQL99 Types

The JDBC API provides default mappings for the new SQL99 types. Except for the
DISTINCT and DATALINK types, these default mappings take the form of interfaces.
The following list gives the SQL99 types and the interfaces to which they are
mapped.
  • BLOB — the Blob interface
  • CLOB — the Clob interface
  • ARRAY — the Array interface
  • Structured types — the Struct interface
  • REF(structured type) — the Ref interface
The other SQL99 data types with default mappings to the Java programming
language are:
  • DISTINCT — the type to which the base type is mapped. For example, a DISTINCT value based on an SQL NUMERIC type maps to a java.math.BigDecimal type because NUMERIC maps to BigDecimal in the Java programming language.
  • DATALINK — a java.net.URL object.

No comments: