Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pdlug committed May 6, 2011
0 parents commit 4fb4b45
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in pacer-graph.gemspec
gemspec
30 changes: 30 additions & 0 deletions README.md
@@ -0,0 +1,30 @@
# OrientDB Graph Database Adapter for Pacer

[Pacer](https://github.com/pangloss/pacer) is a
[JRuby](http://jruby.org) graph traversal framework built on the
[Tinkerpop](http://www.tinkerpop.com) stack.

This plugin enables full
[OrientDB](http://http://www.orientechnologies.com/) graph support in Pacer.


## Usage

Here is how you open a OrientDB graph in Pacer.

require 'pacer'
require 'pacer-orient'

# Graph takes an OrientDB URL, e.g. disk back graph:
graph = Pacer.orient 'local:path/to/graph'

# In memory graph
graph = Pacer.orient 'memory:foo'

# Remote graph
graph = Pacer.orient 'remote:localhost/graph', 'username', 'password'

All other operations are identical across graph implementations (except
where certain features are not supported). See Pacer's documentation for
more information.

28 changes: 28 additions & 0 deletions Rakefile
@@ -0,0 +1,28 @@
require 'bundler'
Bundler::GemHelper.install_tasks

file 'pom.xml' => 'lib/pacer-orient/version.rb' do
pom = File.read 'pom.xml'
when_writing('Update pom.xml version number') do
updated = false
open 'pom.xml', 'w' do |f|
pom.each_line do |line|
if not updated and line =~ %r{<version>.*</version>}
f << line.sub(%r{<version>.*</version>}, "<version>#{ Pacer::Orient::VERSION }</version>")
updated = true
else
f << line
end
end
end
end
end

file Pacer::Orient::JAR_PATH => 'pom.xml' do
when_writing("Execute 'mvn package' task") do
system('mvn clean package')
end
end

task :build => Pacer::Orient::JAR_PATH
task :install => Pacer::Orient::JAR_PATH
Binary file added lib/pacer-orient-1.0.0-standalone.jar
Binary file not shown.
10 changes: 10 additions & 0 deletions lib/pacer-orient.rb
@@ -0,0 +1,10 @@
require 'pacer-orient/version'

require 'pacer'
require Pacer::Orient::JAR

require 'pacer-orient/vertex'
require 'pacer-orient/edge'
require 'pacer-orient/index'
require 'pacer-orient/graph'
require 'pacer-orient/rspec' if defined? RSpec
36 changes: 36 additions & 0 deletions lib/pacer-orient/edge.rb
@@ -0,0 +1,36 @@
require 'yaml'

module Pacer
OrientEdge = com.tinkerpop.blueprints.pgm.impls.orientdb.OrientEdge

# Extend the java class imported from blueprints.
class OrientEdge
include Pacer::Core::Graph::EdgesRoute
include ElementMixin
include EdgeMixin

def in_vertex(extensions = nil)
v = inVertex
v.graph = graph
if extensions.is_a? Enumerable
v.add_extensions extensions
elsif extensions
v.add_extensions [extensions]
else
v
end
end

def out_vertex(extensions = nil)
v = outVertex
v.graph = graph
if extensions.is_a? Enumerable
v.add_extensions extensions
elsif extensions
v.add_extensions [extensions]
else
v
end
end
end
end
121 changes: 121 additions & 0 deletions lib/pacer-orient/graph.rb
@@ -0,0 +1,121 @@
require 'yaml'

module Pacer
OrientGraph = com.tinkerpop.blueprints.pgm.impls.orientdb.OrientGraph
OrientElement = com.tinkerpop.blueprints.pgm.impls.orientdb.OrientElement

# Add 'static methods' to the Pacer namespace.
class << self
# Return a graph for the given path. Will create a graph if none exists at
# that location. (The graph is only created if data is actually added to it).
def orient(url, username = nil, password = nil)
Pacer.starting_graph(self, url) do
if username
OrientGraph.new(url, username, password)
else
OrientGraph.new(url)
end
end
end
end


# Extend the java class imported from blueprints.
class OrientGraph
include GraphMixin
include GraphTransactionsMixin
include ManagedTransactionsMixin
include Pacer::Core::Route
include Pacer::Core::Graph::GraphRoute

# Override to return an enumeration-friendly array of vertices.
def get_vertices
getVertices.to_route(:graph => self, :element_type => :vertex)
end

# Override to return an enumeration-friendly array of edges.
def get_edges
getEdges.to_route(:graph => self, :element_type => :edge)
end

def element_type(et = nil)
return nil unless et
if et == OrientVertex or et == OrientEdge or et == OrientElement
et
else
case et
when :vertex, com.tinkerpop.blueprints.pgm.Vertex, VertexMixin
OrientVertex
when :edge, com.tinkerpop.blueprints.pgm.Edge, EdgeMixin
OrientEdge
when :mixed, com.tinkerpop.blueprints.pgm.Element, ElementMixin
OrientElement
when :object
Object
else
if et == Object
Object
elsif et == OrientVertex.java_class.to_java
OrientVertex
elsif et == OrientEdge.java_class.to_java
OrientEdge
else
raise ArgumentError, 'Element type may be one of :vertex or :edge'
end
end
end
end

def sanitize_properties(props)
pairs = props.map do |name, value|
[name, encode_property(value)]
end
Hash[pairs]
end

def encode_property(value)
case value
when nil
nil
when String
value = value.strip
value = nil if value == ''
value
when Numeric
if value.is_a? Bignum
value.to_yaml
else
value
end
else
value.to_yaml
end
end

if RUBY_VERSION =~ /^1.9/
def decode_property(value)
if value.is_a? String and value[0, 5] == '%YAML'
YAML.load(value)
else
value
end
end
else
def decode_property(value)
if value.is_a? String and value[0, 3] == '---'
YAML.load(value)
else
value
end
end
end

def supports_circular_edges?
false
end

def supports_custom_element_ids?
false
end
end
end
9 changes: 9 additions & 0 deletions lib/pacer-orient/index.rb
@@ -0,0 +1,9 @@
require 'yaml'

module Pacer
OrientIndex = com.tinkerpop.blueprints.pgm.impls.orientdb.OrientIndex

class OrientIndex
include IndexMixin
end
end
43 changes: 43 additions & 0 deletions lib/pacer-orient/rspec.rb
@@ -0,0 +1,43 @@
class Rspec::GraphRunner
module Orient
def all(usage_style = :read_write, indices = true, &block)
super
orient(usage_style, indices, &block)
end

def orient(usage_style = :read_write, indices = true, &block)
for_graph('orient', usage_style, indices, true, orient_graph, orient_graph2, orient_graph_no_indices, block)
end

protected

def orient_graph
return @orient_graph if @orient_graph
path1 = File.expand_path('tmp/spec.orient')
dir = Pathname.new(path1)
dir.rmtree if dir.exist?
@orient_graph = Pacer.orient("local:#{path1}")
end

def orient_graph2
return @orient_graph2 if @orient_graph2
path2 = File.expand_path('tmp/spec.orient.2')
dir = Pathname.new(path2)
dir.rmtree if dir.exist?
@orient_graph2 = Pacer.orient("local:#{path2}")
end

def orient_graph_no_indices
return @orient_graph_no_indices if @orient_graph_no_indices
path3 = File.expand_path('tmp/spec_no_indices.orient')
dir = Pathname.new(path3)
dir.rmtree if dir.exist?
@orient_graph_no_indices = Pacer.orient("local:#{path3}")
@orient_graph_no_indices.drop_index :vertices
@orient_graph_no_indices.drop_index :edges
@orient_graph_no_indices
end
end

include Orient
end
7 changes: 7 additions & 0 deletions lib/pacer-orient/version.rb
@@ -0,0 +1,7 @@
module Pacer
module Orient
VERSION = "1.0.0"
JAR = "pacer-orient-#{ VERSION }-standalone.jar"
JAR_PATH = "lib/#{ JAR }"
end
end
11 changes: 11 additions & 0 deletions lib/pacer-orient/vertex.rb
@@ -0,0 +1,11 @@
require 'yaml'

module Pacer
OrientVertex = com.tinkerpop.blueprints.pgm.impls.orientdb.OrientVertex
# Extend the java class imported from blueprints.
class OrientVertex
include Pacer::Core::Graph::VerticesRoute
include ElementMixin
include VertexMixin
end
end
23 changes: 23 additions & 0 deletions pacer-orient.gemspec
@@ -0,0 +1,23 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "pacer-orient/version"

Gem::Specification.new do |s|
s.name = "pacer-orient"
s.version = Pacer::Orient::VERSION
s.platform = 'jruby'
s.authors = ["Paul Dlug"]
s.email = ["paul.dlug@gmail.com"]
s.homepage = "http://http://www.orientechnologies.com/"
s.summary = %q{OrientDB jars and related code for Pacer}
s.description = s.summary

s.add_dependency 'pacer', "~> 0.7.0"

s.rubyforge_project = "pacer-orient"

s.files = `git ls-files`.split("\n") + [Pacer::Orient::JAR_PATH]
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
end

0 comments on commit 4fb4b45

Please sign in to comment.