pacer-orient 2.1.2-java → 2.2.0.pre-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a412d30bbf1e14575ea9d6bb5640370b16777c7c
4
- data.tar.gz: 619fcd6eb5f3b707089be17635629cbb7a8392a0
3
+ metadata.gz: 9b32edc920ee17066a25d9d17ae4797e4879e52d
4
+ data.tar.gz: e0122dc83de2028ec05812adb6455d47668bd6e2
5
5
  SHA512:
6
- metadata.gz: 95a24e286b6ccd78c0101cc843fb059a95e11e3ce4dbf88e27a5f5240bd35bb4847e5a20936f9c6ff17d9415f07ebec558b64f972e807e6d2ac21aa4df56834f
7
- data.tar.gz: bcd6f2b791474497e2d170a4f9c284824f98fa273269503a63976781782e05ac1f068074043329206da4187c44344de788c16e8e72ef6646f8c48bc606d2a67b
6
+ metadata.gz: a36668673a20c99d81a62b97285e80806bb9bf5c2dd956335fb6108a85e81967fe41af13f0864d262f1e292070848e47ea0cc200c232f903849dc096d9511fb7
7
+ data.tar.gz: 7e321c5921a437089c14fe4f78154f566e1cf39e5b96002ca50f03b200983ac96910795a36e307d1529db74af72ec8cbe73bfa5b59adfff4d7aa7ab5fd343eb4
@@ -1,26 +1,88 @@
1
1
  module Pacer::Orient
2
2
  class FactoryContainer
3
- attr_reader :factory
3
+ attr_reader :factory, :url, :use_pool
4
+ attr_accessor :encoder, :transactional, :lightweight_edges, :edge_classes, :vertex_classes
4
5
 
5
- def initialize(f)
6
+ def initialize(f, url, args)
6
7
  @factory = f
8
+ @url = url
9
+ Pacer.open_graphs[url] = self
10
+ if args
11
+ @transactional = args[:transactional]
12
+ @lightweight_edges = args[:lightweight_edges]
13
+ @edge_classes = args[:edge_classes]
14
+ @vertex_classes = args[:vertex_classes]
15
+ self.stay_open = args[:stay_open]
16
+ @encoder = args.fetch :encoder, Encoder
17
+ min = args[:pool_min]
18
+ max = args[:pool_max]
19
+ if min and max
20
+ setupPool min, max
21
+ end
22
+ end
23
+ end
24
+
25
+ def setupPool(min, max)
26
+ @use_pool = true
27
+ factory.setupPool min, max
28
+ end
29
+
30
+ def stay_open=(b)
31
+ #factory.setLeaveGraphsOpen b
32
+ end
33
+
34
+ def stay_open
35
+ #factory.getLeaveGraphsOpen
36
+ end
37
+
38
+ def graph
39
+ # Shutdown releases the graph to the pool in this case.
40
+ g = Graph.new encoder, proc { get }, proc { |g| g.blueprints_graph.shutdown }
41
+ if block_given?
42
+ r = yield g
43
+ g.shutdown if use_pool
44
+ r
45
+ else
46
+ g
47
+ end
48
+ end
49
+
50
+ def surrender(g)
51
+ g.shutdown if use_pool
7
52
  end
8
53
 
9
54
  def get
10
- factory.get
55
+ if transactional == false
56
+ getNoTx
57
+ else
58
+ getTx
59
+ end
11
60
  end
12
61
 
13
62
  def getTx
14
- factory.getTx
63
+ configure factory.getTx
15
64
  end
16
65
 
17
66
  def getNoTx
18
- factory.getNoTx
67
+ configure factory.getNoTx
19
68
  end
20
69
 
21
70
  # Pacer calls shutdown on all cached graphs when it exits. Orient caches this factory.
22
71
  def shutdown
23
72
  factory.close
