orientdb 1.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +32 -0
- data/LICENSE +20 -0
- data/README.rdoc +88 -0
- data/Rakefile +58 -0
- data/bin/orientdb_console +23 -0
- data/lib/jars/blueprints-core-2.2.0-SNAPSHOT.jar +0 -0
- data/lib/jars/blueprints-orient-graph-2.2.0-SNAPSHOT.jar +0 -0
- data/lib/jars/orient-commons-1.2.0.jar +0 -0
- data/lib/jars/orientdb-client-1.2.0.jar +0 -0
- data/lib/jars/orientdb-core-1.2.0.jar +0 -0
- data/lib/jars/orientdb-distributed-1.2.0.jar +0 -0
- data/lib/jars/orientdb-enterprise-1.2.0.jar +0 -0
- data/lib/jars/orientdb-graphdb-1.2.0.jar +0 -0
- data/lib/jars/orientdb-server-1.2.0.jar +0 -0
- data/lib/jars/orientdb-tools-1.2.0.jar +0 -0
- data/lib/jars/pipes-2.0.0-SNAPSHOT.jar +0 -0
- data/lib/orientdb.rb +29 -0
- data/lib/orientdb/constants.rb +57 -0
- data/lib/orientdb/database.rb +167 -0
- data/lib/orientdb/document.rb +78 -0
- data/lib/orientdb/ext.rb +13 -0
- data/lib/orientdb/oclass.rb +141 -0
- data/lib/orientdb/property.rb +37 -0
- data/lib/orientdb/record.rb +18 -0
- data/lib/orientdb/rid.rb +46 -0
- data/lib/orientdb/schema.rb +33 -0
- data/lib/orientdb/sql.rb +18 -0
- data/lib/orientdb/sql/common.rb +247 -0
- data/lib/orientdb/sql/delete.rb +23 -0
- data/lib/orientdb/sql/ext.rb +249 -0
- data/lib/orientdb/sql/insert.rb +37 -0
- data/lib/orientdb/sql/query.rb +138 -0
- data/lib/orientdb/sql/update.rb +57 -0
- data/lib/orientdb/storage.rb +51 -0
- data/lib/orientdb/version.rb +3 -0
- data/orientdb.gemspec +96 -0
- data/spec/database_spec.rb +111 -0
- data/spec/document_spec.rb +99 -0
- data/spec/graph_spec.rb +39 -0
- data/spec/orientdb_spec.rb +10 -0
- data/spec/spec.opts +7 -0
- data/spec/spec_basic_helper.rb +25 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/sql_spec.rb +839 -0
- data/spec/tinkerpop_graph_spec.rb +32 -0
- metadata +165 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
awesome_print (1.1.0)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.8.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rdoc
|
12
|
+
json (1.7.5-java)
|
13
|
+
rake (10.0.0)
|
14
|
+
rdoc (3.12)
|
15
|
+
json (~> 1.4)
|
16
|
+
rspec (2.11.0)
|
17
|
+
rspec-core (~> 2.11.0)
|
18
|
+
rspec-expectations (~> 2.11.0)
|
19
|
+
rspec-mocks (~> 2.11.0)
|
20
|
+
rspec-core (2.11.1)
|
21
|
+
rspec-expectations (2.11.3)
|
22
|
+
diff-lcs (~> 1.1.3)
|
23
|
+
rspec-mocks (2.11.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
java
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
awesome_print
|
30
|
+
bundler (>= 1.0.0)
|
31
|
+
jeweler (>= 1.8.3)
|
32
|
+
rspec (>= 2.4)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Adrian Madrid
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
= orientdb
|
2
|
+
|
3
|
+
orientdb is a little gem that wraps the Java OrientDB library into a more comfortable Ruby package (in JRuby, of course).
|
4
|
+
|
5
|
+
== What is OrientDB?
|
6
|
+
|
7
|
+
According to the website:
|
8
|
+
|
9
|
+
OrientDB is a new Open Source NoSQL DBMS born with the best features of all the others. It's written in Java and it's amazing fast: can store up to 150,000 records per second on common hardware. Even if it's Document based database the relationships are managed as in Graph Databases with direct connections among records. You can travere entire or part of trees and graphs of records in few milliseconds. Supports schema-less, schema-full and schema-mixed modes. Has a strong security profiling system based on user and roles and support the SQL between the query languages. Thank to the SQL layer it's straightforward to use it for people skilled in Relational world.
|
10
|
+
|
11
|
+
== Getting started
|
12
|
+
|
13
|
+
Let's get the gem installed and test out the interactive console.
|
14
|
+
|
15
|
+
shell> rvm jruby
|
16
|
+
shell> gem install orientdb
|
17
|
+
shell> orientdb_console
|
18
|
+
|
19
|
+
>> db = OrientDB::DocumentDatabase.connect "remote:localhost/demo", 'admin', 'admin'
|
20
|
+
=> #<OrientDB::Database:0x6a346239 @proxy_object=#<Java::ComOrientechnologiesOrientCoreDbDocument::ODatabaseDocumentTx:0x14860315>
|
21
|
+
>> customer = db.get_class "Customer"
|
22
|
+
=> #<OrientDB::OClass:Customer name:string>
|
23
|
+
>> customer.add :name, :string
|
24
|
+
=> true
|
25
|
+
>> db.schema.save
|
26
|
+
=> #<Java::ComOrientechnologiesOrientCoreMetadataSchema::OSchema:0x4a5afcb1>
|
27
|
+
>> invoice = db.get_or_create_class "Invoice"
|
28
|
+
=> #<OrientDB::OClass:Invoice id:integer date:date customer:link total:float>
|
29
|
+
>> invoice.add :id, :int
|
30
|
+
=> true
|
31
|
+
>> invoice.add :date, :date
|
32
|
+
=> true
|
33
|
+
>> invoice.add :total, :float
|
34
|
+
=> true
|
35
|
+
>> invoice.add :customer, customer
|
36
|
+
=> true
|
37
|
+
>> db.schema.save
|
38
|
+
=> #<Java::ComOrientechnologiesOrientCoreMetadataSchema::OSchema:0x4a5afcb1>
|
39
|
+
>> c1 = OrientDB::Document.create db, "Customer", :name => "Leonardo"
|
40
|
+
=> #<OrientDB::Document:Customer name:Leonardo>
|
41
|
+
>> i1 = OrientDB::Document.create db, "Invoice", :id => 1, :data => DateTime.now, :total => 350.75, :customer => c1
|
42
|
+
=> #<OrientDB::Document:Invoice total:350.75 id:1 data:Wed Nov 02 18:21:13 MDT 3910 customer:#<OrientDB::Document:Customer name:Leonardo>>
|
43
|
+
>> i2 = OrientDB::Document.new db, "Invoice", :id => 12
|
44
|
+
=> #<OrientDB::Document:Invoice id:12>
|
45
|
+
>> i2.date = DateTime.now
|
46
|
+
=> #<DateTime: 5893210835369/2400000,-1/4,2299161>
|
47
|
+
>> i2.total = 275.25
|
48
|
+
=> 275.25
|
49
|
+
>> i2.customer = c1
|
50
|
+
=> #<OrientDB::Document:Customer name:Leonardo>
|
51
|
+
>> i2.extra = [3.50, 0.75]
|
52
|
+
=> [3.5, 0.75]
|
53
|
+
>> i2.save
|
54
|
+
=> #<Java::ComOrientechnologiesOrientCoreRecordImpl::ODocument:0x18b9459c>
|
55
|
+
>> i2
|
56
|
+
=> #<OrientDB::Document:Invoice total:275.25 id:12 extra:3.50.75 customer:#<OrientDB::Document:Customer name:Leonardo> date:Wed Nov 02 18:21:13 MDT 3910>
|
57
|
+
>> db.count_class "Customer"
|
58
|
+
=> 1
|
59
|
+
>> db.count_class "Invoice"
|
60
|
+
=> 2
|
61
|
+
>> cs = db.all_in_class "Customer"
|
62
|
+
=> [#<OrientDB::Document:Customer name:Leonardo>]
|
63
|
+
>> c1 = cs.first
|
64
|
+
=> #<OrientDB::Document:Customer name:Leonardo>
|
65
|
+
>> is = db.all_in_class "Invoice"
|
66
|
+
=> [#<OrientDB::Document:Invoice total:275.25 id:12 extra:[3.5, 0.75] customer:#<OrientDB::Document:Customer name:Leonardo> date:Wed Nov 02 18:21:13 MDT 3910>, #<OrientDB::Document:Invoice total:350.75 id:1 data:61246887673000 customer:#<OrientDB::Document:Customer name:Leonardo>>]
|
67
|
+
>> i1 = is.first
|
68
|
+
=> #<OrientDB::Document:Invoice total:275.25 id:12 extra:[3.5, 0.75] customer:#<OrientDB::Document:Customer name:Leonardo> date:Wed Nov 02 18:21:13 MDT 3910>
|
69
|
+
>> i2 = is.last
|
70
|
+
=> #<OrientDB::Document:Invoice total:350.75 id:1 data:61246887673000 customer:#<OrientDB::Document:Customer name:Leonardo>>
|
71
|
+
|
72
|
+
== Contributors
|
73
|
+
|
74
|
+
* Topper Bowers @tobowers - Updated jars to 1.20 and added graph capabilities.
|
75
|
+
|
76
|
+
== Note on Patches/Pull Requests
|
77
|
+
|
78
|
+
* Fork the project.
|
79
|
+
* Make your feature addition or bug fix.
|
80
|
+
* Add tests for it. This is important so I don't break it in a
|
81
|
+
future version unintentionally.
|
82
|
+
* Commit, do not mess with rakefile, version, or history.
|
83
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
84
|
+
* Send me a pull request. Bonus points for topic branches.
|
85
|
+
|
86
|
+
== Copyright
|
87
|
+
|
88
|
+
Copyright (c) 2010 Adrian Madrid. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
#
|
13
|
+
# Test a local database:
|
14
|
+
# rake spec
|
15
|
+
#
|
16
|
+
# Test a remote database:
|
17
|
+
# ORIENTDB_TEST_URL=remote:localhost/test ORIENTDB_TEST_USERNAME=admin ORIENTDB_TEST_PASSWORD=admin ORIENTDB_TEST_POOLED=true rake spec
|
18
|
+
#
|
19
|
+
# Test a pooled remote database:
|
20
|
+
# ORIENTDB_TEST_URL=remote:localhost/test ORIENTDB_TEST_USERNAME=admin ORIENTDB_TEST_PASSWORD=admin ORIENTDB_TEST_POOLED=true rake spec
|
21
|
+
#
|
22
|
+
|
23
|
+
lib = File.expand_path('../lib', __FILE__)
|
24
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
25
|
+
require 'orientdb/version'
|
26
|
+
|
27
|
+
require 'jeweler'
|
28
|
+
Jeweler::Tasks.new do |gem|
|
29
|
+
gem.name = "orientdb"
|
30
|
+
gem.version = OrientDB::VERSION
|
31
|
+
gem.homepage = "http://github.com/aemadrid/orientdb-jruby"
|
32
|
+
gem.summary = %Q{Simple JRuby wrapper for the OrientDB.}
|
33
|
+
gem.description = %Q{Simple JRuby wrapper for the OrientDB.}
|
34
|
+
gem.email = "aemadrid@gmail.com"
|
35
|
+
gem.authors = ["Adrian Madrid"]
|
36
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
37
|
+
gem.platform = 'java'
|
38
|
+
# dependencies defined in Gemfile
|
39
|
+
end
|
40
|
+
Jeweler::RubygemsDotOrgTasks.new
|
41
|
+
|
42
|
+
require 'rspec/core'
|
43
|
+
require 'rspec/core/rake_task'
|
44
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
45
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
46
|
+
end
|
47
|
+
|
48
|
+
task :default => :spec
|
49
|
+
|
50
|
+
require 'rdoc/task'
|
51
|
+
Rake::RDocTask.new do |rdoc|
|
52
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
+
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
55
|
+
rdoc.title = "bd_money #{version}"
|
56
|
+
rdoc.rdoc_files.include('README*')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/orientdb")
|
3
|
+
|
4
|
+
if ARGV.include?('test:db')
|
5
|
+
GEM_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
6
|
+
TEMP_DIR = Dir.pwd + '/tmp'
|
7
|
+
|
8
|
+
TEST_DB_PATH = "#{TEMP_DIR}/databases/db_#{rand(999) + 1}"
|
9
|
+
|
10
|
+
puts ">> GEM_ROOT : #{GEM_ROOT}"
|
11
|
+
puts ">> TEST_DB PATH : #{TEST_DB_PATH}"
|
12
|
+
|
13
|
+
require 'fileutils'
|
14
|
+
FileUtils.remove_dir "#{TEMP_DIR}/databases" rescue nil
|
15
|
+
FileUtils.mkdir_p TEST_DB_PATH
|
16
|
+
DB = OrientDB::DocumentDatabase.new("local:#{TEST_DB_PATH}/test").create
|
17
|
+
end
|
18
|
+
|
19
|
+
include OrientDB
|
20
|
+
|
21
|
+
require 'irb'
|
22
|
+
ARGV.clear
|
23
|
+
IRB.start(__FILE__)
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/orientdb.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
raise "OrieentDB-client only runs on JRuby. Sorry!" unless (RUBY_PLATFORM =~ /java/)
|
2
|
+
|
3
|
+
module OrientDB
|
4
|
+
GEM_PATH = File.dirname File.expand_path(__FILE__) unless const_defined?(:GEM_PATH)
|
5
|
+
end
|
6
|
+
|
7
|
+
$: << OrientDB::GEM_PATH
|
8
|
+
$: << File.join(OrientDB::GEM_PATH, 'jars')
|
9
|
+
|
10
|
+
require 'java'
|
11
|
+
require "orient-commons-1.2.0"
|
12
|
+
require "orientdb-client-1.2.0"
|
13
|
+
require "orientdb-enterprise-1.2.0"
|
14
|
+
require "blueprints-core-2.2.0-SNAPSHOT"
|
15
|
+
require "blueprints-orient-graph-2.2.0-SNAPSHOT"
|
16
|
+
require "pipes-2.0.0-SNAPSHOT"
|
17
|
+
|
18
|
+
require 'orientdb/version'
|
19
|
+
require 'orientdb/ext'
|
20
|
+
require 'orientdb/rid'
|
21
|
+
require 'orientdb/constants'
|
22
|
+
require 'orientdb/property'
|
23
|
+
require 'orientdb/schema'
|
24
|
+
require 'orientdb/storage'
|
25
|
+
require 'orientdb/database'
|
26
|
+
require 'orientdb/record'
|
27
|
+
require 'orientdb/document'
|
28
|
+
require 'orientdb/sql'
|
29
|
+
require 'orientdb/oclass'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module OrientDB
|
2
|
+
CORE = com.orientechnologies.orient.core
|
3
|
+
CLIENT = com.orientechnologies.orient.client
|
4
|
+
|
5
|
+
ClusterType = CORE.storage.OStorage::CLUSTER_TYPE
|
6
|
+
DocumentDatabase = CORE.db.document.ODatabaseDocumentTx
|
7
|
+
DocumentDatabasePool = CORE.db.document.ODatabaseDocumentPool
|
8
|
+
DocumentDatabasePooled = CORE.db.document.ODatabaseDocumentTxPooled
|
9
|
+
GraphDatabase = CORE.db.graph.OGraphDatabase
|
10
|
+
OTraverse = CORE.command.traverse.OTraverse
|
11
|
+
Document = CORE.record.impl.ODocument
|
12
|
+
IndexType = CORE.metadata.schema.OClass::INDEX_TYPE
|
13
|
+
OClassImpl = CORE.metadata.schema.OClassImpl
|
14
|
+
LocalStorage = CORE.storage.impl.local.OStorageLocal
|
15
|
+
LocalCluster = CORE.storage.impl.local.OClusterLocal
|
16
|
+
PropertyImpl = CORE.metadata.schema.OPropertyImpl
|
17
|
+
RecordList = CORE.db.record.ORecordTrackedList
|
18
|
+
RecordSet = CORE.db.record.ORecordTrackedSet
|
19
|
+
Schema = CORE.metadata.schema.OSchema
|
20
|
+
SchemaProxy = CORE.metadata.schema.OSchemaProxy
|
21
|
+
SchemaType = CORE.metadata.schema.OType
|
22
|
+
SQLCommand = CORE.sql.OCommandSQL
|
23
|
+
SQLSynchQuery = CORE.sql.query.OSQLSynchQuery
|
24
|
+
User = CORE.metadata.security.OUser
|
25
|
+
RemoteStorage = CLIENT.remote.OStorageRemote
|
26
|
+
|
27
|
+
#Blueprints
|
28
|
+
BLUEPRINTS = com.tinkerpop.blueprints
|
29
|
+
|
30
|
+
OrientGraph = BLUEPRINTS.impls.orient.OrientGraph
|
31
|
+
Conclusion = com.tinkerpop.blueprints.TransactionalGraph::Conclusion
|
32
|
+
|
33
|
+
|
34
|
+
INDEX_TYPES = IndexType.constants.inject({ }) { |h, s| h[s.downcase.to_sym] = IndexType.const_get s; h }
|
35
|
+
STORAGE_TYPES = ClusterType.constants.inject({ }) { |h, s| h[s.downcase.to_sym] = ClusterType.const_get(s).to_s; h }
|
36
|
+
FIELD_TYPES = SchemaType.constants.inject({ }) { |h, s| h[s.downcase.to_sym] = SchemaType.const_get s; h }
|
37
|
+
{
|
38
|
+
:bool => "BOOLEAN",
|
39
|
+
:double => "BYTE",
|
40
|
+
:datetime => "DATE",
|
41
|
+
:decimal => "FLOAT",
|
42
|
+
:embedded_list => "EMBEDDEDLIST",
|
43
|
+
:list => "EMBEDDEDLIST",
|
44
|
+
:embedded_map => "EMBEDDEDMAP",
|
45
|
+
:map => "EMBEDDEDMAP",
|
46
|
+
:embedded_set => "EMBEDDEDSET",
|
47
|
+
:set => "EMBEDDEDSET",
|
48
|
+
:int => "INTEGER",
|
49
|
+
:link_list => "LINKLIST",
|
50
|
+
:link_map => "LINKMAP",
|
51
|
+
:link_set => "LINKSET",
|
52
|
+
}.map do |k,v|
|
53
|
+
FIELD_TYPES[k] = SchemaType.const_get(v) unless FIELD_TYPES.key?(k)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
module OrientDB
|
2
|
+
module DocumentDatabaseMixin
|
3
|
+
|
4
|
+
def run_command(sql_command = nil)
|
5
|
+
sql_command = prepare_sql_command sql_command
|
6
|
+
command(sql_command).execute(true)
|
7
|
+
end
|
8
|
+
|
9
|
+
alias :cmd :run_command
|
10
|
+
|
11
|
+
def prepare_sql_command(command)
|
12
|
+
return if command.nil?
|
13
|
+
return command.to_sql_command if command.respond_to?(:to_sql_command)
|
14
|
+
case command
|
15
|
+
when OrientDB::SQLCommand
|
16
|
+
command
|
17
|
+
when String
|
18
|
+
OrientDB::SQLCommand.new command
|
19
|
+
else
|
20
|
+
raise "Unknown command type"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def all(sql_query = nil)
|
25
|
+
sql_query = prepare_sql_query sql_query
|
26
|
+
query sql_query
|
27
|
+
end
|
28
|
+
|
29
|
+
def first(sql_query = nil)
|
30
|
+
sql_query = prepare_sql_query(sql_query).setLimit(1)
|
31
|
+
query(sql_query).first
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_by_rid(rid)
|
35
|
+
first "SELECT FROM #{rid}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_by_rids(*rids)
|
39
|
+
all "SELECT FROM [#{rids.map{|x| x.to_s}.join(', ')}]"
|
40
|
+
end
|
41
|
+
|
42
|
+
def prepare_sql_query(query)
|
43
|
+
return if query.nil?
|
44
|
+
return query.to_sql_query if query.respond_to?(:to_sql_query)
|
45
|
+
case query
|
46
|
+
when OrientDB::SQLSynchQuery
|
47
|
+
query
|
48
|
+
when String
|
49
|
+
OrientDB::SQLSynchQuery.new(query)
|
50
|
+
else
|
51
|
+
raise "Unknown query type"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def schema
|
56
|
+
metadata.schema
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_class(klass_name)
|
60
|
+
schema.get_class klass_name.to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_class(klass_name, fields = {})
|
64
|
+
OrientDB::OClassImpl.create self, klass_name.to_s, fields
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_or_create_class(klass_name, fields = {})
|
68
|
+
get_class(klass_name) || create_class(klass_name, fields)
|
69
|
+
end
|
70
|
+
|
71
|
+
def migrate_class(klass_name, fields = {})
|
72
|
+
klass = get_or_create_class klass_name
|
73
|
+
fields.each do |name, options|
|
74
|
+
type = options.delete :type
|
75
|
+
klass.add name, type, options
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def drop_class(klass_name)
|
80
|
+
schema.drop_class(klass_name) if schema.exists_class(klass_name)
|
81
|
+
end
|
82
|
+
|
83
|
+
def recreate_class(klass_name, fields = {})
|
84
|
+
#run_command("DELETE FROM '#{klass_name}'") rescue nil
|
85
|
+
root_class = get_class(klass_name)
|
86
|
+
schema.classes.each do |possible_sub_class|
|
87
|
+
drop_class(possible_sub_class.name) if possible_sub_class.is_sub_class_of(root_class)
|
88
|
+
end
|
89
|
+
drop_class(klass_name) rescue nil
|
90
|
+
create_class klass_name, fields
|
91
|
+
end
|
92
|
+
|
93
|
+
def all_in_class(klass_name)
|
94
|
+
browse_class(klass_name.to_s).map
|
95
|
+
end
|
96
|
+
|
97
|
+
def all_in_cluster(cluster_name)
|
98
|
+
browse_cluster(cluster_name.to_s).map
|
99
|
+
end
|
100
|
+
|
101
|
+
def quote(value)
|
102
|
+
SQL::Query.quote value
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
class DocumentDatabase
|
108
|
+
|
109
|
+
include DocumentDatabaseMixin
|
110
|
+
|
111
|
+
def self.create(database_url)
|
112
|
+
new(database_url).create
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.connect(database_url, username, password)
|
116
|
+
new(database_url).open(username, password)
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.current_thread_connection
|
120
|
+
Thread.current[:orientdb_connection]
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.connect_current_thread(database_url, username, password)
|
124
|
+
Thread.current[:orientdb_connection] = connect database_url, username, password
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.close_current_thread
|
128
|
+
Thread.current[:orientdb_connection] && Thread.current[:orientdb_connection].close
|
129
|
+
end
|
130
|
+
|
131
|
+
alias :each_in_class :browseClass
|
132
|
+
alias :each_in_cluster :browseCluster
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
class DocumentDatabasePool
|
137
|
+
|
138
|
+
def self.connect(url, username, password)
|
139
|
+
global.acquire(url, username, password)
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.current_thread_connection
|
143
|
+
Thread.current[:orientdb_connection]
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.connect_current_thread(database_url, username, password)
|
147
|
+
Thread.current[:orientdb_connection] = connect database_url, username, password
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.close_current_thread
|
151
|
+
Thread.current[:orientdb_connection] && Thread.current[:orientdb_connection].close
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
class DocumentDatabasePooled
|
157
|
+
|
158
|
+
include DocumentDatabaseMixin
|
159
|
+
|
160
|
+
alias :each_in_class :browseClass
|
161
|
+
alias :each_in_cluster :browseCluster
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
|