Guide  Reference  Contents  Previous  Next  Index



Schema Matching for Interoperability

An Objectivity/DB federated database can be shared by Java applications and applications written in C++ or Smalltalk. Each application maps data for an object between the Objectivity/DB data types specified in the schema description for its class and data types native to the application. This chapter explains how to define a persistence-capable Java class that is compatible with an existing schema class description. You can ignore this chapter if your application doesn't interoperate with applications written in different languages.

In This Chapter

Interoperability
Selecting the Class Name
Defining the Inheritance Hierarchy
Defining the Relationships
Defining the Persistent Fields
Mapping Objectivity/DB Types to Java Types
Object-References
Numeric and Character Data
Strings
Date and Time Data
Arrays

Interoperability

If you develop a Java application to interoperate with applications in other languages, you must be sure that your Java classes and the corresponding classes in the other languages are all compatible with the schema of the shared federated database.

Refer to Objectivity documentation for the various languages to find out how each language adds a class description to the schema and what Objectivity/DB types each language supports.
Some field types and inheritance relationships preclude interoperability because they are not supported by all application languages. Java does not support the following characteristics; if a schema description of a class contains any of these characteristics, you cannot define a compatible Java class:


Note: The Objectivity/C++ programming interface allows an application to partition class definitions among multiple schemas in the same federated database. However, Objectivity for Java supports only a single default schema, so a Java application cannot access classes that reside in a nondefault (named) schema.

Selecting the Class Name

Your application can use whatever naming convention you prefer for persistence-capable Java classes. The schema identifies each class with a unique class name. A Java application also has a schema class name for each persistence-capable class. When the application reads or writes a persistent object, Objectivity for Java maps between the Java name of the object's class and the application's schema class name for the class.

If a class name in the schema is a legal Java class name, you may use the same name for the corresponding Java class, but you are not required to do so. The only requirement is that your application's schema class name is the same as the class name in the schema.


Note: You should set the custom schema class names for your application before performing any operations that read or write persistent objects. For more information, see "Schema Class Names".

Defining the Inheritance Hierarchy

When you define a Java class corresponding to an existing schema class definition, the inheritance hierarchy for your Java class must be the same as the inheritance hierarchy reflected in schema class descriptions. In particular, the superclass for your class should be the Java class whose schema class name appears as the superclass in the class definition. You can use the Objectivity/DB objects and types browser to see the superclass specified in an existing class description.


Warning: Objectivity/DB supports multiple inheritance; persistence-capable C++ classes may have more than one immediate superclass. Because Java does not support multiple inheritance, you cannot define a Java class that is equivalent to any class in the schema that uses multiple inheritance.

Defining the Relationships

When you define a Java class corresponding to an existing schema class definition, you should define a relationship corresponding to each relationship in the class description. You can use the Objectivity/DB objects and types browser to see the relationships in an existing class description.

Define each relationship of your Java class as described in the schema. The relationship fields of your Java class should be in the order in which the corresponding relationships appear in the class description. The related class should be the Java class whose schema class name appears in the schema class description. The following properties of the relationship should be the same in your class as in the schema:

Defining the Persistent Fields

When you define a Java class corresponding to an existing schema class definition, you should define a persistent field corresponding to each field in the class description. The fields of your Java class should have the same names as the field names in the class description; they should be declared in your class in the order in which they appear in the class description.

Because different languages support different field access control settings, you do not need to define each Java field with the same access control as appears in the schema. Instead, you should use the field access control that makes sense for your Java application and set the schema policy of your application to disregard field access control when comparing a Java class with the corresponding class description in the schema.

You must select a Java type for each field that is compatible with the corresponding Objectivity/DB data type in the class description. You can use the Objectivity/DB objects and types browser to see the Objectivity/DB type of each field in an existing class description.

Objectivity/DB supports a wide range of data types for persistent data. A given Objectivity/DB type may be mapped to more than one Java data type. However, each Objectivity/DB type has one or more recommended mappings; some Objectivity/DB types can be mapped to additional Java types, but these mappings are not recommended. If at all possible, you should select the Java type of a field from the recommended mappings for the Objectivity/DB type of the field.

Mapping Objectivity/DB Types to Java Types

This section groups Objectivity/DB data types according to the classification presented in Chapter 21, "Objectivity/DB Data Types". For each group of Objectivity/DB data types, a table lists the recommended mappings. When you define a Java class to be compatible with a class description in the schema, you should use these tables to select a recommended Java type corresponding to the Objectivity/DB type of each field. Any notes or warnings about potential problems appear before the corresponding table of mappings.


Warning: Each Objectivity/DB field is defined to contain either a single value or a fixed-sized array of values of the same type. Because Java does not support fixed-sized arrays, you cannot define a Java class that is equivalent to a class in the schema with a field that contains a fixed-sized array.

Object-References

This section describes the Java types that are compatible with Objectivity/DB object references when the referenced class is an application-defined persistence-capable class or a persistence-capable class in the public Objectivity for Java programmer interface. Object references to Objectivity/DB internal persistence-capable classes are described in later sections.

Recommending Mappings

The following table lists the recommended Java type for Objectivity/DB object-reference types.

Objectivity/DB Object-Reference TypesRecommended Java Type
ooRef(AppClass) ooShortRef(AppClass) where AppClass is an application-defined persistence-capable class.PCclass where PCclass is a persistence-capable class that matches the schema description for AppClass and for which the application uses the schema class name AppClass.
ooRef(APIclass) ooShortRef(APIclass) where APIclass is a persistence-capable class in the public Objectivity for Java programmer interface (for example, ooContObj or ooMap).APIclass

Alternative Mappings

A field whose declared Java data type is an interface is represented in the schema by the Objectivity/DB type ooRef(ooObj). As a consequence, you may map a regular or short reference to ooObj to any interface type. Of course, you should only use an interface that is implemented by some persistence-capable class.

The following table lists the Java classes that are allowed mappings for Objectivity/DB object-references to ooObj.

Objectivity/DB Reference TypesAllowed Java Type
ooRef(ooObj) ooShortRef(ooObj) PCinterfacewhere PCinterface is an interface (implemented by one or more persistence-capable classes)

Numeric and Character Data

The following table lists the recommended Java types for each of the Objectivity/DB primitive numeric types that are used for character, integer, and floating-point data.

Objectivity/DB Primitive Type Recommended Java Types
int8 byte
int16 short
int32 int
int64 long
uint8 boolean
short
uint16 character
int
uint32 long
uint64 long
float32 float
float64 double
char byte

Strings

The schema description for a field containing a string specifies an embedded Objectivity/DB non-persistence-capable class. If a class C has a field whose type is a non-persistence-capable string class, an instance of that string class is embedded within the data for a persistent object of class C. Although Java has no way to embed one instance within the data for another, Objectivity for Java can map these embedded instances into standard Java references to Java string classes.

The following table lists the recommended Java types for each Objectivity/DB non-persistence-capable string class.

Objectivity/DB Embedded String ClassRecommended Java Types
ooVString String1
StringBuffer1
ooUTF8String String
StringBuffer
1. Unicode characters will be stored and retrieved correctly, but they may not be rendered correctly by some tools, such as the Objectivity/DB browser.

The ooVString class is intended for strings of ASCII characters only; if a string with Unicode characters is stored as an ooVString and then retrieved by an application, the retrieved string is not guaranteed to be rendered correctly. In contrast, the ooUTF8String class can represent unicode characters that will be rendered correctly on all platforms supporting unicode.


Note: If a schema class description contains an ooVString field, you should avoid using unicode characters in strings stored in the corresponding field of objects of your Java class.

Objectivity/DB also has a persistence-capable string class, oojString, that is used only for the elements of a string array of class ArrayOfObject; you should map references to a string array to the Java type String[] as described in "Arrays". Because schema descriptions do not contain fields that are object references to the class oojString, you do not need to map such object-reference types to a Java string class except in the context of the containing array.


Warning: Objectivity/C++ applications can define special non-persistence-capable optimized string classes named ooString_N where N is the number of characters for which strings of the class are optimized. If a C++ persistence-capable class has a field of type ooString_N, an instance of ooString_N is embedded within the data for a persistent object of the class. Because Java has no way to embed one instance within the data for another, you cannot define a Java class that is equivalent to any class in the schema with a field whose Objectivity/DB type is ooString_N.

Date and Time Data

The schema description for a field containing date or time data specifies either an embedded Objectivity/DB non-persistence-capable class or an object-reference type for which the referenced class is an internal Objectivity/DB persistence-capable class.

Embedded Data and Time Classes

If a class C has a field whose type is a non-persistence-capable date or time class, an instance of that date or time class is embedded within the data for a persistent object of class C. Although Java has no way to embed one instance within the data for another, Objectivity for Java can map these embedded instances into standard Java references to Java date or time classes. Mapping an Objectivity non-persistence-capable class to a Java class can lead to two differences between data in Java memory and the corresponding data after it has been written to the federated database:

For a discussion of these differences, see "Data in the Federated Database".


Note: If a class description contains a field with an embedded non-persistence-capable date or time class, objects of your corresponding Java class should not rely on object identity in that field or use null values in that field. (The loss of object identity should not cause problems, because all Java date and time classes are immutable.)

The following table lists the recommended Java types for each Objectivity/DB non-persistence-capable date and time class.

Objectivity/DB Embedded Date or Time ClassRecommended Java Types
ooSQLdate java.util.Date1, 2
java.sql.Date1, 2
ooSQLnull_date java.util.Date1
java.sql.Date1
ooSQLtime java.sql.Time1, 2
ooSQLnull_time java.sql.Time1
ooSQLtimestamp java.sql.Timestamp1, 2
ooSQLnull_timestamp java.sql.Timestamp1
1. Does not preserve object identity.
2. Null values will be stored as zero and retrieved as zero.

Object References to Data and Time Classes

The following table lists the recommended Java types for object references to each Objectivity/DB persistence-capable date and time class.