73
+ Pacer.open_graphs.delete url
74
+ end
75
+
76
+ private
77
+
78
+ def configure(bg)
79
+ bg.setAutoStartTx false
80
+ bg.setRequireTransaction true
81
+ bg.rollback # a transaction is auto-started when the graph is opened.
82
+ bg.setUseLightweightEdges lightweight_edges if lightweight_edges == false
83
+ bg.setUseClassForEdgeLabel edge_classes if edge_classes == false
84
+ bg.setUseClassForVertexLabel vertex_classes if vertex_classes == false
85
+ bg
24
86
  end
25
87
  end
26
88
  end
@@ -13,10 +13,12 @@ module Pacer
13
13
  import com.orientechnologies.orient.core.sql.OCommandSQL
14
14
  import com.orientechnologies.orient.core.metadata.schema.OType
15
15
  import com.orientechnologies.orient.core.metadata.schema.OClass
16
+ import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal
16
17
 
17
18
  # Marked the types that should be most commonly used.
18
19
  OTYPES = {
19
20
  :any => OType::ANY,
21
+ :all => OType::ANY,
20
22
  :boolean => OType::BOOLEAN, # use this one
21
23
  :bool => OType::BOOLEAN,
22
24
  :short => OType::SHORT,
@@ -26,10 +28,7 @@ module Pacer
26
28
  :float => OType::FLOAT,
27
29
  :double => OType::DOUBLE, # use this one
28
30
  :decimal => OType::DECIMAL, # use this one
29
- #If encoding dates to binary
30
- #:date => OType::BINARY,
31
- #:datetime => OType::BINARY,
32
- #:date_time => OType::BINARY,
31
+ #HINT: If using the BinaryDateEncoder, use :binary instead of the :date or :datetime types.
33
32
  :date => OType::DATE, # use this one
34
33
  :datetime => OType::DATETIME, # use this one
35
34
  :date_time => OType::DATETIME,
@@ -83,15 +82,16 @@ module Pacer
83
82
  }
84
83
 
85
84
  def orient_graph
86
- blueprints_graph.raw_graph
85
+ blueprints_graph.getRawGraph
87
86
  end
88
87
 
89
88
  def allow_auto_tx=(b)
89
+ blueprints_graph.setRequireTransaction !b
90
90
  blueprints_graph.setAutoStartTx b
91
91
  end
92
92
 
93
93
  def allow_auto_tx
94
- blueprints_graph.autoStartTx
94
+ blueprints_graph.isAutoStartTx or not blueprints_graph.isRequireTransaction
95
95
  end
96
96
 
97
97
  def on_commit(&block)
@@ -175,14 +175,12 @@ module Pacer
175
175
  if r
176
176
  r
177
177
  else
178
- in_pure_transaction do
179
- t = if element_type == :vertex
180
- blueprints_graph.createVertexType(t.to_s)
181
- elsif element_type == :edge
182
- blueprints_graph.createEdgeType(t.to_s)
183
- end
184
- OrientType.new self, element_type, t if t
185
- end
178
+ t = if element_type == :vertex
179
+ blueprints_graph.createVertexType(t.to_s)
180
+ elsif element_type == :edge
181
+ blueprints_graph.createEdgeType(t.to_s)
182
+ end
183
+ OrientType.new self, element_type, t if t
186
184
  end
187
185
  end
188
186
 
@@ -218,48 +216,59 @@ module Pacer
218
216
  end
219
217
 
220
218
  def add_vertex_types(*types)
221
- in_pure_transaction do
222
- types.map do |t|
223
- existing = orient_type(t, :vertex)
224
- if existing
225
- existing
226
- else
227
- t = blueprints_graph.createVertexType(t.to_s)
228
- OrientType.new(self, :vertex, t) if t
229
- end
219
+ types.map do |t|
220
+ existing = orient_type(t, :vertex)
221
+ if existing
222
+ existing
223
+ else
224
+ t = blueprints_graph.createVertexType(t.to_s)
225
+ OrientType.new(self, :vertex, t) if t
230
226
  end
