company logo

Database application

When running a database application, a global application instance is created implicitly in order to make global resources available for database functions. The application manages several system resources, which can be defined in different sections of a configuration or ini-file:

  • SYSTEM - System resource database (contains e.g. error messages)
  • CACHE - initialize server or application cache settings (optional)
  • FILE-CATALOG - defines file locations for symbolic file names (optional)
  • DATA-CATALOG - defines data sources in a database (optional)

The global application object instance provides several static functions, which support application management. In order to initialize these resources, i.e. in order to make system errors and data catalogs available, Application::initialize() might be called with a configuration or ini-file. The function will initialize the system resources from definitions passed in the configuration file. When not calling initialize() or when not passing a configuration file, those system resources cannot be used.

The application registers the process and activates the error log file. It opens the system database for providing error messages and, optionally, the data catalog. System resources are initialized once, only, and will be closed when leaving the application or when shutting down the application explicitly (Application::shutDown()).

Default system and catalog sections are defined in the ODABA.Ini-file that is stored in the ODABA installation path. The system section should always refer to the ode.sys database. This might be located on a server, in which case the data source has to provide connection information (server name and port). In order to provide an application specific data or file catalog, application specific settings can be defined in the configuration file passed to the application.

System resources

The system database is opened automatically, when the configuration file passed to Application::initialize() contains a SYSTEM section or an appropriate top option element has been defined in the configuration file. When the system database is not opened, the application still runs fine, but system errors are written to the error log file without explanatory test.

When running the SYSTEM database from a server, the main client automatically connects to the server with the system database (ode.sys). When this connection refers to the same server as other data sources, the application should use the main client in order to connect to other databases.

int   main ( int argc, char *argv[] ) {

  ObjectSpace  os;

  Property     errorClass;

  String       fString("%s::Error %s");

  

  if ( argc < 2 )                          THROW

  Application::initialize(argv[1],argv[0],ConsoleApplication);

  os.open(Application.systemObjectSpace());

  errorClass.open(os,"ODC_ErrorClass",Read);

  Property   errors(errorClass,"errors");

  Value      class_name("sys_ident");

  while ( errorClass.next() ) {

    while ( errors.next() )

      Application::output(errors.format(

                           fString,class_name.toString(),"_errnum");

  return 0;

}

Data catalog

The data catalog is used for referring to registered data sources. In order to access the data catalog, the configuration or ini-file with a [DATA-CATALOG] section has to be passed to Application::initialize().

Data sources defined in the data catalog can be accessed by data source name. Thus, it becomes easier to administrate data sources, since changing the data source location needs to be registered in the catalog, only.

In contrast to configuration and ini-files, names in the data catalog are case sensitive. Within a configuration file, the data catalog entries can be extended by additional data source sections defined in the configuration file.

The catalog can be updated calling the ObjectCommander, but one may also write a script file of program in order to fill the catalog or create new catalog entries.

In order to open an object space from a data source defined in the data catalog, you may call objectSpace::open() with the data source name in the catalog.

// section in the ini file

[DATA-CATALOG]

DICTIONARY=C:/odaba/ode.sys

DATABASE=C:/odaba/catalog.dat

NET=YES

// referring to data catalog in a program

... fragment ( ) {

  ObjectSpace    os(Application::objectSpace("Sample",Write));

  // ... now, property handles can be created

}

File catalog

The file catalog contains values for symbolic file references. The file catalog is typically used in order to assign symbolic file names or folder to database locations on a server. While the client is referring e.g. to a %SAMPLE_DAT% database file, the server defines an appropriate option variable in the file catalog in order to resolve the database location on the server side.

File catalog can be defined in the data catalog file, but also in the (server's) configuration or ini-file. One may also extent the file catalog definitions in the data catalog with file definitions in the configuration file.

Application cache

In order to improve performance, applications may use a read cache. Typically, a cache is defined for the server, when running an application in client server mode. You may, however, also activate the client in an application.

There are some problems for multithread applications, since different locking strategies differ between operating systems. In order to avoid concurrency conflicts, the cache can be activated, which provides save locking within the application and file locking is used in order to solve concurrency problems between different processes.

Related topics