Skip Headers

Oracle9i Lite C and C++ Object Kernel API Reference
Release 5.0.1
Part No. A95263-01
Go To Table Of Contents
Contents
Go To Index
Index

Previous Next

2
OKAPI Functions

This document details the functions of the Oracle Lite Object Kernel API (OKAPI). It includes the following topics:

2.1 Platform Compatibility

In this release of Oracle Lite, OKAPI supports the following platforms:

While almost all functions in the general OKAPI interface, as defined in this guide, are implemented on each platform, some do not have functioning code. Depending on the platform, functions are assigned to one of the following categories:


Compatible

Although the internal processing for compatible functions may differ between a specific platform and the general OKAPI implementation, they are externally identical to the caller on all platforms. These functions are designated by the letter: "C".


Implemented as a Dummy Stub; Always Returns Positive

These functions do nothing internally, but always return a positive result. Programs using these calls compile successfully and should not detect any abnormal behavior. These functions are designated by the letter: "P".


Implemented as a Dummy Stub; Always Returns Negative

These functions do nothing internally and always return a negative result (OK_NOT_SUPPORTED). Programs with these calls compile successfully, but produce runtime errors when the calls are executed. These functions are designated by the letter: "N".


Not Implemented

These functions do not exist in the library for the given platform. Programs using these functions do not compile. Calls to these functions should be commented out. These functions are designated by the letters: "NI".


Note:

The OKAPI header file, okapi.h, includes data structure definitions and function prototypes that are not described in this document. They are provided for backward compatibility and should not be used.

2.2 OKAPI Datatypes

OKAPI defines persistent and runtime datatypes to ensure that OKAPI database applications are machine and compiler independent. OKAPI defines the following persistent datatypes.

Datatype Description
ok4B Signed 4-byte integer
okU4B Unsigned 4-byte integer
ok2B Signed 2-byte integer
okU2B Unsigned 2-byte integer
ok1B Signed 1-byte integer
okU1B Unsigned 1-byte integer
okChar Character
okFloat Single-precision floating-point
okDouble Double-precision floating-point

OKAPI also defines the following basic datatypes for runtime use.

Datatype Definition
okBool Boolean
okByte Byte
okError Error code
okLock Lock mode
okSize Size type
okPtr Generic pointer
okName Name type
okObjData Pointer to the body of a persistent object

2.3 Object Structure

In a typical object system, an object has an unchangeable unique identifier and an object body to hold its attribute values. Conceptually, an object A references another object B by using the unique identifier of B. In practice, an object reference is usually mapped into a memory pointer in a program, which points to an encapsulation of the unique identifier. This in turn contains information for locating the object body. The process of converting an object reference (which is often stored as an unique object identifier on secondary storage) into a memory pointer is commonly known as pointer swizzling.

A cached object generally has a descriptor, a header, and a body. A descriptor contains the ID of the object, a pointer to the object body, and other meta-information about the object. The header contains additional meta-information about the object. The body portion of an object contains data values of the object. An object reference (of type okRef) is a pointer to the descriptor of the object. When an object is fixed in the cache, the body of an object can be directly accessed through a pointer (of type okObjData). The Oracle Lite database uses object handles (of type okHandle) to indicate either an object reference or a direct pointer to the object body. For many OKAPI functions, you can use an object reference and an object body pointer interchangeably as input arguments.

2.4 Object Pointer Conversions

You can convert an object pointer of one type to another, but such conversions should be done with care. Conversions between certain types of pointers may not yield valid results. For example, you should not convert an object reference (okRef) to okObjData, since an object reference points to the descriptor of the object and not the body of the object. An attempt to access the body of an object directly through an object reference returns erroneous results, and may even cause a memory protection fault.

The following table shows the validity of object pointer conversions. In the table:

2.5 Environments

Every database operation must be performed in the context of an environment object (okEnv). An environment object creates an independent environment (with object cache and memory heap) for the execution of database operations. An environment may have one current transaction or no transaction. Within an environment, you can connect to multiple databases simultaneously.

2.5.1 Environment Functions Compatibility Reference

This table lists the OKAPI functions that manage environment objects.

Function Purpose Win32 Palm EPOC
okInit   Creates an object cache for an application and initializes the system. C C C
okFinal   Terminates an environment. C C C
okCleanup   Abnormally terminates an environment. C X C
okGetEnvInfo   Gets information about the environment. C X C

2.5.2 okInit

Creates an object cache for an application and initializes the system.


Syntax
okError okInit(const okEnvParams_s *EnvParams,

   okEnv *RetEnv);

Parameters
EnvParams

The environment handle.

RetEnv

A database handle.


Comments

The okEnvParams_s structure specifies options for the environment. If EnvParams is NULL, the system uses default parameters for the environment. If EnvParams is not NULL, you can set individual parameters to 0 or NULL for the default for that parameter.

The okEnvParams_s structure has the following format:

typedef struct okEnvParams_s {

    okU4B       StructSize;     /* caller fills in size of this structure */

    okU4B       CacheSize;      /* Number of unfixed objects to keep */

    okU4B       NumObjRefs;     /* optional estimated number of descriptors */

    okU4B       UserIDLen;      /* optional length of user ID */

    okName      UserIDPtr;      /* optional pointer to user ID */

    okU4B       PasswdLen;      /* optional length of password */

    okName      PasswdPtr;      /* optional pointer to password */

    okPtr       LocalHeap;      /* optional local heap handle */

    okPtr       CacheHeap;      /* optional cache heap handle */

    okU4B       Options;        /* optional environment options */

    okU1B       CharacterSet;   /* optional environment character set */

    okU1B       _Padding[3];    /* not used */

} okEnvParams_s;

2.5.3 okFinal

Terminates an environment.


Syntax
okError okFinal(okEnv Env);

Parameters
Env

An environment handle.


Comments

This function terminates an environment Env. It disconnects all outstanding database connections with the application and releases all runtime resources allocated by Env. This function commits the last transaction, if still active.

2.5.4 okCleanup

Abnormally terminates an environment.


Syntax
void okCleanup(okEnv Env);

Parameters
Env

An environment handle.


Comments

This function abnormally terminates an environment. It disconnects all outstanding database connections with the application and releases all run-time resources allocated by Env. This function aborts the last transaction, if still active.

The okEnvInfo structure has the following format:

struct okEnvInfo {

   okU4B StructSize;     /* caller fills in size of this structure */

   okU4B XactCount;      /* currently not implemented */

   okU4B MemoryUsed;     /* currently not implemented */

   okU4B MemoryFree;     /* currently not implemented */

   okU4B DescriptorsUsed; /* currently not implemented */

};

2.5.5 okGetEnvInfo

Gets information about the environment.


Syntax
okError okGetEnvInfo(okEnv Env, okEnvInfo_s *RetEnvInfo);

Parameters
Env

An environment handle.

RetEnvInfo

A buffer for returning environment information.

2.5.6 Environment Sample Program

The following code demonstrates the use of the environment procedures:

#define OK_CS_ASCII 1

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okEnvParameters_s EnvParams;  /* Env parameters */

okEnvInfo_s EnvInfo;  /* Env information */

okEnv  Env;  /* Env handle */

okError  e; /* for returned error code */

...


   memset((char *)&EnvParams, 0, sizeof(okEnvParameters_s));

   EnvParams.StructSize = sizeof(okEnvParameters_s);

   EnvParams.CharacterSet = OK_CS_ASCII;

   e = okInit(&EnvParams, &Env);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   (void)okFinal(Env); 

...

2.6 Data Source Name

There are four Data Source Name (DSN) functions that you can use. They are described in the following sections.

2.6.1 okCreateDsn

Creates a DSN.


Syntax

okError okCreateDsn(okName user, okName pub, okName path, okName dbName, ok1B drv);


Parameters
user

The database user name.

pub

The public part of the DSN name (see the example below).

path

The full path to the database file.

dbName

The name of the database file.

drv

A flag that indicates whether an embedded (native) driver or a client driver is used. This parameter can take two values: DRV_NATIVE and DRV_CLIENT.


Comments

okCreateDsn creates a new DSN section in the odbc.ini file and also includes the new entry in the registry.

It gets default volume ID and default data directory (if the path parameter is NULL) from the polite.ini file. If polite.ini does not have a default datadirectory, okCreateDsn gets it from the system environment or from the registry.

the default value for the volume ID is 64. If dbName is NULL, okCreateDsn will use the DSN name as the database file name.

The DSN name will be user_pub or pub if no user name is given (that is, if the user is NULL).

If the datadirectory does not exist, it will be created.


Example

okError e = okCreateDsn("yev","polite","d:\orant\oldb40", NULL,DRV_NATIVE);

The above statement will create the DSN named yev_polite with an ODBC native driver, the datadirectory D:\orant\oldb40\yev and the database file named yev_polite.odb.

2.6.2 okDeleteDsn

Deletes a DSN.


Syntax

okError okDeleteDsn(okName dsn);


Parameters
dsn

DSN name.


Comments

okDeleteDsn deletes the DSN section from the odbc.ini file and from the registry.

2.6.3 okSetDsnAttribute

Writes single attribute into a DSN section.


Syntax

okError okSetDsnAttribute(okName dsn, okName attributeName, okChar * value);


Parameters
dsn

DSN name.

attributeName

The name of the DSN attribute (such as, database, datadirectory, and so on).

value

The attribute value.


Comments

If dsn is not given (NULL), the default dsn name will be taken from polite.ini.

If dsn does not exist, the dsn section will be created, but the attributes will not be filled in automatically.

2.6.4 okGetDsnAttribute

Reads a single attribute from a DSN section.


Syntax

okError okGetDsnAttribute(okName dsn, okName attributeName, okSize valueBufferSize, char * valueBuffer);


Parameters
dsn

DSN name.

attributeName

The name of the DSN attribute.

valueBufferSize

The size of the buffer receiving the value.

valueBuffer

The buffer that receives the attribute value.


Comments

If no dsn name is given, the default dsn name will be taken from polite.ini.

2.7 Databases

A database is a collection of logically related objects. Before a database can store objects, it must be initialized (or formatted). During initialization, the underlying storage structures and storage allocation information are initialized on disk. In addition, the kernel creates system-maintained object groups to hold meta-objects it requires. After initializing the database, an application can create object groups for storing persistent objects. When the objects in a database are no longer needed, the application should delete the database to reclaim its storage space.

Before accessing objects in a database, the application must connect to the database. Connecting to the database involves either activating the database or setting up a communication link between the application (the client) and the server that manages the database.

Once connected, an application can access and update objects in the database in the context of transactions. When it no longer needs the objects in a database, the application can disconnect from the database.

A database connection can be established either inside or outside the context of a transaction. To ensure data integrity, however, a database should not be disconnected while a transaction is active.

2.7.1 Database Functions Compatibility Reference

This table lists the OKAPI database management functions.

Function Purpose Win32 Palm EPOC
okCreateDatabase   Creates a database. C C C
okDeleteDatabase   Deletes a database. C C C
okConnect   Establishes a connection to a database. C C C
okDisconnect   Breaks a connection to a database. C C C

2.7.2 okCreateDatabase

Creates a database.


Syntax
okError okCreateDatabase(okEnv Env, 

   okSize DatabaseNameLen, okName DatabaseNamePtr,

   const okDatabaseParameters_s *DatabaseParams);

Parameters
Env

An environment handle.

DatabaseNameLen

The length of the database name.

DatabaseNamePtr

A name for the new database.

DatabaseParams

Parameters for the creation of the database.


Comments

This function creates a database with the name DatabaseNamePtr. The underlying operating system or file system limits the length of the database name, since each database is mapped to a raw partition or file.

The okDatabaseParameters structure contains parameters for the new database. It has the following format:

typedef struct okDatabaseParameters okDatabaseParameters_s;

struct okDatabaseParameters {

   okU4B  StructSize;    /* caller fills in size of this structure */

   ok2B   VolumeID;      /* database volume ID */

   okU2B  ExtentSize;    /* optional number of pages to cluster */

   okU4B  DatabaseSize;  /* size of database in kilobytes */

   okSize LabelLen;      /* length of label for the database */

   okName LabelPtr;      /* pointer to label for the database */

   okU4B  Options;       /* currently unused */

   okU1B  CharacterSet;  /* character set */

   okU1B  _Padding[3];   /* not used */

};

2.7.3 okDeleteDatabase

Deletes a database.


Syntax
okError okDeleteDatabase(okEnv Env, 

   okSize DatabaseNameLen, okName DatabaseNamePtr);

Parameters
Env

An environment handle.

DatabaseNameLen

The length of the database name.

DatabaseNamePtr

The name of the database to delete.


Comments

This function removes the database with the name DatabaseNamePtr and releases all resources allocated to the database. Since the objects in a deleted database cannot be recovered, you should be sure that the objects in the database are no longer needed before deleting the database.

On the Palm platform you must disconnect from the database before deleting it. See "okDisconnect" for more information.

2.7.4 okConnect

Establishes a database connection.


Syntax
okError okConnect(okEnv Env, 

   okSize DatabaseNameLen, okName DatabaseNamePtr, 

   const okConnOpt_s *Options, okRef *RetDatabase);

Parameters
Env

An environment handle.

DatabaseNameLen

The length of the database name.

DatabaseNamePtr

The name of the database.

Options

Options for the database connection. Possible value:

  • OK_CONNECT_READ_ONLY: connects to the database in read-only mode.

RetDatabase

A buffer for returning a reference to a transient database object representing the connected database.


Comments

