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) an 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);

}

Multithread object spaces

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;

}

Documents