http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreConfiguration.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreConfiguration.java b/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreConfiguration.java new file mode 100644 index 0000000..077e268 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreConfiguration.java @@ -0,0 +1,506 @@ +package mvm.rya.api; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +import java.util.List; + +import mvm.rya.api.layout.TableLayoutStrategy; +import mvm.rya.api.layout.TablePrefixLayoutStrategy; +import mvm.rya.api.persist.RdfEvalStatsDAO; + +import org.apache.hadoop.conf.Configuration; +import org.openrdf.query.algebra.evaluation.QueryOptimizer; + +import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; + +/** + * Rdf triple store specific configuration + */ +public abstract class RdfCloudTripleStoreConfiguration extends Configuration { + + // public static final String CONF_ISQUERYTIMEBASED = "query.timebased"; + public static final String CONF_TTL = "query.ttl"; + public static final String CONF_STARTTIME = "query.startTime"; + // public static final String CONF_TIMEINDEXURIS = "query.timeindexuris"; + public static final String CONF_NUM_THREADS = "query.numthreads"; + public static final String CONF_PERFORMANT = "query.performant"; + public static final String CONF_INFER = "query.infer"; + public static final String CONF_USE_STATS = "query.usestats"; + public static final String CONF_USE_COMPOSITE = "query.usecompositecard"; + public static final String CONF_USE_SELECTIVITY = "query.useselectivity"; + public static final String CONF_TBL_PREFIX = "query.tblprefix"; + public static final String CONF_BATCH_SIZE = "query.batchsize"; + public static final String CONF_OFFSET = "query.offset"; + public static final String CONF_LIMIT = "query.limit"; + public static final String CONF_QUERYPLAN_FLAG = "query.printqueryplan"; + public static final String CONF_QUERY_AUTH = "query.auth"; + public static final String CONF_RESULT_FORMAT = "query.resultformat"; + public static final String CONF_CV = "conf.cv"; + public static final String CONF_TBL_SPO = "tbl.spo"; + public static final String CONF_TBL_PO = "tbl.po"; + public static final String CONF_TBL_OSP = "tbl.osp"; + public static final String CONF_TBL_NS = "tbl.ns"; + public static final String CONF_TBL_EVAL = "tbl.eval"; + public static final String CONF_PREFIX_ROW_WITH_HASH = "tbl.hashprefix"; + public static final String CONF_OPTIMIZERS = "query.optimizers"; + public static final String CONF_PCJ_OPTIMIZER = "pcj.query.optimizer"; + public static final String CONF_PCJ_TABLES = "pcj.index.tables"; + + + /** + * @deprecated use CONF_* + */ + public static final String BINDING_DISP_QUERYPLAN = CONF_QUERYPLAN_FLAG; + /** + * @deprecated use CONF_* + */ + public static final String BINDING_AUTH = CONF_QUERY_AUTH; + /** + * @deprecated use CONF_* + */ + public static final String BINDING_CV = CONF_CV; + /** + * @deprecated use CONF_* + */ + public static final String BINDING_TTL = CONF_TTL; + /** + * @deprecated use CONF_* + */ + public static final String BINDING_STARTTIME = CONF_STARTTIME; + /** + * @deprecated use CONF_* + */ + public static final String BINDING_PERFORMANT = CONF_PERFORMANT; + /** + * @deprecated use CONF_* + */ + public static final String BINDING_INFER = CONF_INFER; + /** + * @deprecated use CONF_* + */ + public static final String BINDING_USESTATS = CONF_USE_STATS; + /** + * @deprecated use CONF_* + */ + public static final String BINDING_OFFSET = CONF_OFFSET; + /** + * @deprecated use CONF_* + */ + public static final String BINDING_LIMIT = CONF_LIMIT; + + public static final String STATS_PUSH_EMPTY_RDFTYPE_DOWN = "conf.stats.rdftype.down"; + public static final String INFER_INCLUDE_INVERSEOF = "infer.include.inverseof"; + public static final String INFER_INCLUDE_SUBCLASSOF = "infer.include.subclassof"; + public static final String INFER_INCLUDE_SUBPROPOF = "infer.include.subpropof"; + public static final String INFER_INCLUDE_SYMMPROP = "infer.include.symmprop"; + public static final String INFER_INCLUDE_TRANSITIVEPROP = "infer.include.transprop"; + + public static final String RDF_DAO_CLASS = "class.rdf.dao"; + public static final String RDF_EVAL_STATS_DAO_CLASS = "class.rdf.evalstats"; + + public static final String REGEX_SUBJECT = "query.regex.subject"; + public static final String REGEX_PREDICATE = "query.regex.predicate"; + public static final String REGEX_OBJECT = "query.regex.object"; + private static final String[] EMPTY_STR_ARR = new String[0]; + + private TableLayoutStrategy tableLayoutStrategy = new TablePrefixLayoutStrategy(); + + public RdfCloudTripleStoreConfiguration() { + } + + public RdfCloudTripleStoreConfiguration(Configuration other) { + super(other); + if (other instanceof RdfCloudTripleStoreConfiguration) { + setTableLayoutStrategy(((RdfCloudTripleStoreConfiguration) other).getTableLayoutStrategy()); + } + } + + public abstract RdfCloudTripleStoreConfiguration clone(); + + public TableLayoutStrategy getTableLayoutStrategy() { + return tableLayoutStrategy; + } + + public void setTableLayoutStrategy(TableLayoutStrategy tableLayoutStrategy) { + if (tableLayoutStrategy != null) { + this.tableLayoutStrategy = tableLayoutStrategy; + } else { + this.tableLayoutStrategy = new TablePrefixLayoutStrategy(); //default + } + set(CONF_TBL_SPO, this.tableLayoutStrategy.getSpo()); + set(CONF_TBL_PO, this.tableLayoutStrategy.getPo()); + set(CONF_TBL_OSP, this.tableLayoutStrategy.getOsp()); + set(CONF_TBL_NS, this.tableLayoutStrategy.getNs()); + set(CONF_TBL_EVAL, this.tableLayoutStrategy.getEval()); + } + + public Long getTtl() { + String val = get(CONF_TTL); + if (val != null) { + return Long.valueOf(val); + } + return null; + } + + public void setTtl(Long ttl) { + Preconditions.checkNotNull(ttl); + Preconditions.checkArgument(ttl >= 0, "ttl must be non negative"); + set(CONF_TTL, ttl.toString()); + } + + public Long getStartTime() { + String val = get(CONF_STARTTIME); + if (val != null) { + return Long.valueOf(val); + } + return null; + } + + public void setStartTime(Long startTime) { + Preconditions.checkNotNull(startTime); + Preconditions.checkArgument(startTime >= 0, "startTime must be non negative"); + set(CONF_STARTTIME, startTime.toString()); + } + + public Integer getNumThreads() { + return getInt(CONF_NUM_THREADS, 2); + } + + public void setNumThreads(Integer numThreads) { + Preconditions.checkNotNull(numThreads); + Preconditions.checkArgument(numThreads > 0, "numThreads must be greater than 0"); + setInt(CONF_NUM_THREADS, numThreads); + } + + public Boolean isPerformant() { + return getBoolean(CONF_PERFORMANT, true); + } + + public void setPerformant(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(CONF_PERFORMANT, val); + } + + public Boolean isInfer() { + return getBoolean(CONF_INFER, true); + } + + public void setInfer(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(CONF_INFER, val); + } + + public Boolean isUseStats() { + return getBoolean(CONF_USE_STATS, false); + } + + public void setUseStats(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(CONF_USE_STATS, val); + } + + public Boolean isUseSelectivity() { + return getBoolean(CONF_USE_SELECTIVITY, false); + } + + public void setUseSelectivity(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(CONF_USE_SELECTIVITY, val); + } + + public Boolean isPrefixRowsWithHash() { + return getBoolean(CONF_PREFIX_ROW_WITH_HASH, false); + } + + public void setPrefixRowsWithHash(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(CONF_PREFIX_ROW_WITH_HASH, val); + } + + public String getTablePrefix() { + return get(CONF_TBL_PREFIX, RdfCloudTripleStoreConstants.TBL_PRFX_DEF); + } + + public void setTablePrefix(String tablePrefix) { + Preconditions.checkNotNull(tablePrefix); + set(CONF_TBL_PREFIX, tablePrefix); + setTableLayoutStrategy(new TablePrefixLayoutStrategy(tablePrefix)); //TODO: Should we change the layout strategy + } + + public Integer getBatchSize() { + String val = get(CONF_BATCH_SIZE); + if (val != null) { + return Integer.valueOf(val); + } + return null; + } + + public void setBatchSize(Long batchSize) { + Preconditions.checkNotNull(batchSize); + Preconditions.checkArgument(batchSize > 0, "Batch Size must be greater than 0"); + setLong(CONF_BATCH_SIZE, batchSize); + } + + public Long getOffset() { + String val = get(CONF_OFFSET); + if (val != null) { + return Long.valueOf(val); + } + return null; + } + + public void setOffset(Long offset) { + Preconditions.checkNotNull(offset); + Preconditions.checkArgument(offset >= 0, "offset must be positive"); + setLong(CONF_OFFSET, offset); + } + + public Long getLimit() { + String val = get(CONF_LIMIT); + if (val != null) { + return Long.valueOf(val); + } + return null; + } + + public void setLimit(Long limit) { + Preconditions.checkNotNull(limit); + Preconditions.checkArgument(limit >= 0, "limit must be positive"); + setLong(CONF_LIMIT, limit); + } + + + public Boolean isDisplayQueryPlan() { + return getBoolean(CONF_QUERYPLAN_FLAG, false); + } + + public void setDisplayQueryPlan(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(CONF_QUERYPLAN_FLAG, val); + } + + /** + * @return + * @deprecated + */ + public String getAuth() { + return Joiner.on(",").join(getAuths()); + } + + /** + * @param auth + * @deprecated + */ + public void setAuth(String auth) { + Preconditions.checkNotNull(auth); + setStrings(CONF_QUERY_AUTH, auth); + } + + public String[] getAuths() { + return getStrings(CONF_QUERY_AUTH, EMPTY_STR_ARR); + } + + public void setAuths(String... auths) { + setStrings(CONF_QUERY_AUTH, auths); + } + + public String getEmit() { + return get(CONF_RESULT_FORMAT); + } + + public void setEmit(String emit) { + Preconditions.checkNotNull(emit); + set(CONF_RESULT_FORMAT, emit); + } + + public String getCv() { + return get(CONF_CV); + } + + public void setCv(String cv) { + Preconditions.checkNotNull(cv); + set(CONF_CV, cv); + } + + + public Boolean isUseCompositeCardinality() { + return getBoolean(CONF_USE_COMPOSITE, true); + } + + public void setCompositeCardinality(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(CONF_USE_COMPOSITE, val); + } + + + public Boolean isStatsPushEmptyRdftypeDown() { + return getBoolean(STATS_PUSH_EMPTY_RDFTYPE_DOWN, true); + } + + public void setStatsPushEmptyRdftypeDown(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(STATS_PUSH_EMPTY_RDFTYPE_DOWN, val); + } + + public Boolean isInferInverseOf() { + return getBoolean(INFER_INCLUDE_INVERSEOF, true); + } + + public void setInferInverseOf(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(INFER_INCLUDE_INVERSEOF, val); + } + + public Boolean isInferSubClassOf() { + return getBoolean(INFER_INCLUDE_SUBCLASSOF, true); + } + + public void setInferSubClassOf(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(INFER_INCLUDE_SUBCLASSOF, val); + } + + public Boolean isInferSubPropertyOf() { + return getBoolean(INFER_INCLUDE_SUBPROPOF, true); + } + + public void setInferSubPropertyOf(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(INFER_INCLUDE_SUBPROPOF, val); + } + + public Boolean isInferSymmetricProperty() { + return getBoolean(INFER_INCLUDE_SYMMPROP, true); + } + + public void setInferSymmetricProperty(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(INFER_INCLUDE_SYMMPROP, val); + } + + public Boolean isInferTransitiveProperty() { + return getBoolean(INFER_INCLUDE_TRANSITIVEPROP, true); + } + + public void setInferTransitiveProperty(Boolean val) { + Preconditions.checkNotNull(val); + setBoolean(INFER_INCLUDE_TRANSITIVEPROP, val); + } + + public void setRdfEvalStatsDaoClass(Class<? extends RdfEvalStatsDAO> rdfEvalStatsDaoClass) { + Preconditions.checkNotNull(rdfEvalStatsDaoClass); + setClass(RDF_EVAL_STATS_DAO_CLASS, rdfEvalStatsDaoClass, RdfEvalStatsDAO.class); + } + + public Class<? extends RdfEvalStatsDAO> getRdfEvalStatsDaoClass() { + return getClass(RDF_EVAL_STATS_DAO_CLASS, null, RdfEvalStatsDAO.class); + } + + + public void setPcjTables(List<String> indexTables) { + Preconditions.checkNotNull(indexTables); + setStrings(CONF_PCJ_TABLES, indexTables.toArray(new String[]{})); + } + + + public List<String> getPcjTables() { + List<String> pcjTables = Lists.newArrayList(); + String[] tables = getStrings(CONF_PCJ_TABLES); + if(tables == null) { + return pcjTables; + } + for(String table: tables) { + Preconditions.checkNotNull(table); + pcjTables.add(table); + } + return pcjTables; + } + + + public void setPcjOptimizer(Class<? extends QueryOptimizer> optimizer) { + Preconditions.checkNotNull(optimizer); + setClass(CONF_PCJ_OPTIMIZER, optimizer, QueryOptimizer.class); + } + + public Class<QueryOptimizer> getPcjOptimizer() { + Class<? extends QueryOptimizer> opt = getClass(CONF_PCJ_OPTIMIZER, null, QueryOptimizer.class); + if (opt != null) { + Preconditions.checkArgument(QueryOptimizer.class.isAssignableFrom(opt)); + return (Class<QueryOptimizer>) opt; + } else { + return null; + } + + } + + + public void setOptimizers(List<Class<? extends QueryOptimizer>> optimizers) { + Preconditions.checkNotNull(optimizers); + List<String> strs = Lists.newArrayList(); + for (Class ai : optimizers){ + Preconditions.checkNotNull(ai); + strs.add(ai.getName()); + } + + setStrings(CONF_OPTIMIZERS, strs.toArray(new String[]{})); + } + + public List<Class<QueryOptimizer>> getOptimizers() { + List<Class<QueryOptimizer>> opts = Lists.newArrayList(); + for (Class<?> clazz : getClasses(CONF_OPTIMIZERS)){ + Preconditions.checkArgument(QueryOptimizer.class.isAssignableFrom(clazz)); + opts.add((Class<QueryOptimizer>) clazz); + } + + return opts; + } + + + + public String getRegexSubject() { + return get(REGEX_SUBJECT); + } + + public void setRegexSubject(String regexSubject) { + Preconditions.checkNotNull(regexSubject); + set(REGEX_SUBJECT, regexSubject); + } + + public String getRegexPredicate() { + return get(REGEX_PREDICATE); + } + + public void setRegexPredicate(String regex) { + Preconditions.checkNotNull(regex); + set(REGEX_PREDICATE, regex); + } + + public String getRegexObject() { + return get(REGEX_OBJECT); + } + + public void setRegexObject(String regex) { + Preconditions.checkNotNull(regex); + set(REGEX_OBJECT, regex); + } +}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreConstants.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreConstants.java b/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreConstants.java new file mode 100644 index 0000000..d04ba27 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreConstants.java @@ -0,0 +1,150 @@ +package mvm.rya.api; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreStatement.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreStatement.java b/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreStatement.java new file mode 100644 index 0000000..fa2bf5f --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreStatement.java @@ -0,0 +1,71 @@ +package mvm.rya.api; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreUtils.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreUtils.java b/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreUtils.java new file mode 100644 index 0000000..2d04c11 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/RdfCloudTripleStoreUtils.java @@ -0,0 +1,419 @@ +package mvm.rya.api; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/date/DateTimeTtlValueConverter.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/date/DateTimeTtlValueConverter.java b/common/rya.api/src/main/java/mvm/rya/api/date/DateTimeTtlValueConverter.java new file mode 100644 index 0000000..e73a71b --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/date/DateTimeTtlValueConverter.java @@ -0,0 +1,79 @@ +package mvm.rya.api.date; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/date/TimestampTtlStrValueConverter.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/date/TimestampTtlStrValueConverter.java b/common/rya.api/src/main/java/mvm/rya/api/date/TimestampTtlStrValueConverter.java new file mode 100644 index 0000000..297cf5c --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/date/TimestampTtlStrValueConverter.java @@ -0,0 +1,55 @@ +package mvm.rya.api.date; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/date/TimestampTtlValueConverter.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/date/TimestampTtlValueConverter.java b/common/rya.api/src/main/java/mvm/rya/api/date/TimestampTtlValueConverter.java new file mode 100644 index 0000000..a709148 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/date/TimestampTtlValueConverter.java @@ -0,0 +1,55 @@ +package mvm.rya.api.date; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/date/TtlValueConverter.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/date/TtlValueConverter.java b/common/rya.api/src/main/java/mvm/rya/api/date/TtlValueConverter.java new file mode 100644 index 0000000..078d0f6 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/date/TtlValueConverter.java @@ -0,0 +1,40 @@ +package mvm.rya.api.date; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/Node.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/Node.java b/common/rya.api/src/main/java/mvm/rya/api/domain/Node.java new file mode 100644 index 0000000..dea3a76 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/Node.java @@ -0,0 +1,37 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RangeURI.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RangeURI.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RangeURI.java new file mode 100644 index 0000000..f3e2302 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RangeURI.java @@ -0,0 +1,51 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RangeValue.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RangeValue.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RangeValue.java new file mode 100644 index 0000000..67c37e7 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RangeValue.java @@ -0,0 +1,71 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RyaRange.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RyaRange.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaRange.java new file mode 100644 index 0000000..2214044 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaRange.java @@ -0,0 +1,31 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +/** + * 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/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RyaSchema.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RyaSchema.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaSchema.java new file mode 100644 index 0000000..380657c --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaSchema.java @@ -0,0 +1,42 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +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"); +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RyaStatement.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RyaStatement.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaStatement.java new file mode 100644 index 0000000..439eee6 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaStatement.java @@ -0,0 +1,251 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +import java.util.Arrays; + +/** + * Date: 7/17/12 + * Time: 7:20 AM + */ +public class RyaStatement { + private RyaURI subject; + private RyaURI predicate; + private RyaType object; + private RyaURI context; + private String qualifer; + private byte[] columnVisibility; + private byte[] value; + private Long timestamp; + + public RyaStatement() { + } + + public RyaStatement(RyaURI subject, RyaURI predicate, RyaType object) { + this(subject, predicate, object, null); + } + + public RyaStatement(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context) { + this(subject, predicate, object, context, null); + } + + public RyaStatement(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context, String qualifier) { + this(subject, predicate, object, context, qualifier, null); + } + + public RyaStatement(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context, String qualifier, byte[] columnVisibility) { + this(subject, predicate, object, context, qualifier, columnVisibility, null); + } + + public RyaStatement(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context, String qualifier, byte[] columnVisibility, byte[] value) { + this(subject, predicate, object, context, qualifier, columnVisibility, value, null); + } + + public RyaStatement(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context, String qualifier, byte[] columnVisibility, byte[] value, Long timestamp) { + this.subject = subject; + this.predicate = predicate; + this.object = object; + this.context = context; + this.qualifer = qualifier; + this.columnVisibility = columnVisibility; + this.value = value; + this.timestamp = timestamp != null ? timestamp : System.currentTimeMillis(); + } + + public RyaURI getSubject() { + return subject; + } + + public void setSubject(RyaURI subject) { + this.subject = subject; + } + + public RyaURI getPredicate() { + return predicate; + } + + public void setPredicate(RyaURI predicate) { + this.predicate = predicate; + } + + public RyaType getObject() { + return object; + } + + public void setObject(RyaType object) { + this.object = object; + } + + public RyaURI getContext() { + return context; + } + + public void setContext(RyaURI context) { + this.context = context; + } + + public byte[] getColumnVisibility() { + return columnVisibility; + } + + public void setColumnVisibility(byte[] columnVisibility) { + this.columnVisibility = columnVisibility; + } + + public byte[] getValue() { + return value; + } + + public void setValue(byte[] value) { + this.value = value; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RyaStatement that = (RyaStatement) o; + + if (!Arrays.equals(columnVisibility, that.columnVisibility)) return false; + if (context != null ? !context.equals(that.context) : that.context != null) return false; + if (object != null ? !object.equals(that.object) : that.object != null) return false; + if (predicate != null ? !predicate.equals(that.predicate) : that.predicate != null) return false; + if (qualifer != null ? !qualifer.equals(that.qualifer) : that.qualifer != null) return false; + if (subject != null ? !subject.equals(that.subject) : that.subject != null) return false; + if (timestamp != null ? !timestamp.equals(that.timestamp) : that.timestamp != null) return false; + if (!Arrays.equals(value, that.value)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = subject != null ? subject.hashCode() : 0; + result = 31 * result + (predicate != null ? predicate.hashCode() : 0); + result = 31 * result + (object != null ? object.hashCode() : 0); + result = 31 * result + (context != null ? context.hashCode() : 0); + result = 31 * result + (qualifer != null ? qualifer.hashCode() : 0); + result = 31 * result + (columnVisibility != null ? Arrays.hashCode(columnVisibility) : 0); + result = 31 * result + (value != null ? Arrays.hashCode(value) : 0); + result = 31 * result + (timestamp != null ? timestamp.hashCode() : 0); + return result; + } + + public String getQualifer() { + return qualifer; + } + + public void setQualifer(String qualifer) { + this.qualifer = qualifer; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("RyaStatement"); + sb.append("{subject=").append(subject); + sb.append(", predicate=").append(predicate); + sb.append(", object=").append(object); + sb.append(", context=").append(context); + sb.append(", qualifier=").append(qualifer); + sb.append(", columnVisibility=").append(columnVisibility == null ? "null" : new String(columnVisibility)); + sb.append(", value=").append(value == null ? "null" : new String(value)); + sb.append(", timestamp=").append(timestamp); + sb.append('}'); + return sb.toString(); + } + + public static RyaStatementBuilder builder() { + return new RyaStatementBuilder(); + } + + public static RyaStatementBuilder builder(RyaStatement ryaStatement) { + return new RyaStatementBuilder(ryaStatement); + } + + + //builder + public static class RyaStatementBuilder { + + RyaStatement ryaStatement; + + public RyaStatementBuilder() { + ryaStatement = new RyaStatement(); + } + + public RyaStatementBuilder(RyaStatement ryaStatement) { + this.ryaStatement = ryaStatement; + } + + public RyaStatementBuilder setTimestamp(Long timestamp) { + ryaStatement.setTimestamp(timestamp); + return this; + } + + public RyaStatementBuilder setValue(byte[] value) { + ryaStatement.setValue(value); + return this; + } + + public RyaStatementBuilder setColumnVisibility(byte[] columnVisibility) { + ryaStatement.setColumnVisibility(columnVisibility); + return this; + } + + public RyaStatementBuilder setQualifier(String str) { + ryaStatement.setQualifer(str); + return this; + } + + public RyaStatementBuilder setContext(RyaURI ryaURI) { + ryaStatement.setContext(ryaURI); + return this; + } + + public RyaStatementBuilder setSubject(RyaURI ryaURI) { + ryaStatement.setSubject(ryaURI); + return this; + } + + public RyaStatementBuilder setPredicate(RyaURI ryaURI) { + ryaStatement.setPredicate(ryaURI); + return this; + } + + public RyaStatementBuilder setObject(RyaType ryaType) { + ryaStatement.setObject(ryaType); + return this; + } + + public RyaStatement build() { + return ryaStatement; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RyaType.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RyaType.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaType.java new file mode 100644 index 0000000..9af0cc7 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaType.java @@ -0,0 +1,110 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + + +import org.openrdf.model.URI; +import org.openrdf.model.vocabulary.XMLSchema; + +/** + * Base Rya Type + * Date: 7/16/12 + * Time: 11:45 AM + */ +public class RyaType implements Comparable { + + private URI dataType; + private String data; + + public RyaType() { + setDataType(XMLSchema.STRING); + } + + public RyaType(String data) { + this(XMLSchema.STRING, data); + } + + + public RyaType(URI dataType, String data) { + setDataType(dataType); + setData(data); + } + + /** + * TODO: Can we get away without using the openrdf URI + * + * @return + */ + public URI getDataType() { + return dataType; + } + + public String getData() { + return data; + } + + public void setDataType(URI dataType) { + this.dataType = dataType; + } + + public void setData(String data) { + this.data = data; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("RyaType"); + sb.append("{dataType=").append(dataType); + sb.append(", data='").append(data).append('\''); + sb.append('}'); + return sb.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + RyaType ryaType = (RyaType) o; + + if (data != null ? !data.equals(ryaType.data) : ryaType.data != null) return false; + if (dataType != null ? !dataType.equals(ryaType.dataType) : ryaType.dataType != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = dataType != null ? dataType.hashCode() : 0; + result = 31 * result + (data != null ? data.hashCode() : 0); + return result; + } + + @Override + public int compareTo(Object o) { + if (o != null && this.getClass().isInstance(o)) { + RyaType other = (RyaType) o; + return this.getData().compareTo(other.getData()); + } + return -1; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RyaTypePrefix.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RyaTypePrefix.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaTypePrefix.java new file mode 100644 index 0000000..2db642f --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaTypePrefix.java @@ -0,0 +1,58 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +import org.openrdf.model.URI; + +import static mvm.rya.api.RdfCloudTripleStoreConstants.DELIM; +import static mvm.rya.api.RdfCloudTripleStoreConstants.LAST; + +/** + * Date: 7/24/12 + * Time: 3:26 PM + */ +public class RyaTypePrefix extends RyaTypeRange { + + public RyaTypePrefix(URI datatype, String prefix) { + super(); + setPrefix(datatype, prefix); + } + + public RyaTypePrefix(String prefix) { + super(); + setPrefix(prefix); + } + + public void setPrefix(String prefix) { + setStart(new RyaType(prefix + DELIM)); + setStop(new RyaType(prefix + LAST)); + } + + public void setPrefix(URI datatype, String prefix) { + setStart(new RyaType(datatype, prefix + DELIM)); + setStop(new RyaType(datatype, prefix + LAST)); + } + + public String getPrefix() { + String data = getStart().getData(); + return data.substring(0, data.length() - 1); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RyaTypeRange.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RyaTypeRange.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaTypeRange.java new file mode 100644 index 0000000..51b5a6f --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaTypeRange.java @@ -0,0 +1,98 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +import org.openrdf.model.URI; + +/** + * Date: 7/17/12 + * Time: 9:53 AM + */ +public class RyaTypeRange extends RyaType implements RyaRange { + private RyaType start; + private RyaType stop; + + public RyaTypeRange() { + } + + public RyaTypeRange(RyaType start, RyaType stop) { + this.start = start; + this.stop = stop; + } + + public RyaType getStart() { + return start; + } + + public void setStart(RyaType start) { + this.start = start; + } + + public RyaType getStop() { + return stop; + } + + public void setStop(RyaType stop) { + this.stop = stop; + } + + @Override + public URI getDataType() { + return start.getDataType(); + } + + @Override + public String getData() { + throw new UnsupportedOperationException(); + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("RyaTypeRange"); + sb.append("{start=").append(start); + sb.append(", stop=").append(stop); + sb.append('}'); + return sb.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + RyaTypeRange that = (RyaTypeRange) o; + + if (start != null ? !start.equals(that.start) : that.start != null) return false; + if (stop != null ? !stop.equals(that.stop) : that.stop != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (start != null ? start.hashCode() : 0); + result = 31 * result + (stop != null ? stop.hashCode() : 0); + return result; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURI.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURI.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURI.java new file mode 100644 index 0000000..a8e5391 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURI.java @@ -0,0 +1,62 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +import org.openrdf.model.URI; +import org.openrdf.model.util.URIUtil; +import org.openrdf.model.vocabulary.XMLSchema; + + +/** + * Date: 7/16/12 + * Time: 11:56 AM + */ +public class RyaURI extends RyaType { + + public RyaURI() { + setDataType(XMLSchema.ANYURI); + } + + public RyaURI(String data) { + super(XMLSchema.ANYURI, data); + } + + public RyaURI(String namespace, String data) { + super(XMLSchema.ANYURI, namespace + data); + } + + protected RyaURI(URI datatype, String data) { + super(datatype, data); + } + + @Override + public void setData(String data) { + super.setData(data); + validate(data); + } + + protected void validate(String data) { + if (data == null) + throw new IllegalArgumentException("Null not URI"); + URIUtil.getLocalNameIndex(data); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURIPrefix.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURIPrefix.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURIPrefix.java new file mode 100644 index 0000000..d6cff02 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURIPrefix.java @@ -0,0 +1,46 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +import mvm.rya.api.RdfCloudTripleStoreConstants; + +/** + * Date: 7/24/12 + * Time: 3:26 PM + */ +public class RyaURIPrefix extends RyaURIRange { + public static final String LAST = "\u00FF"; + + public RyaURIPrefix(String prefix) { + super(); + setPrefix(prefix); + } + + public void setPrefix(String prefix) { + setStart(new RyaURI(prefix + RdfCloudTripleStoreConstants.DELIM)); + setStop(new RyaURI(prefix + LAST)); + } + + public String getPrefix() { + String data = getStart().getData(); + return data.substring(0, data.length() - 1); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURIRange.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURIRange.java b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURIRange.java new file mode 100644 index 0000000..3a00528 --- /dev/null +++ b/common/rya.api/src/main/java/mvm/rya/api/domain/RyaURIRange.java @@ -0,0 +1,94 @@ +package mvm.rya.api.domain; + +/* + * #%L + * mvm.rya.rya.api + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed 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. + * #L% + */ + +/** + * Date: 7/17/12 + * Time: 9:59 AM + */ +public class RyaURIRange extends RyaURI implements RyaRange { + public static final RyaURI LAST_URI = new RyaURI(((char) 255) + ":#" + ((char) 255)); + + private RyaURI start; + private RyaURI stop; + + public RyaURIRange() { + super(); + } + + public RyaURIRange(RyaURI start, RyaURI stop) { + this.start = start; + this.stop = stop; + } + + public RyaURI getStart() { + return start; + } + + public void setStart(RyaURI start) { + this.start = start; + } + + public RyaURI getStop() { + return stop; + } + + public void setStop(RyaURI stop) { + this.stop = stop; + } + + @Override + public String getData() { + throw new UnsupportedOperationException(); + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("RyaURIRange"); + sb.append("{start=").append(start); + sb.append(", stop=").append(stop); + sb.append('}'); + return sb.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + RyaURIRange that = (RyaURIRange) o; + + if (start != null ? !start.equals(that.start) : that.start != null) return false; + if (stop != null ? !stop.equals(that.stop) : that.stop != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (start != null ? start.hashCode() : 0); + result = 31 * result + (stop != null ? stop.hashCode() : 0); + return result; + } +}
