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,26 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+ def fire
4
+ require "ostruct"
5
+
6
+ # Generic Ruby apps
7
+ rspec = OpenStruct.new
8
+ rspec.spec = ->(m) { "spec/#{m}_spec.rb" }
9
+ rspec.spec_dir = "spec"
10
+ rspec.spec_helper = "spec/spec_helper.rb"
11
+
12
+
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ # watch(%r{^spec/usecase/(.+)\.rb$})
15
+ watch(%r{^model/(.+)\.rb$}) { |m| "spec/model/#{m[1]}_spec.rb" }
16
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
17
+ # watch(%r{^examples/time_graph/spec/(.+)_spec\.rb$})
18
+ watch('spec/spec_helper.rb') { "spec" }
19
+ end
20
+
21
+ interactor :simple
22
+ if RUBY_PLATFORM == 'java'
23
+ guard( 'jruby-rspec') {fire} #', :spec_paths => ["spec"]
24
+ else
25
+ guard( :rspec, cmd: "bundle exec rspec") { fire }
26
+ end
@@ -0,0 +1,129 @@
1
+ #Example: Time Graph
2
+
3
+ The bin-directory contains a customized console-application.
4
+ Any libraries are included and one can start exploring the features immediately.
5
+
6
+ *Prerequisites* :
7
+ * Edit the Gemfile, update the pathes to include the orientdb_jruby an d activeorient gem
8
+ * Run "Bundle install" and "Bundle update"
9
+ * customize config/connect.yml
10
+
11
+ There is a rspec-section, run "bundle exec guard", edit the spec-files and start the test by saving the dataset.
12
+
13
+ To play around, start the console by
14
+ cd bin
15
+ ./active-orient-console t # test-modus
16
+
17
+ The Database is initialized/resetted by calling
18
+
19
+ ```ruby
20
+ ActiveOrient::OrientSetup.init_database
21
+ ```
22
+
23
+ This executes the code located in 'config/init_db.rb'
24
+
25
+ The following hierarchy is build:
26
+
27
+ ```ruby
28
+ - E
29
+ - - day_of
30
+ - - time_of
31
+ - V
32
+ - - time_base
33
+ - - - monat
34
+ - - - stunde
35
+ - - - tag
36
+ ```
37
+ And this Graph is realized
38
+
39
+ ```ruby
40
+ Monat --[DAY_OF]-- Tag --[TIME_OF]-- Stunde
41
+ ```
42
+ and populated by calling
43
+
44
+ ```ruby
45
+ CreateTime.populate_month # 1 One Month whith appropoiate Days and Hours
46
+ ```
47
+
48
+ You can check the Status by counting the recods of the Classes
49
+
50
+ ```ruby
51
+ Monat.count # 1
52
+ Tag.count # 32
53
+ Stunde.count # 768
54
+ ```
55
+ which should be equal to the counts of the Edge-Classes DAY_OF and TIME_OF
56
+
57
+ In the Model-directory, customized methods simplify the usage of the graph.
58
+
59
+ Some Examples:
60
+
61
+ ```ruby
62
+ m = Date.today.month # current month
63
+
64
+ Monat[m].tag.value
65
+ => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
66
+
67
+ Monat[m].tag[9].stunde[9].value
68
+ => 9
69
+
70
+ Monat[month].tag[9].next.datum
71
+ => "10.8.2016"
72
+
73
+ Stunde[9] # [] is defined in model/timebase.rb
74
+ => An Array with Stunde-records
75
+ Stunde[9].datum # datum is defined in model/stunde.rb
76
+ => ["0.8.2016 9:00", "1.8.2016 9:00", "2.8.2016 9:00", "3.8.2016 9:00", "4.8.2016 9:00", "5.8.2016 9:00", "6.8.2016 9:00", "7.8.2016 9:00", "8.8.2016 9:00", "9.8.2016 9:00", "10.8.2016 9:00", "11.8.2016 9:00", "12.8.2016 9:00", "13.8.2016 9:00", "14.8.2016 9:00", "15.8.2016 9:00", "16.8.2016 9:00", "17.8.2016 9:00", "18.8.2016 9:00", "19.8.2016 9:00", "20.8.2016 9:00", "21.8.2016 9:00", "22.8.2016 9:00", "23.8.2016 9:00", "24.8.2016 9:00", "25.8.2016 9:00", "26.8.2016 9:00", "27.8.2016 9:00", "28.8.2016 9:00", "29.8.2016 9:00", "30.8.2016 9:00", "31.8.2016 9:00"]
77
+
78
+ Stunde[9][8 ..12].datum # call datum on selected Stunde-records
79
+ => ["8.8.2016 9:00", "9.8.2016 9:00", "10.8.2016 9:00", "11.8.2016 9:00", "12.8.2016 9:00"]
80
+
81
+ ```
82
+
83
+ then you can assign appointments to these dates
84
+
85
+
86
+ lets create a simple diary
87
+
88
+ ```ruby
89
+ ORD.create_vertex_class :termin
90
+ => Termin
91
+ ORD.create_edge_class :date_of
92
+ => DATE_OF
93
+ DATE_OF.create from: Monat[m].tag[9].stunde[12],
94
+ to: Termin.create( short: 'Mittagessen',
95
+ long: 'Schweinshaxen essen mit Lieschen Müller',
96
+ location: 'Hofbauhaus, München' )
97
+ => #<DATE_OF:0x0000000334e038 (..) @attributes={"out"=>"#21:57", "in"=>"#41:0", (..)}>
98
+ # create some regular events
99
+ # attach breakfirst at 9 o clock from the 10th to the 21st Day in the current month
100
+ DATE_OF.create from: Stunde[9][10..21], to: Termin.create( :short => 'Frühstück' )
101
+ => #<DATE_OF:0x000000028d5688 @metadata={(..) "cluster"=>45, "record"=>8},
102
+ @attributes={"out"=>"#22:188", "in"=>"#42:0",(..)}>
103
+
104
+ t = Termin.where short: 'Frühstück'
105
+ t.in_time_of.out.first.datum
106
+ => ["10.8.2016 9:00", "11.8.2016 9:00", "12.8.2016 9:00", "13.8.2016 9:00", "14.8.2016 9:00", "15.8.2016 9:00", "16.8.2016 9:00", "17.8.2016 9:00", "18.8.2016 9:00", "19.8.2016 9:00", "20.8.2016 9:00", "21.8.2016 9:00"]
107
+
108
+
109
+ ```
110
+
111
+
112
+ Another approach, starting with the simple graph
113
+
114
+
115
+
116
+ ```ruby
117
+ Monat[month].tag.each{|d| d.stunde.each{|s| s.termin=[]; s.save } } # populate hour-vertices
118
+ # we append our dates to the termin-property
119
+ Monat[month].tag[9].stunde[8].termin << "Post"
120
+ Monat[month].tag[9].stunde[9].termin << "zweites Frühstück"
121
+ Monat[month].tag.each{|t| t.stunde[12].termin << "Mittag"}
122
+ ```
123
+
124
+
125
+
126
+
127
+
128
+
129
+
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ ## loads the active-orient environment
3
+ ## and starts an interactive shell
4
+ ## Parameter: production (p)
5
+ ## development (d) [default]
6
+ ## test (t)
7
+ require 'logger'
8
+ LogLevel = Logger::WARN
9
+ require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
10
+
11
+ require 'orientdb' if RUBY_PLATFORM == 'java'
12
+ require 'yaml'
13
+
14
+ puts "ORD points to the REST-Instance, Database: #{ActiveOrient.database}"
15
+ puts "DB is the API-Instance of the database, DB.db gets the DB-Api-base " if RUBY_PLATFORM == 'java'
16
+
17
+ puts '-'* 35
18
+ ns= case ActiveOrient::Model.namespace
19
+ when Object
20
+ "No Prefix, just ClassName#CamelCase"
21
+ else
22
+ ActiveOrient::Model.namespace.to_s + "{ClassName.camelcase}"
23
+ end
24
+ puts "Namespace for model-classes : #{ns}"
25
+ puts "Allocated Classes (Hierarchy) ( Modelclasses are Camelized ):"
26
+ puts '-'* 35
27
+
28
+ puts ORD.class_hierarchy.to_yaml
29
+
30
+
31
+ include OrientDB
32
+
33
+ require 'irb'
34
+ ARGV.clear
35
+ IRB.start(__FILE__)
@@ -0,0 +1,119 @@
1
+ ## parameters
2
+ ## @namespace : Class on which ActiveOrient::Model's should base
3
+ ## @do_not_preallocate : avoid preallocation upon boot
4
+
5
+ require 'bundler/setup'
6
+ require 'yaml'
7
+ require 'active-orient'
8
+ if RUBY_VERSION == 'java'
9
+ require 'orientdb'
10
+ end
11
+ project_root = File.expand_path('../..', __FILE__)
12
+ #require "#{project_root}/lib/active-orient.rb"
13
+ # mixin for define_namespace
14
+ include ActiveOrient::Init
15
+
16
+ # make shure that E and V are required first => sort by length
17
+ models= Dir.glob(File.join( project_root, "model",'**', "*rb")).sort{|x,y| x.size <=> y.size }
18
+
19
+ begin
20
+ connect_file = File.expand_path('../../config/connect.yml', __FILE__)
21
+ config_file = File.expand_path('../../config/config.yml', __FILE__)
22
+ connectyml = YAML.load_file( connect_file )[:orientdb][:admin] if connect_file.present?
23
+ configyml = YAML.load_file( config_file )[:active_orient] if config_file.present?
24
+ rescue Errno::ENOENT => e
25
+ ActiveOrient::Base.logger = Logger.new('/dev/stdout')
26
+ ActiveOrient::OrientDB.logger.error{ "config/connectyml not present" }
27
+ ActiveOrient::OrientDB.logger.error{ "Using defaults to connect database-server" }
28
+
29
+ end
30
+
31
+ e= ARGV.present? ? ARGV.last.downcase : 'development'
32
+ env = if e =~ /^p/
33
+ 'production'
34
+ elsif e =~ /^t/
35
+ 'test'
36
+ else
37
+ 'development'
38
+ end
39
+ puts "Using #{env}-environment"
40
+
41
+
42
+ # lib/init.rb
43
+ define_namespace yml: configyml, namespace: @namespace
44
+
45
+ ActiveOrient::Model.model_dir = "#{project_root}/#{ configyml.present? ? configyml[:model_dir] : "model" }"
46
+ puts "BOOT--> Project-Root: #{project_root}"
47
+ puts "BOOT--> mode-dir: #{ActiveOrient::Model.model_dir}"
48
+
49
+ databaseyml = YAML.load_file( connect_file )[:orientdb][:database]
50
+ log_file = if config_file.present?
51
+ dev = YAML.load_file( connect_file )[:orientdb][:logger]
52
+ if dev.blank? || dev== 'stdout'
53
+ '/dev/stdout'
54
+ else
55
+ project_root+'/log/'+env+'.log'
56
+ end
57
+ end
58
+
59
+
60
+ logger = Logger.new log_file
61
+ logger.level = case env
62
+ when 'production'
63
+ Logger::ERROR
64
+ when 'development'
65
+ Logger::WARN
66
+ else
67
+ Logger::INFO
68
+ end
69
+ logger.formatter = proc do |severity, datetime, progname, msg|
70
+ "#{datetime.strftime("%d.%m.(%X)")}#{"%5s" % severity}->#{progname}:..:#{msg}\n"
71
+ end
72
+ ActiveOrient::Model.logger = logger
73
+ ActiveOrient::OrientDB.logger = logger
74
+ if connectyml.present? and connectyml[:user].present? and connectyml[:pass].present?
75
+ ActiveOrient.default_server= { user: connectyml[:user], password: connectyml[:pass] ,
76
+ server: 'localhost', port: 2480 }
77
+ ActiveOrient.database = @configDatabase.presence || databaseyml[env.to_sym]
78
+
79
+ ## Include customized NamingConvention for Edges
80
+ ActiveOrient::Model.orientdb_class name:"E"
81
+ ActiveOrient::Model.orientdb_class name:"V"
82
+ class E #< ActiveOrient::Model
83
+ def self.naming_convention name=nil
84
+ name.present? ? name.upcase : ref_name.upcase
85
+ end
86
+ end
87
+
88
+
89
+ ORD = ActiveOrient::OrientDB.new preallocate: @do_not_preallocate.present? ? false : true
90
+ if RUBY_PLATFORM == 'java'
91
+ DB = ActiveOrient::API.new preallocate: false
92
+ else
93
+ DB = ORD
94
+ end
95
+
96
+ # ORD.create_classes 'E', 'V'
97
+ # E.ref_name = 'E'
98
+ # V.ref_name = 'V'
99
+
100
+ # require model files after initializing the database
101
+ # require "#{project_root}/model/edge.rb"
102
+ # require "#{project_root}/model/vertex.rb"
103
+
104
+ # require db-init and application
105
+ require "#{project_root}/config/init_db.rb"
106
+ require "#{project_root}/lib/createTime.rb"
107
+
108
+ # thus the classes are predefined and modelfiles just extend the classes
109
+ #included_models = models.collect { |file| [file, require( file )] }
110
+ #puts "Included Models: "
111
+ #puts included_models.collect{|x,y| [ "\t",x.split("/").last , " \t-> " , y].join }.join("\n")
112
+ else
113
+ ActiveOrient::Base.logger = Logger.new('/dev/stdout')
114
+ ActiveOrient::OrientDB.logger.error{ "config/connectyml is misconfigurated" }
115
+ ActiveOrient::OrientDB.logger.error{ "Database Server is NOT available"}
116
+ end
117
+
118
+
119
+
@@ -0,0 +1,8 @@
1
+ ---
2
+ :active_orient:
3
+ ## Namespace: Prefix of Model-Objects. :self -> ActiveOrient::Model::{name}
4
+ ## :object => No Prefix
5
+ ## :active_orient => ActiveOrient::{name}
6
+ :namespace: :object
7
+ :model_dir: 'model'
8
+
@@ -0,0 +1,17 @@
1
+ ---
2
+ :orientdb:
3
+ :server: localhost # 172.28.50.109 # localhost #mailout.halfgarten-capital.de
4
+ :port: 2480
5
+ :logger: stdout # 'file' or 'stdout'
6
+ :database:
7
+ :development: time_production
8
+ :production: time_dev
9
+ :test: tempera
10
+ :admin:
11
+ :user: hctw
12
+ :pass: hc
13
+ :auth:
14
+ :user: topo
15
+ :pass: focus
16
+
17
+ # hfx: 101
@@ -0,0 +1,59 @@
1
+ # Execute with
2
+ # ActiveOrient::OrientSetup.init_database
3
+ #
4
+ module ActiveOrient
5
+ module OrientSetup
6
+ def self.init_database
7
+ (logger= ActiveOrient::Base.logger).progname= 'OrientSetup#InitDatabase'
8
+ vertexes = ORD.class_hierarchy base_class: 'time_base'
9
+ # because edges are not resolved because of the namingconvention
10
+ edges = ORD.class_hierarchy base_class: 'E'
11
+ logger.info{ " preallocated-database-classes: #{ORD.database_classes.join(" , ")} " }
12
+
13
+ delete_class = -> (c,d) do
14
+ the_class = ActiveOrient::Model.orientdb_class( name: c, superclass: d)
15
+ logger.info{ "The Class: "+the_class.to_s }
16
+ the_class.delete_class
17
+ end
18
+
19
+ logger.info{ " Deleting Class and Classdefinitions" }
20
+ vertexes.each{|v| delete_class[ v, :time_base ]}
21
+ delete_class[ :time_base, :V ] if defined?(TimeBase)
22
+ edges.each{|e| delete_class[ e, :E ] }
23
+
24
+ logger.info{ " Creating Classes " }
25
+ ORD.create_classes 'E', 'V'
26
+ #E.ref_name = 'E'
27
+ #V.ref_name = 'V'
28
+ #ActiveOrient::Init.vertex_and_egde_class
29
+ ORD.create_vertex_class :time_base # --> TimeBase
30
+ # hour, day: month cannot be alloacated, because Day is a class of DateTime and thus reserved
31
+ time_base_classes = ORD.create_classes( :stunde, :tag, :monat ){ :time_base } # --> Hour, Day, Month
32
+ TimeBase.create_property :value_string, type: :string
33
+ TimeBase.create_property :value, type: :integer
34
+ ## this puts an uniqe index on child-classes
35
+ #time_base_classes.each{|y| y.create_index :value }
36
+
37
+ # modified naming-convention in model/e.rb
38
+ edges = ORD.create_edge_class :time_of, :day_of # --> TIME_OF, :DAY_OF
39
+ edges.each &:uniq_index
40
+
41
+ ORD.database_classes # return_value
42
+ end
43
+ end
44
+ end
45
+ # to_do: define validations
46
+ # hour_class = r.create_vertex_class "Hour", properties: {value_string: {type: :string}, value: {type: :integer}}
47
+ # hour_class.alter_property property: "value", attribute: "MIN", alteration: 0
48
+ # hour_class.alter_property property: "value", attribute: "MAX", alteration: 23
49
+ #
50
+ # day_class = r.create_vertex_class "Day", properties: {value_string: {type: :string}, value: {type: :integer}}
51
+ # day_class.alter_property property: "value", attribute: "MIN", alteration: 1
52
+ # day_class.alter_property property: "value", attribute: "MAX", alteration: 31
53
+ #
54
+ # month_class = r.create_vertex_class "Month", properties: {value_string: {type: :string}, value: {type: :integer}}
55
+ # month_class.alter_property property: "value", attribute: "MIN", alteration: 1
56
+ # month_class.alter_property property: "value", attribute: "MAX", alteration: 12
57
+ #
58
+
59
+ # timeof_class = r.create_edge_class "TIMEOF"
@@ -0,0 +1,51 @@
1
+ #require 'time'
2
+
3
+
4
+
5
+ class CreateTime
6
+ class << self # singleton class
7
+ def populate_month year = Date.today.year, month = Date.today.month
8
+ timestamp = DateTime.new year, month,1
9
+ if Monat.where( :value => month ).blank?
10
+ der_monat= Monat.create value_string: timestamp.strftime("%B"), value: timestamp.month.to_i
11
+ last_month_day = (DateTime.new( year, month+1, 1)-1).day rescue 31 # rescue covers month > 12
12
+ (0 .. last_month_day ).each do | tag |
13
+ der_tag = Tag.create value_string: "March #{timestamp.day}", value: tag
14
+ print der_tag.value.to_s + " > "
15
+ ( 0 .. 23 ).each do | stunde |
16
+ die_stunde = Stunde.create value_string: "March #{timestamp.day} #{timestamp.hour}:00", value: stunde
17
+ print die_stunde.value.to_s + " .. "
18
+ TIME_OF.create_edge from: der_tag, to: die_stunde
19
+ timestamp += Rational(1,24) # + 1 hour
20
+ end
21
+ print "\n"
22
+ DAY_OF.create_edge from: der_monat, to: der_tag
23
+ end
24
+ else
25
+ "Month #{timestamp.strftime("%B %Y ") } exists "
26
+ end
27
+ end
28
+ end
29
+ end # class
30
+
31
+ ## here we start if the file is called from the command-lind
32
+ if $0 == __FILE__
33
+ require './config/boot'
34
+ ActiveOrient::OrientSetup.init_database # --> config/init_db
35
+ CreateTime.populate_month
36
+
37
+
38
+
39
+ puts "Features of the DateTime Graph"
40
+ puts '-' * 40
41
+ puts
42
+ puts "Allocated Month => Monat.first.value :" + Monat.first.value.to_s
43
+ puts
44
+ puts "Adressing Days => Monat.first.tag[2].value:" + Monat.first.tag[2].value.to_s
45
+ puts
46
+ puts "Adressing Hours => Monat.first.tag[2].stunde[4].value :" + Monat.first.tag[5].stunde[4].value.to_s
47
+
48
+
49
+
50
+
51
+ end