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.memory.config;
007:
008: import static org.openrdf.sail.memory.config.MemoryStoreSchema.PERSIST;
009: import static org.openrdf.sail.memory.config.MemoryStoreSchema.SYNC_DELAY;
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 MemoryStoreConfig extends SailImplConfigBase {
023:
024: private boolean persist = false;
025:
026: private long syncDelay = 0L;
027:
028: public MemoryStoreConfig() {
029: super (MemoryStoreFactory.SAIL_TYPE);
030: }
031:
032: public MemoryStoreConfig(boolean persist) {
033: this ();
034: setPersist(persist);
035: }
036:
037: public MemoryStoreConfig(boolean persist, long syncDelay) {
038: this (persist);
039: setSyncDelay(syncDelay);
040: }
041:
042: public boolean getPersist() {
043: return persist;
044: }
045:
046: public void setPersist(boolean persist) {
047: this .persist = persist;
048: }
049:
050: public long getSyncDelay() {
051: return syncDelay;
052: }
053:
054: public void setSyncDelay(long syncDelay) {
055: this .syncDelay = syncDelay;
056: }
057:
058: @Override
059: public Resource export(Graph graph) {
060: Resource implNode = super .export(graph);
061:
062: if (persist) {
063: graph.add(implNode, PERSIST, graph.getValueFactory()
064: .createLiteral(persist));
065: }
066:
067: if (syncDelay != 0) {
068: graph.add(implNode, SYNC_DELAY, graph.getValueFactory()
069: .createLiteral(syncDelay));
070: }
071:
072: return implNode;
073: }
074:
075: @Override
076: public void parse(Graph graph, Resource implNode)
077: throws SailConfigException {
078: super .parse(graph, implNode);
079:
080: try {
081: Literal persistValue = GraphUtil.getOptionalObjectLiteral(
082: graph, implNode, PERSIST);
083: if (persistValue != null) {
084: try {
085: setPersist((persistValue).booleanValue());
086: } catch (IllegalArgumentException e) {
087: throw new SailConfigException(
088: "Boolean value required for " + PERSIST
089: + " property, found "
090: + persistValue);
091: }
092: }
093:
094: Literal syncDelayValue = GraphUtil
095: .getOptionalObjectLiteral(graph, implNode,
096: SYNC_DELAY);
097: if (syncDelayValue != null) {
098: try {
099: setSyncDelay((syncDelayValue).longValue());
100: } catch (NumberFormatException e) {
101: throw new SailConfigException(
102: "Long integer value required for "
103: + SYNC_DELAY + " property, found "
104: + syncDelayValue);
105: }
106: }
107: } catch (GraphUtilException e) {
108: throw new SailConfigException(e.getMessage(), e);
109: }
110: }
111: }
|