231
227
  end
232
228
  end
233
229
 
234
- def create_key_index(name, element_type = :vertex, itype = :non_unique)
235
- type = orient_type(nil, element_type)
236
- type.property!(name).create_index!(itype) if type
230
+ def in_transaction?
231
+ orient_graph.getTransaction.isActive
237
232
  end
238
233
 
239
- def drop_key_index(name, element_type = :vertex)
240
- in_pure_transaction do
241
- super
242
- end
243
- end
244
-
245
- private
246
-
247
- def in_pure_transaction
248
- if @in_pure_transaction
234
+ # Enables using multiple graphs at once.
235
+ def thread_local(revert = false)
236
+ orig = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined
237
+ if orig == orient_graph
249
238
  yield
250
239
  else
251
240
  begin
252
- @in_pure_transaction = true
253
- transaction do
254
- orient_graph.rollback
255
- yield
256
- end
241
+ ODatabaseRecordThreadLocal.INSTANCE.set orient_graph
242
+ yield
257
243
  ensure
258
- @in_pure_transaction = false
244
+ ODatabaseRecordThreadLocal.INSTANCE.set orig if revert
259
245
  end
260
246
  end
261
247
  end
262
248
 
249
+ def transaction(opts = {})
250
+ thread_local do
251
+ if opts[:schema]
252
+ begin
253
+ if in_transaction?
254
+ in_tx = true
255
+ blueprints_graph.commit
256
+ end
257
+ c, r = nested_tx_finalizers
258
+ yield c, r
259
+ ensure
260
+ blueprints_graph.begin if in_tx
261
+ end
262
+ else
263
+ super
264
+ end
265
+ end
266
+ end
267
+
268
+ alias tx transaction
269
+
270
+ private
271
+
263
272
  def sql_range(k, v, params)
264
273
  params.push v.min
265
274
  params.push v.last
@@ -271,9 +280,10 @@ module Pacer
271
280
  filters.properties.select do |k, v|
272
281
  if v
273
282
  p = orient_type.property k
274
- if p and p.indexed?
283
+ if (p and p.indexed?) or key_indices.include?(k)
275
284
  if v.is_a? Range or v.class.name == 'RangeSet'
276
- p.range_index?
285
+ # not p just means it is a key index
286
+ not p or p.range_index?
277
287
  else
278
288
  true
279
289
  end
@@ -332,6 +342,35 @@ module Pacer
332
342
  end
333
343
  end
334
344
  end
345
+
346
+ def finish_transaction!
347
+ end
348
+
349
+ def start_transaction!(opts)
350
+ if allow_auto_tx
351
+ base_tx_finalizers
352
+ elsif in_transaction?
353
+ nested_tx_finalizers
354
+ else
355
+ blueprints_graph.begin
356
+ base_tx_finalizers
357
+ end
358
+ end
359
+
360
+ def base_tx_finalizers
361
+ commit = ->(reopen = true) do
362
+ puts "transaction committed" if Pacer.verbose == :very
363
+ blueprints_graph.commit
364
+ blueprints_graph.begin if reopen
365
+ on_commit_block.call if on_commit_block
366
+ end
367
+ rollback = ->(message = nil) do
368
+ puts ["transaction rolled back", message].compact.join(': ') if Pacer.verbose == :very
369
+ blueprints_graph.rollback
370
+ blueprints_graph.begin unless $!
371
+ end
372
+ [commit, rollback]
373
+ end
335
374
  end
336
375
  end
337
376
  end
@@ -45,9 +45,7 @@ module Pacer::Orient
45
45
  def property!(name, otype)
46
46
  p = raw_property(name)
47
47
  unless p
48
- p = graph.send(:in_pure_transaction) do
49
- type.createProperty(name.to_s, graph.property_type(otype))
50
- end
48
+ p = type.createProperty(name.to_s, graph.property_type(otype))
51
49
  end
