Home > Software Center, Structured Storage > Get Started with DEX Graph Database

Get Started with DEX Graph Database

DEX claimed itself as a high-performance and scalable graph database, which is very attractive for NoSQL database applications. View here for the impressive comparison between DEX and peering products. I also wrote a post about graph databases to compare DEX with others, and the result shows DEX is among the best.

However, the example in Java API for DEX version 4.3 is not updated — they use old examples in old version, which are no longer compatible. A migration manual is useful when you want to write your code based on new version; but not always. This post will show you how to create DEX applications based on new version 4.3.

  1. Download DEX here. The free version can support up to 1 million nodes, which is a constraint compared with Neo4J.
  2. An instruction for use can be found here, but the example in Appendix A is for old version. To deploy, unpack it and add /lib/dexjava.jar to your Java project. Really neat.
  3. The following is the Java code to create new node types, new edge types, select nodes from a specific node type, select nodes from a specific property, and get neighbors of a node. It is straight-forward and should be not hard to read. It works under new version 4.2 & 4.3!

(To understand the Java code, you need to know DEX is based on property graph model)

import java.io.FileNotFoundException;
import java.util.Date;
import com.sparsity.dex.gdb.AttributeKind;
import com.sparsity.dex.gdb.Condition;
import com.sparsity.dex.gdb.DataType;
import com.sparsity.dex.gdb.Database;
import com.sparsity.dex.gdb.Dex;
import com.sparsity.dex.gdb.DexConfig;
import com.sparsity.dex.gdb.EdgesDirection;
import com.sparsity.dex.gdb.Graph;
import com.sparsity.dex.gdb.Objects;
import com.sparsity.dex.gdb.ObjectsIterator;
import com.sparsity.dex.gdb.Session;
import com.sparsity.dex.gdb.Value;

public class example {

	public static void main(String[] args)
			throws FileNotFoundException {
		Dex dex = new Dex(new DexConfig());
		Database gpool = dex.create("example.dex",
		Session sess = gpool.newSession();

		// node types
		Graph dbg = sess.getGraph();
		int person = dbg.newNodeType("PERSON");
		int name = dbg.newAttribute(person, "NAME",
				DataType.String, AttributeKind.Indexed);
		int age = dbg.newAttribute(person, "AGE",
				DataType.Integer, AttributeKind.Basic);
		long p1 = dbg.newNode(person);
		dbg.setAttribute(p1, name,
				new Value().setString("JOHN"));
		dbg.setAttribute(p1, age,
				new Value().setInteger(18));
		long p2 = dbg.newNode(person);
		dbg.setAttribute(p2, name,
				new Value().setString("KELLY"));
		long p3 = dbg.newNode(person);
		dbg.setAttribute(p3, name,
				new Value().setString("MARY"));

		// edge types
		int phones = dbg.newEdgeType("PHONES", true, true);
		int when = dbg.newAttribute(phones, "WHEN",
				DataType.Timestamp, AttributeKind.Basic);
		long e4 = dbg.newEdge(phones, p1, p3);
		dbg.setAttribute(e4, when,
				new Value().setTimestamp(new Date()));
		long e5 = dbg.newEdge(phones, p1, p3);
		dbg.setAttribute(e5, when,
				new Value().setTimestamp(new Date()));
		long e6 = dbg.newEdge(phones, p3, p2);
		dbg.setAttribute(e6, when,
				new Value().setTimestamp(new Date()));

		// Select all objects from a specific node type
		Objects persons = dbg.select(person);
		ObjectsIterator it = persons.iterator();
		while (it.hasNext()) {
			long p = it.next();
			Value v = new Value();
			dbg.getAttribute(p, name, v);

		// get nodes from a specific property
		persons = dbg.select(name, Condition.Equal,
				new Value().setString("JOHN"));
		it = persons.iterator();
		while (it.hasNext()) {
			long p = it.next();
			Value v = new Value();
			dbg.getAttribute(p, name, v);

		// get neighbors
		persons = dbg.explode(p1, phones,
		it = persons.iterator();

  1. 2011-12-13 at 11:06 AM

    Great example to start with DEX!!

    About the restriction on 1M objects, we indeed provide free temporary licenses for bigger graphs (up to billions of objects) for research and evaluation purposes. For now, with a mail with the researcher/evaluator & little project info we create them, we should make this information available in the website as well.

    Also, thanks to the old version example alert!

  1. 2011-11-30 at 11:02 PM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: