Created
July 24, 2010 10:41
-
-
Save anonymous/488604 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package neo4jtest | |
import org.neo4j.kernel._ | |
import org.neo4j.graphdb._ | |
import org.neo4j.graphdb.DynamicRelationshipType | |
import scala.collection.JavaConversions._ // 2010-07-24 00:28:55 - dmilith - required to do foreach on iterators f.e. | |
object Neo4j extends Neo4jWrapper { | |
def main(args: Array[String]): Unit = { | |
println("Hi! My name is") | |
val gdb = new EmbeddedGraphDatabase("/Users/dmilith/tmp/test.graphdb") | |
println("Hi! My name is not") | |
var root: Node = null | |
var dmilith: Node = null | |
var teamon: Node = null | |
var dupa: Node = null | |
var configs: List[Node] = List[Node]() | |
val tx = gdb.beginTx | |
try { | |
// all Neo4j operations that work with the graph | |
// ... | |
root = gdb.createNode | |
dmilith = gdb.createNode | |
teamon = gdb.createNode | |
dupa = gdb.createNode | |
configs :::= List[Node](gdb.createNode, gdb.createNode) | |
root.setProperty("nick", "root") | |
configs.first.setProperty("nick", "config1") | |
configs.last.setProperty("nick", "config") | |
dmilith.setProperty("nick", "dmilith") | |
teamon.setProperty("nick", "teamon") | |
dupa.setProperty("nick", "dupa") | |
// Relationship relationship = firstNode.createRelationshipTo( secondNode, MyRelationshipTypes.KNOWS ); | |
root --> "User" --> dmilith | |
root --> "User" --> teamon | |
dmilith --> "Config" --> configs.first | |
// teamon --> "Config" --> configs.last | |
for (i <- dmilith.getRelationships) { | |
println("i: " + i.getEndNode) | |
} | |
println("dmilith relations: " + (for (i <- dmilith.getRelationships) yield ("" + i.getStartNode.getProperty("nick") + " --> " + i.getEndNode.getProperty("nick")))) | |
println("dmilith has at least one relation: " + dmilith.hasRelationship) | |
println("dmilith has User relation: " + dmilith.hasRelationship("User")) | |
println("dmilith has Config relation: " + dmilith.hasRelationship("Config")) | |
println("teamon has got Config relation: " + teamon.hasRelationship("Config")) | |
println("dupa has got at least one relation: " + dupa.hasRelationship) | |
println("root has got at least one relation: " + root.hasRelationship) | |
println("root has got User relation: " + root.hasRelationship("User")) | |
tx.success | |
} | |
finally { | |
tx.finish | |
} | |
// val teamon = gdb.createNode | |
// val relationType = DynamicRelationshipType.withName("Tag") | |
// val relationship = gdb.createRelationshipTo(node1, relationType) | |
// dmilith --> "VerKnowSys" | |
// teamon --> "VerKnowSys" | |
// dmilith --> "Programmer" | |
// teamon --> "Programmer" | |
println("Node stored in: " + gdb.getStoreDir) | |
gdb.shutdown | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment