http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreConstants.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreConstants.java b/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreConstants.java new file mode 100644 index 0000000..5311bd9 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreConstants.java @@ -0,0 +1,151 @@ +package mvm.rya.api; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import mvm.rya.api.domain.RyaSchema; +import mvm.rya.api.domain.RyaType; +import mvm.rya.api.domain.RyaURI; +import org.apache.hadoop.io.Text; +import org.openrdf.model.Literal; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.ValueFactoryImpl; + +public class RdfCloudTripleStoreConstants { + + public static final String NAMESPACE = RyaSchema.NAMESPACE; + public static final String AUTH_NAMESPACE = RyaSchema.AUTH_NAMESPACE; + public static ValueFactory VALUE_FACTORY = ValueFactoryImpl.getInstance(); + public static URI RANGE = VALUE_FACTORY.createURI(NAMESPACE, "range"); + public static URI PARTITION_TIMERANGE = VALUE_FACTORY.createURI("urn:mvm.mmrts.partition.rdf/08/2011#", "timeRange"); + public static Literal EMPTY_LITERAL = VALUE_FACTORY.createLiteral(0); + public static final byte EMPTY_BYTES[] = new byte[0]; + public static final Text EMPTY_TEXT = new Text(); + + public static final Long MAX_MEMORY = 10000000l; + public static final Long MAX_TIME = 60000l; + public static final Integer NUM_THREADS = 4; + +// public static final String TS = "ts"; +// public static final Text TS_TXT = new Text(TS); + +// public static final String INFO = "info"; +// public static final Text INFO_TXT = new Text(INFO); + + public static final String SUBJECT_CF = "s"; + public static final Text SUBJECT_CF_TXT = new Text(SUBJECT_CF); + public static final String PRED_CF = "p"; + public static final Text PRED_CF_TXT = new Text(PRED_CF); + public static final String OBJ_CF = "o"; + public static final Text OBJ_CF_TXT = new Text(OBJ_CF); + public static final String SUBJECTOBJECT_CF = "so"; + public static final Text SUBJECTOBJECT_CF_TXT = new Text(SUBJECTOBJECT_CF); + public static final String SUBJECTPRED_CF = "sp"; + public static final Text SUBJECTPRED_CF_TXT = new Text(SUBJECTPRED_CF); + public static final String PREDOBJECT_CF = "po"; + public static final Text PREDOBJECT_CF_TXT = new Text(PREDOBJECT_CF); + + public static final String TBL_PRFX_DEF = "rya_"; + public static final String TBL_SPO_SUFFIX = "spo"; + public static final String TBL_PO_SUFFIX = "po"; + public static final String TBL_OSP_SUFFIX = "osp"; + public static final String TBL_EVAL_SUFFIX = "eval"; + public static final String TBL_STATS_SUFFIX = "prospects"; + public static final String TBL_SEL_SUFFIX = "selectivity"; + public static final String TBL_NS_SUFFIX = "ns"; + public static String TBL_SPO = TBL_PRFX_DEF + TBL_SPO_SUFFIX; + public static String TBL_PO = TBL_PRFX_DEF + TBL_PO_SUFFIX; + public static String TBL_OSP = TBL_PRFX_DEF + TBL_OSP_SUFFIX; + public static String TBL_EVAL = TBL_PRFX_DEF + TBL_EVAL_SUFFIX; + public static String TBL_STATS = TBL_PRFX_DEF + TBL_STATS_SUFFIX; + public static String TBL_SEL = TBL_PRFX_DEF + TBL_SEL_SUFFIX; + public static String TBL_NAMESPACE = TBL_PRFX_DEF + TBL_NS_SUFFIX; + + public static Text TBL_SPO_TXT = new Text(TBL_SPO); + public static Text TBL_PO_TXT = new Text(TBL_PO); + public static Text TBL_OSP_TXT = new Text(TBL_OSP); + public static Text TBL_EVAL_TXT = new Text(TBL_EVAL); + public static Text TBL_NAMESPACE_TXT = new Text(TBL_NAMESPACE); + + public static void prefixTables(String prefix) { + if (prefix == null) + prefix = TBL_PRFX_DEF; + TBL_SPO = prefix + TBL_SPO_SUFFIX; + TBL_PO = prefix + TBL_PO_SUFFIX; + TBL_OSP = prefix + TBL_OSP_SUFFIX; + TBL_EVAL = prefix + TBL_EVAL_SUFFIX; + TBL_NAMESPACE = prefix + TBL_NS_SUFFIX; + + TBL_SPO_TXT = new Text(TBL_SPO); + TBL_PO_TXT = new Text(TBL_PO); + TBL_OSP_TXT = new Text(TBL_OSP); + TBL_EVAL_TXT = new Text(TBL_EVAL); + TBL_NAMESPACE_TXT = new Text(TBL_NAMESPACE); + } + + public static final String INFO_NAMESPACE = "namespace"; + public static final Text INFO_NAMESPACE_TXT = new Text(INFO_NAMESPACE); + + public static final byte DELIM_BYTE = 0; + public static final byte TYPE_DELIM_BYTE = 1; + public static final byte LAST_BYTE = -1; //0xff + public static final byte[] LAST_BYTES = new byte[]{LAST_BYTE}; + public static final byte[] TYPE_DELIM_BYTES = new byte[]{TYPE_DELIM_BYTE}; + public static final String DELIM = "\u0000"; + public static final String DELIM_STOP = "\u0001"; + public static final String LAST = "\uFFDD"; + public static final String TYPE_DELIM = new String(TYPE_DELIM_BYTES); + public static final byte[] DELIM_BYTES = DELIM.getBytes(); + public static final byte[] DELIM_STOP_BYTES = DELIM_STOP.getBytes(); + + + /* RECORD TYPES */ + public static final int URI_MARKER = 7; + + public static final int BNODE_MARKER = 8; + + public static final int PLAIN_LITERAL_MARKER = 9; + + public static final int LANG_LITERAL_MARKER = 10; + + public static final int DATATYPE_LITERAL_MARKER = 11; + + public static final int EOF_MARKER = 127; + + // public static final Authorizations ALL_AUTHORIZATIONS = new Authorizations( + // "_"); + + public static enum TABLE_LAYOUT { + SPO, PO, OSP + } + + //TODO: This should be in a version file somewhere + public static URI RTS_SUBJECT = VALUE_FACTORY.createURI(NAMESPACE, "rts"); + public static RyaURI RTS_SUBJECT_RYA = new RyaURI(RTS_SUBJECT.stringValue()); + public static URI RTS_VERSION_PREDICATE = VALUE_FACTORY.createURI(NAMESPACE, "version"); + public static RyaURI RTS_VERSION_PREDICATE_RYA = new RyaURI(RTS_VERSION_PREDICATE.stringValue()); + public static final Value VERSION = VALUE_FACTORY.createLiteral("3.0.0"); + public static RyaType VERSION_RYA = new RyaType(VERSION.stringValue()); + + public static String RYA_CONFIG_AUTH = "RYACONFIG"; +}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreStatement.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreStatement.java b/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreStatement.java new file mode 100644 index 0000000..4a13c01 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreStatement.java @@ -0,0 +1,72 @@ +package mvm.rya.api; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import org.openrdf.model.Resource; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.impl.ContextStatementImpl; +import org.openrdf.model.impl.StatementImpl; + +import java.util.ArrayList; +import java.util.Collection; + +public class RdfCloudTripleStoreStatement extends StatementImpl { + + private Resource[] contexts; //TODO: no blank nodes + + public RdfCloudTripleStoreStatement(Resource subject, URI predicate, Value object) { + super(subject, predicate, object); + } + + public RdfCloudTripleStoreStatement(Resource subject, URI predicate, Value object, + Resource... contexts) { + super(subject, predicate, object); + this.contexts = contexts; + } + + public Resource[] getContexts() { + return contexts; + } + + public Collection<Statement> getStatements() { + Collection<Statement> statements = new ArrayList<Statement>(); + + if (getContexts() != null && getContexts().length > 1) { + for (Resource contxt : getContexts()) { + statements.add(new ContextStatementImpl(getSubject(), + getPredicate(), getObject(), contxt)); + } + } else + statements.add(this); + + return statements; + } + + @Override + public Resource getContext() { + if (contexts == null || contexts.length == 0) + return null; + else return contexts[0]; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreUtils.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreUtils.java b/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreUtils.java new file mode 100644 index 0000000..eeadb9b --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/RdfCloudTripleStoreUtils.java @@ -0,0 +1,420 @@ +package mvm.rya.api; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import mvm.rya.api.layout.TableLayoutStrategy; +import mvm.rya.api.layout.TablePrefixLayoutStrategy; +import org.openrdf.model.Literal; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.BNodeImpl; +import org.openrdf.model.impl.LiteralImpl; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.model.impl.ValueFactoryImpl; + +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; + +public class RdfCloudTripleStoreUtils { + + public static ValueFactory valueFactory = new ValueFactoryImpl(); + public static final Pattern literalPattern = Pattern.compile("^\"(.*?)\"((\\^\\^<(.+?)>)$|(@(.{2}))$)"); + +// public static byte[] writeValue(Value value) throws IOException { +// return RdfIO.writeValue(value); +//// if (value == null) +//// return new byte[]{}; +//// ByteArrayDataOutput dataOut = ByteStreams.newDataOutput(); +//// if (value instanceof URI) { +//// dataOut.writeByte(RdfCloudTripleStoreConstants.URI_MARKER); +//// writeString(((URI) value).toString(), dataOut); +//// } else if (value instanceof BNode) { +//// dataOut.writeByte(RdfCloudTripleStoreConstants.BNODE_MARKER); +//// writeString(((BNode) value).getID(), dataOut); +//// } else if (value instanceof Literal) { +//// Literal lit = (Literal) value; +//// +//// String label = lit.getLabel(); +//// String language = lit.getLanguage(); +//// URI datatype = lit.getDatatype(); +//// +//// if (datatype != null) { +//// dataOut.writeByte(RdfCloudTripleStoreConstants.DATATYPE_LITERAL_MARKER); +//// writeString(label, dataOut); +//// dataOut.write(writeValue(datatype)); +//// } else if (language != null) { +//// dataOut.writeByte(RdfCloudTripleStoreConstants.LANG_LITERAL_MARKER); +//// writeString(label, dataOut); +//// writeString(language, dataOut); +//// } else { +//// dataOut.writeByte(RdfCloudTripleStoreConstants.PLAIN_LITERAL_MARKER); +//// writeString(label, dataOut); +//// } +//// } else { +//// throw new IllegalArgumentException("unexpected value type: " +//// + value.getClass()); +//// } +//// return dataOut.toByteArray(); +// } + +// public static Value readValue(ByteArrayDataInput dataIn, ValueFactory vf) +// throws IOException, ClassCastException { +// return RdfIO.readValue(dataIn, vf, DELIM_BYTE); +//// int valueTypeMarker; +//// try { +//// valueTypeMarker = dataIn.readByte(); +//// } catch (Exception e) { +//// return null; +//// } +//// +//// Value ret = null; +//// if (valueTypeMarker == RdfCloudTripleStoreConstants.URI_MARKER) { +//// String uriString = readString(dataIn); +//// ret = vf.createURI(uriString); +//// } else if (valueTypeMarker == RdfCloudTripleStoreConstants.BNODE_MARKER) { +//// String bnodeID = readString(dataIn); +//// ret = vf.createBNode(bnodeID); +//// } else if (valueTypeMarker == RdfCloudTripleStoreConstants.PLAIN_LITERAL_MARKER) { +//// String label = readString(dataIn); +//// ret = vf.createLiteral(label); +//// } else if (valueTypeMarker == RdfCloudTripleStoreConstants.LANG_LITERAL_MARKER) { +//// String label = readString(dataIn); +//// String language = readString(dataIn); +//// ret = vf.createLiteral(label, language); +//// } else if (valueTypeMarker == RdfCloudTripleStoreConstants.DATATYPE_LITERAL_MARKER) { +//// String label = readString(dataIn); +//// URI datatype = (URI) readValue(dataIn, vf); +//// ret = vf.createLiteral(label, datatype); +//// } else { +//// throw new InvalidValueTypeMarkerRuntimeException(valueTypeMarker, "Invalid value type marker: " +//// + valueTypeMarker); +//// } +//// +//// return ret; +// } + +// public static void writeString(String s, ByteArrayDataOutput dataOut) +// throws IOException { +// dataOut.writeUTF(s); +// } +// +// public static String readString(ByteArrayDataInput dataIn) +// throws IOException { +// return dataIn.readUTF(); +// } +// +// public static byte[] writeContexts(Resource... contexts) throws IOException { +// if (contexts != null) { +// ByteArrayDataOutput cntxout = ByteStreams.newDataOutput(); +// for (Resource resource : contexts) { +// final byte[] context_bytes = RdfCloudTripleStoreUtils +// .writeValue(resource); +// cntxout.write(context_bytes); +// cntxout.write(RdfCloudTripleStoreConstants.DELIM_BYTES); +// } +// return cntxout.toByteArray(); +// } else +// return new byte[]{}; +// } +// +// public static List<Resource> readContexts(byte[] cont_arr, ValueFactory vf) +// throws IOException { +// List<Resource> contexts = new ArrayList<Resource>(); +// String conts_str = new String(cont_arr); +// String[] split = conts_str.split(RdfCloudTripleStoreConstants.DELIM); +// for (String string : split) { +// contexts.add((Resource) RdfCloudTripleStoreUtils.readValue(ByteStreams +// .newDataInput(string.getBytes()), vf)); +// } +// return contexts; +// } + +// public static Statement translateStatementFromRow(ByteArrayDataInput input, Text context, TABLE_LAYOUT tble, ValueFactory vf) throws IOException { +// Resource subject; +// URI predicate; +// Value object; +// if (TABLE_LAYOUT.SPO.equals(tble)) { +// subject = (Resource) RdfCloudTripleStoreUtils.readValue(input, vf); +// predicate = (URI) RdfCloudTripleStoreUtils.readValue(input, vf); +// object = RdfCloudTripleStoreUtils.readValue(input, vf); +// } else if (TABLE_LAYOUT.OSP.equals(tble)) { +// object = RdfCloudTripleStoreUtils.readValue(input, vf); +// subject = (Resource) RdfCloudTripleStoreUtils.readValue(input, vf); +// predicate = (URI) RdfCloudTripleStoreUtils.readValue(input, vf); +// } else if (TABLE_LAYOUT.PO.equals(tble)) { +// predicate = (URI) RdfCloudTripleStoreUtils.readValue(input, vf); +// object = RdfCloudTripleStoreUtils.readValue(input, vf); +// subject = (Resource) RdfCloudTripleStoreUtils.readValue(input, vf); +// } else { +// throw new IllegalArgumentException("Table[" + tble + "] is not valid"); +// } +// if (context == null || INFO_TXT.equals(context)) +// return new StatementImpl(subject, predicate, object); //default graph +// else +// return new ContextStatementImpl(subject, predicate, object, (Resource) readValue(ByteStreams.newDataInput(context.getBytes()), vf)); //TODO: Seems like a perf hog +// } + +// public static byte[] buildRowWith(byte[] bytes_one, byte[] bytes_two, byte[] bytes_three) throws IOException { +// ByteArrayDataOutput rowidout = ByteStreams.newDataOutput(); +// rowidout.write(bytes_one); +// rowidout.writeByte(DELIM_BYTE); +//// rowidout.write(RdfCloudTripleStoreConstants.DELIM_BYTES); +// rowidout.write(bytes_two); +// rowidout.writeByte(DELIM_BYTE); +//// rowidout.write(RdfCloudTripleStoreConstants.DELIM_BYTES); +// rowidout.write(bytes_three); +// return truncateRowId(rowidout.toByteArray()); +// } + +// public static byte[] truncateRowId(byte[] byteArray) { +// if (byteArray.length > 32000) { +// ByteArrayDataOutput stream = ByteStreams.newDataOutput(); +// stream.write(byteArray, 0, 32000); +// return stream.toByteArray(); +// } +// return byteArray; +// } + + + public static class CustomEntry<T, U> implements Map.Entry<T, U> { + + private T key; + private U value; + + public CustomEntry(T key, U value) { + this.key = key; + this.value = value; + } + + @Override + public T getKey() { + return key; + } + + @Override + public U getValue() { + return value; + } + + public T setKey(T key) { + this.key = key; + return this.key; + } + + @Override + public U setValue(U value) { + this.value = value; + return this.value; + } + + @Override + public String toString() { + return "CustomEntry{" + + "key=" + key + + ", value=" + value + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CustomEntry that = (CustomEntry) o; + + if (key != null ? !key.equals(that.key) : that.key != null) return false; + if (value != null ? !value.equals(that.value) : that.value != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = key != null ? key.hashCode() : 0; + result = 31 * result + (value != null ? value.hashCode() : 0); + return result; + } + } + + /** + * If value is a URI, then return as URI, otherwise return namespace/value as the URI + * + * @param namespace + * @param value + * @return + */ + public static URI convertToUri(String namespace, String value) { + if (value == null) + return null; + URI subjUri; + try { + subjUri = valueFactory.createURI(value); + } catch (Exception e) { + //not uri + if (namespace == null) + return null; + subjUri = valueFactory.createURI(namespace, value); + } + return subjUri; + } + + public static Literal convertToDataTypeLiteral(String s) { + int i = s.indexOf("^^"); + if (i != -1) { + String val = s.substring(1, i - 1); + int dt_i_start = i + 2; + int dt_i_end = s.length(); + if (s.charAt(dt_i_start) == '<') { + dt_i_start = dt_i_start + 1; + dt_i_end = dt_i_end - 1; + } + + String dataType = s.substring(dt_i_start, dt_i_end); + return valueFactory.createLiteral(val, valueFactory.createURI(dataType)); + } + return null; + } + + public static boolean isDataTypeLiteral(String lit) { + return lit != null && lit.indexOf("^^") != -1; + } + + public static boolean isUri(String uri) { + if (uri == null) return false; + try { + valueFactory.createURI(uri); + } catch (Exception e) { + return false; + } + return true; + } + + +// public static boolean isQueryTimeBased(Configuration conf) { +// return (conf != null && conf.getBoolean(RdfCloudTripleStoreConfiguration.CONF_ISQUERYTIMEBASED, false)); +// } +// +// public static void setQueryTimeBased(Configuration conf, boolean timeBased) { +// if (conf != null) +// conf.setBoolean(RdfCloudTripleStoreConfiguration.CONF_ISQUERYTIMEBASED, isQueryTimeBased(conf) || timeBased); +// } + + +// public static void addTimeIndexUri(Configuration conf, URI timeUri, Class<? extends TtlValueConverter> ttlValueConvClass) { +// String[] timeIndexUris = conf.getStrings(RdfCloudTripleStoreConfiguration.CONF_TIMEINDEXURIS); +// if (timeIndexUris == null) +// timeIndexUris = new String[0]; +// List<String> stringList = new ArrayList<String>(Arrays.asList(timeIndexUris)); +// String timeUri_s = timeUri.stringValue(); +// if (!stringList.contains(timeUri_s)) +// stringList.add(timeUri_s); +// conf.setStrings(RdfCloudTripleStoreConfiguration.CONF_TIMEINDEXURIS, stringList.toArray(new String[stringList.size()])); +// conf.set(timeUri_s, ttlValueConvClass.getName()); +// } + +// public static Class<? extends TtlValueConverter> getTtlValueConverter(Configuration conf, URI predicate) throws ClassNotFoundException { +// if (predicate == null) +// return null; +// +// String[] s = conf.getStrings(RdfCloudTripleStoreConfiguration.CONF_TIMEINDEXURIS); +// if (s == null) +// return null; +// +// for (String uri : s) { +// if (predicate.stringValue().equals(uri)) { +// return (Class<? extends TtlValueConverter>) RdfCloudTripleStoreUtils.class.getClassLoader().loadClass(conf.get(uri)); +// } +// } +// return null; +// } + + public static String layoutToTable(TABLE_LAYOUT layout, RdfCloudTripleStoreConfiguration conf) { + TableLayoutStrategy tableLayoutStrategy = conf.getTableLayoutStrategy(); + return layoutToTable(layout, tableLayoutStrategy); + } + + public static String layoutToTable(TABLE_LAYOUT layout, TableLayoutStrategy tableLayoutStrategy) { + if (tableLayoutStrategy == null) { + tableLayoutStrategy = new TablePrefixLayoutStrategy(); + } + switch (layout) { + case SPO: { + return tableLayoutStrategy.getSpo(); + } + case PO: { + return tableLayoutStrategy.getPo(); + } + case OSP: { + return tableLayoutStrategy.getOsp(); + } + } + return null; + } + + public static String layoutPrefixToTable(TABLE_LAYOUT layout, String prefix) { + return layoutToTable(layout, new TablePrefixLayoutStrategy(prefix)); + } + + //helper methods to createValue + public static Value createValue(String resource) { + if (isBNode(resource)) + return new BNodeImpl(resource.substring(2)); + Literal literal; + if ((literal = makeLiteral(resource)) != null) + return literal; + if (resource.contains(":") || resource.contains("/") || resource.contains("#")) { + return new URIImpl(resource); + } else { + throw new RuntimeException((new StringBuilder()).append(resource).append(" is not a valid URI, blank node, or literal value").toString()); + } + } + + public static boolean isBNode(String resource) { + return resource.length() > 2 && resource.startsWith("_:"); + } + + public static boolean isLiteral(String resource) { + return literalPattern.matcher(resource).matches() || resource.startsWith("\"") && resource.endsWith("\"") && resource.length() > 1; + } + + public static boolean isURI(String resource) { + return !isBNode(resource) && !isLiteral(resource) && (resource.contains(":") || resource.contains("/") || resource.contains("#")); + } + + public static Literal makeLiteral(String resource) { + Matcher matcher = literalPattern.matcher(resource); + if (matcher.matches()) + if (null != matcher.group(4)) + return new LiteralImpl(matcher.group(1), new URIImpl(matcher.group(4))); + else + return new LiteralImpl(matcher.group(1), matcher.group(6)); + if (resource.startsWith("\"") && resource.endsWith("\"") && resource.length() > 1) + return new LiteralImpl(resource.substring(1, resource.length() - 1)); + else + return null; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/BatchUpdatePCJ.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/BatchUpdatePCJ.java b/common/rya.api/src/main/java/org/apache/rya/api/client/BatchUpdatePCJ.java new file mode 100644 index 0000000..d6f3454 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/BatchUpdatePCJ.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * Batch update a PCJ index. + */ +@ParametersAreNonnullByDefault +public interface BatchUpdatePCJ { + + /** + * Batch update a specific PCJ index using the {@link Statement}s that are + * currently in the Rya instance. + * + * @param ryaInstanceName - The Rya instance whose PCJ will be updated. (not null) + * @param pcjId - Identifies the PCJ index to update. (not null) + * @throws InstanceDoesNotExistException No instance of Rya exists for the provided name. + * @throws PCJDoesNotExistException No PCJ exists for the provided PCJ ID. + * @throws RyaClientException Something caused the command to fail. + */ + public void batchUpdate(String ryaInstanceName, String pcjId) throws InstanceDoesNotExistException, PCJDoesNotExistException, RyaClientException; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/CreatePCJ.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/CreatePCJ.java b/common/rya.api/src/main/java/org/apache/rya/api/client/CreatePCJ.java new file mode 100644 index 0000000..ae22ffe --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/CreatePCJ.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * Create a new PCJ within the target instance of Rya. + */ +@ParametersAreNonnullByDefault +public interface CreatePCJ { + + /** + * Designate a new PCJ that will be maintained by the target instance of Rya. + * + * @param instanceName - Indicates which Rya instance will create and maintain + * the PCJ. (not null) + * @param sparql - The SPARQL query that will be maintained. (not null) + * @return The ID that was assigned to this newly created PCJ. + * @throws InstanceDoesNotExistException No instance of Rya exists for the provided name. + * @throws RyaClientException Something caused the command to fail. + */ + public String createPCJ(final String instanceName, String sparql) throws InstanceDoesNotExistException, RyaClientException; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/DeletePCJ.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/DeletePCJ.java b/common/rya.api/src/main/java/org/apache/rya/api/client/DeletePCJ.java new file mode 100644 index 0000000..92b6b71 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/DeletePCJ.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * Deletes a PCJ from an instance of Rya. + */ +@ParametersAreNonnullByDefault +public interface DeletePCJ { + + /** + * Deletes a PCJ from an instance of Rya. + * + * @param instanceName - Indicates which Rya instance is maintaining the PCJ. (not null) + * @param pcjId - The ID of the PCJ that will be deleted. (not null) + * @throws InstanceDoesNotExistException No instance of Rya exists for the provided name. + * @throws RyaClientException Something caused the command to fail. + */ + public void deletePCJ(String instanceName, final String pcjId) throws InstanceDoesNotExistException, RyaClientException; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/GetInstanceDetails.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/GetInstanceDetails.java b/common/rya.api/src/main/java/org/apache/rya/api/client/GetInstanceDetails.java new file mode 100644 index 0000000..536b5a8 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/GetInstanceDetails.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import javax.annotation.ParametersAreNonnullByDefault; + +import com.google.common.base.Optional; + +import mvm.rya.api.instance.RyaDetails; + +/** + * Get configuration and maintenance information about a specific instance of Rya. + */ +@ParametersAreNonnullByDefault +public interface GetInstanceDetails { + + /** + * Get configuration and maintenance information about a specific instance of Rya. + * + * @param instanceName - Indicates which Rya instance to fetch the details from. (not null) + * @return The {@link RyaDetails} that describe the instance of Rya. If this is + * an older version of Rya, then there may not be any details to fetch. If + * this is the case, empty is returned. + * @throws InstanceDoesNotExistException No instance of Rya exists for the provided name. + * @throws RyaClientException Something caused the command to fail. + */ + public Optional<RyaDetails> getDetails(final String instanceName) throws InstanceDoesNotExistException, RyaClientException; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/Install.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/Install.java b/common/rya.api/src/main/java/org/apache/rya/api/client/Install.java new file mode 100644 index 0000000..28a0dc5 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/Install.java @@ -0,0 +1,268 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import static java.util.Objects.requireNonNull; + +import java.util.Objects; + +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import com.google.common.base.Optional; + +/** + * Installs a new instance of Rya. + */ +@ParametersAreNonnullByDefault +public interface Install { + + /** + * Install a new instance of Rya. + * + * @param instanceName - Indicates the name of the Rya instance to install. (not null) + * @param installConfig - Configures how the Rya instance will operate. The + * instance name that is in this variable must match the {@code instanceName}. (not null) + * @throws DuplicateInstanceNameException A Rya instance already exists for the provided name. + * @throws RyaClientException Something caused the command to fail. + */ + public void install(final String instanceName, final InstallConfiguration installConfig) throws DuplicateInstanceNameException, RyaClientException; + + /** + * A Rya instance already exists for the provided name. + */ + public static class DuplicateInstanceNameException extends RyaClientException { + private static final long serialVersionUID = 1L; + + public DuplicateInstanceNameException(final String message) { + super(message); + } + } + + /** + * Configures how an instance of Rya will be configured when it is installed. + */ + @Immutable + @ParametersAreNonnullByDefault + public static class InstallConfiguration { + + private final boolean enableTableHashPrefix; + private final boolean enableFreeTextIndex; + private final boolean enableGeoIndex; + private final boolean enableEntityCentricIndex; + private final boolean enableTemporalIndex; + private final boolean enablePcjIndex; + private final Optional<String> fluoPcjAppName; + + /** + * Use a {@link Builder} to create instances of this class. + */ + private InstallConfiguration( + final boolean enableTableHashPrefix, + final boolean enableFreeTextIndex, + final boolean enableGeoIndex, + final boolean enableEntityCentricIndex, + final boolean enableTemporalIndex, + final boolean enablePcjIndex, + final Optional<String> fluoPcjAppName) { + this.enableTableHashPrefix = requireNonNull(enableTableHashPrefix); + this.enableFreeTextIndex = requireNonNull(enableFreeTextIndex); + this.enableGeoIndex = requireNonNull(enableGeoIndex); + this.enableEntityCentricIndex = requireNonNull(enableEntityCentricIndex); + this.enableTemporalIndex = requireNonNull(enableTemporalIndex); + this.enablePcjIndex = requireNonNull(enablePcjIndex); + this.fluoPcjAppName = requireNonNull(fluoPcjAppName); + } + + /** + * @return Whether or not the installed instance of Rya will include table prefix hashing. + */ + public boolean isTableHashPrefixEnabled() { + return enableTableHashPrefix; + } + + /** + * @return Whether or not the installed instance of Rya will maintain a Free Text index. + */ + public boolean isFreeTextIndexEnabled() { + return enableFreeTextIndex; + } + + /** + * @return Whether or not the installed instance of Rya will maintain a Geospatial index. + */ + public boolean isGeoIndexEnabled() { + return enableGeoIndex; + } + + /** + * @return Whether or not the installed instance of Rya will maintain an Entity Centric index. + */ + public boolean isEntityCentrixIndexEnabled() { + return enableEntityCentricIndex; + } + + /** + * @return Whether or not the installed instance of Rya will maintain a Temporal index. + */ + public boolean isTemporalIndexEnabled() { + return enableTemporalIndex; + } + + /** + * @return Whether or not the installed instance of Rya will maintain a PCJ index. + */ + public boolean isPcjIndexEnabled() { + return enablePcjIndex; + } + + /** + * @return The name of the Fluo application that updates this instance of Rya's PCJs. + * Optional because this does not have to be the update paradigm used. + */ + public Optional<String> getFluoPcjAppName() { + return fluoPcjAppName; + } + + @Override + public int hashCode() { + return Objects.hash( + enableTableHashPrefix, + enableFreeTextIndex, + enableGeoIndex, + enableEntityCentricIndex, + enableTemporalIndex, + enablePcjIndex, + fluoPcjAppName); + } + + @Override + public boolean equals(final Object obj) { + if(this == obj) { + return true; + } + if(obj instanceof InstallConfiguration) { + final InstallConfiguration config = (InstallConfiguration) obj; + return enableTableHashPrefix == config.enableTableHashPrefix && + enableFreeTextIndex == config.enableFreeTextIndex && + enableGeoIndex == config.enableGeoIndex && + enableEntityCentricIndex == config.enableEntityCentricIndex && + enableTemporalIndex == config.enableTemporalIndex && + enablePcjIndex == config.enablePcjIndex && + Objects.equals(fluoPcjAppName, config.fluoPcjAppName); + } + return false; + } + + /** + * @return An empty instance of {@link Builder}. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Builds instances of {@link InstallConfiguration}. + */ + @ParametersAreNonnullByDefault + public static class Builder { + private boolean enableTableHashPrefix = false; + private boolean enableFreeTextIndex = false; + private boolean enableGeoIndex = false; + private boolean enableEntityCentricIndex = false; + private boolean enableTemporalIndex = false; + private boolean enablePcjIndex = false; + private String fluoPcjAppName = null; + + /** + * @param enabled - Whether or not the installed instance of Rya will include table prefix hashing. + * @return This {@link Builder} so that method invocations may be chained. + */ + public Builder setEnableTableHashPrefix(final boolean enabled) { + enableTableHashPrefix = enabled; + return this; + } + + /** + * @param enabled - Whether or not the installed instance of Rya will maintain a Free Text index. + * @return This {@link Builder} so that method invocations may be chained. + */ + public Builder setEnableFreeTextIndex(final boolean enabled) { + enableFreeTextIndex = enabled; + return this; + } + + /** + * @param enabled - Whether or not the installed instance of Rya will maintain a Geospatial index. + * @return This {@link Builder} so that method invocations may be chained. + */ + public Builder setEnableGeoIndex(final boolean enabled) { + enableGeoIndex = enabled; + return this; + } + + /** + * @param enabled - Whether or not the installed instance of Rya will maintain an Entity Centric index. + * @return This {@link Builder} so that method invocations may be chained. + */ + public Builder setEnableEntityCentricIndex(final boolean enabled) { + enableEntityCentricIndex = enabled; + return this; + } + + /** + * @param enabled - Whether or not the installed instance of Rya will maintain a Temporal index. + * @return This {@link Builder} so that method invocations may be chained. + */ + public Builder setEnableTemporalIndex(final boolean enabled) { + enableTemporalIndex = enabled; + return this; + } + + /** + * @param enabled - Whether or not the installed instance of Rya will maintain a PCJ index. + * @return This {@link Builder} so that method invocations may be chained. + */ + public Builder setEnablePcjIndex(final boolean enabled) { + enablePcjIndex = enabled; + return this; + } + + public Builder setFluoPcjAppName(@Nullable final String fluoPcjAppName) { + this.fluoPcjAppName = fluoPcjAppName; + return this; + } + + /** + * @return Builds an instance of {@link InstallConfiguration} using this builder's values. + */ + public InstallConfiguration build() { + return new InstallConfiguration( + enableTableHashPrefix, + enableFreeTextIndex, + enableGeoIndex, + enableEntityCentricIndex, + enableTemporalIndex, + enablePcjIndex, + Optional.fromNullable(fluoPcjAppName)); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/InstanceDoesNotExistException.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/InstanceDoesNotExistException.java b/common/rya.api/src/main/java/org/apache/rya/api/client/InstanceDoesNotExistException.java new file mode 100644 index 0000000..c8cc0aa --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/InstanceDoesNotExistException.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * One of the {@link RyaClient} commands could not execute because the connected + * instance of Rya does not exist. + */ +@ParametersAreNonnullByDefault +public class InstanceDoesNotExistException extends RyaClientException { + private static final long serialVersionUID = 1L; + + public InstanceDoesNotExistException(final String message) { + super(message); + } + + public InstanceDoesNotExistException(final String message, final Throwable cause) { + super(message, cause); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/InstanceExists.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/InstanceExists.java b/common/rya.api/src/main/java/org/apache/rya/api/client/InstanceExists.java new file mode 100644 index 0000000..6f26fc6 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/InstanceExists.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * Checks if an instance of Rya has been installed. + */ +@ParametersAreNonnullByDefault +public interface InstanceExists { + + /** + * Checks if an instance of Rya has been installed. + * + * @param instanceName - The name to check. (not null) + * @return {@code true} If an instance of Rya exists with the provided name; otherwise {@code false}. + * @throws RyaClientException Something caused the command to fail. + */ + public boolean exists(String instanceName) throws RyaClientException; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/ListInstances.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/ListInstances.java b/common/rya.api/src/main/java/org/apache/rya/api/client/ListInstances.java new file mode 100644 index 0000000..5edfbc4 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/ListInstances.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import java.util.List; + +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * List the names of the installed Rya instances. + */ +@ParametersAreNonnullByDefault +public interface ListInstances { + + /** + * List the names of the installed Rya instances. + * + * @return The names of the installed Rya Instances. + * @throws RyaClientException Something caused the command to fail. + */ + public List<String> listInstances() throws RyaClientException; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/PCJDoesNotExistException.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/PCJDoesNotExistException.java b/common/rya.api/src/main/java/org/apache/rya/api/client/PCJDoesNotExistException.java new file mode 100644 index 0000000..89f095f --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/PCJDoesNotExistException.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * One of the {@link RyaClient} commands could not execute because the connected + * instance of Rya does not have a PCJ matching the provided PCJ ID. + */ +@ParametersAreNonnullByDefault +public class PCJDoesNotExistException extends RyaClientException { + private static final long serialVersionUID = 1L; + + public PCJDoesNotExistException(final String message) { + super(message); + } + + public PCJDoesNotExistException(final String message, final Throwable cause) { + super(message, cause); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClient.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClient.java b/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClient.java new file mode 100644 index 0000000..851a273 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClient.java @@ -0,0 +1,112 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import static java.util.Objects.requireNonNull; + +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +/** + * Provides access to a set of Rya functions. + */ +@Immutable +@ParametersAreNonnullByDefault +public class RyaClient { + // Administrative functions. + private final Install install; + private final CreatePCJ createPcj; + private final DeletePCJ deletePcj; + private final BatchUpdatePCJ batchUpdatePcj; + private final GetInstanceDetails getInstanceDetails; + private final InstanceExists instanceExists; + private final ListInstances listInstances; + + /** + * Constructs an instance of {@link RyaClient}. + */ + public RyaClient( + final Install install, + final CreatePCJ createPcj, + final DeletePCJ deletePcj, + final BatchUpdatePCJ batchUpdatePcj, + final GetInstanceDetails getInstanceDetails, + final InstanceExists instanceExists, + final ListInstances listInstances) { + this.install = requireNonNull(install); + this.createPcj = requireNonNull(createPcj); + this.deletePcj = requireNonNull(deletePcj); + this.batchUpdatePcj = requireNonNull(batchUpdatePcj); + this.getInstanceDetails = requireNonNull(getInstanceDetails); + this.instanceExists = requireNonNull(instanceExists); + this.listInstances = requireNonNull(listInstances); + } + + /** + * @return An instance of {@link Install} that is connected to a Rya storage. + */ + public Install getInstall() { + return install; + } + + /** + * @return An instance of {@link CreatePCJ} that is connected to a Rya storage + * if the Rya instance supports PCJ indexing. + */ + public CreatePCJ getCreatePCJ() { + return createPcj; + } + + /** + * @return An instance of {@link DeletePCJ} that is connected to a Rya storage + * if the Rya instance supports PCJ indexing. + */ + public DeletePCJ getDeletePCJ() { + return deletePcj; + } + + /** + * @return An instnace of {@link BatchUpdatePCJ} that is connected to a Rya storage + * if the Rya instance supports PCJ indexing. + */ + public BatchUpdatePCJ getBatchUpdatePCJ() { + return batchUpdatePcj; + } + + /** + * @return An instance of {@link GetInstanceDetails} that is connected to a Rya storage. + */ + public GetInstanceDetails getGetInstanceDetails() { + return getInstanceDetails; + } + + /** + * @return An instance of {@link ListInstances} that is connected to a Rya storage. + */ + public ListInstances getListInstances() { + return listInstances; + } + + /** + * @return An instance of {@link InstanceExists} that is connected to a Rya storage. + */ + public InstanceExists getInstanceExists() { + return instanceExists; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClientException.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClientException.java b/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClientException.java new file mode 100644 index 0000000..28c78aa --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClientException.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package mvm.rya.api.client; + +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * One of the {@link RyaClient} functions failed. + */ +@ParametersAreNonnullByDefault +public class RyaClientException extends Exception { + private static final long serialVersionUID = 1L; + + public RyaClientException(final String message) { + super(message); + } + + public RyaClientException(final String message, final Throwable cause) { + super(message, cause); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/date/DateTimeTtlValueConverter.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/date/DateTimeTtlValueConverter.java b/common/rya.api/src/main/java/org/apache/rya/api/date/DateTimeTtlValueConverter.java new file mode 100644 index 0000000..199b63d --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/date/DateTimeTtlValueConverter.java @@ -0,0 +1,80 @@ +package mvm.rya.api.date; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import org.openrdf.model.Value; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +/** + * Class DateTimeTtlValueConverter + * @deprecated 2 + */ +public class DateTimeTtlValueConverter implements TtlValueConverter { + + private Value start, stop; + private TimeZone timeZone = TimeZone.getTimeZone("Zulu"); + + @Override + public void convert(String ttl, String startTime) { + try { + long start_l, stop_l; + long ttl_l = Long.parseLong(ttl); + stop_l = System.currentTimeMillis(); + if (startTime != null) + stop_l = Long.parseLong(startTime); + start_l = stop_l - ttl_l; + + GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); + cal.setTimeZone(getTimeZone()); + cal.setTimeInMillis(start_l); + DatatypeFactory factory = DatatypeFactory.newInstance(); + start = vf.createLiteral(factory.newXMLGregorianCalendar(cal)); + + cal.setTimeInMillis(stop_l); + stop = vf.createLiteral(factory.newXMLGregorianCalendar(cal)); + } catch (DatatypeConfigurationException e) { + throw new RuntimeException("Exception occurred creating DataTypeFactory", e); + } + } + + @Override + public Value getStart() { + return start; + } + + @Override + public Value getStop() { + return stop; + } + + public TimeZone getTimeZone() { + return timeZone; + } + + public void setTimeZone(TimeZone timeZone) { + this.timeZone = timeZone; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/date/TimestampTtlStrValueConverter.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/date/TimestampTtlStrValueConverter.java b/common/rya.api/src/main/java/org/apache/rya/api/date/TimestampTtlStrValueConverter.java new file mode 100644 index 0000000..de4ff8b --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/date/TimestampTtlStrValueConverter.java @@ -0,0 +1,56 @@ +package mvm.rya.api.date; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import org.openrdf.model.Value; + +/** + * Class TimestampTtlValueConverter + * @deprecated + */ +public class TimestampTtlStrValueConverter implements TtlValueConverter { + + private Value start, stop; + + @Override + public void convert(String ttl, String startTime) { + long start_l, stop_l; + long ttl_l = Long.parseLong(ttl); + stop_l = System.currentTimeMillis(); + if (startTime != null) + stop_l = Long.parseLong(startTime); + start_l = stop_l - ttl_l; + + start = vf.createLiteral(start_l + ""); + stop = vf.createLiteral(stop_l + ""); + } + + @Override + public Value getStart() { + return start; + } + + @Override + public Value getStop() { + return stop; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/date/TimestampTtlValueConverter.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/date/TimestampTtlValueConverter.java b/common/rya.api/src/main/java/org/apache/rya/api/date/TimestampTtlValueConverter.java new file mode 100644 index 0000000..75366dc --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/date/TimestampTtlValueConverter.java @@ -0,0 +1,56 @@ +package mvm.rya.api.date; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import org.openrdf.model.Value; + +/** + * Class TimestampTtlValueConverter + * @deprecated + */ +public class TimestampTtlValueConverter implements TtlValueConverter { + + private Value start, stop; + + @Override + public void convert(String ttl, String startTime) { + long start_l, stop_l; + long ttl_l = Long.parseLong(ttl); + stop_l = System.currentTimeMillis(); + if (startTime != null) + stop_l = Long.parseLong(startTime); + start_l = stop_l - ttl_l; + + start = vf.createLiteral(start_l); + stop = vf.createLiteral(stop_l); + } + + @Override + public Value getStart() { + return start; + } + + @Override + public Value getStop() { + return stop; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/date/TtlValueConverter.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/date/TtlValueConverter.java b/common/rya.api/src/main/java/org/apache/rya/api/date/TtlValueConverter.java new file mode 100644 index 0000000..1ba9841 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/date/TtlValueConverter.java @@ -0,0 +1,41 @@ +package mvm.rya.api.date; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import org.openrdf.model.Value; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.ValueFactoryImpl; + +/** + * Class TtlValueConverter + * @deprecated + */ +public interface TtlValueConverter { + + ValueFactory vf = ValueFactoryImpl.getInstance(); + + public void convert(String ttl, String startTime); + + public Value getStart(); + + public Value getStop(); +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/domain/Node.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/Node.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/Node.java new file mode 100644 index 0000000..f5ca08c --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/Node.java @@ -0,0 +1,38 @@ +package mvm.rya.api.domain; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import org.openrdf.model.impl.URIImpl; + +/** + * A Node is an expected node in the global graph. This typing of the URI allows us to dictate the difference between a + * URI that is just an Attribute on the subject vs. a URI that is another subject Node in the global graph. It does not + * guarantee that the subject exists, just that there is an Edge to it. + */ +public class Node extends URIImpl { + public Node() { + } + + public Node(String uriString) { + super(uriString); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeURI.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeURI.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeURI.java new file mode 100644 index 0000000..67d5742 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeURI.java @@ -0,0 +1,52 @@ +package mvm.rya.api.domain; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import org.openrdf.model.URI; +import org.openrdf.model.Value; + +/** + * Created by IntelliJ IDEA. + * Date: 4/11/12 + * Time: 1:03 PM + * To change this template use File | Settings | File Templates. + */ +public class RangeURI extends RangeValue<URI> implements URI { + + public RangeURI(URI start, URI end) { + super(start, end); + } + + public RangeURI(RangeValue rangeValue) { + super((URI) rangeValue.getStart(), (URI) rangeValue.getEnd()); + } + + @Override + public String getNamespace() { + throw new UnsupportedOperationException("Ranges do not have a namespace"); + } + + @Override + public String getLocalName() { + throw new UnsupportedOperationException("Ranges do not have a localname"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeValue.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeValue.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeValue.java new file mode 100644 index 0000000..c27edfd --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RangeValue.java @@ -0,0 +1,72 @@ +package mvm.rya.api.domain; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import org.openrdf.model.Value; + +/** + * Created by IntelliJ IDEA. + * Date: 4/10/12 + * Time: 3:57 PM + * To change this template use File | Settings | File Templates. + */ +public class RangeValue<T extends Value> implements Value { + + private T start; + private T end; + + public RangeValue(T start, T end) { + this.start = start; + this.end = end; + } + + @Override + public String stringValue() { + throw new UnsupportedOperationException("Range is only supported at query time"); + } + + public T getStart() { + return start; + } + + public void setStart(T start) { + this.start = start; + } + + public T getEnd() { + return end; + } + + public void setEnd(T end) { + this.end = end; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("RangeValue"); + sb.append("{start=").append(start); + sb.append(", end=").append(end); + sb.append('}'); + return sb.toString(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaRange.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaRange.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaRange.java new file mode 100644 index 0000000..e99f451 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaRange.java @@ -0,0 +1,32 @@ +package mvm.rya.api.domain; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +/** + * Date: 7/17/12 + * Time: 10:02 AM + */ +public interface RyaRange { + public RyaType getStart(); + + public RyaType getStop(); +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/44a2dcf0/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaSchema.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaSchema.java b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaSchema.java new file mode 100644 index 0000000..6744d20 --- /dev/null +++ b/common/rya.api/src/main/java/org/apache/rya/api/domain/RyaSchema.java @@ -0,0 +1,43 @@ +package mvm.rya.api.domain; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +import mvm.rya.api.RdfCloudTripleStoreConstants; +import org.openrdf.model.URI; + +/** + * Date: 7/16/12 + * Time: 11:59 AM + */ +public class RyaSchema { + + public static final String NAMESPACE = "urn:mvm.rya/2012/05#"; + public static final String AUTH_NAMESPACE = "urn:mvm.rya/auth/2012/05#"; + public static final String BNODE_NAMESPACE = "urn:mvm.rya/bnode/2012/07#"; + + //datatypes + public static final URI NODE = RdfCloudTripleStoreConstants.VALUE_FACTORY.createURI(NAMESPACE, "node"); + public static final URI LANGUAGE = RdfCloudTripleStoreConstants.VALUE_FACTORY.createURI(NAMESPACE, "lang"); + + //functions + public static final URI RANGE = RdfCloudTripleStoreConstants.VALUE_FACTORY.createURI(NAMESPACE, "range"); +}
