Skip to content

Instantly share code, notes, and snippets.

@jazzido
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzido/edfb9a5b03d0c3b8f5e5 to your computer and use it in GitHub Desktop.
Save jazzido/edfb9a5b03d0c3b8f5e5 to your computer and use it in GitHub Desktop.
schema creation + data insertion
conf = new BaseConfiguration()
conf.setProperty("storage.backend","cassandra")
conf.setProperty("storage.hostname", "localhost")
conf.setProperty("schema.default", "none")
conf.setProperty("cache.db-cache", true)
conf.setProperty("index.search.backend", "elasticsearch")
conf.setProperty("index.search.hostname", "localhost")
g = TitanFactory.open(conf)
mgmt = g.getManagementSystem()
// schema
mgmt.makeEdgeLabel('isIn').multiplicity(SIMPLE).make()
node_label = mgmt.makeVertexLabel('country').make()
country_name = mgmt.makePropertyKey('countryname').dataType(String.class).make()
country_tld = mgmt.makePropertyKey('countrytld').dataType(String.class).make()
mgmt.buildIndex('idxcountrytld', Vertex.class).addKey(country_tld).unique().indexOnly(node_label).buildCompositeIndex()
mgmt.buildIndex('idxcountryname', Vertex.class).addKey(country_name).indexOnly(node_label).buildMixedIndex('search')
node_label = mgmt.makeVertexLabel('institution').make()
institution_domain = mgmt.makePropertyKey('institutiondomain').dataType(String.class).make()
institution_id = mgmt.makePropertyKey('institutionid').dataType(String.class).make()
institution_name = mgmt.makePropertyKey('institutionname').dataType(String.class).make()
mgmt.buildIndex('idxinstitutiondomain', Vertex.class).addKey(institution_domain).indexOnly(node_label).buildMixedIndex('search')
mgmt.buildIndex('idxinstitutionid', Vertex.class).addKey(institution_id).unique().indexOnly(node_label).buildCompositeIndex()
mgmt.buildIndex('idxinstitutionname', Vertex.class).addKey(institution_name).indexOnly(node_label).buildMixedIndex('search')
mgmt.commit()
// data
txn = g.newTransaction()
ar = txn.addVertexWithLabel('country')
ar.setProperty('countryname', 'Argentina')
ar.setProperty('countrytld', 'ar')
uns = txn.addVertexWithLabel('institution')
uns.setProperty('institutionname', 'UNS')
uns.setProperty('institutiondomain', 'uns.edu.ar')
uns.setProperty('institutionid', 'uns')
uns.addEdge('isIn', ar)
txn.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment