Skip to main content
Jump to: navigation, search

Difference between revisions of "OM2M/one/Advanced DB"

< OM2M‎ | one
Line 1: Line 1:
 
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).
 
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>).
+
By default, OM2M uses the H2 database 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>).
 +
 
 +
If you are looking for more detailed information about H2 itself, check the H2 website and tutorials: [http://www.h2database.com]
  
 
__TOC__
 
__TOC__
  
 
= Prerequisites =
 
= Prerequisites =
* OM2M project cloned and built (LINK TO THE TUTO)
+
* OM2M project cloned and built
* project opened in IDE for further modifications
+
  
 
= Modify the default configuration =
 
= Modify the default configuration =
Line 50: Line 51:
 
This solution may be useful if you want to have a dedicated machine that will be your DB server for your system.
 
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 ===
 
=== 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 H2 in server mode, just download the version you want to use of H2 from H2 website: [http://www.h2database.com/html/download.html]. (The following example use the platform independant zip.) Unzip the file and go to the h2/bin directory.
to launch the server use:
+
To launch the server without any complex configuration, just use:
 
<pre>
 
<pre>
 
java -jar h2*.jar
 
java -jar h2*.jar
 
</pre>
 
</pre>
 +
This operation will open a webpage about the web console. There you can manage your database, create users, etc.
 +
To know more details and possibilities about this part, please visit the H2 online tutorials: [http://www.h2database.com/html/tutorial.html#using_server]
  
 
=== Configure OM2M to connect to the server ===
 
=== Configure OM2M to connect to the server ===
Line 62: Line 65:
 
</pre>
 
</pre>
  
You can find other configurations on the H2 website: LINK TO H2.
+
You can find other configurations on the H2 website: [http://www.h2database.com/html/tutorial.html].
 
+
= Use another DataBase (advanced tutorial) =
+
 
+
* JDBC driver
+
* OM2M update
+
* Connection
+

Revision as of 09:24, 15 March 2016

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 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>).

If you are looking for more detailed information about H2 itself, check the H2 website and tutorials: [1]

Prerequisites

  • OM2M project cloned and built

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: [2]. (The following example use the platform independant zip.) Unzip the file and go to the h2/bin directory. To launch the server without any complex configuration, just use:

java -jar h2*.jar

This operation will open a webpage about the web console. There you can manage your database, create users, etc. To know more details and possibilities about this part, please visit the H2 online tutorials: [3]

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: [4].

Back to the top