Chapter 3. Introduction to interMedia Storage

Introduction

Many enterprises expend tremendous resources on the acquisition, storage, and management of collections of images, including graphics, video, and audio. While acquiring such data can be time-consuming and expensive, it has tremendous business value and represents a large investment. Therefore, storage and processing this media is one of the fastest growing applications.

In this chapter we look at the options for storing media within a database. We also learn how to create a multimedia database using relational and object-relational concepts. We will introduce a simple information systems case study to illustrate the issues and see how the different approaches could work out in practice. To summarize, in this chapter we will cover how

  • Object-relational and relational features of Oracle can contribute to the development of media rich databases.

  • Standard SQL data types, BLOB and BFILE, can be used to store media data.

  • Oracle interMedia data types provide advantages for developers.

  • SQL/MM can be used to store media data.

  • Object types and object tables can be developed to store media data.

This chapter focuses on the storage options for media data that have arisen through the recent developments of object-relational databases and media technologies. First, we will focus on the relational approach and the standard data types available for media storage based on LOBS and BFILES, since these data types are at the basis of the object types described later in this chapter, and it is important to have a sound grasp of their functions and capabilities. This way we will understand the limitations of this approach, particularly in terms of storage of metadata and retrieval before we look at the more complex alternatives.

Object-relational and Relational Features

We can use a relational or object-relational approach to developing databases for media-rich applications. What this means is that we can follow the relational approach based on the standard SQL data types and those implemented in Oracle, or we can use object types as specified in SQL:1999.

As a first option we can choose to restrict the database to the standard media data types specified in SQL:1999 for large object (LOB) data types. These LOB data types include binary large object (BLOB), which is used for image, video, and audio data. In addition there are CLOBs for character data, which we will not be particularly interested in but they can hold large documents and are manipulated by Oracle Text and BFILES, which can be used for any type of data but have certain limitations.

However, SQL:1999 provided a framework for creating object types (also called user-defined, UDT) types that can be used for media databases. There are several advantages to adopting this approach. In the next section we will first briefly explain how to use the SQL types BLOB and BFILE and their advantages and disadvantages. This is important to understand even if we decide to use object types because, from time to time in the development, we will need to know about the properties of BLOBS and BFILES and be able to manipulate them.

Using Large Object Data Types

Large object (LOB) data types in Oracle10g have the advantage of being able to accommodate large size files and to support random access. In Oracle10g there is support for terabyte-size LOB values (maximum size limit for LOBS is 8–128 terabytes, depending on the database block size) in such a way that they can be stored in the database and manipulated in the following programmatic environments:

  • Java (JDBC)

  • OCI

  • PL/SQL (particularly through the package DBMS_LOB)

This means we can store and manipulate LOB (BLOB, CLOB, and NCLOB) data types larger than 4 GB, which was the limit in previous versions of the database, stored in the database tablespaces in a way that optimizes space and provides efficient access. A column of a table can be specified with any LOB data type in the normal way. Incidently Oracle interMedia uses LOB data types to create data types for use in multimedia applications such as interMedia-specialized object types ORDAudio, ORDDoc, ORDImage, and ORDVideo.

Using LOB Locators

When a LOB data type is declared for a column in a table, the values stored are references, known as the LOB locators, that specify the location of the large stored object. If the LOB is small (up to 4 KB) it can be stored with its locator but otherwise it will be moved to a different physical location in the database tablespaces. This is referred to as inline storage but obviously large BLOBS may not be stored inline with other row data. In that case, a locator is stored in the row and the actual BLOB is stored in other tablespaces. The locator can be considered a pointer to the actual location of the BLOB value. When you select a BLOB, you are selecting the locator instead of the actual value, although this is done transparently. An advantage of this design is that multiple BLOB locators can exist in a single row. For example, you might want to store a short video clip of a training tape, an audio recording containing a brief description of its contents, a syllabus of the course, a picture of the instructor, and a set of maps and directions to each training center all in the same row.

LOB data types are restricted in terms of their storage options and standard SQL operations, as shown in Table 3.1. For example they are restricted from primary and foreign key constraints and from use in comparisons other than pure equality tests. However, there are several operations for BLOBs including concatenation, substring, overlay, and trim that are executed through the LOB locator.

Using BFILES

The BFILE data type is a special external LOB data type. These are useful for data objects stored in operating system files, outside the database tablespaces. The database accesses external LOBS using the SQL data type, BFILE. BFILES are read-only data types. The database allows read-only byte stream access to data stored in BFILES and therefore we cannot write to a BFILE from within an application. This obviously makes their use very limited and we would not normally use them. However, we need to know about them as they provide a means of getting data from the external file system into a BLOB.

Table 3.1. Oracle10g Large Object Data Types

Name

Data Type

Size Limitations

Characteristics

BLOB

Binary

8–128 TB

Random access

Transaction support

Needs LOB locator

CLOB

Character

8–128 TB

Random access

Transaction support

Needs LOB locator

BFILE

Binary

4 GB

Read-only

External file

Any storage device accessed by your operating system can hold BFILE data, including hard-disk drives, CD-ROMs, PhotoCDs, and DVDs. The database can access BFILES provided that the operating system supports stream-mode access to the operating system files. A summary of characteristics of LOB data types are:

  • Media objects with data types BLOB and CLOB can be stored in the database.

  • BLOB and CLOB are described as internal LOBS stored within the database tablespaces.

  • BFILE data type is used for objects stored externally as operating system files.

  • BFILE objects are called external LOBS stored outside the database tablespaces.

  • External LOBS (BFILES) could be located in another part of the network or on CD-ROMs or DVDs that are accessible to the database.

  • BFILE data type allows read-only access to these large files and they cannot participate in transactions.

In Oracle10g, small LOBS (up to 4 KB) can be stored inline with the rest of your row data:

  • All types of LOBS are manipulated through a LOB locator.

  • A locator is a unique binary value that acts as a surrogate for the actual binary object held in the database. It can be used to identify either a binary large object or a character large object.

The Disadvantages of Using BFILES

Storing the media data within the database gives a number of advantages that cannot be applied to BFILES, such as

  • Database security

  • Transaction control

  • Database backup and recovery, etc.

When we use a BFILE, the media is stored in files outside the database, and file location and attributes are stored inside the database. Although media functionality, such as image processing, can still be supported by moving the data to a temporary BLOB, the advantages listed above will be lacking.

When we develop an application for media data using an object-relational database there are several options available that would not have been possible with a basic relational database. In order to illustrate the different approaches we will use the following Picture Book case study to develop different solutions.

Family and Friends Picture Book Case Study

The Family and Friends Picture Book database should be capable of storing a wide variety of images obtained from different sources, including digital cameras and scanners. The family mentioned here intends to access the images through a website and to be able to browse through the images to select and retrieve different images. The application should support the following scenarios:

Jo, who is 11 years old, wants to be able to produce greeting cards, especially birthday cards, for her friends using photos of her pets that she takes with her point-and-shoot digital camera.

Jason would like to produce some sports greetings cards but also posters to support and promote the local tennis club events. He will particularly need to locate shots of sporting events and activities.

Marie needs to produce a calendar and a magazine cover for the charity she works for. She needs to locate photos of different seasons of the year.

In addition Marie has an interest in family history and has collected and scanned old black-and-white photographs from the nineteenth century from various older relatives. She wants to link these to the family tree that she is researching.

Matt is interested in astronomy, and his set of photos is mainly focused on the solar system. He captures images from his telescope as well as gets them from various sources, including the Internet. He needs to identify images from the night sky at different locations and times of the year.

In addition, the family records videos and images of their holidays and audio recordings of special family celebrations and music.

As far as possible, the family wants one generic photo database that will support this range of requirements. In this chapter we will focus particularly on the storage requirements and options for the Picture Book. In later chapters we will look at how to retrieve and display the media data. The scenarios above lead to the following functional requirements:

  • Storage of photographic images with a variety of file formats, including application-specific formats.

  • Availability of thumbnail images (lower-resolution images used for quick display) as a means of browsing the database and displaying the result sets from queries.

  • Availability of images of different resolutions, including print levels.

  • Storage of image subjects for future searching and compilation of collections of images.

Using the Relational Approach

First, just using BLOB and BFILE data types, for example, we could specify the main table as follows:

CREATE TABLE photos (
      id           NUMBER PRIMARY KEY,
      description  VARCHAR2(40) NOT NULL,
      location     VARCHAR2(40),
      image        blob,
      thumb        blob
);

In this way we would store both the main image and the thumbnail image within the database as they would be used for random access, transactions, image-processing, and indexing purposes. This is basically a relational approach to the problem and the database would be manipulated mainly through SQL. Consider the following data for rows for the Picture Book photos table that identify the two image files (Figure 3.1) we want to insert into the database.

Storing media data.

Figure 3.1. Storing media data.

id

4310

description

Graduates entering Senate House, 2004

location

C:PICTURES

image

Graduation.jpg

thumb

Small_grad.jpg

The family will probably want to add single images and generate thumbnails to store in the database. This is quite complicated with the relational approach. It involves the following processes for adding a row for a single image:

  • Initialize the image columns so that they can receive data using the EMPTY_BLOB() function.

  • Create a directory object for the corresponding directory, external to the database, that holds the images.

  • Create a temporary storage for the images by using a BFILE and initialize it as well using the BFILENAME() function.

  • Store the image in a BFILE and then transfer this to the image column with the BLOB data type by using the DBMS_LOB package.

This process is sufficiently complex to put many users off from developing a media database. Why is this necessary?

Before media data can be entered into the image column, we must ensure the LOB locator must be non-NULL. Instead of using NULL when the BLOB is missing from a row, the BLOB value is set to EMPTY by using the EMPTY_BLOB() function in the INSERT statement. A column containing a LOB value set to NULL has no locator. By contrast, an empty LOB is a LOB of zero length that has a LOB locator. So, if we select from an empty LOB column or attribute, we get back a locator, which we can use to fill the LOB with data using the OCI or DBMS_LOB routines or an appropriate import method. This initialization requirement will arise whenever a BLOB occurs, even with the interMedia data types described later in this chapter.

This can also be done for initializing the locator of the BFILE column by using the BFILENAME() function. Oracle provides a special function BFILENAME() to associate the external file with the database locator. To associate the BFILE objects with a directory in the external file system that will hold the actual data, we would need to create a DIRECTORY object. We must be connected as dba/system to do this unless, as users, we have been granted the create directory privilege, such as:

GRANT CREATE ANY DIRECTORY TO SCOTT;

This directory association is done by giving the subdirectory holding the image a logical name, using a statement, such as, for Windows,

CREATE DIRECTORY "PHOTO_DIR" AS 'C:PICTURES ';

or, for Unix or Linux,

CREATE DIRECTORY "PHOTO_DIR" AS 'home/images'

We must then grant the users access to the directory object. A directory object has thus been created to hold the external files, called “PHOTO_DIR,” and then access rights can be given to the users as:

GRANT READ ON DIRECTORY PHOTO_DIR TO SCOTT

As we have seen already it is difficult to manipulate LOBS in SQL because the standard functions do not exist and often SQL editors cannot cope with the display of media data. However, there are often reasons why using SQL to update LOBS or extract segments of data without necessarily displaying the data to the user would be an advantage. There are three approaches to manipulating a LOB in Oracle;

  1. Using Oracle API, such as Oracle Objects, for OLE and JDBC API.

  2. Using DBMS_LOB package.

  3. Using Oracle Call Interface (OCI).

We can use the special package DBMS_LOB provided for manipulating LOBS and BFILES. DBMS_LOB is a package that is based on working with LOB locators. It consists of a number of routines for manipulating LOBS. The DBMS_LOB package routines would normally be used within a PL/SQL procedure but some of the DBMS_LOB functions that deal with LOBS can be used directly in SQL. More details are given in Chapters 8 and Chapters 11.

The Disadvantages of Using BLOBS and BFILES

In addition to the problems we have already encountered, when we look at the Picture Book scenarios there are some data items that need to be stored that are associated with the media, for example:

  • The type of media file.

  • The name of the external source file.

  • The time when the media was captured or altered.

  • The height and width of the images when displayed.

It would be much better if the media metadata could be bundled together with the media data so they could not get separated or confused. To do this we will need to create object types. The storage approaches we will consider in the rest of the chapter all use object types. The ways in which we can manipulate LOBS using the relational approach is very limited. As an alternative approach, we can use the Oracle interMedia data types that include LOBS as attributes but provide classes with methods that give the required multimedia functionality. For example, in the Picture Book system we need a method to generate a thumbnail. Oracle interMedia can store the actual multimedia data as an internal source within the database, under transactional control as a BLOB. This is the recommended approach. It can also deal with multimedia data stored as an external source in an operating system–specific file in a local file system, as a URL on an HTTP server, or as a user-defined source on other servers, such as media servers. Although these external storage mechanisms are particularly convenient for integrating existing sets of multimedia data with a database, the multimedia data will not be under transactional control if it is not stored in the database. This would mean that when we wanted to carry out any database processing or image processing, we would need to copy the external BFILE into a temporary LOB within the database before we could process it.

Using the Object-relational Approach

With an object-relational database (ORDBMS) it is possible to create object types that are more complex than the simple data types in SQL. User-defined data types make it easier for applications developers to work with complex data. This approach also gives the developer maximum flexibility in their design because both the relational and object properties can be exploited. This means that we would be able to create object types with more complex structures, for example if we stored a video object we could hold both media data and the related metadata. These object types can then be used in a number of ways. In Oracle an object type is equivalent in concept to a class in UML and would have three kinds of components (Figure 3.2): it must have a name that uniquely identifies it within the database schema; it can have attributes that are either built-in types or object types; and methods that describe the operations that can be applied to the object type. This facility has given the developer the ability to introduce the concepts of object-oriented development into databases, giving the basis for the development of object-relational databases.

