![]() |
Using Cloudscape's Java Extensions
|
Reference Manual |
Storing Java Objects in Cloudscape TablesCloudscape allows you to define a column as a serialization of a class or interface. Serialization is a Java mechanism for reading and writing objects to a stream. To store serialized instances of a class or interface in the database, the class must meet the requirements for serialization. For information about creating serializable Java data types, see Programming Serializable Classes. Once a column is defined to hold serialized instances of a class (or serialized instances of a subclass or class that implements the interface), you can:
Defining a Column to Store a Java Data TypeWhen defining any column in a table, you assign it a name and a data type. For example, to define a column in which you want to store a city's integer id number, you need to give it a name and an SQL data type: city_id INT For Java data types, you must use the keyword SERIALIZE along with the class or interface name (or class alias) to specify the serialized Java class as the data type: columnName SERIALIZE( { JavaClassName | ClassAlias }) The Java class must meet the requirements for serialization (see Requirements for Serialization). For example, to store the Java class JBMSTours.serializabletypes.City (aliased as City) in a table along with its SQL-92 INT id, you would define the table as follows:
CREATE TABLE Cities (city_id INT, Storing Objects in the ColumnOnce the table is defined, you can store any object that is an instance of a class or a sub-class of the class named in the column definition. If the column is defined to serialize an interface, you can store an object that is an instance of a class that implements the interface. From a Java application, you typically insert a row of object values using dynamic parameters and then pass in the in-memory objects. For example, to insert an instance of the Java class City assigned to the variable name theCity in your application, use JDBC methods as shown in the following example: insert = conn.prepareStatement( Cloudscape Database Design ConsiderationsBecause you have the ability to store data as objects or as SQL-92 data types, you must answer some basic design questions for a Cloudscape database:
Another design question to answer is: The advantages of storing the actual objects in the database are:
In addition to these points, the standard relational database design considerations apply for designing a Cloudscape database. |
|
![]() Cloudscape Version 3.6 For information about Cloudscape technical support, go to: www.cloudscape.com/support/.Copyright © 1998, 1999, 2000 Informix Software, Inc. All rights reserved. |