orientdb 1.2.0

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.
Files changed (48) hide show
  1. data/.document +5 -0
  2. data/Gemfile +8 -0
  3. data/Gemfile.lock +32 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +88 -0
  6. data/Rakefile +57 -0
  7. data/bin/orientdb_console +23 -0
  8. data/lib/jars/blueprints-core-2.2.0-SNAPSHOT.jar +0 -0
  9. data/lib/jars/blueprints-orient-graph-2.2.0-SNAPSHOT.jar +0 -0
  10. data/lib/jars/orient-commons-1.2.0.jar +0 -0
  11. data/lib/jars/orientdb-client-1.2.0.jar +0 -0
  12. data/lib/jars/orientdb-core-1.2.0.jar +0 -0
  13. data/lib/jars/orientdb-distributed-1.2.0.jar +0 -0
  14. data/lib/jars/orientdb-enterprise-1.2.0.jar +0 -0
  15. data/lib/jars/orientdb-graphdb-1.2.0.jar +0 -0
  16. data/lib/jars/orientdb-server-1.2.0.jar +0 -0
  17. data/lib/jars/orientdb-tools-1.2.0.jar +0 -0
  18. data/lib/jars/pipes-2.0.0-SNAPSHOT.jar +0 -0
  19. data/lib/orientdb.rb +29 -0
  20. data/lib/orientdb/constants.rb +57 -0
  21. data/lib/orientdb/database.rb +167 -0
  22. data/lib/orientdb/document.rb +78 -0
  23. data/lib/orientdb/ext.rb +13 -0
  24. data/lib/orientdb/oclass.rb +141 -0
  25. data/lib/orientdb/property.rb +37 -0
  26. data/lib/orientdb/record.rb +18 -0
  27. data/lib/orientdb/rid.rb +46 -0
  28. data/lib/orientdb/schema.rb +33 -0
  29. data/lib/orientdb/sql.rb +18 -0
  30. data/lib/orientdb/sql/common.rb +247 -0
  31. data/lib/orientdb/sql/delete.rb +23 -0
  32. data/lib/orientdb/sql/ext.rb +249 -0
  33. data/lib/orientdb/sql/insert.rb +37 -0
  34. data/lib/orientdb/sql/query.rb +138 -0
  35. data/lib/orientdb/sql/update.rb +57 -0
  36. data/lib/orientdb/storage.rb +51 -0
  37. data/lib/orientdb/version.rb +3 -0
  38. data/orientdb.gemspec +95 -0
  39. data/spec/database_spec.rb +111 -0
  40. data/spec/document_spec.rb +99 -0
  41. data/spec/graph_spec.rb +39 -0
  42. data/spec/orientdb_spec.rb +10 -0
  43. data/spec/spec.opts +7 -0
  44. data/spec/spec_basic_helper.rb +25 -0
  45. data/spec/spec_helper.rb +68 -0
  46. data/spec/sql_spec.rb +839 -0
  47. data/spec/tinkerpop_graph_spec.rb +32 -0
  48. metadata +165 -0