52
50
  Property.new self, p
53
51
  end
@@ -59,16 +57,12 @@ module Pacer::Orient
59
57
  end
60
58
 
61
59
  def set_super_class(sc)
62
- graph.send(:in_pure_transaction) do
63
- type.setSuperClass graph.orient_type(element_type, sc)
64
- end
60
+ type.setSuperClass graph.orient_type(element_type, sc)
65
61
  self
66
62
  end
67
63
 
68
64
  def drop_property!(name)
69
- graph.send(:in_pure_transaction) do
70
- type.dropProperty name
71
- end
65
+ type.dropProperty name
72
66
  end
73
67
 
74
68
  def properties
@@ -20,9 +20,7 @@ module Pacer::Orient
20
20
 
21
21
  def create_index!(index_type = :not_unique)
22
22
  unless indexed?
23
- graph.send(:in_pure_transaction) do
24
- property.createIndex graph.index_type(index_type)
25
- end
23
+ property.createIndex graph.index_type(index_type)
26
24
  end
27
25
  self
28
26
  end
@@ -1,7 +1,26 @@
1
1
  module Pacer
2
2
  module Filter
3
3
  module SqlFilter
4
- attr_accessor :sql, :select, :orient_type, :where, :query_args, :order_by, :limit, :offset, :timeout, :parallel
4
+ attr_accessor :sql, :select, :orient_type, :where, :query_args, :order_by, :timeout, :parallel
5
+ attr_writer :limit, :offset
6
+
7
+ def offset(n = nil)
8
+ if n
9
+ @offset = n
10
+ self
11
+ else
12
+ @offset
13
+ end
14
+ end
15
+
16
+ def limit(n = nil)
17
+ if n
18
+ @limit = n
19
+ self
20
+ else
21
+ @limit
22
+ end
23
+ end
5
24
 
6
25
  protected
7
26
 
@@ -1,10 +1,10 @@
1
1
  module Pacer
2
2
  module Orient
3
- VERSION = "2.1.2"
3
+ VERSION = "2.2.0.pre"
4
4
  JAR = "pacer-orient-#{ VERSION }-standalone.jar"
5
5
  JAR_PATH = "lib/#{ JAR }"
6
- ORIENT_VERSION = "1.7.8"
7
- PIPES_VERSION = "2.5.0"
6
+ ORIENT_VERSION = "2.0-M2-SNAPSHOT"
7
+ PIPES_VERSION = "2.6.0"
8
8
  PACER_REQ = ">= 1.5.3"
9
9
  end
10
10
  end
data/lib/pacer-orient.rb CHANGED
@@ -14,6 +14,32 @@ Pacer::FunctionResolver.clear_cache
14
14
  module Pacer
15
15
  # Add 'static methods' to the Pacer namespace.
16
16
  class << self
17
+ def orient_factory(url = nil, args = {})
18
+ if url.nil?
19
+ url = "memory:#{ next_orient_name }"
20
+ elsif url.is_a? String and url !~ /^(plocal|local|remote|memory):/
21
+ url = "plocal:#{ url }"
22
+ end
23
+ if url
24
+ factory = Pacer.open_graphs[url]
25
+ if factory
26
+ factory
27
+ else
28
+ if args
29
+ username = args[:username]
30
+ password = args[:password]
31
+ end
32
+ factory =
33
+ if username
34
+ com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.new url, username, password
35
+ else
36
+ com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.new url
37
+ end
38
+ Pacer::Orient::FactoryContainer.new(factory, url, args)
39
+ end
40
+ end
41
+ end
42
+
17
43
  # Return a graph for the given path. Will create a graph if none exists at
18
44
  # that location.
19
45
  #
@@ -21,52 +47,18 @@ module Pacer
21
47
  # Ruby's at_exit callback, but if an already open graph is given, it will
