active-orient 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +8 -3
  4. data/Guardfile +12 -4
  5. data/README.md +221 -201
  6. data/VERSION +1 -1
  7. data/active-orient.gemspec +3 -2
  8. data/bin/active-orient-console +35 -0
  9. data/config/boot.rb +84 -16
  10. data/config/config.yml +10 -0
  11. data/config/connect.yml +6 -2
  12. data/create_project +19 -0
  13. data/examples/books.rb +86 -39
  14. data/examples/createTime.rb +91 -0
  15. data/examples/streets.rb +85 -84
  16. data/examples/test_commands.rb +92 -0
  17. data/examples/test_commands_2.rb +54 -0
  18. data/examples/test_commands_3.rb +48 -0
  19. data/examples/test_commands_4.rb +28 -0
  20. data/examples/time_graph/Gemfile +21 -0
  21. data/examples/time_graph/Guardfile +26 -0
  22. data/examples/time_graph/README.md +129 -0
  23. data/examples/time_graph/bin/active-orient-console +35 -0
  24. data/examples/time_graph/config/boot.rb +119 -0
  25. data/examples/time_graph/config/config.yml +8 -0
  26. data/examples/time_graph/config/connect.yml +17 -0
  27. data/examples/time_graph/config/init_db.rb +59 -0
  28. data/examples/time_graph/createTime.rb +51 -0
  29. data/examples/time_graph/lib/createTime.rb +82 -0
  30. data/examples/time_graph/model/day_of.rb +3 -0
  31. data/examples/time_graph/model/e.rb +6 -0
  32. data/examples/time_graph/model/edge.rb +53 -0
  33. data/examples/time_graph/model/monat.rb +19 -0
  34. data/examples/time_graph/model/stunde.rb +16 -0
  35. data/examples/time_graph/model/tag.rb +29 -0
  36. data/examples/time_graph/model/time_base.rb +6 -0
  37. data/examples/time_graph/model/time_of.rb +4 -0
  38. data/examples/time_graph/model/v.rb +3 -0
  39. data/examples/time_graph/model/vertex.rb +32 -0
  40. data/examples/time_graph/spec/lib/create_time_spec.rb +50 -0
  41. data/examples/time_graph/spec/rest_helper.rb +37 -0
  42. data/examples/time_graph/spec/spec_helper.rb +46 -0
  43. data/lib/active-orient.rb +56 -6
  44. data/lib/base.rb +149 -147
  45. data/lib/base_properties.rb +40 -41
  46. data/lib/class_utils.rb +301 -0
  47. data/lib/database_utils.rb +97 -0
  48. data/lib/init.rb +35 -0
  49. data/lib/java-api.rb +437 -0
  50. data/lib/jdbc.rb +211 -0
  51. data/lib/model/edge.rb +53 -0
  52. data/lib/model/model.rb +77 -0
  53. data/lib/model/the_class.rb +480 -0
  54. data/lib/model/the_record.rb +310 -0
  55. data/lib/model/vertex.rb +32 -0
  56. data/lib/orient.rb +113 -50
  57. data/lib/orientdb_private.rb +48 -0
  58. data/lib/other.rb +280 -0
  59. data/lib/query.rb +71 -73
  60. data/lib/rest/change.rb +124 -0
  61. data/lib/rest/create.rb +474 -0
  62. data/lib/rest/delete.rb +133 -0
  63. data/lib/rest/operations.rb +150 -0
  64. data/lib/rest/read.rb +150 -0
  65. data/lib/rest/rest.rb +111 -0
  66. data/lib/rest_disabled.rb +24 -0
  67. data/lib/support.rb +387 -296
  68. data/old_lib_functions/two_general_class.rb +139 -0
  69. data/usecase.md +49 -36
  70. data/usecase_oo.md +59 -0
  71. metadata +73 -9
  72. data/lib/model.rb +0 -461
  73. data/lib/rest.rb +0 -1036
  74. data/test.rb +0 -4
@@ -0,0 +1,82 @@
1
+ #require 'time'
2
+
3
+
4
+
5
+ class CreateTime
6
+ class << self # singleton class
7
+ ## simple version: connecting vertices as they are created
8
+ def pop_month year = Date.today.year, month = Date.today.month
9
+ timestamp = DateTime.new year, month,1
10
+ if Monat.where( :value => month ).blank?
11
+ der_monat= Monat.create value_string: timestamp.strftime("%B"), value: timestamp.month.to_i
12
+ last_month_day = (DateTime.new( year, month+1, 1)-1).day rescue 31 # rescue covers month > 12
13
+ (0 .. last_month_day ).each do | tag |
14
+ der_tag = Tag.create value_string: "March #{timestamp.day}", value: tag
15
+ print der_tag.value.to_s + " > "
16
+ ( 0 .. 23 ).each do | stunde |
17
+ die_stunde = Stunde.create value_string: "March #{timestamp.day} #{timestamp.hour}:00", value: stunde
18
+ print die_stunde.value.to_s + " .. "
19
+ TIME_OF.create_edge from: der_tag, to: die_stunde
20
+ timestamp += Rational(1,24) # + 1 hour
21
+ end
22
+ print "\n"
23
+ DAY_OF.create_edge from: der_monat, to: der_tag
24
+ end
25
+ else
26
+ "Month #{timestamp.strftime("%B %Y ") } exists "
27
+ end
28
+ end
29
+ ## we populate the graph with a 1:n-Layer
30
+ # month --> n[day --> n[hour] ]
31
+ # thus creating edges is providing a static :from-vertex to numerous :to-vertices
32
+ # the to:vertices are first created and fenced in an array. Then all edges are created at once.
33
+ # In Rest-Mode this is much quicker.
34
+ def populate_month year = Date.today.year, month = Date.today.month
35
+ timestamp = DateTime.new year, month,1
36
+ days = []
37
+ if Monat.where( :value => month ).blank?
38
+ der_monat= Monat.create value_string: timestamp.strftime("%B"), value: timestamp.month.to_i
39
+ last_month_day = (DateTime.new( year, month+1, 1)-1).day rescue 31 # rescue covers month > 12
40
+ (0 .. last_month_day ).each do | tag |
41
+ der_tag = Tag.create value_string: "March #{timestamp.day}", value: tag
42
+ edges = []
43
+ ( 0 .. 23 ).each do | stunde |
44
+ edges << Stunde.create( value_string: "March #{timestamp.day} #{timestamp.hour}:00", value: stunde)
45
+ timestamp += Rational(1,24) # + 1 hour
46
+ end
47
+ ## insert all edges of the day as batch (in rest-mode)
48
+ TIME_OF.create from: der_tag, to: edges
49
+ days << der_tag
50
+ end
51
+ DAY_OF.create from: der_monat, to: days
52
+ else
53
+ "Month #{timestamp.strftime("%B %Y ") } exists "
54
+ end
55
+ end
56
+ end
57
+ end # class
58
+
59
+ ## here we start if the file is called from the command-lind
60
+ if $0 == __FILE__
61
+ require './config/boot'
62
+ ActiveOrient::OrientSetup.init_database # --> config/init_db
63
+ CreateTime.populate_month
64
+
65
+
66
+ print "\n" * 4
67
+ puts '-' * 40
68
+ puts "Features of the DateTime Graph"
69
+ puts '-' * 40
70
+ puts
71
+ puts "Allocated Month => Monat.first.value:\t\t" + Monat.first.value.to_s
72
+ puts
73
+ puts "Adressing Days => Monat.first.tag[2].value:\t" + Monat.first.tag[2].value.to_s
74
+ puts
75
+ puts "Display Date => Monat.first.tag[13].datum:\t"+ Monat.first.tag[13].datum.to_s
76
+
77
+ puts "Display next Date => Monat.first.tag[13].next.datum:\t"+ Monat.first.tag[13].next.datum.to_s
78
+
79
+
80
+
81
+
82
+ end
@@ -0,0 +1,3 @@
1
+ class DAY_OF < E
2
+
3
+ end
@@ -0,0 +1,6 @@
1
+ class E < ActiveOrient::Model
2
+ ## Edges are referenced with UPCASE-NAMES ---> went to config/boot.rb
3
+ # def self.naming_convention name=nil
4
+ # name.present? ? name.upcase : ref_name.upcase
5
+ # end
6
+ end
@@ -0,0 +1,53 @@
1
+ # to do
2
+ # instead of creating a class, use a module which is included on startup
3
+ # then, after specifying the namespace and before autoaccolating the database-classes create the proper E-Base-class and include this stuff
4
+ class E < ActiveOrient::Model
5
+ ## link to the library-class
6
+ class << self
7
+ =begin
8
+ establish contrains on Edges
9
+
10
+ Edges are uniq!
11
+
12
+ Creates individual indices for child-classes if applied to the class itself.
13
+ =end
14
+ def uniq_index
15
+ create_property :in, type: :link, linked_class: :V
16
+ create_property :out, type: :link, linked_class: :V
17
+ create_index "#{self.name}_idx", on: [ :in, :out ]
18
+ end
19
+ =begin
20
+ Instantiate a new Edge between two Vertices
21
+
22
+ The parameters »from« **or** »to« can take a list of model-records. Then subsequent edges are created.
23
+
24
+ :call-seq:
25
+ Model.create from:, to:, attributes:{}
26
+ =end
27
+
28
+
29
+ def create **keyword_arguments
30
+ new_edge = db.create_edge self, **keyword_arguments
31
+ new_edge = new_edge.pop if new_edge.is_a?( Array) && new_edge.size == 1
32
+ # vertices must be reloaded
33
+
34
+ new_edge # returns the created edge (or an array of created edges
35
+ end
36
+
37
+ # to do
38
+ # def delete
39
+ # delete an edge (as class method)
40
+ # and
41
+ # def remove
42
+ # delete an edge (as instance method)
43
+ #
44
+ def delete where: attributes
45
+ puts "work in progress"
46
+ end
47
+
48
+ # remove works on record-level
49
+ end
50
+ def remove
51
+ db.delete_edge self
52
+ end
53
+ end
@@ -0,0 +1,19 @@
1
+ #ActiveOrient::Model.orientdb_class name: 'time_base', superclass: 'V'
2
+ class Monat < TimeBase
3
+ def der_tag d
4
+ # d=d-1
5
+ d >0 && d<31 ? out_day_of[d].in : nil
6
+ end
7
+
8
+ # returns an array of days
9
+ # thus enables the use as
10
+ # Monat[9].tag[9]
11
+ def tag
12
+ out_day_of.in
13
+ end
14
+
15
+ # returns the specified edge
16
+ # i.e. Monat[9]
17
+ #
18
+
19
+ end
@@ -0,0 +1,16 @@
1
+ class Stunde < TimeBase
2
+
3
+ def tag
4
+ in_time_of.out
5
+ end
6
+
7
+ def datum
8
+ month = in_time_of.out.in_day_of.out.value
9
+ day = in_time_of.out.value
10
+ "#{day.first}.#{month.flatten.first}.#{Date.today.year} #{value}:00"
11
+ end
12
+ def next
13
+ puts value.inspect
14
+ in_day_of.out.first.tag( value + 1 )
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ #ActiveOrient::Model.orientdb_class name: 'time_base', superclass: 'V'
2
+ class Tag < TimeBase
3
+ def monat
4
+ in_day_of.out.value_string.first
5
+ end
6
+
7
+ def die_stunde h
8
+ h.to_i >0 && h.to_i<31 ? out_time_of[h].in : nil
9
+ end
10
+
11
+
12
+ def stunde
13
+ out_time_of.in
14
+ end
15
+
16
+ def monat
17
+ in_day_of.out.first
18
+ end
19
+ def next
20
+ monat.tag[ value + 1 ]
21
+ end
22
+ def prev
23
+ monat.tag[ value - 1 ]
24
+ end
25
+
26
+ def datum
27
+ "#{ value}.#{monat.value}.#{Date.today.year}"
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ class TimeBase < V
2
+
3
+ def self.[] key
4
+ where( value: key).first
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ #ActiveOrient::Model.orientdb_class name: 'time_base', superclass: 'V'
2
+ class TIME_OF < E
3
+
4
+ end
@@ -0,0 +1,3 @@
1
+ class V < ActiveOrient::Model
2
+ # placeholder for project-specific methods on vertices
3
+ end
@@ -0,0 +1,32 @@
1
+ class V < ActiveOrient::Model
2
+ ## link to the library-class
3
+ # create
4
+ # seems not to be nessesary as its identically to the universal create
5
+
6
+
7
+ # to do
8
+
9
+ # def delete
10
+ # delete an edge (as class method)
11
+ # and
12
+ # def remove
13
+ # delete an edge (as instance method)
14
+
15
+ def edges kind=:all # :all, :in, :out
16
+ expression = case kind
17
+ when :all
18
+ /^in|^out/
19
+ when :in
20
+ /^in/
21
+ when :out
22
+ /^out/
23
+ end
24
+ edges = attributes.keys.find_all{ |x| x =~ expression }
25
+ edges.map{|x| attributes[x]}.flatten
26
+ end
27
+
28
+ def remove
29
+ db.delete_vertex self
30
+ end
31
+
32
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'rest_helper'
3
+
4
+ describe CreateTime do
5
+ before( :all ) do
6
+ reset_database
7
+ ActiveOrient::OrientSetup.init_database
8
+ end
9
+ context "check environment" do
10
+ it "nessesary classes are allocated" do
11
+ [ Monat, Tag, Stunde ].each do | klass |
12
+ expect( klass.superclass).to eq TimeBase
13
+ end
14
+ end
15
+ end
16
+
17
+ context "populate" do
18
+ before( :all ) do
19
+ CreateTime.populate_month
20
+ end
21
+ let( :month){ Date.today.month }
22
+
23
+ it "The actual Month is used" do
24
+ expect( Monat.count ).to eq 1
25
+ expect( Monat.first.value ).to eq Date.today.month
26
+ end
27
+
28
+ it "The actual Month has several days" do
29
+ expect( Monat.first.tag.count ).to be >= 28
30
+ end
31
+
32
+ it "Address a specific day", focus: true do
33
+
34
+ expect( Monat[month].tag[5].value ).to eq 5
35
+ end
36
+
37
+ it "Address a specific hour" do
38
+ expect( Monat[month].tag[5].value ).to eq 5
39
+ expect( Monat[month].tag[7].stunde[5].value ).to eq 5
40
+ end
41
+ it "Switch to the next hour" do
42
+
43
+ expect( Monat[month].tag[7].stunde[5].next.value ).to eq 6
44
+ end
45
+ end
46
+
47
+
48
+
49
+
50
+ end
@@ -0,0 +1,37 @@
1
+ # deletes the working database and recreates it
2
+ # reassignes ORD and DB
3
+ def reset_database
4
+ db = ActiveOrient.database
5
+
6
+ # ORD.database_classes.reverse.each do | klass_name |
7
+ # klass = ActiveOrient::Model.orientdb_class name: klass_name
8
+ # klass.delete_class rescue nil
9
+ # end
10
+ ORD.delete_database database: db
11
+ Object.send :remove_const, :ORD
12
+ Object.send :remove_const, :DB
13
+ ActiveOrient.database = db
14
+ Object.send :const_set, :ORD, ActiveOrient::OrientDB.new( preallocate: true )
15
+ if OrientDB::UsingJava
16
+ Object.send :const_set, :DB, ActiveOrient::API.new( preallocate: false)
17
+ else
18
+ Object.send :const_set, :DB, ActiveOrient::OrientDB.new( preallocate: true )
19
+ end
20
+ end
21
+
22
+
23
+ shared_examples_for 'correct allocated classes' do |input|
24
+ it "has allocated all classes" do
25
+ case input
26
+ when Array
27
+ input.each{|y| expect( ORD.database_classes ).to include ORD.classname(y) }
28
+ expect( classes ).to have( input.size ).items
29
+ when Hash
30
+ else
31
+ expect( classes ).to be_kind_of ActiveOrient::Model
32
+
33
+ end
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,46 @@
1
+ ARGV << 'test'
2
+ @do_not_preallocate = true
3
+ require './config/boot'
4
+ #bundler/setup'
5
+ require 'rspec'
6
+ require 'rspec/its'
7
+ require 'rspec/collection_matchers'
8
+ require 'yaml'
9
+ require 'active_support'
10
+ project_root = File.expand_path('../..', __FILE__)
11
+ #require 'my_spec_helper'
12
+
13
+ unless defined?(SPEC_HELPER_LOADED)
14
+ SPEC_HELPER_LOADED = true
15
+ RSpec.configure do |config|
16
+ config.mock_with :rspec
17
+ config.color = true
18
+ # ermöglicht die Einschränkung der zu testenden Specs
19
+ # durch >>it "irgendwas", :focus => true do <<
20
+ config.filter_run :focus => true
21
+ config.run_all_when_everything_filtered = true
22
+ config.order = 'defined' # "random"
23
+ end
24
+
25
+ RSpec.shared_context 'private', private: true do
26
+
27
+ before :all do
28
+ described_class.class_eval do
29
+ @original_private_instance_methods = private_instance_methods
30
+ public *@original_private_instance_methods
31
+ end
32
+ end
33
+
34
+ after :all do
35
+ described_class.class_eval do
36
+ private *@original_private_instance_methods
37
+ end
38
+ end
39
+
40
+ end
41
+ else
42
+ puts "*** ---- *** \n"*3
43
+ puts "Reusing rspec configuration "
44
+ puts "*** ---- *** \n"*3
45
+ end
46
+ #require 'model_helper'
@@ -1,7 +1,57 @@
1
- require "support.rb"
2
- require "base.rb"
3
- require "base_properties.rb"
4
1
 
