001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.sail.nativerdf.config;
007:
008: import static org.openrdf.sail.nativerdf.config.NativeStoreSchema.FORCE_SYNC;
009: import static org.openrdf.sail.nativerdf.config.NativeStoreSchema.TRIPLE_INDEXES;
010:
011: import org.openrdf.model.Graph;
012: import org.openrdf.model.Literal;
013: import org.openrdf.model.Resource;
014: import org.openrdf.model.util.GraphUtil;
015: import org.openrdf.model.util.GraphUtilException;
016: import org.openrdf.sail.config.SailConfigException;
017: import org.openrdf.sail.config.SailImplConfigBase;
018:
019: /**
020: * @author Arjohn Kampman
021: */
022: public class NativeStoreConfig extends SailImplConfigBase {
023:
024: /*-----------*
025: * Variables *
026: *-----------*/
027:
028: private String tripleIndexes;
029:
030: private boolean forceSync = false;
031:
032: /*--------------*
033: * Constructors *
034: *--------------*/
035:
036: public NativeStoreConfig() {
037: super (NativeStoreFactory.SAIL_TYPE);
038: }
039:
040: public NativeStoreConfig(String tripleIndexes) {
041: this ();
042: setTripleIndexes(tripleIndexes);
043: }
044:
045: public NativeStoreConfig(String tripleIndexes, boolean forceSync) {
046: this (tripleIndexes);
047: setForceSync(forceSync);
048: }
049:
050: /*---------*
051: * Methods *
052: *---------*/
053:
054: public String getTripleIndexes() {
055: return tripleIndexes;
056: }
057:
058: public void setTripleIndexes(String tripleIndexes) {
059: this .tripleIndexes = tripleIndexes;
060: }
061:
062: public boolean getForceSync() {
063: return forceSync;
064: }
065:
066: public void setForceSync(boolean forceSync) {
067: this .forceSync = forceSync;
068: }
069:
070: @Override
071: public Resource export(Graph graph) {
072: Resource implNode = super .export(graph);
073:
074: if (tripleIndexes != null) {
075: graph.add(implNode, TRIPLE_INDEXES, graph.getValueFactory()
076: .createLiteral(tripleIndexes));
077: }
078: if (forceSync) {
079: graph.add(implNode, FORCE_SYNC, graph.getValueFactory()
080: .createLiteral(forceSync));
081: }
082:
083: return implNode;
084: }
085:
086: @Override
087: public void parse(Graph graph, Resource implNode)
088: throws SailConfigException {
089: super .parse(graph, implNode);
090:
091: try {
092: Literal tripleIndexLit = GraphUtil
093: .getOptionalObjectLiteral(graph, implNode,
094: TRIPLE_INDEXES);
095: if (tripleIndexLit != null) {
096: setTripleIndexes((tripleIndexLit).getLabel());
097: }
098:
099: Literal forceSyncLit = GraphUtil.getOptionalObjectLiteral(
100: graph, implNode, FORCE_SYNC);
101: if (forceSyncLit != null) {
102: try {
103: setForceSync(forceSyncLit.booleanValue());
104: } catch (IllegalArgumentException e) {
105: throw new SailConfigException(
106: "Boolean value required for " + FORCE_SYNC
107: + " property, found "
108: + forceSyncLit);
109: }
110: }
111: } catch (GraphUtilException e) {
112: throw new SailConfigException(e.getMessage(), e);
113: }
114: }
115: }
|