http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/Titan1VertexQuery.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/Titan1VertexQuery.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/Titan1VertexQuery.java deleted file mode 100644 index a761a74..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/Titan1VertexQuery.java +++ /dev/null @@ -1,80 +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.titan1; - -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.thinkaurelius.titan.core.TitanVertexQuery; - -/** - * Titan 1.0.0 implementation of AtlasVertexQuery. - */ -public class Titan1VertexQuery implements AtlasVertexQuery<Titan1Vertex, Titan1Edge> { - - private Titan1Graph graph; - private TitanVertexQuery<?> query; - - public Titan1VertexQuery(Titan1Graph graph, TitanVertexQuery<?> query) { - this.query = query; - this.graph = graph; - } - - @Override - public AtlasVertexQuery<Titan1Vertex, Titan1Edge> direction(AtlasEdgeDirection queryDirection) { - query.direction(TitanObjectFactory.createDirection(queryDirection)); - return this; - - } - - @Override - public Iterable<AtlasVertex<Titan1Vertex, Titan1Edge>> vertices() { - Iterable vertices = query.vertices(); - return graph.wrapVertices(vertices); - } - - @Override - public Iterable<AtlasVertex<Titan1Vertex, Titan1Edge>> vertices(int limit) { - Preconditions.checkArgument(limit >=0, "Limit should be greater than or equals to 0"); - Iterable vertices = query.limit(limit).vertices(); - return graph.wrapVertices(vertices); - } - - @Override - public Iterable<AtlasEdge<Titan1Vertex, Titan1Edge>> edges() { - Iterable edges = query.edges(); - return graph.wrapEdges(edges); - } - - @Override - public Iterable<AtlasEdge<Titan1Vertex, Titan1Edge>> edges(int limit) { - Preconditions.checkArgument(limit >=0, "Limit should be greater than or equals to 0"); - Iterable edges = query.limit(limit).edges(); - return graph.wrapEdges(edges); - } - - @Override - public long count() { - return query.count(); - } - - -}
http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/TitanObjectFactory.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/TitanObjectFactory.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/TitanObjectFactory.java deleted file mode 100644 index a4776a9..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/TitanObjectFactory.java +++ /dev/null @@ -1,85 +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.titan1; - -import org.apache.atlas.repository.graphdb.AtlasCardinality; -import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; -import org.apache.atlas.repository.graphdb.AtlasPropertyKey; -import org.apache.tinkerpop.gremlin.structure.Direction; - -import com.thinkaurelius.titan.core.Cardinality; -import com.thinkaurelius.titan.core.PropertyKey; - - -/** - * 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 multiplicity - * @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 ((Titan1PropertyKey)key).getWrappedPropertyKey(); - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasElementPropertyConfig.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasElementPropertyConfig.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasElementPropertyConfig.java deleted file mode 100644 index df67a83..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasElementPropertyConfig.java +++ /dev/null @@ -1,136 +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.titan1.graphson; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * Configure how the GraphSON utility treats edge and vertex properties. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class AtlasElementPropertyConfig { - - /** - * Rules for element properties. - */ - public enum ElementPropertiesRule { - INCLUDE, EXCLUDE - } - - private final List<String> vertexPropertyKeys; - private final List<String> edgePropertyKeys; - private final ElementPropertiesRule vertexPropertiesRule; - private final ElementPropertiesRule edgePropertiesRule; - private final boolean normalized; - - /** - * A configuration that includes all properties of vertices and edges. - */ - public static final AtlasElementPropertyConfig ALL_PROPERTIES = new AtlasElementPropertyConfig(null, null, - ElementPropertiesRule.INCLUDE, ElementPropertiesRule.INCLUDE, false); - - public AtlasElementPropertyConfig(final Set<String> vertexPropertyKeys, final Set<String> edgePropertyKeys, - final ElementPropertiesRule vertexPropertiesRule, final ElementPropertiesRule edgePropertiesRule) { - this(vertexPropertyKeys, edgePropertyKeys, vertexPropertiesRule, edgePropertiesRule, false); - } - - public AtlasElementPropertyConfig(final Set<String> vertexPropertyKeys, final Set<String> edgePropertyKeys, - final ElementPropertiesRule vertexPropertiesRule, final ElementPropertiesRule edgePropertiesRule, - final boolean normalized) { - this.vertexPropertiesRule = vertexPropertiesRule; - this.vertexPropertyKeys = sortKeys(vertexPropertyKeys, normalized); - this.edgePropertiesRule = edgePropertiesRule; - this.edgePropertyKeys = sortKeys(edgePropertyKeys, normalized); - this.normalized = normalized; - } - - /** - * Construct a configuration that includes the specified properties from - * both vertices and edges. - */ - public static AtlasElementPropertyConfig includeProperties(final Set<String> vertexPropertyKeys, - final Set<String> edgePropertyKeys) { - return new AtlasElementPropertyConfig(vertexPropertyKeys, edgePropertyKeys, ElementPropertiesRule.INCLUDE, - ElementPropertiesRule.INCLUDE); - } - - public static AtlasElementPropertyConfig includeProperties(final Set<String> vertexPropertyKeys, - final Set<String> edgePropertyKeys, - final boolean normalized) { - return new AtlasElementPropertyConfig(vertexPropertyKeys, edgePropertyKeys, ElementPropertiesRule.INCLUDE, - ElementPropertiesRule.INCLUDE, normalized); - } - - /** - * Construct a configuration that excludes the specified properties from - * both vertices and edges. - */ - public static AtlasElementPropertyConfig excludeProperties(final Set<String> vertexPropertyKeys, - final Set<String> edgePropertyKeys) { - return new AtlasElementPropertyConfig(vertexPropertyKeys, edgePropertyKeys, ElementPropertiesRule.EXCLUDE, - ElementPropertiesRule.EXCLUDE); - } - - public static AtlasElementPropertyConfig excludeProperties(final Set<String> vertexPropertyKeys, - final Set<String> edgePropertyKeys, - final boolean normalized) { - return new AtlasElementPropertyConfig(vertexPropertyKeys, edgePropertyKeys, ElementPropertiesRule.EXCLUDE, - ElementPropertiesRule.EXCLUDE, normalized); - } - - public List<String> getVertexPropertyKeys() { - return vertexPropertyKeys; - } - - public List<String> getEdgePropertyKeys() { - return edgePropertyKeys; - } - - public ElementPropertiesRule getVertexPropertiesRule() { - return vertexPropertiesRule; - } - - public ElementPropertiesRule getEdgePropertiesRule() { - return edgePropertiesRule; - } - - public boolean isNormalized() { - return normalized; - } - - private static List<String> sortKeys(final Set<String> keys, final boolean normalized) { - final List<String> propertyKeyList; - if (keys != null) { - if (normalized) { - final List<String> sorted = new ArrayList<String>(keys); - Collections.sort(sorted); - propertyKeyList = sorted; - } else { - propertyKeyList = new ArrayList<String>(keys); - } - } else { - propertyKeyList = null; - } - - return propertyKeyList; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONMode.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONMode.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONMode.java deleted file mode 100644 index 2bab287..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONMode.java +++ /dev/null @@ -1,43 +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.titan1.graphson; - -/** - * Modes of operation of the GraphSONUtility. - * - * @author Stephen Mallette - */ -public enum AtlasGraphSONMode { - /** - * COMPACT constructs GraphSON on the assumption that all property keys - * are fair game for exclusion including _type, _inV, _outV, _label and _id. - * It is possible to write GraphSON that cannot be read back into Graph, - * if some or all of these keys are excluded. - */ - COMPACT, - - /** - * NORMAL includes the _type field and JSON data typing. - */ - NORMAL, - - /** - * EXTENDED includes the _type field and explicit data typing. - */ - EXTENDED -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONTokens.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONTokens.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONTokens.java deleted file mode 100644 index 49bbdb4..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONTokens.java +++ /dev/null @@ -1,51 +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.titan1.graphson; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public final class AtlasGraphSONTokens { - - private AtlasGraphSONTokens() {} - - public static final String VERTEX = "vertex"; - public static final String EDGE = "edge"; - public static final String INTERNAL_ID = "_id"; - public static final String INTERNAL_LABEL = "_label"; - public static final String INTERNAL_TYPE = "_type"; - public static final String INTERNAL_OUT_V = "_outV"; - public static final String INTERNAL_IN_V = "_inV"; - public static final String VALUE = "value"; - public static final String TYPE = "type"; - public static final String TYPE_LIST = "list"; - public static final String TYPE_STRING = "string"; - public static final String TYPE_DOUBLE = "double"; - public static final String TYPE_INTEGER = "integer"; - public static final String TYPE_FLOAT = "float"; - public static final String TYPE_MAP = "map"; - public static final String TYPE_BOOLEAN = "boolean"; - public static final String TYPE_LONG = "long"; - public static final String TYPE_SHORT = "short"; - public static final String TYPE_BYTE = "byte"; - public static final String TYPE_UNKNOWN = "unknown"; - - public static final String VERTICES = "vertices"; - public static final String EDGES = "edges"; - public static final String MODE = "mode"; -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONUtility.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONUtility.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONUtility.java deleted file mode 100644 index 26abe2e..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/graphson/AtlasGraphSONUtility.java +++ /dev/null @@ -1,513 +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.titan1.graphson; - -import java.io.IOException; -import java.lang.reflect.Array; -import java.util.ArrayList; -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; - -import org.apache.atlas.repository.graphdb.AtlasEdge; -import org.apache.atlas.repository.graphdb.AtlasElement; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.repository.graphdb.titan1.graphson.AtlasElementPropertyConfig.ElementPropertiesRule; -import org.codehaus.jettison.json.JSONException; -import org.codehaus.jettison.json.JSONObject; -import org.codehaus.jettison.json.JSONTokener; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * This class was largely removed from tinkerpop 1. We're adding it back here to - * avoid changing the format of the JSON that we produce. - * - * Helps write individual graph elements to TinkerPop JSON format known as - * GraphSON. - * - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public final class AtlasGraphSONUtility { - - private static final JsonNodeFactory JSON_NODE_FACTORY = JsonNodeFactory.instance; - - private static final ObjectMapper MAPPER = new ObjectMapper(); - - private final AtlasGraphSONMode mode; - private final List<String> vertexPropertyKeys; - private final List<String> edgePropertyKeys; - - private final ElementPropertiesRule vertexPropertiesRule; - private final ElementPropertiesRule edgePropertiesRule; - private final boolean normalized; - - private final boolean includeReservedVertexId; - private final boolean includeReservedEdgeId; - private final boolean includeReservedVertexType; - private final boolean includeReservedEdgeType; - private final boolean includeReservedEdgeLabel; - private final boolean includeReservedEdgeOutV; - private final boolean includeReservedEdgeInV; - - /** - * A GraphSONUtility that includes the specified properties. - */ - private AtlasGraphSONUtility(final AtlasGraphSONMode mode, final Set<String> vertexPropertyKeySet, - final Set<String> edgePropertyKeySet) { - - AtlasElementPropertyConfig config = AtlasElementPropertyConfig.includeProperties(vertexPropertyKeySet, - edgePropertyKeySet); - - this.vertexPropertyKeys = config.getVertexPropertyKeys(); - this.edgePropertyKeys = config.getEdgePropertyKeys(); - this.vertexPropertiesRule = config.getVertexPropertiesRule(); - this.edgePropertiesRule = config.getEdgePropertiesRule(); - this.normalized = config.isNormalized(); - - this.mode = mode; - - this.includeReservedVertexId = includeReservedKey(mode, AtlasGraphSONTokens.INTERNAL_ID, vertexPropertyKeys, - this.vertexPropertiesRule); - this.includeReservedEdgeId = includeReservedKey(mode, AtlasGraphSONTokens.INTERNAL_ID, edgePropertyKeys, - this.edgePropertiesRule); - this.includeReservedVertexType = includeReservedKey(mode, AtlasGraphSONTokens.INTERNAL_TYPE, vertexPropertyKeys, - this.vertexPropertiesRule); - this.includeReservedEdgeType = includeReservedKey(mode, AtlasGraphSONTokens.INTERNAL_TYPE, edgePropertyKeys, - this.edgePropertiesRule); - this.includeReservedEdgeLabel = includeReservedKey(mode, AtlasGraphSONTokens.INTERNAL_LABEL, edgePropertyKeys, - this.edgePropertiesRule); - this.includeReservedEdgeOutV = includeReservedKey(mode, AtlasGraphSONTokens.INTERNAL_OUT_V, edgePropertyKeys, - this.edgePropertiesRule); - this.includeReservedEdgeInV = includeReservedKey(mode, AtlasGraphSONTokens.INTERNAL_IN_V, edgePropertyKeys, - this.edgePropertiesRule); - } - - /* - * Creates GraphSON for a single graph element. - */ - private JSONObject jsonFromElement(final AtlasElement element) throws JSONException { - final ObjectNode objectNode = this.objectNodeFromElement(element); - - try { - return new JSONObject(new JSONTokener(MAPPER.writeValueAsString(objectNode))); - } catch (IOException ioe) { - // repackage this as a JSONException...seems sensible as the caller will only know about - // the jettison object not being created - throw new JSONException(ioe); - } - } - - /** - * Creates GraphSON for a single graph element. - */ - private ObjectNode objectNodeFromElement(final AtlasElement element) { - final boolean isEdge = element instanceof AtlasEdge; - final boolean showTypes = mode == AtlasGraphSONMode.EXTENDED; - final List<String> propertyKeys = isEdge ? this.edgePropertyKeys : this.vertexPropertyKeys; - final ElementPropertiesRule elementPropertyConfig = isEdge ? this.edgePropertiesRule - : this.vertexPropertiesRule; - - final ObjectNode jsonElement = createJSONMap( - createPropertyMap(element, propertyKeys, elementPropertyConfig, normalized), propertyKeys, showTypes); - - if ((isEdge && this.includeReservedEdgeId) || (!isEdge && this.includeReservedVertexId)) { - putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_ID, element.getId()); - } - - // it's important to keep the order of these straight. check AtlasEdge first and then AtlasVertex because there - // are graph implementations that have AtlasEdge extend from AtlasVertex - if (element instanceof AtlasEdge) { - final AtlasEdge edge = (AtlasEdge) element; - - if (this.includeReservedEdgeId) { - putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_ID, element.getId()); - } - - if (this.includeReservedEdgeType) { - jsonElement.put(AtlasGraphSONTokens.INTERNAL_TYPE, AtlasGraphSONTokens.EDGE); - } - - if (this.includeReservedEdgeOutV) { - putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_OUT_V, edge.getOutVertex().getId()); - } - - if (this.includeReservedEdgeInV) { - putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_IN_V, edge.getInVertex().getId()); - } - - if (this.includeReservedEdgeLabel) { - jsonElement.put(AtlasGraphSONTokens.INTERNAL_LABEL, edge.getLabel()); - } - } else if (element instanceof AtlasVertex) { - if (this.includeReservedVertexId) { - putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_ID, element.getId()); - } - - if (this.includeReservedVertexType) { - jsonElement.put(AtlasGraphSONTokens.INTERNAL_TYPE, AtlasGraphSONTokens.VERTEX); - } - } - - return jsonElement; - } - - /** - * Creates a Jettison JSONObject from a graph element. - * - * @param element - * the graph element to convert to JSON. - * @param propertyKeys - * The property getPropertyKeys() at the root of the element to - * serialize. If null, then all getPropertyKeys() are serialized. - * @param mode - * the type of GraphSON to be generated. - */ - public static JSONObject jsonFromElement(final AtlasElement element, final Set<String> propertyKeys, - final AtlasGraphSONMode mode) - throws JSONException { - - final AtlasGraphSONUtility graphson = element instanceof AtlasEdge - ? new AtlasGraphSONUtility(mode, null, propertyKeys) - : new AtlasGraphSONUtility(mode, propertyKeys, null); - return graphson.jsonFromElement(element); - } - - private static ObjectNode objectNodeFromElement(final AtlasElement element, final List<String> propertyKeys, - final AtlasGraphSONMode mode) { - final AtlasGraphSONUtility graphson = element instanceof AtlasEdge - ? new AtlasGraphSONUtility(mode, null, new HashSet<String>(propertyKeys)) - : new AtlasGraphSONUtility(mode, new HashSet<String>(propertyKeys), null); - return graphson.objectNodeFromElement(element); - } - - private static boolean includeReservedKey(final AtlasGraphSONMode mode, final String key, - final List<String> propertyKeys, final ElementPropertiesRule rule) { - // the key is always included in modes other than compact. if it is compact, then validate that the - // key is in the property key list - return mode != AtlasGraphSONMode.COMPACT || includeKey(key, propertyKeys, rule); - } - - private static boolean includeKey(final String key, final List<String> propertyKeys, - final ElementPropertiesRule rule) { - if (propertyKeys == null) { - // when null always include the key and shortcut this piece - return true; - } - - // default the key situation. if it's included then it should be explicitly defined in the - // property getPropertyKeys() list to be included or the reverse otherwise - boolean keySituation = rule == ElementPropertiesRule.INCLUDE; - - switch (rule) { - case INCLUDE: - keySituation = propertyKeys.contains(key); - break; - case EXCLUDE: - keySituation = !propertyKeys.contains(key); - break; - default: - throw new RuntimeException("Unhandled rule: " + rule); - } - - return keySituation; - } - - private static ArrayNode createJSONList(final List<Object> list, final List<String> propertyKeys, - final boolean showTypes) { - final ArrayNode jsonList = JSON_NODE_FACTORY.arrayNode(); - for (Object item : list) { - if (item instanceof AtlasElement) { - jsonList.add(objectNodeFromElement((AtlasElement) item, propertyKeys, - showTypes ? AtlasGraphSONMode.EXTENDED : AtlasGraphSONMode.NORMAL)); - } else if (item instanceof List) { - jsonList.add(createJSONList((List<Object>) item, propertyKeys, showTypes)); - } else if (item instanceof Map) { - jsonList.add(createJSONMap((Map<String, Object>) item, propertyKeys, showTypes)); - } else if (item != null && item.getClass().isArray()) { - jsonList.add(createJSONList(convertArrayToList(item), propertyKeys, showTypes)); - } else { - addObject(jsonList, item); - } - } - return jsonList; - } - - private static ObjectNode createJSONMap(final Map<String, Object> map, final List<String> propertyKeys, - final boolean showTypes) { - final ObjectNode jsonMap = JSON_NODE_FACTORY.objectNode(); - for (Object key : map.keySet()) { - Object value = map.get(key); - if (value != null) { - if (value instanceof List) { - value = createJSONList((List<Object>) value, propertyKeys, showTypes); - } else if (value instanceof Map) { - value = createJSONMap((Map<String, Object>) value, propertyKeys, showTypes); - } else if (value instanceof AtlasElement) { - value = objectNodeFromElement((AtlasElement) value, propertyKeys, - showTypes ? AtlasGraphSONMode.EXTENDED : AtlasGraphSONMode.NORMAL); - } else if (value.getClass().isArray()) { - value = createJSONList(convertArrayToList(value), propertyKeys, showTypes); - } - } - - putObject(jsonMap, key.toString(), getValue(value, showTypes)); - } - return jsonMap; - - } - - private static void addObject(final ArrayNode jsonList, final Object value) { - if (value == null) { - jsonList.add((JsonNode) null); - } else if (value.getClass() == Boolean.class) { - jsonList.add((Boolean) value); - } else if (value.getClass() == Long.class) { - jsonList.add((Long) value); - } else if (value.getClass() == Integer.class) { - jsonList.add((Integer) value); - } else if (value.getClass() == Float.class) { - jsonList.add((Float) value); - } else if (value.getClass() == Double.class) { - jsonList.add((Double) value); - } else if (value.getClass() == Byte.class) { - jsonList.add((Byte) value); - } else if (value.getClass() == Short.class) { - jsonList.add((Short) value); - } else if (value.getClass() == String.class) { - jsonList.add((String) value); - } else if (value instanceof ObjectNode) { - jsonList.add((ObjectNode) value); - } else if (value instanceof ArrayNode) { - jsonList.add((ArrayNode) value); - } else { - jsonList.add(value.toString()); - } - } - - private static void putObject(final ObjectNode jsonMap, final String key, final Object value) { - if (value == null) { - jsonMap.put(key, (JsonNode) null); - } else if (value.getClass() == Boolean.class) { - jsonMap.put(key, (Boolean) value); - } else if (value.getClass() == Long.class) { - jsonMap.put(key, (Long) value); - } else if (value.getClass() == Integer.class) { - jsonMap.put(key, (Integer) value); - } else if (value.getClass() == Float.class) { - jsonMap.put(key, (Float) value); - } else if (value.getClass() == Double.class) { - jsonMap.put(key, (Double) value); - } else if (value.getClass() == Short.class) { - jsonMap.put(key, (Short) value); - } else if (value.getClass() == Byte.class) { - jsonMap.put(key, (Byte) value); - } else if (value.getClass() == String.class) { - jsonMap.put(key, (String) value); - } else if (value instanceof ObjectNode) { - jsonMap.put(key, (ObjectNode) value); - } else if (value instanceof ArrayNode) { - jsonMap.put(key, (ArrayNode) value); - } else { - jsonMap.put(key, value.toString()); - } - } - - private static Map<String, Object> createPropertyMap(final AtlasElement element, final List<String> propertyKeys, - final ElementPropertiesRule rule, final boolean normalized) { - final Map<String, Object> map = new HashMap<String, Object>(); - final List<String> propertyKeyList; - if (normalized) { - final List<String> sorted = new ArrayList<String>(element.getPropertyKeys()); - Collections.sort(sorted); - propertyKeyList = sorted; - } else { - propertyKeyList = new ArrayList<String>(element.getPropertyKeys()); - } - - if (propertyKeys == null) { - for (String key : propertyKeyList) { - final Object valToPutInMap = element.getProperty(key, Object.class); - if (valToPutInMap != null) { - map.put(key, valToPutInMap); - } - } - } else { - if (rule == ElementPropertiesRule.INCLUDE) { - for (String key : propertyKeys) { - final Object valToPutInMap = element.getProperty(key, Object.class); - if (valToPutInMap != null) { - map.put(key, valToPutInMap); - } - } - } else { - for (String key : propertyKeyList) { - if (!propertyKeys.contains(key)) { - final Object valToPutInMap = element.getProperty(key, Object.class); - if (valToPutInMap != null) { - map.put(key, valToPutInMap); - } - } - } - } - } - - return map; - } - - private static Object getValue(Object value, final boolean includeType) { - - Object returnValue = value; - - // if the includeType is set to true then show the data types of the properties - if (includeType) { - - // type will be one of: map, list, string, long, int, double, float. - // in the event of a complex object it will call a toString and store as a - // string - String type = determineType(value); - - ObjectNode valueAndType = JSON_NODE_FACTORY.objectNode(); - valueAndType.put(AtlasGraphSONTokens.TYPE, type); - - if (type.equals(AtlasGraphSONTokens.TYPE_LIST)) { - - // values of lists must be accumulated as ObjectNode objects under the value key. - // will return as a ArrayNode. called recursively to traverse the entire - // object graph of each item in the array. - ArrayNode list = (ArrayNode) value; - - // there is a set of values that must be accumulated as an array under a key - ArrayNode valueArray = valueAndType.putArray(AtlasGraphSONTokens.VALUE); - for (int ix = 0; ix < list.size(); ix++) { - // the value of each item in the array is a node object from an ArrayNode...must - // get the value of it. - addObject(valueArray, getValue(getTypedValueFromJsonNode(list.get(ix)), includeType)); - } - - } else if (type.equals(AtlasGraphSONTokens.TYPE_MAP)) { - - // maps are converted to a ObjectNode. called recursively to traverse - // the entire object graph within the map. - ObjectNode convertedMap = JSON_NODE_FACTORY.objectNode(); - ObjectNode jsonObject = (ObjectNode) value; - Iterator<?> keyIterator = jsonObject.fieldNames(); - while (keyIterator.hasNext()) { - Object key = keyIterator.next(); - - // no need to getValue() here as this is already a ObjectNode and should have type info - convertedMap.put(key.toString(), jsonObject.get(key.toString())); - } - - valueAndType.put(AtlasGraphSONTokens.VALUE, convertedMap); - } else { - - // this must be a primitive value or a complex object. if a complex - // object it will be handled by a call to toString and stored as a - // string value - putObject(valueAndType, AtlasGraphSONTokens.VALUE, value); - } - - // this goes back as a JSONObject with data type and value - returnValue = valueAndType; - } - - return returnValue; - } - - private static Object getTypedValueFromJsonNode(JsonNode node) { - Object theValue = null; - - if (node != null && !node.isNull()) { - if (node.isBoolean()) { - theValue = node.booleanValue(); - } else if (node.isDouble()) { - theValue = node.doubleValue(); - } else if (node.isFloatingPointNumber()) { - theValue = node.floatValue(); - } else if (node.isInt()) { - theValue = node.intValue(); - } else if (node.isLong()) { - theValue = node.longValue(); - } else if (node.isTextual()) { - theValue = node.textValue(); - } else if (node.isArray()) { - // this is an array so just send it back so that it can be - // reprocessed to its primitive components - theValue = node; - } else if (node.isObject()) { - // this is an object so just send it back so that it can be - // reprocessed to its primitive components - theValue = node; - } else { - theValue = node.textValue(); - } - } - - return theValue; - } - - private static List<Object> convertArrayToList(final Object value) { - final ArrayList<Object> list = new ArrayList<Object>(); - int arrlength = Array.getLength(value); - for (int i = 0; i < arrlength; i++) { - Object object = Array.get(value, i); - list.add(object); - } - return list; - } - - private static String determineType(final Object value) { - String type = AtlasGraphSONTokens.TYPE_STRING; - if (value == null) { - type = AtlasGraphSONTokens.TYPE_UNKNOWN; - } else if (value.getClass() == Double.class) { - type = AtlasGraphSONTokens.TYPE_DOUBLE; - } else if (value.getClass() == Float.class) { - type = AtlasGraphSONTokens.TYPE_FLOAT; - } else if (value.getClass() == Byte.class) { - type = AtlasGraphSONTokens.TYPE_BYTE; - } else if (value.getClass() == Short.class) { - type = AtlasGraphSONTokens.TYPE_SHORT; - } else if (value.getClass() == Integer.class) { - type = AtlasGraphSONTokens.TYPE_INTEGER; - } else if (value.getClass() == Long.class) { - type = AtlasGraphSONTokens.TYPE_LONG; - } else if (value.getClass() == Boolean.class) { - type = AtlasGraphSONTokens.TYPE_BOOLEAN; - } else if (value instanceof ArrayNode) { - type = AtlasGraphSONTokens.TYPE_LIST; - } else if (value instanceof ObjectNode) { - type = AtlasGraphSONTokens.TYPE_MAP; - } - - return type; - } - - static class ElementFactory { - - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/query/NativeTitan1GraphQuery.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/query/NativeTitan1GraphQuery.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/query/NativeTitan1GraphQuery.java deleted file mode 100644 index 733964d..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/query/NativeTitan1GraphQuery.java +++ /dev/null @@ -1,141 +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.titan1.query; - -import com.thinkaurelius.titan.core.TitanEdge; -import com.thinkaurelius.titan.core.TitanGraphQuery; -import com.thinkaurelius.titan.core.TitanVertex; -import com.thinkaurelius.titan.core.attribute.Contain; -import com.thinkaurelius.titan.core.attribute.Text; -import com.thinkaurelius.titan.graphdb.query.TitanPredicate; -import org.apache.atlas.repository.graphdb.AtlasEdge; -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.titan1.Titan1Edge; -import org.apache.atlas.repository.graphdb.titan1.Titan1Graph; -import org.apache.atlas.repository.graphdb.titan1.Titan1GraphDatabase; -import org.apache.atlas.repository.graphdb.titan1.Titan1Vertex; -import org.apache.tinkerpop.gremlin.process.traversal.Compare; -import org.apache.tinkerpop.gremlin.structure.Vertex; - -import java.util.*; - -/** - * Titan 1.0.0 implementation of NativeTinkerpopGraphQuery. - */ -public class NativeTitan1GraphQuery implements NativeTinkerpopGraphQuery<Titan1Vertex, Titan1Edge> { - - private Titan1Graph graph; - private TitanGraphQuery<?> query; - - public NativeTitan1GraphQuery(Titan1Graph graph) { - this.query = Titan1GraphDatabase.getGraphInstance().query(); - this.graph = graph; - } - - @Override - public Iterable<AtlasVertex<Titan1Vertex, Titan1Edge>> vertices() { - Iterable<TitanVertex> it = query.vertices(); - return graph.wrapVertices(it); - } - - @Override - public Iterable<AtlasEdge<Titan1Vertex, Titan1Edge>> edges() { - Iterable<TitanEdge> it = query.edges(); - return graph.wrapEdges(it); - } - - @Override - public Iterable<AtlasVertex<Titan1Vertex, Titan1Edge>> vertices(int limit) { - Iterable<TitanVertex> it = query.limit(limit).vertices(); - return graph.wrapVertices(it); - } - - @Override - public Iterable<AtlasVertex<Titan1Vertex, Titan1Edge>> vertices(int offset, int limit) { - List<Vertex> result = new ArrayList<>(limit); - Iterator<? extends 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<? extends Object> 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); - } - - 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.eq; - case GREATER_THAN: - return Compare.gt; - case GREATER_THAN_EQUAL: - return Compare.gte; - case LESS_THAN: - return Compare.lt; - case LESS_THAN_EQUAL: - return Compare.lte; - case NOT_EQUAL: - return Compare.neq; - - default: - throw new RuntimeException("Unsupported comparison operator:" + op); - } - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/query/Titan1GraphQuery.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/query/Titan1GraphQuery.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/query/Titan1GraphQuery.java deleted file mode 100644 index dd0176b..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/query/Titan1GraphQuery.java +++ /dev/null @@ -1,55 +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.titan1.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.titan1.Titan1Edge; -import org.apache.atlas.repository.graphdb.titan1.Titan1Graph; -import org.apache.atlas.repository.graphdb.titan1.Titan1Vertex; -/** - * Titan 1.0.0 implementation of TitanGraphQuery. - */ -public class Titan1GraphQuery extends TinkerpopGraphQuery<Titan1Vertex, Titan1Edge> - implements NativeTinkerpopQueryFactory<Titan1Vertex, Titan1Edge> { - - public Titan1GraphQuery(Titan1Graph graph, boolean isChildQuery) { - super(graph, isChildQuery); - } - - public Titan1GraphQuery(Titan1Graph graph) { - super(graph); - } - - @Override - public AtlasGraphQuery<Titan1Vertex, Titan1Edge> createChildQuery() { - return new Titan1GraphQuery((Titan1Graph) graph, true); - } - - @Override - protected NativeTinkerpopQueryFactory<Titan1Vertex, Titan1Edge> getQueryFactory() { - return this; - } - - @Override - public NativeTinkerpopGraphQuery<Titan1Vertex, Titan1Edge> createNativeTinkerpopQuery() { - return new NativeTitan1GraphQuery((Titan1Graph) graph); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/BigDecimalSerializer.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/BigDecimalSerializer.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/BigDecimalSerializer.java deleted file mode 100644 index c1a096d..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/BigDecimalSerializer.java +++ /dev/null @@ -1,48 +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.titan1.serializer; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import com.thinkaurelius.titan.core.attribute.AttributeSerializer; -import com.thinkaurelius.titan.diskstorage.ScanBuffer; -import com.thinkaurelius.titan.diskstorage.WriteBuffer; -/** - * Serializer for BigDecimal values. - */ -public class BigDecimalSerializer implements AttributeSerializer<BigDecimal> { - - private final BigIntegerSerializer bigIntegerDelegate = new BigIntegerSerializer(); - - @Override - public BigDecimal read(ScanBuffer buffer) { - BigInteger unscaledVal = bigIntegerDelegate.read(buffer); - int scale = buffer.getInt(); - return new BigDecimal(unscaledVal, scale); - } - - @Override - public void write(WriteBuffer buffer, BigDecimal attribute) { - BigInteger unscaledVal = attribute.unscaledValue(); - int scale = attribute.scale(); - bigIntegerDelegate.write(buffer, unscaledVal); - buffer.putInt(scale); - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/BigIntegerSerializer.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/BigIntegerSerializer.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/BigIntegerSerializer.java deleted file mode 100644 index dfda9f6..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/BigIntegerSerializer.java +++ /dev/null @@ -1,46 +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.titan1.serializer; - -import java.math.BigInteger; - -import com.thinkaurelius.titan.core.attribute.AttributeSerializer; -import com.thinkaurelius.titan.diskstorage.ScanBuffer; -import com.thinkaurelius.titan.diskstorage.WriteBuffer; -import com.thinkaurelius.titan.graphdb.database.serialize.attribute.ByteArraySerializer; - -/** - * Serializer for BigInteger values. - */ -public class BigIntegerSerializer implements AttributeSerializer<BigInteger> { - - private final ByteArraySerializer delegate = new ByteArraySerializer(); - - @Override - public BigInteger read(ScanBuffer buffer) { - byte[] value = delegate.read(buffer); - return new BigInteger(value); - } - - @Override - public void write(WriteBuffer buffer, BigInteger attribute) { - byte[] value = attribute.toByteArray(); - delegate.write(buffer, value); - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/StringListSerializer.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/StringListSerializer.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/StringListSerializer.java deleted file mode 100644 index eb99fae..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/StringListSerializer.java +++ /dev/null @@ -1,53 +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.titan1.serializer; - -import java.util.ArrayList; -import java.util.List; - -import com.thinkaurelius.titan.core.attribute.AttributeSerializer; -import com.thinkaurelius.titan.diskstorage.ScanBuffer; -import com.thinkaurelius.titan.diskstorage.WriteBuffer; -import com.thinkaurelius.titan.graphdb.database.idhandling.VariableLong; -import com.thinkaurelius.titan.graphdb.database.serialize.attribute.StringSerializer; -/** - * Serializer for String lists. - */ -public class StringListSerializer implements AttributeSerializer<List<String>> { - - private final StringSerializer stringSerializer = new StringSerializer(); - - @Override - public List<String> read(ScanBuffer buffer) { - int length = (int)VariableLong.readPositive(buffer); - List<String> result = new ArrayList<String>(length); - for(int i = 0; i < length; i++) { - result.add(stringSerializer.read(buffer)); - } - return result; - } - - @Override - public void write(WriteBuffer buffer, List<String> attributes) { - VariableLong.writePositive(buffer, attributes.size()); - for(String attr : attributes) { - stringSerializer.write(buffer, attr); - } - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/TypeCategorySerializer.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/TypeCategorySerializer.java b/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/TypeCategorySerializer.java deleted file mode 100644 index c3e2d1c..0000000 --- a/graphdb/titan1/src/main/java/org/apache/atlas/repository/graphdb/titan1/serializer/TypeCategorySerializer.java +++ /dev/null @@ -1,31 +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.titan1.serializer; - -import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; - -import com.thinkaurelius.titan.graphdb.database.serialize.attribute.EnumSerializer; - -/** - * Serializer for TypeCategory value. - */ -public class TypeCategorySerializer extends EnumSerializer<TypeCategory> { - public TypeCategorySerializer() { - super(TypeCategory.class); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory b/graphdb/titan1/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory deleted file mode 100644 index 24c8a75..0000000 --- a/graphdb/titan1/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory +++ /dev/null @@ -1 +0,0 @@ -org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineFactory http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/test/java/org/apache/atlas/repository/graphdb/titan1/AbstractGraphDatabaseTest.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/test/java/org/apache/atlas/repository/graphdb/titan1/AbstractGraphDatabaseTest.java b/graphdb/titan1/src/test/java/org/apache/atlas/repository/graphdb/titan1/AbstractGraphDatabaseTest.java deleted file mode 100644 index 06e2785..0000000 --- a/graphdb/titan1/src/test/java/org/apache/atlas/repository/graphdb/titan1/AbstractGraphDatabaseTest.java +++ /dev/null @@ -1,189 +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.titan1; - -import org.apache.atlas.graph.GraphSandboxUtil; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.repository.graphdb.AtlasCardinality; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.atlas.repository.graphdb.AtlasGraphManagement; -import org.apache.atlas.repository.graphdb.AtlasPropertyKey; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * - */ -public abstract class AbstractGraphDatabaseTest { - - protected static final String WEIGHT_PROPERTY = "weight"; - protected static final String TRAIT_NAMES = Constants.TRAIT_NAMES_PROPERTY_KEY; - protected static final String TYPE_PROPERTY_NAME = "__type"; - protected static final String TYPESYSTEM = "TYPESYSTEM"; - - private static final String BACKING_INDEX_NAME = "backing"; - - private AtlasGraph<?, ?> graph = null; - - @BeforeClass - public static void createIndices() { - GraphSandboxUtil.create(); - - Titan1GraphDatabase db = new Titan1GraphDatabase(); - AtlasGraphManagement mgmt = db.getGraph().getManagementSystem(); - - if (mgmt.getGraphIndex(BACKING_INDEX_NAME) == null) { - mgmt.createVertexIndex(BACKING_INDEX_NAME, Constants.BACKING_INDEX, - Collections.<AtlasPropertyKey>emptyList()); - } - mgmt.makePropertyKey("age13", Integer.class, AtlasCardinality.SINGLE); - - createIndices(mgmt, "name", String.class, false, AtlasCardinality.SINGLE); - createIndices(mgmt, WEIGHT_PROPERTY, Integer.class, false, AtlasCardinality.SINGLE); - createIndices(mgmt, "size15", String.class, false, AtlasCardinality.SINGLE); - createIndices(mgmt, "typeName", String.class, false, AtlasCardinality.SINGLE); - createIndices(mgmt, "__type", String.class, false, AtlasCardinality.SINGLE); - createIndices(mgmt, Constants.GUID_PROPERTY_KEY, String.class, true, AtlasCardinality.SINGLE); - createIndices(mgmt, Constants.TRAIT_NAMES_PROPERTY_KEY, String.class, false, AtlasCardinality.SET); - createIndices(mgmt, Constants.SUPER_TYPES_PROPERTY_KEY, String.class, false, AtlasCardinality.SET); - mgmt.commit(); - } - - @AfterMethod - public void commitGraph() { - //force any pending actions to be committed so we can be sure they don't cause errors. - pushChangesAndFlushCache(); - getGraph().commit(); - } - - @AfterClass - public static void cleanUp() { - Titan1Graph graph = new Titan1Graph(); - graph.clear(); - - } - - protected <V, E> void pushChangesAndFlushCache() { - getGraph().commit(); - } - - private static void createIndices(AtlasGraphManagement management, String propertyName, Class propertyClass, - boolean isUnique, AtlasCardinality cardinality) { - - if (management.containsPropertyKey(propertyName)) { - //index was already created - return; - } - - AtlasPropertyKey key = management.makePropertyKey(propertyName, propertyClass, cardinality); - try { - if (propertyClass != Integer.class) { - management.addVertexIndexKey(BACKING_INDEX_NAME, key); - } - } catch(Throwable t) { - //ok - t.printStackTrace(); - } - try { - management.createExactMatchIndex(propertyName, isUnique, Collections.singletonList(key)); - - } catch(Throwable t) { - //ok - t.printStackTrace(); - } - - - } - - - - - protected final <V, E> AtlasGraph<V, E> getGraph() { - if (graph == null) { - graph = new Titan1Graph(); - } - return (AtlasGraph<V, E>)graph; - } - - protected Titan1Graph getTitan1Graph() { - AtlasGraph g = getGraph(); - return (Titan1Graph)g; - } - - - protected List<AtlasVertex> newVertices = new ArrayList<>(); - - protected final <V, E> AtlasVertex<V, E> createVertex(AtlasGraph<V, E> theGraph) { - AtlasVertex<V, E> vertex = theGraph.addVertex(); - newVertices.add(vertex); - return vertex; - } - - @AfterMethod - public void removeVertices() { - for(AtlasVertex vertex : newVertices) { - if (vertex.exists()) { - getGraph().removeVertex(vertex); - } - } - getGraph().commit(); - newVertices.clear(); - } - protected void runSynchronouslyInNewThread(final Runnable r) throws Throwable { - - RunnableWrapper wrapper = new RunnableWrapper(r); - Thread th = new Thread(wrapper); - th.start(); - th.join(); - Throwable ex = wrapper.getExceptionThrown(); - if (ex != null) { - throw ex; - } - } - - private static final class RunnableWrapper implements Runnable { - private final Runnable r; - private Throwable exceptionThrown = null; - - private RunnableWrapper(Runnable r) { - this.r = r; - } - - @Override - public void run() { - try { - r.run(); - } catch(Throwable e) { - exceptionThrown = e; - } - - } - - public Throwable getExceptionThrown() { - return exceptionThrown; - } - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/5ba64a8b/graphdb/titan1/src/test/java/org/apache/atlas/repository/graphdb/titan1/GraphQueryTest.java ---------------------------------------------------------------------- diff --git a/graphdb/titan1/src/test/java/org/apache/atlas/repository/graphdb/titan1/GraphQueryTest.java b/graphdb/titan1/src/test/java/org/apache/atlas/repository/graphdb/titan1/GraphQueryTest.java deleted file mode 100644 index 45fbbea..0000000 --- a/graphdb/titan1/src/test/java/org/apache/atlas/repository/graphdb/titan1/GraphQueryTest.java +++ /dev/null @@ -1,451 +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.titan1; - - - -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery; -import org.apache.atlas.repository.graphdb.AtlasGraphQuery.ComparisionOperator; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; - - - -/** - * Tests for Titan1GraphQuery. - */ -@Test -public class GraphQueryTest extends AbstractGraphDatabaseTest { - - - @Test - public <V, E> void testQueryThatCannotRunInMemory() throws AtlasException { - AtlasGraph<V, E> graph = getGraph(); - AtlasVertex<V, E> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - - AtlasVertex<V, E> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - - AtlasVertex<V, E> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - - graph.commit(); - - AtlasVertex<V, E> v4 = createVertex(graph); - v4.setProperty("name", "Fred"); - v4.setProperty("size15", "15"); - - AtlasGraphQuery q = graph.query(); - q.has("name", ComparisionOperator.NOT_EQUAL, "George"); - q.has("size15", "15"); - graph.commit(); - pause(); //pause to let the index get updated - - assertQueryMatches(q, v1, v3, v4); - - } - - @Test - public void testCombinationOfAndsAndOrs() throws AtlasException { - Titan1Graph graph = getTitan1Graph(); - - AtlasVertex<Titan1Vertex, Titan1Edge> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - v1.setProperty("typeName", "Person"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v2 = createVertex(graph); - v2.setProperty("name", "George"); - v2.setProperty("size15", "16"); - v2.setProperty("typeName", "Person"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v3 = createVertex(graph); - v3.setProperty("name", "Jane"); - v3.setProperty("size15", "17"); - v3.setProperty("typeName", "Person"); - - - AtlasVertex<Titan1Vertex, Titan1Edge> v4 = createVertex(graph); - v4.setProperty("name", "Bob"); - v4.setProperty("size15", "18"); - v4.setProperty("typeName", "Person"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v5 = createVertex(graph); - v5.setProperty("name", "Julia"); - v5.setProperty("size15", "19"); - v5.setProperty("typeName", "Manager"); - - - AtlasGraphQuery q = getGraphQuery(); - q.has("typeName", "Person"); - //initially match - AtlasGraphQuery inner1a = q.createChildQuery(); - AtlasGraphQuery inner1b = q.createChildQuery(); - inner1a.has("name", "Fred"); - inner1b.has("name", "Jane"); - q.or(toList(inner1a, inner1b)); - - - AtlasGraphQuery inner2a = q.createChildQuery(); - AtlasGraphQuery inner2b = q.createChildQuery(); - AtlasGraphQuery inner2c = q.createChildQuery(); - inner2a.has("size15", "18"); - inner2b.has("size15", "15"); - inner2c.has("size15", "16"); - q.or(toList(inner2a, inner2b, inner2c)); - - assertQueryMatches(q, v1); - graph.commit(); - pause(); //let the index update - assertQueryMatches(q, v1); - } - - @Test - public void testWithinStep() throws AtlasException { - Titan1Graph graph = getTitan1Graph(); - - AtlasVertex<Titan1Vertex, Titan1Edge> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - v1.setProperty("typeName", "Person"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v2 = createVertex(graph); - v2.setProperty("name", "George"); - v2.setProperty("size15", "16"); - v2.setProperty("typeName", "Person"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v3 = createVertex(graph); - v3.setProperty("name", "Jane"); - v3.setProperty("size15", "17"); - v3.setProperty("typeName", "Person"); - - - AtlasVertex<Titan1Vertex, Titan1Edge> v4 = createVertex(graph); - v4.setProperty("name", "Bob"); - v4.setProperty("size15", "18"); - v4.setProperty("typeName", "Person"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v5 = createVertex(graph); - v5.setProperty("name", "Julia"); - v5.setProperty("size15", "19"); - v5.setProperty("typeName", "Manager"); - - - AtlasGraphQuery q = getGraphQuery(); - q.has("typeName", "Person"); - //initially match - q.in("name", toList("Fred", "Jane")); - q.in("size15", toList("18", "15", "16")); - - assertQueryMatches(q, v1); - graph.commit(); - pause(); //let the index update - assertQueryMatches(q, v1); - } - - @Test - public void testWithinStepWhereGraphIsStale() throws AtlasException { - Titan1Graph graph = getTitan1Graph(); - - AtlasVertex<Titan1Vertex, Titan1Edge> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - v1.setProperty("typeName", "Person"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v2 = createVertex(graph); - v2.setProperty("name", "George"); - v2.setProperty("size15", "16"); - v2.setProperty("typeName", "Person"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v3 = createVertex(graph); - v3.setProperty("name", "Jane"); - v3.setProperty("size15", "17"); - v3.setProperty("typeName", "Person"); - - - AtlasVertex<Titan1Vertex, Titan1Edge> v4 = createVertex(graph); - v4.setProperty("name", "Bob"); - v4.setProperty("size15", "18"); - v4.setProperty("typeName", "Person"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v5 = createVertex(graph); - v5.setProperty("name", "Julia"); - v5.setProperty("size15", "19"); - v5.setProperty("typeName", "Manager"); - - - AtlasGraphQuery q = getGraphQuery(); - q.has("typeName", "Person"); - //initially match - q.in("name", toList("Fred", "Jane")); - - graph.commit(); - pause(); //let the index update - assertQueryMatches(q, v1, v3); - //make v3 no longer match the query. Within step should filter out the vertex since it no longer matches. - v3.setProperty("name", "Janet"); - assertQueryMatches(q, v1); - } - - @Test - public void testSimpleOrQuery() throws AtlasException { - Titan1Graph graph = getTitan1Graph(); - - - AtlasVertex<Titan1Vertex, Titan1Edge> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - - graph.commit(); - - AtlasVertex<Titan1Vertex, Titan1Edge> v4 = createVertex(graph); - v4.setProperty("name", "Fred"); - v4.setProperty("size15", "15"); - - AtlasVertex<Titan1Vertex, Titan1Edge> v5 = createVertex(graph); - v5.setProperty("name", "George"); - v5.setProperty("size15", "16"); - - AtlasGraphQuery q = graph.query(); - AtlasGraphQuery inner1 = q.createChildQuery().has("name", "Fred"); - AtlasGraphQuery inner2 = q.createChildQuery().has("size15", "15"); - q.or(toList(inner1, inner2)); - assertQueryMatches(q, v1, v2, v3, v4); - graph.commit(); - pause(); //pause to let the indexer get updated (this fails frequently without a pause) - assertQueryMatches(q, v1, v2, v3, v4); - } - - - - - @Test - public <V, E> void testQueryMatchesAddedVertices() throws AtlasException { - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - - AtlasVertex<V, E> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - - AtlasVertex<V, E> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - - graph.commit(); - - AtlasVertex<V, E> v4 = createVertex(graph); - v4.setProperty("name", "Fred"); - v4.setProperty("size15", "15"); - - AtlasGraphQuery q = getGraphQuery(); - q.has("name", "Fred"); - q.has("size15", "15"); - - assertQueryMatches(q, v1, v4); - graph.commit(); - assertQueryMatches(q, v1, v4); - - } - - - @Test - public <V, E> void testQueryDoesNotMatchRemovedVertices() throws AtlasException { - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - - AtlasVertex<V, E> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - - AtlasVertex<V, E> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - - AtlasVertex<V, E> v4 = createVertex(graph); - v4.setProperty("name", "Fred"); - v4.setProperty("size15", "15"); - - graph.commit(); - - graph.removeVertex(v1); - - AtlasGraphQuery q = getGraphQuery(); - q.has("name", "Fred"); - q.has("size15", "15"); - - assertQueryMatches(q, v4); - graph.commit(); - - assertQueryMatches(q, v4); - } - - @Test - public <V, E> void testQueryDoesNotMatchUncommittedAddedAndRemovedVertices() throws AtlasException { - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> v1 = createVertex(graph); - - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - - AtlasVertex<V, E> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - - AtlasVertex<V, E> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - - AtlasVertex<V, E> v4 = createVertex(graph); - v4.setProperty("name", "Fred"); - v4.setProperty("size15", "15"); - - - AtlasGraphQuery q = getGraphQuery(); - q.has("name", "Fred"); - q.has("size15", "15"); - - assertQueryMatches(q, v1, v4); - - graph.removeVertex(v1); - - - assertQueryMatches(q, v4); - graph.commit(); - - assertQueryMatches(q, v4); - } - - - @Test - public <V, E> void testQueryResultsReflectPropertyAdd() throws AtlasException { - AtlasGraph<V, E> graph = getGraph(); - - AtlasVertex<V, E> v1 = createVertex(graph); - v1.setProperty("name", "Fred"); - v1.setProperty("size15", "15"); - v1.addProperty(TRAIT_NAMES, "trait1"); - v1.addProperty(TRAIT_NAMES, "trait2"); - - AtlasVertex<V, E> v2 = createVertex(graph); - v2.setProperty("name", "Fred"); - v2.addProperty(TRAIT_NAMES, "trait1"); - - AtlasVertex<V, E> v3 = createVertex(graph); - v3.setProperty("size15", "15"); - v3.addProperty(TRAIT_NAMES, "trait2"); - - AtlasGraphQuery query = getGraphQuery(); - query.has("name", "Fred"); - query.has(TRAIT_NAMES, "trait1"); - query.has("size15", "15"); - - assertQueryMatches(query, v1); - //make v3 match the query - v3.setProperty("name", "Fred"); - v3.addProperty(TRAIT_NAMES, "trait1"); - assertQueryMatches(query, v1, v3); - v3.removeProperty(TRAIT_NAMES); - assertQueryMatches(query, v1); - v3.addProperty(TRAIT_NAMES, "trait2"); - assertQueryMatches(query, v1); - v1.removeProperty(TRAIT_NAMES); - assertQueryMatches(query); - graph.commit(); - assertQueryMatches(query); - - } - - private static <T> List<T> toList(Iterable<T> itr) { - List<T> result = new ArrayList<T>(); - for(T object : itr) { - result.add(object); - } - return result; - - } - - private <V, E> void assertQueryMatches(AtlasGraphQuery expr, AtlasVertex... expectedResults) throws AtlasException { - - //getGraph().commit(); - Collection<AtlasVertex<Titan1Vertex, Titan1Edge>> temp = toList(expr.vertices()); - //filter out vertices from previous test executions - Collection<AtlasVertex<Titan1Vertex, Titan1Edge>> result = - Collections2.filter(temp, new Predicate<AtlasVertex<Titan1Vertex, Titan1Edge>>() { - - @Override - public boolean apply(AtlasVertex<Titan1Vertex, Titan1Edge> input) { - return newVertices.contains(input); - } - - }); - String errorMessage = "Expected/found result sizes differ. Expected: " - + Arrays.asList(expectedResults).toString() +", found: " + result; - assertEquals(errorMessage, expectedResults.length, result.size()); - - for(AtlasVertex<V, E> v : expectedResults) { - assertTrue(result.contains(v)); - } - } - - private static List<Object> toList(Object...objects) { - return Arrays.asList(objects); - } - - private AtlasGraphQuery<Titan1Vertex, Titan1Edge> getGraphQuery() { - return getTitan1Graph().query(); - } - - private void pause() { - try { - Thread.sleep(5000); - } catch(InterruptedException e) { - //ignore - } - } -}