5
- require "model.rb"
6
- require "orient.rb"
7
- require "rest.rb"
2
+ module OrientDB
3
+ UsingJava = RUBY_PLATFORM == 'java' ? true : false
4
+ unless RUBY_PLATFORM == 'java'
5
+ DocumentDatabase = nil
6
+ DocumentDatabasePool = nil
7
+ DocumentDatabasePooled = nil
8
+ GraphDatabase = nil
9
+ OTraverse = nil
10
+ Document = nil
11
+ IndexType = nil
12
+ OClassImpl = nil
13
+ PropertyImpl = nil
14
+ Schema = nil
15
+ SchemaProxy = nil
16
+ SchemaType = nil
17
+ SQLCommand = nil
18
+ SQLSynchQuery = nil
19
+ User = nil
20
+ RemoteStorage = nil
21
+ ServerAdmin = nil
22
+ # defined in other.rb
23
+ #JavaDate
24
+ #RecordList = nil
25
+ # RidBag = nil
26
+ # RecordSet = nil
27
+ end
28
+ end # module OrientDB
29
+ require_relative "support.rb"
30
+ require_relative "base.rb"
31
+ require_relative "base_properties.rb"
32
+ require_relative "orient.rb"
33
+ #require_relative "query.rb"
34
+ if RUBY_PLATFORM == 'java'
35
+ require_relative 'java-api.rb'
36
+ end
37
+ require_relative "orientdb_private.rb" # manage private functions
38
+ require_relative "database_utils.rb" #common methods without rest.specific content
39
+ require_relative "class_utils.rb" #common methods without rest.specific content
40
+ require_relative "other.rb"
41
+ require_relative "rest/rest.rb"
42
+ require_relative "model/model.rb"
43
+ require 'active_support/core_ext/string' # provides blank?, present?, presence etc
44
+ require_relative 'init.rb'
45
+ # create Base Classes
46
+ require_relative "model/edge.rb"
47
+ require_relative "model/vertex.rb"
48
+
49
+ module ActiveOrient
50
+ mattr_accessor :database
51
+ mattr_accessor :database_classes
52
+ mattr_accessor :default_server
53
+
54
+
55
+
56
+ end
57
+