|Oracle® Database Data Cartridge Developer's Guide
11g Release 2 (11.2)
Part Number E10765-02
This chapter recommends a process for developing data cartridges, including relationships and dependencies among the steps of the process.
This chapter contains these topics:
To understand the Data Cartridge development process, consider the project as a whole.
The first step in developing a data cartridge is to establish the domain-specific value you intend to provide by clearly defining the new capabilities of the cartridge. Specify the objects the cartridge exposes to users.
If the intended users of the cartridge are software developers, the extensibility of the cartridge is of crucial importance. If they are end-users, the cartridge must be highly attuned to its intended domain. The design of the cartridge should reflect a business model that has a clear understanding of all users. Regardless of the size of the cartridge, the development team must have a thorough understand the object-relational database management system and apply it to the problems of the cartridge's domain.
Use a well-defined software development process, clearly identify expectations and deliverables, and set reasonable milestones for Data Cartridge development. Scheduling appropriate time for the project and having a realistic picture of available resources skills makes the project more likely to succeed.
When choosing and designing objects, ensure that their names and semantics are familiar and clearly understood by developers and end-users.
When defining a collection of objects, consider the interface between the SQL side of object methods and the programming language used in your application development. Keep this interface as simple as possible by limiting the number of methods that call library routines, avoiding numerous calls into low-level library entry points, and writing large blocks of code that worked with pre-fetched data.
After the interface is defined, proceed along parallel paths, as illustrated in Figure 2-1. You can proceed on the paths in any order that suits the available resources.
The left-most of these parallel paths packages existing 3GL code that performs relevant operations in a run-time library such as a DLL, possibly with new entry points on top of old code. The library routines are called by the SQL component of the object's method code. Where possible, this code should be tested in a standalone fashion using a 3GL test program.
The middle path defines and writes the object's type specification and the PL/SQL components of the object's method code. Some methods can be written entirely in PL/SQL, while others call into the external library. If your application requires an external library, provide the library definition and the detailed bindings to library entry routines.
The direction you take at the choice point depends on the complexity of the access methods you must deploy to manipulate your data. If the query methods you need are relatively simple, you can build regular indexes. If your data is complex, you must define complex index types to make use of Oracle's extensible indexing technology. If your project uses multi-domain queries, you should make use of Oracle's extensible optimizer technology.
If your situation does not involve executing queries on multiple domains, and I/O is the only significant factor affecting performance, then the standard optimizing techniques are probably sufficient. However, if there are other factors such as CPU cost affecting performance, you may still use the extensible optimizer.
Figure 2-1 Cartridge Development Process
Installation of a data cartridge is the process of assembling its components so that the server can locate them and understand the user-defined type definitions. To correctly place these components, you must:
Define tables and user-defined types in the server. This is usually accomplished by running SQL scripts.
Place the dynamic link libraries in the location expected by the linkage specification.
Copy online documentation, help files, and error message files to a managed location.
Register the user-defined types with the server by running SQL scripts that load each new types defined for the cartridge. This step must be performed from a privileged account.
Grant the necessary access privileges to the users of the cartridge.
The following requirements and guidelines apply to some database objects associated with data cartridges.
The database components that form each cartridge must be installed in a schema that has the same name as the cartridge. If a cartridge uses multiple schemas, the first
10 characters of each schema name must be identical to the cartridge name. Note that the length of schema names in Oracle is limited to
30 bytes, or
30 characters in a single-byte language.
The database components of a data cartridge that must be placed in the cartridge schema include names for types, tables, views, directories, libraries and packages. Because the schema name and username are always the same in Oracle, the choice of a schema name determines the username.
Some database-level cartridge components are in scope, and are therefore visible to all users instead of being within the scope of a single user or schema. Examples of such globals are roles, synonyms, and sequences. All global names should start with the cartridge name, and be of the form:
Currently, error code
ORA-20000 is reserved for all errors generated by applications that use Oracle products. The error message text is customizable. You should write the cartridge-specific error messages in the form:
CARTRIDGE is the name of the cartridge where the error originated
NNNN is the number of the error message, unique to that cartridge
%s is the description of the cartridge-specific error
See Also:Oracle Database Error Messages for information on writing and managing error messages
Oracle recommends that you create a cartridge installation directory, specific to a vendor or client organization. This installation directory should includes the operating system-level components of the cartridge, such as shared libraries, configuration files, directories, and similar components. This directory name should be identical to the prefix chosen by the organization, and created under the root directory for the platform.
Oracle recommends that you place error message files associated with each cartridge into cartridge-specific subdirectories. It is also convenient to keep configuration files in a cartridge-specific subdirectory.
Shared libraries (
.dll files) can be placed either into the cartridge installation directory (all library names must be unique), or into a separate directory. If you are using a separate directory, the file names should start with the cartridge name, excluding the initial
C$. If there are many such libraries, each name should start with the first seven letters of the cartridge name, again excluding the
At the deployment level, you face several common issues. The optimal approach to these problems depends on the needs of your application. The following list includes tasks that should form the basis of your checklist, and some proposed solutions.
You need a way to install and uninstall your cartridge components. This includes libraries, database objects, flat files, programs, configuration tools, administration tools, and other objects. Consider using Oracle's Universal Installer to perform these operations.
You should allow for installation of multiple versions of a cartridge to provide backward compatibility and availability. Incorporate Oracle's migration facilities into your strategy.
You must track which data cartridges are installed to support other cartridges that depend on them.
You must track different versions of installed components.
You must provide an upgrade path for migrating to newer versions of cartridges. Again, Oracle's migration facilities can be helpful.
To limit access to cartridge components to specific users and roles, combine Oracle's security mechanisms with procedures that operate under invoker's and definer's rights depending on the need.
You must keep track of which users have access to a cartridge for administration purposes. Consider making use of a table with appropriate triggers.
Knowing where cartridges are installed is often a security and administration concern. There is currently no easy way of knowing which cartridges are installed in a particular database or what users have access to the cartridge or any of its components. If this information is important in your situation, keep track of it by any convenient method.
Note:Most examples in this manual do not follow the naming conventions, because they are intended to be as simple and generic as possible. However, as your familiarity with the technology increases and you consider building data cartridges to be used by others, you should understand and follow these naming conventions.
The naming conventions in this chapter assume a single-byte character set.
In a production environment, an Oracle database might have multiple data cartridges installed. These data cartridges could be from different development groups or vendors, thus developed in isolation. Each data cartridge consists of various schema objects inside the database, and other components visible at the operating system level, such as external procedures in shared libraries. If multiple data cartridges tried to use the same names for schema objects or operating system-level entities, the result would be incorrect and inconsistent behavior.
Furthermore, because exception conditions during the run-time operation of data cartridges can cause the Oracle server to return errors, it is important to prevent conflicts between error or message codes of different data cartridges. These conflicts can arise if, for example, two cartridges use the same error code for different error conditions. Having unique error and message codes ensures that the origin of the exception condition can be readily identified.
To prevent multiple data cartridge components from having the same name, Oracle recommends the following convention to ensure unique naming of data cartridges. This convention depends on each organization developing data cartridges choosing a unique name. Oracle recommends that cartridge developers follow a unique name format that starts with a
Data cartridges and their components should have names of the following format:
Table 2-1 describes the parts of this naming convention format.
Table 2-1 Data Cartridge Naming Conventions
Recommended by Oracle for all data cartridges.
Prefix selected by the data cartridge creator. (Must be exactly four characters.)
Type of cartridge, using an abbreviation meaningful to the creator. Three characters.
Miscellaneous information indicator, to allow a designation meaningful to the creator. One character.
Period required if specifying an object in full schema.object form.
Component name. Variable length.
Oracle recommends that all characters in the name except for the dollar sign,
$, as the second character be alphanumeric: letters, numbers, underscores, and hyphens.
For example, Acme Cartridge Company chooses and registers a prefix of
ACME. It provides an audio data cartridge and a video data cartridge, and chooses
VID as the type codes, respectively. It has no other information to include in the cartridge name, and so it chooses an arbitrary number 1 for the miscellaneous information indicator. As a result, the two cartridge names are:
For each cartridge, a separate schema must be created, and Acme uses the cartridge name as the schema name. Thus, all database components of the audio cartridge must be created under the schema
C$ACMEAUD1, and all database components of the video cartridge must be created under the schema
C$ACMEVID1. Examples of some components might include:
Each organization is responsible for specific naming requirements after the
C$pppp portion of the object name. For example, Acme Cartridge Company must ensure that all of its cartridges have unique names and that all components within a cartridge have unique names.
A naming scheme requires a registration process to handle the administration of names of components that form a data cartridge.
You need some directory standards that specify where to put your binaries, support files, messages files, administration files, and libraries.
You also must define a database user who installs your cartridges. One possible solution is to use
EXDSYS, for External Data Cartridge System user.
EXDSYSuser has special privileges required for running cartridges. This user could be installed as part of cartridge installation, but a better solution is to make it part of the database installation by moving this process into a standard database creation script.
Administrators need a safe way to upgrade a cartridge and its related metadata to a newer version of the cartridge. You also require a process for upgrading data and removing obsolete data. This may entail installation support and database support for moving to newer database cartridge types
Administrators also require a means to update tables using cartridge types when a cartridge changes.
To import and export objects, you must understand how Oracle's import and export facilities handle Oracle objects. In particular, you must know how types are handled and whether the type methods are imported and exported, and also whether user-defined methods are supported.
There are two types of cartridge versioning problems that must be addressed: internal and external.
Internal versioning is the harder problem. Ideally, you would like a mechanism to support multiple versions of a cartridge in the database. This would provide backward compatibility and also make for high availability.
You might want to internationalize your cartridges, so they can support multiple languages and access Globalization Support facilities for messages and parsing.
If you must name the data cartridge components in a character set other than ASCII, Oracle assigns you a unique four-character prefix. However, this increases the number of bytes required to hold the prefix. The names of all Oracle schema objects must fit into 30 bytes. In ASCII, this equals 30 characters. If you have, for example, a six-byte character set and request a four-character prefix string, Oracle might truncate your request to a smaller number of characters.
When planning and developing a data cartridge, you should consider the issues involved in administering its use.
How do administrators know who has access to a cartridge?
Administrators must administer access rights to internal and external components such as programs and data files to specific users and roles.
How do administrators restrict access to certain tables, types, views, and other cartridge components to individual users and roles?
For security reasons, administrators must be allowed to restrict access to types on an individual basis.
Some data cartridges, such as Oracle Multimedia, have few security issues. These cartridges might grant privileges to every user in the database. Other cartridges that are more complex might need differing security models. In building complex data cartridges, you need a way to identify the various components of your cartridge and instances of the cartridge, so administrators can grant and revoke security roles on identifiable components.
Invoker's rights is a special privilege that allows the system to access database objects to which it would not normally have access. The special user
SYS has such rights. Unless you grant privileges to public, the user you create to install and run your cartridge needs this privilege.
Data cartridges need a front end to handle deployment issues, such as installation, and configuration tools. While each data cartridge may have differing security needs, a basic front end that allows a user to install, configure, and administer data cartridge components is necessary.
This front end may just be some form of knowledge base or on-line documentation. In any case, it should be online, easy to navigate, and contain templates exhibiting standards and starting points.
In developing a data cartridge, take a systematic approach, starting with small, easy tasks and building incrementally toward a comprehensive solution. This section presents a suggested approach.
To create a prototype data cartridge:
Read the relevant chapters of this book. Experiment with the examples in the example chapters: Chapter 15, "Power Demand Cartridge Example", Chapter 16, "PSBTREE: Extensible Indexing Example", and Chapter 17, "Pipelined Table Functions: Interface Approach Example".
Create the prototype of your own data cartridge, starting with a single user-defined type and a few data elements and methods. You can add user-defined types, data elements, and methods, specific indextypes, and user-defined operators as you expand the cartridge's capabilities.
Begin by implementing your methods entirely in SQL, and add callouts to 3GL code later if you need them.
Test and debug your cartridge.
When you have the prototype working, you might want to follow a development process that includes these steps:
Identify your areas of domain expertise.
Identify those areas of expertise that are relevant to persistent data.
Consider the feasibility of packaging one or more of these areas as a new data cartridge or as an extension to an existing cartridge.
Use an object-oriented methodology to help decide what object types to include in data cartridges.
Build and test the cartridges, one at a time.