neo4j-java-driver 0.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +16 -0
- data/jruby/neo4j/driver.rb +53 -0
- data/jruby/neo4j/driver/ext/exception_checkable.rb +21 -0
- data/jruby/neo4j/driver/ext/exception_mapper.rb +48 -0
- data/jruby/neo4j/driver/ext/graph_database.rb +56 -0
- data/jruby/neo4j/driver/ext/internal/summary/internal_result_summary.rb +17 -0
- data/jruby/neo4j/driver/ext/internal_driver.rb +18 -0
- data/jruby/neo4j/driver/ext/internal_record.rb +21 -0
- data/jruby/neo4j/driver/ext/internal_statement_result.rb +22 -0
- data/jruby/neo4j/driver/ext/map_accessor.rb +17 -0
- data/jruby/neo4j/driver/ext/ruby_converter.rb +55 -0
- data/jruby/neo4j/driver/ext/run_override.rb +73 -0
- data/jruby/neo4j/driver/ext/start_end_naming.rb +17 -0
- data/jruby/neo4j/driver/ext/statement.rb +13 -0
- data/lib/loader.rb +18 -0
- data/lib/neo4j/driver/auto_closable.rb +32 -0
- data/lib/neo4j/driver/exceptions/authentication_exception.rb +10 -0
- data/lib/neo4j/driver/exceptions/client_exception.rb +10 -0
- data/lib/neo4j/driver/exceptions/database_exception.rb +10 -0
- data/lib/neo4j/driver/exceptions/illegal_state_exception.rb +10 -0
- data/lib/neo4j/driver/exceptions/neo4j_exception.rb +18 -0
- data/lib/neo4j/driver/exceptions/no_such_record_exception.rb +33 -0
- data/lib/neo4j/driver/exceptions/protocol_exception.rb +10 -0
- data/lib/neo4j/driver/exceptions/security_exception.rb +10 -0
- data/lib/neo4j/driver/exceptions/service_unavailable_exception.rb +10 -0
- data/lib/neo4j/driver/exceptions/session_expired_exception.rb +10 -0
- data/lib/neo4j/driver/exceptions/transient_exception.rb +10 -0
- data/lib/neo4j/driver/exceptions/untrusted_server_exception.rb +10 -0
- data/lib/neo4j/driver/internal/duration_normalizer.rb +42 -0
- data/lib/neo4j/driver/internal/ruby_signature.rb +18 -0
- data/lib/neo4j/driver/types/byte_array.rb +17 -0
- data/lib/neo4j/driver/types/local_date_time.rb +20 -0
- data/lib/neo4j/driver/types/local_time.rb +19 -0
- data/lib/neo4j/driver/types/offset_time.rb +19 -0
- data/lib/neo4j/driver/types/point.rb +39 -0
- data/lib/neo4j/driver/types/time.rb +43 -0
- data/lib/neo4j/driver/version.rb +7 -0
- data/lib/neo4j_ruby_driver.rb +19 -0
- data/neo4j-ruby-driver.gemspec +63 -0
- metadata +216 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
module Driver
|
5
|
+
module Ext
|
6
|
+
module RunOverride
|
7
|
+
include ExceptionCheckable
|
8
|
+
extend AutoClosable
|
9
|
+
|
10
|
+
auto_closable :begin_transaction
|
11
|
+
|
12
|
+
# work around jruby issue https://github.com/jruby/jruby/issues/5603
|
13
|
+
Struct.new('Wrapper', :object)
|
14
|
+
|
15
|
+
def write_transaction
|
16
|
+
super { |tx| Struct::Wrapper.new(yield(tx)) }.object
|
17
|
+
end
|
18
|
+
|
19
|
+
# end work around
|
20
|
+
|
21
|
+
def run(statement, parameters = {})
|
22
|
+
check { java_method(:run, [java.lang.String, java.util.Map]).call(statement, to_neo(parameters)) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def begin_transaction # (config = nil)
|
26
|
+
check { super }
|
27
|
+
end
|
28
|
+
|
29
|
+
def close
|
30
|
+
check { super }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def to_neo(object)
|
36
|
+
case object
|
37
|
+
when Hash
|
38
|
+
object.map { |key, value| [key.to_s, to_neo(value)] }.to_h
|
39
|
+
when Types::ByteArray
|
40
|
+
object.to_java_bytes
|
41
|
+
when Date
|
42
|
+
Java::JavaTime::LocalDate.of(object.year, object.month, object.day)
|
43
|
+
when ActiveSupport::Duration
|
44
|
+
Java::OrgNeo4jDriverInternal::InternalIsoDuration.new(
|
45
|
+
*Driver::Internal::DurationNormalizer.normalize(object)
|
46
|
+
)
|
47
|
+
when Types::Point
|
48
|
+
Java::OrgNeo4jDriverV1::Values.point(object.srid, *object.coordinates)
|
49
|
+
when Types::OffsetTime
|
50
|
+
Java::JavaTime::OffsetTime.of(object.hour, object.min, object.sec,
|
51
|
+
object.nsec, Java::JavaTime::ZoneOffset.of_total_seconds(object.utc_offset))
|
52
|
+
when Types::LocalTime
|
53
|
+
Java::JavaTime::LocalTime.of(object.hour, object.min, object.sec, object.nsec)
|
54
|
+
when Types::LocalDateTime
|
55
|
+
Java::JavaTime::LocalDateTime.of(object.year, object.month, object.day, object.hour, object.min, object.sec,
|
56
|
+
object.nsec)
|
57
|
+
when ActiveSupport::TimeWithZone
|
58
|
+
to_zoned_date_time(object, object.time_zone.tzinfo.identifier)
|
59
|
+
when Time
|
60
|
+
to_zoned_date_time(object, object.formatted_offset)
|
61
|
+
else
|
62
|
+
object
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_zoned_date_time(object, zone)
|
67
|
+
Java::JavaTime::ZonedDateTime.of(object.year, object.month, object.day, object.hour, object.min, object.sec,
|
68
|
+
object.nsec, Java::JavaTime::ZoneId.of(zone))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/loader.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zeitwerk'
|
4
|
+
|
5
|
+
class Loader
|
6
|
+
def self.load
|
7
|
+
loader = Zeitwerk::Loader.new
|
8
|
+
loader.tag = 'neo4j-ruby-driver'
|
9
|
+
loader.push_dir(File.expand_path(__dir__))
|
10
|
+
loader.push_dir(File.dirname(File.dirname(caller_locations(1..1).first.path)))
|
11
|
+
loader.ignore(File.expand_path('neo4j-java-driver_jars.rb', __dir__))
|
12
|
+
loader.ignore(File.expand_path('neo4j_ruby_driver.rb', __dir__))
|
13
|
+
loader.ignore(File.expand_path('org', __dir__))
|
14
|
+
loader.inflector = Zeitwerk::GemInflector.new(File.expand_path('neo4j/driver', __dir__))
|
15
|
+
loader.setup
|
16
|
+
loader.eager_load
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
module Driver
|
5
|
+
module AutoClosable
|
6
|
+
def auto_closable(*methods)
|
7
|
+
prepend with_block_definer(methods)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def with_block_definer(methods)
|
13
|
+
Module.new do
|
14
|
+
methods.each do |method|
|
15
|
+
define_method(method) do |*args, &block|
|
16
|
+
closable = super(*args)
|
17
|
+
if block
|
18
|
+
begin
|
19
|
+
block.arity.zero? ? closable.instance_eval(&block) : block.call(closable)
|
20
|
+
ensure
|
21
|
+
closable&.close
|
22
|
+
end
|
23
|
+
else
|
24
|
+
closable
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
module Driver
|
5
|
+
module Exceptions
|
6
|
+
class Neo4jException < RuntimeError
|
7
|
+
attr_reader :code, :cause
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
@code = args.shift if args.count > 1
|
11
|
+
message = args.shift
|
12
|
+
@cause = args.shift
|
13
|
+
super(message)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
module Driver
|
5
|
+
module Exceptions
|
6
|
+
class NoSuchRecordException < RuntimeError
|
7
|
+
EMPTY = 'Cannot retrieve a single record, because this result is empty.'
|
8
|
+
TOO_MANY = 'Expected a result with a single record, but this result ' \
|
9
|
+
'contains at least one more. Ensure your query returns only one record.'
|
10
|
+
NO_MORE = 'No more records'
|
11
|
+
NO_PEEK_PAST = 'Cannot peek past the last record'
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def empty
|
15
|
+
new(EMPTY)
|
16
|
+
end
|
17
|
+
|
18
|
+
def too_many
|
19
|
+
new(TOO_MANY)
|
20
|
+
end
|
21
|
+
|
22
|
+
def no_more
|
23
|
+
new(NO_MORE)
|
24
|
+
end
|
25
|
+
|
26
|
+
def no_peek_past
|
27
|
+
new(NO_PEEK_PAST)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
module Driver
|
5
|
+
module Internal
|
6
|
+
module DurationNormalizer
|
7
|
+
class << self
|
8
|
+
def normalize(object)
|
9
|
+
parts = object.parts
|
10
|
+
months_i, months_remainder_seconds = divmod(months(parts), ActiveSupport::Duration::SECONDS_PER_MONTH)
|
11
|
+
months_days, months_remainder_seconds =
|
12
|
+
months_remainder_seconds.divmod(ActiveSupport::Duration::SECONDS_PER_DAY)
|
13
|
+
days_i, days_remainder_seconds = divmod(months_days + days(parts), ActiveSupport::Duration::SECONDS_PER_DAY)
|
14
|
+
seconds_i, nonanoseconds = divmod(months_remainder_seconds + days_remainder_seconds + seconds(parts),
|
15
|
+
1_000_000_000)
|
16
|
+
[months_i, days_i, seconds_i, nonanoseconds.round]
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def divmod(number, factor)
|
22
|
+
number_i, remainder = number.divmod(1)
|
23
|
+
[number_i.to_i, remainder * factor]
|
24
|
+
end
|
25
|
+
|
26
|
+
def months(parts)
|
27
|
+
parts[:years] * 12 + parts[:months]
|
28
|
+
end
|
29
|
+
|
30
|
+
def days(parts)
|
31
|
+
parts[:weeks] * 7 + parts[:days]
|
32
|
+
end
|
33
|
+
|
34
|
+
def seconds(parts)
|
35
|
+
parts[:hours] * ActiveSupport::Duration::SECONDS_PER_HOUR +
|
36
|
+
parts[:minutes] * ActiveSupport::Duration::SECONDS_PER_MINUTE + parts[:seconds]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
module Driver
|
5
|
+
module Internal
|
6
|
+
module RubySignature
|
7
|
+
class << self
|
8
|
+
def session(args)
|
9
|
+
[
|
10
|
+
args.empty? || args.first.is_a?(String) ? Neo4j::Driver::AccessMode::WRITE : args.shift, # mode
|
11
|
+
args # bookmarks
|
12
|
+
]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
module Driver
|
5
|
+
module Types
|
6
|
+
class LocalDateTime < Time
|
7
|
+
class << self
|
8
|
+
FIELDS = %i[year month day hour min sec nsec].freeze
|
9
|
+
|
10
|
+
def significant_fields
|
11
|
+
FIELDS
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
delegate(*significant_fields, to: :@time)
|
16
|
+
delegate :to_i, to: :@time
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
module Driver
|
5
|
+
module Types
|
6
|
+
class LocalTime < Time
|
7
|
+
class << self
|
8
|
+
FIELDS = %i[hour min sec nsec].freeze
|
9
|
+
|
10
|
+
def significant_fields
|
11
|
+
FIELDS
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
delegate(*significant_fields, to: :@time)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|