An object type’s components.

Figure 3.2. An object type’s components.

In the next section we will look at the object types available in interMedia that integrate data types based on BLOBS and BFILES with other useful data and methods. We will illustrate their application by seeing how these could be used to develop the Picture Book database.

Using Oracle interMedia

First, we will look at the way media data is stored in Oracle interMedia and what other attributes are included.

  • Is the recommended approach to using BLOB or BFILE data types for reasons we will learn as we go along.

  • Is a way of building multimedia applications rather than providing an end-user application.

  • Is a way of supporting existing media standards.

  • Supports a base set of popular multimedia data characteristics.

  • Can be extended to cope with new codecs, data sources, and even specialized data-processing algorithms for audio and video data.

  • Provides a set of multimedia user-defined types to make it easier for the database designer to create multimedia applications.

There are four object types available in interMedia for different kinds of media:

  1. ORDAudio for storing audio data characteristics.

  2. ORDImage for storing image data characteristics.

  3. ORDVideo for storing video data characteristics.

  4. ORDDoc for storing heterogeneous data characteristics.

interMedia provides an object-relational type, known as ORDDoc, that allows a column to hold a mixture of image, audio, and video data, or other heterogeneous media data. All these types belong to the ORDSYS schema and store data source information in an object-relational type, known as ORDSource, that holds the actual digital media data. In addition to specific attributes for the different kind of media (Table 3.2), another advantage is that the object types include a number of data manipulation methods, for example, for image media using ORDImage:

  • Format and compression conversion

  • Scaling

  • Cropping

  • Copying

Although interMedia includes object types for the different media (i.e., ORDAudio, ORDImage, ORDVideo, and ORDDoc), these all have a common data storage model. The media data could be stored as a BLOB under transaction control or outside the database as a BFILE. In that case a pointer is stored in the database and the media itself stored in a BFILE or HTTP server-based URL, or the source may be located on a special external media server. This data can be imported into a BLOB in the database when it is required for transaction processing. However, with new developments it would always be recommended to store the data as a BLOB. We can also process the interMedia data types by using the DBMS_LOB package in the same way as conventional BLOBS but this is usually unnecessary as more extensive methods are provided by interMedia.

Table 3.2. ORDSource Attributes

ORDSource Attribute

Data Type

Purpose

LocalData

BLOB

Locally stored multimedia data

SrcType

VARCHAR2(4000)

Type of data source for nonlocal data (e.g., FILE, HTTP)

SrcLocation

VARCHAR2(4000)

Location of data

Directory for FILE

URL for HTTP

SrcName

VARCHAR2(4000)

Name of object or file

UpdateTime

DATE

Last modified timestamp

Local

NUMBER

Flag that indicates whether the data is local (1 or NULL) = BLOB or external (0)

Before we consider the separate object types, we will briefly look at the attributes of ORDSource because occasionally we may need to access its attributes. This base type can accommodate media data as a BLOB or a BFILE, in which case the location and name of the data file is stored. Although ORDSource has object methods, these should not be called directly. Instead, we should invoke a wrapper method of the media object corresponding to the ORDSource method. We can think of the wrapper as a software adapter or shell that isolates the ORDSource component from other components and provides a cleaner or more specific way of using complicated classes. All the interMedia object types provide wrapper methods to do the following:

  • Set the source of the data as local or external.

  • Modify the time an object was last updated.

  • Set information about the external source type, location, and name of the data.

  • Transfer data into or out of the database.

  • Obtain information about the local data content, such as its length, location, or handle to the BLOB; put the content into a temporary BLOB; or delete it.

  • Access source data by opening it, reading it, writing to it, trimming it, and closing it.

The ORDSource object is embedded within the other interMedia object types and we do not deal with it directly since Oracle Corporation does not recommend that we use this object type. We would normally use the multimedia data types; for example, we could specify the photos table so that it contains interMedia objects. Recall that we defined a table

CREATE TABLE photos
(id           NUMBER PRIMARY KEY,
 description  VARCHAR2(40) NOT NULL,
 location     VARCHAR2(40),
 image        blob,
 thumb        blob);

that could be specified instead as

CREATE TABLE photos
(id          NUMBER PRIMARY KEY,
 description VARCHAR2(40) NOT NULL,
 location    VARCHAR2(40),
 image       ORDSYS.ORDIMAGE,
 thumb       ORDSYS.ORDIMAGE);

Since Oracle interMedia uses object types, an instance of these object types will consist of the media data itself, the methods associated with it, and metadata about the instance, which makes it much easier to develop media applications. We can insert an image into this table using INIT() methods for the interMedia type ORDIMAGE as follows:

INSERT INTO photos
VALUES
(1234, 'Outside Senate House - Graduation 2004', 'Cambridge',
ORDSYS.ORDIMAGE.INIT('FILE', 'PHOTO_DIR', 'graduation.jpg'),
ORDSYS.ORDIMAGE.INIT());

When this row is added to the table, the ORDImage INIT() method inserts a LOB locator into the image column to specify the external target file in the PHOTO_DIR directory and initializes the thumb column as empty rather than NULL. We discuss this method in more detail later.

In interMedia, Oracle has used object-relational concepts to create a set of multimedia object types to make it easier for the database designer to create multimedia applications. The object types have associated methods that cover common media requirements and image processing; for example, it provides methods getContent() and process(), which will already be available so we will not need to develop them specially for the application. This also has another advantage in that it allows databases to be developed in a generic style so that media data can be exchanged between applications. Another advantage is that the data types can still be accessed through a relational approach using PL/SQL and OCI or an object approach can be used based, for example, on C++ or JAVA. A database designer can also use interMedia to

  • Create new object types or composite object types based on the basic interMedia types.

  • Create specialized plug-ins to support new external sources of media data, such as new data formats, using a special ORDPLUGINS schema.

  • Process audio or video data in new ways.

By using these interMedia data types we can then use the methods for

  • Manipulating data about the source and comment attributes.

  • Getting and managing data from Web servers and other servers.

  • Performing file operations (open, close, trim, read, and write) for audio and video only.

  • Extracting metadata attributes from media data.

When we deal with a conventional SQL data type, such as CHAR, we are not conscious that the CHAR data type has methods associated with it. In fact SQLPLUS provides about 15 methods that we know as built-in functions for this data type (UPPER, LOWER, SOUNDEX, SUBSTR, and so on). The interMedia object types also have a useful set of methods. In Chapter 8 we look at these methods in greater detail.

Recall that if using interMedia, we would treat the Picture Book table differently.

CREATE TABLE photos
(id          NUMBER PRIMARY KEY,
 description VARCHAR2(40) NOT NULL,
 location    VARCHAR2(40),
 image       ORDSYS.ORDIMAGE,
 thumb       ORDSYS.ORDIMAGE);

