odba 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/Guide.txt +36 -0
- data/History.txt +4 -0
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.txt +4 -0
- data/Rakefile +2 -0
- data/lib/odba.rb +1 -58
- data/lib/odba/cache.rb +36 -2
- data/lib/odba/connection_pool.rb +5 -2
- data/lib/odba/storage.rb +8 -1
- metadata +15 -13
- data/Manifest.txt +0 -38
data/.gemtest
ADDED
File without changes
|
data/Guide.txt
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
= odba
|
2
|
+
|
3
|
+
ODBA is an unintrusive Object Cache system. It adresses the crosscutting
|
4
|
+
concern of object storage by disconnecting and serializing objects into
|
5
|
+
storage. All disconnected connections are replaced by instances of
|
6
|
+
ODBA::Stub, thus enabling transparent object-loading.
|
7
|
+
|
8
|
+
== ODBA supports
|
9
|
+
|
10
|
+
* transparent loading of connected objects
|
11
|
+
* index-vectors
|
12
|
+
* transactions
|
13
|
+
* transparently fetches Hash-Elements without loading the entire Hash
|
14
|
+
|
15
|
+
== Example
|
16
|
+
include 'odba'
|
17
|
+
|
18
|
+
# connect default storage manager to a relational database
|
19
|
+
ODBA.storage.dbi = ODBA::ConnectionPool.new('DBI::pg::database', 'user', 'pw')
|
20
|
+
|
21
|
+
class Counter
|
22
|
+
include ODBA::Persistable
|
23
|
+
def initialize
|
24
|
+
@pos = 0
|
25
|
+
end
|
26
|
+
def up
|
27
|
+
@pos += 1
|
28
|
+
self.odba_store
|
29
|
+
@pos
|
30
|
+
end
|
31
|
+
def down
|
32
|
+
@pos -= 1
|
33
|
+
self.odba_store
|
34
|
+
@pos
|
35
|
+
end
|
36
|
+
end
|
data/History.txt
CHANGED
data/{LICENSE → LICENSE.txt}
RENAMED
File without changes
|
data/README.txt
CHANGED
data/Rakefile
CHANGED
data/lib/odba.rb
CHANGED
@@ -1,61 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#-- ODBA -- odba -- 13.05.2004 -- hwyss@ywesee.com rwaltert@ywesee.com mwalder@ywesee.com
|
3
|
-
# Copyright (C) 2004 Hannes Wyss
|
4
|
-
#
|
5
|
-
# This library is free software; you can redistribute it and/or
|
6
|
-
# modify it under the terms of the GNU Lesser General Public
|
7
|
-
# License as published by the Free Software Foundation; either
|
8
|
-
# version 2.1 of the License, or (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This library is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
# Lesser General Public License for more details.
|
14
|
-
#
|
15
|
-
# You should have received a copy of the GNU Lesser General Public
|
16
|
-
# License along with this library; if not, write to the Free Software
|
17
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
-
#
|
19
|
-
# ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Z�rich, Switzerland
|
20
|
-
# hwyss@ywesee.com
|
21
|
-
#++
|
22
|
-
# = ODBA - Object DataBase Access
|
23
|
-
#
|
24
|
-
# ODBA is an unintrusive Object Cache system. It adresses the crosscutting
|
25
|
-
# concern of object storage by disconnecting and serializing objects into
|
26
|
-
# storage. All disconnected connections are replaced by instances of
|
27
|
-
# ODBA::Stub, thus enabling transparent object-loading.
|
28
|
-
#
|
29
|
-
# ODBA supports:
|
30
|
-
# * transparent loading of connected objects
|
31
|
-
# * index-vectors
|
32
|
-
# * transactions
|
33
|
-
# * transparently fetches Hash-Elements without loading the entire Hash
|
34
|
-
#
|
35
|
-
# == Example
|
36
|
-
# include 'odba'
|
37
|
-
#
|
38
|
-
# # connect default storage manager to a relational database
|
39
|
-
# ODBA.storage.dbi = ODBA::ConnectionPool.new('DBI::pg::database', 'user', 'pw')
|
40
|
-
#
|
41
|
-
# class Counter
|
42
|
-
# include ODBA::Persistable
|
43
|
-
# def initialize
|
44
|
-
# @pos = 0
|
45
|
-
# end
|
46
|
-
# def up
|
47
|
-
# @pos += 1
|
48
|
-
# self.odba_store
|
49
|
-
# @pos
|
50
|
-
# end
|
51
|
-
# def down
|
52
|
-
# @pos -= 1
|
53
|
-
# self.odba_store
|
54
|
-
# @pos
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
#
|
58
|
-
# :main:lib/odba.rb
|
59
2
|
|
60
3
|
require 'odba/persistable'
|
61
4
|
require 'odba/storage'
|
@@ -68,5 +11,5 @@ require 'odba/index'
|
|
68
11
|
require 'odba/odba'
|
69
12
|
|
70
13
|
class Odba
|
71
|
-
VERSION = '1.0.
|
14
|
+
VERSION = '1.0.1'
|
72
15
|
end
|
data/lib/odba/cache.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# encoding: utf-8
|
3
|
+
# ODBA::Cache -- odba -- 08.12.2011 -- mhatakeyama@ywesee.com
|
4
|
+
# ODBA::Cache -- odba -- 29.04.2004 -- hwyss@ywesee.com rwaltert@ywesee.com mwalder@ywesee.com
|
3
5
|
|
4
6
|
require 'singleton'
|
5
7
|
require 'date'
|
@@ -361,9 +363,41 @@ module ODBA
|
|
361
363
|
invalidate odba_id
|
362
364
|
end
|
363
365
|
end
|
366
|
+
# File lock exclusive control between processes, not threads, to create safely a new odba_id
|
367
|
+
# Sometimes several update jobs (processes) to the same database at the same time
|
368
|
+
LOCK_FILE = '/tmp/lockfile'
|
369
|
+
COUNT_FILE = '/tmp/count'
|
370
|
+
def lock(dbname)
|
371
|
+
lock_file = LOCK_FILE + "." + dbname
|
372
|
+
open(lock_file, 'a') do |st|
|
373
|
+
st.flock(File::LOCK_EX)
|
374
|
+
yield
|
375
|
+
st.flock(File::LOCK_UN)
|
376
|
+
end
|
377
|
+
end
|
378
|
+
def new_id(dbname, odba_storage)
|
379
|
+
count_file = COUNT_FILE + "." + dbname
|
380
|
+
count = nil
|
381
|
+
lock(dbname) do
|
382
|
+
unless File.exist?(count_file)
|
383
|
+
open(count_file, "w") do |out|
|
384
|
+
out.print odba_storage.max_id
|
385
|
+
end
|
386
|
+
end
|
387
|
+
count = File.read(count_file).to_i
|
388
|
+
count += 1
|
389
|
+
open(count_file, "w") do |out|
|
390
|
+
out.print count
|
391
|
+
end
|
392
|
+
odba_storage.update_max_id(count)
|
393
|
+
end
|
394
|
+
count
|
395
|
+
end
|
364
396
|
# Returns the next valid odba_id
|
365
397
|
def next_id
|
366
|
-
id = ODBA.storage.next_id
|
398
|
+
#id = ODBA.storage.next_id
|
399
|
+
dbname = ODBA.storage.dbi.dbi_args.first.split(/:/).last
|
400
|
+
id = new_id(dbname, ODBA.storage)
|
367
401
|
@peers.each do |peer|
|
368
402
|
peer.reserve_next_id id rescue DRb::DRbError
|
369
403
|
end
|
data/lib/odba/connection_pool.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# encoding: utf-8
|
3
|
+
# ODBA::ConnectionPool -- odba -- 08.12.2011 -- mhatakeyama@ywesee.com
|
4
|
+
# ODBA::ConnectionPool -- odba -- 08.03.2005 -- hwyss@ywesee.com
|
3
5
|
|
4
6
|
require 'dbi'
|
5
7
|
require 'thread'
|
@@ -8,7 +10,8 @@ module ODBA
|
|
8
10
|
class ConnectionPool
|
9
11
|
POOL_SIZE = 5
|
10
12
|
SETUP_RETRIES = 3
|
11
|
-
attr_reader :connections
|
13
|
+
#attr_reader :connections
|
14
|
+
attr_reader :connections, :dbi_args
|
12
15
|
# All connections are delegated to DBI. The constructor simply records
|
13
16
|
# the DBI-arguments and reuses them to setup connections when needed.
|
14
17
|
def initialize(*dbi_args)
|
data/lib/odba/storage.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# encoding: utf-8
|
3
|
+
# ODBA::Storage -- odba -- 08.12.2011 -- mhatakeyama@ywesee.com
|
4
|
+
# ODBA::Storage -- odba -- 29.04.2004 -- hwyss@ywesee.com rwaltert@ywesee.com mwalder@ywesee.com
|
3
5
|
|
4
6
|
require 'thread'
|
5
7
|
require 'singleton'
|
@@ -391,6 +393,11 @@ CREATE INDEX target_id_#{table_name} ON #{table_name}(target_id);
|
|
391
393
|
@next_id += 1
|
392
394
|
end
|
393
395
|
end
|
396
|
+
def update_max_id(id)
|
397
|
+
@id_mutex.synchronize do
|
398
|
+
@next_id = id
|
399
|
+
end
|
400
|
+
end
|
394
401
|
def reserve_next_id(reserved_id)
|
395
402
|
@id_mutex.synchronize do
|
396
403
|
ensure_next_id_set
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Masaomi Hatakeyama, Zeno R.R. Davatz
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-12-08 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 41
|
30
30
|
segments:
|
31
31
|
- 2
|
32
|
-
-
|
33
|
-
-
|
34
|
-
version: 2.
|
32
|
+
- 9
|
33
|
+
- 1
|
34
|
+
version: 2.9.1
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
37
|
description: Object Database Access - Ruby Software for ODDB.org Memory Management
|
@@ -42,13 +42,14 @@ executables: []
|
|
42
42
|
extensions: []
|
43
43
|
|
44
44
|
extra_rdoc_files:
|
45
|
+
- Guide.txt
|
45
46
|
- History.txt
|
46
|
-
-
|
47
|
+
- LICENSE.txt
|
47
48
|
- README.txt
|
48
49
|
files:
|
50
|
+
- Guide.txt
|
49
51
|
- History.txt
|
50
|
-
- LICENSE
|
51
|
-
- Manifest.txt
|
52
|
+
- LICENSE.txt
|
52
53
|
- README.txt
|
53
54
|
- Rakefile
|
54
55
|
- install.rb
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- test/test_persistable.rb
|
85
86
|
- test/test_storage.rb
|
86
87
|
- test/test_stub.rb
|
88
|
+
- .gemtest
|
87
89
|
has_rdoc: true
|
88
90
|
homepage: http://scm.ywesee.com/?p=odba/.git;a=summary
|
89
91
|
licenses: []
|
@@ -115,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
117
|
requirements: []
|
116
118
|
|
117
119
|
rubyforge_project: odba
|
118
|
-
rubygems_version: 1.
|
120
|
+
rubygems_version: 1.4.2
|
119
121
|
signing_key:
|
120
122
|
specification_version: 3
|
121
123
|
summary: Object Database Access - Ruby Software for ODDB.org Memory Management
|
data/Manifest.txt
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
LICENSE
|
3
|
-
Manifest.txt
|
4
|
-
README.txt
|
5
|
-
Rakefile
|
6
|
-
install.rb
|
7
|
-
lib/odba.rb
|
8
|
-
lib/odba/18_19_loading_compatibility.rb
|
9
|
-
lib/odba/cache.rb
|
10
|
-
lib/odba/cache_entry.rb
|
11
|
-
lib/odba/connection_pool.rb
|
12
|
-
lib/odba/drbwrapper.rb
|
13
|
-
lib/odba/id_server.rb
|
14
|
-
lib/odba/index.rb
|
15
|
-
lib/odba/index_definition.rb
|
16
|
-
lib/odba/marshal.rb
|
17
|
-
lib/odba/odba.rb
|
18
|
-
lib/odba/odba_error.rb
|
19
|
-
lib/odba/persistable.rb
|
20
|
-
lib/odba/storage.rb
|
21
|
-
lib/odba/stub.rb
|
22
|
-
sql/collection.sql
|
23
|
-
sql/create_tables.sql
|
24
|
-
sql/object.sql
|
25
|
-
sql/object_connection.sql
|
26
|
-
test/suite.rb
|
27
|
-
test/test_array.rb
|
28
|
-
test/test_cache.rb
|
29
|
-
test/test_cache_entry.rb
|
30
|
-
test/test_connection_pool.rb
|
31
|
-
test/test_drbwrapper.rb
|
32
|
-
test/test_hash.rb
|
33
|
-
test/test_id_server.rb
|
34
|
-
test/test_index.rb
|
35
|
-
test/test_marshal.rb
|
36
|
-
test/test_persistable.rb
|
37
|
-
test/test_storage.rb
|
38
|
-
test/test_stub.rb
|