http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/GraphDbObjectFactory.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/GraphDbObjectFactory.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/GraphDbObjectFactory.java deleted file mode 100644 index 73097f2..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/GraphDbObjectFactory.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import com.thinkaurelius.titan.core.EdgeLabel; -import org.apache.atlas.repository.graphdb.AtlasCardinality; -import org.apache.atlas.repository.graphdb.AtlasGraphIndex; -import org.apache.atlas.repository.graphdb.titan0.query.Titan0GraphQuery; - -import com.thinkaurelius.titan.core.Cardinality; -import com.thinkaurelius.titan.core.PropertyKey; -import com.thinkaurelius.titan.core.schema.TitanGraphIndex; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; - -/** - * Factory that serves up instances of graph database abstraction layer classes - * that correspond to Titan/Tinkerpop classes. - */ -public final class GraphDbObjectFactory { - - private GraphDbObjectFactory() { - - } - - /** - * Creates a Titan0Edge that corresponds to the given Gremlin Edge. - * - * @param graph The graph the edge should be created in - * @param source The gremlin edge - */ - public static Titan0Edge createEdge(Titan0Graph graph, Edge source) { - - if (source == null) { - return null; - } - return new Titan0Edge(graph, source); - } - - /** - * Creates a Titan0GraphQuery that corresponds to the given GraphQuery. - * - * @param graph the graph that is being quried - */ - public static Titan0GraphQuery createQuery(Titan0Graph graph) { - - return new Titan0GraphQuery(graph); - } - - /** - * Creates a Titan0Vertex that corresponds to the given Gremlin Vertex. - * - * @param graph The graph that contains the vertex - * @param source the Gremlin vertex - */ - public static Titan0Vertex createVertex(Titan0Graph graph, Vertex source) { - - if (source == null) { - return null; - } - return new Titan0Vertex(graph, source); - } - - /** - * @param propertyKey The Gremlin propertyKey. - * - */ - public static Titan0PropertyKey createPropertyKey(PropertyKey propertyKey) { - if (propertyKey == null) { - return null; - } - return new Titan0PropertyKey(propertyKey); - } - - /** - * @param label The label. - * - */ - public static Titan0EdgeLabel createEdgeLabel(EdgeLabel label) { - if (label == null) { - return null; - } - return new Titan0EdgeLabel(label); - } - - /** - * @param index The gremlin index. - * @return - */ - public static AtlasGraphIndex createGraphIndex(TitanGraphIndex index) { - if (index == null) { - return null; - } - return new Titan0GraphIndex(index); - } - - /** - * Converts a Multiplicity to a Cardinality. - * - * @param cardinality - * @return - */ - public static AtlasCardinality createCardinality(Cardinality cardinality) { - - if (cardinality == Cardinality.SINGLE) { - return AtlasCardinality.SINGLE; - } else if (cardinality == Cardinality.LIST) { - return AtlasCardinality.LIST; - } - return AtlasCardinality.SET; - } - -}
http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Edge.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Edge.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Edge.java deleted file mode 100644 index 1d5d409..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Edge.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; -import org.apache.atlas.repository.graphdb.AtlasEdge; -import org.apache.atlas.repository.graphdb.AtlasVertex; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; - -/** - * Titan 0.5.4 implementation of AtlasEdge. - */ -public class Titan0Edge extends Titan0Element<Edge> implements AtlasEdge<Titan0Vertex, Titan0Edge> { - - - public Titan0Edge(Titan0Graph graph, Edge edge) { - super(graph, edge); - } - - @Override - public String getLabel() { - return wrappedElement.getLabel(); - } - - @Override - public Titan0Edge getE() { - return this; - } - - @Override - public AtlasVertex<Titan0Vertex, Titan0Edge> getInVertex() { - Vertex v = wrappedElement.getVertex(Direction.IN); - return GraphDbObjectFactory.createVertex(graph, v); - } - - @Override - public AtlasVertex<Titan0Vertex, Titan0Edge> getOutVertex() { - Vertex v = wrappedElement.getVertex(Direction.OUT); - return GraphDbObjectFactory.createVertex(graph, v); - } - - @Override - public String toString() { - return "Titan0Edge [id=" + getId() + "]"; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0EdgeLabel.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0EdgeLabel.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0EdgeLabel.java deleted file mode 100644 index 934e255..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0EdgeLabel.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import com.thinkaurelius.titan.core.EdgeLabel; -import org.apache.atlas.repository.graphdb.AtlasEdgeLabel; - -/** - * Titan 0.5.4 implementaiton of AtlasEdgeLabel. - */ -public class Titan0EdgeLabel implements AtlasEdgeLabel { - private final EdgeLabel wrappedEdgeLabel; - - public Titan0EdgeLabel(EdgeLabel toWrap) { - wrappedEdgeLabel = toWrap; - } - - /* - * (non-Javadoc) - * - * @see org.apache.atlas.repository.graphdb.AtlasEdgeLabel#getName() - */ - @Override - public String getName() { - return wrappedEdgeLabel.getName(); - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof Titan0EdgeLabel)) { - return false; - } - Titan0EdgeLabel otherLabel = (Titan0EdgeLabel) other; - return wrappedEdgeLabel.equals(otherLabel.wrappedEdgeLabel); - } - - @Override - public int hashCode() { - int result = 17; - result = 37 * result + wrappedEdgeLabel.hashCode(); - return result; - } - - @Override - public String toString() { - return wrappedEdgeLabel.getName(); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Element.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Element.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Element.java deleted file mode 100644 index 3b50633..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Element.java +++ /dev/null @@ -1,267 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import java.lang.Override; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import org.apache.atlas.repository.graphdb.AtlasEdge; -import org.apache.atlas.repository.graphdb.AtlasElement; -import org.apache.atlas.repository.graphdb.AtlasSchemaViolationException; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; - -import com.google.common.base.Function; -import com.google.common.collect.Lists; -import com.thinkaurelius.titan.core.SchemaViolationException; -import com.thinkaurelius.titan.core.TitanElement; -import com.tinkerpop.blueprints.Element; -import com.tinkerpop.blueprints.util.io.graphson.GraphSONMode; -import com.tinkerpop.blueprints.util.io.graphson.GraphSONUtility; - -/** - * Titan 0.5.4 implementation of AtlasElement. - */ -public class Titan0Element<T extends Element> implements AtlasElement { - - protected Titan0Graph graph; - protected T wrappedElement; - - public Titan0Element(Titan0Graph graph, T element) { - wrappedElement = element; - this.graph = graph; - } - - @Override - public Object getId() { - return wrappedElement.getId(); - } - - @Override - public Set<String> getPropertyKeys() { - return wrappedElement.getPropertyKeys(); - } - - @Override - public <U> void setProperty(String propertyName, U value) { - try { - wrappedElement.setProperty(propertyName, value); - } catch (SchemaViolationException e) { - throw new AtlasSchemaViolationException(e); - } - } - - @Override - public <U> U getProperty(String propertyName, Class<U> clazz) { - - Object rawValue = wrappedElement.getProperty(propertyName); - - if (rawValue == null) { - return null; - } - if (AtlasEdge.class == clazz) { - return (U)graph.getEdge(rawValue.toString()); - } - if (AtlasVertex.class == clazz) { - return (U)graph.getVertex(rawValue.toString()); - } - return (U)rawValue; - - } - - /** - * Gets all of the values of the given property. - * @param propertyName - * @return - */ - @Override - public <T> Collection<T> getPropertyValues(String propertyName, Class<T> type) { - return Collections.singleton(getProperty(propertyName, type)); - } - - @Override - public void removeProperty(String propertyName) { - wrappedElement.removeProperty(propertyName); - - } - - @Override - public JSONObject toJson(Set<String> propertyKeys) throws JSONException { - return GraphSONUtility.jsonFromElement(wrappedElement, propertyKeys, GraphSONMode.NORMAL); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.atlas.repository.graphdb.AtlasElement#getListProperty(java. - * lang.String) - */ - @Override - public List<String> getListProperty(String propertyName) { - return getProperty(propertyName, List.class); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.atlas.repository.graphdb.AtlasElement#setListProperty(java. - * lang.String, java.util.List) - */ - @Override - public void setListProperty(String propertyName, List<String> values) { - setProperty(propertyName, values); - - } - - @Override - public T getWrappedElement() { - return wrappedElement; - } - - @Override - public int hashCode() { - int result = 37; - result = 17 * result + getClass().hashCode(); - result = 17 * result + getWrappedElement().hashCode(); - return result; - } - - @Override - public boolean equals(Object other) { - if (other == null) { - return false; - } - if (other.getClass() != getClass()) { - return false; - } - Titan0Element otherElement = (Titan0Element) other; - return getWrappedElement().equals(otherElement.getWrappedElement()); - } - - /* - * (non-Javadoc) - * - * @see org.apache.atlas.repository.graphdb.AtlasElement#exists() - */ - @Override - public boolean exists() { - try { - return !((TitanElement)wrappedElement).isRemoved(); - } catch(IllegalStateException e) { - return false; - } - - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.atlas.repository.graphdb.AtlasElement#setJsonProperty(java. - * lang.String, java.lang.Object) - */ - @Override - public <T> void setJsonProperty(String propertyName, T value) { - setProperty(propertyName, value); - - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.atlas.repository.graphdb.AtlasElement#getJsonProperty(java. - * lang.String) - */ - @Override - public <T> T getJsonProperty(String propertyName) { - return (T) getProperty(propertyName, String.class); - } - - @Override - public String getIdForDisplay() { - return getId().toString(); - } - - - - @Override - public <V> List<V> getListProperty(String propertyName, Class<V> elementType) { - - List<String> value = getListProperty(propertyName); - - if (value == null) { - return null; - } - - if (AtlasEdge.class == elementType) { - - return (List<V>)Lists.transform(value, new Function<String, AtlasEdge>(){ - - @Override - public AtlasEdge apply(String input) { - return graph.getEdge(input); - } - }); - } - - if (AtlasVertex.class == elementType) { - - return (List<V>)Lists.transform(value, new Function<String, AtlasVertex>(){ - - @Override - public AtlasVertex apply(String input) { - return graph.getVertex(input); - } - }); - } - - return (List<V>)value; - } - - - @Override - public void setPropertyFromElementsIds(String propertyName, List<AtlasElement> values) { - List<String> propertyValue = new ArrayList<>(values.size()); - for(AtlasElement element: values) { - propertyValue.add(element.getId().toString()); - } - setProperty(propertyName, propertyValue); - } - - - @Override - public void setPropertyFromElementId(String propertyName, AtlasElement value) { - setProperty(propertyName, value.getId().toString()); - - } - - - @Override - public boolean isIdAssigned() { - - return true; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Graph.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Graph.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Graph.java deleted file mode 100644 index d191b55..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Graph.java +++ /dev/null @@ -1,432 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.thinkaurelius.titan.core.Cardinality; -import com.thinkaurelius.titan.core.PropertyKey; -import com.thinkaurelius.titan.core.SchemaViolationException; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.TitanIndexQuery; -import com.thinkaurelius.titan.core.schema.TitanManagement; -import com.thinkaurelius.titan.core.util.TitanCleanup; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Element; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.util.io.graphson.GraphSONWriter; -import com.tinkerpop.pipes.util.structures.Row; -import org.apache.atlas.AtlasErrorCode; -import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.groovy.GroovyExpression; -import org.apache.atlas.model.impexp.MigrationStatus; -import org.apache.atlas.repository.graphdb.AtlasEdge; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.atlas.repository.graphdb.AtlasGraphManagement; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery; -import org.apache.atlas.repository.graphdb.AtlasIndexQuery; -import org.apache.atlas.repository.graphdb.AtlasSchemaViolationException; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.repository.graphdb.GremlinVersion; -import org.apache.atlas.repository.graphdb.titan0.query.Titan0GraphQuery; -import org.apache.atlas.repository.graphdb.utils.IteratorToIterableAdapter; -import org.apache.atlas.type.AtlasType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.script.Bindings; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - - -/** - * Titan 0.5.4 implementation of AtlasGraph. - */ -public class Titan0Graph implements AtlasGraph<Titan0Vertex, Titan0Edge> { - private static final Logger LOG = LoggerFactory.getLogger(Titan0Graph.class); - - private final Set<String> multiProperties; - - public Titan0Graph() { - //determine multi-properties once at startup - TitanManagement mgmt = null; - try { - mgmt = Titan0GraphDatabase.getGraphInstance().getManagementSystem(); - Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class); - multiProperties = Collections.synchronizedSet(new HashSet<String>()); - for(PropertyKey key : keys) { - if (key.getCardinality() != Cardinality.SINGLE) { - multiProperties.add(key.getName()); - } - } - } finally { - if (mgmt != null) { - mgmt.rollback(); - } - } - } - - @Override - public AtlasEdge<Titan0Vertex, Titan0Edge> addEdge(AtlasVertex<Titan0Vertex, Titan0Edge> outVertex, - AtlasVertex<Titan0Vertex, Titan0Edge> inVertex, String edgeLabel) { - try { - Edge edge = getGraph().addEdge(null, outVertex.getV().getWrappedElement(), - inVertex.getV().getWrappedElement(), edgeLabel); - return GraphDbObjectFactory.createEdge(this, edge); - } catch (SchemaViolationException e) { - throw new AtlasSchemaViolationException(e); - } - } - - - @Override - public AtlasGraphQuery<Titan0Vertex, Titan0Edge> query() { - - return new Titan0GraphQuery(this); - } - - @Override - public AtlasEdge<Titan0Vertex, Titan0Edge> getEdge(String edgeId) { - Edge edge = getGraph().getEdge(edgeId); - return GraphDbObjectFactory.createEdge(this, edge); - } - - @Override - public void removeEdge(AtlasEdge<Titan0Vertex, Titan0Edge> edge) { - getGraph().removeEdge(edge.getE().getWrappedElement()); - - } - - @Override - public void removeVertex(AtlasVertex<Titan0Vertex, Titan0Edge> vertex) { - getGraph().removeVertex(vertex.getV().getWrappedElement()); - - } - - @Override - public Iterable<AtlasEdge<Titan0Vertex, Titan0Edge>> getEdges() { - Iterable<Edge> edges = getGraph().getEdges(); - return wrapEdges(edges); - } - - @Override - public Iterable<AtlasVertex<Titan0Vertex, Titan0Edge>> getVertices() { - Iterable<Vertex> vertices = getGraph().getVertices(); - return wrapVertices(vertices); - } - - @Override - public AtlasVertex<Titan0Vertex, Titan0Edge> addVertex() { - Vertex result = getGraph().addVertex(null); - return GraphDbObjectFactory.createVertex(this, result); - } - - @Override - public void commit() { - getGraph().commit(); - } - - @Override - public void rollback() { - getGraph().rollback(); - } - - @Override - public AtlasIndexQuery<Titan0Vertex, Titan0Edge> indexQuery(String fulltextIndex, String graphQuery) { - return indexQuery(fulltextIndex, graphQuery, 0); - } - - @Override - public AtlasIndexQuery<Titan0Vertex, Titan0Edge> indexQuery(String fulltextIndex, String graphQuery, int offset) { - TitanIndexQuery query = getGraph().indexQuery(fulltextIndex, graphQuery).offset(offset); - return new Titan0IndexQuery(this, query); - } - - @Override - public AtlasGraphManagement getManagementSystem() { - return new Titan0GraphManagement(this, getGraph().getManagementSystem()); - } - - @Override - public void shutdown() { - getGraph().shutdown(); - } - - @Override - public Set<String> getVertexIndexKeys() { - return getIndexKeys(Vertex.class); - } - - @Override - public Set<String> getEdgeIndexKeys() { - return getIndexKeys(Edge.class); - } - - private Set<String> getIndexKeys(Class<? extends Element> titanClass) { - - return getGraph().getIndexedKeys(titanClass); - } - - @Override - public AtlasVertex<Titan0Vertex, Titan0Edge> getVertex(String vertexId) { - Vertex v = getGraph().getVertex(vertexId); - return GraphDbObjectFactory.createVertex(this, v); - } - - @Override - public Iterable<AtlasVertex<Titan0Vertex, Titan0Edge>> getVertices(String key, Object value) { - - Iterable<Vertex> result = getGraph().getVertices(key, value); - return wrapVertices(result); - } - - private Object convertGremlinValue(Object rawValue) { - - if (rawValue instanceof Vertex) { - return GraphDbObjectFactory.createVertex(this, (Vertex) rawValue); - } else if (rawValue instanceof Edge) { - return GraphDbObjectFactory.createEdge(this, (Edge) rawValue); - } else if (rawValue instanceof Row) { - Row rowValue = (Row)rawValue; - Map<String, Object> result = new HashMap<>(rowValue.size()); - List<String> columnNames = rowValue.getColumnNames(); - for(int i = 0; i < rowValue.size(); i++) { - String key = columnNames.get(i); - Object value = convertGremlinValue(rowValue.get(i)); - result.put(key, value); - } - return result; - } else if (rawValue instanceof List) { - return Lists.transform((List)rawValue, new Function<Object, Object>() { - @Override - public Object apply(Object input) { - return convertGremlinValue(input); - } - }); - } else if (rawValue instanceof Collection) { - throw new UnsupportedOperationException("Unhandled collection type: " + rawValue.getClass()); - } - return rawValue; - } - - @Override - public GremlinVersion getSupportedGremlinVersion() { - - return GremlinVersion.TWO; - } - - private List<Object> convertPathQueryResultToList(Object rawValue) { - return (List<Object>) rawValue; - } - - - @Override - public void clear() { - TitanGraph graph = getGraph(); - if (graph.isOpen()) { - // only a shut down graph can be cleared - graph.shutdown(); - } - TitanCleanup.clear(graph); - } - - private TitanGraph getGraph() { - // return the singleton instance of the graph in the plugin - return Titan0GraphDatabase.getGraphInstance(); - } - - @Override - public void exportToGson(OutputStream os) throws IOException { - GraphSONWriter.outputGraph(getGraph(), os); - } - - @Override - public Object executeGremlinScript(String query, boolean isPath) throws AtlasBaseException { - - Object result = executeGremlinScript(query); - return convertGremlinScriptResult(isPath, result); - } - - private Object convertGremlinScriptResult(boolean isPath, Object result) { - if (isPath) { - List<Object> path = convertPathQueryResultToList(result); - - List<Object> convertedResult = new ArrayList<>(path.size()); - for(Object o : path) { - convertedResult.add(convertGremlinValue(o)); - } - return convertedResult; - } else { - return convertGremlinValue(result); - } - } - - @Override - public ScriptEngine getGremlinScriptEngine() throws AtlasBaseException { - ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("gremlin-groovy"); - - if (engine == null) { - throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_GREMLIN_SCRIPT_ENGINE, "gremlin-groovy"); - } - - //Do not cache script compilations due to memory implications - engine.getContext().setAttribute("#jsr223.groovy.engine.keep.globals", "phantom", ScriptContext.ENGINE_SCOPE); - - return engine; - } - - @Override - public void releaseGremlinScriptEngine(ScriptEngine scriptEngine) { - // no action needed - } - - @Override - public Object executeGremlinScript(ScriptEngine scriptEngine, Map<? extends String, ? extends Object> userBindings, String query, boolean isPath) throws ScriptException { - if (LOG.isDebugEnabled()) { - LOG.debug("executeGremlinScript(query={}, userBindings={})", query, userBindings); - } - - Bindings bindings = scriptEngine.createBindings(); - - if (userBindings != null) { - bindings.putAll(userBindings); - } - - bindings.put("g", getGraph()); - - Object result = scriptEngine.eval(query, bindings); - - return convertGremlinScriptResult(isPath, result); - } - - private Object executeGremlinScript(String gremlinQuery) throws AtlasBaseException { - Object result = null; - ScriptEngine engine = getGremlinScriptEngine(); - - try { - Bindings bindings = engine.createBindings(); - - bindings.put("g", getGraph()); - - result = engine.eval(gremlinQuery, bindings); - } catch (ScriptException e) { - throw new AtlasBaseException(AtlasErrorCode.GREMLIN_SCRIPT_EXECUTION_FAILED, gremlinQuery); - } finally { - releaseGremlinScriptEngine(engine); - } - - return result; - } - - @Override - public GroovyExpression generatePersisentToLogicalConversionExpression(GroovyExpression expr, AtlasType type) { - - //nothing special needed, value is stored in required type - return expr; - } - - @Override - public boolean isPropertyValueConversionNeeded(AtlasType type) { - - return false; - } - - @Override - public boolean requiresInitialIndexedPredicate() { - return false; - } - - @Override - public GroovyExpression getInitialIndexedPredicate(GroovyExpression expr) { - return expr; - } - - @Override - public GroovyExpression addOutputTransformationPredicate(GroovyExpression expr, boolean inSelect, boolean isPath) { - return expr; - } - - public Iterable<AtlasEdge<Titan0Vertex, Titan0Edge>> wrapEdges(Iterator<Edge> it) { - - Iterable<Edge> iterable = new IteratorToIterableAdapter<>(it); - return wrapEdges(iterable); - } - - public Iterable<AtlasVertex<Titan0Vertex, Titan0Edge>> wrapVertices(Iterator<Vertex> it) { - Iterable<Vertex> iterable = new IteratorToIterableAdapter<>(it); - return wrapVertices(iterable); - } - - public Iterable<AtlasVertex<Titan0Vertex, Titan0Edge>> wrapVertices(Iterable<Vertex> it) { - - return Iterables.transform(it, new Function<Vertex, AtlasVertex<Titan0Vertex, Titan0Edge>>(){ - - @Override - public AtlasVertex<Titan0Vertex, Titan0Edge> apply(Vertex input) { - return GraphDbObjectFactory.createVertex(Titan0Graph.this, input); - } - }); - - } - - public Iterable<AtlasEdge<Titan0Vertex, Titan0Edge>> wrapEdges(Iterable<Edge> it) { - Iterable<Edge> result = it; - return Iterables.transform(result, new Function<Edge, AtlasEdge<Titan0Vertex, Titan0Edge>>(){ - - @Override - public AtlasEdge<Titan0Vertex, Titan0Edge> apply(Edge input) { - return GraphDbObjectFactory.createEdge(Titan0Graph.this, input); - } - }); - } - - @Override - public boolean isMultiProperty(String propertyName) { - return multiProperties.contains(propertyName); - } - - @Override - public void loadLegacyGraphSON(Map<String, String> relationshipCache, InputStream fs) throws AtlasBaseException { - } - - @Override - public MigrationStatus getMigrationStatus() { - return new MigrationStatus(); - } - - public void addMultiProperties(Set<String> names) { - multiProperties.addAll(names); - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphDatabase.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphDatabase.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphDatabase.java deleted file mode 100644 index 5af90d8..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphDatabase.java +++ /dev/null @@ -1,204 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.Map; - -import org.apache.atlas.ApplicationProperties; -import org.apache.atlas.AtlasException; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.atlas.repository.graphdb.GraphDatabase; -import org.apache.commons.configuration.Configuration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.ImmutableMap; -import com.thinkaurelius.titan.core.TitanFactory; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.schema.TitanManagement; -import com.thinkaurelius.titan.core.util.TitanCleanup; -import com.thinkaurelius.titan.diskstorage.StandardIndexProvider; -import com.thinkaurelius.titan.diskstorage.solr.Solr5Index; - -/** - * Titan 0.5.4 implementation of GraphDatabase. - */ -public class Titan0GraphDatabase implements GraphDatabase<Titan0Vertex, Titan0Edge> { - - private static final Logger LOG = LoggerFactory.getLogger(Titan0GraphDatabase.class); - - /** - * Constant for the configuration property that indicates the prefix. - */ - public static final String GRAPH_PREFIX = "atlas.graph"; - - public static final String INDEX_BACKEND_CONF = "index.search.backend"; - - public static final String INDEX_BACKEND_LUCENE = "lucene"; - - public static final String INDEX_BACKEND_ES = "elasticsearch"; - - private static volatile Titan0Graph atlasGraphInstance = null; - private static volatile TitanGraph graphInstance = null; - - public static Configuration getConfiguration() throws AtlasException { - Configuration configProperties = ApplicationProperties.get(); - return ApplicationProperties.getSubsetConfiguration(configProperties, GRAPH_PREFIX); - } - - static { - addSolr5Index(); - } - - /** - * Titan loads index backend name to implementation using - * StandardIndexProvider.ALL_MANAGER_CLASSES But - * StandardIndexProvider.ALL_MANAGER_CLASSES is a private static final - * ImmutableMap Only way to inject Solr5Index is to modify this field. So, - * using hacky reflection to add Sol5Index - */ - private static void addSolr5Index() { - try { - Field field = StandardIndexProvider.class.getDeclaredField("ALL_MANAGER_CLASSES"); - field.setAccessible(true); - - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - - Map<String, String> customMap = new HashMap<>(StandardIndexProvider.getAllProviderClasses()); - customMap.put("solr", Solr5Index.class.getName()); // for - // consistency - // with Titan - // 1.0.0 - customMap.put("solr5", Solr5Index.class.getName()); // for backward - // compatibility - ImmutableMap<String, String> immap = ImmutableMap.copyOf(customMap); - field.set(null, immap); - - LOG.debug("Injected solr5 index - {}", Solr5Index.class.getName()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public static TitanGraph getGraphInstance() { - if (graphInstance == null) { - synchronized (Titan0GraphDatabase.class) { - if (graphInstance == null) { - Configuration config; - try { - config = getConfiguration(); - } catch (AtlasException e) { - throw new RuntimeException(e); - } - - graphInstance = TitanFactory.open(config); - atlasGraphInstance = new Titan0Graph(); - validateIndexBackend(config); - } - } - } - return graphInstance; - } - - public static void unload() { - - synchronized (Titan0GraphDatabase.class) { - if (graphInstance == null) { - return; - } - - graphInstance.commit(); - //shutdown invalidates the graph instance - graphInstance.shutdown(); - graphInstance = null; - } - } - - static void validateIndexBackend(Configuration config) { - String configuredIndexBackend = config.getString(INDEX_BACKEND_CONF); - TitanManagement managementSystem = null; - - try { - managementSystem = getGraphInstance().getManagementSystem(); - String currentIndexBackend = managementSystem.get(INDEX_BACKEND_CONF); - - if (!equals(configuredIndexBackend, currentIndexBackend)) { - throw new RuntimeException("Configured Index Backend " + configuredIndexBackend - + " differs from earlier configured Index Backend " + currentIndexBackend + ". Aborting!"); - } - - } finally { - if (managementSystem != null) { - managementSystem.commit(); - } - } - - - } - - private static boolean equals(Object o1, Object o2) { - if (o1 == null) { - return o2 == null; - } - return o1.equals(o2); - } - - @Override - public AtlasGraph<Titan0Vertex, Titan0Edge> getGraph() { - // force graph loading up front to avoid bootstrapping - // issues - getGraphInstance(); - return atlasGraphInstance; - } - - @Override - public boolean isGraphLoaded() { - return graphInstance != null; - } - - - @Override - public void initializeTestGraph() { - - //nothing to do - } - - @Override - public void cleanup() { - try { - getGraphInstance().shutdown(); - } catch(Throwable t) { - LOG.warn("Could not shutdown test TitanGraph", t); - t.printStackTrace(); - } - - try { - TitanCleanup.clear(getGraphInstance()); - } catch(Throwable t) { - LOG.warn("Could not clear test TitanGraph", t); - t.printStackTrace(); - } - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphIndex.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphIndex.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphIndex.java deleted file mode 100644 index 3d4152e..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphIndex.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import java.util.HashSet; -import java.util.Set; - -import org.apache.atlas.repository.graphdb.AtlasGraphIndex; -import org.apache.atlas.repository.graphdb.AtlasPropertyKey; - -import com.thinkaurelius.titan.core.PropertyKey; -import com.thinkaurelius.titan.core.schema.TitanGraphIndex; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; - -/** - * Titan 0.5.4 implementation of AtlasGraphIndex. - */ -public class Titan0GraphIndex implements AtlasGraphIndex { - - private TitanGraphIndex wrappedIndex; - - public Titan0GraphIndex(TitanGraphIndex toWrap) { - wrappedIndex = toWrap; - } - - /* (non-Javadoc) - * @see org.apache.atlas.repository.graphdb.AtlasGraphIndex#isMixedIndex() - */ - @Override - public boolean isMixedIndex() { - return wrappedIndex.isMixedIndex(); - } - - /* (non-Javadoc) - * @see org.apache.atlas.repository.graphdb.AtlasGraphIndex#isEdgeIndex() - */ - @Override - public boolean isEdgeIndex() { - return Edge.class.isAssignableFrom(wrappedIndex.getIndexedElement()); - } - - /* (non-Javadoc) - * @see org.apache.atlas.repository.graphdb.AtlasGraphIndex#isVertexIndex() - */ - @Override - public boolean isVertexIndex() { - return Vertex.class.isAssignableFrom(wrappedIndex.getIndexedElement()); - } - - /* (non-Javadoc) - * @see org.apache.atlas.repository.graphdb.AtlasGraphIndex#isCompositeIndex() - */ - @Override - public boolean isCompositeIndex() { - return wrappedIndex.isCompositeIndex(); - } - - /* (non-Javadoc) - * @see org.apache.atlas.repository.graphdb.AtlasGraphIndex#isUnique() - */ - @Override - public boolean isUnique() { - return wrappedIndex.isUnique(); - } - - /* (non-Javadoc) - * @see org.apache.atlas.repository.graphdb.AtlasGraphIndex#getFieldKeys() - */ - @Override - public Set<AtlasPropertyKey> getFieldKeys() { - PropertyKey[] keys = wrappedIndex.getFieldKeys(); - Set<AtlasPropertyKey> result = new HashSet<>(); - for(PropertyKey key : keys) { - result.add(GraphDbObjectFactory.createPropertyKey(key)); - } - return result; - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphManagement.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphManagement.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphManagement.java deleted file mode 100644 index fadd596..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0GraphManagement.java +++ /dev/null @@ -1,225 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import com.thinkaurelius.titan.core.Cardinality; -import com.thinkaurelius.titan.core.EdgeLabel; -import com.thinkaurelius.titan.core.PropertyKey; -import com.thinkaurelius.titan.core.schema.PropertyKeyMaker; -import com.thinkaurelius.titan.core.schema.TitanGraphIndex; -import com.thinkaurelius.titan.core.schema.TitanManagement; -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Element; -import com.tinkerpop.blueprints.Vertex; -import org.apache.atlas.repository.graphdb.AtlasCardinality; -import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; -import org.apache.atlas.repository.graphdb.AtlasEdgeLabel; -import org.apache.atlas.repository.graphdb.AtlasGraphIndex; -import org.apache.atlas.repository.graphdb.AtlasGraphManagement; -import org.apache.atlas.repository.graphdb.AtlasPropertyKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Titan 0.5.4 implementation of AtlasGraphManagement. - */ -public class Titan0GraphManagement implements AtlasGraphManagement { - - private static final Logger LOG = LoggerFactory.getLogger(Titan0GraphManagement.class); - - private final Titan0Graph graph; - private final TitanManagement management; - - private Set<String> newMultProperties = new HashSet<>(); - - public Titan0GraphManagement(Titan0Graph graph, TitanManagement managementSystem) { - - this.graph = graph; - management = managementSystem; - } - - @Override - public void createEdgeMixedIndex(String index, String backingIndex, List<AtlasPropertyKey> propertyKeys) { - } - - @Override - public void createEdgeIndex(String label, String indexName, AtlasEdgeDirection edgeDirection, List<AtlasPropertyKey> propertyKeys) { - EdgeLabel edgeLabel = management.getEdgeLabel(label); - - if (edgeLabel == null) { - edgeLabel = management.makeEdgeLabel(label).make(); - } - - Direction direction = TitanObjectFactory.createDirection(edgeDirection); - PropertyKey[] keys = TitanObjectFactory.createPropertyKeys(propertyKeys); - - management.buildEdgeIndex(edgeLabel, indexName, direction, keys); - } - - @Override - public void createFullTextMixedIndex(String index, String backingIndex, List<AtlasPropertyKey> propertyKeys) { - } - - private void buildMixedIndex(String index, Class<? extends Element> titanClass, String backingIndex) { - - management.buildIndex(index, titanClass).buildMixedIndex(backingIndex); - } - - @Override - public boolean containsPropertyKey(String propertyKey) { - return management.containsPropertyKey(propertyKey); - } - - @Override - public void rollback() { - management.rollback(); - - } - - @Override - public void commit() { - graph.addMultiProperties(newMultProperties); - newMultProperties.clear(); - management.commit(); - } - - @Override - public AtlasPropertyKey makePropertyKey(String propertyName, Class propertyClass, AtlasCardinality cardinality) { - - if (cardinality.isMany()) { - newMultProperties.add(propertyName); - } - - PropertyKeyMaker propertyKeyBuilder = management.makePropertyKey(propertyName).dataType(propertyClass); - - if (cardinality != null) { - Cardinality titanCardinality = TitanObjectFactory.createCardinality(cardinality); - propertyKeyBuilder.cardinality(titanCardinality); - } - PropertyKey propertyKey = propertyKeyBuilder.make(); - return GraphDbObjectFactory.createPropertyKey(propertyKey); - } - - @Override - public AtlasEdgeLabel makeEdgeLabel(String label) { - EdgeLabel edgeLabel = management.makeEdgeLabel(label).make(); - - return GraphDbObjectFactory.createEdgeLabel(edgeLabel); - } - - @Override - public void deletePropertyKey(String propertyKey) { - PropertyKey titanPropertyKey = management.getPropertyKey(propertyKey); - - if (null == titanPropertyKey) return; - - for (int i = 0;; i++) { - String deletedKeyName = titanPropertyKey + "_deleted_" + i; - if (null == management.getPropertyKey(deletedKeyName)) { - management.changeName(titanPropertyKey, deletedKeyName); - break; - } - } - } - - @Override - public AtlasPropertyKey getPropertyKey(String propertyName) { - - return GraphDbObjectFactory.createPropertyKey(management.getPropertyKey(propertyName)); - } - - @Override - public AtlasEdgeLabel getEdgeLabel(String label) { - return GraphDbObjectFactory.createEdgeLabel(management.getEdgeLabel(label)); - } - - @Override - public void createVertexCompositeIndex(String propertyName, boolean enforceUniqueness, - List<AtlasPropertyKey> propertyKeys) { - - TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class); - for(AtlasPropertyKey key : propertyKeys) { - PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key); - indexBuilder.addKey(titanKey); - } - if (enforceUniqueness) { - indexBuilder.unique(); - } - indexBuilder.buildCompositeIndex(); - } - - @Override - public void createEdgeCompositeIndex(String propertyName, boolean isUnique, List<AtlasPropertyKey> propertyKeys) { - TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Edge.class); - - for(AtlasPropertyKey key : propertyKeys) { - PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key); - indexBuilder.addKey(titanKey); - } - - if (isUnique) { - indexBuilder.unique(); - } - - indexBuilder.buildCompositeIndex(); - } - - @Override - public void createVertexMixedIndex(String propertyName, String backingIndex, List<AtlasPropertyKey> propertyKeys) { - - TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class); - for(AtlasPropertyKey key : propertyKeys) { - PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key); - indexBuilder.addKey(titanKey); - } - indexBuilder.buildMixedIndex(backingIndex); - } - - - @Override - public void addMixedIndex(String indexName, AtlasPropertyKey propertyKey) { - PropertyKey titanKey = TitanObjectFactory.createPropertyKey(propertyKey); - TitanGraphIndex vertexIndex = management.getGraphIndex(indexName); - management.addIndexKey(vertexIndex, titanKey); - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.atlas.repository.graphdb.AtlasGraphManagement#getGraphIndex( - * java.lang.String) - */ - @Override - public AtlasGraphIndex getGraphIndex(String indexName) { - TitanGraphIndex index = management.getGraphIndex(indexName); - return GraphDbObjectFactory.createGraphIndex(index); - } - - @Override - public boolean edgeIndexExist(String label, String indexName) { - EdgeLabel edgeLabel = management.getEdgeLabel(label); - - return edgeLabel != null && management.getRelationIndex(edgeLabel, indexName) != null; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0IndexQuery.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0IndexQuery.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0IndexQuery.java deleted file mode 100644 index c4a312d..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0IndexQuery.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import java.util.Iterator; - -import com.google.common.base.Preconditions; -import org.apache.atlas.repository.graphdb.AtlasIndexQuery; -import org.apache.atlas.repository.graphdb.AtlasVertex; - -import com.google.common.base.Function; -import com.google.common.collect.Iterators; -import com.thinkaurelius.titan.core.TitanIndexQuery; -import com.tinkerpop.blueprints.Vertex; - -/** - * Titan 0.5.4 implementation of AtlasIndexQuery. - */ -public class Titan0IndexQuery implements AtlasIndexQuery<Titan0Vertex, Titan0Edge> { - - private Titan0Graph graph; - private TitanIndexQuery wrappedIndexQuery; - - - public Titan0IndexQuery(Titan0Graph graph, TitanIndexQuery query) { - wrappedIndexQuery = query; - this.graph = graph; - } - - @Override - public Iterator<AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge>> vertices() { - Iterator<TitanIndexQuery.Result<Vertex>> results = wrappedIndexQuery.vertices().iterator(); - - Function<TitanIndexQuery.Result<Vertex>, AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge>> function = - new Function<TitanIndexQuery.Result<Vertex>, AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge>>() { - - @Override - public AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge> apply(TitanIndexQuery.Result<Vertex> source) { - return new ResultImpl(source); - } - }; - return Iterators.transform(results, function); - } - - @Override - public Iterator<Result<Titan0Vertex, Titan0Edge>> vertices(int offset, int limit) { - Preconditions.checkArgument(offset >=0, "Index offset should be greater than or equals to 0"); - Preconditions.checkArgument(limit >=0, "Index limit should be greater than or equals to 0"); - Iterator<TitanIndexQuery.Result<Vertex>> results = wrappedIndexQuery - .offset(offset) - .limit(limit) - .vertices().iterator(); - - Function<TitanIndexQuery.Result<Vertex>, AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge>> function = - new Function<TitanIndexQuery.Result<Vertex>, AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge>>() { - - @Override - public AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge> apply(TitanIndexQuery.Result<Vertex> source) { - return new ResultImpl(source); - } - }; - return Iterators.transform(results, function); - } - - private final class ResultImpl implements AtlasIndexQuery.Result<Titan0Vertex, Titan0Edge> { - private TitanIndexQuery.Result<Vertex> wrappedResult; - - ResultImpl(TitanIndexQuery.Result<Vertex> source) { - wrappedResult = source; - } - - @Override - public AtlasVertex<Titan0Vertex, Titan0Edge> getVertex() { - return GraphDbObjectFactory.createVertex(graph, wrappedResult.getElement()); - } - - @Override - public double getScore() { - return wrappedResult.getScore(); - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0PropertyKey.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0PropertyKey.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0PropertyKey.java deleted file mode 100644 index d6707bd..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0PropertyKey.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import org.apache.atlas.repository.graphdb.AtlasCardinality; -import org.apache.atlas.repository.graphdb.AtlasPropertyKey; - -import com.thinkaurelius.titan.core.PropertyKey; - -/** - * Titan 0.5.4 implementaiton of AtlasPropertyKey. - */ -public class Titan0PropertyKey implements AtlasPropertyKey { - - private PropertyKey wrappedPropertyKey; - - public Titan0PropertyKey(PropertyKey toWrap) { - wrappedPropertyKey = toWrap; - } - - /* - * (non-Javadoc) - * - * @see org.apache.atlas.repository.graphdb.AtlasPropertyKey#getName() - */ - @Override - public String getName() { - return wrappedPropertyKey.getName(); - } - - /** - * @return - */ - public PropertyKey getWrappedPropertyKey() { - return wrappedPropertyKey; - } - - @Override - public AtlasCardinality getCardinality() { - return GraphDbObjectFactory.createCardinality(wrappedPropertyKey.getCardinality()); - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof Titan0PropertyKey)) { - return false; - } - Titan0PropertyKey otherKey = (Titan0PropertyKey) other; - return wrappedPropertyKey.equals(otherKey.wrappedPropertyKey); - } - - @Override - public int hashCode() { - int result = 17; - result = 37 * result + wrappedPropertyKey.hashCode(); - return result; - } - - @Override - public String toString() { - return wrappedPropertyKey.getName(); - } - - - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Vertex.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Vertex.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Vertex.java deleted file mode 100644 index e439ab9..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0Vertex.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import java.util.ArrayList; -import java.util.Collection; - -import org.apache.atlas.repository.graphdb.AtlasEdge; -import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; -import org.apache.atlas.repository.graphdb.AtlasSchemaViolationException; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.repository.graphdb.AtlasVertexQuery; - -import com.thinkaurelius.titan.core.SchemaViolationException; -import com.thinkaurelius.titan.core.TitanProperty; -import com.thinkaurelius.titan.core.TitanVertex; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; - -/** - * Titan 0.5.4 implementation of AtlasVertex. - */ -public class Titan0Vertex extends Titan0Element<Vertex> implements AtlasVertex<Titan0Vertex, Titan0Edge> { - - public Titan0Vertex(Titan0Graph graph, Vertex source) { - super(graph, source); - } - - @Override - public Iterable<AtlasEdge<Titan0Vertex, Titan0Edge>> getEdges(AtlasEdgeDirection dir, String edgeLabel) { - Iterable<Edge> titanEdges = wrappedElement.getEdges(TitanObjectFactory.createDirection(dir), edgeLabel); - return graph.wrapEdges(titanEdges); - } - - private TitanVertex getAsTitanVertex() { - return (TitanVertex) wrappedElement; - } - - @Override - public Iterable<AtlasEdge<Titan0Vertex, Titan0Edge>> getEdges(AtlasEdgeDirection in) { - Iterable<Edge> titanResult = wrappedElement.getEdges(TitanObjectFactory.createDirection(in)); - return graph.wrapEdges(titanResult); - - } - - @Override - public <T> T getProperty(String propertyName, Class<T> clazz) { - - if (graph.isMultiProperty(propertyName)) { - // throw exception in this case to be consistent with Titan 1.0.0 - // behavior. - throw new IllegalStateException(); - } - return super.getProperty(propertyName, clazz); - } - - public <T> void setProperty(String propertyName, T value) { - - try { - super.setProperty(propertyName, value); - } catch (UnsupportedOperationException e) { - // For consistency with Titan 1.0.0, treat sets of multiplicity many - // properties as adds. Handle this here since this is an uncommon - // occurrence. - if (graph.isMultiProperty(propertyName)) { - addProperty(propertyName, value); - } else { - throw e; - } - } - } - - @Override - public <T> void addProperty(String propertyName, T value) { - try { - getAsTitanVertex().addProperty(propertyName, value); - } catch (SchemaViolationException e) { - if (getPropertyValues(propertyName, value.getClass()).contains(value)) { - // follow java set semantics, don't throw an exception if - // value is already there. - return; - } - throw new AtlasSchemaViolationException(e); - } - } - - @Override - public <T> void addListProperty(String propertyName, T value) { - try { - getAsTitanVertex().addProperty(propertyName, value); - } catch (SchemaViolationException e) { - if (getPropertyValues(propertyName, value.getClass()).contains(value)) { - // follow java set semantics, don't throw an exception if - // value is already there. - return; - } - throw new AtlasSchemaViolationException(e); - } - } - - @Override - public <T> Collection<T> getPropertyValues(String key, Class<T> clazz) { - - TitanVertex tv = getAsTitanVertex(); - Collection<T> result = new ArrayList<>(); - for (TitanProperty property : tv.getProperties(key)) { - result.add((T) property.getValue()); - } - return result; - } - - @Override - public AtlasVertexQuery<Titan0Vertex, Titan0Edge> query() { - return new Titan0VertexQuery(graph, wrappedElement.query()); - } - - @Override - public Titan0Vertex getV() { - - return this; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "Titan0Vertex [id=" + getId() + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0VertexQuery.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0VertexQuery.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0VertexQuery.java deleted file mode 100644 index 39e9d6d..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/Titan0VertexQuery.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import com.google.common.base.Preconditions; -import org.apache.atlas.repository.graphdb.AtlasEdge; -import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.repository.graphdb.AtlasVertexQuery; - -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.VertexQuery; - -/** - * Titan 0.5.4 implementation of AtlasVertexQuery. - */ -public class Titan0VertexQuery implements AtlasVertexQuery<Titan0Vertex, Titan0Edge> { - - private Titan0Graph graph; - private VertexQuery vertexQuery; - - public Titan0VertexQuery(Titan0Graph graph, VertexQuery vertexQuery) { - this.vertexQuery = vertexQuery; - this.graph = graph; - } - - @Override - public AtlasVertexQuery<Titan0Vertex, Titan0Edge> direction(AtlasEdgeDirection queryDirection) { - vertexQuery.direction(TitanObjectFactory.createDirection(queryDirection)); - return this; - - } - - @Override - public Iterable<AtlasVertex<Titan0Vertex, Titan0Edge>> vertices() { - Iterable<Vertex> vertices = vertexQuery.vertices(); - return graph.wrapVertices(vertices); - } - - @Override - public Iterable<AtlasVertex<Titan0Vertex, Titan0Edge>> vertices(int limit) { - Preconditions.checkArgument(limit >=0, "Limit should be greater than or equals to 0"); - Iterable<Vertex> vertices = vertexQuery.limit(limit).vertices(); - return graph.wrapVertices(vertices); - } - - @Override - public Iterable<AtlasEdge<Titan0Vertex, Titan0Edge>> edges() { - Iterable<Edge> edges = vertexQuery.edges(); - return graph.wrapEdges(edges); - } - - @Override - public Iterable<AtlasEdge<Titan0Vertex, Titan0Edge>> edges(int limit) { - Preconditions.checkArgument(limit >=0, "Limit should be greater than or equals to 0"); - Iterable<Edge> edges = vertexQuery.limit(limit).edges(); - return graph.wrapEdges(edges); - } - - @Override - public long count() { - return vertexQuery.count(); - } - - @Override - public AtlasVertexQuery<Titan0Vertex, Titan0Edge> label(String label) { - vertexQuery.labels(label); - return this; - } - - @Override - public AtlasVertexQuery<Titan0Vertex, Titan0Edge> has(String key, Object value) { - vertexQuery.has(key, value); - return this; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/TitanObjectFactory.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/TitanObjectFactory.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/TitanObjectFactory.java deleted file mode 100644 index b7c25b8..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/TitanObjectFactory.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0; - -import org.apache.atlas.repository.graphdb.AtlasCardinality; -import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; -import org.apache.atlas.repository.graphdb.AtlasPropertyKey; - -import com.thinkaurelius.titan.core.Cardinality; -import com.thinkaurelius.titan.core.PropertyKey; -import com.tinkerpop.blueprints.Direction; - -import java.util.ArrayList; -import java.util.List; - -/** - * Factory that serves up instances of Titan/Tinkerpop classes that correspond to - * graph database abstraction layer/Atlas classes. - */ -public final class TitanObjectFactory { - - private TitanObjectFactory() { - - } - - /** - * Retrieves the titan direction corresponding to the given - * AtlasEdgeDirection. - * - * @param dir - * @return - */ - public static Direction createDirection(AtlasEdgeDirection dir) { - - switch(dir) { - case IN: - return Direction.IN; - case OUT: - return Direction.OUT; - case BOTH: - return Direction.BOTH; - default: - throw new RuntimeException("Unrecognized direction: " + dir); - } - } - - - /** - * Converts a Multiplicity to a Cardinality. - * - * @param cardinality - * @return - */ - public static Cardinality createCardinality(AtlasCardinality cardinality) { - switch(cardinality) { - - case SINGLE: - return Cardinality.SINGLE; - case LIST: - return Cardinality.LIST; - case SET: - return Cardinality.SET; - default: - throw new IllegalStateException("Unrecognized cardinality: " + cardinality); - } - } - - public static PropertyKey createPropertyKey(AtlasPropertyKey key) { - return ((Titan0PropertyKey)key).getWrappedPropertyKey(); - } - - public static PropertyKey[] createPropertyKeys(List<AtlasPropertyKey> keys) { - PropertyKey[] ret = new PropertyKey[keys.size()]; - - int i = 0; - for (AtlasPropertyKey key : keys) { - ret[i] = createPropertyKey(key); - - i++; - } - - return ret; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/query/NativeTitan0GraphQuery.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/query/NativeTitan0GraphQuery.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/query/NativeTitan0GraphQuery.java deleted file mode 100644 index 68a7048..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/query/NativeTitan0GraphQuery.java +++ /dev/null @@ -1,175 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0.query; - -import com.thinkaurelius.titan.core.Order; -import com.thinkaurelius.titan.core.TitanGraphQuery; -import com.thinkaurelius.titan.core.attribute.Contain; -import com.thinkaurelius.titan.core.attribute.Text; -import com.thinkaurelius.titan.graphdb.query.TitanPredicate; -import com.tinkerpop.blueprints.Compare; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Vertex; -import org.apache.atlas.repository.graphdb.AtlasEdge; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery.ComparisionOperator; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery.MatchingOperator; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery.QueryOperator; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.repository.graphdb.tinkerpop.query.NativeTinkerpopGraphQuery; -import org.apache.atlas.repository.graphdb.titan0.Titan0Edge; -import org.apache.atlas.repository.graphdb.titan0.Titan0Graph; -import org.apache.atlas.repository.graphdb.titan0.Titan0GraphDatabase; -import org.apache.atlas.repository.graphdb.titan0.Titan0Vertex; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/** - * Titan 0.5.4 implementation of NativeTitanGraphQuery. - * - * @author jeff - * - */ -public class NativeTitan0GraphQuery implements NativeTinkerpopGraphQuery<Titan0Vertex, Titan0Edge> { - - private Titan0Graph graph; - private TitanGraphQuery<?> query; - - public NativeTitan0GraphQuery(Titan0Graph graph) { - query = Titan0GraphDatabase.getGraphInstance().query(); - this.graph = graph; - } - - @Override - public Iterable<AtlasVertex<Titan0Vertex, Titan0Edge>> vertices() { - Iterable it = query.vertices(); - return graph.wrapVertices(it); - } - - @Override - public Iterable<AtlasEdge<Titan0Vertex, Titan0Edge>> edges() { - Iterable it = query.edges(); - return graph.wrapEdges(it); - } - - @Override - public Iterable<AtlasEdge<Titan0Vertex, Titan0Edge>> edges(int limit) { - Iterable it = query.limit(limit).edges(); - return graph.wrapEdges(it); - } - - @Override - public Iterable<AtlasEdge<Titan0Vertex, Titan0Edge>> edges(int offset, int limit) { - List<Edge> result = new ArrayList<>(limit); - Iterator<Edge> iter = query.limit(offset + limit).edges().iterator(); - - for (long resultIdx = 0; iter.hasNext() && result.size() < limit; resultIdx++) { - if (resultIdx < offset) { - continue; - } - - result.add(iter.next()); - } - - return graph.wrapEdges(result); - } - - @Override - public Iterable<AtlasVertex<Titan0Vertex, Titan0Edge>> vertices(int limit) { - Iterable it = query.limit(limit).vertices(); - return graph.wrapVertices(it); - } - - @Override - public Iterable<AtlasVertex<Titan0Vertex, Titan0Edge>> vertices(int offset, int limit) { - List<Vertex> result = new ArrayList<>(limit); - Iterator<Vertex> iter = query.limit(offset + limit).vertices().iterator(); - - for (long resultIdx = 0; iter.hasNext() && result.size() < limit; resultIdx++) { - if (resultIdx < offset) { - continue; - } - - result.add(iter.next()); - } - - return graph.wrapVertices(result); - } - - - @Override - public void in(String propertyName, Collection<?> values) { - query.has(propertyName, Contain.IN, values); - - } - - @Override - public void has(String propertyName, QueryOperator op, Object value) { - TitanPredicate pred; - if (op instanceof ComparisionOperator) { - Compare c = getGremlinPredicate((ComparisionOperator) op); - pred = TitanPredicate.Converter.convert(c); - } else { - pred = getGremlinPredicate((MatchingOperator) op); - } - query.has(propertyName, pred, value); - } - - @Override - public void orderBy(final String propertyName, final AtlasGraphQuery.SortOrder sortOrder) { - query.orderBy(propertyName, sortOrder == AtlasGraphQuery.SortOrder.ASC ? Order.ASC : Order.DESC); - } - - private Text getGremlinPredicate(MatchingOperator op) { - switch (op) { - case CONTAINS: - return Text.CONTAINS; - case PREFIX: - return Text.PREFIX; - case SUFFIX: - return Text.CONTAINS_REGEX; - case REGEX: - return Text.REGEX; - default: - throw new RuntimeException("Unsupported matching operator:" + op); - } - } - - private Compare getGremlinPredicate(ComparisionOperator op) { - switch (op) { - case EQUAL: - return Compare.EQUAL; - case GREATER_THAN: - return Compare.GREATER_THAN; - case GREATER_THAN_EQUAL: - return Compare.GREATER_THAN_EQUAL; - case LESS_THAN: - return Compare.LESS_THAN; - case LESS_THAN_EQUAL: - return Compare.LESS_THAN_EQUAL; - case NOT_EQUAL: - return Compare.NOT_EQUAL; - default: - throw new RuntimeException("Unsupported comparison operator:" + op); - } - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/effb7537/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/query/Titan0GraphQuery.java ---------------------------------------------------------------------- diff --git a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/query/Titan0GraphQuery.java b/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/query/Titan0GraphQuery.java deleted file mode 100644 index 234e521..0000000 --- a/graphdb/titan0/src/main/java/org/apache/atlas/repository/graphdb/titan0/query/Titan0GraphQuery.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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.atlas.repository.graphdb.titan0.query; - -import org.apache.atlas.repository.graphdb.AtlasGraphQuery; -import org.apache.atlas.repository.graphdb.tinkerpop.query.TinkerpopGraphQuery; -import org.apache.atlas.repository.graphdb.tinkerpop.query.NativeTinkerpopGraphQuery; -import org.apache.atlas.repository.graphdb.tinkerpop.query.NativeTinkerpopQueryFactory; -import org.apache.atlas.repository.graphdb.titan0.Titan0Edge; -import org.apache.atlas.repository.graphdb.titan0.Titan0Graph; -import org.apache.atlas.repository.graphdb.titan0.Titan0Vertex; - -/** - * Titan 0.5.4 implementation of AtlasGraphQuery. - */ -public class Titan0GraphQuery extends TinkerpopGraphQuery<Titan0Vertex, Titan0Edge> - implements NativeTinkerpopQueryFactory<Titan0Vertex, Titan0Edge> { - - public Titan0GraphQuery(Titan0Graph graph, boolean isChildQuery) { - super(graph, isChildQuery); - } - - public Titan0GraphQuery(Titan0Graph graph) { - super(graph); - } - - @Override - public AtlasGraphQuery<Titan0Vertex, Titan0Edge> createChildQuery() { - return new Titan0GraphQuery((Titan0Graph)graph, true); - } - - @Override - protected NativeTinkerpopQueryFactory<Titan0Vertex, Titan0Edge> getQueryFactory() { - return this; - } - - - @Override - public NativeTinkerpopGraphQuery<Titan0Vertex, Titan0Edge> createNativeTinkerpopQuery() { - return new NativeTitan0GraphQuery((Titan0Graph)graph); - } -}