This function establishes a connection to the database with the name DatabaseNamePtr. It returns in RetDatabase a reference to a database object representing the connected database. An application must connect to the database before performing any operations on the objects in the database. Multiple okConnect calls to the same database by an application return the same database object.

2.7.5 okDisconnect

Breaks a database connection.


Syntax
okError okDisconnect(okEnv Env, okHandle Database);

Parameters
Env

An environment handle.

Database

A database handle.


Comments

This function breaks a connection to the database pointed to by Database. It flushes all objects in the database and releases all control data structures for maintaining the connection. You must invoke okDisconnect outside of a transaction.

2.7.6 Database Sample Program

The following code demonstrates the use of the database procedures:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okDatabaseParameters DatabaseParams;  /* database parameters */

okRef  Database;  /* reference to database object */

okError  e;  /* for returned error code */


...


   memset((char *)&DatabaseParams, 0, sizeof(okDatabaseParameters_s));

   DatabaseParams.StructSize = sizeof(okDatabaseParameters_s);

   e = okCreateDatabase(Env, sizeof("staff.odb"), "staff.odb",  &DatabaseParam);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okConnect(Env, sizeof("staff.odb"), "staff.odb", 0,  &Database);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okDisconnect(Env, Database);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okDeleteDatabase(Env, sizeof("staff.odb"), "staff.odb");

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.8 Schema

There is one object schema for each database. An object schema is similar to a class hierarchy in a programming language environment. A class has a unique name within a database and has zero or more attributes and methods. An attribute is similar to a column in a relational table or an instance variable in some programming languages. A method is a procedure or function that applies to individual instances of a class. Collectively, the attributes and methods of a class are called the properties of the class. A class can inherit properties from one or more classes. The class that inherits the properties is called a subclass, while the class from which the class inherits properties is called the superclass.

In the kernel, class objects represent classes, attribute objects represent attributes, and method objects represent methods. Collectively, the class, attribute, and method objects comprise the schema objects of a class. The kernel provides functions for creating and deleting classes and for locating schema objects by name.

To define a new class, you specify the attributes of the new class through the data structure okAttrDesc_s. You define methods by attaching a Java class to the kernel class.

The data structure for an attribute follows:

typedef struct okAttrDesc okAttrDesc_s;

struct okAttrDesc {

    okU4B       NameLen;        /* length of attribute name */

    okName      NamePtr;        /* pointer to attribute name */

    okU4B       DefinedInLen;   /* optional length of defined-in class name */

    okName      DefinedInPtr;   /* optional pointer to defined-in class name */

    okU4B       DomainLen;      /* length of name of domain class */

    okName      DomainPtr;      /* pointer to name of domain class */

    okU4B       Precision;      /* optional precision of attribute value */

    okU1B       SdtScale;       /* optional SDT scale */

    okU1B       SdtTypeCode;    /* optional SDT type code */

    okU1B       SdtSubtypeCode; /* optional SDT subtype code */

    okU1B       DefCollate;     /* optional default collating sequence */

    ok4B        Dimension;      /* number of data units */

    okU4B       DefaultValSize; /* optional size of default value */

    okByte      *DefaultValPtr; /* optional pointer to default value */

    okU4B       ExtensionCount; /* optional number of extension objects */

    okHandle    *ExtensionHandles; /* optional array of extension handles */

    okU4B       Options;        /* optional attribute options */

};   

The field NamePtr specifies the name of the attribute in the class. Generally, the value for DefinedInPtr is either NULL or the name of the new class. Both values indicate that the attribute is a locally defined attribute. For more complex applications, such as a schema designer, the caller may bypass the default inheritance mechanism and explicitly specify from which superclass an attribute is inherited. DomainPtr specifies the class (type) name of the attribute value. For example, if the type of an attribute is okU4B, its domain is the string "okU4B".

Use the fields Precision, SdtScale, SdtTypeCode, and SdtSubtypeCode to store additional type information of the attribute. For example, you can use them to store type information for SQL datatypes. The kernel does not interpret the semantics of these fields directly.


Note:

The prefix Sdt stands for Standard datatypes, which are extensions to SQL datatypes. These datatypes are defined to enable sharing of common datatypes among different languages, such as between C++ and SQL.

For uniformity, the kernel views every attribute as an array. The field Dimension specifies the number of elements in the attribute. The dimension of a scale attribute, for example, is always OK_SCALE (with a value of 1), and the dimension of a dynamic attribute is OK_DYNAMIC. The field Default allows the caller to maintain default information for the attribute as a string. However, the kernel does not interpret or use this information. The field ExtensionHandles allows the application to store additional meta-information in objects. The kernel manages these extension objects on behalf of the application. However, the kernel does not interpret the semantics of extension objects. Finally, you can use the Options field to specify the following additional status flag bits.

Flag Description
OK_PRIVATE_MEMBER Private member attribute
OK_PUBLIC_MEMBER Public member attribute
OK_PROTECTED_MEMBER Protected member attribute
OK_INHERITED_MEMBER Attribute inherited from a superclass
OK_COPIED_MEMBER Attribute inherited as a copy
OK_NULLABLE_ATTR Attribute that can take a NULL value
OK_RUNTIME_ATTR Runtime attribute with no persistent storage

2.8.1 Schema Functions Compatibility Reference

This table lists the OKAPI functions that manage the schema.

Function Purpose Win32 Palm EPOC
okCreateClass   Creates a new class in a database. C C C
okAttachJavaClass   Attaches a Java class to an Oracle Lite class. C N N
okDeleteClass   Deletes a class from a database. C C C
okDetachJavaClass   Detaches a Java class from an Oracle Lite class. C N N
okSetCallBacks   Specifies activator and deactivator functions for instances of a class. C X C
okFindClass   Finds a class object. C C C
okGetAttrCount   Returns the number of attributes in a class, excluding hidden attributes. C X C
okFindAttr   Finds an attribute object in a class. C C C
okFindMethod   Finds a method object in a class. C N N
okGetSuClasses   Returns the superclasses or subclasses of a class. C C C

2.8.2 okCreateClass

Creates a new class in a database.


Syntax
okError okCreateClass(okEnv Env, okHandle Database, 

   okSize ClassNameLen, okName ClassNamePtr, 

   okSize SuperclassCount, const okHandle Superclasses[],

   okSize AttrCount, const okAttrDesc_s AttrDescs[],

   okSize MethCount, const okMethDesc_s MethDescs[], 

   okU4B Options, okRef *RetClass);

Parameters
Env

An environment handle.

Database

A database object.

ClassNameLen

The length of a class name.

ClassNamePtr

Name of a class.

SuperclassCount

The number of superclasses from which to inherit.

Superclasses

An array of superclasses from which to inherit.

AttrCount

The number of attribute descriptions.

AttrDescs

An array of attribute de­scriptions of type okAttrDesc_s.

MethCount

The number of method descriptions. This parameter is always set to 0. It is currently not used.

MethDescs

An array of method de­scriptions of type okMethDesc_s. This parameter is always set to NULL. It is currently not used.

Options

Additional information for creating the class.

RetClass

The buffer for returning a class object.


Comments

This procedure creates a new class ClassNamePtr in a database represented by Database. The order of the attribute descriptions in the array AttrDescs determines the order of the corresponding attributes in the class. Currently, MethCount must be set to 0 and MethDescs must be set to NULL. The caller uses Options to pass in additional information about the class. The option OK_APP_DEF_INHERIT suppresses default class inheritance. If using this option, you should individually specify the properties that should be inherited in the attribute descriptions and method descriptions.


Caution:

The OK_APP_DEF_INHERIT option is intended for very specialized callers, such as C++ language bindings running on top of the kernel.

Each property of a class, inherited or not, is represented as a schema object, which you can look up by name in the context of the class.

2.8.3 okAttachJavaClass

Attaches a Java class to an Oracle Lite class.


Syntax
okError okAttachJavaClass(okEnv Env, okHandle Database,

   okHandle ClassRef, okU4B ClassDef, okSize JavaClsOrSrcNameLen,

   okName JavaClsOrSrcName, okSize JavaClsOrSrcPthLen, 

   okName JavaClsOrSrcPth, okSize ConsArgCount, 

   okHandle *ConsArgs);

Parameters
Env

An environment handle.

Database

A database object.

ClassRef

A class object.

ClassDef

Class definition. Possible values include:

  • CLS_IN_POLITE: specifies that the class is already in the Oracle Lite database (it is attached to another class prior to this call).

  • CLS_CLS_FILE: specifies that the file in the path JavaClsOrSrcPth is a class file. The kernel attaches the class file to the Oracle Lite class and stores the class file in the database.

  • CLS_SRC_FILE: specifies that the file in the path JavaClsOrSrcPth is a source file. The kernel compiles the Java class using the Java compiler specified in the class path set for the system.

JavaClsOrSrcNameLen

The length of the Java class or source file name.

JavaClsOrSrcName

Name of the Java class. For fully qualified names that include package names, you must use dots to separate the name components.

JavaClsOrSrcPthLen

The length of the path of the Java source or class file.

JavaClsOrSrcPth

The directory path location of the Java class or source file.

ConsArgCount

The number of arguments in the constructor used to create a Java instance.

ConsArgs

An array of attribute handles to pass as arguments to the class constructor.


Comments

This function attaches a Java class to an Oracle Lite class. After the function attaches the Java class, the methods of the Java class become the methods of the Oracle Lite class. Static methods of the Java class become class methods of the Oracle Lite class, while non-static methods become instance methods. Use the ClassDef argument to specify the class location.

When attaching a Java class, you can specify the constructor that the kernel should use to create instances of the class. The arguments ConsArgCount and ConsArgs specify the number of arguments the constructor takes and which attributes of the object should be passed to the constructor. Before an instance method executes (when invoked by the okExecMeth method described in section "Method Invocation"), the kernel constructs a Java object corresponding to the Oracle Lite object using the constructor that takes the attribute values passed in the ConsArgs argument.

2.8.4 okDeleteClass

Deletes a class from a database.


Syntax
okError okDeleteClass(okEnv Env, okHandle Class);

Parameters
Env

An environment handle.

Class

A class object.


Comments

This procedure deletes the class represented by the object Class. It deletes all the schema objects associated with the class. On the Palm platform, inheriting class objects are not automatically removed when you delete the super class. To prevent problems associated with dangling instances, every instance of a class should be deleted before you delete the class.

2.8.5 okDetachJavaClass

Detaches a Java class from an Oracle Lite class.


Syntax
okError okDetachJavaClass(okEnv Env, okHandle Database, 

    okHandle ClassRef, okBool DeleteClassBody);

Parameters
Env

An environment handle.

Database

A database object.

ClassRef

A class object.

DeleteClassBody

A boolean flag to indicate whether to delete the Java class body from the database.


Comments

This procedure detaches the Java class from the Oracle Lite class specified by Class. If DeleteClassBody is TRUE, okDetachJavaClass deletes the class from the database.

2.8.6 okSetCallBacks

Specifies runtime activator and deactivator functions for instances of a class.


Syntax
okError okSetCallBacks(okEnv Env, okHandle Class,

   okPtr ActivatorData, okPtr DeactivatorData, 

   okCallBack Activator, okCallBack Deactivator);

Parameters
Env

An environment handle.

Class

A class object.

ActivatorData

A pointer to data to pass to the activator function.

DeactivatorData

A pointer to data to pass to the deactivator function.

Activator

An activator function for instances of the class.

Deactivator

A deactivator function for instances of the class.


Comments

This procedure allows you to specify runtime activator and deactivator functions for instances of the class Class. Oracle Lite invokes the function Activator, if not NULL, when creating an instance of the class or bringing the instance into cache from disk. Oracle Lite invokes the function Deactivator, if not NULL, when deleting or swapping out an instance.

The kernel does not permanently store these functions in the class object. They must be set at runtime whenever a class object is brought in from disk.

The functions Activator and Deactivator each take two pointers as arguments. The first argument is a pointer given (as either ActivatorData or DeactivatorData) when okSetCallBacks is called. The second points to the body of a Class object.

2.8.7 okFindClass

Finds a class object in a database.


Syntax
okError okFindClass(okEnv Env, okHandle Database, 

   okSize ClassNameLen, okName ClassNamePtr, okRef *RetClass);

Parameters
Env

An environment handle.

Database

A database object.

ClassNameLen

The length of a class name.

ClassNamePtr

The name of a class.

RetClass

A buffer for returning a class object.


Comments

This procedure finds the class object with the name ClassNamePtr in database Database and returns a reference to the class object in RetClass. If it does not find the class in the database, okFindClass returns a NULL reference. Returning NULL is not considered an error (that is, it does not return an error code).

2.8.8 okFindAttr

Finds an attribute object in a class.


Syntax
okError okFindAttr(okEnv Env, okHandle Class, 

    okSize AttrNameLen, okName AttrNamePtr, okHandle DefinedIn, 

    okRef *RetObj, okU4B *RetPos);

Parameters
Env

An environment handle.

Class

A class object.

AttrNameLen

The length of an attribute name.

AttrNamePtr

The name of an attribute.

DefinedIn

The class from which an attribute or a method is inherited.

RetObj

An optional buffer for returning the attribute or method object.

RetPos

An optional buffer for returning the position of the attribute or method.


Comments

This function finds the attribute object for the attribute AttrName in the class represented by Class. If DefinedIn is NULL, it defaults to Class. The first attribute in a class is at position zero.

2.8.9 okGetAttrCount

Returns the number of attributes in a class, excluding hidden attributes.


Syntax
okError okGetAttrCount(okEnv Env, okHandle Class, okU4B *RetCount)

