【Sesame】实现MySQL底层存储对接

来源:互联网 发布:centos开启snmp 编辑:程序博客网 时间:2024/06/16 03:21

本文主要提供了一种方法,用于将sesame图数据库以MySQL形式存储于关系型数据库。

搭建MySQL服务器

这个跳过。记录下访问配置信息:
server: localhost
port: 3306
name: root
password: rootpassword
开启数据库连接,新建一个数据库叫rdf_test

编写Sesame顶层代码

public RepoUtil() {                   valueFactory = new ValueFactoryImpl();     //Initialize the value factory for URI and Literal          MySqlStore ms = new MySqlStore();          /* Set the parameters for mysql store */          ms.setServerName("localhost");          ms.setPortNumber(3306);          ms.setDatabaseName("rdf_test");          ms.setUser("root");          ms.setPassword("rootpassword");          /* Initialize the sail repository w*/          repo = new SailRepository(ms);          try {               repo.initialize();     //or ms.initialize();          } catch (RepositoryException e) {               e.printStackTrace();          }                   try {               repoConn = repo.getConnection();     //get connection               URI s = valueFactory.createURI("http://test.com/user/12345");               URI p = valueFactory.createURI("http://test.com/actioin/create/3");               Literal o = valueFactory.createLiteral("卧槽 看不懂!");               repoConn.add(s, p, o);               repoConn.close();                         //close the connection          } catch (RepositoryException e) {               e.printStackTrace();          }          try {               repo.shutDown();      //It is important! otherwise it would not delete "locked" table.          } catch (RepositoryException e) {               e.printStackTrace();          }/**/     }

顶层调用本段代码,即可实现sesame对MySQL数据库的访问、存储及查询。
sesame已经封装好mysql对应的代码。
注意点:
数据库操作断开会留下lock表,此时比较复杂,需要处理roll back等操作。

原创粉丝点击