pacer-neo4j2 2.0.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ module Pacer
2
+ module Neo4j2
3
+ class Graph
4
+ def lucene(query, opts = {})
5
+ opts = { back: self, element_type: :vertex }.merge opts
6
+ chain_route(opts.merge(query: query,
7
+ filter: :lucene,
8
+ index: choose_index(opts)))
9
+ end
10
+
11
+ private
12
+
13
+ def choose_index(opts)
14
+ et = opts[:element_type]
15
+ idx = opts[:index]
16
+ case idx
17
+ when String, Symbol
18
+ index(idx, et).index.raw_index
19
+ when Pacer::Wrappers::IndexWrapper
20
+ idx.index.raw_index
21
+ when com.tinkerpop.blueprints.Index
22
+ idx.raw_index
23
+ else
24
+ lucene_auto_index(et)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+ module Filter
32
+ module LuceneFilter
33
+ import org.neo4j.index.lucene.QueryContext
34
+
35
+ attr_accessor :index, :query, :sort_by, :reverse_numeric, :sort_numeric, :sort_by_score, :top, :fast
36
+
37
+ def count(max = nil)
38
+ iter = query_result
39
+ c = iter.count
40
+ if c >= 0
41
+ c
42
+ elsif max
43
+ iter.inject(0) do |n, _|
44
+ if n == max
45
+ return :max
46
+ else
47
+ n + 1
48
+ end
49
+ end
50
+ else
51
+ iter.inject(0) { |n, _| n + 1 }
52
+ end
53
+ ensure
54
+ iter.close
55
+ end
56
+
57
+ def sort_by_score!
58
+ self.sort_by_score = true
59
+ self
60
+ end
61
+
62
+ def sort(*keys)
63
+ self.sort_by = keys
64
+ self
65
+ end
66
+
67
+ def top_hits(n)
68
+ self.top = n
69
+ self
70
+ end
71
+
72
+ def fast!
73
+ self.fast = true
74
+ self
75
+ end
76
+
77
+ protected
78
+
79
+ def build_query
80
+ qc = QueryContext.new(query)
81
+ qc = qc.tradeCorrectnessForSpeed if fast
82
+ qc = qc.top(top) if top
83
+ if sort_by_score
84
+ qc.sortByScore
85
+ elsif sort_by
86
+ qc.sort(*[*sort_by].map(&:to_s))
87
+ elsif sort_numeric
88
+ qc.sortNumeric(sort_numeric, false)
89
+ elsif reverse_numeric
90
+ qc.sortNumeric(reverse_numeric, true)
91
+ else
92
+ qc
93
+ end
94
+ end
95
+
96
+ def query_result
97
+ index.query build_query
98
+ end
99
+
100
+ def source_iterator
101
+ pipe = Pacer::Neo4j2::RawVertexWrappingPipe.new graph
102
+ pipe.setStarts query_result
103
+ pipe.enablePath(true)
104
+ pipe
105
+ end
106
+
107
+ def inspect_string
108
+ "#{ inspect_class_name }(#{ query }) ~ #{ query_result.count }"
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,18 @@
1
+ module Pacer
2
+ module Neo4j2
3
+ class RawVertexWrappingPipe < Pacer::Pipes::RubyPipe
4
+ import com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Vertex
5
+
6
+ attr_reader :graph
7
+
8
+ def initialize(graph)
9
+ super()
10
+ @graph = graph.blueprints_graph
11
+ end
12
+
13
+ def processNextStart
14
+ Neo4j2Vertex.new starts.next, graph
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ class RSpec::GraphRunner
2
+ module Neo4j2
3
+ def all(usage_style = :read_write, indices = true, &block)
4
+ super
5
+ neo4j2(usage_style, indices, &block)
6
+ end
7
+
8
+ def neo4j2(usage_style = :read_write, indices = true, &block)
9
+ for_graph('neo4j2', usage_style, indices, true, neo2_graph, neo2_graph2, neo2_graph_no_indices, block)
10
+ end
11
+
12
+ protected
13
+
14
+ def neo2_graph
15
+ return @neo_graph if @neo_graph
16
+ path1 = File.expand_path('tmp/spec.neo4j2')
17
+ dir = Pathname.new(path1)
18
+ dir.rmtree if dir.exist?
19
+ @neo_graph = Pacer.neo4j2(path1)
20
+ end
21
+
22
+ def neo2_graph2
23
+ return @neo_graph2 if @neo_graph2
24
+ path2 = File.expand_path('tmp/spec.neo4j2.2')
25
+ dir = Pathname.new(path2)
26
+ dir.rmtree if dir.exist?
27
+ @neo_graph2 = Pacer.neo4j2(path2)
28
+ end
29
+
30
+ def neo2_graph_no_indices
31
+ return @neo_graph_no_indices if @neo_graph_no_indices
32
+ path3 = File.expand_path('tmp/spec_no_indices.neo4j2')
33
+ dir = Pathname.new(path3)
34
+ dir.rmtree if dir.exist?
35
+ @neo_graph_no_indices = Pacer.neo4j2(path3)
36
+ @neo_graph_no_indices
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ module Pacer
2
+ module Neo4j2
3
+ class TransactionEventHandler
4
+ include org.neo4j.graphdb.event.TransactionEventHandler
5
+
6
+ attr_reader :graph
7
+ attr_accessor :on_commit, :on_commit_failed, :before_commit
8
+
9
+ def initialize(graph)
10
+ @graph = graph
11
+ end
12
+
13
+ def unregister!
14
+ graph.drop_handler self
15
+ end
16
+
17
+ private
18
+
19
+ # Return value is passed to afterCommit or afterRollback, but some values can cause crashes.
20
+ def beforeCommit(data)
21
+ before_commit.call TxDataWrapper.new data, graph if before_commit
22
+ nil
23
+ end
24
+
25
+ def afterCommit(data, ignore)
26
+ on_commit.call TxDataWrapper.new data, graph if on_commit
27
+ end
28
+
29
+ # This is actually only called if the commit fails and then it internally tries to
30
+ # rollback. It seems that it's actually possible for it to fail to rollback here, too...
31
+ #
32
+ # An exception in beforeCommit can definitely trigger this.
33
+ #
34
+ # Regular rollbacks do not get seen by the transaction system and no callback happens.
35
+ def afterRollback(data, ignore)
36
+ on_commit_failed.call TxDataWrapper.new data, graph if on_commit_failed
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,101 @@
1
+ module Pacer
2
+ module Neo4j2
3
+ # Uses the interface defined here:
4
+ # http://api.neo4j.org/1.8/org/neo4j/graphdb/Path.html
5
+ #
6
+ # Note that I have removed methods that I didn't understand, assuming they are internal.
7
+ class TxDataWrapper
8
+ include Algo::Wrapping
9
+
10
+ attr_reader :graph, :tx
11
+
12
+ def initialize(tx, graph)
13
+ @tx = tx
14
+ @graph = graph
15
+ end
16
+
17
+ def created_v
18
+ tx.createdNodes.map { |n| wrap_vertex n }
19
+ end
20
+
21
+ def deleted_v
22
+ tx.deletedNodes.map { |n| wrap_vertex n }
23
+ end
24
+
25
+ def created_e
26
+ tx.createdRelationships.map { |n| wrap_edge n }
27
+ end
28
+
29
+ def deleted_e
30
+ tx.deletedRelationships.map { |n| wrap_edge n }
31
+ end
32
+
33
+ def created_v_ids
34
+ tx.createdNodes.map { |n| n.getId }
35
+ end
36
+
37
+ def deleted_v_ids
38
+ tx.deletedNodes.map { |n| n.getId }
39
+ end
40
+
41
+ def created_e_ids
42
+ tx.createdRelationships.map { |n| n.getId }
43
+ end
44
+
45
+ def deleted_e_ids
46
+ tx.deletedRelationships.map { |n| n.getId }
47
+ end
48
+
49
+ def deleted?(e)
50
+ tx.is_deleted e.element.rawElement
51
+ end
52
+
53
+ def changed_v
54
+ tx.assignedNodeProperties.map do |p|
55
+ { element_type: :vertex,
56
+ id: p.entity.getId,
57
+ key: p.key,
58
+ was: graph.decode_property(p.previouslyCommitedValue),
59
+ is: graph.decode_property(p.value) }
60
+ end +
61
+ tx.removedNodeProperties.map do |p|
62
+ { element_type: :vertex,
63
+ id: p.entity.getId,
64
+ key: p.key,
65
+ was: graph.decode_property(p.previouslyCommitedValue),
66
+ is: nil }
67
+ end
68
+ end
69
+
70
+ def changed_e
71
+ tx.assignedRelationshipProperties.map do |p|
72
+ { element_type: :edge,
73
+ id: p.entity.getId,
74
+ key: p.key,
75
+ was: graph.decode_property(p.previouslyCommitedValue),
76
+ is: graph.decode_property(p.value) }
77
+ end +
78
+ tx.removedRelationshipProperties.map do |p|
79
+ { element_type: :edge,
80
+ id: p.entity.getId,
81
+ key: p.key,
82
+ was: graph.decode_property(p.previouslyCommitedValue),
83
+ is: nil }
84
+ end
85
+ end
86
+
87
+ def changes
88
+ changed_v + changed_e
89
+ end
90
+
91
+ def summary
92
+ { created_v: created_v_ids,
93
+ deleted_v: deleted_v_ids,
94
+ created_e: created_e_ids,
95
+ deleted_e: deleted_e_ids,
96
+ changed_v: changed_v,
97
+ changed_e: changed_e }
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,9 @@
1
+ module Pacer
2
+ module Neo4j2
3
+ VERSION = "2.0.1"
4
+ JAR = "pacer-neo4j2-#{ VERSION }-standalone.jar"
5
+ JAR_PATH = "lib/#{ JAR }"
6
+ BLUEPRINTS_VERSION = "2.6.0-SNAPSHOT"
7
+ PACER_REQ = ">= 1.5.0"
8
+ end
9
+ end
@@ -0,0 +1,99 @@
1
+ require 'pacer' unless defined? Pacer
2
+
3
+ lib_path = File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
4
+ $:.unshift lib_path unless $:.any? { |path| path == lib_path }
5
+
6
+ require 'pacer-neo4j2/version'
7
+
8
+ require Pacer::Neo4j2::JAR
9
+
10
+ require 'pacer-neo4j2/graph'
11
+ require 'pacer-neo4j2/algo/wrapping'
12
+ require 'pacer-neo4j2/algo/path_pipe'
13
+ require 'pacer-neo4j2/algo/block_cost_evaluator'
14
+ require 'pacer-neo4j2/algo/block_estimate_evaluator'
15
+ require 'pacer-neo4j2/algo/block_path_expander'
16
+ require 'pacer-neo4j2/algo/path_wrapper'
17
+ require 'pacer-neo4j2/algo/traversal_branch_wrapper'
18
+ require 'pacer-neo4j2/algo/cypher_transform'
19
+ require 'pacer-neo4j2/algo'
20
+ require 'pacer-neo4j2/raw_vertex_wrapping_pipe'
21
+ require 'pacer-neo4j2/lucene_filter'
22
+ require 'pacer-neo4j2/transaction_event_handler'
23
+ require 'pacer-neo4j2/tx_data_wrapper'
24
+ require 'pacer-neo4j2/blueprints_graph'
25
+
26
+ Pacer::FunctionResolver.clear_cache
27
+
28
+ module Pacer
29
+ # Add 'static methods' to the Pacer namespace.
30
+ class << self
31
+ # Return a graph for the given path. Will create a graph if none exists at
32
+ # that location. (The graph is only created if data is actually added to it).
33
+ #
34
+ # If the graph is opened from a path, it will be registered to be closed by
35
+ # Ruby's at_exit callback, but if an already open graph is given, it will
36
+ # not.
37
+ #
38
+ # Please note that Pacer turns on Neo4j's checkElementsInTransaction
39
+ # feature by default. For some sort of performance improvement at
40
+ # the expense of an odd consistency model within transactions that
41
+ # require considerable more complexity in client code, you can use
42
+ # `graph.setCheckElementsInTransaction(false)` to disable the
43
+ # feature.
44
+ #
45
+ # It is recommended that *in production* the `allow_auto_tx` and
46
+ # `allow_auto_read_tx` options be set to `false` to prevent hard-to-debug
47
+ # errors caused by Blueprints' automatically starting transactions which it
48
+ # never automatically commits or rolls back. When working in the console,
49
+ # however, reenabling automatic read transactons is generally recommended,
50
+ # together with periodic use of `rollback_implicit_transaction`
51
+ def neo4j2(path_or_graph, args = nil)
52
+ if path_or_graph.is_a? String
53
+ path = File.expand_path(path_or_graph)
54
+ open = proc do
55
+ raw_graph = Pacer.open_graphs[path]
56
+ if raw_graph
57
+ graph = Pacer::Neo4j2::BlueprintsGraph.new(raw_graph)
58
+ else
59
+ if args
60
+ graph = Pacer::Neo4j2::BlueprintsGraph.new(path, args.to_hash_map)
61
+ else
62
+ graph = Pacer::Neo4j2::BlueprintsGraph.new(path)
63
+ end
64
+ graph.allow_auto_tx = false
65
+ graph.allow_auto_read_tx = false
66
+ Pacer.open_graphs[path] = graph.raw_graph
67
+ graph.setCheckElementsInTransaction true
68
+ end
69
+ graph
70
+ end
71
+ shutdown = proc do |g|
72
+ g.blueprints_graph.shutdown
73
+ Pacer.open_graphs.delete path
74
+ end
75
+ Neo4j2::Graph.new(Pacer::YamlEncoder, open, shutdown)
76
+ else
77
+ # Don't register the new graph so that it won't be automatically closed.
78
+ Neo4j2::Graph.new Pacer::YamlEncoder, proc { Pacer::Neo4j2::BlueprintsGraph.new(path_or_graph) }
79
+ end
80
+ end
81
+
82
+ def neo2_batch(path)
83
+ bp_neo_class = com.tinkerpop.blueprints.impls.neo4jbatch.Neo4j2BatchGraph
84
+ path = File.expand_path(path)
85
+ open = proc do
86
+ graph = bp_neo_class.new(path)
87
+ Pacer.open_graphs[path] = :open_batch_graph
88
+ graph
89
+ end
90
+ shutdown = proc do |g|
91
+ g.blueprints_graph.shutdown
92
+ Pacer.open_graphs.delete path
93
+ end
94
+ g = PacerGraph.new(Pacer::YamlEncoder, open, shutdown)
95
+ g.disable_transactions = true
96
+ g
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pacer-neo4j2/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pacer-neo4j2"
7
+ s.version = Pacer::Neo4j2::VERSION
8
+ s.platform = 'java'
9
+ s.authors = ["Darrick Wiebe"]
10
+ s.email = ["dw@xnlogic.com"]
11
+ s.homepage = "http://neo4j.org"
12
+ s.summary = %q{Neo4J jars and related code for Pacer}
13
+ s.description = s.summary
14
+
15
+ s.add_dependency 'pacer', Pacer::Neo4j2::PACER_REQ
16
+
17
+ s.rubyforge_project = "pacer-neo4j2"
18
+
19
+ s.files = `git ls-files`.split("\n") + [Pacer::Neo4j2::JAR_PATH]
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,22 @@
1
+ <assembly>
2
+ <id>standalone</id>
3
+ <formats>
4
+ <format>jar</format>
5
+ </formats>
6
+ <includeBaseDirectory>false</includeBaseDirectory>
7
+
8
+ <fileSets>
9
+ <fileSet>
10
+ <directory>target/classes</directory>
11
+ <outputDirectory>/</outputDirectory>
12
+ </fileSet>
13
+ </fileSets>
14
+
15
+ <dependencySets>
16
+ <dependencySet>
17
+ <outputDirectory>/</outputDirectory>
18
+ <unpack>true</unpack>
19
+ <scope>runtime</scope>
20
+ </dependencySet>
21
+ </dependencySets>
22
+ </assembly>
data/pom.xml ADDED
@@ -0,0 +1,95 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5
+ <modelVersion>4.0.0</modelVersion>
6
+ <groupId>com.tinkerpop.pacer</groupId>
7
+ <artifactId>pacer-neo4j2</artifactId>
8
+ <!-- NOTE: the following properties are automatically updated based on the values in lib/pacer-neo4j2/version.rb -->
9
+ <properties>
10
+ <blueprints.version>2.6.0-SNAPSHOT</blueprints.version>
11
+ <gem.version>2.0.1</gem.version>
12
+ </properties>
13
+ <!-- NOTE: the following properties are automatically updated based on the values in lib/pacer-neo4j2/version.rb -->
14
+ <version>${gem.version}</version>
15
+ <packaging>pom</packaging>
16
+ <url>https://github.com/pangloss/pacer</url>
17
+ <name>Pacer Neo4J dependencies and related code.</name>
18
+ <description>
19
+ </description>
20
+ <inceptionYear>2011</inceptionYear>
21
+ <developers>
22
+ <developer>
23
+ <name>Darrick Wiebe</name>
24
+ <email>darrick@innatesoftware.com</email>
25
+ <url>http://github.com/pangloss</url>
26
+ </developer>
27
+ </developers>
28
+ <dependencies>
29
+ <dependency>
30
+ <groupId>com.tinkerpop.blueprints</groupId>
31
+ <artifactId>blueprints-neo4j2-graph</artifactId>
32
+ <version>${blueprints.version}</version>
33
+ </dependency>
34
+ </dependencies>
35
+
36
+ <build>
37
+ <directory>${basedir}/target</directory>
38
+ <finalName>${project.artifactId}-${project.version}</finalName>
39
+ <resources>
40
+ <resource>
41
+ <directory>${basedir}/src/main/resources
42
+ </directory>
43
+ </resource>
44
+ </resources>
45
+ <testResources>
46
+ <testResource>
47
+ <directory>${basedir}/src/test/resources
48
+ </directory>
49
+ </testResource>
50
+ </testResources>
51
+ <plugins>
52
+ <plugin>
53
+ <artifactId>maven-compiler-plugin</artifactId>
54
+ <configuration>
55
+ <source>1.6</source>
56
+ <target>1.6</target>
57
+ </configuration>
58
+ </plugin>
59
+ <plugin>
60
+ <artifactId>maven-assembly-plugin</artifactId>
61
+ <version>2.2-beta-4</version>
62
+ <executions>
63
+ <execution>
64
+ <phase>package</phase>
65
+ <goals>
66
+ <goal>attached</goal>
67
+ </goals>
68
+ </execution>
69
+ </executions>
70
+ <configuration>
71
+ <descriptors>
72
+ <descriptor>pom/standalone.xml</descriptor>
73
+ </descriptors>
74
+ <finalName>${project.artifactId}-${project.version}</finalName>
75
+ <outputDirectory>lib</outputDirectory>
76
+ <workDirectory>target/assembly/work</workDirectory>
77
+ <tarLongFileMode>warn</tarLongFileMode>
78
+ </configuration>
79
+ </plugin>
80
+ <plugin>
81
+ <groupId>org.apache.maven.plugins</groupId>
82
+ <artifactId>maven-javadoc-plugin</artifactId>
83
+ <version>2.6.1</version>
84
+ </plugin>
85
+ </plugins>
86
+ <extensions>
87
+ <extension>
88
+ <groupId>org.apache.maven.wagon</groupId>
89
+ <artifactId>wagon-ftp</artifactId>
90
+ <version>1.0-alpha-6</version>
91
+ </extension>
92
+ </extensions>
93
+ </build>
94
+
95
+ </project>
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pacer-neo4j2
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.1
5
+ platform: java
6
+ authors:
7
+ - Darrick Wiebe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pacer
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.0
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 1.5.0
25
+ prerelease: false
26
+ type: :runtime
27
+ description: Neo4J jars and related code for Pacer
28
+ email:
29
+ - dw@xnlogic.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - README.md
37
+ - Rakefile
38
+ - lib/pacer-neo4j2.rb
39
+ - lib/pacer-neo4j2/algo.rb
40
+ - lib/pacer-neo4j2/algo/block_cost_evaluator.rb
41
+ - lib/pacer-neo4j2/algo/block_estimate_evaluator.rb
42
+ - lib/pacer-neo4j2/algo/block_path_expander.rb
43
+ - lib/pacer-neo4j2/algo/cypher_transform.rb
44
+ - lib/pacer-neo4j2/algo/path_pipe.rb
45
+ - lib/pacer-neo4j2/algo/path_wrapper.rb
46
+ - lib/pacer-neo4j2/algo/traversal_branch_wrapper.rb
47
+ - lib/pacer-neo4j2/algo/wrapping.rb
48
+ - lib/pacer-neo4j2/blueprints_graph.rb
49
+ - lib/pacer-neo4j2/graph.rb
50
+ - lib/pacer-neo4j2/lucene_filter.rb
51
+ - lib/pacer-neo4j2/raw_vertex_wrapping_pipe.rb
52
+ - lib/pacer-neo4j2/rspec.rb
53
+ - lib/pacer-neo4j2/transaction_event_handler.rb
54
+ - lib/pacer-neo4j2/tx_data_wrapper.rb
55
+ - lib/pacer-neo4j2/version.rb
56
+ - pacer-neo4j2.gemspec
57
+ - pom.xml
58
+ - pom/standalone.xml
59
+ - lib/pacer-neo4j2-2.0.1-standalone.jar
60
+ homepage: http://neo4j.org
61
+ licenses: []
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project: pacer-neo4j2
79
+ rubygems_version: 2.1.9
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Neo4J jars and related code for Pacer
83
+ test_files: []
84
+ has_rdoc: