forked from pdlug/pacer-orient
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4fb4b45
Showing
14 changed files
with
462 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in pacer-graph.gemspec | ||
gemspec |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'yaml' | ||
|
||
module Pacer | ||
OrientIndex = com.tinkerpop.blueprints.pgm.impls.orientdb.OrientIndex | ||
|
||
class OrientIndex | ||
include IndexMixin | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Pacer | ||
module Orient | ||
VERSION = "1.0.0" | ||
JAR = "pacer-orient-#{ VERSION }-standalone.jar" | ||
JAR_PATH = "lib/#{ JAR }" | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.