orientdb 0.0.7-jruby → 0.0.8-jruby

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
data/lib/orientdb.rb CHANGED
@@ -21,7 +21,9 @@ require 'orientdb/version'
21
21
  require 'orientdb/user'
22
22
  require 'orientdb/property'
23
23
  require 'orientdb/schema'
24
+ require 'orientdb/storage'
24
25
  require 'orientdb/database'
26
+ require 'orientdb/record'
25
27
  require 'orientdb/document'
26
28
  require 'orientdb/sql_query'
27
29
  require 'orientdb/oclass'
@@ -1,22 +1,29 @@
1
1
  module OrientDB
2
2
 
3
- ClusterType = com.orientechnologies.orient.core.storage.OStorage::CLUSTER_TYPE
4
- Database = com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx
5
- DatabasePool = com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool
6
- Document = com.orientechnologies.orient.core.record.impl.ODocument
7
- IndexType = com.orientechnologies.orient.core.metadata.schema.OProperty::INDEX_TYPE
8
- OClass = com.orientechnologies.orient.core.metadata.schema.OClass
9
- Property = com.orientechnologies.orient.core.metadata.schema.OProperty
10
- Schema = com.orientechnologies.orient.core.metadata.schema.OSchema
11
- SchemaType = com.orientechnologies.orient.core.metadata.schema.OType
12
- SQLQuery = com.orientechnologies.orient.core.sql.query.OSQLSynchQuery
13
- SQLCommand = com.orientechnologies.orient.core.sql.OCommandSQL
14
- User = com.orientechnologies.orient.core.metadata.security.OUser
3
+ ClusterType = com.orientechnologies.orient.core.storage.OStorage::CLUSTER_TYPE
4
+ Database = com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx
5
+ DatabasePool = com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool
6
+ Document = com.orientechnologies.orient.core.record.impl.ODocument
7
+ IndexType = com.orientechnologies.orient.core.metadata.schema.OProperty::INDEX_TYPE
8
+ OClass = com.orientechnologies.orient.core.metadata.schema.OClass
9
+ LocalStorage = com.orientechnologies.orient.core.storage.impl.local.OStorageLocal
10
+ LocalCluster = com.orientechnologies.orient.core.storage.impl.local.OClusterLocal
11
+ LogicalCluster = com.orientechnologies.orient.core.storage.impl.local.OClusterLogical
12
+ Property = com.orientechnologies.orient.core.metadata.schema.OProperty
13
+ RecordList = com.orientechnologies.orient.core.db.record.ORecordTrackedList
14
+ RecordMap = com.orientechnologies.orient.core.db.record.ORecordTrackedMap
15
+ RecordSet = com.orientechnologies.orient.core.db.record.ORecordTrackedSet
16
+ RemoteStorage = com.orientechnologies.orient.client.remote.OStorageRemote
17
+ Schema = com.orientechnologies.orient.core.metadata.schema.OSchema
18
+ SchemaType = com.orientechnologies.orient.core.metadata.schema.OType
19
+ SQLQuery = com.orientechnologies.orient.core.sql.query.OSQLSynchQuery
20
+ SQLCommand = com.orientechnologies.orient.core.sql.OCommandSQL
21
+ User = com.orientechnologies.orient.core.metadata.security.OUser
15
22
 
16
- STORAGE_TYPES = %w{ LOGICAL MEMORY PHYSICAL }.inject({}) { |h, s| h[s.downcase.to_sym] = ClusterType.const_get s; h }
17
- INDEX_TYPES = %w{ FULLTEXT NOTUNIQUE UNIQUE }.inject({}) { |h, s| h[s.downcase.to_sym] = IndexType.const_get s; h }
23
+ STORAGE_TYPES = %w{ LOGICAL MEMORY PHYSICAL }.inject({}) { |h, s| h[s.downcase.to_sym] = ClusterType.const_get s; h }
24
+ INDEX_TYPES = %w{ FULLTEXT NOTUNIQUE UNIQUE }.inject({}) { |h, s| h[s.downcase.to_sym] = IndexType.const_get s; h }
18
25
 
