s2container 0.8.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.
- data/Apache_Software_License_2.0.txt +202 -0
- data/ChangeLog +1 -0
- data/ChangeLog.ja +64 -0
- data/README +9 -0
- data/Rakefile +51 -0
- data/example/example01/example.rb +13 -0
- data/example/example01/run.rb +20 -0
- data/example/example02/example.rb +30 -0
- data/example/example02/run.rb +8 -0
- data/example/example03/example.rb +8 -0
- data/example/example03/run.rb +12 -0
- data/example/example04/example.rb +9 -0
- data/example/example04/run.rb +15 -0
- data/example/example05/example.rb +9 -0
- data/example/example05/run.rb +21 -0
- data/example/example06/example.rb +9 -0
- data/example/example06/run.rb +8 -0
- data/example/example07/example.rb +8 -0
- data/example/example07/run.rb +15 -0
- data/example/example08/example.rb +9 -0
- data/example/example08/run.rb +19 -0
- data/example/example09/example.rb +7 -0
- data/example/example09/run.rb +11 -0
- data/example/example10/example.rb +9 -0
- data/example/example10/run.rb +10 -0
- data/example/example11/example.rb +18 -0
- data/example/example11/run.rb +10 -0
- data/example/example12/example.rb +9 -0
- data/example/example12/run.rb +8 -0
- data/example/example13/example.rb +18 -0
- data/example/example13/example.sql +4 -0
- data/example/example13/run.rb +22 -0
- data/example/example13/sample.db +0 -0
- data/example/example14/example.db +0 -0
- data/example/example14/example.rb +57 -0
- data/example/example14/example.sql +50 -0
- data/example/example14/run1.rb +23 -0
- data/example/example14/run2.rb +28 -0
- data/example/example14/run3.rb +25 -0
- data/example/example14/run4.rb +23 -0
- data/example/example14/run5.rb +35 -0
- data/example/example15/example.rb +20 -0
- data/example/example15/run.rb +28 -0
- data/example/example16/example.rb +15 -0
- data/example/example16/run.rb +24 -0
- data/example/quickstart/quickstart1/quickstart.rb +10 -0
- data/example/quickstart/quickstart2/quickstart.rb +9 -0
- data/example/quickstart/quickstart3/quickstart.rb +9 -0
- data/example/quickstart/quickstart4/quickstart.rb +14 -0
- data/example/quickstart/quickstart5/quickstart.rb +21 -0
- data/example/quickstart/quickstart6/quickstart.rb +28 -0
- data/example/quickstart/quickstart7/quickstart.rb +18 -0
- data/lib/s2container.rb +25 -0
- data/lib/seasar/aop/aspect.rb +30 -0
- data/lib/seasar/aop/interceptor/trace-interceptor.rb +48 -0
- data/lib/seasar/aop/method-invocation.rb +57 -0
- data/lib/seasar/aop/pointcut.rb +53 -0
- data/lib/seasar/aop/s2aop-factory.rb +125 -0
- data/lib/seasar/aop.rb +29 -0
- data/lib/seasar/beans/abstract-property-desc.rb +59 -0
- data/lib/seasar/beans/attribute-accessor-desc.rb +60 -0
- data/lib/seasar/beans/bean-desc-factory.rb +68 -0
- data/lib/seasar/beans/bean-desc.rb +232 -0
- data/lib/seasar/beans/instance-variable-desc.rb +58 -0
- data/lib/seasar/beans.rb +29 -0
- data/lib/seasar/container/arg-def.rb +51 -0
- data/lib/seasar/container/aspect-def.rb +60 -0
- data/lib/seasar/container/aspect-info-def.rb +94 -0
- data/lib/seasar/container/assembler/abstract-assembler.rb +68 -0
- data/lib/seasar/container/assembler/auto-property-assembler.rb +57 -0
- data/lib/seasar/container/assembler/autobinding-auto-def.rb +55 -0
- data/lib/seasar/container/assembler/autobinding-def-factory.rb +57 -0
- data/lib/seasar/container/assembler/autobinding-none-def.rb +53 -0
- data/lib/seasar/container/assembler/manual-constructor-assembler.rb +67 -0
- data/lib/seasar/container/assembler/manual-property-assembler.rb +68 -0
- data/lib/seasar/container/autobinding-def.rb +36 -0
- data/lib/seasar/container/component-def.rb +229 -0
- data/lib/seasar/container/component-info-def.rb +117 -0
- data/lib/seasar/container/deployer/abstract-component-deployer.rb +47 -0
- data/lib/seasar/container/deployer/instance-def-factory.rb +56 -0
- data/lib/seasar/container/deployer/instance-outer-def.rb +44 -0
- data/lib/seasar/container/deployer/instance-prototype-def.rb +44 -0
- data/lib/seasar/container/deployer/instance-singleton-def.rb +42 -0
- data/lib/seasar/container/deployer/outer-component-deployer.rb +47 -0
- data/lib/seasar/container/deployer/prototype-component-deployer.rb +51 -0
- data/lib/seasar/container/deployer/singleton-component-deployer.rb +54 -0
- data/lib/seasar/container/exception/component-notfound-runtime-exception.rb +44 -0
- data/lib/seasar/container/exception/cyclic-reference-runtime-exception.rb +43 -0
- data/lib/seasar/container/exception/illegal-autobinding-def-runtime-exception.rb +43 -0
- data/lib/seasar/container/exception/illegal-instance-def-runtime-exception.rb +44 -0
- data/lib/seasar/container/exception/toomany-registration-runtime-exception.rb +46 -0
- data/lib/seasar/container/instance-def.rb +37 -0
- data/lib/seasar/container/outer-component-def.rb +34 -0
- data/lib/seasar/container/property-def.rb +43 -0
- data/lib/seasar/container/s2application-context.rb +447 -0
- data/lib/seasar/container/s2container-component-def.rb +41 -0
- data/lib/seasar/container/s2container.rb +308 -0
- data/lib/seasar/container/simple-component-def.rb +45 -0
- data/lib/seasar/container/toomany-registration-component-def.rb +69 -0
- data/lib/seasar/container.rb +143 -0
- data/lib/seasar/dbi/dbi-interceptor.rb +97 -0
- data/lib/seasar/dbi/paginate.rb +215 -0
- data/lib/seasar/dbi.rb +26 -0
- data/lib/seasar/exception/notyet-implemented-exception.rb +25 -0
- data/lib/seasar/exception/property-notfound-runtime-exception.rb +48 -0
- data/lib/seasar/exception/s2runtime-exception.rb +35 -0
- data/lib/seasar/exception/unsupported-operation-exception.rb +25 -0
- data/lib/seasar/exception.rb +27 -0
- data/lib/seasar/log/s2logger.rb +75 -0
- data/lib/seasar/log.rb +38 -0
- data/lib/seasar/util/class-util.rb +116 -0
- data/lib/seasar/util.rb +24 -0
- data/setup.rb +1585 -0
- data/test/seasar/aop/test_pointcut.rb +25 -0
- data/test/seasar/aop/test_s2aop_factory.rb +90 -0
- data/test/seasar/beans/test_bean-desc.rb +179 -0
- data/test/seasar/container/assembler/test_auto_property_assembler.rb +87 -0
- data/test/seasar/container/assembler/test_autobinding_def_factory.rb +22 -0
- data/test/seasar/container/assembler/test_manual_property_assembler.rb +59 -0
- data/test/seasar/container/assembler/test_manula_constructor_assembler.rb +59 -0
- data/test/seasar/container/assembler/test_proc_constructor_assembler.rb +61 -0
- data/test/seasar/container/deployer/test_instance_def_factory.rb +24 -0
- data/test/seasar/container/deployer/test_prototype-deployer.rb +25 -0
- data/test/seasar/container/deployer/test_singleton-component-deployer.rb +24 -0
- data/test/seasar/container/s2app_load_sample.rb +6 -0
- data/test/seasar/container/test_arg-def.rb +34 -0
- data/test/seasar/container/test_aspect-info-def.rb +85 -0
- data/test/seasar/container/test_component-def.rb +91 -0
- data/test/seasar/container/test_component-info-def.rb +88 -0
- data/test/seasar/container/test_s2application-context.rb +290 -0
- data/test/seasar/container/test_s2container.rb +268 -0
- data/test/seasar/dbi/test_paginate.rb +265 -0
- data/test/seasar/test_log.rb +20 -0
- data/test/seasar/test_util.rb +46 -0
- data/test/test-suite.rb +7 -0
- metadata +211 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
module Example
|
2
|
+
class Dao
|
3
|
+
s2comp
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@dbh = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_by_name(name)
|
10
|
+
sth = @dbh.prepare("SELECT * FROM people WHERE name = ?")
|
11
|
+
sth.execute(name)
|
12
|
+
sth.fetch {|row|
|
13
|
+
printf "ID: %d, Name: %s, Height: %.1f\n", row[0], row[1], row[2]
|
14
|
+
}
|
15
|
+
sth.finish
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dbi'
|
5
|
+
|
6
|
+
require 's2container'
|
7
|
+
require 'example'
|
8
|
+
|
9
|
+
s2comp(:class => DBI::DatabaseHandle, :name => :dbh, :autobinding => :none) {
|
10
|
+
DBI.connect("dbi:SQLite3:sample.db")
|
11
|
+
}
|
12
|
+
|
13
|
+
begin
|
14
|
+
s2app[Example::Dao].find_by_name('hoge')
|
15
|
+
rescue Seasar::DBI::DBIInterceptor::ConnectError => e
|
16
|
+
s2logger.fatal(e.cause.class.name){"#{e.cause.message} #{e.cause.backtrace}"}
|
17
|
+
rescue => e
|
18
|
+
s2logger.fatal(e.class.name){"#{e.message} #{e.backtrace}"}
|
19
|
+
ensure
|
20
|
+
s2app[DBI::DatabaseHandle].disconnect if s2app[DBI::DatabaseHandle]
|
21
|
+
end
|
22
|
+
|
Binary file
|
Binary file
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Example
|
2
|
+
class PrefectureDao
|
3
|
+
s2comp
|
4
|
+
s2aspect :interceptor => "dbi.interceptor", :pointcut => /^find/
|
5
|
+
s2aspect :interceptor => "dbi.interceptor", :pointcut => /^insert/
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@dbh = :di, ::DBI::DatabaseHandle
|
9
|
+
end
|
10
|
+
|
11
|
+
def transactional_insert(id, name)
|
12
|
+
result = nil
|
13
|
+
@dbh['AutoCommit'] = false
|
14
|
+
begin
|
15
|
+
result = self.insert(id, name)
|
16
|
+
@dbh.commit
|
17
|
+
rescue => e
|
18
|
+
s2logger.warn(self.class.superclass.name) { "transaction failed. #{e.class.name} #{e.message}" }
|
19
|
+
@dbh.rollback
|
20
|
+
end
|
21
|
+
@dbh['AutoCommit'] = true
|
22
|
+
return result
|
23
|
+
end
|
24
|
+
|
25
|
+
def insert(id, name)
|
26
|
+
return 'insert into prefecture values(?, ?)'
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_all
|
30
|
+
return 'select * from prefecture'
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_by_id(id)
|
34
|
+
return 'select * from prefecture where id = ?'
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_by_id_hash(id)
|
38
|
+
return 'select * from prefecture where id = :id', {:id => id}
|
39
|
+
end
|
40
|
+
|
41
|
+
def find_by_name(name)
|
42
|
+
return "select * from prefecture where name = ?", name
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_by_dto(dto)
|
46
|
+
return "select * from prefecture where name like ? limit ? offset ?", [dto.name_like, dto.limit, dto.offset]
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_total_by_dto(dto)
|
50
|
+
return "select count(*) as total from prefecture where name like ?", dto.name_like
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class PrefectureDto < Seasar::DBI::Paginate
|
55
|
+
attr_accessor :name_like
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
DROP TABLE prefecture;
|
2
|
+
CREATE TABLE prefecture(id INTEGER PRIMARY KEY, name text);
|
3
|
+
INSERT INTO prefecture(id,name) VALUES (1,'北海道');
|
4
|
+
INSERT INTO prefecture(id,name) VALUES (2,'青森県');
|
5
|
+
INSERT INTO prefecture(id,name) VALUES (3,'岩手県');
|
6
|
+
INSERT INTO prefecture(id,name) VALUES (4,'宮城県');
|
7
|
+
INSERT INTO prefecture(id,name) VALUES (5,'秋田県');
|
8
|
+
INSERT INTO prefecture(id,name) VALUES (6,'山形県');
|
9
|
+
INSERT INTO prefecture(id,name) VALUES (7,'福島県');
|
10
|
+
INSERT INTO prefecture(id,name) VALUES (8,'茨城県');
|
11
|
+
INSERT INTO prefecture(id,name) VALUES (9,'栃木県');
|
12
|
+
INSERT INTO prefecture(id,name) VALUES (10,'群馬県');
|
13
|
+
INSERT INTO prefecture(id,name) VALUES (11,'埼玉県');
|
14
|
+
INSERT INTO prefecture(id,name) VALUES (12,'千葉県');
|
15
|
+
INSERT INTO prefecture(id,name) VALUES (13,'東京都');
|
16
|
+
INSERT INTO prefecture(id,name) VALUES (14,'神奈川県');
|
17
|
+
INSERT INTO prefecture(id,name) VALUES (15,'新潟県');
|
18
|
+
INSERT INTO prefecture(id,name) VALUES (16,'富山県');
|
19
|
+
INSERT INTO prefecture(id,name) VALUES (17,'石川県');
|
20
|
+
INSERT INTO prefecture(id,name) VALUES (18,'福井県');
|
21
|
+
INSERT INTO prefecture(id,name) VALUES (19,'山梨県');
|
22
|
+
INSERT INTO prefecture(id,name) VALUES (20,'長野県');
|
23
|
+
INSERT INTO prefecture(id,name) VALUES (21,'岐阜県');
|
24
|
+
INSERT INTO prefecture(id,name) VALUES (22,'静岡県');
|
25
|
+
INSERT INTO prefecture(id,name) VALUES (23,'愛知県');
|
26
|
+
INSERT INTO prefecture(id,name) VALUES (24,'三重県');
|
27
|
+
INSERT INTO prefecture(id,name) VALUES (25,'滋賀県');
|
28
|
+
INSERT INTO prefecture(id,name) VALUES (26,'京都府');
|
29
|
+
INSERT INTO prefecture(id,name) VALUES (27,'大阪府');
|
30
|
+
INSERT INTO prefecture(id,name) VALUES (28,'兵庫県');
|
31
|
+
INSERT INTO prefecture(id,name) VALUES (29,'奈良県');
|
32
|
+
INSERT INTO prefecture(id,name) VALUES (30,'和歌山県');
|
33
|
+
INSERT INTO prefecture(id,name) VALUES (31,'鳥取県');
|
34
|
+
INSERT INTO prefecture(id,name) VALUES (32,'島根県');
|
35
|
+
INSERT INTO prefecture(id,name) VALUES (33,'岡山県');
|
36
|
+
INSERT INTO prefecture(id,name) VALUES (34,'広島県');
|
37
|
+
INSERT INTO prefecture(id,name) VALUES (35,'山口県');
|
38
|
+
INSERT INTO prefecture(id,name) VALUES (36,'徳島県');
|
39
|
+
INSERT INTO prefecture(id,name) VALUES (37,'香川県');
|
40
|
+
INSERT INTO prefecture(id,name) VALUES (38,'愛媛県');
|
41
|
+
INSERT INTO prefecture(id,name) VALUES (39,'高知県');
|
42
|
+
INSERT INTO prefecture(id,name) VALUES (40,'福岡県');
|
43
|
+
INSERT INTO prefecture(id,name) VALUES (41,'佐賀県');
|
44
|
+
INSERT INTO prefecture(id,name) VALUES (42,'長崎県');
|
45
|
+
INSERT INTO prefecture(id,name) VALUES (43,'熊本県');
|
46
|
+
INSERT INTO prefecture(id,name) VALUES (44,'大分県');
|
47
|
+
INSERT INTO prefecture(id,name) VALUES (45,'宮崎県');
|
48
|
+
INSERT INTO prefecture(id,name) VALUES (46,'鹿児島県');
|
49
|
+
INSERT INTO prefecture(id,name) VALUES (47,'沖縄県');
|
50
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 's2container'
|
5
|
+
require 'seasar/dbi'
|
6
|
+
require 'example'
|
7
|
+
|
8
|
+
s2comp(:class => DBI::DatabaseHandle, :namespace => "dbi", :autobinding => :none) {
|
9
|
+
DBI.connect("dbi:SQLite3:example.db")
|
10
|
+
}
|
11
|
+
|
12
|
+
begin
|
13
|
+
s2app[Example::PrefectureDao].find_all.each {|h|
|
14
|
+
puts h["id"] << "\t" << h["name"]
|
15
|
+
}
|
16
|
+
rescue Seasar::DBI::DBIInterceptor::ConnectError => e
|
17
|
+
s2logger.fatal(e.cause.class.name){"#{e.cause.message} #{e.cause.backtrace}"}
|
18
|
+
rescue => e
|
19
|
+
s2logger.fatal(e.class.name){"#{e.message} #{e.backtrace}"}
|
20
|
+
ensure
|
21
|
+
s2app[DBI::DatabaseHandle].disconnect if s2app[DBI::DatabaseHandle]
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dbi'
|
5
|
+
|
6
|
+
require 's2container'
|
7
|
+
require 'seasar/dbi'
|
8
|
+
require 'example'
|
9
|
+
|
10
|
+
s2comp(:class => DBI::DatabaseHandle, :namespace => "dbi", :autobinding => :none) {
|
11
|
+
DBI.connect("dbi:SQLite3:example.db")
|
12
|
+
}
|
13
|
+
|
14
|
+
begin
|
15
|
+
s2app[Example::PrefectureDao].find_by_id(1).each {|h|
|
16
|
+
puts h["id"] << "\t" << h["name"]
|
17
|
+
}
|
18
|
+
s2app[Example::PrefectureDao].find_by_id_hash(1).each {|h|
|
19
|
+
puts h["id"] << "\t" << h["name"]
|
20
|
+
}
|
21
|
+
rescue Seasar::DBI::DBIInterceptor::ConnectError => e
|
22
|
+
s2logger.fatal(e.cause.class.name){"#{e.cause.message} #{e.cause.backtrace}"}
|
23
|
+
rescue => e
|
24
|
+
s2logger.fatal(e.class.name){"#{e.message} #{e.backtrace}"}
|
25
|
+
ensure
|
26
|
+
s2app[DBI::DatabaseHandle].disconnect if s2app[DBI::DatabaseHandle]
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dbi'
|
5
|
+
|
6
|
+
require 's2container'
|
7
|
+
require 'seasar/dbi'
|
8
|
+
require 'example'
|
9
|
+
|
10
|
+
s2comp(:class => DBI::DatabaseHandle, :namespace => "dbi", :autobinding => :none) {
|
11
|
+
DBI.connect("dbi:SQLite3:example.db")
|
12
|
+
}
|
13
|
+
|
14
|
+
begin
|
15
|
+
s2app[Example::PrefectureDao].find_by_name("北海道").each {|h|
|
16
|
+
puts h["id"] << "\t" << h["name"]
|
17
|
+
}
|
18
|
+
rescue Seasar::DBI::DBIInterceptor::ConnectError => e
|
19
|
+
s2logger.fatal(e.cause.class.name){"#{e.cause.message} #{e.cause.backtrace}"}
|
20
|
+
rescue => e
|
21
|
+
s2logger.fatal(e.class.name){"#{e.message} #{e.backtrace}"}
|
22
|
+
ensure
|
23
|
+
s2app[DBI::DatabaseHandle].disconnect if s2app[DBI::DatabaseHandle]
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dbi'
|
5
|
+
|
6
|
+
require 's2container'
|
7
|
+
require 'seasar/dbi'
|
8
|
+
require 'example'
|
9
|
+
|
10
|
+
s2comp(:class => DBI::DatabaseHandle, :namespace => "dbi", :autobinding => :none) {
|
11
|
+
DBI.connect("dbi:SQLite3:example.db")
|
12
|
+
}
|
13
|
+
|
14
|
+
begin
|
15
|
+
puts s2app[Example::PrefectureDao].transactional_insert(48, "その他")
|
16
|
+
rescue Seasar::DBI::DBIInterceptor::ConnectError => e
|
17
|
+
s2logger.fatal(e.cause.class.name){"#{e.cause.message} #{e.cause.backtrace}"}
|
18
|
+
rescue => e
|
19
|
+
s2logger.fatal(e.class.name){"#{e.message} #{e.backtrace}"}
|
20
|
+
ensure
|
21
|
+
s2app[DBI::DatabaseHandle].disconnect if s2app[DBI::DatabaseHandle]
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dbi'
|
5
|
+
|
6
|
+
require 's2container'
|
7
|
+
require 'seasar/dbi'
|
8
|
+
require 'example'
|
9
|
+
|
10
|
+
s2comp(:class => DBI::DatabaseHandle, :namespace => "dbi", :autobinding => :none) {
|
11
|
+
DBI.connect("dbi:SQLite3:example.db")
|
12
|
+
}
|
13
|
+
|
14
|
+
begin
|
15
|
+
dto = Example::PrefectureDto.new
|
16
|
+
dto.limit = 5
|
17
|
+
dto.name_like = '%県'
|
18
|
+
dto.total = s2app[Example::PrefectureDao].find_total_by_dto(dto)[0]["total"]
|
19
|
+
puts "page : #{dto.page}"
|
20
|
+
s2app[Example::PrefectureDao].find_by_dto(dto).each {|h|
|
21
|
+
puts h["id"] << "\t" << h["name"]
|
22
|
+
}
|
23
|
+
dto.next
|
24
|
+
puts "page : #{dto.page}"
|
25
|
+
s2app[Example::PrefectureDao].find_by_dto(dto).each {|h|
|
26
|
+
puts h["id"] << "\t" << h["name"]
|
27
|
+
}
|
28
|
+
rescue Seasar::DBI::DBIInterceptor::ConnectError => e
|
29
|
+
s2logger.fatal(e.cause.class.name){"#{e.cause.message} #{e.cause.backtrace}"}
|
30
|
+
rescue => e
|
31
|
+
s2logger.fatal(e.class.name){"#{e.message} #{e.backtrace}"}
|
32
|
+
ensure
|
33
|
+
s2app[DBI::DatabaseHandle].disconnect if s2app[DBI::DatabaseHandle]
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Example
|
2
|
+
class Action
|
3
|
+
s2comp
|
4
|
+
def add2d(a, b)
|
5
|
+
return a + b
|
6
|
+
end
|
7
|
+
|
8
|
+
def add3d(a, b, c)
|
9
|
+
return a + b + c
|
10
|
+
end
|
11
|
+
|
12
|
+
def add2dp(a, b, &procedure)
|
13
|
+
return a + b + procedure.call
|
14
|
+
end
|
15
|
+
|
16
|
+
def echo(val)
|
17
|
+
print val.to_s + ' - '
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../lib')
|
2
|
+
|
3
|
+
require 's2container'
|
4
|
+
require 'example'
|
5
|
+
|
6
|
+
s2aspect {|invoker|
|
7
|
+
if invoker.args.size < invoker.method.arity
|
8
|
+
lambda {|*args|
|
9
|
+
method = invoker.enhanced_class.instance_method(invoker.method.name).bind(invoker.this)
|
10
|
+
method.call(*(invoker.args + args), &invoker.procedure)
|
11
|
+
}
|
12
|
+
else
|
13
|
+
invoker.proceed
|
14
|
+
end
|
15
|
+
}
|
16
|
+
|
17
|
+
component = s2app[Example::Action]
|
18
|
+
p component.add2d(2, 3) # -> 5
|
19
|
+
|
20
|
+
p component.add2d(2).call().call(3) # -> 5
|
21
|
+
|
22
|
+
p component.add3d(1).call(2, 3) # -> 6
|
23
|
+
p component.add3d(1).call(2).call(3) # -> 6
|
24
|
+
|
25
|
+
p (1 .. 10).map(&component.add2d(10)) # -> [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
|
26
|
+
|
27
|
+
pr = component.add2dp(1) {2}
|
28
|
+
p pr[3] # -> 6
|
@@ -0,0 +1,24 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../lib')
|
2
|
+
|
3
|
+
require 's2container'
|
4
|
+
require 'example'
|
5
|
+
|
6
|
+
Seasar::Container::ComponentInfoDef.auto_namespace = true
|
7
|
+
|
8
|
+
container = s2app.create(%w[A.B A.C])
|
9
|
+
p container.component_def?(:foo)
|
10
|
+
p container.component_def?(:bar)
|
11
|
+
p container.component_def?(:hoge)
|
12
|
+
|
13
|
+
puts ""
|
14
|
+
container = s2app.create(%w[X])
|
15
|
+
p container.component_def?(:foo)
|
16
|
+
p container.component_def?(:hoge)
|
17
|
+
p container.component_def?(:huga)
|
18
|
+
|
19
|
+
puts ""
|
20
|
+
container = s2app.create(%w[X.Y])
|
21
|
+
p container.component_def?(:foo)
|
22
|
+
p container.component_def?(:hoge)
|
23
|
+
p container.component_def?(:huga)
|
24
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../../lib')
|
2
|
+
require 's2container'
|
3
|
+
|
4
|
+
class Action
|
5
|
+
attr_accessor :name
|
6
|
+
end
|
7
|
+
|
8
|
+
s2comp(:class => Action) {
|
9
|
+
act = Action.new
|
10
|
+
act.name = "foo"
|
11
|
+
next act
|
12
|
+
}
|
13
|
+
|
14
|
+
p s2app.get(Action).name
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../../lib')
|
2
|
+
require 's2container'
|
3
|
+
|
4
|
+
class Action
|
5
|
+
attr_accessor :name
|
6
|
+
s2comp(:instance => :prototype) {
|
7
|
+
act = Action.new
|
8
|
+
act.name = "foo"
|
9
|
+
next act
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
action = s2app.get(Action) {
|
14
|
+
act = Action.new
|
15
|
+
act.name = "bar"
|
16
|
+
next act
|
17
|
+
}
|
18
|
+
p action.name
|
19
|
+
|
20
|
+
p s2app[Action].name
|
21
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../../lib')
|
2
|
+
require 's2container'
|
3
|
+
|
4
|
+
class Action
|
5
|
+
s2comp
|
6
|
+
def initialize
|
7
|
+
@a = nil
|
8
|
+
@b = :di, ServiceB
|
9
|
+
end
|
10
|
+
attr_reader :a, :b
|
11
|
+
attr_accessor :c
|
12
|
+
end
|
13
|
+
|
14
|
+
class ServiceA
|
15
|
+
s2comp :name => :a
|
16
|
+
end
|
17
|
+
|
18
|
+
class ServiceB
|
19
|
+
s2comp :instance => :prototype
|
20
|
+
end
|
21
|
+
|
22
|
+
class ServiceC
|
23
|
+
s2comp :name => :c
|
24
|
+
end
|
25
|
+
|
26
|
+
p s2app[Action].a
|
27
|
+
p s2app[Action].b
|
28
|
+
p s2app[Action].c
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift(File::expand_path(File::dirname(__FILE__)) + '/../../../lib')
|
2
|
+
require 's2container'
|
3
|
+
|
4
|
+
class Action
|
5
|
+
s2comp
|
6
|
+
s2aspect :interceptor => Seasar::Aop::Interceptor::TraceInterceptor.new
|
7
|
+
s2aspect :interceptor => "interceptor.trace"
|
8
|
+
def index
|
9
|
+
s2logger.debug(self){"Action::index called."}
|
10
|
+
return 100
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
s2aspect(:pattern => Action) {|invocation|
|
15
|
+
invocation.proceed * 1.05
|
16
|
+
}
|
17
|
+
|
18
|
+
p s2app[Action].index
|
data/lib/s2container.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
require 'seasar/container'
|
20
|
+
require 'seasar/log'
|
21
|
+
require 'seasar/aop'
|
22
|
+
require 'seasar/util'
|
23
|
+
require 'seasar/exception'
|
24
|
+
require 'seasar/beans'
|
25
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
# ++
|
19
|
+
|
20
|
+
module Seasar
|
21
|
+
module Aop
|
22
|
+
class Aspect
|
23
|
+
def initialize(interceptor, pointcut)
|
24
|
+
@interceptor = interceptor
|
25
|
+
@pointcut = pointcut
|
26
|
+
end
|
27
|
+
attr_accessor :interceptor, :pointcut
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# +----------------------------------------------------------------------+
|
4
|
+
# | Copyright 2005-2008 the Seasar Foundation and the Others. |
|
5
|
+
# +----------------------------------------------------------------------+
|
6
|
+
# | Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
+
# | you may not use this file except in compliance with the License. |
|
8
|
+
# | You may obtain a copy of the License at |
|
9
|
+
# | |
|
10
|
+
# | http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
+
# | |
|
12
|
+
# | Unless required by applicable law or agreed to in writing, software |
|
13
|
+
# | distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
+
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|
15
|
+
# | either express or implied. See the License for the specific language |
|
16
|
+
# | governing permissions and limitations under the License. |
|
17
|
+
# +----------------------------------------------------------------------+
|
18
|
+
#++
|
19
|
+
|
20
|
+
module Seasar
|
21
|
+
module Aop
|
22
|
+
module Interceptor
|
23
|
+
class TraceInterceptor
|
24
|
+
s2component :name => 'trace', :namespace => 'interceptor', :default => true
|
25
|
+
|
26
|
+
#
|
27
|
+
# - args
|
28
|
+
# 1. Seasar::Aop::MethodInvocation <em>invocation</em>
|
29
|
+
# - return
|
30
|
+
# - Object
|
31
|
+
#
|
32
|
+
def call(invocation)
|
33
|
+
#class_name = invocation.this.class.name
|
34
|
+
class_name = invocation.component_class.name
|
35
|
+
method_name = invocation.method.name
|
36
|
+
msg = "before : #{class_name}.#{method_name}(#{invocation.args.inspect})"
|
37
|
+
s2logger.debug(self.class.name) {msg}
|
38
|
+
start_time = Time.now
|
39
|
+
result = invocation.proceed()
|
40
|
+
time = Time.now - start_time
|
41
|
+
msg = "after : #{class_name}.#{method_name}(#{invocation.args.inspect}) : #{result} : #{time}"
|
42
|
+
s2logger.debug(self.class.name) {msg}
|
43
|
+
return result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|