Using a transaction listener with an embedded instance

(Davide Rossi) #1

Hi, after a bit of struggling with Maven I'm now able to run an application using an embedded Stardog.
Now I'd like to attach a transaction listener to it.
I see there is a good example here: https://github.com/stardog-union/stardog-examples/tree/develop/examples/connectable however I cannot understand how to attach the listener to the embedded instance of Stardog I just created. I see the example uses a guice to inject the the listener but the missing part is how to use the injector configured with this module: ExampleModule.java.
Should the injector configured with that module return a Connection, an AdminConnection?
Do you have a simple two-liners to show how to use it?

BTW the link to " 9. Transaction Listener" in List of Examples here https://github.com/stardog-union/stardog-examples is wrong (404).

(zachary.whitley) #2

I don’t believed that the listener is defined for a specific connection but listens on all connections. It will be looked up my the service definition and injected. There shouldn’t be anything specific you need to do for embedded mode. It’s all automagic.

(Davide Rossi) #3

But do I have to create an Injector or I don't?

(Evren Sirin) #4

The example you refer to is for an embedded connection already. You need the Guice module definition as in that example but do not need to create an injector explicitly which is done by Stardog internals. You need the service loader file [1] so Stardog will include use your Guice module.

Best,
Evren

[1] https://github.com/stardog-union/stardog-examples/tree/develop/examples/connectable/main/resources/META-INF/services

(Davide Rossi) #5

Gotcha. That was the piece I was missing. Thanks.

(zachary.whitley) #6

The correct link would most likely be https://github.com/stardog-union/stardog-examples/tree/develop/examples/connectable

(system) closed #7

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.