annotate src/main/java/de/mpiwg/itgroup/annotationManager/RDFHandling/TripleStoreConnection.java @ 34:bd414fe235b5 default tip

now with 100% better sparql.
author casties
date Thu, 31 May 2012 21:32:30 +0200
parents a3e324009990
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
1 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
2 *
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
3 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
4 package de.mpiwg.itgroup.annotationManager.RDFHandling;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
5
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
6 import org.apache.log4j.Logger;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
7 import org.restlet.Context;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
8 import org.restlet.engine.component.ChildContext;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
9
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
10 import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreStoreError;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
11 import de.mpiwg.itgroup.triplestoremanager.exceptions.TripleStoreHandlerException;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
12 import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
13
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
14 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
15 * @author casties
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
16 *
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
17 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
18 public class TripleStoreConnection {
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
19
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
20 protected static Logger logger = Logger.getRootLogger();
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
21
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
22 private String user;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
23 private String password;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
24 private String url = "jdbc:virtuoso://virtuoso.mpiwg-berlin.mpg.de:1111";
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
25
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
26 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
27 * Creates TripleStoreConnection with parameters from web context.
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
28 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
29 public TripleStoreConnection() {
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
30 ChildContext context = (ChildContext)Context.getCurrent();
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
31 user = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUser", true);
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
32 password = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUserPassword", true);
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
33 url = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreConnectionURL", true, url);
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
34 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
35
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
36 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
37 * @param user
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
38 * @param password
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
39 * @param url
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
40 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
41 public TripleStoreConnection(String user, String password, String url) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
42 super();
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
43 this.user = user;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
44 this.password = password;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
45 this.url = url;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
46 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
47
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
48 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
49 * returns TripleStoreHandler.
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
50 *
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
51 * @return
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
52 * @throws TripleStoreHandlerException
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
53 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
54 public TripleStoreHandler getTripleStoreHandler() throws TripleStoreHandlerException {
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
55 if (user == null || password == null || url == null) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
56 logger.error(String.format("Missing triplestore parameters! (user=%s pw=%s url=%s)", user, password, url));
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
57 throw new TripleStoreStoreError();
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
58 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
59 TripleStoreHandler th = new TripleStoreHandler(url, user, password);
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
60 return th;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
61 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
62
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
63 /**
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
64 * returns new TripleStoreHandler.
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
65 *
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
66 * uses parameters from web context.
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
67 *
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
68 * @return
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
69 * @throws TripleStoreStoreError
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
70 * @throws TripleStoreHandlerException
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
71 */
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
72 public static TripleStoreHandler newTripleStoreHandler() throws TripleStoreStoreError, TripleStoreHandlerException {
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
73 ChildContext context = (ChildContext)Context.getCurrent();
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
74 String user = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUser");
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
75 String password = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUserPassword");
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
76 String url = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreConnectionURL");
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
77 if (user == null || password == null || url == null) {
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
78 logger.error(String.format("Missing triplestore parameters! (user=%s pw=%s url=%s)", user, password, url));
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
79 throw new TripleStoreStoreError();
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
80 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
81 TripleStoreHandler th = new TripleStoreHandler(url, user, password);
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
82 return th;
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
83 }
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
84
b0ef5c860464 updating and deleting annotations works now!
casties
parents:
diff changeset
85 }