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.
Files changed (136) hide show
  1. data/Apache_Software_License_2.0.txt +202 -0
  2. data/ChangeLog +1 -0
  3. data/ChangeLog.ja +64 -0
  4. data/README +9 -0
  5. data/Rakefile +51 -0
  6. data/example/example01/example.rb +13 -0
  7. data/example/example01/run.rb +20 -0
  8. data/example/example02/example.rb +30 -0
  9. data/example/example02/run.rb +8 -0
  10. data/example/example03/example.rb +8 -0
  11. data/example/example03/run.rb +12 -0
  12. data/example/example04/example.rb +9 -0
  13. data/example/example04/run.rb +15 -0
  14. data/example/example05/example.rb +9 -0
  15. data/example/example05/run.rb +21 -0
  16. data/example/example06/example.rb +9 -0
  17. data/example/example06/run.rb +8 -0
  18. data/example/example07/example.rb +8 -0
  19. data/example/example07/run.rb +15 -0
  20. data/example/example08/example.rb +9 -0
  21. data/example/example08/run.rb +19 -0
  22. data/example/example09/example.rb +7 -0
  23. data/example/example09/run.rb +11 -0
  24. data/example/example10/example.rb +9 -0
  25. data/example/example10/run.rb +10 -0
  26. data/example/example11/example.rb +18 -0
  27. data/example/example11/run.rb +10 -0
  28. data/example/example12/example.rb +9 -0
  29. data/example/example12/run.rb +8 -0
  30. data/example/example13/example.rb +18 -0
  31. data/example/example13/example.sql +4 -0
  32. data/example/example13/run.rb +22 -0
  33. data/example/example13/sample.db +0 -0
  34. data/example/example14/example.db +0 -0
  35. data/example/example14/example.rb +57 -0
  36. data/example/example14/example.sql +50 -0
  37. data/example/example14/run1.rb +23 -0
  38. data/example/example14/run2.rb +28 -0
  39. data/example/example14/run3.rb +25 -0
  40. data/example/example14/run4.rb +23 -0
  41. data/example/example14/run5.rb +35 -0
  42. data/example/example15/example.rb +20 -0
  43. data/example/example15/run.rb +28 -0
  44. data/example/example16/example.rb +15 -0
  45. data/example/example16/run.rb +24 -0
  46. data/example/quickstart/quickstart1/quickstart.rb +10 -0
  47. data/example/quickstart/quickstart2/quickstart.rb +9 -0
  48. data/example/quickstart/quickstart3/quickstart.rb +9 -0
  49. data/example/quickstart/quickstart4/quickstart.rb +14 -0
  50. data/example/quickstart/quickstart5/quickstart.rb +21 -0
  51. data/example/quickstart/quickstart6/quickstart.rb +28 -0
  52. data/example/quickstart/quickstart7/quickstart.rb +18 -0
  53. data/lib/s2container.rb +25 -0
  54. data/lib/seasar/aop/aspect.rb +30 -0
  55. data/lib/seasar/aop/interceptor/trace-interceptor.rb +48 -0
  56. data/lib/seasar/aop/method-invocation.rb +57 -0
  57. data/lib/seasar/aop/pointcut.rb +53 -0
  58. data/lib/seasar/aop/s2aop-factory.rb +125 -0
  59. data/lib/seasar/aop.rb +29 -0
  60. data/lib/seasar/beans/abstract-property-desc.rb +59 -0
  61. data/lib/seasar/beans/attribute-accessor-desc.rb +60 -0
  62. data/lib/seasar/beans/bean-desc-factory.rb +68 -0
  63. data/lib/seasar/beans/bean-desc.rb +232 -0
  64. data/lib/seasar/beans/instance-variable-desc.rb +58 -0
  65. data/lib/seasar/beans.rb +29 -0
  66. data/lib/seasar/container/arg-def.rb +51 -0
  67. data/lib/seasar/container/aspect-def.rb +60 -0
  68. data/lib/seasar/container/aspect-info-def.rb +94 -0
  69. data/lib/seasar/container/assembler/abstract-assembler.rb +68 -0
  70. data/lib/seasar/container/assembler/auto-property-assembler.rb +57 -0
  71. data/lib/seasar/container/assembler/autobinding-auto-def.rb +55 -0
  72. data/lib/seasar/container/assembler/autobinding-def-factory.rb +57 -0
  73. data/lib/seasar/container/assembler/autobinding-none-def.rb +53 -0
  74. data/lib/seasar/container/assembler/manual-constructor-assembler.rb +67 -0
  75. data/lib/seasar/container/assembler/manual-property-assembler.rb +68 -0
  76. data/lib/seasar/container/autobinding-def.rb +36 -0
  77. data/lib/seasar/container/component-def.rb +229 -0
  78. data/lib/seasar/container/component-info-def.rb +117 -0
  79. data/lib/seasar/container/deployer/abstract-component-deployer.rb +47 -0
  80. data/lib/seasar/container/deployer/instance-def-factory.rb +56 -0
  81. data/lib/seasar/container/deployer/instance-outer-def.rb +44 -0
  82. data/lib/seasar/container/deployer/instance-prototype-def.rb +44 -0
  83. data/lib/seasar/container/deployer/instance-singleton-def.rb +42 -0
  84. data/lib/seasar/container/deployer/outer-component-deployer.rb +47 -0
  85. data/lib/seasar/container/deployer/prototype-component-deployer.rb +51 -0
  86. data/lib/seasar/container/deployer/singleton-component-deployer.rb +54 -0
  87. data/lib/seasar/container/exception/component-notfound-runtime-exception.rb +44 -0
  88. data/lib/seasar/container/exception/cyclic-reference-runtime-exception.rb +43 -0
  89. data/lib/seasar/container/exception/illegal-autobinding-def-runtime-exception.rb +43 -0
  90. data/lib/seasar/container/exception/illegal-instance-def-runtime-exception.rb +44 -0
  91. data/lib/seasar/container/exception/toomany-registration-runtime-exception.rb +46 -0
  92. data/lib/seasar/container/instance-def.rb +37 -0
  93. data/lib/seasar/container/outer-component-def.rb +34 -0
  94. data/lib/seasar/container/property-def.rb +43 -0
  95. data/lib/seasar/container/s2application-context.rb +447 -0
  96. data/lib/seasar/container/s2container-component-def.rb +41 -0
  97. data/lib/seasar/container/s2container.rb +308 -0
  98. data/lib/seasar/container/simple-component-def.rb +45 -0
  99. data/lib/seasar/container/toomany-registration-component-def.rb +69 -0
  100. data/lib/seasar/container.rb +143 -0
  101. data/lib/seasar/dbi/dbi-interceptor.rb +97 -0
  102. data/lib/seasar/dbi/paginate.rb +215 -0
  103. data/lib/seasar/dbi.rb +26 -0
  104. data/lib/seasar/exception/notyet-implemented-exception.rb +25 -0
  105. data/lib/seasar/exception/property-notfound-runtime-exception.rb +48 -0
  106. data/lib/seasar/exception/s2runtime-exception.rb +35 -0
  107. data/lib/seasar/exception/unsupported-operation-exception.rb +25 -0
  108. data/lib/seasar/exception.rb +27 -0
  109. data/lib/seasar/log/s2logger.rb +75 -0
  110. data/lib/seasar/log.rb +38 -0
  111. data/lib/seasar/util/class-util.rb +116 -0
  112. data/lib/seasar/util.rb +24 -0
  113. data/setup.rb +1585 -0
  114. data/test/seasar/aop/test_pointcut.rb +25 -0
  115. data/test/seasar/aop/test_s2aop_factory.rb +90 -0
  116. data/test/seasar/beans/test_bean-desc.rb +179 -0
  117. data/test/seasar/container/assembler/test_auto_property_assembler.rb +87 -0
  118. data/test/seasar/container/assembler/test_autobinding_def_factory.rb +22 -0
  119. data/test/seasar/container/assembler/test_manual_property_assembler.rb +59 -0
  120. data/test/seasar/container/assembler/test_manula_constructor_assembler.rb +59 -0
  121. data/test/seasar/container/assembler/test_proc_constructor_assembler.rb +61 -0
  122. data/test/seasar/container/deployer/test_instance_def_factory.rb +24 -0
  123. data/test/seasar/container/deployer/test_prototype-deployer.rb +25 -0
  124. data/test/seasar/container/deployer/test_singleton-component-deployer.rb +24 -0
  125. data/test/seasar/container/s2app_load_sample.rb +6 -0
  126. data/test/seasar/container/test_arg-def.rb +34 -0
  127. data/test/seasar/container/test_aspect-info-def.rb +85 -0
  128. data/test/seasar/container/test_component-def.rb +91 -0
  129. data/test/seasar/container/test_component-info-def.rb +88 -0
  130. data/test/seasar/container/test_s2application-context.rb +290 -0
  131. data/test/seasar/container/test_s2container.rb +268 -0
  132. data/test/seasar/dbi/test_paginate.rb +265 -0
  133. data/test/seasar/test_log.rb +20 -0
  134. data/test/seasar/test_util.rb +46 -0
  135. data/test/test-suite.rb +7 -0
  136. metadata +211 -0
@@ -0,0 +1,308 @@
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
+ module Seasar
20
+ module Container
21
+ class S2Container
22
+
23
+ # - args
24
+ # - none
25
+ def initialize
26
+ @component_def_list = []
27
+ @component_def_map = {}
28
+ @outer_component_def = Seasar::Container::OuterComponentDef.new(self)
29
+ component_def = SimpleComponentDef.new(self, 's2container')
30
+ @component_def_map['container'] = component_def
31
+ @component_def_map[:container] = component_def
32
+ @component_def_map[self.class] = component_def
33
+ @root = self
34
+ @parents = []
35
+ @children = []
36
+ @namespace = nil
37
+ end
38
+ attr_accessor :root, :parents, :namespace
39
+
40
+ #
41
+ # - args
42
+ # 1. Object|Seasar::Container::ComponentDef <em>item</em>
43
+ # 2. String|Symbol <em>name</em>
44
+ # - return
45
+ # - none
46
+ #
47
+ def register(item, name = nil)
48
+ if item.is_a?(ComponentDef)
49
+ component_def = item
50
+ elsif item.class == Class
51
+ return self.register(ComponentDef.new(item, name))
52
+ else
53
+ component_def = SimpleComponentDef.new(item)
54
+ end
55
+
56
+ component_def.container = self if component_def.container.nil?
57
+ @component_def_list << component_def
58
+ self.register_by_name(component_def)
59
+ self.register_by_class(component_def)
60
+ end
61
+
62
+ #
63
+ # - args
64
+ # 1. Seasar::Container::ComponentDef <em>component_def</em>
65
+ # - return
66
+ # - none
67
+ #
68
+ def register_by_class(component_def)
69
+ component_def.component_class.ancestors.each {|base|
70
+ next if (base == Object or base == Kernel)
71
+ self.register_map(base, component_def)
72
+ }
73
+ end
74
+
75
+ #
76
+ # - args
77
+ # 1. Seasar::Container::ComponentDef <em>component_def</em>
78
+ # - return
79
+ # - none
80
+ #
81
+ def register_by_name(component_def)
82
+ if not component_def.component_name.nil?
83
+ self.register_map(component_def.component_name, component_def)
84
+ end
85
+ end
86
+
87
+ #
88
+ # - args
89
+ # 1. String|Symbol <em>key</em>
90
+ # 2. Seasar::Container::ComponentDef <em>component_def</em>
91
+ # - return
92
+ # - none
93
+ #
94
+ def register_map(key, component_def)
95
+ if @component_def_map.key?(key)
96
+ self.process_toomany_registration(key, component_def)
97
+ else
98
+ @component_def_map[key] = component_def
99
+ end
100
+ end
101
+
102
+ #
103
+ # - args
104
+ # - none
105
+ # - return
106
+ # - Integer
107
+ #
108
+ def get_component_def_size
109
+ return @component_def_list.length
110
+ end
111
+
112
+ #
113
+ # - args
114
+ # 1. String|Symbol <em>key</em>
115
+ # 2. Proc <em>procedure</em>
116
+ # - return
117
+ # - Object
118
+ #
119
+ def get_component(key, &procedure)
120
+ cd = self.get_component_def(key)
121
+ cd.onetime_proc = procedure
122
+ return cd.get_component
123
+ end
124
+ alias component get_component
125
+ alias get get_component
126
+ alias [] get_component
127
+
128
+ #
129
+ # - args
130
+ # 1. String|Symbol <em>key</em>
131
+ # - return
132
+ # - Seasar::Container::ComponentDef
133
+ #
134
+ def get_component_def(key)
135
+ component_def = self.get_component_def_internal(key);
136
+ if component_def.nil?
137
+ raise Seasar::Container::Exception::ComponentNotFoundRuntimeException.new(key)
138
+ end
139
+ return component_def
140
+ end
141
+ alias component_def get_component_def
142
+
143
+ # ComponentDefをkeyで検索して返します。見つからなければnilが返ります。
144
+ # keyがclassの場合は、自分自身が保持しているかを検索して、すべての子のコンテナ
145
+ # に問い合わせます。keyが文字列の場合は、「.」区切りになっている場合は、namespace
146
+ # で指定されたコンテナ以下のすべての子コンテナ内でComponentDefを検索します。
147
+ # その後、見つからない場合は、自分自身が保持しているすべての子コンテナを検索します。
148
+ #
149
+ # - args
150
+ # 1. String|Symbol <em>key</em>
151
+ # - return
152
+ # - Seasar::Container::ComponentDef
153
+ #
154
+ def get_component_def_internal(key, search_parent = true, ignore_children = [])
155
+ if @component_def_map.key?(key)
156
+ return @component_def_map[key]
157
+ elsif key.is_a?(String) && key.match(/\./)
158
+ component_def = self.get_component_def_with_namespace(key)
159
+ return component_def unless component_def.nil?
160
+ else
161
+ component_def = self.get_component_def_from_children(key, ignore_children)
162
+ return component_def unless component_def.nil?
163
+ end
164
+ return nil unless search_parent
165
+
166
+ ignore_children << self
167
+ return nil if @parents.size == 0
168
+ @parents.each {|parent|
169
+ next if parent.parents.size == 0 && ignore_children.member?(parent)
170
+ component_def = parent.get_component_def_internal(key, true, ignore_children)
171
+ return component_def unless component_def.nil?
172
+ }
173
+ return nil
174
+ end
175
+
176
+ #
177
+ # - args
178
+ # 1. String|Symbol <em>key</em>
179
+ # - return
180
+ # - Seasar::Container::ComponentDef
181
+ #
182
+ def get_component_def_with_namespace(key)
183
+ if /^(.+?)\.(.+)$/ =~ key
184
+ component_def = self.get_component_def_internal($1, false)
185
+ unless component_def.nil?
186
+ child_container = component_def.get_component()
187
+ component_def = child_container.get_component_def_internal($2, false)
188
+ return component_def unless component_def.nil?
189
+ end
190
+ end
191
+ return nil
192
+ end
193
+
194
+ #
195
+ # - args
196
+ # 1. String|Symbol <em>key</em>
197
+ # - return
198
+ # - Seasar::Container::ComponentDef
199
+ #
200
+ def get_component_def_from_children(key, ignore_children = [])
201
+ @children.each {|child_container|
202
+ next if ignore_children.member?(child_container)
203
+ component_def = child_container.get_component_def_internal(key, false)
204
+ return component_def unless component_def.nil?
205
+ }
206
+ return nil
207
+ end
208
+
209
+ #
210
+ # - args
211
+ # 1. String|Symbol <em>key</em>
212
+ # - return
213
+ # - Boolean
214
+ #
215
+ def has_component_def(key)
216
+ return self.get_component_def_internal(key).nil? == false
217
+ end
218
+ alias component_def? has_component_def
219
+
220
+ #
221
+ # - args
222
+ # 1. String|Symbol <em>key</em>
223
+ # - return
224
+ # - Array
225
+ #
226
+ def find_components(key)
227
+ component_defs = self.find_component_defs(key)
228
+ components = []
229
+ for component_def in component_defs
230
+ components << component_def.component
231
+ end
232
+ return components
233
+ end
234
+
235
+ #
236
+ # - args
237
+ # 1. String|Symbol <em>key</em>
238
+ # - return
239
+ # - Array
240
+ #
241
+ def find_component_defs(key)
242
+ component_def = self.get_component_def(key)
243
+ if component_def.instance_of?(Seasar::Container::TooManyRegistrationComponentDef)
244
+ return component_def.component_defs
245
+ else
246
+ return [component_def]
247
+ end
248
+ end
249
+
250
+ #
251
+ # - args
252
+ # 1. Seasar::Container::S2Container <em>child_container</em>
253
+ # - return
254
+ # - none
255
+ #
256
+ def include(child_container)
257
+ child_container.root = @root
258
+ child_container.parents << self
259
+ @children << child_container
260
+ namespace = child_container.namespace
261
+ if not namespace.nil?
262
+ self.register_map(namespace, S2ContainerComponentDef.new(child_container, namespace))
263
+ end
264
+ end
265
+
266
+ #
267
+ # - args
268
+ # 1. Strig
269
+ # - return
270
+ # - none
271
+ #
272
+ def namespace=(namespace)
273
+ @namespace = namespace
274
+ @component_def_map[@namespace] = SimpleComponentDef.new(self, @namespace)
275
+ end
276
+
277
+ #
278
+ # - args
279
+ # 1. Object <em>instance</em>
280
+ # - return
281
+ # - Seasar::Container::Assembler::AbstractAssembler
282
+ #
283
+ def inject(instance)
284
+ @outer_component_def.instance = instance
285
+ return @outer_component_def.component
286
+ end
287
+
288
+ #
289
+ # - args
290
+ # 1. String|Symbol <em>key</em>
291
+ # 2. Seasar::Container::ComponentDef <em>component_def</em>
292
+ # - return
293
+ # - none
294
+ #
295
+ def process_toomany_registration(key, new_component_def)
296
+ component_def = @component_def_map[key]
297
+ if component_def.instance_of?(Seasar::Container::TooManyRegistrationComponentDef)
298
+ component_def.add_component_def(new_component_def)
299
+ else
300
+ tmrcf = Seasar::Container::TooManyRegistrationComponentDef.new(key)
301
+ tmrcf.add_component_def(component_def)
302
+ tmrcf.add_component_def(new_component_def)
303
+ @component_def_map[key] = tmrcf
304
+ end
305
+ end
306
+ end
307
+ end
308
+ end
@@ -0,0 +1,45 @@
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
+ module Seasar
20
+ module Container
21
+ class SimpleComponentDef < ComponentDef
22
+
23
+ # - args
24
+ # 1. Object <em>component</em>
25
+ # 2. Symbol|String <em>name</em>
26
+ def initialize(component, component_name = nil)
27
+ super(component.class, component_name)
28
+ @component = component
29
+ end
30
+
31
+ #
32
+ # - args
33
+ # - none
34
+ # - return
35
+ # - Object
36
+ #
37
+ def get_component
38
+ return @component
39
+ end
40
+ alias get get_component
41
+ alias component get_component
42
+ alias [] get_component
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,69 @@
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
+ module Seasar
20
+ module Container
21
+ class TooManyRegistrationComponentDef < SimpleComponentDef
22
+
23
+ # - args
24
+ # 1. String|Symbol <em>key</em>
25
+ def initialize(key)
26
+ @key = key
27
+ @component_defs = []
28
+ end
29
+ attr_accessor :component_defs
30
+
31
+ #
32
+ # - args
33
+ # 1. Seasar::Container::ComponentDef <em>component_def</em>
34
+ # - return
35
+ # - none
36
+ #
37
+ def add_component_def(component_def)
38
+ @component_defs << component_def
39
+ end
40
+
41
+ #
42
+ # - args
43
+ # - none
44
+ # - return
45
+ # - Object
46
+ #
47
+ def get_component
48
+ raise Seasar::Container::Exception::TooManyRegistrationRuntimeException.new(@key, self.get_component_classes)
49
+ end
50
+ alias get get_component
51
+ alias component get_component
52
+ alias [] get_component
53
+
54
+ #
55
+ # - args
56
+ # - none
57
+ # - return
58
+ # - Array
59
+ #
60
+ def get_component_classes
61
+ component_classes = []
62
+ @component_defs.each {|component_def|
63
+ component_classes << component_def.component_class
64
+ }
65
+ return component_classes
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,143 @@
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
+
21
+ #
22
+ # - args
23
+ # - none
24
+ # - return
25
+ # - Seasar::Container::S2ApplicationContext
26
+ #
27
+ def s2app
28
+ return Seasar::Container::S2ApplicationContext.instance
29
+ end
30
+
31
+ #
32
+ # - args
33
+ # 1. Hash _option_
34
+ # - :name
35
+ # - :class
36
+ # - :instance
37
+ # - :autobinding
38
+ # - :namespace
39
+ # - :static
40
+ # 2. Proc _option_ constructor block of component
41
+ # - return
42
+ # - nil
43
+ #
44
+ def s2component(option = {}, &procedure)
45
+ if option[:class].nil?
46
+ if self.class == Class
47
+ option[:class] = self
48
+ option[:static] = true
49
+ else
50
+ raise TypeError.new("class not specified.")
51
+ end
52
+ end
53
+ s2app.register(option, &procedure)
54
+ end
55
+ alias s2comp s2component
56
+
57
+ #
58
+ # - args
59
+ # 1. Hash _option_
60
+ # - :pattern
61
+ # - :pointcut
62
+ # - :interceptor
63
+ # 2. Proc _option_ interceptor block
64
+ # - return
65
+ # - nil
66
+ #
67
+ def s2aspect(option = {}, &procedure)
68
+ clazz = nil
69
+ if option[:class].nil?
70
+ if self.class == Class
71
+ clazz = self
72
+ option[:static] = true
73
+ end
74
+ else
75
+ clazz = option[:class]
76
+ end
77
+
78
+ if option[:pattern].nil?
79
+ if not clazz.nil?
80
+ option[:pattern] = self.name
81
+ end
82
+ end
83
+ s2app.aspect(option, &procedure)
84
+ end
85
+
86
+ #
87
+ # - args
88
+ # - mixed _arg_
89
+ # - return
90
+ # - nil
91
+ #
92
+ def s2di(arg = nil)
93
+ return :di => arg
94
+ end
95
+
96
+ module Seasar
97
+ module Container
98
+ autoload :ArgDef, 'seasar/container/arg-def'
99
+ autoload :AspectDef, 'seasar/container/aspect-def'
100
+ autoload :AspectInfoDef, 'seasar/container/aspect-info-def'
101
+ autoload :AutoBindingDef, 'seasar/container/autobinding-def'
102
+ autoload :ComponentDef, 'seasar/container/component-def'
103
+ autoload :ComponentInfoDef, 'seasar/container/component-info-def'
104
+ autoload :InstanceDef, 'seasar/container/instance-def'
105
+ autoload :OuterComponentDef, 'seasar/container/outer-component-def'
106
+ autoload :PropertyDef, 'seasar/container/property-def'
107
+ autoload :S2ApplicationContext, 'seasar/container/s2application-context'
108
+ autoload :S2ContainerComponentDef, 'seasar/container/s2container-component-def'
109
+ autoload :S2Container, 'seasar/container/s2container'
110
+ autoload :SimpleComponentDef, 'seasar/container/simple-component-def'
111
+ autoload :TooManyRegistrationComponentDef, 'seasar/container/toomany-registration-component-def'
112
+
113
+ module Assembler
114
+ autoload :AbstractAssembler, 'seasar/container/assembler/abstract-assembler'
115
+ autoload :AutoPropertyAssembler, 'seasar/container/assembler/auto-property-assembler'
116
+ autoload :AutoBindingAutoDef, 'seasar/container/assembler/autobinding-auto-def'
117
+ autoload :AutoBindingDefFactory, 'seasar/container/assembler/autobinding-def-factory'
118
+ autoload :AutoBindingNoneDef, 'seasar/container/assembler/autobinding-none-def'
119
+ autoload :ManualConstructorAssembler, 'seasar/container/assembler/manual-constructor-assembler'
120
+ autoload :ManualPropertyAssembler, 'seasar/container/assembler/manual-property-assembler'
121
+ end
122
+
123
+ module Deployer
124
+ autoload :AbstractComponentDeployer, 'seasar/container/deployer/abstract-component-deployer'
125
+ autoload :InstanceDefFactory, 'seasar/container/deployer/instance-def-factory'
126
+ autoload :InstanceOuterDef, 'seasar/container/deployer/instance-outer-def'
127
+ autoload :InstancePrototypeDef, 'seasar/container/deployer/instance-prototype-def'
128
+ autoload :InstanceSingletonDef, 'seasar/container/deployer/instance-singleton-def'
129
+ autoload :OuterComponentDeployer, 'seasar/container/deployer/outer-component-deployer'
130
+ autoload :PrototypeComponentDeployer, 'seasar/container/deployer/prototype-component-deployer'
131
+ autoload :SingletonComponentDeployer, 'seasar/container/deployer/singleton-component-deployer'
132
+ end
133
+
134
+ module Exception
135
+ autoload :ComponentNotFoundRuntimeException, 'seasar/container/exception/component-notfound-runtime-exception'
136
+ autoload :CyclicReferenceRuntimeException, 'seasar/container/exception/cyclic-reference-runtime-exception'
137
+ autoload :IllegalAutoBindingDefRuntimeException, 'seasar/container/exception/illegal-autobinding-def-runtime-exception'
138
+ autoload :IllegalInstanceDefRuntimeException, 'seasar/container/exception/illegal-instance-def-runtime-exception'
139
+ autoload :TooManyRegistrationRuntimeException, 'seasar/container/exception/toomany-registration-runtime-exception'
140
+ end
141
+ end
142
+ end
143
+
@@ -0,0 +1,97 @@
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
+ module Seasar
20
+ module DBI
21
+ class DBIInterceptor
22
+ s2comp :namespace => 'dbi', :name => 'interceptor', :default => true
23
+
24
+ # - args
25
+ # - none
26
+ #
27
+ def initialize
28
+ @dbh = :di, ::DBI::DatabaseHandle
29
+ @statements = {}
30
+ @auto_finish = true
31
+ end
32
+ attr_accessor :auto_finish
33
+ #attr_accessor :auto_finish, :database_handle
34
+
35
+ #
36
+ # - args
37
+ # 1. Seasar::Aop::MethodInvocation <em>invocation</em>
38
+ # - return
39
+ # - Object
40
+ #
41
+ def call(invocation)
42
+ sql, context = invocation.proceed
43
+ sql.strip!
44
+ context = invocation.args if context.nil?
45
+ if !context.is_a?(Array) && !context.is_a?(Hash)
46
+ context = [context]
47
+ end
48
+
49
+ if not @statements.key?(sql) or @statements[sql].finished?
50
+ s2logger.debug(self.class.name){"#{sql} : (#{context.inspect})"}
51
+ @statements[sql] = @dbh.prepare(sql)
52
+ end
53
+ begin
54
+ if context.is_a?(Array)
55
+ @statements[sql].execute(*context)
56
+ else
57
+ @statements[sql].execute(context)
58
+ end
59
+ rescue => e
60
+ @statements[sql].finish
61
+ raise e
62
+ end
63
+
64
+ if @statements[sql].column_names.size == 0
65
+ result = @statements[sql].rows
66
+ else
67
+ result = []
68
+ @statements[sql].fetch_hash {|row| result << row}
69
+ end
70
+
71
+ @statements[sql].finish if @auto_finish
72
+ return result
73
+ end
74
+
75
+ #
76
+ # - args
77
+ # - none
78
+ # - return
79
+ # - none
80
+ #
81
+ def finish_all
82
+ @statements.each {|key, val| val.finish if not val.finished? }
83
+ end
84
+
85
+ class ConnectError < ::Exception
86
+ #
87
+ # - args
88
+ # 1. Error <em>cause</em>
89
+ #
90
+ def initialize(cause)
91
+ @cause = cause
92
+ end
93
+ attr_reader :cause
94
+ end
95
+ end
96
+ end
97
+ end