22
48
  # not.
23
49
  def orient(url = nil, args = nil)
24
- if url.nil?
25
- url = "memory:#{ next_orient_name }"
26
- elsif url.is_a? String and url !~ /^(plocal|local|remote|memory):/
27
- url = "plocal:#{ url }"
28
- end
29
- if args
30
- username = args.delete :username
31
- password = args.delete :password
32
- transactional = args.delete :transactional
33
- lightweight_edges = args.delete :lightweight_edges
34
- edge_classes = args.delete :edge_classes
35
- vertex_classes = args.delete :vertex_classes
36
- end
37
- if url.is_a? String
50
+ if url.is_a? Pacer::Graph
51
+ # Don't register the new graph so that it won't be automatically closed.
52
+ Orient::Graph.new Pacer::Orient::Encoder, proc { url }
53
+ else
38
54
  open = proc do
39
- # TODO: can / should I cache connections? Is it essential to shut down Orient?
40
- factory = Pacer.open_graphs[[url, username]]
41
- unless factory
42
- factory =
43
- if username
44
- com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.new url, username, password
45
- else
46
- com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.new url
47
- end
48
- Pacer.open_graphs[[url, username]] = Pacer::Orient::FactoryContainer.new(factory)
49
- end
50
- if transactional == false
51
- graph = factory.getNoTx()
52
- else
53
- graph = factory.getTx()
54
- end
55
- graph.useLightweightEdges = lightweight_edges if lightweight_edges == false
56
- graph.useClassForEdgeLabel = edge_classes if edge_classes == false
57
- graph.useClassForVertexLabel = vertex_classes if vertex_classes == false
58
- #graph.setAutoStartTx false
59
- graph
55
+ orient_factory(url, args).get
60
56
  end
61
57
  shutdown = proc do |g|
62
- factory = Pacer.open_graphs.delete [url, username]
58
+ factory = Pacer.open_graphs.delete url
63
59
  factory.shutdown if factory
64
60
  end
65
61
  Orient::Graph.new(Pacer::Orient::Encoder, open, shutdown)
66
- else
67
- # Don't register the new graph so that it won't be automatically closed.
68
- graph = url
69
- Orient::Graph.new Pacer::Orient::Encoder, proc { graph }
70
62
  end
71
63
  end
72
64
 
data/pom.xml CHANGED
@@ -7,9 +7,9 @@
7
7
  <artifactId>pacer-orient</artifactId>
8
8
  <!-- NOTE: the following properties are automatically updated based on the values in lib/pacer-orient/version.rb -->
9
9
  <properties>
10
- <orient.version>1.7.8</orient.version>
11
- <gem.version>2.1.2</gem.version>
12
- <pipes.version>2.5.0</pipes.version>
10
+ <orient.version>2.0-M2-SNAPSHOT</orient.version>
11
+ <gem.version>2.2.0.pre</gem.version>
12
+ <pipes.version>2.6.0</pipes.version>
13
13
  </properties>
14
14
  <!-- NOTE: the following properties are automatically updated based on the values in lib/pacer-orient/version.rb -->
15
15
  <version>${gem.version}</version>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pacer-orient
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0.pre
5
5
  platform: java
6
6
  authors:
7
7
  - Darrick Wiebe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-19 00:00:00.000000000 Z
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pacer
@@ -48,7 +48,7 @@ files:
48
48
  - pacer-orient.gemspec
49
49
  - pom.xml
50
50
  - pom/standalone.xml
51
- - lib/pacer-orient-2.1.2-standalone.jar
51
+ - lib/pacer-orient-2.2.0.pre-standalone.jar
52
52
  homepage: http://orientechnologies.com
53
53
  licenses: []
54
54
  metadata: {}
@@ -63,9 +63,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - '>'
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.3.1
69
69
  requirements: []
70
70
  rubyforge_project: pacer-orient
71
71
  rubygems_version: 2.1.9