This structure would allow us to include data relevant to the application, such as the description and location of the images, separately from data about the images, such as height, width, and MIME type, which would be encapsulated in the ORDIMAGE data type.

Manipulating Image Data Using interMedia

Oracle interMedia uses instances of object types that consist of the media data itself, the methods associated with it, and metadata about the instance. The methods will be the special procedures needed to manage the object and will be the same for all instances of the object. The metadata might include information about the object’s size, compression, or format. The metadata are always stored in the database even if the media data is externally located. The metadata includes the information about the source of the media data, source type, location, source name, and whether the media data is stored locally (in the database) or externally. Examples of metadata used by the different types of media are included in Table 3.3. It also shows what kind of media data it applies to and the purpose of the metadata in separate attributes. interMedia manages the metadata for all the media types and may automatically extract it for audio, image, and video processing.

Table 3.3. Metadata and interMedia

Media Data

Metadata

Purpose/Comment/Note

Audio, video

Description

Needed for semantic nature

Audio, doc, image, video

MIME type

Needed for real-time nature, so that browser knows how to display/play media. When MIME is used, all the media is retrieved and then played using a single local clock.

Audio, doc, video

Comments

Semantic nature, text-based retrieval

Audio

Encoding type, number of channels, sampling rate, sample size, compression type, play time (duration) format

Size—needed for issues related to performance for delivery across networked systems. This is particularly important because poor performance will result in distortions that are not acceptable to the user.

Doc

Source, format, content length

Size—needed for issues related to performance for delivery across networked systems as this type could include image, audio, or video.

Image

Height and width, image content length, format, compression type

Size—needed for issues related to performance for delivery across networked systems.

Video

Frame width and height, frame resolution, frame rate, play time (duration), number of frames, compression type, number of colors, bit rate

Size—needed for issues related to performance for delivery across networked systems where jitter becomes a problem.

The metadata described in Table 3.3 (e.g., relating to size) is often called content- or format-related metadata. The object types ORDAudio, ORDDoc, ORDImage, and ORDVideo contain specific attributes (see Table 3.4) and methods for their kind of media. In addition to specific attributes, another advantage is that the package includes a number of data manipulation methods, for example for image media:

  • checkProperties()

  • getCompressionFormat()

  • getContentFormat()

  • getHeight()

  • getWidth()

Table 3.4. Attributes of interMedia Types

Attribute

Data Type

Purpose

ORDAudio

  

Description

VARCHAR2(4000)

Free form description

Source

ORDSource

Source storing data

Format

VARCHAR2(31)

e.g., WAV

mimeType

VARCHAR2(4000)

MIME type of stored data (e.g., audio/x-aiff)

Comments

CLOB

Extracted metadata as XML

Encoding

VARCHAR2(256)

Encoding type that will be the same as the compression type

numberofChannels

INTEGER

Audio channel number form 1–6

samplingRate

INTEGER

Rate data recorded in samples per second, range 5500–48,000

sampleSize

INTEGER

Width 8–16 bits

compressionType

VARCHAR2(4000)

For audio it is the same as encoding

audioDuration

INTEGER

Time to play whole object

ORDImage

  

Source

ORDSource

Source storing data

mimeType

VARCHAR2(4000)

MIME type of stored data (e.g., image/tiff)

Height

INTEGER

Height in pixels

Width

INTEGER

Width in pixels

contentLength

INTEGER

Size in bytes

fileFormat

VARCHAR2(4000)

File type (e.g., tiff)

contentFormat

VARCHAR2(4000)

Type of image (e.g., grayscale)

compressionFormat

VARCHAR2(4000)

Image compression format (e.g., JPEG)

ORDVideo

  

Description

VARCHAR2(4000)

Free form description

Source

ORDSource

Source storing data

MIME type

VARCHAR2(4000)

MIME type of stored data (e.g., video/x-msvideo)

Comments

CLOB

Extracted metadata as XML

compressionType

VARCHAR2(4000)

Compression type

Height

INTEGER

Height of frame in pixels

Width

INTEGER

Width of frame in pixels

frameResolution

INTEGER

Number of pixels per inch

frameRate

INTEGER

Number of frames per second

videoDuration

INTEGER

Time to play entire clip

ORDDoc

  

Source

ORDSource

Source storing data

Format

VARCHAR(80)

Format of the media data

mimeType

VARCHAR(80)

MIME type information

contentLength

INTEGER

Length of the media data

Comments

CLOB

Extracted metadata as XML

New Formats Supported

Another advantage of using interMedia is that the object types are updated to include new formats and methods as multimedia technology changes and new standards are set up. This makes maintenance of multimedia applications much more straightforward. For example, interMedia now supports the MPEG-2 and MPEG-4 file formats and new methods are also incorporated as required. It also includes DICM as the interMedia designation for the digital imaging and communications in medicine (DICOM) format. FPIX, or FlashPix, is a format developed by Kodak, Microsoft Corporation, Hewlett-Packard Company, and Live Picture, Inc., for storing digital photography. Oracle interMedia does not write FlashPix images. The MIME type is image/x-fpx. The ORDVideo and ORDDoc object types now support the setProperties() method for extracting metadata information from MPEG-2 video streams. The ORDVideo, ORDAudio, and ORDDoc object types now support the setProperties() method for extracting metadata from MPEG-4 (.MP4) files.

Oracle interMedia also supports the ASF file format for ORDAudio, ORDVideo, and ORDDoc objects. Windows Media files from Microsoft (.WMV, .WMA, and .ASF) use the ASF file format. With this feature, the setProperties() method can extract metadata from ASF files. New image processing features are also now available through interMedia, as discussed in Chapter 9.

In the following sections we will show how to use each of the interMedia object types for storage of the different media.

ORDImage

In this section we will find out how to intialize the ORDImage object type (set the encapsulated BLOB to EMPTY_BLOB()), locate the data in the external source, and then import into the database when required. This process involves using several ORDImage methods. There are two ORDImage initialization methods available:

  • INIT()

  • INIT (srcType, srcLocation, srcName)

The fact that interMedia object types can evolve as technology changes brings many benefits. However, there are potential compatibility issues with client-side applications that were developed with previous releases, even after a server upgrade that includes evolved object types. The recommended approach, therefore, is to always use the INIT() method provided for all ORDSYS types, which initalizes all attributes before inserting data. INSERT statements left unchanged using the default constructor, which initializes each object attribute, and may fail if interMedia object types evolve.

INSERT INTO photos(id, description, image)
VALUES (1255, 'my image', ORDSYS.ORDImage.init());

The INIT() method is a static method that initializes all the ORDImage attributes to NULL with the following exceptions:

  • source.updateTime is set to SYSDATE

  • source.local is set to 1 (local)

  • source.localData is set to EMPTY BLOB

