Previous Table of Contents Next


Designing a Data Cartridge

There are several things to keep in mind while designing a data cartridge. Object data types (ODT)

  Should not keep global data.
  Should not attempt to keep state information across transactions.
  Do not support inheritance.
  Do not have private or protected elements.
  Do not have private or protected methods.
  Must not have name space collisions.

In order for multiple cartridges to operate, make sure that the following schema objects are unique:

  Directory names
  Library names
  Package names
  Type names
  Table names

A well-defined naming scheme must be used to achieve such uniqueness. I suggest the following naming scheme.


 “OOOOCCCSSSSSSSSSSSSSSSS”

Where

OOOO represents the organization name up to 4 characters
CCC represents the cartridge type and tag up to 3 characters
SSS... represents the Schema Object name.

Oracle8’s Extensibility Feature

The developer can use Oracle8’s extensibility features to declare new datatypes, make use of different programming languages, and leverage new constructs to model and store data in the Oracle8 database. The following constructs are the building blocks for developing data cartridges:

  Object types
  Collections
  Large object types

Object Types

Oracle8 allows developers to add new datatypes by making use of object types. Object types are similar to classes in Java or C++. They bundle a data structure and the functions and procedures associated with that structure. An object type must be associated with a column of a table before it can store any data. Each row object in an object type column has a unique identifier known as an Object ID (OID).

Object types consist of attributes and variables that define the data structure they represent, and methods, functions, and procedures that manipulate the underlying data structure. An object type consists of two parts.

  Specification. This defines the attributes and the publicly accessible methods.
  Body. This implements the publicly and privately declared methods.

The following example shows how to create a simple object type:


create type complex as object (

    real_part real,

    im_part real,

    member function addcomplex (x complex) return complex

    );

create type body complex as

    member function addcomplex (x complex) return complex is

    begin

    return complex (real_part + x.real_part, im_part+ x.im_part);

    end addcomplex;

end;


Tip:  
Methods can be implemented in PL/SQL, C, or in later releases using Java. For an example of implementing methods in C, please refer to the section on external procedures later in this chapter.


Tip:  
The attributes of object types can be other object types, collections, or large objects.

Collections

A collection is an ordered group of elements of the same datatype. The position of an element in the collection is determined by a unique subscript. Collections behave like arrays, except that collections can only have one dimension and must be integer-indexed. Collections can be attributes of an object type. Oracle8 provides two types of collections:

  Nested tables
  Variable-size arrays

Nested Tables

Nested tables are like one-dimensional arrays, with the following exceptions:

  They are unbounded and therefore can grow dynamically.
  They do not retain ordering; in other words, the order of insertion is not necessarily the order of retrieval.
  When declaring a nested table, use the keyword TABLE in conjunction with the CREATE TYPE statement.

The following example shows how to declare a nested table collection type:


create type projects as table of varchar2(25)

create type employee as object (

    emp_id      integer(4),

    emp_name    varchar2(25),

    emp_addr    varchar2(40),

    emp_proj    projects)

Variable-Size Arrays

VARRAYs have the following features:

  They have a fixed lower bound of 1 and a user-defined upper bound.
  They are like one-dimensional arrays and do not grow dynamically.
  They preserve the ordering of elements.

The following example shows how to create a VARRAY:


create type projectIDs as varray(20) of number(2)

create type department as object (

    dept_id    number(2),

    dept_name    varchar2(20),

    dept_projid    projectIDs)

Large Object Types

Large objects are used for storing raw, unstructured data such as text, images, audio, or video. LOBs are divided into two parts.

  LOB index. The LOB data is broken into chunks of the underlying data stream. The LOB index maintains a b-tree index of these chunks.
  LOB storage. It is the tablespace of the file that stores the raw information.

Access to the LOB data is provided through PL/SQL packages and OCI APIs.

Oracle8 supports two types of LOB data: internal and external.

Internal LOBs

Internal LOBs are stored in tablespaces and participate in the transactional model. They can be committed or rolled back just like any other Oracle8 data type. Oracle8 introduces the following three LOB types to replace the Oracle7 datatypes LONG and LONG RAW:

  BLOBs (Binary Large Objects)—Used to store unstructured data.
  CLOBs (Character Large Objects)—Use to store single byte-width character data.
  NCLOBs (National Character Large Objects)—Used to store fixed-width, multi-byte character data.

The LOB data types have the following advantages over LONG and LONG RAW:

  Multiple LOB columns can exist in the same table.
  LOBs can be stored out-of-line in a particular tablespace.
  LOBs can be up to 4GB.
  LOBs can be used as attributes of object types.


Previous Table of Contents Next
Используются технологии uCoz