19
- FIELD_TYPES = {
26
+ FIELD_TYPES = {
20
27
  :binary => "BINARY",
21
28
  :bool => "BOOLEAN",
22
29
  :boolean => "BOOLEAN",
@@ -105,8 +105,8 @@ class OrientDB::Database
105
105
  OrientDB::OClass.create self, klass_name.to_s, fields
106
106
  end
107
107
 
108
- def get_or_create_class(klass_name)
109
- get_class(klass_name) || create_class(klass_name)
108
+ def get_or_create_class(klass_name, fields = {})
109
+ get_class(klass_name) || create_class(klass_name, fields)
110
110
  end
111
111
 
112
112
  alias :each_in_class :browseClass
@@ -29,8 +29,7 @@ module OrientDB
29
29
  end
30
30
 
31
31
  def method_missing(method_name, *args, &blk)
32
- return self[method_name] if contains_field(method_name.to_s)
33
- return nil if schema_class.exists_property?(method_name.to_s)
32
+ return self[method_name] if field?(method_name)
34
33
 
35
34
  match = method_name.to_s.match(/(.*?)([?=!]?)$/)
36
35
  case match[2]
@@ -10,17 +10,12 @@ module OrientDB
10
10
  FIELD_TYPES[value]
11
11
  else
12
12
  FIELD_TYPES[value.to_s.to_sym]
13
- end
13
+ end
14
14
  raise "Uknown schema type for [#{value}]" unless type
15
15
  type
16
16
  end
17
17
 
18
18
  def add(property_name, type, options = {})
19
- if type.is_a?(Hash)
20
- real_type = type.delete(:type)
21
- return add(property_name, real_type, type)
22
- end
23
-
24
19
  property_name = property_name.to_s
25
20
  if exists_property(property_name)
26
21
  puts "We already have that property name [#{property_name}]"
@@ -28,14 +23,15 @@ module OrientDB
28
23
  end
29
24
 
30
25
  case type
26
+ when SchemaType
27
+ prop = create_property property_name, type
31
28
  when Symbol
32
29
  prop = create_property property_name, type_for(type)
33
- when OrientDB::OClass
30
+ when OClass
34
31
  prop = create_property property_name, type_for(:link), type
35
32
  when Array
36
- type[0] = type_for(type[0]) if type[0].is_a?(Symbol)
37
- type[1] = type_for(type[1]) if type[1].is_a?(Symbol)
38
- prop = create_property property_name, *type
33
+ type, sub_type = type_for(type.first), type_for(type.last)
34
+ prop = create_property property_name, type, sub_type
39
35
  else
40
36
  raise "ERROR! Unknown type [ #{property_name} | #{type} : #{type.class.name} ]"
41
37
  end
@@ -78,19 +74,28 @@ module OrientDB
78
74
  class << self
79
75
 
80
76
  def create(db, name, fields = {})
77
+ puts "create [#{name}], #{fields.inspect}"
81
78
  name = name.to_s
82
79
  add_cluster = fields.delete :add_cluster
83
80
  add_cluster = true if add_cluster.nil?
81
+ use_cluster = fields.delete :use_cluster
82
+ puts "use_cluster : #{use_cluster}"
84
83
 
85
84
  if db.schema.exists_class? name
86
85
  klass = db.get_class name
87
86
  else
88
- if add_cluster && !db.storage.cluster_names.include?(name.downcase)
87
+ if use_cluster
88
+ cluster = db.storage.get_cluster use_cluster
89
+ klass = db.schema.create_class name, use_cluster
90
+ puts "created and used cluster [#{cluster}] for [#{klass}]"
91
+ elsif add_cluster && !db.storage.cluster_names.include?(name.downcase)
89
92
  cluster = db.storage.add_cluster name.downcase, STORAGE_TYPES[:physical]
90
93
  klass = db.schema.create_class name, cluster
94
+ puts "created and added cluster [#{cluster}] for [#{klass}]"
91
95
  else
92
96
  klass = db.schema.create_class name
93
- cluster = db.storage.get_cluster_by_name name.downcase
97
+ cluster = db.storage.get_cluster klass.cluster_ids.first
98
+ puts "created and got cluster [#{cluster}] for [#{klass}]"
94
99
  end
95
100
  end
96
101
 
@@ -101,7 +106,16 @@ module OrientDB
101
106
 
102
107
  unless fields.empty?
103
108
  fields.each do |property_name, type|
104
- klass.add property_name, type
109
+ case type
110
+ when Symbol, Array, OrientDB::OClass
111
+ klass.add property_name, type
112
+ when Hash
113
+ options = type.dup
114
+ type = options.delete :type
115
+ klass.add property_name, type, options
116
+ else
117
+ raise "Unknown field options [#{type.inspect}]"
118
+ end
105
119
  end
106
120
  db.schema.save
107
121
  end
@@ -0,0 +1,30 @@
1
+ module OrientDB
2
+
3
+ class RecordList
4
+ def jruby_value
5
+ map
6
+ end
7
+
8
+ def inspect
9
+ "#<OrientDB::RecordList:#{toString}>"
10
+ end
11
+
12
+ alias :to_s :inspect
13
+ end
14
+
15
+ class RecordMap
16
+ def inspect
17
+ "#<OrientDB::RecordMap:#{toString}>"
18
+ end
19
+
20
+ alias :to_s :inspect
21
+ end
22
+
23
+ class RecordSet
24
+ def inspect
25
+ "#<OrientDB::RecordSet:#{toString}>"
26
+ end
27
+
28
+ alias :to_s :inspect
29
+ end
30
+ end
@@ -2,6 +2,12 @@ module OrientDB
2
2
 
3
3
  class Schema
4
4
 
5
+ def inspect
6
+ "#<OrientDB::Schema:#{toString}>"
7
+ end
8
+
9
+ alias :to_s :inspect
10
+
5
11
  end
6
12
 
7
13
  end
@@ -0,0 +1,61 @@
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
+ class LogicalCluster
52
+
53
+ def inspect
54
+ "#<OrientDB::LogicalCluster:#{getId} name=#{getName.inspect}>"
55
+ end
56
+
57
+ alias :to_s :inspect
58
+
59
+ end
60
+
61
+ end
data/orientdb.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{orientdb}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
  s.platform = %q{jruby}
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Adrian Madrid"]
13
- s.date = %q{2011-01-13}
13
+ s.date = %q{2011-01-14}
14
14
  s.default_executable = %q{orientdb_console}
15
15
  s.description = %q{Simple JRuby wrapper for the OrientDB.}
16
16
  s.email = ["aemadrid@gmail.com"]
@@ -43,8 +43,10 @@ Gem::Specification.new do |s|
43
43
  "lib/orientdb/ext.rb",
44
44
  "lib/orientdb/oclass.rb",
45
45
  "lib/orientdb/property.rb",
46
+ "lib/orientdb/record.rb",
46
47
  "lib/orientdb/schema.rb",
47
48
  "lib/orientdb/sql_query.rb",
49
+ "lib/orientdb/storage.rb",
48
50
  "lib/orientdb/user.rb",
49
51
  "lib/orientdb/version.rb",
50
52
  "orientdb.gemspec",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 8
9
+ version: 0.0.8
10
10
  platform: jruby
11
11
  authors:
12
12
  - Adrian Madrid
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-13 00:00:00 -07:00
17
+ date: 2011-01-14 00:00:00 -07:00
18
18
  default_executable: orientdb_console
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -76,8 +76,10 @@ files:
76
76
  - lib/orientdb/ext.rb
77
77
  - lib/orientdb/oclass.rb
78
78
  - lib/orientdb/property.rb
79
+ - lib/orientdb/record.rb
79
80
  - lib/orientdb/schema.rb
80
81
  - lib/orientdb/sql_query.rb
82
+ - lib/orientdb/storage.rb
81
83
  - lib/orientdb/user.rb
82
84
  - lib/orientdb/version.rb
83
85
  - orientdb.gemspec