001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.sail.rdbms.config;
007:
008: import static org.openrdf.model.util.GraphUtil.getOptionalObjectLiteral;
009: import static org.openrdf.sail.rdbms.config.RdbmsStoreSchema.INDEXED;
010: import static org.openrdf.sail.rdbms.config.RdbmsStoreSchema.JDBC_DRIVER;
011: import static org.openrdf.sail.rdbms.config.RdbmsStoreSchema.LAYOUT;
012: import static org.openrdf.sail.rdbms.config.RdbmsStoreSchema.PASSWORD;
013: import static org.openrdf.sail.rdbms.config.RdbmsStoreSchema.URL;
014: import static org.openrdf.sail.rdbms.config.RdbmsStoreSchema.USER;
015:
016: import org.openrdf.model.Graph;
017: import org.openrdf.model.Literal;
018: import org.openrdf.model.Resource;
019: import org.openrdf.model.URI;
020: import org.openrdf.model.util.GraphUtilException;
021: import org.openrdf.sail.config.SailConfigException;
022: import org.openrdf.sail.config.SailImplConfigBase;
023:
024: /**
025: * Holds the JDBC Driver, URL, user, and password.
026: *
027: * @author James Leigh
028: *
029: */
030: public class RdbmsStoreConfig extends SailImplConfigBase {
031: private String jdbcDriver;
032: private String url;
033: private String user;
034: private String password;
035: private String layout;
036: private String indexed;
037:
038: public RdbmsStoreConfig() {
039: super (RdbmsStoreFactory.SAIL_TYPE);
040: }
041:
042: public String getJdbcDriver() {
043: return jdbcDriver;
044: }
045:
046: public void setJdbcDriver(String jdbcDriver) {
047: this .jdbcDriver = jdbcDriver;
048: }
049:
050: public String getUrl() {
051: return url;
052: }
053:
054: public void setUrl(String url) {
055: this .url = url;
056: }
057:
058: public String getUser() {
059: return user;
060: }
061:
062: public void setUser(String user) {
063: this .user = user;
064: }
065:
066: public String getPassword() {
067: return password;
068: }
069:
070: public void setPassword(String password) {
071: this .password = password;
072: }
073:
074: public String getLayout() {
075: return layout;
076: }
077:
078: public void setLayout(String layout) {
079: this .layout = layout;
080: }
081:
082: public String getIndexed() {
083: return indexed;
084: }
085:
086: public void setIndexed(String indexed) {
087: this .indexed = indexed;
088: }
089:
090: @Override
091: public Resource export(Graph graph) {
092: Resource implNode = super .export(graph);
093: set(graph, implNode, JDBC_DRIVER, jdbcDriver);
094: set(graph, implNode, URL, url);
095: set(graph, implNode, USER, user);
096: set(graph, implNode, PASSWORD, password);
097: set(graph, implNode, LAYOUT, layout);
098: set(graph, implNode, INDEXED, indexed);
099: return implNode;
100: }
101:
102: @Override
103: public void parse(Graph graph, Resource implNode)
104: throws SailConfigException {
105: super .parse(graph, implNode);
106:
107: try {
108: jdbcDriver = get(graph, implNode, JDBC_DRIVER);
109: url = get(graph, implNode, URL);
110: user = get(graph, implNode, USER);
111: password = get(graph, implNode, PASSWORD);
112: layout = get(graph, implNode, LAYOUT);
113: indexed = get(graph, implNode, INDEXED);
114: } catch (GraphUtilException e) {
115: throw new SailConfigException(e.getMessage(), e);
116: }
117: }
118:
119: private String get(Graph graph, Resource implNode, URI predicate)
120: throws GraphUtilException {
121: Literal lit = getOptionalObjectLiteral(graph, implNode,
122: predicate);
123: if (lit == null)
124: return null;
125: return lit.getLabel();
126: }
127:
128: private void set(Graph graph, Resource implNode, URI predicate,
129: String value) {
130: if (value != null) {
131: Literal lit = graph.getValueFactory().createLiteral(value);
132: graph.add(implNode, predicate, lit);
133: }
134: }
135:
136: }
|