Skip to content

Instantly share code, notes, and snippets.

@sarmbruster
sarmbruster / .gitignore
Created May 6, 2012 12:46
gitignore file for grails applications
*.iws
*.ipr
*.iml
.classpath
.DS_Store
.project
.settings
*.launch
*.tmproj
*.log
@sarmbruster
sarmbruster / upgrade_neo4j.groovy
Last active October 9, 2015 17:28
groovy script for upgrading neo4j datastores
// hackish script for upgrading a neo4j datastore
// uncomment one of Grab annotations below to match the desired target version of neo4j
def cli = new CliBuilder(usage: 'upgrade_neo4j.groovy -[h] [graphdb-directory]',
header: '''
upgrades a Neo4j database to any desired versions. Notes:
* take backup before running this
* upgrades must be done step-by-step, e.g. 1.5 -> 1.6, 1.6 -> 1.7
* to specify the upgrade for a step, enable the @Grab line in the script
@Grab(group = 'org.neo4j', module='neo4j-community', version='1.8.M06')
import org.neo4j.kernel.EmbeddedGraphDatabase
import org.neo4j.cypher.ExecutionEngine
import org.neo4j.cypher.ExecutionResult
import org.neo4j.graphdb.Direction
import org.neo4j.graphdb.Node
import org.neo4j.tooling.GlobalGraphOperations
def dir = '/tmp/poc'
new File(dir).deleteDir(); // clean up directory from prev. runs
@Grab(group="org.neo4j", module="neo4j-community", version="1.9.M05")
import org.neo4j.graphdb.*
// make sure we start with empty dir
def graphDbDir = "/tmp/neo4j-dummy"
new File(graphDbDir).deleteDir()
def graphDb = new org.neo4j.kernel.EmbeddedGraphDatabase(graphDbDir)
def indexer = graphDb.index().relationshipAutoIndexer
@GrabResolver(name='grails-core', root='http://repo.grails.org/grails/core')
@Grab(group='org.grails', module='grails-datastore-gorm-mongo', version='1.0.0.BUILD-SNAPSHOT')
@Grab(group='org.slf4j', module='slf4j-simple', version='1.6.1')
import grails.persistence.*
import org.grails.datastore.gorm.mongo.config.*
MongoDatastoreConfigurer.configure("myDatabase", Book)
Book.withSession {
@sarmbruster
sarmbruster / cypher_csv.groovy
Created June 8, 2013 20:10
simple groovy script to execute a cypher query (args[1]) against a local datastore (args[0]) and format output as csv
@Grab(group="org.neo4j", module="neo4j-cypher", version="1.9")
@Grab(group='net.sf.opencsv', module='opencsv', version='2.3')
import org.neo4j.kernel.EmbeddedGraphDatabase
import org.neo4j.cypher.javacompat.ExecutionEngine
import au.com.bytecode.opencsv.CSVWriter
assert args, "specify location of graph.db"
def db = new org.neo4j.kernel.EmbeddedGraphDatabase(args[0])
@sarmbruster
sarmbruster / neo4jEmbeddedSpring.xml
Last active December 19, 2015 22:39
Spring bean definition in XML to create a Neo4j GraphDatabaseService using the GraphDatabaseFactory
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
@sarmbruster
sarmbruster / neo4j_jdbc_cypher.groovy
Last active December 20, 2015 07:38
how to use Neo4j's Cypher over JDBC from a groovy script
@GrabResolver(name="neo4j", root="http://m2.neo4j.org/")
@GrabResolver(name="restlet", root="http://maven.restlet.org/")
@GrabConfig(systemClassLoader = true)
@Grab('org.neo4j:neo4j-jdbc:1.9')
import groovy.sql.*
def sql = Sql.newInstance('jdbc:neo4j://localhost:7474/')
println "simple cypher statement"
@sarmbruster
sarmbruster / neo4jHighlyAvailableSpring.xml
Created August 13, 2013 16:02
how to instantiate a HighlyAvailableGraphdatabase via HighlyAvailableGraphDatabaseFactory using Spring for Neo4j 1.9
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
/*
small groovy script to demo how to spawn a neo4j ha instance from own code *and* run a server on top of it
requirement for this script:
* a 3 member cluster is assumed, so either use this script 3 times with adopted config or run 2 Neo4j servers + this script
* have two files neo4j-server.properties and neo4.properties in the same directory with this script, having the following contents:
neo4j-server.properties:
========================