Parameters
Env

An environment handle.

Class

A class object.

RetCount

An optional buffer for returning the attribute count.


Comments

This function should be used in place of DAR_COUNT(class->Attributes) which does not exclude hidden attributes. This function will be available for Win32 in a future release.

2.8.10 okFindMethod

Finds a method object in a class.


Syntax
okError okFindMethod(okEnv Env, okHandle dbH, 

   okHandle clsR, okU4B MethType, okSize MethNameLen, 

   okName MethName, okSize MethSigLen, okName MethSig,

   okHandle *retMeth);

Parameters
Env

An environment handle.

dbH

A database object.

clsR

A class object.

MethType

The type of Java method to find. Possible values:

  • OK_CLASS_METHOD: to find a class method.

  • OK_INSTANCE_METHOD: to find an instance method.

MethNameLen

The length of the method name.

MethName

The method name.

MethSigLen

The length of the method signature as a string. If the method lookup should be based only on the name, set this value to 0.

MethSig

A Java Native Interface (JNI) style method signature string.

retMeth

An optional buffer for returning the attribute or method object.


Comments

This procedure finds the method object for the method MethName in the class represented by Class. The MethType argument specifies the type of method to find. Possible values are OK_CLASS_METHOD for class method and OK_INSTANCE_METHOD for instance method. Since more than one method may exist with the same name, the arguments MethSigLen and MethSig permit the caller to specify the method signature. You must specify the method signature as a string using the JNI format. For example, for the method String M (int, Date), the JNI signature is:

 "(ILjava/sql/Date;)Ljava/lang/String;"

2.8.11 okGetSuClasses

Returns the superclasses or subclasses of a class.


Syntax
okError okGetSuClasses(okEnv Env, okHandle Class, 

   okBool isSuper, okBool isImmediate, okArray *RetList);

Parameters
Env

An environment handle.

Class

A class object.

isSuper

A Boolean flag which is TRUE if the function should return superclasses, and FALSE if it should return subclasses.

isImmediate

A Boolean flag which is TRUE if the function should return all superclasses or subclasses, and FALSE if it should return only the immediate superclasses or subclasses.

RetList

An array for returning the results of the lookup.


Comments

This procedure returns the superclasses (when isSuper is TRUE) or subclasses (when isSuper is FALSE) of the class Class in RetList.

2.8.12 Schema Sample Program

The following code demonstrates the schema procedures:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okError e;

okEnv Env;

okHandle Database;

okRef PersonRef, StudentRef, DeptRef, MethRef, NameAttr;

okArray AttrDescs;

okU4B NamePos;


...

   okAttrDesc_s DeptAttrs[] = {

      {sizeof("Name"), "Name", 0, NULL, sizeof("okChar"), "okChar",

       0, 0, 0, 0, 0, OK_DYNAMIC, 0, NULL, 0, NULL, 0},

      {sizeof("Students"), "Students", 0, NULL, 

      sizeof("Student_s"),

      "Student_s", 0, 0, 0, 0, 0, OK_DYNAMIC, 0, NULL, 0, NULL, 0},

      {sizeof("Staff"), "Staff", 0, NULL, sizeof("Professor_s"), 

      "Professor_s", 0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0}

   };


   okAttrDesc_s PersonAttrs[] = {

      {sizeof("ID"), "ID", 0, NULL, sizeof("okU4B"), "okU4B",

      0,0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0},

      {sizeof("Name"), "Name", 0, NULL, sizeof("okChar"), "okChar",

      0, 0, 0, 0, 0, OK_DYNAMIC, 0, NULL, 0, NULL, 0},

      {sizeof("Age"), "Age", 0, NULL, sizeof("okU2B"), "okU2B",

      0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0},

      {sizeof("Gender"), "Gender", 0, NULL, sizeof("okU2B"), "okU2B",

      0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0},

      {sizeof("Phone"), "Phone", 0, NULL, sizeof("okU1B"), "okU1B",

      0, 0, 0, 0, 0, 8, 0, NULL, 0, NULL, 0},

      {sizeof("Picture"), "Picture", 0, NULL, sizeof("okLong"), 

      "okLong", 0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0}

   };

   okAttrDesc_s StudentAttrs[] = {

      {sizeof("Dept"), "Dept", 0, NULL, sizeof("Dept_s"), "Dept_s",

      0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0},

      {sizeof("Clock"), "Clock", 0, NULL, sizeof("okU4B"), "okU4B",

      0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL,OK_RUNTIME_ATTR}

   };

   okAttrDesc_s ProfessorAttrs[] = {

      {sizeof("Dept"), "Dept", 0, NULL, sizeof("Dept_s"), "Dept_s",

      0, 0, 0, 0, 0, OK_SCALAR, 0, NULL, 0, NULL, 0}

   };


   #include <time.h>

   /* constructor function for run-time attr of "Student" */

   void GetTime(okPtr NotUsed, okObjData *StudentP)

      {((Student_s *)StudentP)->Clock = (okU4B)clock(); }


   e = okConnect(Env, 9, "staff.odb", FALSE, &Database);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* create class "Dept_s" */

   e = okCreateClass(Env, Database, sizeof("Dept_s"), "Dept_s",

       0, NULL, sizeof(DeptAttrs)/sizeof(okAttrDesc_s), 

       DeptAttrs, 0, NULL, 0, NULL); 

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* creates class "Person_s" */

   e = okCreateClass(Env, Database, sizeof("Person_s"),"Person_s", 

      0, NULL, sizeof(PersonAttrs)/sizeof(okAttrDesc_s),

      PersonAttrs, 0, NULL, 0, &PersonRef);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* creates class "Student_s" */

   e = okCreateClass(Env, Database, sizeof("Student_s"),

      "Student_s", 1, &PersonRef,

      sizeof(StudentAttrs)/sizeof(okAttrDesc_s), StudentAttrs,

      0, NULL, 0, &StudentRef);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* creates class "Professor_s" */

   e = okCreateClass(Env, Database, sizeof("Professor_s"),

      "Professor_s", 1, &PersonRef,

      sizeof(ProfessorAttrs)/sizeof(okAttrDesc_s),

      ProfessorAttrs, 0, NULL, 0, NULL);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* set constructor for run-time attr */

   e = okSetCallBacks(Env, StudentRef, NULL, NULL, GetTime, NULL);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okFindClass(Env, Database, sizeof("Dept_s"), 

      "Dept_s", &DeptRef);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okFindAttr(Env, DeptRef, sizeof("Name"), 

      "Name", NULL, &NameAttr, &NamePos);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* attach a Java class to class Dept_s. Assume that the Java 

   source file is c:\JavaSrc\DeptMeths. Use the Name

   attribute of Dept_s as a constructor argument */


   e = okAttachJavaClass(Env, Database, DeptRef, CLS_SRC_FILE,

      9,"DeptMeths",10,

      "c:\\JavaSrc",1,&NameAttr);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* find the void HireStaff(int ID, String Name) method */

   e = okFindMethod(Env, Database, DeptRef, OK_INSTANCE_METHOD,

      9, "HireStaff", 22, 

      "(ILjava/lang/String;)V", &MethRef);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   {okArrayBaseClasses;

    e = okGetSuClasses(Env, StudentRef, 

      TRUE, TRUE, &BaseClasses);

    if (OK_IS_ERROR(e)) { /* error handling */ }

   }   


   e = okDeleteClass(Env, PersonRef);

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.9 Groups

Object grouping is a powerful mechanism for placing and manipulating a collection of objects in a database. Specifically, object grouping supports:

You create object groups in the context of a database. A group object represents each group. The group object has a name that must be unique within the database. When creating a new object, you can specify the group to which the object belongs. If you do not specify a group, the object is stored in a system-maintained default group, which can be changed by the application.

2.9.1 Group Functions Compatibility Reference

This table lists the OKAPI functions that manage groups.

Function Purpose Win32 Palm EPOC
okCreateGroup   Creates an object group in a database. C C C
okDeleteGroup   Deletes an object group from a database. C C C
okFindGroup   Finds an object group in a database. C C C
okSetDefaultGroup   Changes the current default object group maintained by the kernel. C C C

2.9.2 okCreateGroup

Creates a group object within a database.


Syntax
okError okCreateGroup(okEnv Env, okHandle Database, 

   okSize GroupNameLen, okName GroupNamePtr, 

   okU4B Options, okRef *RetGroup);

Parameters
Env

An environment handle.

Database

A database object.

GroupNameLen

The length of a group name.

GroupNamePtr

The name of a new group.

Options

Options for group op­eration.

RetGroup

A buffer for returning a group object.


Comments

This function creates an object group with the name GroupNamePtr in the database Database. It returns a reference to the new group object in RetGroup. Options is currently not used.

2.9.3 okDeleteGroup

Deletes a group object from a database.


Syntax
okError okDeleteGroup(okEnv Env, okHandle Group);

Parameters
Env

An environment handle.

Group

The group object to delete.


Comments

This function deletes the group specified by Group. This function deletes the group object as well as all objects in the group.

2.9.4 okFindGroup

Finds a group object in a database.


Syntax
okError okFindGroup(okEnv Env, okHandle Database, 

   okSize GroupNameLen, okName GroupNamePtr, 

   okRef *RetGroup);

Parameters
Env

An environment handle.

Database

A database object.

GroupNameLen

The length of the group name.

GroupNamePtr

The name of the new group.

RetGroup

A buffer for returning a group object.


Comments

This function finds the group with the name GroupNamePtr in the database Database. If it does not find a group with the given name, the function returns a NULL reference. Returning NULL is not considered an error (that is, no error code is returned).

2.9.5 okSetDefaultGroup

Changes the current default object group maintained by the kernel.


Syntax
okError okSetDefaultGroup(okEnv Env, okHandle NewDefGroup, 

      okRef *RetOldDefGroup);

Parameters
Env

An environment handle.

NewDefGroup

The new default group.

RetOldDefGroup

A buffer for returning the group.


Comments

This function changes the current default object group to the group specified by NewDefGroup. If NewDefGroup is NULL, the default group reverts to the system-defined default group. If RetOldRefGroup is not NULL, this function makes NewDefGroup the default object group and returns a reference to the prior default group object in RetOldDefGroup.

2.9.6 Group Sample Program

The following code demonstrates the use of the group procedures:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okRef FacultyRef;

okRef PrevDefGroup;

okError e;


...


   e = okCreateGroup(Env, Database, sizeof("Faculty"), 

      "Faculty", 0, &FacultyRef);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okFindGroup(Env, Database, sizeof("Faculty"), 

      "Faculty", &FacultyRef);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   

   e = okSetDefaultGroup(Env, FacultyRef, &PrevDefGroup);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   

   e = okDeleteGroup(Env, FacultyRef);

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.10 Objects

The object is the fundamental unit in the kernel. All persistent entities are modeled and stored as objects. Several important meta-objects contain information about an object. First, since an object is an instantiation of a class, its class object defines the object. Second, since all objects are stored in a group, the group object determines the persistent storage for the object. The third meta-object associated with an object is its database object, which can be indirectly derived from its group object.

2.10.1 Object Functions Compatibility Reference

This table lists the OKAPI object functions.

Function Purpose Win32 Palm EPOC
okCreateObj   Creates a new instance of a class. C C C
okDeleteObj   Deletes an object from a database. C C C
okFixObj   Fixes (or pins) an object in cache and returns a pointer to the object's body. C C C
okUnfixObj   Unfixes an object. C C C
okPrepForUpdate   Prepares an object for updating. C C C
okSetShortLock   Acquires a lock on an object. C P C
okCreateObjs   Creates an array of objects from a single class. C C C
okDeleteObjs   Deletes an array of objects. C C C
okSetShortLocks   Locks an array of objects. C P C
okPrepForUpdates   Prepares an array of fixed objects for updating. C NI C
okFixObjs   Fixes an array of objects and returns pointers to the body of each object. C C C
okUnfixObjs   Unfixes an array of objects. C C C

2.10.2 okCreateObj

Creates a new instance of a class.


Syntax
okError okCreateObj(okEnv Env, okHandle Group, 

   okHandle Class, const void *InitialVal, okU4B Options, 

   void *RetHandle);

Parameters
Env

An environment handle.

Group

The group in which to create the object.

Class

The class object to instantiate.

InitialVal

The value of an object.

Options

Options for object creation.

RetHandle

A buffer for returning the pointer to the body of the object.


Comments

This function creates a new instance of the class Class in the group Group. If Group is NULL, the kernel assigns the object to a system-maintained default group. Optionally, you can pass an initial value for the object in Val. The option OK_FIX_OBJ (passed in Options) specifies that the newly created object should be fixed in cache upon return from the function.

2.10.3 okDeleteObj

Deletes an object from a database.


Syntax
okError okDeleteObj(okEnv Env, okHandle Obj);

Parameters
Env

An environment handle.

Obj

The object to delete.


Comments

This function removes the object obj from cache and reclaims its storage space on disk. After the function deletes the object, the kernel rejects attempts to access the object.

2.10.4 okFixObj

Fixes (or pins) an object in cache and returns a pointer to the object's body.


Syntax
okError okFixObj(okEnv Env, okHandle Obj, 

   okLock LockMode, void *RetObjData);

Parameters
Env

An environment handle.

Obj

The object to fix.

LockMode

The type of lock to apply to the object. OKAPI defines the following lock modes:

Lock Description
OK_NOLOCK No lock
OK_ISLOCK Intent shared lock
OK_IXLOCK Intent exclusive lock
OK_SIXLOCK Shared-intent exclusive lock
OK_SLOCK Shared (read) lock
OK_XLOCK Exclusive (write) lock
OK_ULOCK Update lock
RetObjData

A buffer for returning the pointer to the body of the object.


Comments

This function fixes (or pins) the object Obj in cache and returns a pointer to the object's body in RetObjData. The kernel guarantees that a fixed object is not swapped out. In other words, the memory pointer returned in RetObjData is valid as long as the object remains fixed. Mode specifies the lock mode to apply to the object. In single-user mode, all lock requests are ignored.

This function allows you to directly manipulate the contents of an object. By casting the returned memory pointer to the appropriate pointer type, you can access the object body in the same manner as a C structure. Accessing data through a memory pointer instead of through an OKAPI function may be efficient, but it can cause problems with the integrity of the data. If changing attribute values through a memory pointer, you must notify the kernel of your changes by calling okPrepForUpdate, or by passing the appropriate flag to okUnfixObj.

To avoid memory leaks, you should call okUnfixObj after calling okFixObj to unfix the object once it is no longer needed. However, if you are certain that the cache is large enough to hold the objects that the application directly or indirectly handles in a transaction, you can reduce function call overhead by leaving the objects fixed. At the end of each transaction, the kernel automatically unfixes all objects in the cache.

2.10.5 okUnfixObj

Unfixes an object.


Syntax
okError okUnfixObj(okEnv Env, 

   okHandle Obj, okBool isUpdated);

Parameters
Env

An environment handle.

Obj

The object handle.

isUpdated

A Boolean flag indicating whether the object has been updated while fixed in cache.


Comments

This function unfixes (or un-pins) the object Obj and, if isUpdated is TRUE, marks the object as dirty. An object can be fixed when created or through a call to okFixObj. After an object is unfixed, the kernel may swap the object out at any time. Usually, it swaps out the object when the cache is nearly full.

Since an object may be fixed several times (such as when different modules of an application fix the object), the kernel keeps a fix count for each object in the cache. The kernel increments the counter whenever the application fixes the object, and decrements the counter whenever the application unfixes the object with okUnfixObj. The kernel does not swap out an object unless its fix count is zero.

2.10.6 okPrepForUpdate

Prepares an object for updating.


Syntax
okError okPrepForUpdate(okEnv Env, okHandle Obj);

Parameters
Env

An environment handle.

Obj

The object handle.


Comments

This function prepares an object Obj for updating. okPrepForUpdate acquires a write (or exclusive) lock on the object and marks the object as dirty. This function applies to objects that are fixed in cache. It makes no attempt to swap in an object if the object is not in the cache, and it does not increase the fix count of the object.

2.10.7 okSetShortLock

Acquires a lock on an object.


Syntax
okError okSetShortLock(okEnv Env, okHandle Obj, 

   okLock LockMode);

Parameters
Env

An environment handle.

Obj

The object handle.

LockMode

The mode of the lock to apply to the object. OKAPI defines the following lock modes:

Lock Description
OK_NOLOCK No lock
OK_ISLOCK Intent shared lock
OK_IXLOCK Intent exclusive lock
OK_SIXLOCK Shared-intent exclusive lock
OK_SLOCK Shared (read) lock
OK_XLOCK Exclusive (write) lock
OK_ULOCK Update lock

Comments

This function acquires a lock of the mode LockMode on the object Obj. If the lock request conflicts with an outstanding lock on the same object, the caller is blocked until the lock request is granted or rejected due to deadlock or time-out. In single-user mode, all lock requests are ignored.

2.10.8 okCreateObjs

Creates an array of objects from a single class.


Syntax
okError okCreateObjs(okEnv Env, okHandle Group, okHandle Class, const okByte    

   *InitialVal, okU4B Options, okU4B ObjCount, okHandle RetHandles[]);

Parameters
Env

An environment handle.

Group

Group in which to create objects.

Class

Class object to instantiate.

InitialVal

The value of objects.

Options

Options for object creation.

ObjCount

Number of objects to create.

RetHandles

A buffer for returning the pointers to the bodies of the objects.


Comments

This function creates a specified number (ObjCount) of new instances of the class Class in the group Group. If Group is NULL, the kernel assigns the objects to a system-maintained default group. Optionally, you can pass an initial value for the objects in InitialVal. The option OK_FIX_OBJ (passed in Options) specifies that the newly created objects should be fixed in cache upon return from the function.

2.10.9 okDeleteObjs

Deletes an array of objects from a database.


Syntax
okError okDeleteObjs(okEnv Env, okU4B ObjCount, okHandle Objs[]);

Parameters
Env

An environment handle.

ObjCount

Number of objects to delete.

Objs

Handles of objects to delete.


Comments

This function removes the objects Objs[] from cache and reclaims the storage space on disk. After the function deletes the objects, the kernel rejects attempts to access the objects.

2.10.10 okSetShortLocks

Acquires a lock on an array of objects.


Syntax
okError okSetShortLocks(okEnv Env, okU4B ObjCount, okHandle Objs[], 

   okLock LockMode);

Parameters
Env

An environment handle.

ObjCount

The number of objects to lock.

Objs

The handles of objects to lock.

LockMode

The mode of the lock to apply to the objects. OKAPI defines the following lock modes:

Lock Description
OK_NOLOCK No lock
OK_ISLOCK Intent shared lock
OK_IXLOCK Intent exclusive lock
OK_SIXLOCK Shared-intent exclusive lock
OK_SLOCK Shared (read) lock
OK_XLOCK Exclusive (write) lock
OK_ULOCK Update lock

Comments

This function acquires a lock of the mode LockMode on the objects Objs[]. If the lock request conflicts with an outstanding lock on the same object, the caller is blocked until the lock request is granted or rejected due to deadlock or time-out. In single-user mode, all lock requests are ignored.

2.10.11 okPrepForUpdates

Prepares an array of objects for updating.


Syntax
okError okPrepForUpdates(okEnv Env, okU4B ObjCount, okHandle Objs[]);

Parameters
Env

An environment handle.

ObjCount

The number of objects to prepare.

Objs

The handles of the objects to prepare.


Comments

This function prepares an array of objects Objs for updating. okPrepForUpdates acquires a write (or exclusive) lock on the objects and marks the objects as dirty. This function applies to objects that are fixed in cache. It makes no attempt to swap in objects if the objects are not in the cache, and it does not increase the fix count of the objects.

2.10.12 okFixObjs

Fixes (or pins) an array of objects in cache and returns a pointer to the body of each object.


Syntax
okError okFixObjs(okEnv Env, okU4B ObjCount, okHandle Objs[], 

   okLock LockMode, void *RetObjData[]);

Parameters
Env

An environment handle.

ObjCount

The number of objects to fix.

Objs

The objects to fix.

LockMode

The type of lock to apply to the object. OKAPI defines the following lock modes:

Lock Description
OK_NOLOCK No lock
OK_ISLOCK Intent shared lock
OK_IXLOCK Intent exclusive lock
OK_SIXLOCK Shared-intent exclusive lock
OK_SLOCK Shared (read) lock
OK_XLOCK Exclusive (write) lock
OK_ULOCK Update lock
RetObjData

A buffer for returning the pointer to the body of each object.


Comments

This function fixes (or pins) the objects Objs[] in cache and returns a pointer to the body of each object in RetObjData. The kernel guarantees that fixed objects are not swapped out. In other words, the memory pointer returned in RetObjData is valid as long as the objects remain fixed. Mode specifies the lock mode to apply to the objects. In single-user mode, all lock requests are ignored.

This function allows you to directly manipulate the contents of objects. By casting the returned memory pointer to the appropriate pointer type, you can access the object body in the same manner as a C structure. Accessing data through a memory pointer instead of through an OKAPI function may be efficient, but it can cause problems with the integrity of the data. If changing attribute values through a memory pointer, you must notify the kernel of your changes by calling okPrepForUpdates, or by passing the appropriate flag to okUnfixObjs.

To avoid memory leaks, you should call okUnfixObjs after calling okFixObjs to unfix the objects once they are no longer needed. However, if you are certain that the cache is large enough to hold the objects that the application directly or indirectly handles in a transaction, you can reduce function call overhead by leaving the objects fixed. At the end of each transaction, the kernel automatically unfixes all objects in the cache.

2.10.13 okUnfixObjs

Unfixes an array of objects.


Syntax
okError okUnfixObjs(okEnv Env, okU4B ObjCount,

   okHandle Objs[], okBool isUpdated);

Parameters
Env

An environment handle.

ObjCount

The number of objects to be unfixed.

Objs

The objects to unfix.

isUpdated

A Boolean flag indicating whether the objects have been updated while fixed in cache.


Comments

This function unfixes (or un-pins) the objects Objs[] and, if isUpdated is TRUE, marks the objects as dirty. A group of objects can be fixed when created or through a call to okFixObjs. After the objects are unfixed, the kernel may swap the objects out at any time. Usually, it swaps out the objects when the cache is nearly full.

Since an object may be fixed several times (such as when different modules of an application fix the object), the kernel keeps a fix count for each object in the cache. The kernel increments the counter whenever the application fixes the object, and decrements the counter whenever the application unfixes the object with okUnfixObj or OkUnfixObjs. The kernel does not swap out an object unless its fix count is zero.

2.10.14 Object Sample Program

The following code demonstrates the use of object functions:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okEnv       Env;

okHandle    Database, Object;

okRef  Group, Class, ObjRef;

okObjData  ClassObj;

okError  e;


...


   /* assume Env and Database are set up properly */

   e = okFindGroup(Env, Database, sizeof("Faculty"), 

      "Faculty", &Group);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okFindClass(Env, Database, sizeof("Professor_s"),  "Professor_s", 

      &Class);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* fix the class object then release it */

   e = okFixObj(Env, Class, OK_NOLOCK, (okObjData *)&ClassObj);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okUnfixObj(Env, (okHandle)ClassObj, FALSE);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* create a new "Professor_s" object in "Faculty" group */

   e = okCreateObj(Env, Group, Class, NULL, OK_FIX_OBJ, &Object);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* set an exclusive lock on the "Dept_s" object */

   e = okSetShortLock(Env, Object, OK_XLOCK);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* release the new object then delete it */

   e = okUnfixObj(Env, (okHandle)Object, FALSE);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okDeleteObj(Env, Object);

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.11 Object Information and Control

You can use the object information and control functions to query and control objects.

2.11.1 Object Information and Control Functions Compatibility Reference

This table lists the OKAPI object information and control functions.

Function Purpose Win32 Palm EPOC
okGetObjRef   Acquires a reference to an object. C C C
okIsInstanceOf   Determines whether an object is an instance of a particular class. C C C
okGetObjInfo   Returns information about an object. C C C
okIsObjEqual   Determines whether two object handles are equal. C C C
okCtrlObjs   Enables the caller to apply control operations to an array of objects. C P C
okGetObjRefs   Gets an array of handles to objects. C NI C
okFindRefs   Finds an array of object references, given an array of object IDs. C C C

2.11.2 okGetObjRef

Acquires a reference to an object.


Syntax
okError okGetObjRef(okEnv Env, okHandle Obj, 

   okRef *RetRef);

Parameters
Env

An environment handle.

Obj

The object handle.

RetRef

A buffer for returning the reference to the object.


Comments

This function returns a reference in RetRef to the object Obj. An object handle can be an object reference or a memory pointer to the body of the object. If Obj is already an object reference, the function returns the object reference in RetRef. If Obj is a memory pointer to the object body, okGetObjRef locates or creates an object reference to the object and returns it in RetRef.

2.11.3 okIsInstanceOf

Determines whether an object is an instance of a particular class.


Syntax
okError okIsInstanceOf(okEnv Env, okHandle Obj, 

   okHandle Class, okBool isImmediate, okBool *RetResult);

Parameters
Env

An environment handle.

Obj

The object handle.

Class

The class object.

isImmediate

A Boolean flag indicating whether to consider superclasses.

RetResult

A Boolean value to indicate whether the object is an instance of a class.


Comments

This function determines whether the object Obj is an instance of the class Class. It returns a Boolean result (either TRUE or FALSE) in RetResult. The argument isImmediate specifies whether the function should consider inheritance. If isImmediate is TRUE, the function returns TRUE only if Class is the class object of Obj. If isImmediate is FALSE, the function returns TRUE if Class is the class object or a superclass object of Obj.

On the Palm platform, if Class is the superclass object of obj, the function will return FALSE regardless of whether isImmediate is TRUE or FALSE.

2.11.4 okGetObjInfo

Returns information about an object.


Syntax
okError okGetObjInfo(okEnv Env, okHandle Obj,

   okOID_s *RetObjID, okRef *RetDatabase, 

   okRef *RetGroup, okRef *RetClass, okObjInfo_s *RetInfo);

Parameters
Env

An environment handle.

Obj

The object handle.

RetObjID

An optional buffer for returning the object ID.

RetDatabase

An optional buffer for returning the database of an object.

RetGroup

An optional buffer for returning the group of an object.

RetClass

An optional buffer for returning the class of an object.

RetInfo

A buffer for returning object information.


Comments

This function returns information regarding an object Obj, including its unique ID (in RetObjID) and associated meta-objects. The meta-objects include the database object (in RefDatabase), group object (in RetGroup), and class object (in RetClass). RetInfo provides the version and lock mode of the object in the following format:

typedef struct {

    okU4B Version;

    wsLockMode LockMode;

} okObjInfo_s;

2.11.5 okIsObjEqual

Determines whether two object handles are equal.


Syntax
okError okIsObjEqual(okEnv Env, 

   okHandle Obj1, okHandle Obj2, okBool *RetResult);

Parameters
Env

An environment handle.

Obj1

The first object handle to compare.

Obj2

The second object handle to compare.

RetResult

A Boolean value to indicate the result.


Comments

This function determines whether two object handles, Obj1 and Obj2, are equal. It considers two object handles equal only if they point to the same object.

2.11.6 okCtrlObjs

Applies control operations to an array of objects.


Syntax
okError okCtrlObjs(okEnv Env, okU4B ObjCount,

   const okHandle ObjHandles[], okU4B Actions);

Parameters
Env

An environment handle.

ObjCount

The number of objects in the control operation.

ObjHandles

The objects in the control operation.

Actions

The operations to apply to the objects. Actions can be any combination of the following:

  • OK_FLUSH_OBJECT: Writes a copy of the object to disk if marked dirty.

  • OK_FREE_OBJECT: Releases the memory space used by the body of an object. This option invalidates all direct memory pointers to the object body, but does not invalidate object references to the object. This is intended for use when the application no longer needs the object.

  • OK_FREE_DESC: Releases the descriptor of an object and the body of the object if it exists in the cache.


    Important:

    Use of the OK_FREE_DESC option invalidates all existing object references, including those embedded in other cached objects. This is intended for use when memory is extremely scarce and the space used by object descriptors needs to be reclaimed.


Comments

This function allows you to apply the control operations specified in Actions to an array of objects ObjHandles.

2.11.7 okGetObjRefs

Gets references to an array of objects.


Syntax
okError okGetObjRef(okEnv Env, okU4B ObjCount, okHandle Objs[], 

   okRef *RetRefs[]);

Parameters
Env

An environment handle.

ObjCount

The number of objects.

Objs

The object handle.

RetRefs

A buffer for returning the references to the objects.


Comments

This function returns references in RetRefs[] to the objects in Objs[]. An object handle can be an object reference or a memory pointer to the body of the object. If Objs[] is already an object reference, the function returns the object reference in RetRefs[]. If Objs[] is a memory pointer to the object bodies, okGetObjRefs locates or creates object references to the objects and returns them in RetRefs[].

2.11.8 okFindRefs

Finds references to an array of objects, given an array of object IDs.


Syntax
ok Error okFindRefs,( okEnv Env, okU4B ObjCount, okOID_s ObjIDs[], 

   okRef RetObjRefs[]);

Parameters
Env

An environment handle.

ObjCount

The number of objects.

ObjIDs

The Object IDs.

RetObjRefs

A buffer for returning the references to the objects.


Comments

This function returns references in RetObjRefs[] to the objects identified in ObjIDs[].

2.11.9 Object Information and Control Sample Program

The following code demonstrates the use of the object information and control procedures:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okRef Group, Class, ObjRef;

okHandle Object, NewObj;

Professor_s *Advisor;

okBool isa, isEqual;

okError e;


...


   e = okFindGroup(Env, Database, 

      sizeof("Faculty"), "Faculty", &Group);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okFindClass(Env, Database, 

      sizeof("Professor_s"), "Professor_s", &Class);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* create a new "Professor_s" object in "Faculty" group */

   e = okCreateObj(Env, Group, Class, NULL, OK_FIX_OBJ, &Object);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okGetObjRef(Env, Object, &ObjRef);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okIsInstanceOf(Env, Object, Class, TRUE, &isa);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   { 

      okOID_sObjID;

      okRefDatabase, Group, Class;


      e = okGetObjInfo(Env, Object, &ObjID, &Database, &Group, 

         &Class, NULL);

      if (OK_IS_ERROR(e)) { /* error handling */ }

   }


   e = okCtrlObjs(Env, 1, &Object, OK_FLUSH_OBJECT|OK_FREE_DESC);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* create a new "Dept_s" object */

   e = okCreateObj(Env, Group, Class, NULL, OK_FIX_OBJ, &NewObj);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okIsObjEqual(Env, Object, NewObj, &isEqual);

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.12 Attribute Values

An object's attribute values collectively represent the object's internal state. As explained in the section "Schema", each attribute in a class is represented by an attribute object. The attribute object defines the attribute.

Functions that access or update attribute values also require attribute objects as parameters. For example, to execute an update operation or a search, you must provide a value for the update or for the search predicate. OKAPI provides the following structure to represent attribute values:

typedef struct okAttrVal_s { /* for holding attribute value */

   okU4B   BufSize;    /* size of buffer in bytes */

   okByte  *BufPtr;    /* pointer to buffer */

   ok4B    Indicator;  /* data size if >= 0, NULL if < 0 */

} okAttrVal_s;

BufPtr points to a buffer for holding an attribute value. BufSize specifies the size of the buffer in bytes. Indicator contains the actual number of bytes in the attribute value. A negative number in Indicator indicates a NULL value (an undefined or not initialized value).

2.12.1 Dynamic Array Attributes

When manipulating an attribute that is a dynamic array, you should set BufSize to sizeof(okArray), and BufPtr should point to a variable of type okArray. When getting an attribute, the kernel sets the Indicator field to the actual size of the returned data. If the Indicator is negative, the attribute has a null value.

Optionally, you can set a flag within the attrVal.BufSize which indicates to OKAPI that a dynamic array should be created. You can then pass the string inside of attrVal.BuffPtr as follows:

attrVal.BufSize = attrVal.Indicator = OK_NEW_ARRAY | strlen((char *) attrVal.BufPtr);


Note:

The flag, OK_NEW_ARRAY, is not supported or required on the Palm platform.

2.12.2 Attribute Value Functions Compatibility Reference

This table lists the OKAPI functions that manage attribute values.

Function Purpose Win32 Palm EPOC
okGetAttrVal   Extracts the value of an attribute and returns either a copy of the value or a direct memory pointer to the attribute value in the object body. C C C
okSetAttrVal   Updates the value of an attribute. C C C
okGetAttrValAt   Extracts the value of the attribute at a specified position and returns either a copy of the value or a direct memory pointer to the attribute value in the object body. C C C
okSetAttrValAt   Updates the value of an attribute at a specified position. C C C
okSetAttrVals   Updates the values of multiple attributes listed by their names. C C C
okSetAttrValsAt   Updates the value of attributes at a specified position. C C C

2.12.3 okGetAttrVal

Extracts the value of an attribute and returns either a copy of the value or a direct memory pointer to the attribute value in the object body.


Syntax
okError okGetAttrVal(okEnv Env, okHandle Obj, 

   okHandle AttrObj, okBool toCopy, okAttrVal_s *RetVal);

Parameters
Env

An environment handle.

Obj

An object handle.

AttrObj

An object representing the attribute to access.

toCopy

A Boolean flag:

TRUE - On Win32 and EPOC platforms it returns a pointer to a pointer to the attribute. On the Palm platform it returns a pointer directly to the attribute.

FALSE - On Win32 and EPOC it returns a pointer directly to the attribute. The Palm platform does not support a FALSE value for this parameter.

RetVal

A buffer for returning a value.


Comments

This function extracts the value of the attribute AttrObj and returns in RetVal either a copy of the value (if toCopy is TRUE) or a direct memory pointer to the attribute value in the object body (if toCopy is FALSE). If toCopy is FALSE, the function fixes the object in cache to ensure the validity of the returned memory pointer. As a result, you must explicitly unfix the object by calling okUnfixObj. You do not need to fix the object before calling this function.

If the size of the attribute is small, you should make a copy of the attribute value, and avoid the function call overhead of explicitly unfixing the object. However, if the attribute is large, such as a dynamic or an embedded array, it may be more efficient to obtain a memory pointer to the object and access the attribute value directly.

If the attribute contains a dynamic array, okGetAttrVal returns a pointer to the dynamic array. The type of the attribute value returned is okArray, which is a generic pointer type. The elements in the array are not returned in the buffer provided by RetVal. If toCopy is TRUE, okGetAttrVal creates a new copy of the dynamic array. You must explicitly release the copy of the array using okDeleteArray when it is no longer needed. However, you do not need to unfix the object itself. If toCopy is FALSE, you do not need to release the dynamic array the function returns, but you must unfix its containing object explicitly using okUnfixObj.

2.12.4 okSetAttrVal

Updates the value of an attribute.


Syntax
okError okSetAttrVal(okEnv Env, okHandle Obj, 

      okHandle AttrObj, const okAttrVal_s *NewVal);

Parameters
Env

An environment handle.

Obj

An object handle.

AttrObj

An object representing the attribute to access.

NewVal

A buffer containing a new value.


Comments

This function updates the value of the attribute identified by AttrObj in object Obj with the new value specified in NewVal. You do not need to fix the object before calling this function. If the attribute contains a dynamic array, the NewVal buffer should point to a dynamic array. This function releases the original dynamic array in the attribute, creates the new dynamic array in NewVal, and places the new array in the object.

2.12.5 okGetAttrValAt

Extracts the value of the attribute at a specified position and returns either a copy of the value or a direct memory pointer to the attribute value in the object body.


Syntax
okError okGetAttrValAt(okEnv Env, okHandle Obj, 

      okU4B Position, okBool toCopy, okAttrVal_s *RetVal);

Parameters
Env

An environment handle.

Obj

An object handle.

Position

The position of the attribute to access.

toCopy

A Boolean flag:

TRUE - On Win32 and EPOC platforms it returns a pointer to a pointer to the attribute. On the Palm platform it returns a pointer directly to the attribute.

FALSE - On Win32 and EPOC it returns a pointer directly to the attribute. The Palm platform does not support a FALSE value for this parameter.

RetVal

A buffer for returning a value.


Comments

This function extracts the value of the attribute at position Position. It returns (in RetVal) either a copy of the value if toCopy is TRUE, or a direct memory pointer to the attribute value in the object body if toCopy is FALSE. If toCopy is FALSE, the object is implicitly fixed, which guarantees the validity of the returned memory pointer. Consequently, the caller must unfix the object with okUnfixObj. The object does not need to be fixed before a call to this function. See the preceding discussion of okGetAttrVal for more information.

2.12.6 okSetAttrValAt

Updates the value of an attribute at a specified position.


Syntax
okError okSetAttrValAt(okEnv Env, okHandle Obj, 

   okU4B Position, const okAttrVal_s *NewVal);

Parameters
Env

An environment handle.

Obj

An object handle.

Position

The position of the attribute to access.

NewVal

A buffer containing a new value.


Comments

This function updates the value of the attribute at position Position in object Obj with the new value specified in NewVal. The object does not need to be fixed before a call to this function. See the preceding discussion of okSetAttrVals for more information.

2.12.7 okSetAttrVals

Updates the values of multiple attributes listed by their names.


Syntax
okError okSetAttrVals(okEnv Env, okHandle ObjH, okSize AttrCnt,

      okHandle AttrH, const okAttrVal_s *NewVal);

Parameters
Env

An environment handle.

ObjH

An object handle.

AttrCnt

The number of attributes to update.

AttrH

The handles of the attributes to update.

NewVal

A buffer containing the new values.


Comments

This function updates the value of the attributes identified by AttrObj in object ObjH with the new value specified in NewVal. You do not need to fix the object before calling this function. If the attribute contains a dynamic array, the NewVal buffer should point to a dynamic array. This function releases the original dynamic array in the attribute, creates the new dynamic array in NewVal, and places the new array in the object.

2.12.8 okSetAttrValsAt

Updates the value of attributes at a specified position.


Syntax
okError okSetAttrValsAt(okEnv Env, okHandle ObjH, okSize AttrPosCnt, 

   okU4B *Position, const okAttrVal_s *NewVal);

Parameters
Env

An environment handle.

ObjH

An object handle.

AttrPosCnt

The number of attributes to update.

Position

A buffer containing the positions of the attributes to access.

NewVal

A buffer containing the new values.


Comments

This function updates the value of the attribute at position Position in object ObjH with the new value specified in NewVal. The object does not need to be fixed before a call to this function. See the preceding discussion of okSetAttrVal for more information.

2.12.9 Attribute Value Sample Program

The following code demonstrates the use of the attribute value procedures:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"

#define DEPT_NAME "Computer Science"


okEnv Env;

okHandle  Object, Group;

okRef AttrRef, AttrRefs[2];

okArray DeptName;

okAttrVal_s Value, AttrVals[2];

okError  e;

okU4B AttrPoss[2];


...


   /* assume class "Dept_s" is in Class, find its attribute "Name" */

   e = okFindAttr(Env, Class, 

      sizeof("Name"), "Name", NULL, &AttrRef, NULL);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   

   /* create a new "Dept_s" object */

   e = okCreateObj(Env, Group, Class, NULL, OK_FIX_OBJ, &Object);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   

   /* prepare the string "Computer Science" in Value */

   e = okCreateArray(Env, &DeptName,

      sizeof(DEPT_NAME), DEPT_NAME);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   Value.BufSize = Value.Indicator = sizeof(okArray);

   Value.BufPtr = (okByte *)&DeptName;

   

   /* a silly sequence just to illustrate usage ... */

   e = okSetAttrVal(Env, Object, AttrRef, &Value);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okGetAttrVal(Env, Object, AttrRef, FALSE, &Value);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okSetAttrValAt(Env, Object, 0, &Value);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okGetAttrValAt(Env, Object, 0, FALSE, &Value);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okGetAttrVals (Env, Object, Obj, 2, AttrRefs, AttrVals);

   e = okGetAttrVals At (Env, Object, 2, AttrPoss, AttrVals);

...

2.13 Method Invocation

The method invocation function, okExecMeth, invokes methods in a class.

2.13.1 Method Invocation Function Compatibility Reference

