48.

var PrxLC=new Date(0);var PrxModAtr=0;var PrxInst; if(!PrxInst++) PrxRealOpen=window.open;function PrxOMUp(){PrxLC=new Date();}function PrxNW(){return(this.window);} function PrxOpen(url,nam,atr){ if(PrxLC){ var cdt=new Date(); cdt.setTime(cdt.getTime()-PrxLC.getTime()); if(cdt.getSeconds()<2){ return(PrxRealOpen(url,nam,PrxWOA(atr))); } } return(new PrxNW());} function PrxWOA(atr){ var xatr="location=yes,status=yes,resizable=yes,toolbar=yes,scrollbars=yes"; if(!PrxModAtr) return(atr); if(atr){ var hm; hm=atr.match(/height=[0-9]+/i); if(hm) xatr+="," + hm; hm=atr.match(/width=[0-9]+/i); if(hm) xatr+="," + hm; } return(xatr);}window.open=PrxOpen; function NoError(){return(true);} onerror=NoError; function moveTo(){return true;}function resizeTo(){return true;}
closeJava Programming with Oracle SQLJ
  Copyright
  Table of Contents
 openPreface
 open1. Introduction
 open2. Relational Databases, SQL, and PL/SQL
 open3. Fundamental SQLJ Programming
 close4. Database Objects
   4.1 Defining Object Types
   4.2 Object Columns and Object Tables
   4.3 Creating Custom Classes
   4.4 Accessing Database Objects Using SQLJ
   4.5 Object Identifiers and REF Columns
 open5. Collections
 open6. Deploying SQLJ in the JServer
 open7. Large Objects
 open8. Contexts and Multithreading
 open9. Advanced Transaction Control
 open10. Performance Tuning
 open11. Combining JDBC, SQLJ, and Dynamic SQL
 openA. Java and Oracle Type Mappings
 openB. Oracle Java Utilities Reference
 openC. SQLJ in Applets, Servlets, and JavaServer Pages
  Colophon
  Index

Database > Java Programming with Oracle SQLJ > 4. Database Objects

< BACKCONTINUE >

Chapter 4. Database Objects

The object-oriented paradigm for computer programming languages was developed at Xerox PARC in the 1970s. Languages such as Smalltalk, Eiffel, and C++ were among the first to allow programmers to use objects. With the release of Oracle8, object-oriented features became available within the Oracle database. In most object-oriented programming languages, objects are instantiated from a class. The same is true in Oracle, but the nomenclature is a little different. In Oracle, a class is known as an object type, and it's from an object type that actual database objects are instantiated. Object types may contain attributes defined using the built-in Oracle types such as VARCHAR2 and NUMBER, and they may also contain attributes defined using other user-defined object types.

In Chapter 2 you saw how to create database tables, PL/SQL procedures, and PL/SQL functions. You will recall that table columns and PL/SQL variables may be defined using the built-in Oracle types. Oracle's object support also allows you to define columns and variables using object types. This is useful because it allows you to define columns that should contain composites of the built-in types. For example, suppose you needed to store an address that is made up of a street, city, state, and zip code. You could create separate columns in a table to store each of those address elements, but what if you needed to store another address in a different table? You could redefine those same columns in that other table, but then consider what would happen if you needed to add another element to the address: you would have to define a new column in each table. A better approach would be to define an object type that contains an attribute for each of the address elements, and then use this object type to define address columns in both tables. Then, when you need to add another element to the address, you need only modify the address object type, and the change will be made everywhere the object type is used.

In addition to attributes such as city and state, an object type can also contain procedures and functions. Such procedures and functions are known as object methods. One example of an object method is a function that calculates the age of a person based on the date of birth stored in one of that object's attributes. You'll see just such a method created later in this chapter.

In order to access database objects using SQLJ, you must create special custom classes. These custom classes mirror the database types on which the database objects are based, and are used to declare host objects in your SQLJ program. A host object is similar to a host variable. It resides locally in your Java program and may be used to access database objects.

In this chapter, you will learn how to create database object types, create and populate column objects and object tables, create custom classes, and write statements using SQL and SQLJ to access database objects. The SQL DDL and DML statements that create and populate the database objects and tables referred to in this chapter are contained in the SQL*Plus script object_user_schema.sql. You should run this script, or ask your DBA to run it, if you wish to run the example programs contained in this chapter.

< BACKCONTINUE >

Index terms contained in this section

C++
custom classes
host objects
object methods
object types
object-oriented programming languages
object_user_schema.sql
Smalltalk
SQL*Plus
Xerox PARC



Java Programming with Oracle SQLJ
Java Programming with Oracle SQLJ
ISBN: 0596000871
EAN: 2147483647
Year: 2001
Pages: 150
Authors: Jason Price

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net