company logo

Using database object space handle

The object space handle is required only, when you are working with multiple object space (or multiple universe) databases. Object space handles have to be created also, when you are running transactions on the same database in different threads.

Multiple object space database

By default, each database contains (is) a root object space. Subordinated object spaces are created in order to support e.g. different customers in the same database. In this case, each customer gets its own object space, which is completely separated from the object spaces for other customers. Still, each customer may refer to common resources stored in the root object space.

Below the root object space, several sub-object spaces might be created, which may have subordinated object spaces again etc.

ObjectSpace  createCustomer ( Database &db, String customerId ) {

  ObjectSpace os;

  Property    osNames(db,"ODC_NamedObject",Read);

  

  if ( osNames.locate(customerId) )

    printf("Customer %s already exists", customerId);

  else

    os.open(db,customerId); // now, customer exists

  return(os);

}

ObjectSpace  openCustomer ( Database &db, String customerId ) {

  ObjectSpace os;

  Property    osNames(db,"ODC_NamedObject",Read);

  

  if ( osNames.locate(customerId) )

    os.open(db,customerId);

  else

    printf("Customer %s does not exists", customerId);

  return(os);

}

Using object space handles in multi-thread applications

Object space handles are not thread save. In order to use object spaces and subordinated handles in different threads, handle copies have to be created for each thread, i.e. each thread has to create a copy of the database root object space by calling the copy constructor or the database open() function implementation.

ObjectSpace threadOpen ( ObjectSpace &os ) {

  ObjectSpace copyOs;

  if os.isValid() )

    copyOs.open(os,Write);

  return copy;

}

Notes:

The copy constructor just creates a handle copy and not a copy for the access node. Hence, the copy constructor cannot be used for creating a handle node copy for the thread.

Overloaded object spaces

In order to merge extents from different object spaces, object spaces may be overloaded. One way of overloading is provided for object space hierarchies. By setting the overload property of a subordinated object space handle to true ( ObjectSpace ::overload( true ) ),