The alternative signature, INIT(srcType, srcLocation, srcName), is a static method that initializes all the ORDImage attributes to NULL with the following exceptions:

  • source.updateTime is set to SYSDATE

  • source.local is set to 0

  • source.localData is set to EMPTY BLOB

  • source.srcType is set to the input value

  • source.srcLocation is set to the input value

  • source.srcName is set to the input value

To initialize an ORDImage object, we can use a PL/SQL procedure:

CREATE OR REPLACE PROCEDURE init_image_type
AS
BEGIN
 INSERT INTO photos (id,description, image)
   VALUES (1235, 'graduates in Cambridge',
ORDSYS.ORDImage.INIT('FILE', 'PHOTO_DIR','graduation.jpg'));
 COMMIT;
END;

This procedure will link the row identified as 1235 with the external file graduation.jpg in the directory called PHOTO_DIR. The media data is still outside the database.

Note that when we use the INIT() method, then ‘FILE’ could be ‘HTTP’ if the media file were read from a Web server and then the directory object for the file, in this case ‘PHOTO_DIR’, would be a URL instead. As we mentioned before, this will add the data in such a way that the actual source is not local to the database.

Using PL/SQL Stored Procedures

This section gives a brief reminder of PL/SQL stored procedures, if you were not familiar with these. The procedures are useful for accessing data stored in tables and combining this with variables created to hold data for processing within the procedure. PL/SQL variables can have a wide range of data types, such as scalar, object types, and LOBS. The procedure begins with a specification of its name, init_image_type. The inclusion of the keyword IS or AS is essential, since the declaration of variables needed by the stored procedure is placed between the words AS and BEGIN. The second part, between BEGIN and END, forms the body of the procedure in the form of a compound statement that expresses step-by-step how the procedure processes the data. Although the compound statement may consist of a number of SQL statements separated by semicolons, it is essential that the definition of the body of the procedure is treated as a complete unit, and not as a series of individual SQL statements.

EXCEPTION is an important section that is not included in this example but is executed whenever an error occurs based on a group of predefined PL/SQL errors. Using the EXCEPTION clause, which is an optional part of the COMPOUND statement, is a way of clearly separating error-processing from normal-processing statements. Predefined internal exceptions are provided by Oracle to cater for common problems, such as when no data is retrieved or a statement attempts to divide by zero.

A procedure is defined with a list of parameters. Each parameter for a procedure must have a name that is unique for that procedure, a data type, and a mode of use. The purpose of the three modes of parameter and the way parameters of the different modes can be used are listed here.

IN

Provides an input value; an argument for this kind of parameter can be a literal (i.e., an actual) value, a variable, or an expression. It cannot be assigned a different value by the procedure and so cannot be placed on the left-hand side of an assignment statement or receive data through either a SELECT...INTO statement or FETCH statement.

INOUT

Can either provide an input value or return an output value; an argument for this kind of parameter must be a variable so that its value can be changed by the procedure.

OUT

Returns an output value; an argument for this kind of parameter must be a variable.

If a mode is not specified for a parameter, it is assumed to be an IN parameter. An IN parameter for a procedure can never be changed within the procedure. It must have the same value after an invocation call as before it.

An OUT or INOUT parameter does not have these restrictions and can be used much more freely in a procedure. You should note, however, that an OUT parameter does not have an initial value (and an INOUT parameter may not have one) so initialization is required if it is used to provide a value.

Since we have inserted the media data we can then process the data to transfer it to the internal source as follows using one of the methods of the ORDImage type as

obj.importFrom(ctx,'file','PHOTO_DIR','Graduation.jpg'),

This statement would be used within a PL/SQL procedure, such as the one below, which copies the existing image with id 1235 from the table into the variable obj that is a temporary variable defined as an ORDSYS.ORDImage object type containing a BLOB that can then be used with the importFrom method. We can see that the procedure also outputs a number of useful messages about the source and checks that it is now local to the database.

CREATE OR REPLACE PROCEDURE import_ext_image
AS
 obj ORDSYS.ORDImage;
 ctx RAW(64) :=NULL;
BEGIN
 SELECT p.image INTO obj FROM photos p
  WHERE p.id  = 1235 FOR UPDATE;
 -- set source to a file
 -- import data
 obj.importFrom(ctx,'file','PHOTO_DIR','Graduation.jpg'),
 -- check size
 DBMS_OUTPUT.PUT_LINE('Length is ' || obj.getContentLength);
 DBMS_OUTPUT.PUT_LINE('Source is ' || obj.getSource());
 UPDATE photos p SET p.image = obj WHERE p.id = 1235;
 COMMIT;
SELECT p.image INTO obj FROM photos p
  WHERE p.id  = 1235 FOR UPDATE;
