Chapter 12. Using multi databases in DODS

DODS has the possibility of working with more than one database at the same time. This means that, when the application is started, it doesn't have to be stopped in order to change the database the application uses.

The table supports multi databases if the attribute multidb of <table> tag in doml file is set to true for that table.

To take advantage of simultaneous use of multiple table DODS requires separate doml file for every distinct database.

Example:

<doml>
  <database database="Standard">
    .........
    <package id="multibase.data.employee">
        <table id="multibase.data.employee.Employee"  multidb="true">
             <column id="firstName" usedForQuery="true">
                 <type dbType="VARCHAR" javaType="String"/>
             </column>
             ........
        </table>
        .........
    </package>
    .........
</doml>
<doml>
  <database database="Standard">
        .............
        <package id="multibase.data.employee.programer">
          <table id="multibase.data.employee.programer.Programer"  multidb="true">
            <column id="firstName" usedForQuery="true">
              <type dbType="VARCHAR" javaType="String"/>
            </column>
            .............
          </table>
          ............
        </package>
        ............
  </database>
</doml>

For that kind of table, in <App_name>.conf file must be defined all logical databases the application will use on this table. For each of these databases must be configured all needed parameters.

Example:

#-----------------------------------------------------------------------------
#                   Database Manager Configuration
#-----------------------------------------------------------------------------

DatabaseManager.Databases[] = "programer", "employee"
DatabaseManager.DefaultDatabase = "employee"

DatabaseManager.DB.programer.Connection.User = ""
DatabaseManager.DB.employee.Connection.User = ""

DatabaseManager.DB.programer.Connection.Password = ""
DatabaseManager.DB.employee.Connection.Password = ""

......................................................

DatabaseManager.DB.programer.Connection.Logging = false
DatabaseManager.DB.employee.Connection.Logging = false

DatabaseManager.DB.programer.ObjectId.CacheSize = 20
DatabaseManager.DB.programer.ObjectId.MinValue = 1000000

DatabaseManager.DB.employee.ObjectId.CacheSize = 20
DatabaseManager.DB.employee.ObjectId.MinValue = 1000000

If the table doesn't support multi databases, the default database will be used for this table.

When the <App_name>.conf file (with information about all databases) is updated, and the application is started, it uses the default database. The definition of the new (desired) database is being done in the stage of creation of DO and Query objects.

When a Query object is created for a database (given or default), the results of this Query are only DOs from that database, not from any other database.

If caching is used, there is only one cache for all <table_name>DO's original data originalData (these DataStruct objects can belong to different databases, but are all placed in the same DataStruct cache).

DODS takes care of referential integrities within the database which means that DODS searches referenced object in the same database in which the object that referenced it is. If you want to use referenced objects from any other database, you must yourself take care of referential integrities.

In the <table_name>DO class public constructors and methods (query, createVirgin, createCopy, createExisting) are now defined and with the database parameter.

Here are some examples of using these constructors and methods.

Query example:

ProgramerDO[] programers;
ProgramerQuery pQuery = new ProgramerQuery("programer");
programers = pQuery.getDOArray();

Create example:

EmployeeDO newE=EmployeeDO.createVirgin("employee");
newE.setFirstName(employees[i][0]);
...................................
newE.save();

Example of transferring data from one database to another:

ProgramerDO[] programers;
ProgramerQuery pQuery = new ProgramerQuery("programer");
programers = pQuery.getDOArray();
for(int i=0; i< programers.length; i++) {
   EmployeeDO newEmployee=EmployeeDO.createVirgin("employee");
   newEmployee.setFirstName(programers[i].getFirstName());
   newEmployee.setLastName(programers[i].getLastName());
   newEmployee.setOccupation("programer");
   newEmployee.setDepartment("IT");
   newEmployee.save();
}

You can use them with this parameter in which case the object will be created for the given logical database, or you can use these constructors and methods without database parameter. In this case, they will be created for default database. If the methods with database parameter are used, and the parameter is set to null, the default database is used.