Objectivity/DB Object-Reference to Date or Time ClassRecommended Java Types
ooRef(oojDate) java.util.Date
java.sql.Date
ooRef(oojTime) java.sql.Time
ooRef(oojTimestamp) java.sql.Timestamp

Arrays

The schema description for a field containing a variable-length array specifies either an embedded non-persistence-capable Objectivity/DB array class or an object-reference type for which the referenced class is an internal Objectivity/DB persistence-capable array class.

Embedded Array Classes

Java preserves array identity; Objectivity/DB's persistence-capable array classes preserve identity but its non-persistence-capable array classes do not. If a non-persistence-capable array class is mapped to a Java array, array identity is lost when a Java array is written to the federated database. For example, suppose that two Java objects reference the same array in persistent fields. If the two objects are saved in the database and later read by a Java application, the two retrieved objects will reference the different arrays.


Note: If a class description contains a field with an embedded non-persistence-capable array class, objects of your corresponding Java class should not rely on array identify in that field.

Recommended Mappings

The following table lists the recommended Java type for each Objectivity/DB non-persistence-capable array class.

Objectivity/DB Embedded Array ClassesRecommended Java Type
ooVArray(int8) byte[]1
ooVArray(int16) short[]1
ooVArray(int32) int[]1
ooVArray(int64) long[]1
ooVArray(uint8) boolean[]1
ooVArray(uint16) char[]1
ooVArray(float32) float[]1
ooVArray(float64) double[]1
ooVArray(ooRef(AppClass)) ooVArray(ooShortRef(AppClass)) where AppClass is an application-defined persistence-capable class.PCclass[]1 where PCclass is a persistence-capable class that matches the schema description for AppClass and for which the application uses the schema class name AppClass.
ooVArray(ooRef(APIclass)) ooVArray(ooShortRef(APIclass))where APIclass is a persistence-capable class in the public Objectivity for Java programmer interface (for example, ooContObj or ooMap).APIclass[]1
1. Does not preserve array identity.

Alternative Mappings

A field whose declared Java data type is an interface is represented in the schema by the Objectivity/DB type ooRef(ooObj). As a consequence, you may map an array of object references to ooObj to an array of any interface type. Of course, you should only use an interface that is implemented by some persistence-capable class.

The following table lists the Java classes that are allowed mappings for Objectivity/DB non-persistence-capable array classes involving object references to ooObj.

Objectivity/DB Embedded Array ClassesAllowed Java Types
ooVArray(ooRef(ooObj)) ooVArray(ooShortRef(ooObj)) PCinterface[]1 where PCinterface is an interface (implemented by one or more persistence-capable classes)
1. Does not preserve array identity.

Object-References to Array Classes

An object reference to an Objectivity/DB array class corresponds to a Java array. In the case of an array of objects, the class of the array elements determines the appropriate Java array type.

Recommended Mappings

The following table lists the recommended Java type for object references to the Objectivity/DB persistence-capable array classes.

Objectivity/DB Object Reference to Array ClassRecommended Java Types
ooRef(oojArrayOfInt8) byte[]
ooRef(oojArrayOfInt16) short[]
ooRef(oojArrayOfInt32) int[]
ooRef(oojArrayOfInt64) long[]
ooRef(oojArrayOfBoolean) boolean[]
ooRef(oojArrayOfCharacter) char[]
ooRef(oojArrayOfFloat) float[]
ooRef(oojArrayOfDouble) double[]
ooRef(oojArrayOfObject) where array elements are of type oojString String[]
ooRef(oojArrayOfObject) where array elements are of type oojDatejava.util.Date[] java.sql.Date[]
ooRef(oojArrayOfObject) where array elements are of type oojTimejava.sql.Time[]
ooRef(oojArrayOfObject) where array elements are of type oojTimestampjava.sql.Timestamp[]
ooRef(oojArrayOfObject) where array elements are of type ooRef(AppClass) and AppClass is an application-defined persistence-capable classPCclass[] where PCclass is a persistence-capable class that matches the schema description for AppClass and for which the application uses the schema class name AppClass.
ooRef(oojArrayOfObject) where array elements are of type ooRef(APIclass) and APIclass is a persistence-capable class in the public Objectivity for Java programmer interface (for example, ooContObj or ooMap)APIclass[]

Alternative Mappings

A field whose declared Java data type is an interface is represented in the schema by the Objectivity/DB type ooRef(ooObj). As a consequence, you may map an array of object references to ooObj to an array of any interface type. Of course, you should only use an interface that is implemented by some persistence-capable class.

The following table lists the Java classes that are allowed mappings for object references to the Objectivity/DB array classes involving references to ooObj.

Objectivity/DB Object Reference to Array ClassAllowed Java Types
ooRef(oojArrayOfObject) where array elements are of type ooRef(ooObj)PCinterface[] where PCinterface is an interface (implemented by one or more persistence-capable classes)



Guide  Reference  Contents  Previous  Next  Index



Copyright © 2000, Objectivity, Inc. All rights reserved.