Skip to main content
Jump to: navigation, search

OM2M/one/Advanced DB

In this tutorial, you can configure the OM2M default database (H2) your way and, if needed, use an alternative system and set it up. (From now, database is referred as DB). By default, OM2M uses the H2 database (LINK TO H2 WEBSITE) through a persistence abstraction layer and a JPA (EclipseLink). H2 server is configured to run in an embedded mode and the database file is stored in the product directory (database/<file>).

Prerequisites

  • OM2M project cloned and built (LINK TO THE TUTO)
  • project opened in IDE for further modifications

Modify the default configuration

In the following guidelines, the modified constants are located in the config.in file. This file is located in the configuration folder in the product directory once you have cloned and built the project.

DB reset on startup

By default the DB is reset on startup of the platform that is to say data are deleted. To modify this configuration just change the following constant to false. This constant can be found in the config.ini file, in your product (IN, MN, etc.).

org.eclipse.om2m.dbReset=false

Use another User / password to access the DB

By default, the user and its password used to connect to the DB are "om2m". Of course you can use different user/pwd if you want to use another configuration for your persistence part. To change the user and its password, modify the two following constants:

org.eclipse.om2m.dbUser=your_user
org.eclipse.om2m.dbPassword=password

Use a different location for DB file

To change the location of the DB file, you need to modify one constant in the config.ini file. (located in the configuration folder in the product (IN, MN, etc.). For the IN you have by default:

org.eclipse.om2m.dbUrl=jdbc\:h2\:./database/indb

You can use any alternative path, just put it after the last ":" in the "jdbc\:h2\:" part like this:

org.eclipse.om2m.dbUrl=jdbc\:h2\:YOUR/PATH/ABSOLUTE/OR/RELATIVE

Run H2 in another mode

By default H2 is embedded in OM2M and stores data into a file. You can set up H2 to run in server mode (classic) and configure OM2M to connect to this server, or even run H2 in memory (for gateways for instance) if needed.

Run H2 in memory

For limited gateways, you may want to configure H2 in memory mode to have a faster interaction. However be aware of possible loss of data in case of reboot or shut down of your gateway. This mode is interesting if you have few data stored in the gateway itself and have another instance that is safer. To use H2 in this mode just modify this constant in the config.ini file of your node:

org.eclipse.om2m.dbUrl=jdbc\:h2\:mem\:

Run a server and configure the connection

This solution may be useful if you want to have a dedicated machine that will be your DB server for your system.

Launch the DB server

To launch H2 in server mode, just download the version you want to use of H2 from H2 website. Unzip the file and go to h2/bin directory. to launch the server use:

java -jar h2*.jar

Configure OM2M to connect to the server

Just modify this constant in the config.ini file:

org.eclipse.om2m.dbUrl=jdbc\:h2\:tcp\://<dbServer>\:<port>/~/sample

You can find other configurations on the H2 website: LINK TO H2.

Use another DataBase (advanced tutorial)

  • JDBC driver
  • OM2M update
  • Connection

Back to the top