HOWTO use the very same CCDB for different databases

From GlueXWiki
Revision as of 22:16, 3 April 2014 by Romanov (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

CCDB uses connection string to connect to databases. To use different databases with one installation of CCDB one should pass different connection string to it. So, here is how to do this.

Lets consider we have two databases ONE and TWO

1. Command line tools (CCDB CLI):

There are two ways of passing connection string to ccdb command:

  • Use CCDB_CONNECTION environment variable
  • '-c <connection string>' flag on ccdb start.

Flag '-c' has higher priority, so if you execute the next command, you may be solid sure ccdb is connected to DB ONE

> ccdb -i -c mysql://ONE_db_user@host/ONE

To skip writing '-c ...', one could create an alias:

alias ccdb_online="ccdb -c mysql://ONE_user@host/ONE"

Now when ccdb_online is called, it connects to database ONE.

To end up with the example, lets suppose we have environment setup:

alias ccdb_online="ccdb -c mysql://ONE_user@host/ONE"  
export CCDB_CONNECTION=mysql://TWO_user@host/TWO

Now if we call...

> ccdb -i          # connects to db TWO, because of CCDB_CONNECTION
> ccdb_online -i   # connects to ONE, because it is alias with '-c' flag

Without doubt one should be able even to call:

> ccdb -i -c sqlite:///some.file.db
> ccdb_online -i -c sqlite:///some.file.db   # SHOULD work too


Jana uses JANA_CALIB_URL environment variable. One has to set right connection string to this variable before JANA starts.

3. Language interfaces.

Language interfaces (C++ API, Python API and Java) API get connection string directly in factory function. Like:

Calibration* calib = CalibrationGenerator.Create("mysql://ONE_user@host/ONE",...)

So one just passes the right connection string to API.