@Override public <I extends Io> I io(final Io.Builder<I> builder) { if (builder.requiresVersion(GryoVersion.V1_0) || builder.requiresVersion(GraphSONVersion.V1_0)) { return (I) builder.graph(this).onMapper(mapper -> mapper.addRegistry(JanusGraphIoRegistryV1d0.getInstance())).create(); } else if (builder.requiresVersion(GraphSONVersion.V2_0)) { return (I) builder.graph(this).onMapper(mapper -> mapper.addRegistry(JanusGraphIoRegistry.getInstance())).create(); } else { return (I) builder.graph(this).onMapper(mapper -> mapper.addRegistry(JanusGraphIoRegistry.getInstance())).create(); } }
@Test public void testGeoShapeSerializationReadWriteAsGraphSONEmbedded() throws Exception { GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); GraphSONMapper m = graph.io(IoCore.graphson()).mapper().embedTypes(true).create(); GraphWriter writer = graph.io(IoCore.graphson()).writer().mapper(m).create(); FileOutputStream fos = new FileOutputStream("/tmp/test.json"); writer.writeGraph(fos, graph); clearGraph(config); open(config); GraphReader reader = graph.io(IoCore.graphson()).reader().mapper(m).create(); FileInputStream fis = new FileInputStream("/tmp/test.json"); reader.readGraph(fis, graph); TitanIndexTest.assertGraphOfTheGods(graph); }
@Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> data() { final GraphSONMapper v1mapper = GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistryV1d0.getInstance()).create(); final GraphSONMapper v2mapper = GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistry.getInstance()).create(); final GraphSONMapper v3mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistry.getInstance()).create(); return Arrays.asList(new Object[][]{ {"graphson-v1-embedded", (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v1mapper).create(), (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v1mapper).create()}, {"graphson-v2-embedded", (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v2mapper).create(), (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v2mapper).create()}, {"graphson-v3", (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v3mapper).create(), (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v3mapper).create()}, {"gryo", (Function<Graph, GraphReader>) g -> g.io(IoCore.gryo()).reader().mapper(g.io(IoCore.gryo()).mapper().create()).create(), (Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().mapper(g.io(IoCore.gryo()).mapper().create()).create()} }); }
@Test public void testGeoShapeSerializationReadWriteAsGryo() throws Exception { GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); graph.io(IoCore.gryo()).writeGraph("/tmp/test.kryo"); clearGraph(config); open(config); graph.io(IoCore.gryo()).readGraph("/tmp/test.kryo"); TitanIndexTest.assertGraphOfTheGods(graph); } }
private void testSerialization(Function<Geoshape,Geoshape> makeGeoshape) throws Exception { if (makeGeoshape != null) { addGeoshape(makeGeoshape); } GraphWriter writer = writerMaker.apply(graph); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); writer.writeGraph(outputStream, graph); clearGraph(config); open(config); GraphReader reader = readerMaker.apply(graph); ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); reader.readGraph(inputStream, graph); JanusGraphIndexTest.assertGraphOfTheGods(graph); if (makeGeoshape != null) { assertGeoshape(makeGeoshape); } }
private void addRequestMessageEntry(final Object obj, final String title, final String description) { final List<Compatibility> incompatibilityList = Compatibilities.with(GryoCompatibility.class) .before("3.0") .match(); final Compatibility[] incompatibilities = new Compatibility[incompatibilityList.size()]; incompatibilityList.toArray(incompatibilities); addEntry("RequestMessage", obj, title, description, incompatibilities); }
@SuppressWarnings("rawtypes") @Override public void register(Class<? extends Io> ioClass, Class clazz, Object ser) { super.register(ioClass, clazz, ser); } }
private static boolean afterIo(final Compatibility version, final String after) { return versionCompare(version.getVersion(), after) > 0; }
private static boolean afterRelease(final Compatibility version, final String after) { return versionCompare(version.getReleaseVersion(), after) > 0; }
/** * Finds {@link Compatibility} instances between (and not inclusive of) the specified versions. */ public Compatibilities betweenReleases(final String start, final String end) { return beforeRelease(end).afterRelease(start); }
private GraphSONWriter(final Builder builder) { mapper = builder.mapper.createMapper(); wrapAdjacencyList = builder.wrapAdjacencyList; }
/** * Get the vertices at the specified graph location. * * @param location the location of the graph (or the root location and search will be made) * @param readerClass the class of the parser that understands the graph format * @return an iterator of vertices. */ public default Iterator<Vertex> head(final String location, final Class readerClass) { return this.head(location, readerClass, Integer.MAX_VALUE); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public <I extends Io> I io(final Io.Builder<I> builder) { return (I) builder.graph(this).onMapper(mapper -> mapper.addRegistry(HugeGraphIoRegistry.instance()) ).create(); }
private static boolean beforeIo(final Compatibility version, final String before) { return versionCompare(version.getVersion(), before) < 0; }
private static boolean beforeRelease(final Compatibility version, final String before) { return versionCompare(version.getReleaseVersion(), before) < 0; }
/** * Get the {@link KeyValue} data at the specified memory location. * * @param location the root location of the data * @param memoryKey the memory key * @param readerClass the class of the parser that understands the memory format * @return an iterator of key-values. */ public default <K, V> Iterator<KeyValue<K, V>> head(final String location, final String memoryKey, final Class readerClass) { return this.head(location, memoryKey, readerClass, Integer.MAX_VALUE); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public <I extends Io> I io(final Io.Builder<I> builder) { return (I) builder.graph(this).onMapper(mapper -> mapper.addRegistry(HugeGraphIoRegistry.instance()) ).create(); }
/** * Get a string representation of the specified number of lines at the data source location. * * @param location the data source location * @return an iterator of lines */ public default Iterator<String> head(final String location) { return this.head(location, Integer.MAX_VALUE); }