Transactions using spring

0 views
Skip to first unread message

julie...@gmail.com

unread,
May 26, 2016, 3:52:31 AM5/26/16
to Stardog
We have several semantic projects and we decided to evaluate Stardog in a proof of concept.
Our app is built using the spring framework. We saw that you offer support for the spring framework. However, after a review of the code, it seems you don't implement the java.sql.Datasource interface but your own version of it. This prevents us from using available transaction managers.
This leads us to asking you a question: in which way do you recommend to handle transaction (programmatically)? To provide us an answer, you may also need to know we use Jena (we know you just proxy to sesame).

Al Baker

unread,
May 26, 2016, 3:34:44 PM5/26/16
to sta...@clarkparsia.com
Hi Julien,

The stardog-spring package presents a DataSource bean, created from a DataSourceFactory bean, to be used primarily with the SnarlTemplate.  It is very similar to the JDBC data sources and JdbcTemplate in the core Spring framework.  However, the Stardog classes do not implement any of the java.sql interfaces, so they are not bean drop-in replacements for any JDBC Spring capability.

Like JdbcTemplate, the SnarlTemplate removes all of the boiler plate (obtaining connections from a pool, beginning and closing out transactions, etc) and provides callback interfaces typical of the Spring Framework (e.g. RowMapper).   Basically, it should feel very much like a typical Spring application with some ready made beans to get you started.  These classes can be instantiated and managed elsewhere as standalone resources – e.g. The DataSource bean is just a wrapper on the ConnectionPool API, but it’d be just another resource and not something compatible with dbcp, c3p0, etc.

See below example:


SnarlTemplate tmp = new SnarlTemplate(); tmp.setDataSource(dataSource);
String sparql = "SELECT ?a ?b WHERE { ?a <http://purl.org/dc/elements/1.1/title> ?b } LIMIT 5";
List<Map<String,String>> results = tmp.query(sparql, new RowMapper<Map<String,String>>() {
@Override
public Map<String,String> mapRow(BindingSet bindingSet) {
Map<String,String> map = new HashMap<String,String>();
map.put("a", bindingSet.getValue("a").stringValue());
map.put("b", bindingSet.getValue("b").stringValue());
return map;
}
});


In this example, the SnarlTemplate and DataSource would both be configured beans in your application context (e.g. [1])

The template query method will handle all the boiler plate.  For any APIs not wrapped in this manner, there is an Execute method that provides full access to the connection, where you can further utilize the Stardog API [2].  The Junit is a good example of all the API usage [3].

Comments, suggestions and pull requests are always welcome if there’s other capabilities you’re looking for.

Thanks,
Al






--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

julie...@gmail.com

unread,
May 27, 2016, 5:09:31 AM5/27/16
to Stardog
Thanks for your meticulous answer,

We won't use the SnarlTemplate because we want our software to be independent of the database. This is why we use jena. 

Yet, there are still several blur points for us . How do you advise us to manage transactions? Since there is no transaction manager available for your DataSource implementation, do we have to directly use Jena methods? Does it offer the full capabilities of Stardog transactions?

As a suggestion, we recommend you to implement a transaction manager for Spring. This would allow spring developers to play with transactions in a elegant fashion.

Best regards,
Julien

Evren Sirin

unread,
May 27, 2016, 10:02:39 AM5/27/16
to Stardog
You can manage Stardog transactions via Jena. Transactions are
supported both for Model and Dataset instances backed by Stardog.

Best,
Evren

Kendall Clark

unread,
May 27, 2016, 4:21:53 PM5/27/16
to Stardog
Stardog's Spring support is open source, with a friendly license and full revision history on Github.

We'd be happy to review PRs that add a transaction manager!

Cheers,
Kendall

Reply all
Reply to author
Forward
0 new messages