IF (obj.isLocal()= True ) THEN DBMS_OUTPUT.PUT_LINE('Local is
set true'),
ELSE DBMS_OUTPUT.PUT_LINE('Local is set FALSE'),
END IF;
END;

In this procedure there is a SELECT statement that selects a single image value from a table and places it INTO the variable obj. This procedure works by selecting the row that has the initalized image column (ID 1235) for update. The importFrom method is called to import the actual media data into the variable obj and to check some details such as its content length and source. Then the data from obj is written into the database itself with the update statement. Finally, we check if the local attribute is true to check the data is inside the database.

In the procedure we used a ctx variable. This is a parameter used by a source plug-in, if it exists. If not used, as in this case, it should be set to NULL.

The recommended declaration for the ctx variable when not used is as follows:

ctx raw(64) := NULL;

If a source plug-in were developed and used, then the ctx variable would be used to initialize context information for the client. Until the execution of the importFrom() method, the image object content is a FILE, but importFrom(ctx) moves the data into the database and makes it reside in the database, making the image object contain the media content in the BLOB attribute of the object.

The UPDATE statement makes the actual changes to the table row.

When we execute the procedure we obtain the following information showing the image has been imported as local data

SQL> EXECUTE import_ext_image;
Length is 73874
Source is file://PHOTO_DIR/Graduation.jpg
Local is set true

PL/SQL procedure successfully completed.

The advantage of using the object type is that we can now manipulate the media data in ways that would have been very difficult with a simple BLOB. There are several operators that alter the scale of an image, so simplify the creation of images with a specific size such as thumbnail images. The maxScale and fixedScale operators are especially useful for creating thumbnail images from various-sized originals. The fixedScale operator specifies scaling values in pixels. The two integer values supplied to the fixedScale operator are the desired dimensions (width and height) of the destination image. The supplied dimensions may be larger or smaller (or one larger and one smaller) than the dimensions of the source image.

The maxScale operator as well preserves the aspect ratio (relative width and height) of the source image and also accepts two integer dimensions, but these values represent the maximum value of the appropriate dimension after scaling. The final dimension may actually be less than the supplied value. We can use these ORDImage methods to generate a thumbnail image and store this in the thumb column, as in the following example that creates, at most, a 32 × 32 pixel thumbnail image, preserving the original aspect ratio.

CREATE OR REPLACE PROCEDURE image_thumb
 (img_id IN NUMBER)
 AS
   timage ORDSYS.ORDImage;
 BEGIN
  SELECT image INTO timage FROM photos
   WHERE id = img_id FOR UPDATE;
  timage.process('maxScale=32 32'),
  UPDATE photos p SET thumb = timage
   WHERE id = img_id;
  COMMIT;
  EXCEPTION
   WHEN ORDSYS.ORDImageExceptions.DATA_NOT_LOCAL THEN
    DBMS_OUTPUT.PUT_LINE('Data is not local'),
 END;

SQL> execute image_thumb(1235);

We deal with the development of PL/SQL applications in Chapter 8 but the example above illustrates how the image is selected and then how the thumbnail is generated. The statement

DBMS_OUTPUT.PUT_LINE('Data is not local'),

is used to display messages and data values from PL/SQL.

Another useful method is setProperties(), which can be used in a procedure to extract the metadata of the image in id 1235:

image width = 1407
image height = 1320
image size = 309128
image file type = JFIF
image type = 24BITRGB
image compression = JPEG-PROGRESSIVE
image mime type = image/jpeg

ORDAudio

The family wanted to store their audio files in the database, perhaps by using a table with the following structure.

CREATE TABLE audio_ord
(id    NUMBER PRIMARY KEY,
 description VARCHAR2(40) NOT NULL,
 audio       ORDSYS.ORDAudio,);

We can initialize the ORDAudio object attribute in the usual way, as follows.

BEGIN
INSERT INTO audio_ord(id,description, audio)
VALUES (1729, 'School String Festival Beethovens 9th ',
ORDSYS.ORDAudio.init());
 COMMIT;
END;

We can also update using the INIT method, as follows.

UPDATE audio_ord
 SET
audio=ORDSYS.ORDAUDIO.INIT('FILE','AUDIO_DIR','BEETHOVEN.WAV'
);

SetProperties() is a useful method that reads the audio data to get the values of the object attributes and then stores them in the object attributes. This method sets the properties for each of the following attributes of the audio data for which values are available: compression type, duration, encoding type, format, MIME type, number of channels, sampling rate, and sample size. It also populates the comments field of the object with a rich set of format and application properties in XML form if the value of the setComments parameter is TRUE as illustrated by the following procedure.

CREATE OR REPLACE PROCEDURE get_audio_props
AS
 obj ORDSYS.ORDAudio;
 ctx RAW(64) :=NULL;
BEGIN
 SELECT p.audio INTO obj FROM audio_ord p
  WHERE p.id = 1729 FOR UPDATE;
 obj.setProperties(ctx,TRUE);
 DBMS_OUTPUT.PUT_LINE('format: ' || obj.getformat);
 DBMS_OUTPUT.PUT_LINE('encoding: ' || obj.getEncoding);
 DBMS_OUTPUT.PUT_LINE(
                  'numberOfChannels: ' ||
TO_CHAR(obj.getNumberOfChannels));
 DBMS_OUTPUT.PUT_LINE('samplingRate: ' ||
TO_CHAR(obj.getSamplingRate));
 DBMS_OUTPUT.PUT_LINE('sampleSize: ' ||
TO_CHAR(obj.getSampleSize));
 UPDATE  audio_ord p set p.audio = obj
   WHERE  p.id = 1729;
 COMMIT;
 EXCEPTION
  WHEN ORDSYS.ORDAudioExceptions.METHOD_NOT_SUPPORTED THEN

DBMS_OUTPUT.PUT_LINE('ORDAudioExceptions.METHOD_NOT_SUPPORTED
caught'),
  WHEN OTHERS THEN
   DBMS_OUTPUT.PUT_LINE('EXCEPTION caught'),
END;

ORDDoc

The ORDDoc object type supports the storage and management of any media data including image, audio, and video. This object type is defined as follows.

CREATE OR REPLACE TYPE ORDDoc
AS OBJECT
(
  -- ATTRIBUTES
source               ORDSource,
format               VARCHAR(80),
mimeType             VARCHAR(80),
contentLength        INTEGER,
comments                 CLOB,

We could create a table for the Family Picture Book that could hold any type of multimedia data and then insert using the following statements.

CREATE TABLE doc_ord
  (id               NUMBER PRIMARY KEY,
   description VARCHAR2(40) NOT NULL,
   my_doc      ORDSYS.ORDDoc)

INSERT INTO doc_ord VALUES
 ('1241','the grape in many wines such as Chablis',
ORDSYS.ORDdoc.INIT('FILE', 'PHOTO_DIR','CHARDONNAY.JPEG'));

INSERT INTO doc_ord VALUES
 ('1242','A recipe for Hungarian Goulash',
ORDSYS.ORDdoc.INIT('FILE', 'PHOTO_DIR','recipe.doc'))

This object type also has a setProperties() method that reads the media data to get the values of the object attributes and then stores them in the object attributes. This method understands all supported image, audio, and video format. This method sets the properties for the following attributes of the media data: format, MIME type, and content length. It populates the comments field of the object with an extensive set of format and application properties in XML form if the value of the setComments parameter is TRUE. The next procedure illustrates how this is done in the case where the comments field of the object remains unpopulated. The default value is FALSE.

create OR REPLACE PROCEDURE set_doc_prop
 AS
   obj ORDSYS.ORDDoc;
   ctx RAW(64) :=NULL;
 BEGIN
   SELECT my_doc INTO obj FROM doc_ord
     WHERE id = 1242 FOR UPDATE;
   obj.setProperties(ctx,FALSE);
   DBMS_OUTPUT.put_line('format: ' || obj.getformat());
   UPDATE  doc_ord SET my_doc = obj
     WHERE  id=1242;
   COMMIT;
   EXCEPTION
    WHEN ORDSYS.ORDDocExceptions.DOC_PLUGIN_EXCEPTION THEN
     DBMS_OUTPUT.put_line('DOC PLUGIN EXCEPTION caught'),
    WHEN OTHERS THEN
     DBMS_OUTPUT.put_line('EXCEPTION caught'),
 END;

ORDVideo

The family could create a separate table to store their family videos in the database, perhaps with the following structure.

CREATE TABLE video_ord
(      id          NUMBER PRIMARY KEY,
       description VARCHAR2(40) NOT NULL,
       video       ORDSYS.ORDVideo);

INSERT INTO video_ord VALUES
 ('1234','some pond life', ORDSYS.ORDVIDEO.INIT('FILE',
'VIDEO_DIR','CYCLIDIUM_GLAUCOMA.MOV'))
COMMIT;

Now we can use a procedure to capture the properties of the video. The video that has been stored as a BFILE in the ORDVideo column is selected and copied to a temporary BLOB within the database to get its attributes, which are then displayed.

CREATE OR REPLACE PROCEDURE get_video_props
AS
 obj ORDSYS.ORDVideo;
 tempLob   CLOB;
 ctx RAW(64) :=NULL;
BEGIN
 SELECT p.video INTO obj FROM video_ord p
  WHERE p.id  = 1234;
 DBMS_OUTPUT.PUT_LINE('getting comma separated list of all
attributes'),
 DBMS_OUTPUT.PUT_LINE('--------------------------------------
------- '),
 DBMS_LOB.CREATETEMPORARY(tempLob, FALSE, DBMS_LOB.CALL);
 obj.getAllAttributes(ctx,tempLob);
 DBMS_OUTPUT.PUT_LINE(DBMS_LOB.substr(tempLob,
DBMS_LOB.getLength(tempLob),1));
 COMMIT;
 EXCEPTION
  WHEN ORDSYS.ORDVideoExceptions.METHOD_NOT_SUPPORTED THEN
   DBMS_OUTPUT.PUT_LINE('VIDEO METHOD_NOT_SUPPORTED EXCEPTION
caught'),
  WHEN OTHERS THEN
   DBMS_OUTPUT.PUT_LINE('EXCEPTION CAUGHT'),
END;

We have seen how it is possible to use these interMedia object types to store and manipulate actual media data. In the case of an object type, methods can be functions or procedures written in PL/SQL or written in an external language, such as C++ or Java, and stored externally to the database. The methods are all called member functions.

Using SQL/MM Still Image Standard (ISO/IEC 13249-5:2001 SQL/MM)

This ISO/IEC standard defines object-relational types for images and image characteristics. It was developed in response to requests to deal with multimedia applications and issues of interoperability that had emerged with the popularity of Web-based user interfaces and multimedia delivery systems. The proposed standard was initially known as SQL/MM (MM for multimedia). It was originally intended to cover a number of different application domains such as full-text data, spatial data, and image data (still and moving). Later, data mining was added to the standard.

In addition, it was intended that the media data should be accessed through ordinary SQL:1999 facilities or by expressions that invoke SQL stored routines. SQL/MM is a multipart standard, however, unlike SQL itself, the various parts of SQL/MM are quite independent from one another. There is one common part known as the Framework that is found in Part 1. This provides definitions of common concepts used in all the other parts and the relationship between them. In particular, it describes the manner in which the other parts use SQL’s structured user-defined types to define the types required by the subject matter of each part.

Since the parts of the standard that deal with full-text, spatial data and data mining do not concern us here, we will focus on the standard for images.

SQL/MM Still Image is the part of the SQL/MM standard that provides structured user-defined types that would allow you to store new images into a database, retrieve them, modify them in various ways, and—most importantly—locate them by applying various “visual” predicates to collections of images. In SQL/MM Still Image, images are represented using an SQL:1999 structured type called SI_StillImage. This type can be used to store collections of picture elements (pixels) representing two-dimensional images.

The images can be stored in several formats, depending on what the underlying implementation supports—for example, formats such as JPEG, TIFF, and GIF are commonly supported as input and output formats, as well as formats in which images are stored and manipulated. The SI_StillImage type also encapsulates metadata information about each image, such as its format, its dimensions (height and width in pixels), its color space, and so forth. Methods applied to SI_StillImage instances include routines to scale an image (change its size proportionally); to crop an image (remove pixels both horizontally and vertically); and to create a thumbnail image.

A related set of object types is included in the standard to describe various features of images, for example:

  • SI_AverageColor type is used to represent the “average” color of a given image. The idea is that we can describe or match an image on the basis of its average color. This value may be used in locating images in collections (seeking an image of the sea by finding an image that is primarily blue).

  • SI_ColorHistogram type provides information about the colors in an image at a finer level of granularity than the image’s average color; it indicates how much of each color is found in an image (see Chapter 2).

  • SI_PositionalColor type represents the location of specific colors in an image, supporting queries such as “sunsets at sea” provided this was expressed as “has red and orange above dark blue”; such images could be located using those color characteristics. The idea is that we can divide an image into a number of rectangular areas and then describe the image by the most significant color in each area.

  • SI_Texture type allows the recording of information such as coarseness, contrast, and direction of granularity.

  • SI_FeatureList type permits recording all of the features described in the above list for each image.

These object types are provided within Oracle interMedia for interoperability purposes. A developer needs to consider whether to use it or ORDImage in an application. Some features that are available through ORDImage are not specified by the SQL/MM Still Image standard, and therefore are not available for StillImage objects:

  • Storing image data outside the database

  • Image processing operations (such as scaling up, compressing, and so on) that are specific to ORDImage

  • Java client API

In addition, the following image-matching features are not specified by the SQL/MM Still Image standard, and therefore are not available for StillImage objects:

  • Image matching based on shape

  • Indexing (average color, texture, positional color, and color histogram)

One of the ideas behind the SQL/MM standard was that SQL should be used to query the rich media data in as straightforward a way as possible. By combining several features of an image, it is possible to write queries that can retrieve from a very large image base a much smaller collection of images from which we can quickly select the exact image we want. It is also possible to screen collections of images to find images of potential interest for various reasons. For example, checking whether a new logo might conflict with other logos that have already been copyrighted, using an SQL statement like this one:

SELECT id
FROM photo_table
WHERE SI_findTexture(new_image).
SI_Score(image) > 1.2

Additional challenges are posed by moving images, such as digitized video. That sort of data is not addressed by SQL/MM Still Image, but it is possible that some future part of SQL/MM will be oriented toward moving images.

Oracle interMedia provides support for the first edition of the ISO/ IEC 13249-5:2001 SQL/MM Part 5: Still Image Standard through the SI_StillImage object type. This is a complex object type. The media data within the object type is held as the ORDSource object type that was described in detail earlier. Each object type includes attributes, methods, and associated SQL functions and procedures. In addition, Oracle has added some extra attributes. Although the SQL/MM standard does not provide support for all the features currently offered by the ORDImage object type in interMedia described next, the use of the SQL/MM standard interface may make some applications more portable across various vendor databases.

The SI_StillImage object type represents digital images with inherent image characteristics such as height, width, format, and so on. It is created in the ORDSYS schema with invoker rights and it is declared as INSTAN-TIABLE and NOT FINAL (see Chapter 8).

We can see from Table 3.5 that the SI_StillImage type is a complex type where a number of attributes are themselves object types known as collection types (e.g., colorsList). These are explained in greater detail in Chapter 8. You can obtain a full description by typing in SQL*PLUS, “DESCRIBE SI_StillImage.”

These attributes are listed to help understanding of the object type, however, it is recommended to access the properties of SI_StillImage type through its methods as the attributes are subject to change since a revised version of the SQL/MM standard is expected soon. To illustrate its use we could use the SI_StillImage object type to define the images in a Photo Store table, as follows.

Table 3.5. SI_StillImage Data Attributes

Attribute Name

Data Type

Purpose

Content_SI

ORDSYS.ORDSOURCE

Holds binary image as BLOB

contentLength_SI

INTEGER

Length of the image in bytes

Format_SI

VARCHAR2(4000)

Image format

height_SI

INTEGER

Number of image lines

width_SI

INTEGER

Number of image columns

Oracle Attribute Extensions

  

mimeType_ora

VARCHAR2(4000)

MIME type information

contentFormat_ora

VARCHAR2(4000)

Type of image (e.g., black-and-white)

compressionFormat_ora

VARCHAR2(4000)

Compression algorithm

retainFeatures_SI

INTEGER

A flag that indicates whether or not image features will be extracted and cached

averageColorSpec_ora

SI_Color

The cached SI_Color object

colorsList_ora

colorsList

Cached array of colors

frequenciesList_ora

colorFrequenciesList

Cached array of color frequencies

colorPositions_ora

colorPositions

Cached array of color positions

textureEncoding_ora

textureEncoding

Cached array of textures

CREATE TABLE photos_SI
(      id          NUMBER PRIMARY KEY,
       description VARCHAR2(40) NOT NULL,
       location    VARCHAR2(40),
       image       SI_StillImage,
       thumb       SI_StillImage)

The following example demonstrates how to insert a StillImage object into a database table. This example uses the PL/SQL package DBMS_LOB.LOADFROM FILE to load a BFILE into a temporary BLOB, which is then inserted into the column attribute. Alternatively, it would be possible to use SQL*Loader. Typically, you would use the PL/ SQL package if you were inserting objects one-by-one, and you would use SQL*Loader to insert objects in a batch job.

CREATE OR REPLACE PROCEDURE still_insert
AS
   lobd blob;
   fils BFILE := BFILENAME('PHOTO_DIR','cats.jpg'),
BEGIN
   DBMS_LOB.CREATETEMPORARY(lobd, TRUE);
   DBMS_LOB.fileopen(fils, DBMS_LOB.file_readonly);
   DBMS_LOB.LOADFROMFILE(lobd, fils,
   DBMS_LOB.GETLENGTH(fils));
   DBMS_LOB.FILECLOSE(fils);
   INSERT INTO photos_si (id,description,location, image)
       VALUES(1239, 'Two Siamese cats - Ben and Emma',
          'Buckinghamshire',new ORDSYS.SI_StillImage(lobd));
   DBMS_LOB.FREETEMPORARY(lobd);
   COMMIT;
END;

Using interMedia to Create Your Own Object Types

An object type is a simple definition of the class that will be stored in the data dictionary. For example, we could define a person object type. An example of a full specification of object and attributes would be:

CREATE TYPE person_t AS OBJECT
(       first_name     CHAR(20),
        second_name    CHAR(20),
        d_o_b          DATE);

The advantage of this approach would be that we could have a standard definition of a person that can be incorporated into any relational table of our database ensuring consistency throughout the enterprise. Alternatively, object types can be used to create object tables. Let us look again at the first table definition for the Photo Book:

CREATE TABLE photos
(      id          NUMBER PRIMARY KEY,
       description VARCHAR2(40) NOT NULL,
       location    VARCHAR2(40),
       image       BLOB,
       thumb       blob);

Instead we could create a simple object consisting of the same SQL data types:

CREATE TYPE photo_t AS OBJECT
 (      id          NUMBER,
        description VARCHAR2(40),
        image       BLOB,
        thumb       BLOB);

We can use object types in two ways: to specify an attribute in a relational table or to generate an object table of the same type. The object type can then be used to set up an object table for the photo_table type with a primary key based in the id column:

CREATE TABLE photo_table OF photo_t
(CONSTRAINT PK_photo_tab PRIMARY KEY(id))

This has the advantage of avoiding the storage and performance overhead of maintaining the 16-byte OID column and its index. Instead of using the system-generated OIDs, we used a CREATE TABLE statement to specify that the system use the primary key column(s) as the OIDs of the objects in the table. This can appear to be like a normal relational table so we can DESCRIBE, SELECT, INSERT, and UPDATE.

SELECT description FROM photo_table;

A system-defined constructor method is generated automatically for every object type. The name of the constructor method is the same as the name of the object type. We can INSERT into the photo_table using the constructor method:

INSERT INTO photo_table
VALUES
(photo_t(1234, 'Outside Senate House - Graduation 2004',
'Cambridge', EMPTY_BLOB(),EMPTY_BLOB()))

The advantage of this development approach is that it would give a standardized table for images that could be used to meet many requirements. This object type, just like a class, can be used to specify the structure of the data and the ways of operating on it. An instance of data that is structured according to the object type and stored in the database is an object. Since an object type is a concept or a template, when it is defined in the database it does not result in any allocation of storage. Since Oracle is following an object-relational paradigm instead of storing the objects in the database, we can create an object table that is defined for the purpose of holding object instances of a particular type.

The Disadvantages of Using Your Own Object Types

There are several disadvantages to using your own object types:

  • Problems of inconsistency and interoperability can arise.

  • Object types consist of attributes and methods so we would need to develop our own methods for each object type.

  • Maintenance problems are also increased as media devices change.

These problems make it sensible for developers to consider the advantages of using the standard interMedia types provided by Oracle, the SI_StillImage object type and the ORD types described previously.

There is, however, one advantage for developers who are familiar with object-relational concepts in that it is possible to develop an object type that contains the interMedia object types combined with metadata for specific application areas. For example, if we were developing an application that was related to the Dublin Core metadata standards (http://purl.org/metadata/dublin_core; see Chapter 2), we could create a type as an alternative to a purely relational approach, which would ensure the metadata was encapsulated with the interMedia attributes and methods.

CREATE TYPE dublin_core_t    AS OBJECT
(     identifier        CHAR(10),
      subject           VARCHAR2(80),
      title             VARCHAR2(80),
      creator           VARCHAR2(80),
      publisher         VARCHAR2(60),
      description       ORDSYS.ORDDOC,
      contributor       VARCHAR2(80),
      subject_date      DATE,
      resource          VARCHAR2(100),
      format            VARCHAR2(30),
      relation          VARCHAR2(100),
      source            VARCHAR2(100),
      language          CHAR(10),
      coverage          VARCHAR2(100),
      rights            VARCHAR2(100))

Then create the object table for that type setting the primary key:

CREATE TABLE dublin_core_table OF dublin_core_t
(CONSTRAINT PK_dublin_core PRIMARY KEY(identifier))

Summary

This chapter has introduced the storage options for the developer of rich-media databases. We started by considering the SQL:1999 large binary object use in databases. However, when we deal with media it is essential to know the source of the data and who owns the data and issues, such as compression, file type, etc. This metadata needs to be stored in such a way that it is integrated as much as possible with the media data and cannot be separated from it. For these reasons an object-relational approach is preferable.

Therefore, the chapter introduced object types and looked at the implications of designing user-defined types and using SQL/MM data types such as SI_StillImage as well as the interMedia data types.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.239.166