index int64 0 0 | repo_id stringlengths 9 205 | file_path stringlengths 31 246 | content stringlengths 1 12.2M | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/QueryParser.java | /*
* 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 org.apache.clerezza.sparql;
import org.apache.clerezza.sparql.query.Query;
import org.osgi.service.component.annotations.Component;
import java.io.StringReader;
/**
* This class implements an OSGi service to provide a method to parse a
* SPARQL query and generate a {@link Query} object.
*
* @author hasan
*/
@Component(service = QueryParser.class)
public class QueryParser {
private static volatile QueryParser instance;
public QueryParser() {
QueryParser.instance = this;
}
/**
* Returns an instance of this class.
* This method is provided due to backward compatibility.
*/
public static QueryParser getInstance() {
if (instance == null) {
synchronized (QueryParser.class) {
if (instance == null) {
new QueryParser();
}
}
}
return instance;
}
/**
* Parses a SPARQL query string into a {@link Query} object.
*
* @param queryString
* SPARQL query string
* @return
* {@link Query} object corresponding to the specified query string
*
* @throws org.apache.clerezza.sparql.ParseException
*/
public Query parse(final String queryString) throws ParseException {
JavaCCGeneratedQueryParser parser = new JavaCCGeneratedQueryParser(
new StringReader(queryString));
return parser.parse();
}
}
| 200 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/SparqlPreParser.java | /*
* 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 org.apache.clerezza.sparql;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.query.*;
import org.apache.clerezza.sparql.update.Update;
import java.io.StringReader;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* This class implements an OSGi service to provide a method to obtain referred Graphs in a SPARQL Query or Update.
*
* @author hasan
*/
public class SparqlPreParser {
GraphStore graphStore;
public SparqlPreParser() {
}
public SparqlPreParser(GraphStore graphStore) {
this.graphStore = graphStore;
}
/**
* This returns the graphs targeted by the queryString. These are the
* triple collections explicitly referred in FROM and FROM NAMED clauses,
* and if the queryString contains no FROM clause the defaultGraph.
*
* For queries that are not limited to a specified set of graphs, null is returned.
*
* @param queryString
* @param defaultGraph
* @return
* @throws ParseException
*/
public Set<IRI> getReferredGraphs(String queryString, IRI defaultGraph) throws ParseException {
Set<IRI> referredGraphs;
JavaCCGeneratedSparqlPreParser parser = new JavaCCGeneratedSparqlPreParser(new StringReader(queryString));
SparqlUnit sparqlUnit;
sparqlUnit = parser.parse();
boolean referringVariableNamedGraph = false;
if (sparqlUnit.isQuery()) {
Query q = sparqlUnit.getQuery();
DataSet dataSet = q.getDataSet();
if (dataSet != null) {
referredGraphs = dataSet.getDefaultGraphs();
referredGraphs.addAll(dataSet.getNamedGraphs());
} else {
referredGraphs = new HashSet<IRI>();
}
GroupGraphPattern queryPattern = q.getQueryPattern();
if (queryPattern != null) {
Set<GraphPattern> graphPatterns = queryPattern.getGraphPatterns();
for (GraphPattern graphPattern : graphPatterns) {
}
}
// referringVariableNamedGraph = q.referringVariableNamedGraph();
referringVariableNamedGraph = referringVariableNamedGraph(q);
} else {
Update u = sparqlUnit.getUpdate();
referredGraphs = u.getReferredGraphs(defaultGraph, graphStore);
}
if (referredGraphs.isEmpty()) {
if (referringVariableNamedGraph) {
return null;
}
referredGraphs.add(defaultGraph);
}
return referredGraphs;
}
private boolean referringVariableNamedGraph(Query query) {
GroupGraphPattern queryPattern = query.getQueryPattern();
if (queryPattern == null) {
return false;
}
Set<GraphPattern> graphPatterns = queryPattern.getGraphPatterns();
return referringVariableNamedGraph(graphPatterns);
}
private boolean referringVariableNamedGraph(Set<GraphPattern> graphPatterns) {
boolean referringVariableNamedGraph = false;
for (GraphPattern graphPattern : graphPatterns) {
if (referringVariableNamedGraph(graphPattern)) {
referringVariableNamedGraph = true;
break;
}
}
return referringVariableNamedGraph;
}
private boolean referringVariableNamedGraph(GraphPattern graphPattern) {
if (graphPattern instanceof GraphGraphPattern) {
return ((GraphGraphPattern) graphPattern).getGraph().isVariable();
}
if (graphPattern instanceof AlternativeGraphPattern) {
List<GroupGraphPattern> alternativeGraphPatterns =
((AlternativeGraphPattern) graphPattern).getAlternativeGraphPatterns();
boolean referringVariableNamedGraph = false;
for (GroupGraphPattern groupGraphPattern : alternativeGraphPatterns) {
if (referringVariableNamedGraph(groupGraphPattern)) {
referringVariableNamedGraph = true;
break;
}
}
return referringVariableNamedGraph;
}
if (graphPattern instanceof OptionalGraphPattern) {
GraphPattern mainGraphPattern = ((OptionalGraphPattern) graphPattern).getMainGraphPattern();
if (referringVariableNamedGraph(mainGraphPattern)) {
return true;
}
GroupGraphPattern optionalGraphPattern = ((OptionalGraphPattern) graphPattern).getOptionalGraphPattern();
return referringVariableNamedGraph(optionalGraphPattern);
}
if (graphPattern instanceof MinusGraphPattern) {
GraphPattern minuendGraphPattern = ((MinusGraphPattern) graphPattern).getMinuendGraphPattern();
if (referringVariableNamedGraph(minuendGraphPattern)) {
return true;
}
GroupGraphPattern subtrahendGraphPattern = ((MinusGraphPattern) graphPattern).getSubtrahendGraphPattern();
return referringVariableNamedGraph(subtrahendGraphPattern);
}
if (graphPattern instanceof GroupGraphPattern) {
GroupGraphPattern groupGraphPattern = (GroupGraphPattern) graphPattern;
if (groupGraphPattern.isSubSelect()) {
Query query = ((GroupGraphPattern) graphPattern).getSubSelect();
return referringVariableNamedGraph(query);
} else {
Set<GraphPattern> graphPatterns = ((GroupGraphPattern) graphPattern).getGraphPatterns();
return referringVariableNamedGraph(graphPatterns);
}
}
return false;
}
}
| 201 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/NoQueryEngineException.java | /*
* 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 org.apache.clerezza.sparql;
/**
* Indicates that there is no available query engine for resolving a query.
*
* @author rbn
*/
public class NoQueryEngineException extends RuntimeException {
/**
* Creates a new instance of <code>NoQueryEngineException</code> without detail message.
*/
public NoQueryEngineException() {
}
/**
* Constructs an instance of <code>NoQueryEngineException</code> with the specified detail message.
* @param msg the detail message.
*/
public NoQueryEngineException(String msg) {
super(msg);
}
}
| 202 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/ResultSet.java | /*
* 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 org.apache.clerezza.sparql;
import java.util.Iterator;
import java.util.List;
/**
* The reult of a sparql SELECT-query. This corresponds to a Solution Sequence
* as per section 12.1.6 of http://www.w3.org/TR/rdf-sparql-query/.
*
* Note that the scope of blank nodes is the reult set and not the
* Graph from where they originate.
*
* @author rbn
*/
public interface ResultSet extends Iterator<SolutionMapping> {
/** Iterate over the variable names (strings) in this QuerySolution.
* @return Iterator of strings
*/
public List<String> getResultVars() ;
}
| 203 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/GraphStore.java | package org.apache.clerezza.sparql;
import org.apache.clerezza.IRI;
import java.util.Set;
public interface GraphStore {
/**
* Lists the name of the <Code>Graph</code>s available through this <code>GraphStore</code>.
*
* @return the list of <Code>Graph</code>s
*/
Set<IRI> listGraphs();
/**
* Lists the name of the named <Code>Graph</code>s available through this <code>GraphStore</code>.
*
* @return the list of named <Code>Graph</code>s
*/
Set<IRI> listNamedGraphs();
}
| 204 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/Update.java | /*
* 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 org.apache.clerezza.sparql.update;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.GraphStore;
import java.util.Set;
/**
* <p>This interface represents a SPARQL Update.</p>
*
* @author hasan
*/
public interface Update {
/**
*
* @param defaultGraph
* if default graph is referred either implicitly or explicitly in a SPARQL {@link Update}
* the specified defaultGraph should be returned in the resulting set.
* @param graphStore
* the specified tcProvider is used to get the named graphs referred in the SPARQL {@link Update}.
* @return a set of graphs referred in the {@link Update}.
*/
public Set<IRI> getReferredGraphs(IRI defaultGraph, GraphStore graphStore);
public void addOperation(UpdateOperation updateOperation);
/**
*
* @return A valid String representation of the {@link Update}.
*/
@Override
public abstract String toString();
}
| 205 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/UpdateOperation.java | /*
* 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 org.apache.clerezza.sparql.update;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.GraphStore;
import java.util.Set;
/**
* SPARQL Update Operation
*
* @author hasan
*/
public interface UpdateOperation {
public enum GraphSpec {
GRAPH, DEFAULT, NAMED, ALL
}
/**
*
* @param defaultGraph
* if default graph is referred either implicitly or explicitly as an input graph in this operation
* the specified defaultGraph should be returned in the resulting set.
* @param graphStore
* the specified tcProvider is used to get the named graphs referred as input graphs in this operation.
* @return a set of graphs referred as input graphs in this operation.
*/
public Set<IRI> getInputGraphs(IRI defaultGraph, GraphStore graphStore);
/**
*
* @param defaultGraph
* if default graph is referred either implicitly or explicitly as a destination graph in this operation
* the specified defaultGraph should be returned in the resulting set.
* @param graphStore
* the specified tcProvider is used to get the named graphs referred as destination graphs in this operation.
* @return a set of graphs referred as destination graphs in this operation.
*/
public Set<IRI> getDestinationGraphs(IRI defaultGraph, GraphStore graphStore);
}
| 206 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/SimpleUpdateOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.update.UpdateOperation;
import java.util.Set;
/**
*
* @author hasan
*/
public class SimpleUpdateOperation extends BaseUpdateOperation {
private boolean silent;
public SimpleUpdateOperation() {
this.silent = false;
inputGraphSpec = UpdateOperation.GraphSpec.DEFAULT;
destinationGraphSpec = UpdateOperation.GraphSpec.DEFAULT;
}
public void setSilent(boolean silent) {
this.silent = silent;
}
public boolean isSilent() {
return silent;
}
public void setInputGraph(IRI source) {
inputGraphSpec = UpdateOperation.GraphSpec.GRAPH;
inputGraphs.clear();
inputGraphs.add(source);
}
public IRI getInputGraph(IRI defaultGraph) {
Set<IRI> result = getInputGraphs(defaultGraph, null);
if (result.isEmpty()) {
return null;
} else {
return result.iterator().next();
}
}
public void setDestinationGraph(IRI destination) {
destinationGraphSpec = UpdateOperation.GraphSpec.GRAPH;
destinationGraphs.clear();
destinationGraphs.add(destination);
}
public IRI getDestinationGraph(IRI defaultGraph) {
Set<IRI> result = getDestinationGraphs(defaultGraph, null);
if (result.isEmpty()) {
return null;
} else {
return result.iterator().next();
}
}
}
| 207 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/Quad.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
import org.apache.clerezza.sparql.query.TriplePattern;
import org.apache.clerezza.sparql.query.UriRefOrVariable;
import org.apache.clerezza.sparql.query.impl.SimpleBasicGraphPattern;
import java.util.Set;
/**
*
* @author hasan
*/
public class Quad extends SimpleBasicGraphPattern {
private UriRefOrVariable ImmutableGraph = null;
public Quad(UriRefOrVariable ImmutableGraph, Set<TriplePattern> triplePatterns) {
super(triplePatterns);
this.ImmutableGraph = ImmutableGraph;
}
public UriRefOrVariable getGraph() {
return this.ImmutableGraph;
}
}
| 208 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/ModifyOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.GraphStore;
import org.apache.clerezza.sparql.query.GroupGraphPattern;
import org.apache.clerezza.sparql.query.impl.SimpleDataSet;
import org.apache.clerezza.sparql.update.UpdateOperation;
import java.util.HashSet;
import java.util.Set;
/**
* This ModifyOperation is a DELETE/INSERT operation.
* @see <a href="http://www.w3.org/TR/2013/REC-sparql11-update-20130321/#deleteInsert">SPARQL 1.1 Update: 3.1.3 DELETE/INSERT</a>
*
* The DELETE/INSERT operation can be used to remove or add triples from/to the ImmutableGraph Store based on bindings
* for a query pattern specified in a WHERE clause.
*
* @author hasan
*/
public class ModifyOperation implements UpdateOperation {
private IRI fallbackGraph = null;
private UpdateOperationWithQuads deleteOperation = null;
private UpdateOperationWithQuads insertOperation = null;
private SimpleDataSet dataSet = null;
private GroupGraphPattern queryPattern = null;
public void setFallbackGraph(IRI fallbackGraph) {
this.fallbackGraph = fallbackGraph;
}
public void setDeleteOperation(UpdateOperationWithQuads deleteOperation) {
this.deleteOperation = deleteOperation;
}
public void setInsertOperation(UpdateOperationWithQuads insertOperation) {
this.insertOperation = insertOperation;
}
public void setDataSet(SimpleDataSet dataSet) {
this.dataSet = dataSet;
}
public void addGraphToDataSet(IRI ImmutableGraph) {
if (dataSet == null) {
dataSet = new SimpleDataSet();
}
dataSet.addDefaultGraph(ImmutableGraph);
}
public void addNamedGraphToDataSet(IRI namedGraph) {
if (dataSet == null) {
dataSet = new SimpleDataSet();
}
dataSet.addNamedGraph(namedGraph);
}
public void setQueryPattern(GroupGraphPattern queryPattern) {
this.queryPattern = queryPattern;
}
@Override
public Set<IRI> getInputGraphs(IRI defaultGraph, GraphStore graphStore) {
Set<IRI> graphs = new HashSet<IRI>();
if (dataSet != null) {
graphs.addAll(dataSet.getDefaultGraphs());
graphs.addAll(dataSet.getNamedGraphs());
} else {
if (fallbackGraph != null) {
graphs.add(fallbackGraph);
}
}
if (graphs.isEmpty()) {
graphs.add(defaultGraph);
}
if (queryPattern != null) {
graphs.addAll(queryPattern.getReferredGraphs());
}
return graphs;
}
@Override
public Set<IRI> getDestinationGraphs(IRI defaultGraph, GraphStore graphStore) {
Set<IRI> graphs = new HashSet<IRI>();
IRI dfltGraph = (fallbackGraph != null) ? fallbackGraph : defaultGraph;
if (deleteOperation != null) {
graphs.addAll(deleteOperation.getDestinationGraphs(dfltGraph, graphStore));
}
if (insertOperation != null) {
graphs.addAll(insertOperation.getDestinationGraphs(dfltGraph, graphStore));
}
return graphs;
}
}
| 209 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/DeleteDataOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
/**
*
* @author hasan
*/
public class DeleteDataOperation extends UpdateOperationWithQuads {
}
| 210 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/BaseUpdateOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.GraphStore;
import org.apache.clerezza.sparql.update.UpdateOperation;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author hasan
*/
public abstract class BaseUpdateOperation implements UpdateOperation {
protected Set<IRI> inputGraphs = new HashSet<IRI>();
protected Set<IRI> destinationGraphs = new HashSet<IRI>();
protected GraphSpec inputGraphSpec = GraphSpec.GRAPH;
protected GraphSpec destinationGraphSpec = GraphSpec.GRAPH;
public void setInputGraphSpec(GraphSpec inputGraphSpec) {
this.inputGraphSpec = inputGraphSpec;
}
public GraphSpec getInputGraphSpec() {
return inputGraphSpec;
}
public void setDestinationGraphSpec(GraphSpec destinationGraphSpec) {
this.destinationGraphSpec = destinationGraphSpec;
}
public GraphSpec getDestinationGraphSpec() {
return destinationGraphSpec;
}
@Override
public Set<IRI> getInputGraphs(IRI defaultGraph, GraphStore graphStore) {
return getGraphs(defaultGraph, graphStore, inputGraphSpec, inputGraphs);
}
private Set<IRI> getGraphs(IRI defaultGraph, GraphStore graphStore, GraphSpec graphSpec, Set<IRI> graphs) {
switch (graphSpec) {
case DEFAULT:
Set<IRI> result = new HashSet<IRI>();
result.add(defaultGraph);
return result;
case NAMED:
case ALL:
return graphStore.listGraphs();
default:
return graphs;
}
}
@Override
public Set<IRI> getDestinationGraphs(IRI defaultGraph, GraphStore graphStore) {
return getGraphs(defaultGraph, graphStore, destinationGraphSpec, destinationGraphs);
}
public void addInputGraph(IRI ImmutableGraph) {
inputGraphs.add(ImmutableGraph);
}
public void addDestinationGraph(IRI ImmutableGraph) {
destinationGraphs.add(ImmutableGraph);
}
}
| 211 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/InsertDataOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
/**
*
* @author hasan
*/
public class InsertDataOperation extends UpdateOperationWithQuads {
}
| 212 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/DeleteWhereOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
/**
*
* @author hasan
*/
public class DeleteWhereOperation extends UpdateOperationWithQuads {
}
| 213 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/CreateOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
import org.apache.clerezza.IRI;
/**
*
* @author hasan
*/
public class CreateOperation extends BaseUpdateOperation {
private boolean silent;
public CreateOperation() {
this.silent = false;
}
public void setSilent(boolean silent) {
this.silent = silent;
}
public boolean isSilent() {
return silent;
}
public void setDestinationGraph(IRI destination) {
destinationGraphs.clear();
destinationGraphs.add(destination);
}
public IRI getDestinationGraph() {
if (destinationGraphs.isEmpty()) {
return null;
} else {
return destinationGraphs.iterator().next();
}
}
}
| 214 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/ClearOrDropOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.GraphStore;
import org.apache.clerezza.sparql.update.UpdateOperation;
import java.util.Set;
/**
*
* @author hasan
*/
public class ClearOrDropOperation extends BaseUpdateOperation {
private boolean silent;
public ClearOrDropOperation() {
this.silent = false;
destinationGraphSpec = UpdateOperation.GraphSpec.DEFAULT;
}
public void setSilent(boolean silent) {
this.silent = silent;
}
public boolean isSilent() {
return silent;
}
public void setDestinationGraph(IRI destination) {
destinationGraphSpec = UpdateOperation.GraphSpec.GRAPH;
destinationGraphs.clear();
destinationGraphs.add(destination);
}
public IRI getDestinationGraph(IRI defaultGraph, GraphStore graphStore) {
Set<IRI> result = getDestinationGraphs(defaultGraph, graphStore);
if (result.isEmpty()) {
return null;
} else {
return result.iterator().next();
}
}
}
| 215 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/ClearOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
/**
*
* @author hasan
*/
public class ClearOperation extends ClearOrDropOperation {
}
| 216 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/AddOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
/**
* The ADD operation is a shortcut for inserting all data from an input ImmutableGraph into a destination ImmutableGraph.
* Data from the input ImmutableGraph is not affected, and initial data from the destination ImmutableGraph, if any, is kept intact.
* @see <a href="http://www.w3.org/TR/2013/REC-sparql11-update-20130321/#add">SPARQL 1.1 Update: 3.2.5 ADD</a>
*
* @author hasan
*/
public class AddOperation extends SimpleUpdateOperation {
}
| 217 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/UpdateOperationWithQuads.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.GraphStore;
import org.apache.clerezza.sparql.query.TriplePattern;
import org.apache.clerezza.sparql.query.UriRefOrVariable;
import org.apache.clerezza.sparql.update.UpdateOperation;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
* @author hasan
*/
public class UpdateOperationWithQuads implements UpdateOperation {
private Quad defaultQuad = null;
private List<Quad> quads = new ArrayList<Quad>();
public UpdateOperationWithQuads() {
}
public void addQuad(Set<TriplePattern> triplePatterns) {
if (defaultQuad == null) {
defaultQuad = new Quad(null, triplePatterns);
} else {
defaultQuad.addTriplePatterns(triplePatterns);
}
}
public void addQuad(UriRefOrVariable ImmutableGraph, Set<TriplePattern> triplePatterns) {
if (ImmutableGraph == null) {
addQuad(triplePatterns);
} else {
quads.add(new Quad(ImmutableGraph, triplePatterns));
}
}
@Override
public Set<IRI> getInputGraphs(IRI defaultGraph, GraphStore graphStore) {
return new HashSet<IRI>();
}
@Override
public Set<IRI> getDestinationGraphs(IRI defaultGraph, GraphStore graphStore) {
Set<IRI> graphs = new HashSet<IRI>();
if (defaultQuad != null) {
graphs.add(defaultGraph);
}
for (Quad quad : quads) {
UriRefOrVariable ImmutableGraph = quad.getGraph();
if (!ImmutableGraph.isVariable()) {
graphs.add(ImmutableGraph.getResource());
}
}
return graphs;
}
}
| 218 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/CopyOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
/**
*
* @author hasan
*/
public class CopyOperation extends SimpleUpdateOperation {
}
| 219 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/SimpleUpdate.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.GraphStore;
import org.apache.clerezza.sparql.update.Update;
import org.apache.clerezza.sparql.update.UpdateOperation;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
* @author hasan
*/
public class SimpleUpdate implements Update {
protected List<UpdateOperation> operations = new ArrayList<UpdateOperation>();
@Override
public Set<IRI> getReferredGraphs(IRI defaultGraph, GraphStore graphStore) {
Set<IRI> referredGraphs = new HashSet<IRI>();
for (UpdateOperation operation : operations) {
referredGraphs.addAll(operation.getInputGraphs(defaultGraph, graphStore));
referredGraphs.addAll(operation.getDestinationGraphs(defaultGraph, graphStore));
}
return referredGraphs;
}
@Override
public void addOperation(UpdateOperation updateOperation) {
operations.add(updateOperation);
}
}
| 220 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/LoadOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
import org.apache.clerezza.IRI;
/**
* The LOAD operation reads an RDF document from a IRI and inserts its triples into the specified ImmutableGraph in the ImmutableGraph Store.
* If the destination ImmutableGraph already exists, then no data in that ImmutableGraph will be removed.
* If no destination ImmutableGraph IRI is provided to load the triples into, then the data will be loaded into the default ImmutableGraph.
* @see <a href="http://www.w3.org/TR/2013/REC-sparql11-update-20130321/#load">SPARQL 1.1 Update: 3.1.4 LOAD</a>
* @author hasan
*/
public class LoadOperation extends SimpleUpdateOperation {
public void setSource(IRI source) {
setInputGraph(source);
}
public IRI getSource() {
return getInputGraph(null);
}
}
| 221 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/MoveOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
/**
*
* @author hasan
*/
public class MoveOperation extends SimpleUpdateOperation {
}
| 222 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/update/impl/DropOperation.java | /*
* 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 org.apache.clerezza.sparql.update.impl;
/**
*
* @author hasan
*/
public class DropOperation extends ClearOrDropOperation {
}
| 223 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/UnaryOperation.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* Defines an operation with a single operand.
*
* @author hasan
*/
public class UnaryOperation extends AbstractOperation {
private Expression operand;
public UnaryOperation(String operator, Expression operand) {
super(operator);
this.operand = operand;
}
public Expression getOperand() {
return operand;
}
}
| 224 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/DataSet.java | /*
* 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 org.apache.clerezza.sparql.query;
import org.apache.clerezza.IRI;
import java.util.Set;
/**
* This interface definition is not yet stable and may change in future.
*
* @author hasan
*/
public interface DataSet {
/**
*
* @return
* an empty set if no default ImmutableGraph is specified,
* otherwise a set of their UriRefs
*/
public Set<IRI> getDefaultGraphs();
/**
*
* @return
* an empty set if no named ImmutableGraph is specified,
* otherwise a set of their UriRefs
*/
public Set<IRI> getNamedGraphs();
}
| 225 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/BinaryOperation.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* Defines an operation with two operands: a left hand side and a right hand side
* operand.
*
* @author hasan
*/
public class BinaryOperation extends AbstractOperation {
private Expression lhsOperand;
private Expression rhsOperand;
public BinaryOperation(String operator,
Expression lhsOperand, Expression rhsOperand) {
super(operator);
this.lhsOperand = lhsOperand;
this.rhsOperand = rhsOperand;
}
public Expression getLhsOperand() {
return lhsOperand;
}
public Expression getRhsOperand() {
return rhsOperand;
}
}
| 226 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/PropertyPathExpression.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* This interface models property path expressions.
* @see <a href="http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#propertypaths">
* SPARQL 1.1 Query Language: 9 Property Paths</a>
*
* @author hasan
*/
public interface PropertyPathExpression {
}
| 227 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/GroupGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query;
import org.apache.clerezza.IRI;
import java.util.List;
import java.util.Set;
/**
* Defines a group ImmutableGraph pattern.
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#GroupPatterns">
* SPARQL Query Language: 5.2 Group ImmutableGraph Patterns</a>
*
* @author hasan
*/
public interface GroupGraphPattern extends GraphPattern {
/**
*
* @return
* true if it wraps a {@link SelectQuery}, false otherwise.
*/
public boolean isSubSelect();
/**
*
* @return
* the wrapped subselect if it wraps a {@link SelectQuery}, null otherwise.
*/
public SelectQuery getSubSelect();
/**
*
* @return
* null if it wraps a {@link SelectQuery}, otherwise
* a set of all patterns, ANDed together.
*/
public Set<GraphPattern> getGraphPatterns();
/**
*
* @return
* all graphs referred in this ImmutableGraph pattern.
*/
public Set<IRI> getReferredGraphs();
/**
* @return
* null if it wraps a {@link SelectQuery}, otherwise
* a list of filter expressions for all patterns in the group if any.
*/
public List<Expression> getFilter();
}
| 228 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/ServiceGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* Defines a service ImmutableGraph pattern.
* @see <a href="http://www.w3.org/TR/sparql11-federated-query/">
* SPARQL 1.1 Federated Query</a>
*
* @author hasan
*/
public interface ServiceGraphPattern extends GraphPattern {
/**
*
* @return a {@link UriRefOrVariable} which specifies the service endpoint.
*/
public UriRefOrVariable getService();
/**
*
* @return the pattern to match.
*/
public GroupGraphPattern getGroupGraphPattern();
}
| 229 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/MinusGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
*
* @author hasan
*/
public interface MinusGraphPattern extends GraphPattern {
/**
*
* @return
* the minuend ImmutableGraph pattern to match
*/
public GraphPattern getMinuendGraphPattern();
/**
*
* @return
* the subtrahend ImmutableGraph pattern to match
*/
public GroupGraphPattern getSubtrahendGraphPattern();
}
| 230 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/PropertyPathExpressionOrVariable.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* Wraps either a {@link PropertyPathExpression} or a {@link Variable}
*
* @author hasan
*/
public class PropertyPathExpressionOrVariable {
private final PropertyPathExpression propertyPathExpression;
private final Variable variable;
public PropertyPathExpressionOrVariable(PropertyPathExpression propertyPathExpression) {
if (propertyPathExpression == null) {
throw new IllegalArgumentException("Invalid propertyPathExpression: null");
}
this.propertyPathExpression = propertyPathExpression;
variable = null;
}
public PropertyPathExpressionOrVariable(Variable variable) {
if (variable == null) {
throw new IllegalArgumentException("Invalid variable: null");
}
this.variable = variable;
propertyPathExpression = null;
}
/**
*
* @return
* true if it is a {@link Variable}, false if it is a {@link PropertyPathExpression}
*/
public boolean isVariable() {
return propertyPathExpression == null;
}
/**
*
* @return
* the wrapped PropertyPathExpression if it is a PropertyPathExpression, null otherwise
*/
public PropertyPathExpression getPropertyPathExpression() {
return propertyPathExpression;
}
/**
*
* @return
* the wrapped Variable if it is a Variable, null otherwise
*/
public Variable getVariable() {
return variable;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof PropertyPathExpressionOrVariable)) {
return false;
}
final PropertyPathExpressionOrVariable other = (PropertyPathExpressionOrVariable) obj;
if (this.isVariable() != other.isVariable()) {
return false;
}
if (this.isVariable()) {
if (!this.getVariable().equals(other.getVariable())) {
return false;
}
} else {
if (!this.getPropertyPathExpression().equals(other.getPropertyPathExpression())) {
return false;
}
}
return true;
}
@Override
public int hashCode() {
return (isVariable()
? 13 * getVariable().hashCode() + 17
: 13 * getPropertyPathExpression().hashCode() + 17);
}
}
| 231 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/DescribeQuery.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.List;
/**
* <p>This interface represents a SPARQL SELECT query.</p>
*
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#describe">
* SPARQL Query Language: 10.4 DESCRIBE (Informative)</a>
*
* @author hasan
*/
public interface DescribeQuery extends QueryWithSolutionModifier {
/**
* <p>Tests if all variables in the query should be described.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#describe">
* SPARQL Query Language: 10.4 DESCRIBE (Informative)</a>
* @return <code>true</code> if the query should return all variables.
*/
public boolean isDescribeAll();
/**
* <p>Gets the list of {@link ResourceOrVariable}s to describe.
* If {@link #isDescribeAll()} returns <code>true</code> then
* this list contains all the variables from the query.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#describe">
* SPARQL Query Language: 10.4 DESCRIBE (Informative)</a>
* @return A list of {@link ResourceOrVariable}s to describe.
*/
public List<ResourceOrVariable> getResourcesToDescribe();
}
| 232 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/BuiltInCall.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.List;
/**
* Defines a built-in call which is one form of {@link Expression}.
* A built-in call has a name of type String and a list of arguments,
* where each argument is an {@link Expression}.
*
* @author hasan
*/
public class BuiltInCall implements Expression {
protected String name;
private final List<Expression> arguments;
public BuiltInCall(String name, List<Expression> arguments) {
this.name = name;
this.arguments = arguments;
}
public String getName() {
return name;
};
public List<Expression> getArguements() {
return arguments;
}
}
| 233 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/PatternExistenceCondition.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.ArrayList;
import java.util.List;
/**
* This expression is intended to be used as a filter expression to test whether a ImmutableGraph pattern matches
* the dataset or not, given the values of variables in the group ImmutableGraph pattern in which the filter occurs.
* It does not generate any additional bindings.
*
* @see <a href="http://www.w3.org/TR/sparql11-query/#neg-pattern">SPARQL 1.1 Query Language: 8.1 Filtering Using ImmutableGraph Patterns</a>
*
* @author hasan
*/
public class PatternExistenceCondition extends BuiltInCall {
private boolean negated = false;
private GroupGraphPattern pattern;
public PatternExistenceCondition() {
super("EXISTS", new ArrayList<Expression>());
}
public PatternExistenceCondition(String name, List<Expression> arguments) {
super(name, new ArrayList<Expression>());
if (!(name.equalsIgnoreCase("EXISTS") || name.equalsIgnoreCase("NOT EXISTS"))) {
throw new RuntimeException("Unsupported name: " + name);
} else {
this.negated = name.equalsIgnoreCase("NOT EXISTS");
}
}
public boolean isExistenceTest() {
return !negated;
}
public GroupGraphPattern getPattern() {
return pattern;
}
public void setExistenceTest(boolean existenceTest) {
this.negated = !existenceTest;
this.name = existenceTest ? "EXISTS" : "NOT EXISTS";
}
public void setPattern(GroupGraphPattern pattern) {
this.pattern = pattern;
}
}
| 234 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/PathSupportedBasicGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.Set;
/**
* Defines a basic ImmutableGraph pattern that supports property path expressions.
* A {@link PathSupportedBasicGraphPattern} is a set of {@link PropertyPathPattern}s.
* A {@link PropertyPathPattern} is a generalization of a {@link TriplePattern} to include
* a {@link PropertyPathExpression} in the property position.
* Therefore, a {@link PathSupportedBasicGraphPattern} can be seen as a generalization of a {@link BasicGraphPattern}
* @see <a href="http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#sparqlBasicGraphPatterns">
* SPARQL 1.1 Query Language: 18.1.6 Basic ImmutableGraph Patterns</a>
* and <a href="http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#sparqlPropertyPaths">
* SPARQL 1.1 Query Language: 18.1.7 Property Path Patterns</a>
*
* @author hasan
*/
public interface PathSupportedBasicGraphPattern extends GraphPattern {
/**
*
* @return a set of all property path patterns to match.
*/
public Set<PropertyPathPattern> getPropertyPathPatterns();
}
| 235 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/InlineData.java | /*
* 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 org.apache.clerezza.sparql.query;
import org.apache.clerezza.RDFTerm;
import java.util.List;
/**
*
* @author hasan
*/
public interface InlineData extends GraphPattern {
public List<Variable> getVariables();
public List<List<RDFTerm>> getValues();
}
| 236 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/LiteralExpression.java | /*
* 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 org.apache.clerezza.sparql.query;
import org.apache.clerezza.Literal;
/**
* Wraps a {@link Literal} in an {@link Expression}.
*
* @author hasan
*/
public class LiteralExpression implements Expression {
private final Literal literal;
public LiteralExpression(Literal literal) {
this.literal = literal;
}
public Literal getLiteral() {
return literal;
}
}
| 237 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/Expression.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.io.Serializable;
/**
* This interface models logical, relational, and numeric expression.
* This includes terms and factors in mathematical formulas which can contain
* variables, literals, and function calls.
* In a SPARQL query, expressions can occur in an ORDER BY clause or
* a FILTER constraint.
*
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#modOrderBy">
* SPARQL Query Language: 9.1 ORDER BY</a>
*
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#termConstraint">
* SPARQL Query Language: 3 RDF Term Constraints (Informative)</a>
*
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#evaluation">
* SPARQL Query Language: 11.2 Filter Evaluation</a>
*
* @author hasan
*/
public interface Expression extends Serializable {
}
| 238 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/UnaryPropertyPathOperation.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
*
* @author hasan
*/
public class UnaryPropertyPathOperation implements PropertyPathExpression {
private String operator;
private PropertyPathExpression operand;
public UnaryPropertyPathOperation(String operator, PropertyPathExpression operand) {
this.operator = operator;
this.operand = operand;
}
public PropertyPathExpression getOperand() {
return operand;
}
}
| 239 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/Variable.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.UUID;
/**
* Defines a Variable. A Variable can occur in an {@link Expression} and is
* itself an {@link Expression}.
*
* @author hasan
*/
public class Variable implements Expression {
private String name;
private Expression boundExpression;
public Variable() {
this.name = UUID.randomUUID().toString();
}
/**
* Creates a variable with the specified name
*
* @param name
*/
public Variable(String name) {
if (name == null) {
throw new IllegalArgumentException("name may not be null");
}
this.name = name;
}
public Variable(String name, Expression boundExpression) {
this.name = name;
this.boundExpression = boundExpression;
}
/**
* @return the name
*/
public String getName() {
return name;
}
public Expression getBoundExpression() {
return boundExpression;
}
public void setBoundExpression(Expression boundExpression) {
this.boundExpression = boundExpression;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Variable other = (Variable) obj;
return name.equals(other.name);
}
@Override
public int hashCode() {
return name.hashCode();
}
}
| 240 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/AlternativeGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.List;
/**
* Defines alternative ImmutableGraph patterns.
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#alternatives">
* SPARQL Query Language: 7 Matching Alternatives</a>
*
* @author hasan
*/
public interface AlternativeGraphPattern extends GraphPattern {
/**
*
* @return
* a list of alternative {@link GroupGraphPattern}s
*/
public List<GroupGraphPattern> getAlternativeGraphPatterns();
}
| 241 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/BinaryPropertyPathOperation.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
*
* @author hasan
*/
public class BinaryPropertyPathOperation implements PropertyPathExpression {
private String operator;
private PropertyPathExpression lhsOperand;
private PropertyPathExpression rhsOperand;
public BinaryPropertyPathOperation(String operator, PropertyPathExpression lhsOperand, PropertyPathExpression rhsOperand) {
this.operator = operator;
this.lhsOperand = lhsOperand;
this.rhsOperand = rhsOperand;
}
public PropertyPathExpression getLhsOperand() {
return lhsOperand;
}
public PropertyPathExpression getRhsOperand() {
return rhsOperand;
}
}
| 242 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/TriplePattern.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* Defines a triple pattern consisting of a subject, a predicate, and an object.
* The subject and object are of type {@link ResourceOrVariable}, whereas
* the predicate is of type {@link UriRefOrVariable}.
*
* @author hasan
*/
public interface TriplePattern {
/**
* @return the subject
*/
public ResourceOrVariable getSubject();
/**
* @return the predicate
*/
public UriRefOrVariable getPredicate();
/**
* @return the object
*/
public ResourceOrVariable getObject();
}
| 243 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/UriRefOrVariable.java | /*
* 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 org.apache.clerezza.sparql.query;
import org.apache.clerezza.IRI;
/**
* Wraps either a {@link IRI} or a {@link Variable}.
*
* @author rbn
*/
public class UriRefOrVariable extends ResourceOrVariable {
public UriRefOrVariable(Variable variable) {
super(variable);
}
public UriRefOrVariable(IRI resource) {
super(resource);
}
@Override
public IRI getResource() {
return (IRI)super.getResource();
}
}
| 244 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/Query.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* <p>This interface represents a SPARQL query.</p>
* <p>There are four types of SPARQL queries: {@link SelectQuery},
* {@link ConstructQuery}, {@link DescribeQuery}, and {@link AskQuery}.</p>
*
* @author hasan
*/
public interface Query {
/**
* <p>Gets {@link DataSet} containing the specification of the default
* ImmutableGraph and named graphs, if any.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#specifyingDataset">
* SPARQL Query Language: 8.2 Specifying RDF Datasets</a>
* @return
* null if no data set is specified, indicating the use of
* system default ImmutableGraph. Otherwise a {@link DataSet} object is returned.
*/
public DataSet getDataSet();
/**
* <p>Gets the query pattern of the WHERE clause for the query.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#GraphPattern">
* SPARQL Query Language: 5 ImmutableGraph Patterns</a>
* @return
* the {@link GroupGraphPattern} of the WHERE clause for this query.
* If the WHERE clause is not specified, null is returned.
*/
public GroupGraphPattern getQueryPattern();
public InlineData getInlineData();
/**
*
* @return A valid String representation of the query.
*/
@Override
public abstract String toString();
}
| 245 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/PropertyPathPattern.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* Defines a property path pattern consisting of a subject, a property path expression, and an object.
* The subject and object are of type {@link ResourceOrVariable}, whereas
* the predicate is of type {@link PropertyPathExpressionOrVariable}.
* @see <a href="http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#sparqlPropertyPaths">
* SPARQL 1.1 Query Language: 18.1.7 Property Path Patterns</a>
*
* @author hasan
*/
public interface PropertyPathPattern {
/**
* @return the subject
*/
public ResourceOrVariable getSubject();
/**
* @return the property path expression
*/
public PropertyPathExpressionOrVariable getPropertyPathExpression();
/**
* @return the object
*/
public ResourceOrVariable getObject();
}
| 246 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/QueryWithSolutionModifier.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.List;
/**
* <p>This interface represents a SPARQL query which contains a specification
* of solution modifiers: GROUP BY, HAVING, ORDER BY, OFFSET, and LIMIT.</p>
*
* @see <a href="http://www.w3.org/TR/sparql11-query/#aggregates">
* SPARQL 1.1 Query Language: 11 Aggregates</a>
* and
* @see <a href="http://www.w3.org/TR/sparql11-query/#solutionModifiers">
* SPARQL 1.1 Query Language: 15 Solution Sequences and Modifiers</a>
*
* @author hasan
*/
public interface QueryWithSolutionModifier extends Query {
public List<Expression> getGroupConditions();
public List<Expression> getHavingConditions();
/**
* <p>Gets the list of required ordering conditions in decreasing ordering
* priority.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#modOrderBy">
* SPARQL Query Language: 9.1 ORDER BY</a>
* @return A list of {@link OrderCondition}s, in order of priority.
*/
public List<OrderCondition> getOrderConditions();
/**
* <p>Gets the numeric offset of the first row to be returned by the query.
* The default offset is 0, meaning to start at the beginning.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#modOffset">
* SPARQL Query Language: 9.4 OFFSET</a>
* @return The number of rows to skip in the result.
*/
public int getOffset();
/**
* <p>Gets the maximum number of results to be returned by the query.
* A limit of -1 means no limit (return all results).
* A limit of 0 means that no results should be returned.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#modResultLimit">
* SPARQL Query Language: 9.5 LIMIT</a>
* @return The maximum number of rows to returned by the query.
*/
public int getLimit();
}
| 247 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/AskQuery.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* <p>This interface represents a SPARQL ASK query.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#ask">
* SPARQL Query Language: 10.3 ASK</a>
*
* @author hasan
*/
public interface AskQuery extends Query {
}
| 248 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/RhsListBinaryOperation.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.List;
/**
* Defines an operation with two operands: a left hand side and a right hand side operand
* where the right hand side operand is a list.
*
* @author hasan
*/
public class RhsListBinaryOperation extends AbstractOperation {
private Expression lhsOperand;
private List<Expression> rhsOperand;
public RhsListBinaryOperation(String operator, Expression lhsOperand, List<Expression> rhsOperand) {
super(operator);
this.lhsOperand = lhsOperand;
this.rhsOperand = rhsOperand;
}
public Expression getLhsOperand() {
return lhsOperand;
}
public List<Expression> getRhsOperand() {
return rhsOperand;
}
}
| 249 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/AbstractOperation.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* Defines an operation in an {@link Expression}. An operation has an operator
* and one or more operands.
*
* @author hasan
*/
public abstract class AbstractOperation implements Expression {
private String operator;
public AbstractOperation(String operator) {
this.operator = operator;
}
/**
* A string representation of the operator
* @return The operator as a string
*/
public String getOperatorString() {
return operator;
}
}
| 250 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/FunctionCall.java | /*
* 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 org.apache.clerezza.sparql.query;
import org.apache.clerezza.IRI;
import java.util.List;
/**
* Defines a function call which is one form of {@link Expression}.
* A function call has a name of type {@link IRI} and a list of arguments,
* where each argument is an {@link Expression}.
*
* @author hasan
*/
public class FunctionCall implements Expression {
private final IRI name;
private final List<Expression> arguments;
public FunctionCall(IRI name, List<Expression> arguments) {
this.name = name;
this.arguments = arguments;
}
public IRI getName() {
return name;
};
public List<Expression> getArguements() {
return arguments;
}
}
| 251 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/ResourceOrVariable.java | /*
* 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 org.apache.clerezza.sparql.query;
import org.apache.clerezza.RDFTerm;
/**
* Wraps either a {@link RDFTerm} or a {@link Variable}
*
* @author hasan
*/
public class ResourceOrVariable {
private final RDFTerm resource;
private final Variable variable;
public ResourceOrVariable(RDFTerm resource) {
if (resource == null) {
throw new IllegalArgumentException("Invalid resource: null");
}
this.resource = resource;
variable = null;
}
public ResourceOrVariable(Variable variable) {
if (variable == null) {
throw new IllegalArgumentException("Invalid variable: null");
}
this.variable = variable;
resource = null;
}
/**
*
* @return
* true if it is a {@link Variable}, false if it is a {@link RDFTerm}
*/
public boolean isVariable() {
return resource == null;
}
/**
*
* @return
* the wrapped Resource if it is a Resource, null otherwise
*/
public RDFTerm getResource() {
return resource;
}
/**
*
* @return
* the wrapped Variable if it is a Variable, null otherwise
*/
public Variable getVariable() {
return variable;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof ResourceOrVariable)) {
return false;
}
final ResourceOrVariable other = (ResourceOrVariable) obj;
if (this.isVariable() != other.isVariable()) {
return false;
}
if (this.isVariable()) {
if (!this.getVariable().equals(other.getVariable())) {
return false;
}
} else {
if (!this.getResource().equals(other.getResource())) {
return false;
}
}
return true;
}
@Override
public int hashCode() {
return (isVariable()
? 13 * getVariable().hashCode() + 7
: 13 * getResource().hashCode() + 7);
}
}
| 252 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/OrderCondition.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* Defines an order condition in an ORDER BY clause.
*
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#modOrderBy">
* SPARQL Query Language: 9.1 ORDER BY</a>
*
* @author hasan
*/
public interface OrderCondition {
public Expression getExpression();
/**
* @return <code>true</code> if ascending, <code>false</code> if descending
*/
public boolean isAscending();
}
| 253 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/SelectQuery.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.List;
/**
* <p>This interface represents a SPARQL SELECT query.</p>
*
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#select">
* SPARQL Query Language: 10.1 SELECT</a>
*
* @author hasan
*/
public interface SelectQuery extends QueryWithSolutionModifier {
/**
* <p>Tests if this query should return distinct results.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#modDistinct">
* SPARQL Query Language: 9.3.1 DISTINCT</a>
* @return <code>true</code> if the query should return distinct results.
*/
public boolean isDistinct();
/**
* <p>Tests if this query should return reduced results.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#modReduced">
* SPARQL Query Language: 9.3.2 REDUCED</a>
* @return <code>true</code> if the query should return reduced results.
*/
public boolean isReduced();
/**
* <p>Tests if this query returns all its variables, and not a projected subset.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#solutionModifiers">
* SPARQL Query Language: 9 Solution Sequences and Modifiers</a>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#modProjection">
* SPARQL Query Language: 9.2 Projection</a>
* @return <code>true</code> if the query should return all variables.
*/
public boolean isSelectAll();
/**
* <p>Gets the list of {@link Variable}s to project the solution to.
* If {@link #isSelectAll()} returns <code>true</code> then
* this list contains all the variables from the query.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#select">
* SPARQL Query Language: 10.1 SELECT</a>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#modProjection">
* SPARQL Query Language: 9.2 Projection</a>
* @return A list of {@link Variable}s to return from the query.
*/
public List<Variable> getSelection();
}
| 254 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/PredicatePath.java | /*
* 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 org.apache.clerezza.sparql.query;
import org.apache.clerezza.IRI;
/**
*
* @author hasan
*/
public class PredicatePath implements PropertyPathExpression {
private IRI predicatePath;
public PredicatePath(IRI predicatePath) {
this.predicatePath = predicatePath;
}
public IRI getPredicatePath() {
return predicatePath;
}
}
| 255 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/PropertySet.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.HashSet;
import java.util.Set;
/**
* A property set is intended to store only predicate paths and inverse predicate paths.
*
* @author hasan
*/
public class PropertySet implements PropertyPathExpression {
private Set<PropertyPathExpression> propertySet = new HashSet<PropertyPathExpression>();
/**
*
* @param propertyPathExpression expected value is a predicate path or an inverse predicate path
*/
public void addElement(PropertyPathExpression propertyPathExpression) {
this.propertySet.add(propertyPathExpression);
}
public Set<PropertyPathExpression> getPropertySet() {
return propertySet;
}
}
| 256 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/BasicGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.Set;
/**
* Defines a basic ImmutableGraph pattern.
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#BasicGraphPatterns">
* SPARQL Query Language: 5.1 Basic ImmutableGraph Patterns</a>
*
* @author hasan
*/
public interface BasicGraphPattern extends GraphPattern {
/**
*
* @return a set of all triple patterns to match.
*/
public Set<TriplePattern> getTriplePatterns();
}
| 257 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/OptionalGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* Specifying an optional ImmutableGraph pattern implies the existence of a main ImmutableGraph
* pattern.
* The main ImmutableGraph pattern is an empty group pattern if it is not specified.
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#optionals">
* SPARQL Query Language: 6 Including Optional Values</a>
*
* @author hasan
*/
public interface OptionalGraphPattern extends GraphPattern {
/**
*
* @return
* the main ImmutableGraph pattern to match
*/
public GraphPattern getMainGraphPattern();
/**
*
* @return
* the optional ImmutableGraph pattern to match
*/
public GroupGraphPattern getOptionalGraphPattern();
}
| 258 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/ConstructQuery.java | /*
* 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 org.apache.clerezza.sparql.query;
import java.util.Set;
/**
* <p>This interface represents a SPARQL CONSTRUCT query.</p>
*
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#construct">
* SPARQL Query Language: 10.2 CONSTRUCT</a>
*
* @author hasan
*/
public interface ConstructQuery extends QueryWithSolutionModifier {
/**
* <p>Gets the template for constructing triples in a CONSTRUCT query.</p>
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#construct">
* SPARQL Query Language: 10.2 CONSTRUCT</a>
* @return a template as a set of triple patterns for constructing
* new triples.
*/
public Set<TriplePattern> getConstructTemplate();
}
| 259 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/SparqlUnit.java | /*
* 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 org.apache.clerezza.sparql.query;
import org.apache.clerezza.sparql.update.Update;
/**
* <p>This interface represents a SPARQL Query or Update.</p>
*
* @author hasan
*/
public interface SparqlUnit {
/**
*
* @return
* true if it is a {@link Query}, false if it is an {@link Update}
*/
public boolean isQuery();
/**
*
* @return
* the wrapped Query if it is a {@link Query}, null otherwise
*/
public Query getQuery();
/**
*
* @return
* the wrapped Update if it is an {@link Update}, null otherwise
*/
public Update getUpdate();
}
| 260 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/GraphGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* Defines a ImmutableGraph ImmutableGraph pattern.
* @see <a href="http://www.w3.org/TR/rdf-sparql-query/#queryDataset">
* SPARQL Query Language: 8.3 Querying the Dataset</a>
*
* @author hasan
*/
public interface GraphGraphPattern extends GraphPattern {
/**
*
* @return a {@link UriRefOrVariable} which specifies the ImmutableGraph
* against which the pattern should match.
*/
public UriRefOrVariable getGraph();
/**
*
* @return the pattern to match.
*/
public GroupGraphPattern getGroupGraphPattern();
}
| 261 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/UriRefExpression.java | /*
* 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 org.apache.clerezza.sparql.query;
import org.apache.clerezza.IRI;
/**
* Wraps a {@link IRI} in an {@link Expression}.
*
* @author hasan
*/
public class UriRefExpression implements Expression {
private final IRI uriRef;
public UriRefExpression(IRI uriRef) {
this.uriRef = uriRef;
}
public IRI getUriRef() {
return uriRef;
}
}
| 262 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/GraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query;
/**
* This is the generic interface for all types of ImmutableGraph patterns:
* {@link BasicGraphPattern}, {@link PathSupportedBasicGraphPattern}, {@link GroupGraphPattern},
* {@link GraphGraphPattern}, {@link AlternativeGraphPattern}, and
* {@link OptionalGraphPattern}
*
* @author hasan
*/
public interface GraphPattern {
}
| 263 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleSparqlUnit.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.Query;
import org.apache.clerezza.sparql.query.SparqlUnit;
import org.apache.clerezza.sparql.update.Update;
/**
*
* @author hasan
*/
public class SimpleSparqlUnit implements SparqlUnit {
private final Query query;
private final Update update;
public SimpleSparqlUnit(Query query) {
if (query == null) {
throw new IllegalArgumentException("Invalid query: null");
}
this.query = query;
update = null;
}
public SimpleSparqlUnit(Update update) {
if (update == null) {
throw new IllegalArgumentException("Invalid update: null");
}
this.update = update;
query = null;
}
@Override
public boolean isQuery() {
return update == null;
}
@Override
public Query getQuery() {
return query;
}
@Override
public Update getUpdate() {
return update;
}
}
| 264 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleStringQuerySerializer.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.BlankNode;
import org.apache.clerezza.IRI;
import org.apache.clerezza.RDFTerm;
import org.apache.clerezza.sparql.StringQuerySerializer;
import org.apache.clerezza.sparql.query.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Set;
/**
* This class implements abstract methods of {@link StringQuerySerializer}
* to serialize specific {@link Query} types.
*
* @author hasan
*/
public class SimpleStringQuerySerializer extends StringQuerySerializer {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public String serialize(SelectQuery selectQuery) {
StringBuffer s = new StringBuffer("SELECT ");
if (selectQuery.isDistinct()) {
s.append("DISTINCT\n");
}
if (selectQuery.isReduced()) {
s.append("REDUCED\n");
}
if (selectQuery.isSelectAll()) {
s.append("*");
} else {
for (Variable v : selectQuery.getSelection()) {
appendVariable(s, v);
s.append(" ");
}
}
s.append("\n");
appendDataSet(s, (SimpleQuery) selectQuery);
appendWhere(s, (SimpleQuery) selectQuery);
appendModifier(s, (SimpleQueryWithSolutionModifier) selectQuery);
return s.toString();
}
private void appendVariable(StringBuffer s, Variable v) {
s.append("?").append(v.getName());
}
private void appendDataSet(StringBuffer s, SimpleQuery q) {
DataSet dataSet = q.getDataSet();
if (dataSet != null) {
for (IRI dg : dataSet.getDefaultGraphs()) {
s.append("FROM ").append(dg.toString()).append("\n");
}
for (IRI ng : dataSet.getNamedGraphs()) {
s.append("FROM NAMED ").append(ng.toString()).append("\n");
}
}
}
private void appendWhere(StringBuffer s, SimpleQuery q) {
GroupGraphPattern queryPattern = q.getQueryPattern();
if (queryPattern == null) {
return;
}
s.append("WHERE\n");
appendGroupGraphPattern(s, q.getQueryPattern());
}
private void appendGroupGraphPattern(StringBuffer s,
GroupGraphPattern groupGraphPattern) {
s.append("{ ");
for (GraphPattern graphPattern : groupGraphPattern.getGraphPatterns()) {
appendGraphPattern(s, graphPattern);
}
for (Expression e : groupGraphPattern.getFilter()) {
boolean brackettedExpr = !((e instanceof BuiltInCall)
|| (e instanceof FunctionCall));
s.append("FILTER ");
if (brackettedExpr) {
s.append("(");
}
appendExpression(s, e);
if (brackettedExpr) {
s.append(")");
}
s.append("\n");
}
s.append("} ");
}
private void appendGraphPattern(StringBuffer s, GraphPattern graphPattern) {
if (graphPattern instanceof BasicGraphPattern) {
appendTriplePatterns(s,
((BasicGraphPattern) graphPattern).getTriplePatterns());
} else if (graphPattern instanceof GroupGraphPattern) {
appendGroupGraphPattern(s, (GroupGraphPattern) graphPattern);
} else if (graphPattern instanceof OptionalGraphPattern) {
appendGraphPattern(s,
((OptionalGraphPattern) graphPattern).getMainGraphPattern());
s.append(" OPTIONAL ");
appendGroupGraphPattern(s,
((OptionalGraphPattern) graphPattern).getOptionalGraphPattern());
} else if (graphPattern instanceof AlternativeGraphPattern) {
List<GroupGraphPattern> alternativeGraphPatterns =
((AlternativeGraphPattern) graphPattern).getAlternativeGraphPatterns();
if ((alternativeGraphPatterns != null) &&
(!alternativeGraphPatterns.isEmpty())) {
appendGroupGraphPattern(s, alternativeGraphPatterns.get(0));
int size = alternativeGraphPatterns.size();
int i = 1;
while (i < size) {
s.append(" UNION ");
appendGroupGraphPattern(s, alternativeGraphPatterns.get(i));
i++;
}
}
} else if (graphPattern instanceof GraphGraphPattern) {
s.append("ImmutableGraph ");
appendResourceOrVariable(s, ((GraphGraphPattern) graphPattern).getGraph());
s.append(" ");
appendGroupGraphPattern(s, ((GraphGraphPattern) graphPattern).getGroupGraphPattern());
} else {
logger.warn("Unsupported GraphPattern {}", graphPattern.getClass());
}
}
private void appendTriplePatterns(StringBuffer s,
Set<TriplePattern> triplePatterns) {
for (TriplePattern p : triplePatterns) {
appendResourceOrVariable(s, p.getSubject());
s.append(" ");
appendResourceOrVariable(s, p.getPredicate());
s.append(" ");
appendResourceOrVariable(s, p.getObject());
s.append(" .\n");
}
}
private void appendResourceOrVariable(StringBuffer s, ResourceOrVariable n) {
if (n.isVariable()) {
appendVariable(s, n.getVariable());
} else {
RDFTerm r = n.getResource();
if (r instanceof BlankNode) {
s.append("_:").append(r.toString().replace("@", "."));
} else {
s.append(r.toString());
}
}
}
private void appendExpression(StringBuffer s, Expression e) {
if (e instanceof Variable) {
appendVariable(s, (Variable) e);
} else if (e instanceof BinaryOperation) {
BinaryOperation bo = (BinaryOperation) e;
s.append("(");
appendExpression(s, bo.getLhsOperand());
s.append(") ").append(bo.getOperatorString()).append(" (");
appendExpression(s, bo.getRhsOperand());
s.append(")");
} else if (e instanceof UnaryOperation) {
UnaryOperation uo = (UnaryOperation) e;
s.append(uo.getOperatorString()).append(" (");
appendExpression(s, uo.getOperand());
s.append(")");
} else if (e instanceof BuiltInCall) {
BuiltInCall b = (BuiltInCall) e;
appendCall(s, b.getName(), b.getArguements());
} else if (e instanceof FunctionCall) {
FunctionCall f = (FunctionCall) e;
appendCall(s, f.getName().getUnicodeString(), f.getArguements());
} else if (e instanceof LiteralExpression) {
appendLiteralExpression(s, (LiteralExpression) e);
} else if (e instanceof UriRefExpression) {
s.append(((UriRefExpression) e).getUriRef().toString());
}
}
private void appendCall(StringBuffer s, String name, List<Expression> expr) {
s.append(name).append("(");
for (Expression e : expr) {
appendExpression(s, e);
s.append(",");
}
if (expr.isEmpty()) {
s.append(")");
} else {
s.setCharAt(s.length()-1, ')');
}
}
private void appendLiteralExpression(StringBuffer s, LiteralExpression le) {
s.append(le.getLiteral().toString());
}
private void appendModifier(StringBuffer s, SimpleQueryWithSolutionModifier q) {
List<OrderCondition> orderConditions = q.getOrderConditions();
if ((orderConditions != null) && (!orderConditions.isEmpty())) {
s.append("ORDER BY ");
for (OrderCondition oc : orderConditions) {
appendOrderCondition(s, oc);
s.append("\n");
}
}
if (q.getOffset() > 0) {
s.append("OFFSET ").append(q.getOffset()).append("\n");
}
if (q.getLimit() >= 0) {
s.append("LIMIT ").append(q.getLimit()).append("\n");
}
}
private void appendOrderCondition(StringBuffer s, OrderCondition oc) {
if (!oc.isAscending()) {
s.append("DESC(");
}
appendExpression(s, oc.getExpression());
if (!oc.isAscending()) {
s.append(")");
}
s.append(" ");
}
@Override
public String serialize(ConstructQuery constructQuery) {
StringBuffer s = new StringBuffer("CONSTRUCT\n");
Set<TriplePattern> triplePatterns = constructQuery.getConstructTemplate();
s.append("{ ");
if (triplePatterns != null && !triplePatterns.isEmpty()) {
appendTriplePatterns(s, triplePatterns);
}
s.append("}\n");
appendDataSet(s, (SimpleQuery) constructQuery);
appendWhere(s, (SimpleQuery) constructQuery);
appendModifier(s, (SimpleQueryWithSolutionModifier) constructQuery);
return s.toString();
}
@Override
public String serialize(DescribeQuery describeQuery) {
StringBuffer s = new StringBuffer("DESCRIBE\n");
if (describeQuery.isDescribeAll()) {
s.append("*");
} else {
for (ResourceOrVariable n : describeQuery.getResourcesToDescribe()) {
appendResourceOrVariable(s, n);
s.append(" ");
}
}
appendDataSet(s, (SimpleQuery) describeQuery);
appendWhere(s, (SimpleQuery) describeQuery);
appendModifier(s, (SimpleQueryWithSolutionModifier) describeQuery);
return s.toString();
}
@Override
public String serialize(AskQuery askQuery) {
StringBuffer s = new StringBuffer("ASK\n");
appendDataSet(s, (SimpleQuery) askQuery);
appendWhere(s, (SimpleQuery) askQuery);
return s.toString();
}
}
| 265 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleDescribeQuery.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.DescribeQuery;
import org.apache.clerezza.sparql.query.ResourceOrVariable;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author hasan
*/
public class SimpleDescribeQuery extends SimpleQueryWithSolutionModifier
implements DescribeQuery {
private boolean describeAll;
private List<ResourceOrVariable> resourcesToDescribe =
new ArrayList<ResourceOrVariable>();
@Override
public boolean isDescribeAll() {
return describeAll;
}
@Override
public List<ResourceOrVariable> getResourcesToDescribe() {
return resourcesToDescribe;
}
public void setDescribeAll() {
assert resourcesToDescribe.isEmpty();
describeAll = true;
}
public void addResourceToDescribe(ResourceOrVariable node) {
resourcesToDescribe.add(node);
}
@Override
public String toString() {
return (new SimpleStringQuerySerializer()).serialize(this);
}
}
| 266 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleDataSet.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.query.DataSet;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author hasan
*/
public class SimpleDataSet implements DataSet {
private Set<IRI> defaultGraphs = new HashSet<IRI>();
private Set<IRI> namedGraphs = new HashSet<IRI>();
@Override
public Set<IRI> getDefaultGraphs() {
return defaultGraphs;
}
@Override
public Set<IRI> getNamedGraphs() {
return namedGraphs;
}
public void addDefaultGraph(IRI defaultGraph) {
defaultGraphs.add(defaultGraph);
}
public void addNamedGraph(IRI namedGraph) {
namedGraphs.add(namedGraph);
}
}
| 267 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleGraphGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.GraphGraphPattern;
import org.apache.clerezza.sparql.query.GroupGraphPattern;
import org.apache.clerezza.sparql.query.UriRefOrVariable;
/**
*
* @author hasan
*/
public class SimpleGraphGraphPattern implements GraphGraphPattern {
private UriRefOrVariable ImmutableGraph;
private GroupGraphPattern groupGraphPattern;
public SimpleGraphGraphPattern(UriRefOrVariable ImmutableGraph,
GroupGraphPattern groupGraphPattern) {
if (ImmutableGraph == null) {
throw new IllegalArgumentException("ImmutableGraph may not be null");
}
if (groupGraphPattern == null) {
throw new IllegalArgumentException("Group ImmutableGraph Pattern may not be null");
}
this.ImmutableGraph = ImmutableGraph;
this.groupGraphPattern = groupGraphPattern;
}
@Override
public UriRefOrVariable getGraph() {
return ImmutableGraph;
}
@Override
public GroupGraphPattern getGroupGraphPattern() {
return groupGraphPattern;
}
}
| 268 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleServiceGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.GroupGraphPattern;
import org.apache.clerezza.sparql.query.ServiceGraphPattern;
import org.apache.clerezza.sparql.query.UriRefOrVariable;
/**
*
* @author hasan
*/
public class SimpleServiceGraphPattern implements ServiceGraphPattern {
private UriRefOrVariable service;
private GroupGraphPattern groupGraphPattern;
private boolean silent;
public SimpleServiceGraphPattern(UriRefOrVariable service,
GroupGraphPattern groupGraphPattern) {
if (service == null) {
throw new IllegalArgumentException("Service endpoint may not be null");
}
if (groupGraphPattern == null) {
throw new IllegalArgumentException("Group ImmutableGraph Pattern may not be null");
}
this.service = service;
this.groupGraphPattern = groupGraphPattern;
this.silent = false;
}
@Override
public UriRefOrVariable getService() {
return service;
}
@Override
public GroupGraphPattern getGroupGraphPattern() {
return groupGraphPattern;
}
public void setSilent(boolean silent) {
this.silent = silent;
}
public boolean isSilent() {
return silent;
}
}
| 269 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleBasicGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.BasicGraphPattern;
import org.apache.clerezza.sparql.query.TriplePattern;
import java.util.LinkedHashSet;
import java.util.Set;
/**
*
* @author hasan
*/
public class SimpleBasicGraphPattern implements BasicGraphPattern {
private Set<TriplePattern> triplePatterns;
public SimpleBasicGraphPattern(Set<TriplePattern> triplePatterns) {
this.triplePatterns = (triplePatterns == null)
? new LinkedHashSet<TriplePattern>()
: triplePatterns;
}
@Override
public Set<TriplePattern> getTriplePatterns() {
return triplePatterns;
}
public void addTriplePatterns(Set<TriplePattern> triplePatterns) {
this.triplePatterns.addAll(triplePatterns);
}
}
| 270 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleInlineData.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.RDFTerm;
import org.apache.clerezza.sparql.query.InlineData;
import org.apache.clerezza.sparql.query.Variable;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author hasan
*/
public class SimpleInlineData implements InlineData {
private List<Variable> variables = new ArrayList<Variable>();
private List<List<RDFTerm>> values = new ArrayList<List<RDFTerm>>();
@Override
public List<Variable> getVariables() {
return variables;
}
@Override
public List<List<RDFTerm>> getValues() {
return values;
}
public void addVariable(Variable variable) {
variables.add(variable);
}
public void addValues(List<RDFTerm> values) {
this.values.add(values);
}
}
| 271 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleQueryWithSolutionModifier.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.Expression;
import org.apache.clerezza.sparql.query.OrderCondition;
import org.apache.clerezza.sparql.query.QueryWithSolutionModifier;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author hasan
*/
public abstract class SimpleQueryWithSolutionModifier extends SimpleQuery
implements QueryWithSolutionModifier {
private List<Expression> groupConditions = new ArrayList<Expression>();
private List<Expression> havingConditions = new ArrayList<Expression>();
private List<OrderCondition> orderConditions = new ArrayList<OrderCondition>();
/**
* Result offset. 0 means no offset.
*/
private int offset = 0;
/**
* Result limit. -1 means no limit.
*/
private int limit = -1;
@Override
public List<Expression> getGroupConditions() {
return groupConditions;
}
@Override
public List<Expression> getHavingConditions() {
return havingConditions;
}
@Override
public List<OrderCondition> getOrderConditions() {
return orderConditions;
}
@Override
public int getOffset() {
return offset;
}
@Override
public int getLimit() {
return limit;
}
public void addGroupCondition(Expression groupCondition) {
groupConditions.add(groupCondition);
}
public void addHavingCondition(Expression havingCondition) {
havingConditions.add(havingCondition);
}
public void addOrderCondition(OrderCondition orderCondition) {
orderConditions.add(orderCondition);
}
public void setOffset(int offset) {
this.offset = offset;
}
public void setLimit(int limit) {
this.limit = limit;
}
}
| 272 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleAskQuery.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.AskQuery;
/**
*
* @author hasan
*/
public class SimpleAskQuery extends SimpleQueryWithSolutionModifier implements AskQuery {
@Override
public String toString() {
return (new SimpleStringQuerySerializer()).serialize(this);
}
}
| 273 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleMinusGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.GraphPattern;
import org.apache.clerezza.sparql.query.GroupGraphPattern;
import org.apache.clerezza.sparql.query.MinusGraphPattern;
/**
* This class implements {@link MinusGraphPattern}.
*
* @author hasan
*/
public class SimpleMinusGraphPattern implements MinusGraphPattern {
private GraphPattern minuendGraphPattern;
private GroupGraphPattern subtrahendGraphPattern;
/**
* Constructs a {@link MinusGraphPattern} out of a {@link GraphPattern}
* as the minuend ImmutableGraph pattern and a {@link GroupGraphPattern} as the
* subtrahend pattern.
*
* @param minuendGraphPattern
* a {@link GraphPattern} specifying the minuend pattern.
* @param subtrahendGraphPattern
* a {@link GroupGraphPattern} specifying the subtrahend pattern.
*/
public SimpleMinusGraphPattern(GraphPattern minuendGraphPattern, GroupGraphPattern subtrahendGraphPattern) {
if (subtrahendGraphPattern == null) {
throw new IllegalArgumentException("Subtrahend ImmutableGraph pattern may not be null");
}
if (minuendGraphPattern == null) {
this.minuendGraphPattern = new SimpleGroupGraphPattern();
} else {
this.minuendGraphPattern = minuendGraphPattern;
}
this.subtrahendGraphPattern = subtrahendGraphPattern;
}
@Override
public GraphPattern getMinuendGraphPattern() {
return minuendGraphPattern;
}
@Override
public GroupGraphPattern getSubtrahendGraphPattern() {
return subtrahendGraphPattern;
}
}
| 274 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleConstructQuery.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.ConstructQuery;
import org.apache.clerezza.sparql.query.TriplePattern;
import java.util.LinkedHashSet;
import java.util.Set;
/**
*
* @author hasan
*/
public class SimpleConstructQuery extends SimpleQueryWithSolutionModifier
implements ConstructQuery {
private Set<TriplePattern> triplePatterns;
public SimpleConstructQuery(Set<TriplePattern> triplePatterns) {
this.triplePatterns = (triplePatterns == null)
? new LinkedHashSet<TriplePattern>()
: triplePatterns;
}
@Override
public Set<TriplePattern> getConstructTemplate() {
return triplePatterns;
}
@Override
public String toString() {
return (new SimpleStringQuerySerializer()).serialize(this);
}
}
| 275 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimplePropertyPathPattern.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.BlankNodeOrIRI;
import org.apache.clerezza.RDFTerm;
import org.apache.clerezza.sparql.query.*;
/**
*
* @author hasan
*/
public class SimplePropertyPathPattern implements PropertyPathPattern {
private ResourceOrVariable subject;
private PropertyPathExpressionOrVariable propertyPathExpression;
private ResourceOrVariable object;
public SimplePropertyPathPattern(ResourceOrVariable subject,
PropertyPathExpressionOrVariable propertyPathExpression,
ResourceOrVariable object) {
if (subject == null) {
throw new IllegalArgumentException("Invalid subject: null");
}
if (propertyPathExpression == null) {
throw new IllegalArgumentException("Invalid property path expression: null");
}
if (object == null) {
throw new IllegalArgumentException("Invalid object: null");
}
this.subject = subject;
this.propertyPathExpression = propertyPathExpression;
this.object = object;
}
public SimplePropertyPathPattern(Variable subject, Variable propertyPathExpression, Variable object) {
this(new ResourceOrVariable(subject), new PropertyPathExpressionOrVariable(propertyPathExpression),
new ResourceOrVariable(object));
}
public SimplePropertyPathPattern(BlankNodeOrIRI subject, Variable propertyPathExpression, Variable object) {
this(new ResourceOrVariable(subject), new PropertyPathExpressionOrVariable(propertyPathExpression),
new ResourceOrVariable(object));
}
public SimplePropertyPathPattern(Variable subject, Variable propertyPathExpression, RDFTerm object) {
this(new ResourceOrVariable(subject), new PropertyPathExpressionOrVariable(propertyPathExpression),
new ResourceOrVariable(object));
}
public SimplePropertyPathPattern(BlankNodeOrIRI subject, Variable propertyPathExpression, RDFTerm object) {
this(new ResourceOrVariable(subject), new PropertyPathExpressionOrVariable(propertyPathExpression),
new ResourceOrVariable(object));
}
public SimplePropertyPathPattern(Variable subject, PropertyPathExpression propertyPathExpression, Variable object) {
this(new ResourceOrVariable(subject), new PropertyPathExpressionOrVariable(propertyPathExpression),
new ResourceOrVariable(object));
}
public SimplePropertyPathPattern(BlankNodeOrIRI subject, PropertyPathExpression propertyPathExpression, Variable object) {
this(new ResourceOrVariable(subject), new PropertyPathExpressionOrVariable(propertyPathExpression),
new ResourceOrVariable(object));
}
public SimplePropertyPathPattern(Variable subject, PropertyPathExpression propertyPathExpression, RDFTerm object) {
this(new ResourceOrVariable(subject), new PropertyPathExpressionOrVariable(propertyPathExpression),
new ResourceOrVariable(object));
}
public SimplePropertyPathPattern(BlankNodeOrIRI subject, PropertyPathExpression propertyPathExpression, RDFTerm object) {
this(new ResourceOrVariable(subject), new PropertyPathExpressionOrVariable(propertyPathExpression),
new ResourceOrVariable(object));
}
@Override
public ResourceOrVariable getSubject() {
return subject;
}
@Override
public PropertyPathExpressionOrVariable getPropertyPathExpression() {
return propertyPathExpression;
}
@Override
public ResourceOrVariable getObject() {
return object;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof PropertyPathPattern)) {
return false;
}
final PropertyPathPattern other = (PropertyPathPattern) obj;
if (!this.subject.equals(other.getSubject())) {
return false;
}
if (!this.propertyPathExpression.equals(other.getPropertyPathExpression())) {
return false;
}
if (!this.object.equals(other.getObject())) {
return false;
}
return true;
}
@Override
public int hashCode() {
return (subject.hashCode() >> 1) ^ propertyPathExpression.hashCode() ^ (object.hashCode() << 1);
}
}
| 276 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleOrderCondition.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.Expression;
import org.apache.clerezza.sparql.query.OrderCondition;
/**
*
* @author hasan
*/
public class SimpleOrderCondition implements OrderCondition {
private Expression expression;
private boolean ascending;
public SimpleOrderCondition(Expression expression, boolean ascending) {
this.expression = expression;
this.ascending = ascending;
}
@Override
public Expression getExpression() {
return expression;
}
@Override
public boolean isAscending() {
return ascending;
}
}
| 277 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleSelectQuery.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.SelectQuery;
import org.apache.clerezza.sparql.query.Variable;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author hasan
*/
public class SimpleSelectQuery extends SimpleQueryWithSolutionModifier
implements SelectQuery {
private boolean distinct;
private boolean reduced;
private boolean selectAll;
private List<Variable> variables = new ArrayList<Variable>();
@Override
public boolean isDistinct() {
return distinct;
}
@Override
public boolean isReduced() {
return reduced;
}
@Override
public boolean isSelectAll() {
return selectAll;
}
@Override
public List<Variable> getSelection() {
return variables;
}
public void setDistinct() {
distinct = true;
}
public void setReduced() {
reduced = true;
}
public void setSelectAll() {
assert variables.isEmpty();
selectAll = true;
}
public void addSelection(Variable var) {
variables.add(var);
}
@Override
public String toString() {
return (new SimpleStringQuerySerializer()).serialize(this);
}
}
| 278 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleTriplePattern.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.BlankNodeOrIRI;
import org.apache.clerezza.IRI;
import org.apache.clerezza.RDFTerm;
import org.apache.clerezza.sparql.query.ResourceOrVariable;
import org.apache.clerezza.sparql.query.TriplePattern;
import org.apache.clerezza.sparql.query.UriRefOrVariable;
import org.apache.clerezza.sparql.query.Variable;
/**
*
* @author hasan
*/
public class SimpleTriplePattern implements TriplePattern {
private ResourceOrVariable subject;
private UriRefOrVariable predicate;
private ResourceOrVariable object;
public SimpleTriplePattern(ResourceOrVariable subject,
UriRefOrVariable predicate,
ResourceOrVariable object) {
if (subject == null) {
throw new IllegalArgumentException("Invalid subject: null");
}
if (predicate == null) {
throw new IllegalArgumentException("Invalid predicate: null");
}
if (object == null) {
throw new IllegalArgumentException("Invalid object: null");
}
this.subject = subject;
this.predicate = predicate;
this.object = object;
}
public SimpleTriplePattern(Variable subject, Variable predicate, Variable object) {
this(new ResourceOrVariable(subject), new UriRefOrVariable(predicate),
new ResourceOrVariable(object));
}
public SimpleTriplePattern(BlankNodeOrIRI subject, Variable predicate, Variable object) {
this(new ResourceOrVariable(subject), new UriRefOrVariable(predicate),
new ResourceOrVariable(object));
}
public SimpleTriplePattern(Variable subject, IRI predicate, Variable object) {
this(new ResourceOrVariable(subject), new UriRefOrVariable(predicate),
new ResourceOrVariable(object));
}
public SimpleTriplePattern(BlankNodeOrIRI subject, IRI predicate, Variable object) {
this(new ResourceOrVariable(subject), new UriRefOrVariable(predicate),
new ResourceOrVariable(object));
}
public SimpleTriplePattern(Variable subject, Variable predicate, RDFTerm object) {
this(new ResourceOrVariable(subject), new UriRefOrVariable(predicate),
new ResourceOrVariable(object));
}
public SimpleTriplePattern(BlankNodeOrIRI subject, Variable predicate, RDFTerm object) {
this(new ResourceOrVariable(subject), new UriRefOrVariable(predicate),
new ResourceOrVariable(object));
}
public SimpleTriplePattern(Variable subject, IRI predicate, RDFTerm object) {
this(new ResourceOrVariable(subject), new UriRefOrVariable(predicate),
new ResourceOrVariable(object));
}
public SimpleTriplePattern(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
this(new ResourceOrVariable(subject), new UriRefOrVariable(predicate),
new ResourceOrVariable(object));
}
@Override
public ResourceOrVariable getSubject() {
return subject;
}
@Override
public UriRefOrVariable getPredicate() {
return predicate;
}
@Override
public ResourceOrVariable getObject() {
return object;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof TriplePattern)) {
return false;
}
final TriplePattern other = (TriplePattern) obj;
if (!this.subject.equals(other.getSubject())) {
return false;
}
if (!this.predicate.equals(other.getPredicate())) {
return false;
}
if (!this.object.equals(other.getObject())) {
return false;
}
return true;
}
@Override
public int hashCode() {
return (subject.hashCode() >> 1) ^ subject.hashCode() ^ (subject.hashCode() << 1);
}
}
| 279 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleAlternativeGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.AlternativeGraphPattern;
import org.apache.clerezza.sparql.query.GroupGraphPattern;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author hasan
*/
public class SimpleAlternativeGraphPattern implements AlternativeGraphPattern {
private List<GroupGraphPattern> alternativeGraphPatterns;
public SimpleAlternativeGraphPattern(
List<GroupGraphPattern> alternativeGraphPatterns) {
this.alternativeGraphPatterns = (alternativeGraphPatterns == null)
? new ArrayList<GroupGraphPattern>()
: alternativeGraphPatterns;
this.alternativeGraphPatterns = alternativeGraphPatterns;
}
public SimpleAlternativeGraphPattern(GroupGraphPattern... groupGraphPatterns) {
alternativeGraphPatterns = new ArrayList<GroupGraphPattern>();
GroupGraphPattern[] g = groupGraphPatterns;
for (int i = 0; i < g.length; i++) {
alternativeGraphPatterns.add(g[i]);
}
}
@Override
public List<GroupGraphPattern> getAlternativeGraphPatterns() {
return alternativeGraphPatterns;
}
public void addAlternativeGraphPattern(GroupGraphPattern groupGraphPattern) {
alternativeGraphPatterns.add(groupGraphPattern);
}
}
| 280 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleQuery.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.query.DataSet;
import org.apache.clerezza.sparql.query.GroupGraphPattern;
import org.apache.clerezza.sparql.query.InlineData;
import org.apache.clerezza.sparql.query.Query;
/**
*
* @author hasan
*/
public abstract class SimpleQuery implements Query {
private SimpleDataSet dataSet = null;
private GroupGraphPattern queryPattern = null;
private InlineData inlineData = null;
@Override
public DataSet getDataSet() {
return dataSet;
}
@Override
public GroupGraphPattern getQueryPattern() {
return queryPattern;
}
@Override
public InlineData getInlineData() {
return inlineData;
}
public void addDefaultGraph(IRI defaultGraph) {
if (dataSet == null) {
dataSet = new SimpleDataSet();
}
dataSet.addDefaultGraph(defaultGraph);
}
public void addNamedGraph(IRI namedGraph) {
if (dataSet == null) {
dataSet = new SimpleDataSet();
}
dataSet.addNamedGraph(namedGraph);
}
public void setQueryPattern(GroupGraphPattern queryPattern) {
this.queryPattern = queryPattern;
}
public void setInlineData(InlineData inlineData) {
this.inlineData = inlineData;
}
@Override
public abstract String toString();
}
| 281 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleGroupGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.IRI;
import org.apache.clerezza.sparql.query.*;
import java.util.*;
/**
* This class implements {@link GroupGraphPattern}.
*
* @author hasan
*/
public class SimpleGroupGraphPattern implements GroupGraphPattern {
private List<Expression> constraints = new ArrayList<Expression>();
private List<GraphPattern> graphPatterns = new ArrayList<GraphPattern>();
private SelectQuery subSelect = null;
private boolean lastBasicGraphPatternIsComplete = true;
@Override
public boolean isSubSelect() {
return subSelect != null;
}
@Override
public SelectQuery getSubSelect() {
return subSelect;
}
@Override
public Set<GraphPattern> getGraphPatterns() {
return subSelect == null ? new LinkedHashSet(graphPatterns) : null;
}
@Override
public List<Expression> getFilter() {
return subSelect == null ? constraints : null;
}
public void setSubSelect(SelectQuery subSelect) {
this.subSelect = subSelect;
}
/**
* Adds a {@link GraphPattern} to the group.
*
* @param graphPattern
* the GraphPattern to be added.
*/
public void addGraphPattern(GraphPattern graphPattern) {
subSelect = null;
graphPatterns.add(graphPattern);
lastBasicGraphPatternIsComplete =
!(graphPattern instanceof BasicGraphPattern || graphPattern instanceof PathSupportedBasicGraphPattern);
}
/**
* Adds a constraint to the {@link GroupGraphPattern}.
*
* @param constraint
* an {@link Expression} as the constraint to be added.
*/
public void addConstraint(Expression constraint) {
subSelect = null;
constraints.add(constraint);
}
public void endLastBasicGraphPattern() {
lastBasicGraphPatternIsComplete = true;
}
/**
* If the last {@link GraphPattern} added to the group is not a
* {@link SimplePathSupportedBasicGraphPattern}, then creates one containing the
* specified {@link PropertyPathPattern}s and adds it to the group.
* Otherwise, adds the specified {@link PropertyPathPattern}s to the last
* added {@link SimplePathSupportedBasicGraphPattern} in the group.
*
* @param propertyPathPatterns
* a set of {@link PropertyPathPattern}s to be added into a
* {@link SimplePathSupportedBasicGraphPattern} of the group.
*/
public void addPropertyPathPatterns(Set<PropertyPathPattern> propertyPathPatterns) {
subSelect = null;
if (lastBasicGraphPatternIsComplete) {
graphPatterns.add(new SimplePathSupportedBasicGraphPattern(propertyPathPatterns));
lastBasicGraphPatternIsComplete = false;
} else {
GraphPattern prevGraphPattern;
int size = graphPatterns.size();
prevGraphPattern = graphPatterns.get(size-1);
if (prevGraphPattern instanceof SimplePathSupportedBasicGraphPattern) {
((SimplePathSupportedBasicGraphPattern) prevGraphPattern).addPropertyPathPatterns(propertyPathPatterns);
}
}
}
/**
* If the last {@link GraphPattern} added to the group is not a
* {@link SimpleBasicGraphPattern}, then creates one containing the
* specified {@link TriplePattern}s and adds it to the group.
* Otherwise, adds the specified {@link TriplePattern}s to the last
* added {@link SimpleBasicGraphPattern} in the group.
*
* @param triplePatterns
* a set of {@link TriplePattern}s to be added into a
* {@link SimpleBasicGraphPattern} of the group.
*/
public void addTriplePatterns(Set<TriplePattern> triplePatterns) {
subSelect = null;
GraphPattern prevGraphPattern;
int size = graphPatterns.size();
if (!lastBasicGraphPatternIsComplete && (size > 0)) {
prevGraphPattern = graphPatterns.get(size-1);
if (prevGraphPattern instanceof SimpleBasicGraphPattern) {
((SimpleBasicGraphPattern) prevGraphPattern)
.addTriplePatterns(triplePatterns);
return;
}
}
graphPatterns.add(new SimpleBasicGraphPattern(triplePatterns));
lastBasicGraphPatternIsComplete = false;
}
/**
* Adds an {@link OptionalGraphPattern} to the group consisting of
* a main ImmutableGraph pattern and the specified {@link GroupGraphPattern} as
* the optional pattern.
* The main ImmutableGraph pattern is taken from the last added {@link GraphPattern}
* in the group, if it exists. Otherwise, the main ImmutableGraph pattern is null.
*
* @param optional
* a {@link GroupGraphPattern} as the optional pattern of
* an {@link OptionalGraphPattern}.
*/
public void addOptionalGraphPattern(GroupGraphPattern optional) {
subSelect = null;
GraphPattern prevGraphPattern = null;
int size = graphPatterns.size();
if (size > 0) {
prevGraphPattern = graphPatterns.remove(size-1);
}
graphPatterns.add(new SimpleOptionalGraphPattern(prevGraphPattern, optional));
lastBasicGraphPatternIsComplete = true;
}
public void addMinusGraphPattern(GroupGraphPattern subtrahend) {
subSelect = null;
GraphPattern prevGraphPattern = null;
int size = graphPatterns.size();
if (size > 0) {
prevGraphPattern = graphPatterns.remove(size-1);
}
graphPatterns.add(new SimpleMinusGraphPattern(prevGraphPattern, subtrahend));
lastBasicGraphPatternIsComplete = true;
}
@Override
public Set<IRI> getReferredGraphs() {
Set<IRI> referredGraphs = new HashSet<IRI>();
if (subSelect != null) {
GroupGraphPattern queryPattern = subSelect.getQueryPattern();
referredGraphs.addAll(queryPattern.getReferredGraphs());
} else {
for (GraphPattern graphPattern : graphPatterns) {
referredGraphs.addAll(getReferredGraphs(graphPattern));
}
}
return referredGraphs;
}
private Set<IRI> getReferredGraphs(GraphPattern graphPattern) {
Set<IRI> referredGraphs = new HashSet<IRI>();
if (graphPattern instanceof GraphGraphPattern) {
GraphGraphPattern graphGraphPattern = (GraphGraphPattern) graphPattern;
UriRefOrVariable ImmutableGraph = graphGraphPattern.getGraph();
if (!ImmutableGraph.isVariable()) {
referredGraphs.add(ImmutableGraph.getResource());
}
referredGraphs.addAll(graphGraphPattern.getGroupGraphPattern().getReferredGraphs());
} else if (graphPattern instanceof AlternativeGraphPattern) {
List<GroupGraphPattern> alternativeGraphPatterns =
((AlternativeGraphPattern) graphPattern).getAlternativeGraphPatterns();
for (GroupGraphPattern groupGraphPattern : alternativeGraphPatterns) {
referredGraphs.addAll(groupGraphPattern.getReferredGraphs());
}
} else if (graphPattern instanceof OptionalGraphPattern) {
GraphPattern mainGraphPattern = ((OptionalGraphPattern) graphPattern).getMainGraphPattern();
referredGraphs.addAll(getReferredGraphs(mainGraphPattern));
GroupGraphPattern optionalGraphPattern = ((OptionalGraphPattern) graphPattern).getOptionalGraphPattern();
referredGraphs.addAll(optionalGraphPattern.getReferredGraphs());
} else if (graphPattern instanceof MinusGraphPattern) {
GraphPattern minuendGraphPattern = ((MinusGraphPattern) graphPattern).getMinuendGraphPattern();
referredGraphs.addAll(getReferredGraphs(minuendGraphPattern));
GroupGraphPattern subtrahendGraphPattern = ((MinusGraphPattern) graphPattern).getSubtrahendGraphPattern();
referredGraphs.addAll(subtrahendGraphPattern.getReferredGraphs());
} else if (graphPattern instanceof GroupGraphPattern) {
GroupGraphPattern groupGraphPattern = (GroupGraphPattern) graphPattern;
referredGraphs.addAll(groupGraphPattern.getReferredGraphs());
}
return referredGraphs;
}
}
| 282 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimpleOptionalGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.GraphPattern;
import org.apache.clerezza.sparql.query.GroupGraphPattern;
import org.apache.clerezza.sparql.query.OptionalGraphPattern;
/**
* This class implements {@link OptionalGraphPattern}.
*
* @author hasan
*/
public class SimpleOptionalGraphPattern implements OptionalGraphPattern {
private GraphPattern mainGraphPattern;
private GroupGraphPattern optionalGraphPattern;
/**
* Constructs an {@link OptionalGraphPattern} out of a {@link GraphPattern}
* as the main ImmutableGraph pattern and a {@link GroupGraphPattern} as the
* optional pattern.
*
* @param mainGraphPattern
* a {@link GraphPattern} specifying the main pattern.
* @param optionalGraphPattern
* a {@link GroupGraphPattern} specifying the optional pattern.
*/
public SimpleOptionalGraphPattern(GraphPattern mainGraphPattern,
GroupGraphPattern optionalGraphPattern) {
if (optionalGraphPattern == null) {
throw new IllegalArgumentException("Optional ImmutableGraph pattern may not be null");
}
if (mainGraphPattern == null) {
this.mainGraphPattern = new SimpleGroupGraphPattern();
} else {
this.mainGraphPattern = mainGraphPattern;
}
this.optionalGraphPattern = optionalGraphPattern;
}
@Override
public GraphPattern getMainGraphPattern() {
return mainGraphPattern;
}
@Override
public GroupGraphPattern getOptionalGraphPattern() {
return optionalGraphPattern;
}
}
| 283 |
0 | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query | Create_ds/clerezza/sparql/src/main/java/org/apache/clerezza/sparql/query/impl/SimplePathSupportedBasicGraphPattern.java | /*
* 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 org.apache.clerezza.sparql.query.impl;
import org.apache.clerezza.sparql.query.PathSupportedBasicGraphPattern;
import org.apache.clerezza.sparql.query.PropertyPathPattern;
import java.util.LinkedHashSet;
import java.util.Set;
/**
*
* @author hasan
*/
public class SimplePathSupportedBasicGraphPattern implements PathSupportedBasicGraphPattern {
private Set<PropertyPathPattern> propertyPathPatterns;
public SimplePathSupportedBasicGraphPattern(Set<PropertyPathPattern> propertyPathPatterns) {
this.propertyPathPatterns = (propertyPathPatterns == null)
? new LinkedHashSet<PropertyPathPattern>()
: propertyPathPatterns;
}
@Override
public Set<PropertyPathPattern> getPropertyPathPatterns() {
return propertyPathPatterns;
}
public void addPropertyPathPatterns(Set<PropertyPathPattern> propertyPathPatterns) {
this.propertyPathPatterns.addAll(propertyPathPatterns);
}
}
| 284 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset/SecurityTest.java | /*
* 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 org.apache.clerezza.dataset;
import org.apache.clerezza.Graph;
import org.apache.clerezza.IRI;
import org.apache.clerezza.Triple;
import org.apache.clerezza.dataset.providers.WeightedA;
import org.apache.clerezza.dataset.providers.WeightedDummy;
import org.apache.clerezza.dataset.security.TcPermission;
import org.apache.clerezza.implementation.TripleImpl;
import org.apache.clerezza.implementation.graph.ReadOnlyException;
import org.apache.clerezza.implementation.literal.PlainLiteralImpl;
import org.junit.jupiter.api.*;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import java.io.FilePermission;
import java.lang.reflect.ReflectPermission;
import java.security.*;
import java.util.Collections;
import java.util.PropertyPermission;
import static org.slf4j.LoggerFactory.getLogger;
/**
*
* @author reto
*/
@RunWith(JUnitPlatform.class)
public class SecurityTest {
private static final Logger LOGGER = getLogger(SecurityTest.class);
public SecurityTest() {
}
@BeforeAll
public static void setUpClass() throws Exception {
////needed to unbind because this is injected with META-INF/services - file
TcManager.getInstance().unbindWeightedTcProvider(new WeightedA());
TcManager.getInstance().bindWeightedTcProvider(new WeightedDummy());
TcManager.getInstance().createGraph(new IRI("http://example.org/ImmutableGraph/alreadyexists"));
TcManager.getInstance().createGraph(new IRI("http://example.org/read/ImmutableGraph"));
}
@AfterAll
public static void tearDownClass() throws Exception {
}
@BeforeEach
public void setUp() {
Policy.setPolicy(new Policy() {
@Override
public PermissionCollection getPermissions(CodeSource codeSource) {
PermissionCollection result = new Permissions();
result.add(new TcPermission("http://example.org/permitted", "read"));
result.add(new TcPermission("http://example.org/ImmutableGraph/alreadyexists", "readwrite"));
result.add(new TcPermission("http://example.org/read/ImmutableGraph", "read"));
result.add(new TcPermission("http://example.org/area/allowed/*", "readwrite"));
result.add(new TcPermission("urn:x-localinstance:/graph-access.graph", "readwrite"));
//result.add(new AllPermission());
result.add(new RuntimePermission("*"));
result.add(new ReflectPermission("suppressAccessChecks"));
result.add(new PropertyPermission("*", "read"));
//(java.util.PropertyPermission line.separator read)
result.add(new FilePermission("/-", "read,write"));
return result;
}
});
System.setSecurityManager(new SecurityManager() {
@Override
public void checkPermission(Permission perm) {
LOGGER.debug("Checking {}", perm);
super.checkPermission(perm);
}
@Override
public void checkPermission(Permission perm, Object context) {
LOGGER.debug("Checking {}", perm);
super.checkPermission(perm, context);
}
});
}
@AfterEach
public void tearDown() {
System.setSecurityManager(null);
}
@Test
public void testAcessGraph()
{
Assertions.assertThrows(
NoSuchEntityException.class,
() -> TcManager.getInstance().getImmutableGraph(new IRI("http://example.org/permitted"))
);
}
@Test
public void testNoWildCard() {
Assertions.assertThrows(
AccessControlException.class,
() -> TcManager.getInstance().getImmutableGraph(
new IRI("http://example.org/permitted/subthing")
)
);
}
@Test
public void testAllowedArea() {
Assertions.assertThrows(
NoSuchEntityException.class,
() -> TcManager.getInstance().getImmutableGraph(
new IRI("http://example.org/area/allowed/something")
)
);
}
@Test
public void testAcessForbiddenGraph() {
Assertions.assertThrows(
AccessControlException.class,
() -> TcManager.getInstance().getImmutableGraph(new IRI("http://example.org/forbidden"))
);
}
@Test
public void testCustomPermissions() {
IRI graphUri = new IRI("http://example.org/custom");
TcManager.getInstance().getTcAccessController().setRequiredReadPermissionStrings(graphUri,
Collections.singletonList("(java.io.FilePermission \"/etc\" \"write\")"));
//new FilePermission("/etc", "write").toString()));
Graph ag = TcManager.getInstance().getGraph(new IRI("urn:x-localinstance:/graph-access.graph"));
LOGGER.info("Custom permissions graph: {}", ag);
Assertions.assertThrows(
NoSuchEntityException.class,
() -> TcManager.getInstance().getMGraph(graphUri)
);
}
@Test
public void testCustomPermissionsIncorrect() {
IRI graphUri = new IRI("http://example.org/custom");
TcManager.getInstance().getTcAccessController().setRequiredReadPermissionStrings(graphUri,
Collections.singletonList("(java.io.FilePermission \"/etc\" \"write\")"));
//new FilePermission("/etc", "write").toString()));
Graph ag = TcManager.getInstance().getGraph(new IRI("urn:x-localinstance:/graph-access.graph"));
LOGGER.info("Incorrect custom permissions graph: {}", ag);
Assertions.assertThrows(
AccessControlException.class,
() -> TcManager.getInstance().createGraph(graphUri)
);
}
@Test
public void testCustomReadWritePermissions() {
IRI graphUri = new IRI("http://example.org/read-write-custom");
TcManager.getInstance().getTcAccessController().setRequiredReadWritePermissionStrings(graphUri,
Collections.singletonList("(java.io.FilePermission \"/etc\" \"write\")"));
//new FilePermission("/etc", "write").toString()));
Graph ag = TcManager.getInstance().getGraph(new IRI("urn:x-localinstance:/graph-access.graph"));
LOGGER.info("Custom read/write permissions graph: {}", ag);
TcManager.getInstance().createGraph(graphUri);
}
@Test
public void testCreateMGraph() {
Assertions.assertThrows(
EntityAlreadyExistsException.class,
() -> TcManager.getInstance().createGraph(
new IRI("http://example.org/ImmutableGraph/alreadyexists")
)
);
}
@Test
public void testCreateMGraphWithoutWritePermission() {
Assertions.assertThrows(
AccessControlException.class,
() -> TcManager.getInstance().createGraph(new IRI("http://example.org/read/ImmutableGraph"))
);
}
@Test
public void testAddTripleToMGraph() {
Graph graph = TcManager.getInstance().getMGraph(new IRI("http://example.org/read/ImmutableGraph"));
Triple triple = new TripleImpl(
new IRI("http://example.org/definition/isNonLiteral"),
new IRI("http://example.org/definition/isTest"),
new PlainLiteralImpl("test"));
Assertions.assertThrows(ReadOnlyException.class, () -> graph.add(triple));
}
}
| 285 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset/TcManagerTest.java | /*
* 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 org.apache.clerezza.dataset;
import org.apache.clerezza.Graph;
import org.apache.clerezza.IRI;
import org.apache.clerezza.ImmutableGraph;
import org.apache.clerezza.Triple;
import org.apache.clerezza.dataset.providers.WeightedA;
import org.apache.clerezza.dataset.providers.WeightedA1;
import org.apache.clerezza.dataset.providers.WeightedAHeavy;
import org.apache.clerezza.dataset.providers.WeightedBlight;
import org.apache.clerezza.implementation.TripleImpl;
import org.apache.clerezza.implementation.in_memory.SimpleGraph;
import org.apache.clerezza.sparql.NoQueryEngineException;
import org.apache.clerezza.sparql.QueryEngine;
import org.apache.clerezza.sparql.query.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import java.lang.reflect.Field;
import java.util.Iterator;
import static org.junit.jupiter.api.Assertions.*;
/**
*
* @author reto
*/
@RunWith(JUnitPlatform.class)
public class TcManagerTest {
public static IRI uriRefAHeavy = new IRI("http://example.org/aHeavy");
public static IRI uriRefB = new IRI("http://example.org/b");;
public static final IRI uriRefA = new IRI("http://example.org/a");
public static final IRI uriRefA1 = new IRI("http://example.org/a1");
private TcManager graphAccess;
private QueryEngine queryEngine;
private final WeightedA weightedA = new WeightedA();
private final WeightedA1 weightedA1 = new WeightedA1();
private WeightedTcProvider weightedBlight = new WeightedBlight();
@BeforeEach
public void setUp() {
graphAccess = TcManager.getInstance();
graphAccess.bindWeightedTcProvider(weightedA);
graphAccess.bindWeightedTcProvider(weightedA1);
graphAccess.bindWeightedTcProvider(weightedBlight);
queryEngine = Mockito.mock(QueryEngine.class);
}
@AfterEach
public void tearDown() {
graphAccess = TcManager.getInstance();
graphAccess.unbindWeightedTcProvider(weightedA);
graphAccess.unbindWeightedTcProvider(weightedA1);
graphAccess.unbindWeightedTcProvider(weightedBlight);
queryEngine = null;
}
@Test
public void getGraphFromA() {
ImmutableGraph graphA = graphAccess.getImmutableGraph(uriRefA);
Iterator<Triple> iterator = graphA.iterator();
assertEquals(new TripleImpl(uriRefA, uriRefA, uriRefA), iterator.next());
assertFalse(iterator.hasNext());
Graph triplesA = graphAccess.getGraph(uriRefA);
iterator = triplesA.iterator();
assertEquals(new TripleImpl(uriRefA, uriRefA, uriRefA), iterator.next());
assertFalse(iterator.hasNext());
}
@Test
public void getGraphFromB() {
ImmutableGraph graphA = graphAccess.getImmutableGraph(uriRefB);
Iterator<Triple> iterator = graphA.iterator();
assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next());
assertFalse(iterator.hasNext());
Graph triplesA = graphAccess.getGraph(uriRefB);
iterator = triplesA.iterator();
assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next());
assertFalse(iterator.hasNext());
}
@Test
public void getGraphFromAAfterUnbinding() {
graphAccess.unbindWeightedTcProvider(weightedA);
ImmutableGraph graphA = graphAccess.getImmutableGraph(uriRefA);
Iterator<Triple> iterator = graphA.iterator();
assertEquals(new TripleImpl(uriRefA1, uriRefA1, uriRefA1),
iterator.next());
assertFalse(iterator.hasNext());
Graph triplesA = graphAccess.getGraph(uriRefA);
iterator = triplesA.iterator();
assertEquals(new TripleImpl(uriRefA1, uriRefA1, uriRefA1),
iterator.next());
assertFalse(iterator.hasNext());
}
@Test
public void getGraphFromAWithHeavy() {
final WeightedAHeavy weightedAHeavy = new WeightedAHeavy();
graphAccess.bindWeightedTcProvider(weightedAHeavy);
ImmutableGraph graphA = graphAccess.getImmutableGraph(uriRefA);
Iterator<Triple> iterator = graphA.iterator();
assertEquals(new TripleImpl(uriRefAHeavy, uriRefAHeavy, uriRefAHeavy),
iterator.next());
assertFalse(iterator.hasNext());
Graph triplesA = graphAccess.getGraph(uriRefA);
iterator = triplesA.iterator();
assertEquals(new TripleImpl(uriRefAHeavy, uriRefAHeavy, uriRefAHeavy),
iterator.next());
assertFalse(iterator.hasNext());
graphAccess.unbindWeightedTcProvider(weightedAHeavy);
}
@Test
public void executeSparqlQueryNoEngineWithString() throws Exception {
// Prepare
injectQueryEngine(null);
// Execute
assertThrows(NoQueryEngineException.class, () -> graphAccess.executeSparqlQuery("", new SimpleGraph()));
}
@Test
public void executeSparqlQueryNoEngineWithQuery() throws Exception {
// Prepare
injectQueryEngine(null);
// Execute
assertThrows(
NoQueryEngineException.class,
() -> graphAccess.executeSparqlQuery((Query) null, new SimpleGraph())
);
}
@Test
public void executeSparqlQueryNoEngineWithSelectQuery() throws Exception {
// Prepare
injectQueryEngine(null);
// Execute
assertThrows(
NoQueryEngineException.class,
() -> graphAccess.executeSparqlQuery((SelectQuery) null, new SimpleGraph())
);
}
@Test
public void executeSparqlQueryNoEngineWithAskQuery() throws Exception {
// Prepare
injectQueryEngine(null);
// Execute
assertThrows(
NoQueryEngineException.class,
() -> graphAccess.executeSparqlQuery((AskQuery) null, new SimpleGraph())
);
}
@Test
public void executeSparqlQueryNoEngineWithDescribeQuery() throws Exception {
// Prepare
injectQueryEngine(null);
// Execute
assertThrows(
NoQueryEngineException.class,
() -> graphAccess.executeSparqlQuery((DescribeQuery) null, new SimpleGraph())
);
}
@Test
public void executeSparqlQueryNoEngineWithConstructQuery() throws Exception {
// Prepare
injectQueryEngine(null);
// Execute
assertThrows(
NoQueryEngineException.class,
() -> graphAccess.executeSparqlQuery((ConstructQuery) null, new SimpleGraph())
);
}
@Test
public void executeSparqlQueryWithEngineWithString() throws Exception {
// Prepare
injectQueryEngine(queryEngine);
Graph Graph = new SimpleGraph();
// Execute
graphAccess.executeSparqlQuery("", Graph);
// Verify
Mockito.verify(queryEngine).execute(graphAccess, Graph, "");
// Mockito.verify(queryEngine, Mockito.never()).execute(
// (TcManager) Mockito.anyObject(),
// (Graph) Mockito.anyObject(),
// Mockito.anyString());
}
@Test
public void executeSparqlQueryWithEngineWithSelectQuery() throws Exception {
// Prepare
injectQueryEngine(queryEngine);
Graph Graph = new SimpleGraph();
SelectQuery query = Mockito.mock(SelectQuery.class);
// Execute
graphAccess.executeSparqlQuery(query, Graph);
// Verify
Mockito.verify(queryEngine).execute(graphAccess, Graph,
query.toString());
// Mockito.verify(queryEngine, Mockito.never()).execute(
// (TcManager) Mockito.anyObject(),
// (Graph) Mockito.anyObject(), Mockito.anyString());
}
@Test
public void executeSparqlQueryWithEngineWithAskQuery() throws Exception {
// Prepare
injectQueryEngine(queryEngine);
Graph Graph = new SimpleGraph();
AskQuery query = Mockito.mock(AskQuery.class);
Mockito.when(
queryEngine.execute((TcManager) Mockito.anyObject(),
(Graph) Mockito.anyObject(),
Mockito.anyString())).thenReturn(Boolean.TRUE);
// Execute
graphAccess.executeSparqlQuery(query, Graph);
// Verify
Mockito.verify(queryEngine).execute(graphAccess, Graph,
query.toString());
// Mockito.verify(queryEngine, Mockito.never()).execute(
// (TcManager) Mockito.anyObject(),
// (Graph) Mockito.anyObject(), Mockito.anyString());
}
@Test
public void executeSparqlQueryWithEngineWithDescribeQuery()
throws Exception {
// Prepare
injectQueryEngine(queryEngine);
Graph Graph = new SimpleGraph();
DescribeQuery query = Mockito.mock(DescribeQuery.class);
// Execute
graphAccess.executeSparqlQuery(query, Graph);
// Verify
Mockito.verify(queryEngine).execute(graphAccess, Graph,
query.toString());
// Mockito.verify(queryEngine, Mockito.never()).execute(
// (TcManager) Mockito.anyObject(),
// (Graph) Mockito.anyObject(), Mockito.anyString());
}
@Test
public void executeSparqlQueryWithEngineWithConstructQuery()
throws Exception {
// Prepare
injectQueryEngine(queryEngine);
Graph Graph = new SimpleGraph();
ConstructQuery query = Mockito.mock(ConstructQuery.class);
// Execute
graphAccess.executeSparqlQuery(query, Graph);
// Verify
Mockito.verify(queryEngine).execute(graphAccess, Graph,
query.toString());
// Mockito.verify(queryEngine, Mockito.never()).execute(
// (TcManager) Mockito.anyObject(),
// (Graph) Mockito.anyObject(), Mockito.anyString());
}
// ------------------------------------------------------------------------
// Implementing QueryableTcProvider
// ------------------------------------------------------------------------
private void injectQueryEngine(QueryEngine engine)
throws NoSuchFieldException, IllegalAccessException {
Field queryEngineField = TcManager.class
.getDeclaredField("queryEngine");
queryEngineField.setAccessible(true);
queryEngineField.set(graphAccess, engine);
}
}
| 286 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset/test | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset/test/utils/TcProviderTest.java | /*
* 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 org.apache.clerezza.dataset.test.utils;
import org.apache.clerezza.*;
import org.apache.clerezza.dataset.EntityAlreadyExistsException;
import org.apache.clerezza.dataset.NoSuchEntityException;
import org.apache.clerezza.dataset.TcProvider;
import org.apache.clerezza.implementation.TripleImpl;
import org.apache.clerezza.implementation.in_memory.SimpleGraph;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
*
* @author mir,rbn
*/
@RunWith(JUnitPlatform.class)
public abstract class TcProviderTest {
protected final IRI uriRefA = generateUri("a");
protected final IRI uriRefA1 = generateUri("a1");
protected final IRI uriRefB = generateUri("b");
protected final IRI uriRefB1 = generateUri("b1");
protected final IRI uriRefC = generateUri("c");
protected final IRI graphIRI = generateUri("myGraph");
protected final IRI otherGraphIRI = new IRI(graphIRI.getUnicodeString());
@Test
public void testCreateImmutableGraph() {
TcProvider simpleTcmProvider = getInstance();
Graph mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
ImmutableGraph createdGraph = simpleTcmProvider.createImmutableGraph(uriRefA, mGraph);
Iterator<Triple> iteratorInput = mGraph.iterator();
Iterator<Triple> iteratorCreated = createdGraph.iterator();
Assertions.assertEquals(iteratorInput.next(), iteratorCreated.next());
Assertions.assertFalse(iteratorCreated.hasNext());
try {
simpleTcmProvider.createImmutableGraph(uriRefA, mGraph);
Assertions.assertTrue(false);
} catch (EntityAlreadyExistsException e) {
Assertions.assertTrue(true);
}
simpleTcmProvider.deleteGraph(uriRefA);
}
@Test
public void testCreateGraph() {
TcProvider simpleTcmProvider = getInstance();
Graph mGraph = simpleTcmProvider.createGraph(uriRefA);
Assertions.assertTrue(mGraph.isEmpty());
try {
simpleTcmProvider.createGraph(uriRefA);
Assertions.assertTrue(false);
} catch (EntityAlreadyExistsException e) {
Assertions.assertTrue(true);
}
simpleTcmProvider.deleteGraph(uriRefA);
}
@Test
public void testGetImmutableGraph() {
TcProvider simpleTcmProvider = getInstance();
// add Graphs
Graph mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
simpleTcmProvider.createImmutableGraph(uriRefA, mGraph);
mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1));
simpleTcmProvider.createImmutableGraph(uriRefA1, mGraph);
mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB));
simpleTcmProvider.createImmutableGraph(uriRefB, mGraph);
mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1));
simpleTcmProvider.createImmutableGraph(uriRefB1, mGraph);
ImmutableGraph bGraph = simpleTcmProvider.getImmutableGraph(uriRefB);
Iterator<Triple> iterator = bGraph.iterator();
Assertions.assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next());
Assertions.assertFalse(iterator.hasNext());
simpleTcmProvider.deleteGraph(uriRefA);
simpleTcmProvider.deleteGraph(uriRefA1);
simpleTcmProvider.deleteGraph(uriRefB);
simpleTcmProvider.deleteGraph(uriRefB1);
}
@Test
public void testGetGraph() {
TcProvider simpleTcmProvider = getInstance();
// add Graphs
Graph mGraph = simpleTcmProvider.createGraph(uriRefA);
mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
mGraph = simpleTcmProvider.createGraph(uriRefA1);
mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1));
mGraph = simpleTcmProvider.createGraph(uriRefB);
mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefA));
mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB));
mGraph.remove(new TripleImpl(uriRefB, uriRefB, uriRefA));
Assertions.assertEquals(1, mGraph.size());
mGraph = simpleTcmProvider.createGraph(uriRefB1);
mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1));
Graph bGraph = simpleTcmProvider.getGraph(uriRefB);
Iterator<Triple> iterator = bGraph.iterator();
Assertions.assertEquals(new TripleImpl(uriRefB, uriRefB, uriRefB), iterator.next());
Assertions.assertFalse(iterator.hasNext());
simpleTcmProvider.deleteGraph(uriRefA);
simpleTcmProvider.deleteGraph(uriRefA1);
simpleTcmProvider.deleteGraph(uriRefB);
simpleTcmProvider.deleteGraph(uriRefB1);
}
@Test
public void testGetTriples() {
TcProvider simpleTcmProvider = getInstance();
// add Graphs
Graph mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
simpleTcmProvider.createImmutableGraph(uriRefA, mGraph);
mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB));
simpleTcmProvider.createImmutableGraph(uriRefB, mGraph);
// add Graphs
mGraph = simpleTcmProvider.createGraph(uriRefA1);
mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1));
mGraph = simpleTcmProvider.createGraph(uriRefB1);
mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1));
// get a ImmutableGraph
Graph tripleCollection = simpleTcmProvider.getGraph(uriRefA);
// get a Graph
Graph tripleCollection2 = simpleTcmProvider.getGraph(uriRefB1);
Iterator<Triple> iterator = tripleCollection.iterator();
Assertions.assertEquals(new TripleImpl(uriRefA, uriRefA, uriRefA), iterator.next());
Assertions.assertFalse(iterator.hasNext());
iterator = tripleCollection2.iterator();
Assertions.assertEquals(new TripleImpl(uriRefB1, uriRefB1, uriRefB1), iterator.next());
Assertions.assertFalse(iterator.hasNext());
simpleTcmProvider.deleteGraph(uriRefA);
simpleTcmProvider.deleteGraph(uriRefA1);
simpleTcmProvider.deleteGraph(uriRefB);
simpleTcmProvider.deleteGraph(uriRefB1);
}
@Test
public void testDeleteEntity() {
TcProvider simpleTcmProvider = getInstance();
Graph mGraph = new SimpleGraph();
mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
ImmutableGraph graph = mGraph.getImmutableGraph();
simpleTcmProvider.createImmutableGraph(uriRefA, graph);
simpleTcmProvider.createImmutableGraph(uriRefC, graph);
simpleTcmProvider.deleteGraph(uriRefA);
try {
simpleTcmProvider.getGraph(uriRefA);
Assertions.assertTrue(false);
} catch (NoSuchEntityException e) {
Assertions.assertTrue(true);
}
// Check that graph is still available under uriRefC
ImmutableGraph cGraph = simpleTcmProvider.getImmutableGraph(uriRefC);
Assertions.assertNotNull(cGraph);
simpleTcmProvider.deleteGraph(uriRefC);
}
/**
* Subclasses implement this method to provide implementation instances of
* <code>TcProvider</code>. The first call within a test method has to
* return a empty TcProvider. Subsequent calls within the test method
* should instantiate a new provider, but load the previously added data from
* its "persistent" store.
*
* @return a TcProvider of the implementation to be tested.
*/
protected abstract TcProvider getInstance();
// @Test
// public void testGetNames() {
// Graph mGraph = new SimpleGraph();
// mGraph.add(new TripleImpl(uriRefB, uriRefB, uriRefB));
// simpleTcmProvider.createGraph(uriRefB, mGraph.getGraph());
//
// mGraph = new SimpleGraph();
// mGraph.add(new TripleImpl(uriRefA, uriRefA, uriRefA));
// ImmutableGraph graph = mGraph.getGraph();
// simpleTcmProvider.createGraph(uriRefA, graph);
// simpleTcmProvider.createGraph(uriRefC, graph);
//
// Set<IRI> names = simpleTcmProvider.getNames(graph);
//
// assertTrue(names.contains(uriRefA));
// assertTrue(names.contains(uriRefC));
// assertEquals(2, names.size());
//
// assertFalse(names.contains(uriRefB));
// }
@Test
public void testCreateGraphExtended() throws Exception {
TcProvider provider = getInstance();
Graph graph = provider.createGraph(graphIRI);
Assertions.assertNotNull(graph);
//get a new provider and check that graph is there
provider = getInstance();
graph = provider.getGraph(graphIRI);
Assertions.assertNotNull(graph);
//check that there is no such graph, but only the mgraph
boolean expThrown = false;
try {
ImmutableGraph g = provider.getImmutableGraph(graphIRI);
} catch(NoSuchEntityException e) {
expThrown = true;
}
Assertions.assertTrue(expThrown);
provider.deleteGraph(graphIRI);
}
@Test
public void testCreateImmutableGraphExtended() throws Exception {
TcProvider provider = getInstance();
ImmutableGraph graph = provider.createImmutableGraph(graphIRI, null);
Assertions.assertNotNull(graph);
//get a new provider and check that graph is there
provider = getInstance();
graph = provider.getImmutableGraph(graphIRI);
Assertions.assertNotNull(graph);
//check that there is no such mgraph, but only the graph
boolean expThrown = false;
try {
Graph g = provider.getMGraph(graphIRI);
} catch(NoSuchEntityException e) {
expThrown = true;
}
Assertions.assertTrue(expThrown);
provider.deleteGraph(graphIRI);
}
@Test
public void testCreateGraphNoDuplicateNames() throws Exception {
TcProvider provider = getInstance();
ImmutableGraph graph = provider.createImmutableGraph(graphIRI, null);
Assertions.assertNotNull(graph);
boolean expThrown = false;
try {
ImmutableGraph other = provider.createImmutableGraph(otherGraphIRI, null);
} catch(EntityAlreadyExistsException eaee) {
expThrown = true;
}
Assertions.assertTrue(expThrown);
provider.deleteGraph(graphIRI);
}
@Test
public void testCreateGraphNoDuplicateNames2() throws Exception {
TcProvider provider = getInstance();
Graph graph = provider.createGraph(graphIRI);
Assertions.assertNotNull(graph);
boolean expThrown = false;
try {
Graph other = provider.createGraph(otherGraphIRI);
} catch(EntityAlreadyExistsException eaee) {
expThrown = true;
}
Assertions.assertTrue(expThrown);
provider.deleteGraph(graphIRI);
}
@Test
public void testCreateGraphWithInitialCollection() throws Exception {
Triple t1 = createTestTriple();
TcProvider provider = getInstance();
ImmutableGraph graph = provider.createImmutableGraph(graphIRI, createTestTripleCollection(t1));
Assertions.assertEquals(1, graph.size());
Assertions.assertTrue(graph.contains(t1));
provider.deleteGraph(graphIRI);
}
@Test
public void testGraphIsNotMutable() throws Exception {
Triple t1 = createTestTriple();
Set<Triple> t = new HashSet<Triple>();
t.add(t1);
TcProvider provider = getInstance();
ImmutableGraph graph = provider.createImmutableGraph(graphIRI, createTestTripleCollection(t1));
boolean expThrown = false;
try {
graph.add(t1);
} catch(UnsupportedOperationException uoe) {
expThrown = true;
}
Assertions.assertTrue(expThrown);
expThrown = false;
try {
graph.remove(t1);
} catch(UnsupportedOperationException uoe) {
expThrown = true;
}
Assertions.assertTrue(expThrown);
expThrown = false;
try {
graph.addAll(t);
} catch(UnsupportedOperationException uoe) {
expThrown = true;
}
Assertions.assertTrue(expThrown);
expThrown = false;
try {
graph.clear();
} catch(UnsupportedOperationException uoe) {
expThrown = true;
}
Assertions.assertTrue(expThrown);
expThrown = false;
try {
graph.removeAll(t);
} catch(UnsupportedOperationException uoe) {
expThrown = true;
}
Assertions.assertTrue(expThrown);
provider.deleteGraph(graphIRI);
}
// This tests can not pass, because equals in AbstractGraph is not implemented
// yet.
// @Test
// public void testGraphHasName() throws Exception {
//
// TcProvider provider = getInstance();
//
// Graph triples = createTestTripleCollection(createTestTriple());
// ImmutableGraph graph = provider.createGraph(graphIRI, triples);
//
// provider = getInstance();
// Set<IRI> names = provider.getNames(graph);
// assertTrue(names.contains(graphIRI));
// }
//
// @Test
// public void testCreateSameGraphWithDifferentNames() throws Exception {
//
// Graph triples = createTestTripleCollection(createTestTriple());
//
// TcProvider provider = getInstance();
// IRI name1 = new IRI("http://myGraph1");
// ImmutableGraph graph = provider.createGraph(name1, triples);
//
// IRI name2 = new IRI("http://myGraph2");
// ImmutableGraph secondGraph = provider.createGraph(name2, triples);
//
// Set<IRI> names = provider.getNames(graph);
// assertNotNull(names);
// assertEquals(2, names.size());
// }
@Test
public void testGraphDeletion() throws Exception {
Graph triples = createTestTripleCollection(createTestTriple());
TcProvider provider = getInstance();
IRI name1 = new IRI("http://myGraph1");
ImmutableGraph graph = provider.createImmutableGraph(name1, triples);
IRI name2 = new IRI("http://myGraph2");
ImmutableGraph secondGraph = provider.createImmutableGraph(name2, triples);
//if we delete graph with name1, the second graph should still be there
provider.deleteGraph(name1);
provider = getInstance();
ImmutableGraph firstGraph = provider.getImmutableGraph(name2);
Assertions.assertNotNull(firstGraph);
//check second name is not there
boolean expThrown = false;
try {
ImmutableGraph g = provider.getImmutableGraph(name1);
} catch(NoSuchEntityException nses) {
expThrown = true;
}
Assertions.assertTrue(expThrown);
provider.deleteGraph(name2);
}
@Test
public void testGetTriplesGraph() throws Exception {
TcProvider provider = getInstance();
Graph graph = provider.createGraph(graphIRI);
Graph tc = provider.getGraph(graphIRI);
Assertions.assertNotNull(tc);
provider.deleteGraph(graphIRI);
}
private Triple createTestTriple() {
BlankNodeOrIRI subject = new BlankNode() {};
IRI predicate = new IRI("http://test.com/");
BlankNodeOrIRI object = new IRI("http://test.com/myObject");
return new TripleImpl(subject, predicate, object);
}
private Graph createTestTripleCollection(Triple t) {
Set<Triple> ts = new HashSet<Triple>();
ts.add(t);
return new SimpleGraph(ts);
}
protected IRI generateUri(String name) {
return new IRI("http://example.org/" + name);
}
}
| 287 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset/providers/WeightedDummy.java | /*
* 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 org.apache.clerezza.dataset.providers;
import org.apache.clerezza.Graph;
import org.apache.clerezza.IRI;
import org.apache.clerezza.ImmutableGraph;
import org.apache.clerezza.dataset.EntityAlreadyExistsException;
import org.apache.clerezza.dataset.EntityUndeletableException;
import org.apache.clerezza.dataset.NoSuchEntityException;
import org.apache.clerezza.dataset.WeightedTcProvider;
import org.apache.clerezza.implementation.in_memory.SimpleGraph;
import org.apache.clerezza.implementation.in_memory.SimpleImmutableGraph;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
*
* @author mir
*/
public class WeightedDummy implements WeightedTcProvider {
private Map<IRI, Graph> tripleMap = new HashMap<IRI, Graph>();
@Override
public ImmutableGraph createImmutableGraph(IRI name, Graph triples)
throws EntityAlreadyExistsException {
if ((name == null) || (name.getUnicodeString() == null)
|| (name.getUnicodeString().trim().length() == 0)) {
throw new IllegalArgumentException("Name must not be null");
}
try {
// throws NoSuchEntityException if a Graph with that name
// already exists
this.getGraph(name);
} catch (NoSuchEntityException e) {
ImmutableGraph result;
if (ImmutableGraph.class.isAssignableFrom(triples.getClass())) {
result = (ImmutableGraph) triples;
} else {
result = new SimpleImmutableGraph(triples);
}
tripleMap.put(name, result);
return result;
}
throw new EntityAlreadyExistsException(name);
}
@Override
public Graph createGraph(IRI name) throws EntityAlreadyExistsException {
if ((name == null) || (name.getUnicodeString() == null)
|| (name.getUnicodeString().trim().length() == 0)) {
throw new IllegalArgumentException("Name must not be null");
}
try {
// throws NoSuchEntityException if a Graph with that name
// already exists
this.getGraph(name);
} catch (NoSuchEntityException e) {
Graph result = new SimpleGraph();
tripleMap.put(name, result);
return result;
}
throw new EntityAlreadyExistsException(name);
}
@Override
public void deleteGraph(IRI name)
throws NoSuchEntityException, EntityUndeletableException {
if (tripleMap.remove(name) == null) {
throw new NoSuchEntityException(name);
}
}
@Override
public ImmutableGraph getImmutableGraph(IRI name) throws NoSuchEntityException {
Graph Graph = tripleMap.get(name);
if (Graph == null) {
throw new NoSuchEntityException(name);
} else if (ImmutableGraph.class.isAssignableFrom(Graph.getClass())) {
return (ImmutableGraph) Graph;
}
throw new NoSuchEntityException(name);
}
@Override
public Graph getMGraph(IRI name) throws NoSuchEntityException {
Graph Graph = tripleMap.get(name);
if (Graph == null) {
throw new NoSuchEntityException(name);
} else if (Graph.class.isAssignableFrom(Graph.getClass())) {
return (Graph) Graph;
}
throw new NoSuchEntityException(name);
}
@Override
public Set<IRI> getNames(ImmutableGraph ImmutableGraph) {
throw new UnsupportedOperationException(
"Not supported yet. equals() has to be implemented first");
}
@Override
public Graph getGraph(IRI name)
throws NoSuchEntityException {
Graph Graph = tripleMap.get(name);
if (Graph == null) {
throw new NoSuchEntityException(name);
} else {
return Graph;
}
}
@Override
public int getWeight() {
return 1;
}
@Override
public Set<IRI> listImmutableGraphs() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> listMGraphs() {
return new HashSet<IRI>();
}
@Override
public Set<IRI> listGraphs() {
return listMGraphs();
}
}
| 288 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset/providers/WeightedA.java | /*
* 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 org.apache.clerezza.dataset.providers;
import org.apache.clerezza.Graph;
import org.apache.clerezza.IRI;
import org.apache.clerezza.ImmutableGraph;
import org.apache.clerezza.dataset.EntityUndeletableException;
import org.apache.clerezza.dataset.NoSuchEntityException;
import org.apache.clerezza.dataset.TcManagerTest;
import org.apache.clerezza.dataset.WeightedTcProvider;
import org.apache.clerezza.implementation.TripleImpl;
import org.apache.clerezza.implementation.in_memory.SimpleGraph;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author reto
*/
public class WeightedA implements WeightedTcProvider {
private Set<IRI> mGraphList = new HashSet<IRI>();
@Override
public int getWeight() {
return 5;
}
@Override
public ImmutableGraph getImmutableGraph(IRI name) throws NoSuchEntityException {
if (name.equals(TcManagerTest.uriRefA)) {
Graph mResult = new SimpleGraph();
mResult.add(new TripleImpl(TcManagerTest.uriRefA,
TcManagerTest.uriRefA, TcManagerTest.uriRefA));
mGraphList.add(name);
return mResult.getImmutableGraph();
}
throw new NoSuchEntityException(name);
}
@Override
public Graph getMGraph(IRI name) throws NoSuchEntityException {
throw new NoSuchEntityException(name);
}
@Override
public Graph getGraph(IRI name) throws NoSuchEntityException {
return getImmutableGraph(name);
}
@Override
public Graph createGraph(IRI name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ImmutableGraph createImmutableGraph(IRI name, Graph triples) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void deleteGraph(IRI name) throws NoSuchEntityException,
EntityUndeletableException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> getNames(ImmutableGraph ImmutableGraph) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> listGraphs() {
return Collections.singleton(TcManagerTest.uriRefA);
}
@Override
public Set<IRI> listMGraphs() {
return mGraphList;
}
@Override
public Set<IRI> listImmutableGraphs() {
return listGraphs();
}
}
| 289 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset/providers/WeightedAHeavy.java | /*
* 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 org.apache.clerezza.dataset.providers;
import org.apache.clerezza.Graph;
import org.apache.clerezza.IRI;
import org.apache.clerezza.ImmutableGraph;
import org.apache.clerezza.implementation.TripleImpl;
import org.apache.clerezza.implementation.in_memory.SimpleGraph;
import org.apache.clerezza.dataset.EntityUndeletableException;
import org.apache.clerezza.dataset.NoSuchEntityException;
import org.apache.clerezza.dataset.TcManagerTest;
import org.apache.clerezza.dataset.WeightedTcProvider;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author reto
*/
public class WeightedAHeavy implements WeightedTcProvider {
@Override
public int getWeight() {
return 20;
}
@Override
public ImmutableGraph getImmutableGraph(IRI name) throws NoSuchEntityException {
if (name.equals(TcManagerTest.uriRefA)) {
Graph mResult = new SimpleGraph();
mResult.add(new TripleImpl(TcManagerTest.uriRefAHeavy,
TcManagerTest.uriRefAHeavy, TcManagerTest.uriRefAHeavy));
return mResult.getImmutableGraph();
}
throw new NoSuchEntityException(name);
}
@Override
public Graph getMGraph(IRI name) throws NoSuchEntityException {
throw new NoSuchEntityException(name);
}
@Override
public Graph getGraph(IRI name) throws NoSuchEntityException {
return getImmutableGraph(name);
}
@Override
public Graph createGraph(IRI name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ImmutableGraph createImmutableGraph(IRI name, Graph triples) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void deleteGraph(IRI name) throws NoSuchEntityException,
EntityUndeletableException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> getNames(ImmutableGraph ImmutableGraph) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> listGraphs() {
return Collections.singleton(TcManagerTest.uriRefA);
}
@Override
public Set<IRI> listMGraphs() {
return new HashSet<IRI>();
}
@Override
public Set<IRI> listImmutableGraphs() {
return listGraphs();
}
}
| 290 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset/providers/WeightedBlight.java | /*
* 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 org.apache.clerezza.dataset.providers;
import org.apache.clerezza.Graph;
import org.apache.clerezza.IRI;
import org.apache.clerezza.ImmutableGraph;
import org.apache.clerezza.dataset.EntityUndeletableException;
import org.apache.clerezza.dataset.NoSuchEntityException;
import org.apache.clerezza.dataset.TcManagerTest;
import org.apache.clerezza.dataset.WeightedTcProvider;
import org.apache.clerezza.implementation.TripleImpl;
import org.apache.clerezza.implementation.in_memory.SimpleGraph;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author reto
*/
public class WeightedBlight implements WeightedTcProvider {
@Override
public int getWeight() {
return 2;
}
@Override
public ImmutableGraph getImmutableGraph(IRI name) throws NoSuchEntityException {
if (name.equals(TcManagerTest.uriRefB)) {
Graph mResult = new SimpleGraph();
mResult.add(new TripleImpl(TcManagerTest.uriRefB, TcManagerTest.uriRefB, TcManagerTest.uriRefB));
return mResult.getImmutableGraph();
}
if (name.equals(TcManagerTest.uriRefA)) {
Graph mResult = new SimpleGraph();
//empty ImmutableGraph
return mResult.getImmutableGraph();
}
throw new NoSuchEntityException(name);
}
@Override
public Graph getMGraph(IRI name) throws NoSuchEntityException {
throw new NoSuchEntityException(name);
}
@Override
public Graph getGraph(IRI name) throws NoSuchEntityException {
return getImmutableGraph(name);
}
@Override
public Graph createGraph(IRI name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ImmutableGraph createImmutableGraph(IRI name, Graph triples) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void deleteGraph(IRI name) throws NoSuchEntityException,
EntityUndeletableException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> getNames(ImmutableGraph ImmutableGraph) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> listImmutableGraphs() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> listMGraphs() {
return new HashSet<IRI>();
}
@Override
public Set<IRI> listGraphs() {
return listMGraphs();
}
}
| 291 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/dataset/providers/WeightedA1.java | /*
* 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 org.apache.clerezza.dataset.providers;
import org.apache.clerezza.Graph;
import org.apache.clerezza.IRI;
import org.apache.clerezza.ImmutableGraph;
import org.apache.clerezza.implementation.TripleImpl;
import org.apache.clerezza.dataset.EntityUndeletableException;
import org.apache.clerezza.dataset.NoSuchEntityException;
import org.apache.clerezza.dataset.TcManagerTest;
import org.apache.clerezza.dataset.WeightedTcProvider;
import org.apache.clerezza.implementation.in_memory.SimpleGraph;
import java.util.HashSet;
import java.util.Set;
/**
* Same weight as WeightedA, but later in string-ordering
*
* @author reto
*/
public class WeightedA1 implements WeightedTcProvider {
private Set<IRI> mGraphList = new HashSet<IRI>();
@Override
public int getWeight() {
return 5;
}
@Override
public ImmutableGraph getImmutableGraph(IRI name) throws NoSuchEntityException {
if (name.equals(TcManagerTest.uriRefA)) {
Graph mResult = new SimpleGraph();
mResult.add(new TripleImpl(TcManagerTest.uriRefA1,
TcManagerTest.uriRefA1, TcManagerTest.uriRefA1));
mGraphList.add(name);
return mResult.getImmutableGraph();
}
throw new NoSuchEntityException(name);
}
@Override
public Graph getMGraph(IRI name) throws NoSuchEntityException {
throw new NoSuchEntityException(name);
}
@Override
public Graph getGraph(IRI name) throws NoSuchEntityException {
return getImmutableGraph(name);
}
@Override
public Graph createGraph(IRI name) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ImmutableGraph createImmutableGraph(IRI name, Graph triples) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void deleteGraph(IRI name) throws NoSuchEntityException,
EntityUndeletableException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> getNames(ImmutableGraph ImmutableGraph) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> listImmutableGraphs() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<IRI> listMGraphs() {
return mGraphList;
}
@Override
public Set<IRI> listGraphs() {
return listMGraphs();
}
}
| 292 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/simple | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/simple/storage/SimpleGraphGenericTest.java | /*
* 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 org.apache.clerezza.simple.storage;
import org.apache.clerezza.Graph;
import org.apache.clerezza.implementation.in_memory.SimpleGraph;
import org.apache.clerezza.test.utils.GraphTest;
/**
*
* @author mir
*/
public class SimpleGraphGenericTest extends GraphTest{
@Override
protected Graph getEmptyGraph() {
return new SimpleGraph();
}
}
| 293 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/simple | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/simple/storage/GenericTcProviderTest.java | /*
* 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 org.apache.clerezza.simple.storage;
import org.apache.clerezza.dataset.TcProvider;
import org.apache.clerezza.dataset.test.utils.TcProviderTest;
import org.junit.jupiter.api.AfterEach;
/**
*
* @author mir
*/
public class GenericTcProviderTest extends TcProviderTest {
SimpleTcProvider provider = new SimpleTcProvider();
@AfterEach
public void cleanUp() {
provider = new SimpleTcProvider();
}
@Override
protected TcProvider getInstance() {
return provider;
}
}
| 294 |
0 | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/simple | Create_ds/clerezza/dataset/src/test/java/org/apache/clerezza/simple/storage/AccessViaTcManager.java | /*
* 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 org.apache.clerezza.simple.storage;
import org.apache.clerezza.Graph;
import org.apache.clerezza.IRI;
import org.apache.clerezza.implementation.in_memory.SimpleGraph;
import org.apache.clerezza.dataset.TcManager;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
/**
*
* @author developer
*/
@RunWith(JUnitPlatform.class)
public class AccessViaTcManager {
@Test
public void simple() {
Graph g = TcManager.getInstance().createGraph(new IRI("http://example.org/foo"));
Assertions.assertTrue(g instanceof SimpleGraph);
}
}
| 295 |
0 | Create_ds/clerezza/dataset/src/main/java/org/apache/clerezza | Create_ds/clerezza/dataset/src/main/java/org/apache/clerezza/dataset/MGraphServiceFactory.java | /*
* 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 org.apache.clerezza.dataset;
import org.apache.clerezza.IRI;
import org.apache.clerezza.dataset.security.TcAccessController;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
/**
* @see <a href="http://www.osgi.org/javadoc/r4v41/org/osgi/framework/ServiceFactory.html">
* Interface ServiceFactory</a>
*
* @author mir
*/
public class MGraphServiceFactory implements ServiceFactory {
private TcManager tcManager;
private IRI name;
private final TcAccessController tcAccessController;
MGraphServiceFactory(TcManager tcManager, IRI name,
TcAccessController tcAccessController) {
this.tcManager = tcManager;
this.name = name;
this.tcAccessController = tcAccessController;
}
@Override
public Object getService(Bundle arg0, ServiceRegistration arg1) {
return new SecuredGraph(tcManager.getMGraph(name), name, tcAccessController);
}
@Override
public void ungetService(Bundle arg0, ServiceRegistration arg1, Object arg2) {
}
}
| 296 |
0 | Create_ds/clerezza/dataset/src/main/java/org/apache/clerezza | Create_ds/clerezza/dataset/src/main/java/org/apache/clerezza/dataset/NoSuchEntityException.java | /*
* 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 org.apache.clerezza.dataset;
import org.apache.clerezza.IRI;
/**
* is thrown on an attempt to perform an operation on an entity (i.e. a
* <code>ImmutableGraph</code> or <code>Graph</code> that does not exist.
*
* @author reto
*/
public class NoSuchEntityException extends RuntimeException {
private IRI entityName;
/**
* creates an exception indicating that the entity with the specified name
* does not exist.
*
* @param entityName the name for which no entity exists
*/
public NoSuchEntityException(IRI entityName) {
super("No such entity: "+entityName);
this.entityName = entityName;
}
/**
* the name for which no entity exists.
*
* @return the name of the entity that doesn't exist
*/
public IRI getEntityName() {
return entityName;
}
}
| 297 |
0 | Create_ds/clerezza/dataset/src/main/java/org/apache/clerezza | Create_ds/clerezza/dataset/src/main/java/org/apache/clerezza/dataset/TcManager.java | /*
* 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 org.apache.clerezza.dataset;
import org.apache.clerezza.Graph;
import org.apache.clerezza.IRI;
import org.apache.clerezza.ImmutableGraph;
import org.apache.clerezza.implementation.in_memory.SimpleGraph;
import org.apache.clerezza.implementation.graph.WriteBlockedGraph;
import org.apache.clerezza.dataset.security.TcAccessController;
import org.apache.clerezza.sparql.*;
import org.apache.clerezza.sparql.query.*;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import java.security.AccessControlException;
import java.util.*;
/**
* This class extends <code>TcProviderMultiplexer</code>, delegating the actual provision and creation of
* Graphs or MGraphs to registered <code>WeightedTcProvider</code>s. The class attempts to satisfy the
* request using the registered <code>WeightedTcProvider</code> in decreasing order of weight. If multiple
* providers have the same weight the lexicographical order of the fully qualified class name determines
* which one is used, namely the one that occurs earlier. If a call to a registered provider causes an
* <code>IllegalArgumentException</code>,
* <code>NoSuchEntityException</code> or
* <code>UnsupportedOperationException</code> then the call is delegated to the
* next provider.
*
* Only one instance of this class should exist in a system, the public no
* argument constructor is meant for initialization by dependency injection
* systems such as OSGi-DS. Applications should use the static
* <code>getInstance()</code> method if they aren't using a framework that
* injects them the instance.
*
* This class returns
* <code>Graph</code>s a subtype of
* <code>Graph</code> that allows read/write locks.
*
* This class also registers all Graphs as services with the property
* 'name' indicating there name.
*
* Security checks are done when a Graph is retrieved. The returned
* Graph will do no further security checks. Because of this it
* should not be passed to a context where different access control applies. If
* an Graph is retrieved without having write permission the returned graph
* will be read-only.
*
* If a Graphs needs to passed around across different security
* contexts the one retrieved from the OSGi service whiteboard should be used as
* this performs access control on every access.
*
* @author reto, mir, hasan
*
*/
//immedia is set to true as this should register the ImmutableGraph services (even if manager service is not required)
@Component(service = TcManager.class, immediate = true,
property={
"graph.cache.enabled=true",
"Graph.services.enabled=true"})
public class TcManager extends TcProviderMultiplexer implements GraphStore {
public final static String GENERAL_PURPOSE_TC = "general.purpose.tc";
public final static String Graph_SERVICES_ENABLED = "Graph.services.enabled";
public final static String MGRAPH_CACHE_ENABLED = "graph.cache.enabled";
private static volatile TcManager instance;
private TcAccessController tcAccessController = new TcAccessController() {
@Override
protected TcManager getTcManager() {
return TcManager.this;
}
};
private Map<IRI, ServiceRegistration> serviceRegistrations = Collections
.synchronizedMap(new HashMap<IRI, ServiceRegistration>());
protected QueryEngine queryEngine;
private boolean isActivated = false;
private boolean isTcServicesEnabled = true;
private ComponentContext componentContext;
protected SortedSet<WeightedTcProvider> tempProviderList = new TreeSet<WeightedTcProvider>(
new WeightedProviderComparator());
/**
* the constructor sets the singleton instance to allow instantiation by
* OSGi-DS. This constructor should not be called except by OSGi-DS,
* otherwise the static
* <code>getInstance</code> method should be used.
*/
public TcManager() {
TcManager.instance = this;
}
/**
* This returns the singleton instance. If an instance has been previously
* created (e.g. by OSGi declarative services) this instance is returned,
* otherwise a new instance is created and providers are injected using the
* service provider interface (META-INF/services/)
*
* @return the singleton instance
*/
public static TcManager getInstance() {
if (instance == null) {
synchronized (TcManager.class) {
if (instance == null) {
instance = new TcManager();
instance.isActivated = true;
Iterator<WeightedTcProvider> weightedProviders = ServiceLoader.load(WeightedTcProvider.class).iterator();
while (weightedProviders.hasNext()) {
WeightedTcProvider weightedProvider = weightedProviders.next();
instance.bindWeightedTcProvider(weightedProvider);
}
Iterator<QueryEngine> queryEngines = ServiceLoader.load(QueryEngine.class).iterator();
System.out.println("looking for QE");
if (queryEngines.hasNext()) {
instance.queryEngine = queryEngines.next();
System.out.println("QE: " + instance.queryEngine.getClass());
}
}
}
}
return instance;
}
protected void activate(final ComponentContext componentContext) {
this.componentContext = componentContext;
// Read configuration
isTcServicesEnabled = true;
Object configTcServicesEnabled = componentContext.getProperties().get(Graph_SERVICES_ENABLED);
if ( configTcServicesEnabled != null && configTcServicesEnabled instanceof String ) {
isTcServicesEnabled = Boolean.valueOf((String)configTcServicesEnabled);
}
Object configCacheEnabled = componentContext.getProperties().get(MGRAPH_CACHE_ENABLED);
if ( configCacheEnabled != null && configCacheEnabled instanceof String ) {
setCachingEnabled(Boolean.valueOf((String)configCacheEnabled));
}
isActivated = true;
for (WeightedTcProvider provider : tempProviderList) {
addWeightedTcProvider(provider);
}
tempProviderList.clear();
}
protected void deactivate(final ComponentContext componentContext) {
for (ServiceRegistration registration : serviceRegistrations.values()) {
registration.unregister();
}
serviceRegistrations.clear();
this.componentContext = null;
isActivated = false;
}
@Override
public ImmutableGraph getImmutableGraph(IRI name) throws NoSuchEntityException {
tcAccessController.checkReadPermission(name);
return super.getImmutableGraph(name);
}
@Override
public Graph getMGraph(IRI name) {
try {
tcAccessController.checkReadWritePermission(name);
} catch (AccessControlException e) {
tcAccessController.checkReadPermission(name);
return new WriteBlockedGraph(super.getMGraph(name));
}
return super.getMGraph(name);
}
@Override
public Graph getGraph(IRI name) {
try {
tcAccessController.checkReadWritePermission(name);
} catch (AccessControlException e) {
tcAccessController.checkReadPermission(name);
return new WriteBlockedGraph(super.getGraph(name));
}
return super.getGraph(name);
}
@Override
public Graph createGraph(IRI name)
throws UnsupportedOperationException {
tcAccessController.checkReadWritePermission(name);
return super.createGraph(name);
}
@Override
public ImmutableGraph createImmutableGraph(IRI name, Graph triples) {
tcAccessController.checkReadWritePermission(name);
return super.createImmutableGraph(name, triples);
}
@Override
public void deleteGraph(IRI name) {
tcAccessController.checkReadWritePermission(name);
super.deleteGraph(name);
}
@Override
public Set<IRI> getNames(ImmutableGraph ImmutableGraph) {
return super.getNames(ImmutableGraph);
}
@Override
public Set<IRI> listNamedGraphs() {
return this.listGraphs();
}
@Override
public Set<IRI> listGraphs() {
Set<IRI> result = super.listGraphs();
return excludeNonReadable(result);
}
@Override
public Set<IRI> listMGraphs() {
Set<IRI> result = super.listMGraphs();
return excludeNonReadable(result);
}
@Override
public Set<IRI> listImmutableGraphs() {
Set<IRI> result = super.listImmutableGraphs();
return excludeNonReadable(result);
}
private Set<IRI> excludeNonReadable(Set<IRI> tcNames) {
SecurityManager security = System.getSecurityManager();
if (security == null) {
return tcNames;
}
Set<IRI> result = new HashSet<IRI>();
for (IRI name : tcNames) {
try {
tcAccessController.checkReadPermission(name);
} catch (AccessControlException e) {
continue;
}
result.add(name);
}
return result;
}
/**
* Executes any sparql query. The type of the result object will vary
* depending on the type of the query. If the defaultGraph is available
* in this TcManages executeSparqlQuery(String, UriRef) should be used instead.
*
* @param query the sparql query to execute
* @param defaultGraph the default ImmutableGraph against which to execute the query
* if no FROM clause is present
* @return the resulting ResultSet, ImmutableGraph or Boolean value
*/
public Object executeSparqlQuery(String query, Graph defaultGraph) throws ParseException {
TcProvider singleTargetTcProvider = null;
final IRI defaultGraphName = new IRI("urn:x-temp:/kjsfadfhfasdffds");
final SparqlPreParser sparqlPreParser = new SparqlPreParser(this);
final Set<IRI> referencedGraphs = sparqlPreParser.getReferredGraphs(query, defaultGraphName);
if ((referencedGraphs != null) && (!referencedGraphs.contains(defaultGraphName))) {
singleTargetTcProvider = getSingleTargetTcProvider(referencedGraphs);
}
if ((singleTargetTcProvider != null) && (singleTargetTcProvider instanceof QueryableTcProvider)) {
return ((QueryableTcProvider) singleTargetTcProvider).executeSparqlQuery(query, null);
}
final QueryEngine queryEngine = this.queryEngine;
if (queryEngine != null) {
return queryEngine.execute(this, defaultGraph, query);
} else {
throw new NoQueryEngineException();
}
}
/**
* Executes any sparql query. The type of the result object will vary
* depending on the type of the query. Note that this method only works for
* queries that do not need a default ImmutableGraph.
*
* @param query the sparql query to execute
* @param forceFastlane indicate whether to force fastlane usage.
* @return the resulting ResultSet, ImmutableGraph or Boolean value
*/
public Object executeSparqlQuery(String query, boolean forceFastlane) throws ParseException {
TcProvider singleTargetTcProvider = null;
if (forceFastlane) {
singleTargetTcProvider = getSingleTargetTcProvider(Collections.EMPTY_SET);
} else {
final IRI defaultGraphName = new IRI("urn:x-temp:/kjsfadfhfasdffds");
SparqlPreParser sparqlPreParser = new SparqlPreParser(this);
final Set<IRI> referencedGraphs = sparqlPreParser.getReferredGraphs(query, defaultGraphName);
if ((referencedGraphs != null) && (!referencedGraphs.contains(defaultGraphName))) {
singleTargetTcProvider = getSingleTargetTcProvider(referencedGraphs);
}
}
if ((singleTargetTcProvider != null) && (singleTargetTcProvider instanceof QueryableTcProvider)) {
return ((QueryableTcProvider)singleTargetTcProvider).executeSparqlQuery(query, null);
}
final QueryEngine queryEngine = this.queryEngine;
if (queryEngine != null) {
return queryEngine.execute(this, new SimpleGraph(), query);
} else {
throw new NoQueryEngineException();
}
}
/**
* Executes any sparql query. The type of the result object will vary
* depending on the type of the query. If the defaultGraph is available
* in this TcManages executeSparqlQuery(String, UriRef) should be used instead.
*
* @param query the sparql query to execute
* @param defaultGraphName the ImmutableGraph to be used as default ImmutableGraph in the Sparql ImmutableGraph Store
* @return the resulting ResultSet, ImmutableGraph or Boolean value
*/
public Object executeSparqlQuery(String query, IRI defaultGraphName) throws ParseException {
return executeSparqlQuery(query, defaultGraphName, false);
}
/**
* Executes any sparql query. The type of the result object will vary
* depending on the type of the query. If the defaultGraph is available
* in this TcManages executeSparqlQuery(String, UriRef) should be used instead.
*
* @param query the sparql query to execute
* @param defaultGraphName the ImmutableGraph to be used as default ImmutableGraph in the Sparql ImmutableGraph Store
* @param forceFastlane indicate whether to force fastlane usage.
* @return the resulting ResultSet, ImmutableGraph or Boolean value
*/
public Object executeSparqlQuery(String query, IRI defaultGraphName, boolean forceFastlane) throws ParseException {
TcProvider singleTargetTcProvider = null;
if (forceFastlane) {
singleTargetTcProvider = getSingleTargetTcProvider(Collections.singleton(defaultGraphName));
} else {
SparqlPreParser sparqlPreParser = new SparqlPreParser(this);
final Set<IRI> referencedGraphs = sparqlPreParser.getReferredGraphs(query, defaultGraphName);
if ((referencedGraphs != null)) {
singleTargetTcProvider = getSingleTargetTcProvider(referencedGraphs);
}
}
if ((singleTargetTcProvider != null) && (singleTargetTcProvider instanceof QueryableTcProvider)) {
return ((QueryableTcProvider)singleTargetTcProvider).executeSparqlQuery(query, defaultGraphName);
}
final QueryEngine queryEngine = this.queryEngine;
if (queryEngine != null) {
return queryEngine.execute(this, this.getGraph(defaultGraphName), query);
} else {
throw new NoQueryEngineException();
}
}
/**
* Executes any sparql query. The type of the result object will vary
* depending on the type of the query.
*
* @param query the sparql query to execute
* @param defaultGraph the default ImmutableGraph against which to execute the query
* if no FROM clause is present
* @return the resulting ResultSet, ImmutableGraph or Boolean value
*
* @deprecated Query is discontinued
*/
@Deprecated
public Object executeSparqlQuery(Query query, Graph defaultGraph) {
final QueryEngine queryEngine = this.queryEngine;
if (queryEngine != null) {
return queryEngine.execute(this, defaultGraph, query.toString());
} else {
throw new NoQueryEngineException();
}
}
/**
* Executes a sparql SELECT query.
*
* @param query the sparql SELECT query to execute
* @param defaultGraph the default ImmutableGraph against which to execute the query
* if not FROM clause is present
* @return the resulting ResultSet
* @deprecated Query is discontinued
*/
@Deprecated
public ResultSet executeSparqlQuery(SelectQuery query,
Graph defaultGraph) {
return (ResultSet) executeSparqlQuery((Query) query, defaultGraph);
}
/**
* Executes a sparql ASK query.
*
* @param query the sparql ASK query to execute
* @param defaultGraph the default ImmutableGraph against which to execute the query
* if not FROM clause is present
* @return the boolean value this query evaluates to
* @deprecated Query is discontinued
*/
@Deprecated
public boolean executeSparqlQuery(AskQuery query,
Graph defaultGraph) {
return (Boolean) executeSparqlQuery((Query) query, defaultGraph);
}
/**
* Executes a sparql DESCRIBE query.
*
* @param query the sparql DESCRIBE query to execute
* @param defaultGraph the default ImmutableGraph against which to execute the query
* if not FROM clause is present
* @return the resulting ImmutableGraph
* @deprecated Query is discontinued
*/
@Deprecated
public ImmutableGraph executeSparqlQuery(DescribeQuery query,
Graph defaultGraph) {
return (ImmutableGraph) executeSparqlQuery((Query) query, defaultGraph);
}
/**
* Executes a sparql CONSTRUCT query.
*
* @param query the sparql CONSTRUCT query to execute
* @param defaultGraph the default ImmutableGraph against which to execute the query
* if not FROM clause is present
* @return the resulting ImmutableGraph
* @deprecated Query is discontinued
*/
@Deprecated
public ImmutableGraph executeSparqlQuery(ConstructQuery query,
Graph defaultGraph) {
return (ImmutableGraph) executeSparqlQuery((Query) query, defaultGraph);
}
/**
* @return the TcAccessController that can be used to set the permissions
* needed to access a Triple Collection
*/
public TcAccessController getTcAccessController() {
return tcAccessController;
}
/**
* Registers a provider
*
* @param provider the provider to be registered
*/
@Reference(policy = ReferencePolicy.DYNAMIC,
cardinality = ReferenceCardinality.MULTIPLE)
protected void bindWeightedTcProvider(WeightedTcProvider provider) {
if (isActivated) {
addWeightedTcProvider(provider);
} else {
tempProviderList.add(provider);
}
}
/**
* Unregister a provider
*
* @param provider the provider to be deregistered
*/
protected void unbindWeightedTcProvider(
WeightedTcProvider provider) {
removeWeightedTcProvider(provider);
}
/**
* Registers a provider
*
* @param provider the provider to be registered
*/
@Reference(policy = ReferencePolicy.DYNAMIC,
cardinality = ReferenceCardinality.AT_LEAST_ONE,
target = "("+ TcManager.GENERAL_PURPOSE_TC+"=true)")
protected void bindGpWeightedTcProvider(WeightedTcProvider provider) {
if (isActivated) {
addWeightedTcProvider(provider);
} else {
tempProviderList.add(provider);
}
}
/**
* Unregister a provider
*
* @param provider the provider to be deregistered
*/
protected void unbindGpWeightedTcProvider(
WeightedTcProvider provider) {
removeWeightedTcProvider(provider);
}
@Reference(policy = ReferencePolicy.DYNAMIC,
cardinality = ReferenceCardinality.OPTIONAL)
protected void bindQueryEngine(QueryEngine queryEngine) {
this.queryEngine = queryEngine;
}
protected void unbindQueryEngine(QueryEngine queryEngine) {
this.queryEngine = null;
}
@Override
protected void mGraphAppears(IRI name) {
if (isTcServicesEnabled()) {
// Only create the service when activated. When not activated
// creating will be delayed till after activation.
if (componentContext != null) {
registerGraphAsService(name, true);
}
}
}
@Override
protected void graphAppears(IRI name) {
if (isTcServicesEnabled()) {
// Only create the service when activated. When not activated
// creating will be delayed till after activation.
if (componentContext != null) {
registerGraphAsService(name, false);
}
}
}
private void registerGraphAsService(IRI name, boolean isMGraph) {
Dictionary<String,Object> props = new Hashtable<String, Object>();
props.put("name", name.getUnicodeString());
String[] interfaceNames;
Object service;
if (isMGraph) {
interfaceNames = new String[]{
Graph.class.getName(),
Graph.class.getName()
};
service = new MGraphServiceFactory(this, name, tcAccessController);
} else {
interfaceNames = new String[]{ImmutableGraph.class.getName()};
service = new ImmutableGraphServiceFactory(this, name, tcAccessController);
}
final int bundleState = componentContext.getBundleContext().getBundle().getState();
if ((bundleState == Bundle.ACTIVE) || (bundleState == Bundle.STARTING)) {
ServiceRegistration serviceReg = componentContext.getBundleContext()
.registerService(interfaceNames, service, props);
serviceRegistrations.put(name, serviceReg);
}
}
@Override
protected void tcDisappears(IRI name) {
ServiceRegistration reg = serviceRegistrations.get(name);
if (reg != null) {
reg.unregister();
serviceRegistrations.remove(name);
}
}
private TcProvider getSingleTargetTcProvider(final Set<IRI> referencedGraphs) {
TcProvider singleTargetTcProvider = null;
for (WeightedTcProvider provider : providerList) {
final Set<IRI> providerGraphs = provider.listGraphs();
if (providerGraphs.containsAll(referencedGraphs)) {
singleTargetTcProvider = provider;
break; //success
}
for (IRI graphName : referencedGraphs) {
if (providerGraphs.contains(graphName)) {
break; //failure
}
}
}
return singleTargetTcProvider;
}
public boolean isTcServicesEnabled() {
return isTcServicesEnabled;
}
}
| 298 |
0 | Create_ds/clerezza/dataset/src/main/java/org/apache/clerezza | Create_ds/clerezza/dataset/src/main/java/org/apache/clerezza/dataset/TcProvider.java | /*
* 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 org.apache.clerezza.dataset;
import org.apache.clerezza.Graph;
import org.apache.clerezza.IRI;
import org.apache.clerezza.ImmutableGraph;
import java.util.Set;
/**
* A TC (Graph) Provider allows access to and optionally
* creation of named {@link ImmutableGraph}s and {@link Graph}s (mutable graphs)
*
* @author reto
*/
public interface TcProvider {
/**
* Get a <code>ImmutableGraph</code> by its name
*
* @param name the name of the ImmutableGraph
* @return the <code>ImmutableGraph</code> with the specified name
* @throws NoSuchEntityException if there is no <code>ImmutableGraph</code>
* with the specified name
*/
ImmutableGraph getImmutableGraph(IRI name) throws NoSuchEntityException;
/**
* Get an <code>Graph</code> taht is not <code>ImmutableGrah</code>. The instances
* returned in different invocations are <code>equals</code>.
*
* @param name the name of the <code>Graph</code>
* @return <code>Graph</code> with the specified name
* @throws NoSuchEntityException if there is no <code>Graph</code>
* with the specified name
*/
Graph getMGraph(IRI name) throws NoSuchEntityException;
/**
* This method is used to get a <code>Graph</code> indifferently
* whether it's a ImmutableGraph or not. If the <code>name</code> names an
* <code>Graph</code> the result is the same as when invoking
* <code>getMGraph</code> with that argument, analogously for
* <code>ImmutableGraph</code>S the method returns an instance equals to what
* <code>getImmutableGraph</code> would return.
*
* @param name the name of the <Code>ImmutableGraph</code> or <code>Graph</code>
* @return the <Code>ImmutableGraph</code> or <code>Graph</code>
* @throws NoSuchEntityException if there is no <code>ImmutableGraph</code>
* or <code>Graph</code> with the specified name
*/
Graph getGraph(IRI name) throws NoSuchEntityException;
/**
* Lists the name of the <Code>ImmutableGraph</code>s available through this
* <code>TcProvider</code>, implementations may take into account the
* security context and omit <Code>ImmutableGraph</code>s for which access is not
* allowed.
*
* @return the list of <Code>ImmutableGraph</code>s
*/
Set<IRI> listImmutableGraphs();
/**
* Lists the name of the <Code>Graph</code>s available through this
* <code>TcProvider</code> that are not <Code>ImmutableGraph</code>, implementations may take into account the
* security context and omit <Code>Graph</code>s for which access is not
* allowed.
*
* @return the list of <Code>Graph</code>s
*/
Set<IRI> listMGraphs();
/**
* Lists the name of the <Code>Graph</code>s available through this
* <code>TcProvider</code> indifferently whether they are mutables or
* immutables, implementations may take into account the security context and
* omit <Code>Graph</code>s for which access is not allowed.
*
* @return the list of <Code>Graph</code>s
*/
Set<IRI> listGraphs();
/**
* Creates an initially empty <code>Graph</code> with a specified name
*
* @param name names the new <code>Graph</code>
* @return the newly created <code>Graph</code>
* @throws UnsupportedOperationException if this provider doesn't support
* creating <code>Graph</code>S
* @throws EntityAlreadyExistsException if an Graph with the specified name
* already exists
*/
Graph createGraph(IRI name) throws UnsupportedOperationException,
EntityAlreadyExistsException;
/**
* Creates a <code>ImmutableGraph</code> with a specified name
*
* @param name the name of the <code>ImmutableGraph</code> to be created
* @param triples the triples of the new <code>ImmutableGraph</code>
* @return the newly created <code>ImmutableGraph</code>
* @throws UnsupportedOperationException if this provider doesn't support
* creating <code>ImmutableGraph</code>S
* @throws EntityAlreadyExistsException if a ImmutableGraph with the specified name
* already exists
*/
ImmutableGraph createImmutableGraph(IRI name, Graph triples)
throws UnsupportedOperationException, EntityAlreadyExistsException;
/**
* Deletes the <code>ImmutableGraph</code> or <code>Graph</code> of a specified name.
* If <code>name</code> references a ImmutableGraph and the ImmutableGraph has other names, it
* will still be available with those other names.
*
* @param name the entity to be removed
* @throws UnsupportedOperationException if this provider doesn't support
* entities deletion.
* @throws NoSuchEntityException if <code>name</code> doesn't refer to a
* <code>ImmutableGraph</code> or an <code>Graph</code>.
* @throws EntityUndeletableException if the specified ImmutableGraph is undeletable
*/
void deleteGraph(IRI name) throws UnsupportedOperationException,
NoSuchEntityException, EntityUndeletableException;
/**
* get a set of the names of a <code>ImmutableGraph</code>
*
* @param immutableGraph
* @return the set names of <code>ImmutableGraph</code>, the set is empty if
* <code>ImmutableGraph</code> is unknown
*/
Set<IRI> getNames(ImmutableGraph immutableGraph);
}
| 299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.