Skip to content
Permalink
Browse files

[#1088] Move Element factories from Config to BaseFactory (#1301)

fixes #1088
  • Loading branch information...
timo95 authored and ChrizZz110 committed Jul 3, 2019
1 parent 069a60a commit 3479c1fa5b703c6d79082abf46cdbf9ea2b76307
Showing with 351 additions and 323 deletions.
  1. +1 −41 gradoop-common/src/main/java/org/gradoop/common/config/GradoopConfig.java
  2. +39 −37 gradoop-common/src/main/java/org/gradoop/common/util/AsciiGraphLoader.java
  3. +45 −5 gradoop-common/src/test/java/org/gradoop/common/GradoopTestUtils.java
  4. +22 −24 gradoop-common/src/test/java/org/gradoop/common/util/AsciiGraphLoaderTest.java
  5. +2 −2 ...a-integration/src/main/java/org/gradoop/dataintegration/importer/impl/csv/MinimalCSVImporter.java
  6. +1 −1 ...integration/src/main/java/org/gradoop/dataintegration/importer/impl/json/MinimalJSONImporter.java
  7. +3 −3 ...tion/src/main/java/org/gradoop/dataintegration/transformation/impl/ExtractPropertyFromVertex.java
  8. +3 −3 ...ation/src/main/java/org/gradoop/dataintegration/transformation/impl/functions/CreateNewEdges.java
  9. +3 −3 ...tion/src/main/java/org/gradoop/dataintegration/transformation/impl/functions/CreateNewVertex.java
  10. +3 −3 ...rg/gradoop/dataintegration/transformation/impl/functions/CreateNewVertexWithEqualityCondense.java
  11. +3 −3 ...c/test/java/org/gradoop/dataintegration/importer/impl/json/functions/MinimalJsonToVertexTest.java
  12. +3 −2 ...est/java/org/gradoop/dataintegration/transformation/functions/AccumulatePropagatedValuesTest.java
  13. +2 −2 ...test/java/org/gradoop/dataintegration/transformation/functions/BuildIdPropertyValuePairsTest.java
  14. +2 −2 ...g/gradoop/dataintegration/transformation/functions/BuildTargetVertexIdPropertyValuePairsTest.java
  15. +5 −4 ...va/org/gradoop/dataintegration/transformation/functions/CreateCartesianNeighborhoodEdgesTest.java
  16. +3 −3 ...src/test/java/org/gradoop/dataintegration/transformation/functions/CreateEdgesFromTripleTest.java
  17. +3 −3 ...src/test/java/org/gradoop/dataintegration/transformation/functions/CreateVertexFromEdgesTest.java
  18. +2 −2 .../src/test/java/org/gradoop/dataintegration/transformation/impl/ExtractPropertyFromVertexTest.java
  19. +1 −1 gradoop-flink/src/main/java/org/gradoop/flink/algorithms/btgs/BusinessTransactionGraphs.java
  20. +3 −3 ...k/src/main/java/org/gradoop/flink/algorithms/fsm/transactional/tle/functions/SubgraphDecoder.java
  21. +6 −4 gradoop-flink/src/main/java/org/gradoop/flink/io/impl/csv/CSVDataSource.java
  22. +6 −10 gradoop-flink/src/main/java/org/gradoop/flink/io/impl/csv/indexed/IndexedCSVDataSource.java
  23. +10 −10 gradoop-flink/src/main/java/org/gradoop/flink/io/impl/deprecated/json/JSONDataSource.java
  24. +2 −2 ...src/main/java/org/gradoop/flink/io/impl/deprecated/logicalgraphcsv/LogicalGraphCSVDataSource.java
  25. +4 −4 ...n/java/org/gradoop/flink/io/impl/deprecated/logicalgraphcsv/LogicalGraphIndexedCSVDataSource.java
  26. +2 −2 gradoop-flink/src/main/java/org/gradoop/flink/io/impl/graph/GraphDataSource.java
  27. +9 −9 gradoop-flink/src/main/java/org/gradoop/flink/io/impl/tlf/functions/GraphTransactionFromText.java
  28. +12 −1 gradoop-flink/src/main/java/org/gradoop/flink/model/api/layouts/BaseLayoutFactory.java
  29. +1 −1 gradoop-flink/src/main/java/org/gradoop/flink/model/api/layouts/GraphCollectionLayoutFactory.java
  30. +1 −1 gradoop-flink/src/main/java/org/gradoop/flink/model/api/layouts/LogicalGraphLayoutFactory.java
  31. +3 −18 gradoop-flink/src/main/java/org/gradoop/flink/model/impl/epgm/GraphCollectionFactory.java
  32. +3 −18 gradoop-flink/src/main/java/org/gradoop/flink/model/impl/epgm/LogicalGraphFactory.java
  33. +49 −4 gradoop-flink/src/main/java/org/gradoop/flink/model/impl/layouts/common/BaseFactory.java
  34. +2 −8 gradoop-flink/src/main/java/org/gradoop/flink/model/impl/layouts/gve/GVEGraphLayoutFactory.java
  35. +1 −1 ...k/src/main/java/org/gradoop/flink/model/impl/layouts/transactional/TxCollectionLayoutFactory.java
  36. +1 −1 gradoop-flink/src/main/java/org/gradoop/flink/model/impl/operators/cypher/capf/query/CAPFQuery.java
  37. +10 −8 ...link/src/main/java/org/gradoop/flink/model/impl/operators/cypher/capf/result/CAPFQueryResult.java
  38. +3 −3 ...radoop/flink/model/impl/operators/cypher/capf/result/functions/CreateGraphHeadWithProperties.java
  39. +19 −19 ...oop-flink/src/main/java/org/gradoop/flink/model/impl/operators/matching/common/PostProcessor.java
  40. +7 −7 ...ain/java/org/gradoop/flink/model/impl/operators/matching/single/cypher/CypherPatternMatching.java
  41. +6 −6 ...flink/model/impl/operators/matching/single/preserving/explorative/ExplorativePatternMatching.java
  42. +3 −3 ...n/java/org/gradoop/flink/model/impl/operators/matching/single/simulation/dual/DualSimulation.java
  43. +1 −1 ...a/org/gradoop/flink/model/impl/operators/matching/transactional/TransactionalPatternMatching.java
  44. +1 −1 gradoop-flink/src/main/java/org/gradoop/flink/model/impl/operators/split/Split.java
  45. +8 −6 gradoop-flink/src/main/java/org/gradoop/flink/util/FlinkAsciiGraphLoader.java
  46. +2 −2 gradoop-flink/src/test/java/org/gradoop/flink/model/impl/functions/epgm/LabelIsInTest.java
  47. +2 −2 ...t/java/org/gradoop/flink/model/impl/functions/filters/AbstractRichCombinedFilterFunctionTest.java
  48. +9 −8 gradoop-flink/src/test/java/org/gradoop/flink/model/impl/layouts/gve/GVELayoutTest.java
  49. +9 −8 ...link/src/test/java/org/gradoop/flink/model/impl/layouts/transactional/TxCollectionLayoutTest.java
  50. +3 −2 gradoop-store/gradoop-accumulo/src/test/java/org/gradoop/storage/impl/accumulo/basic/StoreTest.java
  51. +6 −4 gradoop-store/gradoop-hbase/src/main/java/org/gradoop/storage/impl/hbase/io/HBaseDataSource.java
  52. +1 −2 gradoop-store/gradoop-hbase/src/test/java/org/gradoop/storage/impl/hbase/HBaseEPGMStoreTest.java
@@ -20,10 +20,7 @@
import org.gradoop.common.model.api.entities.Vertex;
import org.gradoop.common.model.impl.pojo.EPGMEdge;
import org.gradoop.common.model.impl.pojo.EPGMGraphHead;
import org.gradoop.common.model.impl.pojo.EPGMGraphHeadFactory;
import org.gradoop.common.model.impl.pojo.EPGMVertex;
import org.gradoop.common.model.impl.pojo.EPGMEdgeFactory;
import org.gradoop.common.model.impl.pojo.EPGMVertexFactory;

/**
* Basic Gradoop Configuration.
@@ -32,32 +29,7 @@
* @param <V> EPGM vertex type
* @param <E> EPGM edge type
*/
public class GradoopConfig
<G extends GraphHead, V extends Vertex, E extends Edge> {

/**
* Knows how to create {@link EPGMGraphHead}
*/
private final EPGMGraphHeadFactory graphHeadFactory;

/**
* Knows how to create {@link EPGMVertex}
*/
private final EPGMVertexFactory vertexFactory;

/**
* Knows how to create {@link EPGMEdge}
*/
private final EPGMEdgeFactory edgeFactory;

/**
* Creates a new Configuration.
*/
protected GradoopConfig() {
this.graphHeadFactory = new EPGMGraphHeadFactory();
this.vertexFactory = new EPGMVertexFactory();
this.edgeFactory = new EPGMEdgeFactory();
}
public class GradoopConfig<G extends GraphHead, V extends Vertex, E extends Edge> {

/**
* Creates a default Configuration using POJO handlers for vertices, edges
@@ -68,16 +40,4 @@ protected GradoopConfig() {
public static GradoopConfig<EPGMGraphHead, EPGMVertex, EPGMEdge> getDefaultConfig() {
return new GradoopConfig<>();
}

public EPGMGraphHeadFactory getGraphHeadFactory() {
return graphHeadFactory;
}

public EPGMVertexFactory getVertexFactory() {
return vertexFactory;
}

public EPGMEdgeFactory getEdgeFactory() {
return edgeFactory;
}
}
@@ -19,11 +19,11 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.gradoop.common.model.api.entities.ElementFactoryProvider;
import org.gradoop.common.model.api.entities.GraphHead;
import org.gradoop.common.model.api.entities.Edge;
import org.gradoop.common.model.api.entities.Vertex;
import org.gradoop.common.model.impl.id.GradoopId;
import org.gradoop.common.config.GradoopConfig;
import org.gradoop.common.model.impl.id.GradoopIdSet;
import org.gradoop.common.model.impl.properties.Properties;
import org.s1ck.gdl.GDLHandler;
@@ -40,16 +40,16 @@
*
* @see <a href="https://github.com/s1ck/gdl">GDL on GitHub</a>
*
* @param <G> EPGM graph head type
* @param <V> EPGM vertex type
* @param <E> EPGM edge type
* @param <G> graph head type
* @param <V> vertex type
* @param <E> edge type
*/
public class AsciiGraphLoader<G extends GraphHead, V extends Vertex, E extends Edge> {

/**
* Gradoop configuration
* Factory provider for graph elements.
*/
private final GradoopConfig<G, V, E> config;
private final ElementFactoryProvider<G, V, E> elementFactoryProvider;

/**
* Used to parse GDL scripts.
@@ -98,12 +98,12 @@
* Creates a new AsciiGraphLoader.
*
* @param gdlHandler GDL Handler
* @param config Gradoop configuration
* @param elementFactoryProvider Factory provider for EPGM elements.
*/
private AsciiGraphLoader(GDLHandler gdlHandler,
GradoopConfig<G, V, E> config) {
ElementFactoryProvider<G, V, E> elementFactoryProvider) {
this.gdlHandler = gdlHandler;
this.config = config;
this.elementFactoryProvider = elementFactoryProvider;

this.graphHeads = Maps.newHashMap();
this.vertices = Maps.newHashMap();
@@ -123,72 +123,74 @@ private AsciiGraphLoader(GDLHandler gdlHandler,
/**
* Creates an AsciiGraphLoader from the given ASCII GDL string.
*
* @param asciiGraph GDL string
* @param config Gradoop configuration
* @param <G> EPGM graph head type
* @param <V> EPGM vertex type
* @param <E> EPGM edge type
* @param asciiGraph GDL string
* @param elementFactoryProvider Factory provider for graph elements.
* @param <G> graph head type
* @param <V> vertex type
* @param <E> edge type
*
* @return AsciiGraphLoader
*/
public static
<G extends GraphHead, V extends Vertex, E extends Edge>
AsciiGraphLoader<G, V, E> fromString(String asciiGraph,
GradoopConfig<G, V, E> config) {
ElementFactoryProvider<G, V, E> elementFactoryProvider) {
return new AsciiGraphLoader<>(new GDLHandler.Builder()
.setDefaultGraphLabel(GradoopConstants.DEFAULT_GRAPH_LABEL)
.setDefaultVertexLabel(GradoopConstants.DEFAULT_VERTEX_LABEL)
.setDefaultEdgeLabel(GradoopConstants.DEFAULT_EDGE_LABEL)
.buildFromString(asciiGraph),
config);
elementFactoryProvider);
}

/**
* Creates an AsciiGraphLoader from the given ASCII GDL file.
*
* @param fileName File that contains a GDL script
* @param config Gradoop configuration
* @param <G> EPGM graph head type
* @param <V> EPGM vertex type
* @param <E> EPGM edge type
* @param fileName File that contains a GDL script
* @param elementFactoryProvider Factory provider for graph elements.
* @param <G> graph head type
* @param <V> vertex type
* @param <E> edge type
*
* @return AsciiGraphLoader
* @throws IOException on failure
*/
public static
<G extends GraphHead, V extends Vertex, E extends Edge>
AsciiGraphLoader<G, V, E> fromFile(String fileName,
GradoopConfig<G, V, E> config) throws IOException {
ElementFactoryProvider<G, V, E> elementFactoryProvider)
throws IOException {
return new AsciiGraphLoader<>(new GDLHandler.Builder()
.setDefaultGraphLabel(GradoopConstants.DEFAULT_GRAPH_LABEL)
.setDefaultVertexLabel(GradoopConstants.DEFAULT_VERTEX_LABEL)
.setDefaultEdgeLabel(GradoopConstants.DEFAULT_EDGE_LABEL)
.buildFromFile(fileName),
config);
elementFactoryProvider);
}

/**
* Creates an AsciiGraphLoader from the given ASCII GDL file.
*
* @param inputStream File that contains a GDL script
* @param config Gradoop configuration
* @param <G> EPGM graph head type
* @param <V> EPGM vertex type
* @param <E> EPGM edge type
* @param inputStream File that contains a GDL script
* @param elementFactoryProvider Factory provider for graph elements.
* @param <G> graph head type
* @param <V> vertex type
* @param <E> edge type
*
* @return AsciiGraphLoader
* @throws IOException on failure
*/
public static
<G extends GraphHead, V extends Vertex, E extends Edge>
AsciiGraphLoader<G, V, E> fromStream(InputStream inputStream,
GradoopConfig<G, V, E> config) throws IOException {
ElementFactoryProvider<G, V, E> elementFactoryProvider)
throws IOException {
return new AsciiGraphLoader<>(new GDLHandler.Builder()
.setDefaultGraphLabel(GradoopConstants.DEFAULT_GRAPH_LABEL)
.setDefaultVertexLabel(GradoopConstants.DEFAULT_VERTEX_LABEL)
.setDefaultEdgeLabel(GradoopConstants.DEFAULT_EDGE_LABEL)
.buildFromStream(inputStream),
config);
elementFactoryProvider);
}

/**
@@ -473,13 +475,13 @@ private void initEdges() {
}

/**
* Creates a new EPGMGraph from the GDL Loader.
* Creates a new Graph from the GDL Loader.
*
* @param g graph from GDL Loader
* @return EPGM graph head
* @return graph head
*/
private G initGraphHead(Graph g) {
G graphHead = (G) config.getGraphHeadFactory().createGraphHead(
G graphHead = elementFactoryProvider.getGraphHeadFactory().createGraphHead(
g.getLabel(), Properties.createFromMap(g.getProperties()));
graphHeadIds.put(g.getId(), graphHead.getId());
graphHeads.put(graphHead.getId(), graphHead);
@@ -490,12 +492,12 @@ private G initGraphHead(Graph g) {
* Creates a new Vertex from the GDL Loader or updates an existing one.
*
* @param v vertex from GDL Loader
* @return EPGM vertex
* @return vertex
*/
private V initVertex(org.s1ck.gdl.model.Vertex v) {
V vertex;
if (!vertexIds.containsKey(v.getId())) {
vertex = (V) config.getVertexFactory().createVertex(
vertex = elementFactoryProvider.getVertexFactory().createVertex(
v.getLabel(),
Properties.createFromMap(v.getProperties()),
createGradoopIdSet(v));
@@ -512,12 +514,12 @@ private V initVertex(org.s1ck.gdl.model.Vertex v) {
* Creates a new Edge from the GDL Loader.
*
* @param e edge from GDL loader
* @return EPGM edge
* @return edge
*/
private E initEdge(org.s1ck.gdl.model.Edge e) {
E edge;
if (!edgeIds.containsKey(e.getId())) {
edge = (E) config.getEdgeFactory().createEdge(
edge = elementFactoryProvider.getEdgeFactory().createEdge(
e.getLabel(),
vertexIds.get(e.getSourceVertexId()),
vertexIds.get(e.getTargetVertexId()),
@@ -23,15 +23,21 @@
import org.apache.flink.core.memory.DataOutputView;
import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
import org.apache.flink.types.Value;
import org.gradoop.common.config.GradoopConfig;
import org.gradoop.common.model.api.entities.EdgeFactory;
import org.gradoop.common.model.api.entities.Element;
import org.gradoop.common.model.api.entities.ElementFactoryProvider;
import org.gradoop.common.model.api.entities.GraphElement;
import org.gradoop.common.model.api.entities.GraphHeadFactory;
import org.gradoop.common.model.api.entities.Identifiable;
import org.gradoop.common.model.api.entities.VertexFactory;
import org.gradoop.common.model.impl.comparators.IdentifiableComparator;
import org.gradoop.common.model.impl.id.GradoopId;
import org.gradoop.common.model.impl.pojo.EPGMEdge;
import org.gradoop.common.model.impl.pojo.EPGMEdgeFactory;
import org.gradoop.common.model.impl.pojo.EPGMGraphHead;
import org.gradoop.common.model.impl.pojo.EPGMGraphHeadFactory;
import org.gradoop.common.model.impl.pojo.EPGMVertex;
import org.gradoop.common.model.impl.pojo.EPGMVertexFactory;
import org.gradoop.common.model.impl.properties.PropertyValue;
import org.gradoop.common.util.AsciiGraphLoader;

@@ -103,6 +109,12 @@

private static Comparator<Identifiable> ID_COMPARATOR = new IdentifiableComparator();

/**
* Singleton instance of a EPGM ElementFactoryProvider.
*/
private static ElementFactoryProvider<EPGMGraphHead, EPGMVertex, EPGMEdge> epgmElementFactoryProvider =
null;

static {
MAP_VAL_9.put(PropertyValue.create(KEY_0), PropertyValue.create(NULL_VAL_0));
MAP_VAL_9.put(PropertyValue.create(KEY_1), PropertyValue.create(BOOL_VAL_1));
@@ -165,6 +177,37 @@
SUPPORTED_PROPERTIES.put(KEY_f, SET_VAL_f);
}

/**
* Returns a {@link ElementFactoryProvider} able to create EPGM elements.
*
* @return ElementFactoryProvider for EPGM elements
*/
public static ElementFactoryProvider<EPGMGraphHead, EPGMVertex, EPGMEdge> getEPGMElementFactoryProvider() {
if (epgmElementFactoryProvider == null) {
epgmElementFactoryProvider = new ElementFactoryProvider<EPGMGraphHead, EPGMVertex, EPGMEdge>() {
GraphHeadFactory<EPGMGraphHead> graphHeadFactory = new EPGMGraphHeadFactory();
VertexFactory<EPGMVertex> vertexFactory = new EPGMVertexFactory();
EdgeFactory<EPGMEdge> edgeFactory = new EPGMEdgeFactory();

@Override
public GraphHeadFactory<EPGMGraphHead> getGraphHeadFactory() {
return graphHeadFactory;
}

@Override
public VertexFactory<EPGMVertex> getVertexFactory() {
return vertexFactory;
}

@Override
public EdgeFactory<EPGMEdge> getEdgeFactory() {
return edgeFactory;
}
};
}
return epgmElementFactoryProvider;
}

/**
* Creates a social network as a basis for tests.
* <p/>
@@ -176,11 +219,8 @@
*/
public static AsciiGraphLoader<EPGMGraphHead, EPGMVertex, EPGMEdge> getSocialNetworkLoader()
throws IOException {

GradoopConfig<EPGMGraphHead, EPGMVertex, EPGMEdge> config = GradoopConfig.getDefaultConfig();

InputStream inputStream = GradoopTestUtils.class.getResourceAsStream(SOCIAL_NETWORK_GDL_FILE);
return AsciiGraphLoader.fromStream(inputStream, config);
return AsciiGraphLoader.fromStream(inputStream, getEPGMElementFactoryProvider());
}

/**

0 comments on commit 3479c1f

Please sign in to comment.
You can’t perform that action at this time.