@@ -0,0 +1,57 @@
1
+ module OrientDB::SQL
2
+ class Update
3
+
4
+ include OrientDB::SQL::UtilsMixin
5
+ include OrientDB::SQL::ClassClusterParametersMixin
6
+ include OrientDB::SQL::FieldsValuesParametersMixin
7
+ include OrientDB::SQL::ConditionsParametersMixin
8
+
9
+ def initialize
10
+ @oclass = nil
11
+ @cluster = nil
12
+ @action = "SET"
13
+ @fields = []
14
+ @values = []
15
+ @conditions = []
16
+ end
17
+
18
+ def action(new_action)
19
+ @action = new_action.to_s.upcase
20
+ self
21
+ end
22
+
23
+ alias :action! :action
24
+
25
+ def to_s
26
+ (target_sql(:update) + fields_sql + conditions_sql).strip
27
+ end
28
+
29
+ def to_sql_command
30
+ OrientDB::SQLCommand.new to_s
31
+ end
32
+
33
+ private
34
+
35
+ def fields_sql
36
+ raise "Missing fields" if @fields.empty?
37
+ str = "#{@action} "
38
+ if @action == "REMOVE" && @values.empty?
39
+ str += @fields.join(', ')
40
+ else
41
+ raise "Missing values" if @values.empty?
42
+ raise "Unbalanced fields & values" unless @values.size == @fields.size
43
+ ary = []
44
+ @fields.each_with_index do |field, idx|
45
+ ary << "#{field} = #{@values[idx]}"
46
+ end
47
+ str += ary.join(", ")
48
+ end
49
+ str + ' '
50
+ end
51
+
52
+ def values_sql
53
+ "(#{@values.join(', ')})"
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,51 @@
1
+ module OrientDB
2
+
3
+ class LocalStorage
4
+
5
+ def get_cluster(name_or_id)
6
+ case name_or_id
7
+ when Integer
8
+ getClusterById name_or_id
9
+ else
10
+ getClusterByName name_or_id.to_s
11
+ end
12
+ end
13
+
14
+ def inspect
15
+ "#<OrientDB::LocalStorage:#{hashCode}>"
16
+ end
17
+
18
+ alias :to_s :inspect
19
+
20
+ end
21
+
22
+ class RemoteStorage
23
+
24
+ def get_cluster(name_or_id)
25
+ case name_or_id
26
+ when Integer
27
+ getClusterById name_or_id
28
+ else
29
+ getClusterByName name_or_id.to_s
30
+ end
31
+ end
32
+
33
+ def inspect
34
+ "#<OrientDB::RemoteStorage:#{hashCode}>"
35
+ end
36
+
37
+ alias :to_s :inspect
38
+
39
+ end
40
+
41
+ class LocalCluster
42
+
43
+ def inspect
44
+ "#<OrientDB::LocalCluster:#{getId} name=#{getName.inspect}>"
45
+ end
46
+
47
+ alias :to_s :inspect
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,3 @@
1
+ module OrientDB
2
+ VERSION = '1.2.0'
3
+ end
@@ -0,0 +1,95 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "orientdb"
8
+ s.version = "1.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Adrian Madrid"]
12
+ s.date = "2012-11-13"
13
+ s.description = "Simple JRuby wrapper for the OrientDB."
14
+ s.email = "aemadrid@gmail.com"
15
+ s.executables = ["orientdb_console"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "bin/orientdb_console",
28
+ "lib/jars/blueprints-core-2.2.0-SNAPSHOT.jar",
29
+ "lib/jars/blueprints-orient-graph-2.2.0-SNAPSHOT.jar",
30
+ "lib/jars/orient-commons-1.2.0.jar",
31
+ "lib/jars/orientdb-client-1.2.0.jar",
32
+ "lib/jars/orientdb-core-1.2.0.jar",
33
+ "lib/jars/orientdb-distributed-1.2.0.jar",
34
+ "lib/jars/orientdb-enterprise-1.2.0.jar",
35
+ "lib/jars/orientdb-graphdb-1.2.0.jar",
36
+ "lib/jars/orientdb-server-1.2.0.jar",
37
+ "lib/jars/orientdb-tools-1.2.0.jar",
38
+ "lib/jars/pipes-2.0.0-SNAPSHOT.jar",
39
+ "lib/orientdb.rb",
40
+ "lib/orientdb/constants.rb",
41
+ "lib/orientdb/database.rb",
42
+ "lib/orientdb/document.rb",
43
+ "lib/orientdb/ext.rb",
44
+ "lib/orientdb/oclass.rb",
45
+ "lib/orientdb/property.rb",
46
+ "lib/orientdb/record.rb",
47
+ "lib/orientdb/rid.rb",
48
+ "lib/orientdb/schema.rb",
49
+ "lib/orientdb/sql.rb",
50
+ "lib/orientdb/sql/common.rb",
51
+ "lib/orientdb/sql/delete.rb",
52
+ "lib/orientdb/sql/ext.rb",
53
+ "lib/orientdb/sql/insert.rb",
54
+ "lib/orientdb/sql/query.rb",
55
+ "lib/orientdb/sql/update.rb",
56
+ "lib/orientdb/storage.rb",
57
+ "lib/orientdb/version.rb",
58
+ "orientdb.gemspec",
59
+ "spec/database_spec.rb",
60
+ "spec/document_spec.rb",
61
+ "spec/graph_spec.rb",
62
+ "spec/orientdb_spec.rb",
63
+ "spec/spec.opts",
64
+ "spec/spec_basic_helper.rb",
65
+ "spec/spec_helper.rb",
66
+ "spec/sql_spec.rb",
67
+ "spec/tinkerpop_graph_spec.rb"
68
+ ]
69
+ s.homepage = "http://github.com/aemadrid/orientdb-jruby"
70
+ s.require_paths = ["lib"]
71
+ s.rubygems_version = "1.8.24"
72
+ s.summary = "Simple JRuby wrapper for the OrientDB."
73
+
74
+ if s.respond_to? :specification_version then
75
+ s.specification_version = 3
76
+
77
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
78
+ s.add_development_dependency(%q<rspec>, [">= 2.4"])
79
+ s.add_development_dependency(%q<awesome_print>, [">= 0"])
80
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
81
+ s.add_development_dependency(%q<jeweler>, [">= 1.8.3"])
82
+ else
83
+ s.add_dependency(%q<rspec>, [">= 2.4"])
84
+ s.add_dependency(%q<awesome_print>, [">= 0"])
85
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
86
+ s.add_dependency(%q<jeweler>, [">= 1.8.3"])
87
+ end
88
+ else
89
+ s.add_dependency(%q<rspec>, [">= 2.4"])
90
+ s.add_dependency(%q<awesome_print>, [">= 0"])
91
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
92
+ s.add_dependency(%q<jeweler>, [">= 1.8.3"])
93
+ end
94
+ end
95
+
@@ -0,0 +1,111 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe "OrientDB" do
4
+
5
+ describe "DocumentDatabase" do
6
+
7
+ before :all do
8
+ create_classes
9
+ end
10
+
11
+ it "should create a valid simple table" do
12
+ exp_class = "#<OrientDB::OClassImpl:person name=STRING>"
13
+ exp_props = ["#<OrientDB::Property:name type=string indexed=false mandatory=false not_null=false>"]
14
+ @person_class.to_s.should == exp_class
15
+ @person_class.properties.map { |x| x.to_s }.should == exp_props
16
+ end
17
+
18
+ it "should create a valid simple descendant table" do
19
+ exp_class = "#<OrientDB::OClassImpl:customer super=person tab=FLOAT name=STRING>"
20
+ exp_props = [
21
+ "#<OrientDB::Property:tab type=float indexed=false mandatory=false not_null=false>",
22
+ "#<OrientDB::Property:name type=string indexed=false mandatory=false not_null=false>"
23
+ ]
24
+ @customer_class.to_s.should == exp_class
25
+ @customer_class.properties.map { |x| x.to_s }.should == exp_props
26
+ end
27
+
28
+ it "should create a complex table" do
29
+ #exp_class = "#<OrientDB::OClassImpl:invoice total=FLOAT sold_on=DATE lines=LINKLIST number=INTEGER(idx) customer=LINK>"
30
+ exp_props = [
31
+ "#<OrientDB::Property:total type=float indexed=false mandatory=false not_null=false>",
32
+ "#<OrientDB::Property:sold_on type=date indexed=false mandatory=false not_null=false>",
33
+ "#<OrientDB::Property:lines type=linklist indexed=false mandatory=false not_null=false>",
34
+ "#<OrientDB::Property:number type=integer indexed=true mandatory=true not_null=false>",
35
+ "#<OrientDB::Property:customer type=link indexed=false mandatory=false not_null=true>"
36
+ ]
37
+ #@invoice_class.to_s.should == exp_class
38
+ #@invoice_class.properties.map { |x| x.to_s }.should == exp_props
39
+
40
+ #TODO: test all those things above
41
+ %w(total sold_on lines number customer).each do |property|
42
+ @invoice_class.get_property(property).class.to_s.should == "Java::ComOrientechnologiesOrientCoreMetadataSchema::OPropertyImpl"
43
+ end
44
+
45
+ number_prop = @invoice_class.get_property("number")
46
+ number_prop.type.to_s.should == "INTEGER"
47
+ number_prop.indexed.should be_true
48
+ number_prop.mandatory.should be_true
49
+ number_prop.not_null.should be_false
50
+ end
51
+
52
+ describe "Query" do
53
+
54
+ before :all do
55
+ create_classes
56
+
57
+ @oclass = @employee_class.name
58
+ @e1 = OrientDB::Document.create DB, @oclass, :name => "Mark", :age => 36, :groups => %w{admin sales}
59
+ @e2 = OrientDB::Document.create DB, @oclass, :name => "John", :age => 37, :groups => %w{admin tech}
60
+ @e3 = OrientDB::Document.create DB, @oclass, :name => "Luke", :age => 38, :groups => %w{tech support}
61
+ @e4 = OrientDB::Document.create DB, @oclass, :name => "Matt", :age => 39, :groups => %w{admin office}
62
+ @e5 = OrientDB::Document.create DB, @oclass, :name => "Pete", :age => 40, :groups => %w{vp office}
63
+ @employees = [@e1, @e2, @e3, @e4, @e5]
64
+ end
65
+
66
+ it "should prepare valid queries" do
67
+ exp = "SELECT * FROM #{@oclass}"
68
+ qry1 = DB.prepare_sql_query exp
69
+ qry1.should be_a_kind_of OrientDB::SQLSynchQuery
70
+ qry1.text.should == exp
71
+
72
+ qry2 = DB.prepare_sql_query OrientDB::SQL::Query.new.from(@oclass).where(:name => "John")
73
+ qry2.should be_a_kind_of OrientDB::SQLSynchQuery
74
+ qry2.text.should == "SELECT FROM #{@oclass} WHERE name = 'John'"
75
+
76
+ qry3 = DB.prepare_sql_query qry2.text
77
+ qry3.should be_a_kind_of OrientDB::SQLSynchQuery
78
+ qry3.text.should == qry2.text
79
+
80
+ qry4 = DB.prepare_sql_query qry3
81
+ qry4.should be_a_kind_of OrientDB::SQLSynchQuery
82
+ qry4.text.should == qry2.text
83
+ end
84
+
85
+ it "should get all rows for a class" do
86
+ DB.all('SELECT FROM employee').map { |x| x.name }.sort.should == @employees.map { |x| x.name }.sort
87
+ end
88
+
89
+ it "should create a valid query and return the right results" do
90
+ qry = OrientDB::SQL::Query.new.from(@oclass).where("'admin' IN groups", 'age > 37')
91
+ DB.first(qry).should == @e4
92
+ end
93
+
94
+ it "should find rows by simple field values" do
95
+ DB.first('SELECT * FROM employee WHERE age = 37').should == @e2
96
+ end
97
+
98
+ it "should find rows by simple field values" do
99
+ DB.find_by_rid(@e3.rid).rid.should == @e3.rid
100
+ end
101
+
102
+ it "should find rows by values in arrays" do
103
+ qry = DB.prepare_sql_query "SELECT * FROM #{@oclass} WHERE 'admin' IN groups"
104
+ DB.all(qry).map { |x| x.name }.sort.should == [@e1, @e2, @e4].map { |x| x.name }.sort
105
+ end
106
+
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -0,0 +1,99 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe "OrientDB" do
4
+
5
+ describe "RID" do
6
+ it "should create valid empty" do
7
+ rid = OrientDB::RID.new
8
+ rid.to_s == '-1:-1'
9
+ rid.valid?.should == true
10
+ end
11
+
12
+ it "should create valid saved" do
13
+ rid = OrientDB::RID.new '5:40'
14
+ rid.to_s == '5:40'
15
+ rid.valid?.should == true
16
+ rid.saved?.should == true
17
+ rid.unsaved?.should == false
18
+ rid.cluster_id.should == 5
19
+ rid.document_id.should == 40
20
+ end
21
+
22
+ it "should create valid unsaved" do
23
+ rid = OrientDB::RID.new '-1:-1'
24
+ rid.to_s == '5:40'
25
+ rid.valid?.should == true
26
+ rid.saved?.should == false
27
+ rid.unsaved?.should == true
28
+ rid.cluster_id.should == -1
29
+ rid.document_id.should == -1
30
+ end
31
+ end
32
+
33
+ describe "Document" do
34
+
35
+ before :all do
36
+ create_classes
37
+
38
+ @h_fields = {:sku => 'H509', :title => "Hammer", :price => 3.25}
39
+ @hammer = OrientDB::Document.create DB, @product_class.name, @h_fields
40
+
41
+ @n_fields = {:sku => 'N034', :title => "Nail", :price => 0.25}
42
+ @nail = OrientDB::Document.create DB, @product_class.name, @n_fields
43
+
44
+ @line1 = OrientDB::Document.create DB, @line_class.name,
45
+ :product => @hammer,
46
+ :quantity => 1,
47
+ :price => @hammer.price
48
+ @line2 = OrientDB::Document.create DB, @line_class.name,
49
+ :product => @nail,
50
+ :quantity => 10,
51
+ :price => @nail.price
52
+ @lines = [@line1, @line2]
53
+ @total = @lines.inject(0.0) { |a, x| a + x.price * x.quantity }
54
+
55
+ @customer = OrientDB::Document.create DB, @customer_class.name,
56
+ :name => "Mark Dumber",
57
+ :tab => 500.00
58
+
59
+ @invoice = OrientDB::Document.create DB, @invoice_class.name,
60
+ :number => 10001,
61
+ :customer => @customer,
62
+ :total => @total.to_s,
63
+ :sold_on => Date.civil(2011, 1, 1).proxy_object,
64
+ :lines => @lines
65
+ end
66
+
67
+ it "should instantiate new documents" do
68
+ @screw = OrientDB::Document.new DB, @product_class.name, :sku => "S365", :price => 0.33
69
+ @screw.should be_a_kind_of OrientDB::Document
70
+ end
71
+
72
+ it "should create simple documents" do
73
+ @hammer.should be_a_kind_of OrientDB::Document
74
+ @h_fields.each { |k, v| @hammer[k].should == v }
75
+
76
+ @nail.should be_a_kind_of OrientDB::Document
77
+ @n_fields.each { |k, v| @nail.send(k).should == v }
78
+ end
79
+
80
+ it "should create embedded documents" do
81
+ @line1.should be_a_kind_of OrientDB::Document
82
+ @line1.product.should == @hammer
83
+ @line1.price.should == @hammer.price
84
+
85
+ @line2.should be_a_kind_of OrientDB::Document
86
+ @line2.product.should == @nail
87
+ @line2.price.should == @nail.price
88
+ end
89
+
90
+ it "should create complex, embedded documents" do
91
+ @invoice.should be_a_kind_of OrientDB::Document
92
+ # @invoice.to_s.should == "#<OrientDB::Document:invoice_line:8:0 product:#<OrientDB::Document:product:7:0 title:Hammer price:5.5 sku:H509> price:5.5 quantity:1>"
93
+ @invoice.customer.should == @customer
94
+ @invoice.total = @total
95
+ @invoice.lines.map{|x| x}.should == [@line1, @line2]
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe "OrientDB" do
4
+
5
+ describe "Graph Database" do
6
+
7
+ before do
8
+ @database = OrientDB::GraphDatabase.new("local:#{TEST_DB_PATH}/graph").create
9
+ @root_node = @database.create_vertex.field("id", 0).save
10
+ #this creates a long chain of nodes... 1000 of 'em that are chained together
11
+ @last_node = @root_node
12
+ 1000.times do |i|
13
+ new_node = @database.create_vertex.field("id", i+1).save
14
+ @database.create_edge(@last_node, new_node)
15
+ @last_node = new_node
16
+ end
17
+ @database.set_root("graph", @root_node)
18
+ end
19
+
20
+ after do
21
+ @database.drop
22
+ @database.close
23
+ end
24
+
25
+ it "should get the root" do
26
+ @database.get_root("graph").should == @root_node
27
+ end
28
+
29
+ it "should traverse to the last node" do
30
+ node = @root_node
31
+ while @database.get_out_edges(node) and !@database.get_out_edges(node).empty?
32
+ node = @database.get_in_vertex(@database.get_out_edges(node).first)
33
+ end
34
+ node.should == @last_node
35
+ end
36
+
37
+ end
38
+
39
+ end