Giter Site home page Giter Site logo

graphtransactionexample's Introduction

GraphTransactionExample

This is a simple DSE Graph Transaction example using string passing via the Java driver.

Overview

This example contains the current recommended approach to achieving transaction [durability] (https://en.wikipedia.org/wiki/Durability_(database_systems)) and atomicity with DSE Graph.

The string execution functionality that exists within the DSE Graph drivers enables the mechanism to provide atomicity with Graph transactions. When a Gremlin string is executed within a session, and assuming the default mode for logged_batch is true for the graph, the contents of that string are treated as a Cassandra Batch. That is, the entire contents of the Gremlin string are ensured to succeed if any of the Gremlin string succeeds.

One can use the Gremlin String context to create advanced DSE Graph “transactions”. To do this, first create the logic to be executed in the transaction in a separate groovy or java file. Place this file as a resource in your java project. Finally use something like the following method to execute the string in a session.

  public String getQuery(String name) {
        try {
            return IOUtils.toString(getClass().getResourceAsStream(name+".groovy"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

Example

This example contains 2 files:

  1. src\main\java\Example.java - the java code that executes the Gremlin traversal with parameters
  2. src\main\resources\Traversal.groovy - the file that contains the Gremline traversal

To execute this example, you will need to create a simple Graph in DSE Graph that contains:

  1. a Vertex Label - Customer
  2. an Edge - Related

Here is the ddl to create the schema.

schema.propertyKey("rType").Text().single().create()
schema.propertyKey("name").Text().single().create()
schema.propertyKey("age").Text().single().create()
schema.edgeLabel("related").multiple().properties("rType").create()
schema.vertexLabel("customer").properties("name", "age").create()
schema.edgeLabel("related").connection("customer", "customer").add()

graphtransactionexample's People

Contributors

jlacefie avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.