Db4o persistence in openHAB 2

Hi,

I noticed, that the db4o persistence service is not shown in the list of installable services in the Paper UI.

I tested copying the db4o bundle from my 1.8.3 installation to the openhab 2 addons folder and it seems to work.

I could find no information to db4o in openHAB 2. Is there a reason why it is not shown or has ist just not been tested?

Thanks for your help!

Juelicher

There is no db4o support in openHAB 2

Yes, I noticed that, but I wonder why.

When copying the db4o 1,8,3 bundle to the addons folder it seems to work without problems but maybe I am overseeing something?

Interesting, I really liked db4o for storing scratch values frequently.

Me too! I don’t wont to have the hassle of installing and maintaining a database server, if not needed.

I did some tests with db4o and sqlite and compared the results from the persistence functions. Everything seems to be plausible so far. But this was, by no means, an extensive test.

My only complaint is that you gracefully handle a query that has no data. So when you 0 out your db and your rules first run they error on not finding the data. I at least have not found a way to test if the data is there is not use a default value and not error.

I am nut sure, if I understand you correctly. Currently I am performing checks like this:

if (WaterMeter_Value.historicState(now.withTimeAtStartOfDay.withDayOfMonth(1)) != null) {
}

Interesting…

val double today_grid = if(Today_Grid_kWh.previousState().state == null) 0 else Today_Grid_kWh.previousState().state

However if I start with a clean db that throws and error because there is no Today_Grid_kWh previous state in the db. I have been getting past this for now by manually entering data in my db after I clear my db, but I would like to not do that manually.

Full rule:

rule "Today Grid Used"
when
  Item Grid_wh changed
then
  val double previous_meter = Grid_wh.previousState(true, "db4o").state
  val double current_meter = Grid_wh.state
  logInfo("Testing", "Current: " + current_meter)
  logInfo("Testing", "Previous: " + previous_meter)
  val double today_grid = if(Today_Grid_kWh.state == null) 0 else Today_Grid_kWh.state
  postUpdate(Today_Grid_kWh, today_grid + ((current_meter - previous_meter)/1000))
end

Error with Today_Grid_kWh NOT in db yet.

2017-01-22 18:28:43.585 [INFO ] [g.openhab.model.script.Testing] - Current: 33796387.885
2017-01-22 18:28:43.630 [INFO ] [g.openhab.model.script.Testing] - Previous: 33796365.197
2017-01-22 18:28:43.650 [INFO ] [runtime.busevents             ] - Creek_Level state updated to 2.42
2017-01-22 18:28:43.656 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Today Grid Used'
java.lang.NullPointerException: null
	at org.openhab.model.script.lib.NumberExtensions.operator_equals(NumberExtensions.java:81) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor115.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_66]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_66]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation(XbaseInterpreter.java:713) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_66]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_66]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.openhab.model.script.interpreter.ScriptInterpreter.internalFeatureCallDispatch(ScriptInterpreter.java:69) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateAbstractFeatureCall(XbaseInterpreter.java:658) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_66]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_66]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateIfExpression(XbaseInterpreter.java:327) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_66]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_66]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateVariableDeclaration(XbaseInterpreter.java:601) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor82.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_66]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_66]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateBlockExpression(XbaseInterpreter.java:321) ~[na:na]
	at sun.reflect.GeneratedMethodAccessor84.invoke(Unknown Source) ~[na:na]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_66]
	at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_66]
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:204) ~[na:na]
	at org.openhab.model.script.internal.engine.ScriptImpl.execute(ScriptImpl.java:59) ~[na:na]
	at org.openhab.core.scriptengine.ScriptExecutionThread.run(ScriptExecutionThread.java:44) ~[na:na]

I am not really sure, which line causes the exception.

What you could test:

  • changing null to uppercase NULL, the migration doc states, that there is a difference.

  • Replacing val double previous_meter = Grid_wh.previousState(true, “db4o”).state:
    val double previous_meter
    if (Grid_wh.previousState(true, “db4o”) != null {
    previous_meter = Grid_wh.previousState(true, “db4o”).state
    } else {
    previous_meter = 0
    }