This table shows the platform compatibility of okExecMeth.

Function Purpose Win32 Palm EPOC
okExecMeth   Executes a method. X X X

2.13.2 okExecMeth

Executes a method.


Syntax
okError okExecMeth (okEnv env, okHandle dbH, okHandle meth, 

   okHandle obj,  okSize argValCount, okAttrVal_s  *argVals, 

   okU1B  *outFlag, okAttrVal_s  *result );

Parameters
Env

An environment handle.

dbH

Handle to the database.

meth

The method object to execute.

obj

The handle to the object containing the method to execute.

argValCount

The number of arguments passed to the method.

argVals

An array of arguments passed to the method.

outFlag

A flag indicating IN/OUT parameters.

result

The result of the method.


Comments

This function executes the method meth. If the method is a class method, obj can be NULL. Otherwise, obj is a valid object handle. ArgValCount is the number of argument values provided in the argVals array. argVals is an array of okAttrVal_s structures, each containing an argument value. OutFlag is an array of ArgValCount bytes. A non-zero value in the n-th byte means that the n-th argument is an IN/OUT argument. Set outFlag to NULL if the method does not use IN/OUT arguments. The corresponding Java type of an IN/OUT argument must be a mutable type. The kernel returns the result in the okAttrVal_s structure pointed to by result.

2.13.3 Method Invocation Sample Program

The following code demonstrates the use of the method invocation procedure:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


#define  DEPT_NAME "Computer Science"


...


   okAttrVal_s argVals[2], res;

   /* declare other variables here */

   /* find the void HireStaff(int ID, String Name) method */

   e = okFindMethod(Env, Database, DeptRef, OK_INSTANCE_METHOD,

      9, "HireStaff", 22, 

      "(ILjava/lang/String;)V", &MethRef);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   /* use iterator to get a department object into variable dept */

   /* initialize argVal2[0] and argVals[1] here */

   e = okExecMeth(Env, Database, MethRef, dept, 2, argVals,NULL,&res);


...

2.14 Iterators (Queries)

The kernel supports queries against database objects using iterators. An iterator is similar to a scan in a relational database system. The scope of each query typically covers all instances of a class in an object group. Optionally, you can expand the scope of a query to include instances of all subclasses as well. The iterator only returns instances that satisfy the specified search conditions. A cursor associated with each iterator points to the current object in the iteration.

A query starts when you create the iterator and ends when you delete the iterator. During its lifetime, the iterator retrieves qualified objects one at a time from the database. The current object in the iteration establishes the cursor position, which can be saved or changed by the application. For each iteration, the application can set the cursor movement properties with one of the following:


Search Conditions

The kernel supports queries based on search conditions in the form <Connective, Attribute, Operator, Value>, where:

Use the data structure okSearchCond_s to represent a search condition.

typedef struct okSearchCond okSearchCond_s;

struct okSearchCond {

    okU4B       AttrPos;        /* relative position of attribute */

    okU1B       Operator;       /* operator to compare with */

    okU1B       Connective;     /* how to connect to next condition */

    okU1B       Collate;        /* optional collating sequence */

    okU1B       _Padding;       /* not used */

    okAttrVal_s AttrVal;        /* value to compare against */

};

Passing Search Conditions

To issue a query, you pass the search conditions in a dynamic array of okSearchCond_s to the kernel. The logical AND operator takes precedence over the logical OR operator during the evaluation of search conditions. In other words, when both the AND and OR operators appear, the kernel interprets the search conditions as a set of disjunctive (OR) expressions, each of which is composed of conjunctive (AND) terms.

2.14.1 Iterator Functions Compatibility Reference

This table lists the OKAPI iterator functions.

Function Purpose Win32 Palm EPOC
okCreateIterator   Prepares a query against instances of a class and returns a transient iterator object. C C C
okDeleteIterator   Terminates a query associated with an iterator. C C C
okIterate   Advances the cursor associated with an iterator and returns a pointer to the body of the current object. C C C
okGetCursor   Returns the current cursor position of an iterator. C C C
okSetCursor   Sets the current cursor position of an iterator. C C C

2.14.2 okCreateIterator

Prepares a query against instances of a class and returns a transient iterator object.


Syntax
okError okCreateIterator(okEnv Env, okHandle Group,

   okHandle Class, okBool isImmediate, okU4B CondCount,

   const okSearchCond_s SearchConds[], Reserved, 

   okU4B UpdAttrCount, const okU4B UpdAttrPos[], 

   okIterator *RetIter);

Parameters
Env

An environment handle.

Group

A group object.

Class

A class object.

isImmediate

A Boolean flag which is TRUE if subclasses should be included in the query, and FALSE if subclasses should not be included.

CondCount

The number of search conditions.

SearchConds

An array of search conditions of type okSearchCond_s.

Reserved

Reserved parameter. No value required.

UpdAttrCount

The number of attributes to update.

UpdAttrPos

The array of positions of the attributes the caller intends to update in the qualified instances.

RetIter

A buffer for returning an iterator.


Comments

This function prepares a query against instances of the class Class in the object group Group. It returns a transient iterator object in RetIter. UpdAttrPos enables the kernel to avoid picking an access path whose scanning order may be affected by the updates.

2.14.3 okDeleteIterator

Terminates a query associated with an iterator.


Syntax
okError okDeleteIterator(okEnv Env, okIterator Iter);

Parameters
Env

An environment handle.

Iter

An iterator.


Comments

This function releases all system resources allocated to the iterator, including the iterator object.

2.14.4 okIterate

Advances the cursor associated with an iterator and returns a pointer to the body of the current object.


Syntax
okError okIterate(okEnv Env, okIterator Iter, 

   okU4B Action, okObjData *RetObj);

Parameters
Env

An environment handle.

Iter

An iterator.

Action

Specifies the direction in which the cursor should move:

  • OK_FIRST: move the cursor to the first qualified object.

  • OK_LAST: move the cursor to the last qualified object.

  • OK_NEXT: move the cursor to the next qualified object.

  • OK_PRIOR: move the cursor to the prior qualified object.

RetObj

A buffer for returning a pointer to the object body.


Comments

This function advances the cursor associated with an iterator and returns (in RetObj) a pointer to the body of the current object. The kernel fixes the object returned by the function and automatically unfixes it when the cursor is moved. okIterate returns NULL in RetObj if:

  • The direction is OK_NEXT and the iterator reaches the end of the scan.

  • The direction is OK_PRIOR and the iterator reaches the beginning of the scan.

Neither event returns an error code.

2.14.5 okGetCursor

Returns the current cursor position of an iterator.


Syntax
okError okGetCursor(okEnv Env, okIterator Iter, 

   okCursor *RetCursor);

Parameters
Env

An environment handle.

Iter

An iterator.

RetCursor

A buffer for returning the cursor.


Comments

This function returns in RetCursor the current cursor position of an iterator. A cursor returned by okGetCursor is a transient object. You can use the returned cursor to alter the cursor position of Iter.

After calling okSetCursor, the user must call okIterate to get the reference to the object. For example:

okSetCursor (env, iterHandle, &RetCursor);

okIterate (env, iterHandle, OK_PRIOR, &foundRef);

okIterate (env, iterHandle, OK_NEXT, &foundRef);

2.14.6 okSetCursor

Changes the current cursor position of an iterator.


Syntax
okError okSetCursor(okEnv Env, okIterator Iter,

   okCursor Cursor);

Parameters
Env

An environment handle.

Iter

An iterator.

Cursor

The new cursor position.


Comments

This function changes the current cursor position of an iterator to that specified by Cursor, which you can obtain with okGetCursor. All cursors associated with an iterator are automatically deleted when okDeleteIterator deletes the iterator object. After calling okSetCursor, the user must call okIterate to get the reference of the object.

2.14.7 Iterator Sample Program

The following code demonstrates the use of the iterator procedures:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okEnv Env;

okHandle Database;

okRef  Group, Class;

okIterator  Itor;

okCursor  Cursor;

Professor_S *Advisor;

okError  e;

okU4B  MinID = 101;

okU2B  MaxAge = 50;


...


   okSearchCond_s Cond[2] = { /* ID >= 101 && Age < 50 */

      {0, OK_GE, OK_AND, 0, 0,{sizeof(okU4B), 

        (unsigned char *)&MinID,sizeof(okU4B)}},

      {2, OK_LT, OK_AND, 0, 0,{sizeof(okU2B), 

        (unsigned char *)&MaxAge,sizeof(okU2B)}}

   };


   e = okFindGroup(Env, Database, sizeof("Faculty"), 

      "Faculty", &Group);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okFindClass(Env, Database, sizeof("Professor_s"),  

      "Professor_s", &Class);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okCreateIterator(Env, Group, Class, TRUE, 2, Cond, 

      0, 0, NULL, &Itor);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okIterate(Env, Itor, OK_NEXT, (okObjData *)&Advisor);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okGetCursor(Env, Itor, &Cursor);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okSetCursor(Env, Itor, Cursor);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okDeleteIterator(Env, Itor);

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.15 Indexes

To speed up query processing, the kernel supports indexes on instances of a class in an object group. The query optimizer in the kernel automatically picks an efficient access path when you create an iterator (that is, when you issue a query). The kernel maintains the index as objects are updated. The kernel currently supports only B-tree indexes.

You can obtain information about existing indexes using the okNextIndex function. okNextIndex returns information in the following data structure.

typedef struct {

   okU2B IdxType;

   okU2B IndexNo;

   okU2B Options;

   okArray AttrPos; /* Will be created/resized as necessary */

   /* Used internally for iteration */

   ok2B PrevIdx;

   okU4B ClassNo;

   okPtr Conx;

} okIdxInfo_s;

2.15.1 Index Functions Compatibility Reference

This table lists the OKAPI index management functions.

Function Purpose Win32 Palm EPOC
okCreateIndex   Creates an index on a set of attributes. C C C
okDeleteIndex   Deletes an index. C C C
okGetIndexInfo   Returns index information. C N C
okNextIndex   Returns the next index for a given group and class. C N C

2.15.2 okCreateIndex

Creates an index on a set of attributes.


Syntax
okError okCreateIndex(okEnv Env, okHandle Group,

   okHandle Class, okU4B NumAttrs, okU4B AttrPos[],

   okU2B IndexType, okU2B Options, okU2B *RetIndexNo);

Parameters
Env

An environment handle.

Group

A group object.

Class

A class object.

NumAttrs

The number of attributes on which the index is created.

AttrPos

The position of the attributes on which the index is created. Starts at 0.

IndexType

The type of index to create. Currently OK_BTREE, for a B-tree index, is the only supported value for this parameter.

Options

Additional options for index creation.

RetIndexNo

A buffer for returning the number of the new index.


Comments

This function creates an index on a set of attributes indicated by AttrPos. It creates the index on instances of Class in the object group Group. Options specifies key constraints on each constructed index. Valid key constraints include:

  • OK_UNIQUE_KEY: key values must be unique and NULL values are allowed.

  • OK_PRIMARY_KEY: key values must be unique and NULL values are not allowed.

After creating the index, the kernel automatically maintains the index whenever objects are created, updated, or deleted. If the specified index already exists, okCreateIndex does nothing. An error code is not returned.

2.15.3 okDeleteIndex

Deletes an index.


Syntax
okError okDeleteIndex(okEnv Env, okHandle Group, 

   okHandle Class, okU4B IndexNo, okU2B IndexType);

Parameters
Env

An environment handle.

Group

A group object.

Class

A class object.

IndexNo

The index number or attribute position.

IndexType

The type of index to delete. Currently OK_BTREE (for a b-tree index) is the only supported value for this parameter.


Comments

This function deletes the specified index. The arguments Group, Class, and IndexNo identify the index to delete. If the index is a multi-attribute index, IndexNo must be the index number returned by okCreateIndex. If the index is a single-attribute index, IndexNo can be the attribute position. If the index does not exist, okDeleteIndex does nothing. An error code is not returned.

2.15.4 okGetIndexInfo

Returns information pertaining to an index.


Syntax
okError okGetIndexInfo(okEnv Env, okHandle Group, 

   okHandle Class, okU4B AttrPos, okU2B IndexType, 

   okU2B *RetInfo);

Parameters
Env

An environment handle.

Group

A group object.

Class

A class object.

AttrPos

The index number or attribute position.

IndexType

The type of index on which to return information. Currently OK_BTREE (for a b-tree index) is the only supported value for this parameter.

RetInfo

The buffer for returning index information.


Comments

This function returns information in RetInfo pertaining to the index at attribute position AttrPos of Class instances in the group Group.

The returned bit map, which is placed in RefInfo, uses the following bit fields:

  • OK_INDEX_EXISTS: the index exists; if the index does not exist, the return value is zero.

  • OK_UNIQUE_KEY: key values must be unique and NULL values are allowed.

  • OK_PRIMARY_KEY: key values must be unique and NULL values are not allowed.

If you are getting an index on four attributes, for example:

attrpos[]={0,1,2,3}

You can call okGetIndexInfo on attribute 0 to return the index information. Calling okGetIndexInfo on any other attribute will return a value of 0.

2.15.5 okNextIndex

Returns the next index for a given group and class.


Syntax
okError okNextIndex(okEnv Env, okHandle Group, 

   okHandle Class, okIdxInfo_s *Info);

Parameters
Env

An environment handle.

Group

A group object.

Class

A class object.

Info

The index number or attribute position.


Comments

This function returns in Info the next index in the specified group and class. The first call should set the Group argument to the appropriate group and the Info.AttrPos array to NULL. Subsequent calls should set the group to NULL. After retrieving the information for all the indexes, you should delete the Info.AttrPos array. okError returns TRUE if the an index exists, and FALSE if no index exists.

2.15.6 Index Sample Program

The following code demonstrates the use of the index procedures:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okRef  Group, Class;

okU2B  IndexType;

okError  e;


...


   e = okFindGroup(Env, Database, sizeof("Faculty"), 

      "Faculty", &Group);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okFindClass(Env, Database, sizeof("Professor_s"),  "Professor_s",

      &Class);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* create a B-Tree type of index on attribute ID */

   e = okCreateIndex(Env, Group, Class, 0, OK_BTREE,  OK_UNIQUE_KEY);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okGetIndexInfo(Env, Group, Class, 0, &IndexType);

   if (!(RetInfo & OK_INDEX_EXISTS) { /* error handling */ }


   e = okDeleteIndex(Env, Group, Class, 0, OK_BTREE);

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.16 Object Naming

Object naming allows you to register a symbolic name for an object. After registering the object, you can look it up efficiently by name. You can assign any object a name, regardless of the object's class. Each database has its own name space organized as a hierarchy, which makes the names easier to manage.

As in the UNIX file system, directory objects implement the name hierarchy in a database. A root directory object describes the top-level objects in the name hierarchy. Each intermediate node in the hierarchy is a directory object that contains names and object references to objects at the next level in the sub-tree. The leaf nodes of the hierarchy are the named objects. When you create a new directory object and assign it a name within the hierarchy, a sub-hierarchy in a name space is created.

An object name is a character string that references an object relative to a directory object. You form the object name by concatenating the local names of all the directory objects, from the root to the target object, with the local name of the object. Components in an object name are separated by the backslash delimiter (\). The system-created root directory object is represented by a backslash (\).

The mechanism behind object naming is similar to "soft links" in the UNIX file system. The following rules apply to object naming:

2.16.1 Object Naming Functions Compatibility Reference

This table lists the OKAPI functions that manage object names.

Function Purpose Win32 Palm EPOC
okCreateName   Creates a name for an object. C C C
okDeleteName   Deletes an object name. C C C
okFindObj   Finds an object name. C C C

2.16.2 okCreateName

Creates a name for an object.


Syntax
okError okCreateName(okEnv Env, okHandle Directory, 

   okSize ObjNameLen, okName ObjNamePtr, okHandle Obj);

Parameters
Env

An environment handle.

Directory

A directory object.

ObjNameLen

The length of an object name.

ObjNamePtr

A name for an object.

Obj

An object.


Comments

This function creates a name for the object Obj, relative to the directory object Directory. ObjNamePtr must be a NULL-terminated string. It cannot be empty. Instead of specifying the root directory object in a database, the caller can specify the database object. You can use the database object interchangeably with the root directory object in the Directory parameter for all object naming functions.

If you are using a one-level naming system, you need only to use the database reference for the Directory parameter value.

If you are using a multi-level naming system, you must create directory objects for each level. To create a directory object, use NULL as the obj parameter value and use the directory object for the Directory parameter value.

2.16.3 okDeleteName

Deletes an object name.


Syntax
okError okDeleteName(okEnv Env, okHandle Directory, 

   okSize ObjNameLen, okName ObjNamePtr);

Parameters
Env

An environment handle.

Directory

A directory object.

ObjNameLen

The length of an object name.

ObjNamePtr

A name for an object.


Comments

This function deletes the object name ObjNamePtr relative to the directory object Directory from the name hierarchy in the database. Instead of specifying the root directory object in a database, the caller can specify the database object. You can use the database object interchangeably with the root directory object in the Directory parameter for all object naming functions.

2.16.4 okFindObj

Finds an object name.


Syntax
okError okFindObj(okEnv Env, okHandle Directory, 

   okSize ObjNameLen, okName ObjNamePtr, 

   okRef *RetObj, okBool *isDirectory);

Parameters
Env

An environment handle.

Directory

A directory object.

ObjNameLen

The length of an object name.

ObjNamePtr

A name for an object.

RetObj

A buffer for returning the object reference.

isDirectory

A buffer for returning a Boolean flag which is TRUE if the object found is a directory object.


Comments

This function locates the object with the name specified by ObjNamePtr relative to Directory. The function returns a reference to the object, if found, in RetObj. If the object cannot be found, the function returns a NULL reference in RetObj. This is not considered an error. A Boolean flag returned in isDirectory indicates whether the object found is a directory object. Instead of specifying the root directory object in a database, the caller can specify the database object. You can use the database object interchangeably with the root directory object in the Directory parameter for all object naming functions.

2.16.5 Object Naming Sample Program

The following code demonstrates the use of the object naming procedures:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okRef  Group, Class;

Professor_s *Chairman;

okError  e;


...


   /* create a directory called "EECS" */

   e = okCreateName(Env, Database /* to use root directory */,  sizeof("EECS"),

       "EECS", NULL);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* create a new professor object in Chairman */

   e = okFindGroup(Env, Database, 

      sizeof("Faculty"), "Faculty", &Group);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okFindClass(Env, Database, 

      sizeof("Professor_s"), "Professor_s", &Class);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okCreateObj(Env, Group, Class, 

      NULL, OK_FIX_OBJ, (okObjData *)&Chairman);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   /* assign "\EECS\CHAIRMAN" as name of a new "Professor_s" object */

   e = okCreateName(Env, Database, 

      sizeof("\\EECS\\CHAIRMAN"), "\\EECS\\CHAIRMAN", Chairman);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okFindObj(Env, Database, 

      sizeof("\\EECS\\CHAIRMAN"), "\\EECS\\CHAIRMAN", &Chairman, NULL);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okDeleteName(Env, Database, 

      sizeof("\\EECS\\CHAIRMAN"), "\\EECS\\CHAIRMAN");

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.17 Relationships

OKAPI supports relationships between objects of different classes or of the same class. Conceptually, each relationship between two objects consists of a pair of mutually dependent object references in an opposite direction. For example, a relationship between two objects A and B is represented by an object reference from A to B and a corresponding object reference from B to A.

OKAPI supports the following types of relationships:

Relationship Example
Referential integrity If object A references object B and B is deleted, A's reference to B is nullified. If a reference in A is changed to be a reference to object C, references in both B and C must be updated accordingly.
Cascaded deletion If object A is deleted, B is also deleted. If B references C in a cascaded deletion relationship, C is also deleted.
Restricted deletion A cannot be deleted if B still exists.
Sole ownership B can only be referenced by one object with which B has a sole-ownership relationship.

A relationship by default implies referential integrity. Note, however, that an object reference need not be part of a relationship.

A relationship between two classes is represented by two attributes, one from each of the participating classes. A relationship is represented in the form <FromClass, FromAttribute, ToClass, ToAttribute>.

2.17.1 Relationship Functions Compatibility Reference

This table lists the OKAPI functions that manage relationships.

Function Purpose Win32 Palm EPOC
okCreateRel   Establishes a relationship between two classes. C N C
okDeleteRel   Deletes a relationship. C N C

2.17.2 okCreateRel

Establishes a relationship between two classes.


Syntax
okError okCreateRel(okEnv Env, okHandle FromClass,

   okHandle FromAttr, okHandle ToClass, 

   okHandle ToAttr, okU4B Options);

Parameters
Env

An environment handle.

FromClass

The first class involved in the relationship.

FromAttr

The attribute in the first class of the relationship.

ToClass

The second class involved in the relationship.

ToAttr

The attribute in the second class of the relation­ship.

Options

The type of relationship. Allowable values:

  • OK_REF_INTEGRITY: for referential integrity.

  • OK_CASCADE_DEL: for cascading deletion.

  • OK_RESTRICT_DEL: for restricted deletion.

  • OK_ONE_PARENT: for one parent only.


Comments

This function establishes a relationship between classes FromClass and ToClass. The relationship is maintained through the attribute FromAttr in FromClass and the attribute ToAttr in ToClass. Note that the kernel can maintain a relationship properly only if all object updates are made through the okCreateObj, okDeleteObj, okSetAttrVal, and okSetAttrValAt functions. Specifically, a direct modification to an attribute which participates in a relationship may cause a violation of the constraints required of the relationship. This function only works on the class attributes.

After creating the relationship between two classes and instantiating objects from those classes, you must update each objects class attribute with the reference to the related object using okSetAttrVal or okSetAttrValAt. The related object's class attribute will be updated automatically.

2.17.3 okDeleteRel

Deletes a relationship.


Syntax
okError okDeleteRel(okEnv Env, okHandle FromClass, 

   okHandle FromAttr, okHandle ToClass, okHandle ToAttr);

Parameters
Env

An environment handle.

FromClass

The first class involved in the relationship.

FromAttr

The attribute in the first class of the relationship.

ToClass

The second class involved in the relationship.

ToAttr

The attribute in the second class of the relation­ship.


Comments

This function deletes a previously established relationship maintained in the attribute FromAttr in FromClass and the attribute ToAttr in ToClass.

2.17.4 Relationship Sample Program

The following code demonstrates the use of the relationship procedures:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okRef  DeptClass, StaffAttr, ProfClass, DeptAttr;

okError  e;


...


   e = okFindClass(Env, Database, sizeof("Dept_s"), "Dept_s",  &DeptClass);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okFindAttr(Env, DeptClass, sizeof("Staff"), "Staff", 

      NULL, &StaffAttr, NULL);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okFindClass(Env, Database, sizeof("Professor_s"),

      "Professor_s", &ProfClass);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okFindAttr(Env, ProfClass, sizeof("Dept"), "Dept", 

      NULL, &DeptAttr, NULL);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okCreateRel(Env, DeptClass, StaffAttr, ProfClass, DeptAttr,

      OK_REF_INTEGRITY);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okDeleteRel(Env, DeptClass, StaffAttr, ProfClass,  DeptAttr);

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.18 Binary Large Objects (BLOBs)

A binary large object (BLOB) stores unstructured binary data. BLOBS can be thought of as bitstreams with no character set semantics. BLOBs can store up to two gigabytes of binary data. They are intended for storing large pieces of raw data, such as a digitized image.

In general, a BLOB behaves the same way as other kernel objects. All BLOB objects belong to the class okLong. However, since a BLOB may be too big to fit into the address space of an application, OKAPI provides functions for retrieving and updating a portion of a BLOB object. In addition, OKAPI supplies functions for inquiring and changing the size of a BLOB object. Due to the size of a BLOB, the kernel does not allow a BLOB to be fixed in the cache.

2.18.1 BLOB Functions Compatibility Reference

This table lists the OKAPI functions that manage binary large objects (BLOBs).

Function Purpose Win32 Palm EPOC
okCreateBlob   Creates a BLOB. C C C
okDeleteBlob   Deletes a BLOB. C C C
okGetBlobVal   Retrieves a portion of a BLOB starting from a given byte offset. C C C
okSetBlobVal   Modifies a portion of a BLOB. C C C
okSetBlobSize   Adjusts the size of a BLOB. C C C
okGetBlobSize   Returns the size of a BLOB. C C C

2.18.2 okCreateBlob

Creates a BLOB.


Syntax
okError okCreateBlob(okEnv Env, okHandle Group, 

   okU4B Size, okU4B EstimatedSize, okRef *RetBlobObj);

Parameters
Env

An environment handle.

Group

A group object.

Size

The size of BLOB data in bytes.

EstimatedSize

The estimated size of the large object in bytes.

RetBlobObj

A buffer for returning a reference to a BLOB object.


Comments

This function creates a new BLOB in the object group Group and returns a reference to it in RetBlobObj. After creating the BLOB, the kernel guarantees that the object can grow to at least EstimatedSize bytes, subject to the actual amount of space available on disk. On the Palm Computing Platform, the maximum allowable size for a BLOB is 64K. The argument Size specifies the initial size of the BLOB object. A large object can grow to at least two megabytes, regardless of the value specified in EstimatedSize. The maximum size allowable for a large object is two gigabytes.

2.18.3 okDeleteBlob

Deletes a BLOB.


Syntax
okError okDeleteBlob(okEnv Env, okHandle BlobObj);

Parameters
Env

An environment handle.

BlobObj

A handle to the BLOB object to delete.


Comments

This function deletes a BLOB and releases the space used by the BLOB.

2.18.4 okGetBlobVal

Retrieves a portion of a BLOB starting from a given byte offset.


Syntax
okError okGetBlobVal(okEnv Env, okHandle BlobObj, 

   okU4B Offset, okU4B Size, okAttrVal_s *RetVal);

Parameters
Env

An environment handle.

BlobObj

A handle to the BLOB object to read from.

Offset

The byte offset into a BLOB object.

Size

The size of BLOB data in bytes.

RetVal

A buffer for returning the BLOB data in bytes.


Comments

This function retrieves a portion of a BLOB BlobObj, starting from a given byte offset. The value retrieved and its length are returned in the buffer and indicator specified in RetVal.

2.18.5 okSetBlobVal

Modifies a portion of a BLOB.


Syntax
okError okSetBlobVal(okEnv Env, okHandle BlobObj, 

   okU4B Offset, okU4B Size, okAttrVal_s *NewVal);

Parameters
Env

An environment handle.

BlobObj

A handle to the BLOB to modify.

Offset

The byte offset into a BLOB.

Size

The size of BLOB data in bytes.

NewVal

A buffer containing the new data value.


Comments

This function modifies a portion of a BLOB. The new value and its length are specified in NewVal. You must adjust the size of the BLOB to accommodate the modification prior to calling okSetBlobVal. For example, to append new data to the end of a large object, the size of the large object must first be adjusted with a call to okSetBlobSize to ensure that the new data fits into the large object.

2.18.6 okSetBlobSize

Adjusts the size of a BLOB.


Syntax
okError okSetBlobSize(okEnv Env, okHandle BlobObj,

   okU4B Size);

Parameters
Env

An environment handle.

BlobObj

A handle to the BLOB object to modify.

Size

The new size of the BLOB data in bytes.


Comments

This function adjusts the size of a BLOB. You can expand a large object by specifying a Size that is larger than the current size of BlobObj. Similarly, you can truncate a large object by specifying a Size that is smaller than the current size of BlobObj.

2.18.7 okGetBlobSize

Returns the size of a BLOB.


Syntax
okError okGetBlobSize(okEnv Env, okHandle BlobObj, 

   okU4B *RetSize);

Parameters
Env

An environment handle.

BlobObj

A handle to a BLOB object.

RetSize

The size of the BLOB in bytes.


Comments

This function returns in RetSize the current size in bytes of a BLOB BlobObj.

2.18.8 BLOB Sample Program

The following code demonstrates the use of the procedures that manage BLOBs:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


#define  BUF_SIZE 1024

#define  PICTURE_SIZE ((okU4B)10*BUF_SIZE)


okAttrVal_s BlobVal;

okByte Buffer[BUF_SIZE];

okRef Group, Blob;

okU4B BlobSize;

okError e;


...


   /* create a blob in a group */

   e = okCreateBlob(Env, Group, PICTURE_SIZE /* a hint */, &Blob);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okSetBlobSize(Env, Blob, sizeof(Buffer));

   if (OK_IS_ERROR(e)) { /* error handling */ }


   memset((void *)Buffer, 1, sizeof(Buffer));

   memset((void *)&BlobVal, 0, sizeof(BlobVal));

   BlobVal.BufSize = BlobVal.Indicator = BUF_SIZE;

   BlobVal.BufPtr = Buffer;

   e = okSetBlobVal(Env, Blob, 0, &BlobVal);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okGetBlobVal(Env, Blob, 0, BUF_SIZE, &BlobVal);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okGetBlobSize(Env, Blob, BUF_SIZE, &BlobSize);

   if (OK_IS_ERROR(e)) { /* error handling */ }


   e = okDeleteBlob(Env, Blob);

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.19 Transactions

A transaction is an integral unit of work consisting of a sequence of operations on one or more databases. All operations of a transaction either succeed or fail together. The effects of a committed transaction persist even if the system crashes. The kernel uses logging to support the properties of transactions.

2.19.1 Transaction Function Compatibility Reference

This table lists the OKAPI functions that manage transactions.

Function Purpose Win32 Palm EPOC
okTransact   Controls the outcome of the current transaction and optionally starts a new transaction. C C C
okSetIsolationLevel   Sets the current isolation level. C X C
okGetIsolationLevel   Gets the current isolation level. C X C

2.19.2 okTransact

Controls the outcome of the current transaction and optionally starts a new transaction.


Syntax
okError okTransact(okEnv Env, okU4B Action);

Parameters
Env

An environment handle.

Action

Action to perform.


Comments

This function controls the outcome of the current transaction and, optionally, starts a new transaction, as specified by the flags in the bit map Action. Action can take the following flags:

Flag Description
OK_BEGIN Begin a new transaction.
OK_COMMIT_END Commit the current transaction.
OK_ROLLBACK_END Roll back the current transaction.
OK_COMMIT_CONTINUE Commit and start a new transaction at the same level.
OK_ROLLBACK_CONTINUE Roll back and start a new transaction at the same level.
OK_CHECKPOINT_COMMIT Commit the current transaction but retain all locks.

For most OKAPI functions that affect objects in a database, a transaction is automatically started if one is not already active.

2.19.3 okSetIsolationLevel

Sets the current isolation level.


Syntax
okError okSetIsolationLevel (okEnv Env, okU2B Level);

Parameters
Env

An environment handle.

Level

Isolation level. Allowable values:

  • OK_TXN_SINGLE_USER: for single user.

  • OK_TXN_READ_COMMITTED: for read committed.

  • OK_TXN_REPEATABLE_READ: for repeatable read.

  • OK_TXN_SERIALIZABLE: for serializable.

2.19.4 okGetIsolationLevel

Gets the current isolation level.


Syntax
okError okGetIsolationLevel (okEnv Env, okU2B *Level);

Parameters
Env

An environment handle.

Level

A buffer for returning the isolation level.

2.19.5 Transaction Sample Program

The following code demonstrates the okTransact procedure:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okError  e;


...


   e = okTransact(Env, OK_BEGIN);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   /* do something ... */

   e = okTransact(Env, OK_COMMIT_END);

   if (OK_IS_ERROR(e)) { /* error handling */ }


...

2.20 Dynamic Arrays

OKAPI's dynamic array library (okArray) extends the ANSI C memory allocation library. Like memory space allocated by malloc, the memory for a dynamic array is allocated at runtime. You can cast a dynamic array to a pointer type to access an element of the array directly. The application should explicitly release the dynamic array when it is no longer needed to prevent memory leaks. A function in the dynamic array library (similar to realloc) adjusts the size of a dynamic array.

Unlike space allocated by malloc, a dynamic array carries information about the size of the array, which the caller can query. The actual space taken by the dynamic array (its capacity) may be larger than the size of the array. The dynamic array library uses a predictive allocation algorithm to reduce memory fragmentation caused by small incremental expansions of an array. In addition, the library includes functions for appending and copying dynamic arrays.

The following shows the correspondence between the ANSI C memory allocation library and the OKAPI dynamic array library.

ANSI C Function OKAPI Dynamic Array Function
malloc() okCreateArray()
free() okDeleteArray()
realloc() okSetArraySize()
((UserType *)p)[i] ((UserType *)p)[i]

You can make a dynamic array persistent by embedding it in a persistent object. As such, dynamic arrays form the basis for supporting variable-length attributes in persistent objects. Once a dynamic array becomes a part of a persistent object, the kernel automatically manages storage allocation and de-allocation for the array. For example, when fetching an object with a variable-length attribute from disk, the kernel allocates a dynamic array to hold the values of the variable-length attribute in memory. Similarly, it releases space occupied by a variable-length attribute when the object that contains the attributes is swapped out or deleted.

2.20.1 Dynamic Array Functions Compatibility Reference

This table lists the OKAPI functions that manage dynamic arrays.

Function Purpose Win32 Palm EPOC
okCreateArray   Creates a dynamic array. C C C
okDeleteArray   Deletes a dynamic array. C C C
okGetArraySize   Returns the size of a dynamic array. C C C
okSetArraySize   Sets the size of a dynamic array. C C C
okAppendArray   Appends data to the end of a dynamic array. C C C
okCopyArray   Creates a copy of a dynamic array. C C C
okCreateMDArray   Creates a new multi-dimensional array. C C C
okCopyMDArray   Copies a multi-dimensional array. C C C
okFreeMDArray   Frees a multi-dimensional array. C C C

2.20.2 okCreateArray

Creates a new dynamic array.


Syntax
okError okCreateArray (okEnv Env, okArray *RetArray, 

    okU4B Size, const okByte *Data);

Parameters
Env

An environment handle.

RetArray

A buffer for returning a pointer to the new dynamic array.

Size

The size of data in a dynamic array.

Data

Data value for a dynamic array.


Comments

This procedure creates an array and returns a pointer to the new array in RetArray. If Data is NULL, the initial value of the dynamic array is not initialized. This function assumes that RetArray does not point to a valid dynamic array before the call. To avoid a memory leak, the caller should release any valid dynamic array pointed to by RetArray before passing RetArray to okCreateArray. It is an error if RetArray is NULL.

Generally, you should call okCreateArray to initialize an array before performing any other operation on it. Alternatively, you can initialize it by setting it directly to NULL, as follows:

okArray anArray = NULL;

2.20.3 okDeleteArray

Deallocates the memory occupied by a dynamic array.


Syntax
okError okDeleteArray(okEnv Env, okArray *Array);

Parameters
Env

An environment handle.

Array

A pointer to a dynamic array.


Comments

This procedure deallocates the memory occupied by a dynamic array pointed to by Array. The function sets the value pointed to by Array to NULL. If Array is NULL prior to the call, okDeleteArray performs no action.

2.20.4 okGetArraySize

Retrieves the size, in bytes, of a dynamic array.


Syntax
okError okGetArraySize(okEnv Env, const okArray *Array, 

   okU4B *RetSize);

Parameters
Env

An environment handle.

Array

A pointer to a dynamic array.

RetSize

A buffer for returning the size of a dynamic array.


Comments

This procedure retrieves the size in bytes of a dynamic array pointed to by Array. It returns 0 if Array is NULL or if Array points to a NULL pointer.

2.20.5 okSetArraySize

Sets the size in bytes of a dynamic array.


Syntax
okError okSetArraySize(okEnv Env, okArray *Array, 

   okU4B NewSize);

Parameters
Env

An environment handle.

Array

A pointer to a dynamic array.

NewSize

The new size of the dynamic array.


Comments

This procedure adjusts the size of the dynamic array pointed to by Array. If Array points to a NULL pointer and NewSize is greater than zero, okSetArraySize creates a new array. If NewSize is larger than or equal to the original size of the dynamic array, the original value of the dynamic array remains intact. The newly added memory is not initialized. If NewSize is smaller than the original size of the dynamic array, the value in the array is truncated according to NewSize. You can use this function when you know how many bytes are to be added to a dynamic array. Instead of calling okAppendArray incrementally to append each data item to the dynamic array, you can adjust the size once and assign the data items directly into the array, treating it as a regular C array.

2.20.6 okAppendArray

Appends data to the end of a dynamic array.


Syntax
okError okAppendArray(okEnv Env, okArray *Array, 

   okU4B Size, const okByte *Data);

Parameters
Env

An environment handle.

Array

A pointer to a dynamic array.

Size

The size of data in a dynamic array.

Data

Data value for a dynamic array.


Comments

This procedure appends Size bytes of new data (pointed to by Data) to the end of a dynamic array pointed to by Array. If Array originally points to a NULL pointer and Size is greater than zero, okAppendArray creates a new array. If Data is NULL, it does not initialize the newly appended area. It is an error if Array is NULL.

2.20.7 okCopyArray

Creates a copy of a dynamic array.


Syntax
okError okCopyArray(okEnv NewEnv, okArray *RetNewArray,

   okEnv OldEnv, const okArray *OldArray);

Parameters
NewEnv

The environment handle for the target array.

RetNewArray

The target array.

OldEnv

The environment handle for the source array.

OldArray

The source array.


Comments

This function creates a copy of a dynamic array pointed to by OldArray and returns a pointer to it in RetNewArray. It does not release a dynamic array pointed to by OldArray. To avoid memory leaks, you should release any valid dynamic array pointed to by RetNewArray before passing it to this function. If OldArray is NULL or points to a NULL pointer, the function returns a NULL pointer in RetNewArray. It is an error if RetNewArray is NULL.

2.20.8 okCreateMDArray

Creates a new multi-dimensional array.


Syntax
okError okCreateMDArray (okEnv Env, okSize Dim, const okSize *Size, okArray *d);

Parameters
Env

An environment handle.

Dim

Dimension. The number of elements.

Size

The size of data in each element (bytes).

d

The array handle.

2.20.9 okCopyMDArray

Copies a multi-dimensional array.


Syntax
okError okCopyMDArray (okEnv Env, okSize Dim, okArray s, okArray *d);

Parameters
Env

An environment handle.

Dim

Dimension. The number of elements.

s

The source array.

d

The target array.

2.20.10 okFreeMDArray

Frees a multi-dimensional array.


Syntax
okError okFreeMDArray (okEnv Env, okSize Dim, okArray a);

Parameters
Env

An environment handle.

Dim

Dimension. The number of elements.

a

A handle to the array to free.

2.20.11 Dynamic Array Sample Program

The following code demonstrates the use of the dynamic array procedures:

#include "okbasic.h"

#include "okerr.h"

#include "okapi.h"


okChar *CityName = "San Jose";

okU4B CityPopulation = 300000;

okU4B ArraySize;      /* size of a dynamic array */

okArray City;         /* dynamic array of okChar */

okArray Population;   /* dynamic array of okU4B */

okArray NewArray;     /* a new array */

okError e;

okEnv   Env;


...


   /* see okInit to initialize the environment here */

   e = okCreateArray(Env, &City, 

      strlen(CityName)+1, (okByte *)CityName);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   e = okCreateArray(Env, &Population, 

      sizeof(okU4B), (okByte *)&CityPopulation); 

   if (OK_IS_ERROR(e)) { /* error handling */ }

      

   e = okGetArraySize(Env, &City, &ArraySize);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   if (ArraySize != sizeof("San Jose")) { /* error handling */ }


   e = okSetArraySize(Env, &Population, 2*sizeof(okU4B));

   if (OK_IS_ERROR(e)) { /* error handling */ }


   CityPopulation = 350000;

   e = okAppendArray(Env, &Population,  

      sizeof(okU4B), (okByte *)CityPopulation);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   

   e = okCopyArray(Env, &NewArray, Env, &City);

   if (OK_IS_ERROR(e)) { /* error handling */ }

   

   e = okDeleteArray(Env, &City);

   if (OK_IS_ERROR(e)) { /* error handling */ }


...


Previous Next
Oracle Logo
Copyright © 2002 Oracle Corporation

All rights reserved
Go To Table Of Contents
Contents
Go To Index
Index