Compare commits
295 Commits
1.0.0.M3-M
...
1.1.0.M1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4be229312c | ||
|
|
54ec7af462 | ||
|
|
7162677992 | ||
|
|
cf131aaa7e | ||
|
|
6cd3b7a3aa | ||
|
|
71e639402c | ||
|
|
fed31c74e1 | ||
|
|
5b13307e39 | ||
|
|
d317bcfa71 | ||
|
|
883bfbe79e | ||
|
|
7502ac137c | ||
|
|
3dfc59bfb8 | ||
|
|
9e50621c1b | ||
|
|
472beaf6d2 | ||
|
|
d6d8a13b0c | ||
|
|
3dcf93744b | ||
|
|
6373a70ca4 | ||
|
|
858afa80f1 | ||
|
|
97f57e3541 | ||
|
|
05c2045e45 | ||
|
|
d3598198a6 | ||
|
|
2a8fe5bac7 | ||
|
|
cdc8f52bad | ||
|
|
39492daa50 | ||
|
|
16904ba1a7 | ||
|
|
51a469b46f | ||
|
|
9f2b1f4ed0 | ||
|
|
e0ea8a6088 | ||
|
|
8861934336 | ||
|
|
93c9713adf | ||
|
|
68a0c1ee2c | ||
|
|
c3d533d59d | ||
|
|
e4b9be6b38 | ||
|
|
09a8b9c9c4 | ||
|
|
e531508bdc | ||
|
|
289c4b95ae | ||
|
|
25e6d6e025 | ||
|
|
83d18b5ce6 | ||
|
|
8f09748d78 | ||
|
|
4429971548 | ||
|
|
065a50bc8c | ||
|
|
f8daa69e53 | ||
|
|
8a18cd4aef | ||
|
|
3320208a1d | ||
|
|
4ebc6e96d3 | ||
|
|
91fe5480a8 | ||
|
|
b6322d7bbc | ||
|
|
572c4bb2cd | ||
|
|
9caa8b15cd | ||
|
|
275f4fe6b8 | ||
|
|
4c40ef7e3d | ||
|
|
609097c0dc | ||
|
|
307d86498e | ||
|
|
19879b8dab | ||
|
|
b190f22551 | ||
|
|
0e9c6a5de8 | ||
|
|
5ec0cc7327 | ||
|
|
817e167056 | ||
|
|
4a6fa5cade | ||
|
|
9cd33763b6 | ||
|
|
de8d2a1c74 | ||
|
|
9f940cd2b6 | ||
|
|
0d69baa32c | ||
|
|
433e5a660e | ||
|
|
ee33ce1571 | ||
|
|
9ac11e967a | ||
|
|
a89a0ac542 | ||
|
|
0ad0dad124 | ||
|
|
8f2771416e | ||
|
|
7af009cc7f | ||
|
|
35ad949c18 | ||
|
|
8206b5f950 | ||
|
|
170081137a | ||
|
|
6862bd8a45 | ||
|
|
490db7c39f | ||
|
|
f3979c3676 | ||
|
|
8d18729898 | ||
|
|
b5e0b2bec2 | ||
|
|
9eb47827c1 | ||
|
|
f97ab25411 | ||
|
|
6616761f50 | ||
|
|
89de566893 | ||
|
|
ea1f090b40 | ||
|
|
b5958fb5cc | ||
|
|
75b7aff80a | ||
|
|
7da0fcdd0c | ||
|
|
c88b6d89db | ||
|
|
de1540aadc | ||
|
|
d1b24d6cfb | ||
|
|
e85f3d3299 | ||
|
|
ef6e08d3f4 | ||
|
|
21010fbd49 | ||
|
|
4325d6c9fa | ||
|
|
bc16ccfded | ||
|
|
04f5f9f662 | ||
|
|
b1f1b8efaa | ||
|
|
de300e2643 | ||
|
|
20088b83d9 | ||
|
|
58f200f15e | ||
|
|
8718700249 | ||
|
|
f4063d1679 | ||
|
|
ef063613c7 | ||
|
|
2eda0f1701 | ||
|
|
ec7b65e21d | ||
|
|
c7f7571f3f | ||
|
|
9f71af42e8 | ||
|
|
92775170e1 | ||
|
|
4c7e338770 | ||
|
|
e3fff52d17 | ||
|
|
5477ab20b2 | ||
|
|
4cf3567f42 | ||
|
|
b26bb62a63 | ||
|
|
f156d7b5af | ||
|
|
7bf3643902 | ||
|
|
201ae3e92d | ||
|
|
07556ec58c | ||
|
|
39807b17e1 | ||
|
|
4913fe26ac | ||
|
|
7642a719ff | ||
|
|
6c1ce576a4 | ||
|
|
c99882201d | ||
|
|
ce6a64e4a9 | ||
|
|
2fcc323bcd | ||
|
|
17c7b1d2b5 | ||
|
|
cfefe46cd4 | ||
|
|
64921ddad1 | ||
|
|
edda1764fe | ||
|
|
8113b79109 | ||
|
|
9fde4dff3e | ||
|
|
d4b3e2b99d | ||
|
|
68a31d75f3 | ||
|
|
3e15c21419 | ||
|
|
e9f253d34f | ||
|
|
80aa057acb | ||
|
|
613b183b70 | ||
|
|
5d1320a82a | ||
|
|
8ccaf61d12 | ||
|
|
2c46cfd8fe | ||
|
|
45f2900d15 | ||
|
|
79934538b6 | ||
|
|
0e4e0094a5 | ||
|
|
5df61563f4 | ||
|
|
04ebec993d | ||
|
|
caa245dd08 | ||
|
|
717ff38319 | ||
|
|
33155ba0f4 | ||
|
|
9f62efa47c | ||
|
|
620fc876f4 | ||
|
|
cfcf839232 | ||
|
|
7ce1e5fbd3 | ||
|
|
2d12ba38f8 | ||
|
|
1554d489ca | ||
|
|
f030d304f4 | ||
|
|
105e1da82b | ||
|
|
dbc7601d7b | ||
|
|
ccf981b8fb | ||
|
|
8a43b4bbc0 | ||
|
|
1c2c592b96 | ||
|
|
cd4b409bf2 | ||
|
|
f71477f17d | ||
|
|
454df1e7f1 | ||
|
|
80641a0943 | ||
|
|
e405bf574c | ||
|
|
9f8e406aff | ||
|
|
7d26366352 | ||
|
|
864ae831dd | ||
|
|
bfb13d99e3 | ||
|
|
f39de4c28e | ||
|
|
3bdeb68617 | ||
|
|
6b40a27c92 | ||
|
|
237cbec945 | ||
|
|
39bc6771b7 | ||
|
|
73b2d5a99c | ||
|
|
5dab0c721e | ||
|
|
bf7c9663cf | ||
|
|
135742b7e4 | ||
|
|
dee0307055 | ||
|
|
06fb4144e0 | ||
|
|
5fdc600570 | ||
|
|
f54c69b6ef | ||
|
|
decdcff79f | ||
|
|
be8daa5268 | ||
|
|
c4cd074d4d | ||
|
|
8b7521a93b | ||
|
|
ba508f497c | ||
|
|
091246a9aa | ||
|
|
745e1f313d | ||
|
|
234e04f4a3 | ||
|
|
15ab529596 | ||
|
|
00bea23eed | ||
|
|
c646c1f3b2 | ||
|
|
069f491603 | ||
|
|
e426ba4d43 | ||
|
|
756f886cef | ||
|
|
9bb42245bb | ||
|
|
c15263a259 | ||
|
|
758ee97a8d | ||
|
|
4f92690f58 | ||
|
|
595ed69820 | ||
|
|
48bf08afa3 | ||
|
|
98bdae4a00 | ||
|
|
f08b87d8d6 | ||
|
|
6c3ffeac5f | ||
|
|
490ddc4a0e | ||
|
|
ae26f4fea1 | ||
|
|
e9ea756a3a | ||
|
|
c4c95813b7 | ||
|
|
bfeb1b34c1 | ||
|
|
44def7dddb | ||
|
|
df10bb2168 | ||
|
|
f98607f5dc | ||
|
|
da23133327 | ||
|
|
ce5046c35f | ||
|
|
95245015bc | ||
|
|
fc40e6b08c | ||
|
|
eac5cb8c46 | ||
|
|
54377031bb | ||
|
|
213963f2ff | ||
|
|
0fb21aa2a1 | ||
|
|
e0da98ec51 | ||
|
|
7610246a1d | ||
|
|
ce59d893ba | ||
|
|
e130fb5a2d | ||
|
|
fedcbdae4f | ||
|
|
7cd020ffa7 | ||
|
|
b01e1a994b | ||
|
|
dd02338b5e | ||
|
|
7084839df1 | ||
|
|
09aad4343f | ||
|
|
c6a97ef407 | ||
|
|
ceac760d19 | ||
|
|
244e9bc6d8 | ||
|
|
2016aab969 | ||
|
|
35f180f999 | ||
|
|
ad8b6fccb4 | ||
|
|
d237ee80c8 | ||
|
|
eb276841dd | ||
|
|
1d51052ab1 | ||
|
|
58898e97c2 | ||
|
|
a5328da460 | ||
|
|
fd7e41b753 | ||
|
|
f349f5ea10 | ||
|
|
aa9d69d584 | ||
|
|
764317635c | ||
|
|
9ed5e6886c | ||
|
|
94f36d27fc | ||
|
|
a5fb4872b7 | ||
|
|
2f577c9678 | ||
|
|
9bcd19866f | ||
|
|
2af45518bd | ||
|
|
e1daf36ed8 | ||
|
|
101064769c | ||
|
|
ac9c804aae | ||
|
|
992f09d731 | ||
|
|
4324ed8231 | ||
|
|
eebe973209 | ||
|
|
bb01cccac5 | ||
|
|
2bdd49e3b7 | ||
|
|
f424b7c760 | ||
|
|
58b9db28a8 | ||
|
|
3e56210c78 | ||
|
|
523612a3a9 | ||
|
|
1604c80d32 | ||
|
|
d27a1ad310 | ||
|
|
d2cca2c52a | ||
|
|
ce0539a3dc | ||
|
|
4b4c35b904 | ||
|
|
f0df16a340 | ||
|
|
a9670de959 | ||
|
|
2d5f41f65c | ||
|
|
2e3f2c602c | ||
|
|
a2687b6688 | ||
|
|
e89ea320bc | ||
|
|
df24218a4f | ||
|
|
2d09b8b7d1 | ||
|
|
dd06973f50 | ||
|
|
2256ebac1b | ||
|
|
f4373957b3 | ||
|
|
af0cd9049a | ||
|
|
99edcb82cf | ||
|
|
7a98877e75 | ||
|
|
d856a7cad9 | ||
|
|
c1b396cca5 | ||
|
|
2e86012b3f | ||
|
|
538a62efce | ||
|
|
3573851bfc | ||
|
|
e47ddf4bf2 | ||
|
|
c59711a409 | ||
|
|
b1ab3f6ade | ||
|
|
fa094eef25 | ||
|
|
8ac2ff6b81 | ||
|
|
46d6dffdd4 | ||
|
|
06632cc3ae | ||
|
|
df0427442a | ||
|
|
eb20aea7fe |
30
.gitignore
vendored
30
.gitignore
vendored
@@ -1,13 +1,17 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
*.iws
|
*.iws
|
||||||
target
|
*.orig
|
||||||
.springBeans
|
target
|
||||||
.ant-targets-build.xml
|
.springBeans
|
||||||
.settings/
|
.sonar4clipse
|
||||||
.project
|
*.sonar4clipseExternals
|
||||||
.classpath
|
.ant-targets-build.xml
|
||||||
src/ant/.ant-targets-upload-dist.xml
|
.settings/
|
||||||
atlassian-ide-plugin.xml
|
.project
|
||||||
/.gradle/
|
.classpath
|
||||||
|
src/ant/.ant-targets-upload-dist.xml
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
/.gradle/
|
||||||
|
/.idea/
|
||||||
|
|||||||
291
etc/formatting.xml
Normal file
291
etc/formatting.xml
Normal file
@@ -0,0 +1,291 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<profiles version="12">
|
||||||
|
<profile kind="CodeFormatterProfile" name="Spring Data" version="12">
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.source" value="1.7"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="2"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="tab"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.7"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="120"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.7"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
58
pom.xml
58
pom.xml
@@ -1,18 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-document-dist</artifactId>
|
<artifactId>spring-data-mongodb-dist</artifactId>
|
||||||
<name>Spring Data Document Distribution</name>
|
<name>Spring Data MongoDB Distribution</name>
|
||||||
<version>1.0.0.M3</version>
|
<version>1.1.0.M1</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<module>spring-data-document-parent</module>
|
|
||||||
<module>spring-data-mongodb</module>
|
<module>spring-data-mongodb</module>
|
||||||
<module>spring-data-mongodb-cross-store</module>
|
<module>spring-data-mongodb-cross-store</module>
|
||||||
<module>spring-data-mongodb-log4j</module>
|
<module>spring-data-mongodb-log4j</module>
|
||||||
<!-- <module>spring-data-couchdb</module> -->
|
<module>spring-data-mongodb-parent</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
@@ -90,7 +88,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<!-- dist.* properties are used by the antrun tasks below -->
|
<!-- dist.* properties are used by the antrun tasks below -->
|
||||||
<dist.id>spring-data-document</dist.id>
|
<dist.id>spring-data-mongo</dist.id>
|
||||||
<dist.name>Spring Data Mongo</dist.name>
|
<dist.name>Spring Data Mongo</dist.name>
|
||||||
<dist.key>SDMONGO</dist.key>
|
<dist.key>SDMONGO</dist.key>
|
||||||
<dist.version>${project.version}</dist.version>
|
<dist.version>${project.version}</dist.version>
|
||||||
@@ -146,37 +144,35 @@
|
|||||||
<htmlCustomization>${project.basedir}/src/docbkx/resources/xsl/html.xsl</htmlCustomization>
|
<htmlCustomization>${project.basedir}/src/docbkx/resources/xsl/html.xsl</htmlCustomization>
|
||||||
<useExtensions>1</useExtensions>
|
<useExtensions>1</useExtensions>
|
||||||
<highlightSource>1</highlightSource>
|
<highlightSource>1</highlightSource>
|
||||||
<highlightDefaultLanguage></highlightDefaultLanguage>
|
<highlightDefaultLanguage />
|
||||||
<!-- callouts -->
|
<!-- callouts -->
|
||||||
<entities>
|
<entities>
|
||||||
<entity>
|
<entity>
|
||||||
<name>version</name>
|
<name>version</name>
|
||||||
<value>${pom.version}</value>
|
<value>${project.version}</value>
|
||||||
</entity>
|
</entity>
|
||||||
</entities>
|
</entities>
|
||||||
<postProcess>
|
<postProcess>
|
||||||
<copy todir="${project.basedir}/target/site/reference">
|
<copy todir="${project.basedir}/target/site/reference">
|
||||||
<fileset dir="${project.basedir}/target/docbkx">
|
<fileset dir="${project.basedir}/target/docbkx">
|
||||||
<include name="**/*.html"/>
|
<include name="**/*.html" />
|
||||||
<include name="**/*.pdf"/>
|
<include name="**/*.pdf" />
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
<copy todir="${project.basedir}/target/site/reference/html">
|
<copy todir="${project.basedir}/target/site/reference/html">
|
||||||
<fileset dir="${project.basedir}/src/docbkx/resources">
|
<fileset dir="${project.basedir}/src/docbkx/resources">
|
||||||
<include name="**/*.css"/>
|
<include name="**/*.css" />
|
||||||
<include name="**/*.png"/>
|
<include name="**/*.png" />
|
||||||
<include name="**/*.gif"/>
|
<include name="**/*.gif" />
|
||||||
<include name="**/*.jpg"/>
|
<include name="**/*.jpg" />
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
<copy todir="${project.basedir}/target/site/reference/html">
|
<copy todir="${project.basedir}/target/site/reference/html">
|
||||||
<fileset dir="${project.basedir}/src/docbkx/resources/images">
|
<fileset dir="${project.basedir}/src/docbkx/resources/images">
|
||||||
<include name="*.png"/>
|
<include name="*.png" />
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
<move file="${project.basedir}/target/site/reference/pdf/index.pdf"
|
<move file="${project.basedir}/target/site/reference/pdf/index.pdf" tofile="${project.basedir}/target/site/reference/pdf/spring-data-mongo-reference.pdf" failonerror="false" />
|
||||||
tofile="${project.basedir}/target/site/reference/pdf/spring-data-document-reference.pdf"
|
|
||||||
failonerror="false"/>
|
|
||||||
</postProcess>
|
</postProcess>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
@@ -185,7 +181,7 @@
|
|||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>2.5</version>
|
<version>2.5</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<javadoc:aggregate>true</javadoc:aggregate>
|
<aggregate>true</aggregate>
|
||||||
<breakiterator>true</breakiterator>
|
<breakiterator>true</breakiterator>
|
||||||
<header>Spring Data Document</header>
|
<header>Spring Data Document</header>
|
||||||
<source>1.5</source>
|
<source>1.5</source>
|
||||||
@@ -235,7 +231,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<tasks>
|
<tasks>
|
||||||
<ant antfile="${basedir}/src/ant/upload-dist.xml">
|
<ant antfile="${basedir}/src/ant/upload-dist.xml">
|
||||||
<target name="upload-dist"/>
|
<target name="upload-dist" />
|
||||||
</ant>
|
</ant>
|
||||||
</tasks>
|
</tasks>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -258,22 +254,16 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
<!-- the name of this project is 'spring-data-document-dist';
|
<!-- the name of this project is 'spring-data-mongo-dist';
|
||||||
make sure the zip file is just 'spring-data-document'. -->
|
make sure the zip file is just 'spring-data-mongo'. -->
|
||||||
<finalName>${dist.finalName}</finalName>
|
<finalName>${dist.finalName}</finalName>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
|
<!-- Necessary for the build extension -->
|
||||||
<pluginRepository>
|
<pluginRepository>
|
||||||
<!-- necessary for bundlor and utils -->
|
<id>spring-plugins-release</id>
|
||||||
<id>repository.plugin.springsource.release</id>
|
<url>http://repo.springsource.org/plugins-release</url>
|
||||||
<name>SpringSource Maven Repository</name>
|
|
||||||
<url>http://repository.springsource.com/maven/bundles/release</url>
|
|
||||||
</pluginRepository>
|
|
||||||
<pluginRepository>
|
|
||||||
<id>repository.springframework.maven.release</id>
|
|
||||||
<name>Spring Framework Maven Release Repository</name>
|
|
||||||
<url>http://maven.springframework.org/release</url>
|
|
||||||
</pluginRepository>
|
</pluginRepository>
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
@@ -283,7 +273,7 @@
|
|||||||
<site>
|
<site>
|
||||||
<id>static.springframework.org</id>
|
<id>static.springframework.org</id>
|
||||||
<url>
|
<url>
|
||||||
scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/data-document/snapshot-site/
|
scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/data-mongodb/snapshot-site
|
||||||
</url>
|
</url>
|
||||||
</site>
|
</site>
|
||||||
<repository>
|
<repository>
|
||||||
|
|||||||
@@ -1,156 +0,0 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-document-parent</artifactId>
|
|
||||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
|
||||||
<relativePath>../spring-data-document-parent/pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
<artifactId>spring-data-couchdb</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
<name>Spring Data CouchDB Support</name>
|
|
||||||
|
|
||||||
<licenses>
|
|
||||||
<license>
|
|
||||||
<name>The Apache Software License, Version 2.0</name>
|
|
||||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
|
||||||
<distribution>repo</distribution>
|
|
||||||
</license>
|
|
||||||
</licenses>
|
|
||||||
|
|
||||||
<developers>
|
|
||||||
<developer>
|
|
||||||
<id>tareq.abedrabbo</id>
|
|
||||||
<name>Tareq Abedrabbo</name>
|
|
||||||
<email>tareq.abedrabbo@opencredo.com</email>
|
|
||||||
<organization>OpenCredo</organization>
|
|
||||||
<organizationUrl>http://www.opencredo.org</organizationUrl>
|
|
||||||
<roles>
|
|
||||||
<role>Project Admin</role>
|
|
||||||
<role>Developer</role>
|
|
||||||
</roles>
|
|
||||||
<timezone>+0</timezone>
|
|
||||||
</developer>
|
|
||||||
<developer>
|
|
||||||
<id>tomas.lukosius</id>
|
|
||||||
<name>Tomas Lukosius</name>
|
|
||||||
<email>tomas.lukosius@opencredo.com</email>
|
|
||||||
<organization>OpenCredo</organization>
|
|
||||||
<organizationUrl>http://www.opencredo.org</organizationUrl>
|
|
||||||
<roles>
|
|
||||||
<role>Project Admin</role>
|
|
||||||
<role>Developer</role>
|
|
||||||
</roles>
|
|
||||||
<timezone>+0</timezone>
|
|
||||||
</developer>
|
|
||||||
</developers>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<!-- Spring -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-beans</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-tx</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Spring Data -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-commons-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Dependencies for web analytics functionality - to me moved into spring framework -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>servlet-api</artifactId>
|
|
||||||
<version>2.5</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-core</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-web</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-webmvc</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Jackson JSON -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
|
||||||
<artifactId>jackson-core-asl</artifactId>
|
|
||||||
<version>1.6.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
|
||||||
<artifactId>jackson-mapper-asl</artifactId>
|
|
||||||
<version>1.6.1</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.annotation</groupId>
|
|
||||||
<artifactId>jsr250-api</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-all</artifactId>
|
|
||||||
<version>1.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-all</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Couch DB -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.code.jcouchdb</groupId>
|
|
||||||
<artifactId>jcouchdb</artifactId>
|
|
||||||
<version>0.11.0-1</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.springsource.bundlor</groupId>
|
|
||||||
<artifactId>com.springsource.bundlor.maven</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb;
|
|
||||||
|
|
||||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
|
||||||
import org.springframework.web.client.HttpServerErrorException;
|
|
||||||
|
|
||||||
public class CouchServerResourceUsageException extends InvalidDataAccessResourceUsageException {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new CouchServerResourceUsageException,
|
|
||||||
* wrapping an arbitrary HttpServerErrorException.
|
|
||||||
*
|
|
||||||
* @param cause the HttpServerErrorException thrown
|
|
||||||
*/
|
|
||||||
public CouchServerResourceUsageException(HttpServerErrorException cause) {
|
|
||||||
super(cause != null ? cause.getMessage() : null, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb;
|
|
||||||
|
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
|
||||||
|
|
||||||
public class CouchUsageException extends InvalidDataAccessApiUsageException {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new CouchUsageException,
|
|
||||||
* wrapping an arbitrary HttpServerErrorException.
|
|
||||||
*
|
|
||||||
* @param cause the HttpServerErrorException thrown
|
|
||||||
*/
|
|
||||||
public CouchUsageException(HttpClientErrorException cause) {
|
|
||||||
super(cause != null ? cause.getMessage() : null, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb;
|
|
||||||
|
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
|
||||||
import org.springframework.web.client.HttpStatusCodeException;
|
|
||||||
|
|
||||||
public class DocumentExistsException extends DataIntegrityViolationException {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new DocumentExistsException,
|
|
||||||
* wrapping an arbitrary HttpServerErrorException.
|
|
||||||
*
|
|
||||||
* @param cause the HttpServerErrorException thrown
|
|
||||||
*/
|
|
||||||
public DocumentExistsException(String documentId, HttpStatusCodeException cause) {
|
|
||||||
super(cause != null ? cause.getMessage() : null, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb;
|
|
||||||
|
|
||||||
import org.springframework.dao.UncategorizedDataAccessException;
|
|
||||||
import org.springframework.web.client.RestClientException;
|
|
||||||
|
|
||||||
public class UncategorizedCouchDataAccessException extends UncategorizedDataAccessException {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new HibernateSystemException,
|
|
||||||
* wrapping an arbitrary HibernateException.
|
|
||||||
*
|
|
||||||
* @param cause the HibernateException thrown
|
|
||||||
*/
|
|
||||||
public UncategorizedCouchDataAccessException(RestClientException cause) {
|
|
||||||
super(cause != null ? cause.getMessage() : null, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb.admin;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.data.document.couchdb.support.CouchUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.client.RestOperations;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
public class CouchAdmin implements CouchAdminOperations {
|
|
||||||
|
|
||||||
private String databaseUrl;
|
|
||||||
private RestOperations restOperations = new RestTemplate();
|
|
||||||
|
|
||||||
public CouchAdmin(String databaseUrl) {
|
|
||||||
|
|
||||||
if (!databaseUrl.trim().endsWith("/")) {
|
|
||||||
this.databaseUrl = databaseUrl.trim() + "/";
|
|
||||||
} else {
|
|
||||||
this.databaseUrl = databaseUrl.trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> listDatabases() {
|
|
||||||
String dbs = restOperations.getForObject(databaseUrl + "_all_dbs", String.class);
|
|
||||||
return Arrays.asList(StringUtils.commaDelimitedListToStringArray(dbs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createDatabase(String dbName) {
|
|
||||||
org.springframework.util.Assert.hasText(dbName);
|
|
||||||
restOperations.put(databaseUrl + dbName, null);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteDatabase(String dbName) {
|
|
||||||
org.springframework.util.Assert.hasText(dbName);
|
|
||||||
restOperations.delete(CouchUtils.ensureTrailingSlash(databaseUrl + dbName));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public DbInfo getDatabaseInfo(String dbName) {
|
|
||||||
String url = CouchUtils.ensureTrailingSlash(databaseUrl + dbName);
|
|
||||||
Map dbInfoMap = (Map) restOperations.getForObject(url, Map.class);
|
|
||||||
return new DbInfo(dbInfoMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb.admin;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface CouchAdminOperations {
|
|
||||||
|
|
||||||
|
|
||||||
// functionality for /_special - replication, logs, UUIDs
|
|
||||||
|
|
||||||
List<String> listDatabases();
|
|
||||||
|
|
||||||
void createDatabase(String name);
|
|
||||||
|
|
||||||
void deleteDatabase(String name);
|
|
||||||
|
|
||||||
DbInfo getDatabaseInfo(String name);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.couchdb.admin;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class DbInfo {
|
|
||||||
|
|
||||||
private Map dbInfoMap;
|
|
||||||
|
|
||||||
public DbInfo(Map dbInfoMap) {
|
|
||||||
super();
|
|
||||||
this.dbInfoMap = dbInfoMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCompactRunning() {
|
|
||||||
return (Boolean) this.dbInfoMap.get("compact_running");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDbName() {
|
|
||||||
return (String) this.dbInfoMap.get("db_name");
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDiskFormatVersion() {
|
|
||||||
return (Long) this.dbInfoMap.get("disk_format_version");
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDiskSize() {
|
|
||||||
return (Long) this.dbInfoMap.get("disk_size");
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDocCount() {
|
|
||||||
return (Long) this.dbInfoMap.get("doc_count");
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDocDeleteCount() {
|
|
||||||
return (Long) this.dbInfoMap.get("doc_del_count");
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getInstanceStartTime() {
|
|
||||||
return (Long) this.dbInfoMap.get("instance_start_time");
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getPurgeSequence() {
|
|
||||||
return (Long) this.dbInfoMap.get("purge_seq");
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getUpdateSequence() {
|
|
||||||
return (Long) this.dbInfoMap.get("update_seq");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map getDbInfoMap() {
|
|
||||||
return Collections.unmodifiableMap(dbInfoMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
|
||||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
|
||||||
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
|
||||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
|
||||||
import org.springframework.data.document.couchdb.monitor.ServerInfo;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
public class CouchJmxParser implements BeanDefinitionParser {
|
|
||||||
|
|
||||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
|
||||||
String databaseUrl = element.getAttribute("database-url");
|
|
||||||
if (!StringUtils.hasText(databaseUrl)) {
|
|
||||||
databaseUrl = "http://localhost:5984";
|
|
||||||
}
|
|
||||||
registerJmxComponents(databaseUrl, element, parserContext);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void registerJmxComponents(String databaseUrl, Element element, ParserContext parserContext) {
|
|
||||||
Object eleSource = parserContext.extractSource(element);
|
|
||||||
|
|
||||||
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
|
|
||||||
|
|
||||||
/*
|
|
||||||
createBeanDefEntry(AssertMetrics.class, compositeDef, mongoRefName, eleSource, parserContext);
|
|
||||||
createBeanDefEntry(BackgroundFlushingMetrics.class, compositeDef, mongoRefName, eleSource, parserContext);
|
|
||||||
createBeanDefEntry(BtreeIndexCounters.class, compositeDef, mongoRefName, eleSource, parserContext);
|
|
||||||
createBeanDefEntry(ConnectionMetrics.class, compositeDef, mongoRefName, eleSource, parserContext);
|
|
||||||
createBeanDefEntry(GlobalLockMetrics.class, compositeDef, mongoRefName, eleSource, parserContext);
|
|
||||||
createBeanDefEntry(MemoryMetrics.class, compositeDef, mongoRefName, eleSource, parserContext);
|
|
||||||
createBeanDefEntry(OperationCounters.class, compositeDef, mongoRefName, eleSource, parserContext);
|
|
||||||
*/
|
|
||||||
createBeanDefEntry(ServerInfo.class, compositeDef, databaseUrl, eleSource, parserContext);
|
|
||||||
//createBeanDefEntry(MongoAdmin.class, compositeDef, mongoRefName, eleSource, parserContext);
|
|
||||||
|
|
||||||
|
|
||||||
parserContext.registerComponent(compositeDef);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void createBeanDefEntry(Class clazz, CompositeComponentDefinition compositeDef, String databaseUrl, Object eleSource, ParserContext parserContext) {
|
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(clazz);
|
|
||||||
builder.getRawBeanDefinition().setSource(eleSource);
|
|
||||||
builder.addConstructorArg(databaseUrl);
|
|
||||||
BeanDefinition assertDef = builder.getBeanDefinition();
|
|
||||||
String assertName = parserContext.getReaderContext().registerWithGeneratedName(assertDef);
|
|
||||||
compositeDef.addNestedComponent(new BeanComponentDefinition(assertDef, assertName));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb.core;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
|
|
||||||
public interface CouchOperations {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads a document from the database and maps it a Java object.
|
|
||||||
* </p>
|
|
||||||
* This method is intended to work when a default database
|
|
||||||
* is set on the CouchDbDocumentOperations instance.
|
|
||||||
*
|
|
||||||
* @param id the id of the CouchDB document to read
|
|
||||||
* @param targetClass the target type to map to
|
|
||||||
* @return the mapped object
|
|
||||||
*/
|
|
||||||
<T> T findOne(String id, Class<T> targetClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads a document from the database and maps it a Java object.
|
|
||||||
*
|
|
||||||
* @param uri the full URI of the document to read
|
|
||||||
* @param targetClass the target type to map to
|
|
||||||
* @return the mapped object
|
|
||||||
*/
|
|
||||||
<T> T findOne(URI uri, Class<T> targetClass);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps a Java object to JSON and writes it to the database
|
|
||||||
* </p>
|
|
||||||
* This method is intended to work when a default database
|
|
||||||
* is set on the CouchDbDocumentOperations instance.
|
|
||||||
*
|
|
||||||
* @param id the id of the document to write
|
|
||||||
* @param document the object to write
|
|
||||||
*/
|
|
||||||
void save(String id, Object document);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps a Java object to JSON and writes it to the database
|
|
||||||
*
|
|
||||||
* @param uri the full URI of the document to write
|
|
||||||
* @param document the object to write
|
|
||||||
*/
|
|
||||||
void save(URI uri, Object document);
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.couchdb.core;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.data.document.couchdb.CouchServerResourceUsageException;
|
|
||||||
import org.springframework.data.document.couchdb.CouchUsageException;
|
|
||||||
import org.springframework.data.document.couchdb.DocumentRetrievalFailureException;
|
|
||||||
import org.springframework.data.document.couchdb.UncategorizedCouchDataAccessException;
|
|
||||||
import org.springframework.data.document.couchdb.support.CouchUtils;
|
|
||||||
import org.springframework.http.*;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.web.client.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class CouchTemplate implements CouchOperations {
|
|
||||||
|
|
||||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
|
||||||
|
|
||||||
private String defaultDocumentUrl;
|
|
||||||
|
|
||||||
private RestOperations restOperations = new RestTemplate();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs an instance of CouchDbDocumentTemplate with a default database
|
|
||||||
*
|
|
||||||
* @param defaultDatabaseUrl the default database to connect to
|
|
||||||
*/
|
|
||||||
public CouchTemplate(String defaultDatabaseUrl) {
|
|
||||||
Assert.hasText(defaultDatabaseUrl, "defaultDatabaseUrl must not be empty");
|
|
||||||
defaultDocumentUrl = CouchUtils.addId(defaultDatabaseUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs an instance of CouchDbDocumentTemplate with a default database
|
|
||||||
*
|
|
||||||
* @param defaultDatabaseUrl the default database to connect to
|
|
||||||
*/
|
|
||||||
public CouchTemplate(String defaultDatabaseUrl, RestOperations restOperations) {
|
|
||||||
this(defaultDatabaseUrl);
|
|
||||||
Assert.notNull(restOperations, "restOperations must not be null");
|
|
||||||
this.restOperations = restOperations;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public <T> T findOne(String id, Class<T> targetClass) {
|
|
||||||
Assert.state(defaultDocumentUrl != null, "defaultDatabaseUrl must be set to use this method");
|
|
||||||
try {
|
|
||||||
return restOperations.getForObject(defaultDocumentUrl, targetClass, id);
|
|
||||||
//TODO check this exception translation and centralize.
|
|
||||||
} catch (HttpClientErrorException clientError) {
|
|
||||||
if (clientError.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
||||||
throw new DocumentRetrievalFailureException(defaultDocumentUrl + "/" + id);
|
|
||||||
}
|
|
||||||
throw new CouchUsageException(clientError);
|
|
||||||
} catch (HttpServerErrorException serverError) {
|
|
||||||
throw new CouchServerResourceUsageException(serverError);
|
|
||||||
} catch (RestClientException otherError) {
|
|
||||||
throw new UncategorizedCouchDataAccessException(otherError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T findOne(URI uri, Class<T> targetClass) {
|
|
||||||
Assert.state(uri != null, "uri must be set to use this method");
|
|
||||||
try {
|
|
||||||
return restOperations.getForObject(uri, targetClass);
|
|
||||||
//TODO check this exception translation and centralize.
|
|
||||||
} catch (HttpClientErrorException clientError) {
|
|
||||||
if (clientError.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
||||||
throw new DocumentRetrievalFailureException(uri.getPath());
|
|
||||||
}
|
|
||||||
throw new CouchUsageException(clientError);
|
|
||||||
} catch (HttpServerErrorException serverError) {
|
|
||||||
throw new CouchServerResourceUsageException(serverError);
|
|
||||||
} catch (RestClientException otherError) {
|
|
||||||
throw new UncategorizedCouchDataAccessException(otherError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(String id, Object document) {
|
|
||||||
Assert.notNull(document, "document must not be null for save");
|
|
||||||
HttpEntity<?> httpEntity = createHttpEntity(document);
|
|
||||||
try {
|
|
||||||
ResponseEntity<Map> response = restOperations.exchange(defaultDocumentUrl, HttpMethod.PUT, httpEntity, Map.class, id);
|
|
||||||
//TODO update the document revision id on the object from the returned value
|
|
||||||
//TODO better exception translation
|
|
||||||
} catch (RestClientException e) {
|
|
||||||
throw new UncategorizedCouchDataAccessException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(URI uri, Object document) {
|
|
||||||
Assert.notNull(document, "document must not be null for save");
|
|
||||||
Assert.notNull(uri, "URI must not be null for save");
|
|
||||||
HttpEntity<?> httpEntity = createHttpEntity(document);
|
|
||||||
try {
|
|
||||||
ResponseEntity<Map> response = restOperations.exchange(uri, HttpMethod.PUT, httpEntity, Map.class);
|
|
||||||
//TODO update the document revision id on the object from the returned value
|
|
||||||
//TODO better exception translation
|
|
||||||
} catch (RestClientException e) {
|
|
||||||
throw new UncategorizedCouchDataAccessException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private HttpEntity<?> createHttpEntity(Object document) {
|
|
||||||
|
|
||||||
if (document instanceof HttpEntity) {
|
|
||||||
HttpEntity httpEntity = (HttpEntity) document;
|
|
||||||
Assert.isTrue(httpEntity.getHeaders().getContentType().equals(MediaType.APPLICATION_JSON),
|
|
||||||
"HttpEntity payload with non application/json content type found.");
|
|
||||||
return httpEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpHeaders httpHeaders = new HttpHeaders();
|
|
||||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
HttpEntity<Object> httpEntity = new HttpEntity<Object>(document, httpHeaders);
|
|
||||||
|
|
||||||
return httpEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,315 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb.core.support;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.*;
|
|
||||||
import org.codehaus.jackson.map.JsonMappingException;
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
|
||||||
import org.codehaus.jackson.map.type.TypeFactory;
|
|
||||||
import org.codehaus.jackson.type.JavaType;
|
|
||||||
import org.springframework.http.HttpInputMessage;
|
|
||||||
import org.springframework.http.HttpOutputMessage;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.converter.AbstractHttpMessageConverter;
|
|
||||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
||||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
public class CouchDbMappingJacksonHttpMessageConverter extends
|
|
||||||
AbstractHttpMessageConverter<Object> {
|
|
||||||
|
|
||||||
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
|
||||||
|
|
||||||
private static final String ROWS_FIELD_NAME = "rows";
|
|
||||||
private static final String VALUE_FIELD_NAME = "value";
|
|
||||||
private static final String INCLUDED_DOC_FIELD_NAME = "doc";
|
|
||||||
private static final String TOTAL_ROWS_FIELD_NAME = "total_rows";
|
|
||||||
|
|
||||||
private ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
private boolean prefixJson = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a new {@code BindingJacksonHttpMessageConverter}.
|
|
||||||
*/
|
|
||||||
public CouchDbMappingJacksonHttpMessageConverter() {
|
|
||||||
super(new MediaType("application", "json", DEFAULT_CHARSET));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the {@code ObjectMapper} for this view. If not set, a default
|
|
||||||
* {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
|
|
||||||
* <p/>
|
|
||||||
* Setting a custom-configured {@code ObjectMapper} is one way to take
|
|
||||||
* further control of the JSON serialization process. For example, an
|
|
||||||
* extended {@link org.codehaus.jackson.map.SerializerFactory} can be
|
|
||||||
* configured that provides custom serializers for specific types. The other
|
|
||||||
* option for refining the serialization process is to use Jackson's
|
|
||||||
* provided annotations on the types to be serialized, in which case a
|
|
||||||
* custom-configured ObjectMapper is unnecessary.
|
|
||||||
*/
|
|
||||||
public void setObjectMapper(ObjectMapper objectMapper) {
|
|
||||||
Assert.notNull(objectMapper, "'objectMapper' must not be null");
|
|
||||||
this.objectMapper = objectMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether the JSON output by this view should be prefixed with
|
|
||||||
* "{} &&". Default is false.
|
|
||||||
* <p/>
|
|
||||||
* Prefixing the JSON string in this manner is used to help prevent JSON
|
|
||||||
* Hijacking. The prefix renders the string syntactically invalid as a
|
|
||||||
* script so that it cannot be hijacked. This prefix does not affect the
|
|
||||||
* evaluation of JSON, but if JSON validation is performed on the string,
|
|
||||||
* the prefix would need to be ignored.
|
|
||||||
*/
|
|
||||||
public void setPrefixJson(boolean prefixJson) {
|
|
||||||
this.prefixJson = prefixJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canRead(Class<?> clazz, MediaType mediaType) {
|
|
||||||
JavaType javaType = getJavaType(clazz);
|
|
||||||
return this.objectMapper.canDeserialize(javaType) && canRead(mediaType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the Jackson {@link JavaType} for the specific class.
|
|
||||||
* <p/>
|
|
||||||
* <p/>
|
|
||||||
* Default implementation returns
|
|
||||||
* {@link TypeFactory#type(java.lang.reflect.Type)}, but this can be
|
|
||||||
* overridden in subclasses, to allow for custom generic collection
|
|
||||||
* handling. For instance:
|
|
||||||
* <p/>
|
|
||||||
* <pre class="code">
|
|
||||||
* protected JavaType getJavaType(Class<?> clazz) {
|
|
||||||
* if (List.class.isAssignableFrom(clazz)) {
|
|
||||||
* return TypeFactory.collectionType(ArrayList.class, MyBean.class);
|
|
||||||
* } else {
|
|
||||||
* return super.getJavaType(clazz);
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @param clazz the class to return the java type for
|
|
||||||
* @return the java type
|
|
||||||
*/
|
|
||||||
protected JavaType getJavaType(Class<?> clazz) {
|
|
||||||
return TypeFactory.type(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
|
|
||||||
return this.objectMapper.canSerialize(clazz) && canWrite(mediaType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean supports(Class<?> clazz) {
|
|
||||||
// should not be called, since we override canRead/Write instead
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
|
|
||||||
throws IOException, HttpMessageNotReadableException {
|
|
||||||
JavaType javaType = getJavaType(clazz);
|
|
||||||
try {
|
|
||||||
return success(clazz, inputMessage);
|
|
||||||
|
|
||||||
// return this.objectMapper.readValue(inputMessage.getBody(),
|
|
||||||
// javaType);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new HttpMessageNotReadableException("Could not read JSON: "
|
|
||||||
+ ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object success(Class<?> clazz, HttpInputMessage inputMessage)
|
|
||||||
throws JsonParseException, IOException {
|
|
||||||
|
|
||||||
//Note, parsing code used from ektorp project
|
|
||||||
JsonParser jp = objectMapper.getJsonFactory().createJsonParser(
|
|
||||||
inputMessage.getBody());
|
|
||||||
if (jp.nextToken() != JsonToken.START_OBJECT) {
|
|
||||||
throw new RuntimeException("Expected data to start with an Object");
|
|
||||||
}
|
|
||||||
Map<String, Integer> fields = readHeaderFields(jp);
|
|
||||||
|
|
||||||
List result;
|
|
||||||
if (fields.containsKey(TOTAL_ROWS_FIELD_NAME)) {
|
|
||||||
int totalRows = fields.get(TOTAL_ROWS_FIELD_NAME);
|
|
||||||
if (totalRows == 0) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
result = new ArrayList(totalRows);
|
|
||||||
} else {
|
|
||||||
result = new ArrayList();
|
|
||||||
}
|
|
||||||
|
|
||||||
ParseState state = new ParseState();
|
|
||||||
|
|
||||||
Object first = parseFirstRow(jp, state, clazz);
|
|
||||||
if (first == null) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
} else {
|
|
||||||
result.add(first);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (jp.getCurrentToken() != null) {
|
|
||||||
skipToField(jp, state.docFieldName, state);
|
|
||||||
if (atEndOfRows(jp)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
result.add(jp.readValueAs(clazz));
|
|
||||||
endRow(jp, state);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object parseFirstRow(JsonParser jp, ParseState state, Class clazz)
|
|
||||||
throws JsonParseException, IOException, JsonProcessingException,
|
|
||||||
JsonMappingException {
|
|
||||||
skipToField(jp, VALUE_FIELD_NAME, state);
|
|
||||||
JsonNode value = null;
|
|
||||||
if (atObjectStart(jp)) {
|
|
||||||
value = jp.readValueAsTree();
|
|
||||||
jp.nextToken();
|
|
||||||
if (isEndOfRow(jp)) {
|
|
||||||
state.docFieldName = VALUE_FIELD_NAME;
|
|
||||||
Object doc = objectMapper.readValue(value, clazz);
|
|
||||||
endRow(jp, state);
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
skipToField(jp, INCLUDED_DOC_FIELD_NAME, state);
|
|
||||||
if (atObjectStart(jp)) {
|
|
||||||
state.docFieldName = INCLUDED_DOC_FIELD_NAME;
|
|
||||||
Object doc = jp.readValueAs(clazz);
|
|
||||||
endRow(jp, state);
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isEndOfRow(JsonParser jp) {
|
|
||||||
return jp.getCurrentToken() == JsonToken.END_OBJECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void endRow(JsonParser jp, ParseState state) throws IOException, JsonParseException {
|
|
||||||
state.inRow = false;
|
|
||||||
jp.nextToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean atObjectStart(JsonParser jp) {
|
|
||||||
return jp.getCurrentToken() == JsonToken.START_OBJECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean atEndOfRows(JsonParser jp) {
|
|
||||||
return jp.getCurrentToken() != JsonToken.START_OBJECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void skipToField(JsonParser jp, String fieldName, ParseState state) throws JsonParseException, IOException {
|
|
||||||
String lastFieldName = null;
|
|
||||||
while (jp.getCurrentToken() != null) {
|
|
||||||
switch (jp.getCurrentToken()) {
|
|
||||||
case FIELD_NAME:
|
|
||||||
lastFieldName = jp.getCurrentName();
|
|
||||||
jp.nextToken();
|
|
||||||
break;
|
|
||||||
case START_OBJECT:
|
|
||||||
if (!state.inRow) {
|
|
||||||
state.inRow = true;
|
|
||||||
jp.nextToken();
|
|
||||||
} else {
|
|
||||||
if (isInField(fieldName, lastFieldName)) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
jp.skipChildren();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (isInField(fieldName, lastFieldName)) {
|
|
||||||
jp.nextToken();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
jp.nextToken();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInField(String fieldName, String lastFieldName) {
|
|
||||||
return lastFieldName != null && lastFieldName.equals(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private Map<String, Integer> readHeaderFields(JsonParser jp)
|
|
||||||
throws JsonParseException, IOException {
|
|
||||||
Map<String, Integer> map = new HashMap<String, Integer>();
|
|
||||||
jp.nextToken();
|
|
||||||
String nextFieldName = jp.getCurrentName();
|
|
||||||
while (!nextFieldName.equals(ROWS_FIELD_NAME)) {
|
|
||||||
jp.nextToken();
|
|
||||||
map.put(nextFieldName, Integer.valueOf(jp.getIntValue()));
|
|
||||||
jp.nextToken();
|
|
||||||
nextFieldName = jp.getCurrentName();
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
|
|
||||||
throws IOException, HttpMessageNotWritableException {
|
|
||||||
|
|
||||||
JsonEncoding encoding = getEncoding(outputMessage.getHeaders()
|
|
||||||
.getContentType());
|
|
||||||
JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory()
|
|
||||||
.createJsonGenerator(outputMessage.getBody(), encoding);
|
|
||||||
try {
|
|
||||||
if (this.prefixJson) {
|
|
||||||
jsonGenerator.writeRaw("{} && ");
|
|
||||||
}
|
|
||||||
this.objectMapper.writeValue(jsonGenerator, o);
|
|
||||||
} catch (JsonGenerationException ex) {
|
|
||||||
throw new HttpMessageNotWritableException("Could not write JSON: "
|
|
||||||
+ ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private JsonEncoding getEncoding(MediaType contentType) {
|
|
||||||
if (contentType != null && contentType.getCharSet() != null) {
|
|
||||||
Charset charset = contentType.getCharSet();
|
|
||||||
for (JsonEncoding encoding : JsonEncoding.values()) {
|
|
||||||
if (charset.name().equals(encoding.getJavaName())) {
|
|
||||||
return encoding;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return JsonEncoding.UTF8;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ParseState {
|
|
||||||
boolean inRow;
|
|
||||||
String docFieldName = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2002-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb.monitor;
|
|
||||||
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class to encapsulate common configuration settings when connecting to a CouchDB database
|
|
||||||
*
|
|
||||||
* @author Mark Pollack
|
|
||||||
*/
|
|
||||||
public abstract class AbstractMonitor {
|
|
||||||
|
|
||||||
|
|
||||||
protected RestTemplate restTemplate;
|
|
||||||
protected String databaseUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the databaseUrl used to connect to CouchDB
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getDatabaseUrl() {
|
|
||||||
return this.databaseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2002-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb.monitor;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
|
||||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Expose basic server information via JMX
|
|
||||||
*
|
|
||||||
* @author Mark Pollack
|
|
||||||
*/
|
|
||||||
@ManagedResource(description = "Server Information")
|
|
||||||
public class ServerInfo extends AbstractMonitor {
|
|
||||||
|
|
||||||
|
|
||||||
public ServerInfo(String databaseUrl) {
|
|
||||||
this.databaseUrl = databaseUrl;
|
|
||||||
this.restTemplate = new RestTemplate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ManagedOperation(description = "Server host name")
|
|
||||||
public String getHostName() throws UnknownHostException {
|
|
||||||
return InetAddress.getLocalHost().getHostName();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ManagedOperation(description = "CouchDB Server Version")
|
|
||||||
public String getVersion() {
|
|
||||||
return (String) getRoot().get("version");
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManagedOperation(description = "Message of the day")
|
|
||||||
public String getMotd() {
|
|
||||||
return (String) getRoot().get("greeting");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map getRoot() {
|
|
||||||
Map map = restTemplate.getForObject(getDatabaseUrl(), Map.class);
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
/**
|
|
||||||
* CouchDB specific JMX monitoring support.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb.monitor;
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.couchdb.support;
|
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper class featuring helper methods for internal CouchDB classes.
|
|
||||||
* <p/>
|
|
||||||
* <p>Mainly intended for internal use within the framework.
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Tareq Abedrabbo
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
public abstract class CouchUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the given runtime exception to an appropriate exception from the
|
|
||||||
* <code>org.springframework.dao</code> hierarchy.
|
|
||||||
* Return null if no translation is appropriate: any other exception may
|
|
||||||
* have resulted from user code, and should not be translated.
|
|
||||||
*
|
|
||||||
* @param ex runtime exception that occurred
|
|
||||||
* @return the corresponding DataAccessException instance,
|
|
||||||
* or <code>null</code> if the exception should not be translated
|
|
||||||
*/
|
|
||||||
public static DataAccessException translateCouchExceptionIfPossible(RuntimeException ex) {
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an id variable to a URL
|
|
||||||
*
|
|
||||||
* @param url the URL to modify
|
|
||||||
* @return the modified URL
|
|
||||||
*/
|
|
||||||
public static String addId(String url) {
|
|
||||||
return ensureTrailingSlash(url) + "{id}";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a 'changes since' variable to a URL
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String addChangesSince(String url) {
|
|
||||||
return ensureTrailingSlash(url) + "_changes?since={seq}";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensures that a URL ends with a slash.
|
|
||||||
*
|
|
||||||
* @param url the URL to modify
|
|
||||||
* @return the modified URL
|
|
||||||
*/
|
|
||||||
public static String ensureTrailingSlash(String url) {
|
|
||||||
if (!url.endsWith("/")) {
|
|
||||||
url += "/";
|
|
||||||
}
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
http\://www.springframework.org/schema/data/couch=org.springframework.data.document.couchdb.config.CouchNamespaceHandler
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
http\://www.springframework.org/schema/data/couch/spring-couch-1.0.xsd=org/springframework/data/document/couchdb/config/spring-couch-1.0.xsd
|
|
||||||
http\://www.springframework.org/schema/data/couch/spring-couch.xsd=org/springframework/data/document/couchdb/config/spring-couch-1.0.xsd
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# Tooling related information for the Couch DB namespace
|
|
||||||
http\://www.springframework.org/schema/data/couch@name=Couch Namespace
|
|
||||||
http\://www.springframework.org/schema/data/couch@prefix=couch
|
|
||||||
http\://www.springframework.org/schema/data/couch@icon=org/springframework/jdbc/config/spring-jdbc.gif
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<xsd:schema xmlns="http://www.springframework.org/schema/data/couch"
|
|
||||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
||||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xmlns:repository="http://www.springframework.org/schema/data/repository"
|
|
||||||
targetNamespace="http://www.springframework.org/schema/data/couch"
|
|
||||||
elementFormDefault="qualified" attributeFormDefault="unqualified">
|
|
||||||
|
|
||||||
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
|
|
||||||
<xsd:import namespace="http://www.springframework.org/schema/context"
|
|
||||||
schemaLocation="http://www.springframework.org/schema/context/spring-context.xsd"/>
|
|
||||||
<xsd:import namespace="http://www.springframework.org/schema/data/repository"
|
|
||||||
schemaLocation="http://www.springframework.org/schema/data/repository/spring-repository.xsd"/>
|
|
||||||
|
|
||||||
|
|
||||||
<xsd:element name="jmx">
|
|
||||||
<xsd:annotation>
|
|
||||||
<xsd:documentation><![CDATA[
|
|
||||||
Defines a JMX Model MBeans for monitoring a CouchDB server'.
|
|
||||||
]]></xsd:documentation>
|
|
||||||
</xsd:annotation>
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="database-url" type="xsd:string" use="optional">
|
|
||||||
<xsd:annotation>
|
|
||||||
<xsd:documentation><![CDATA[
|
|
||||||
The database URL of the CouchDB]]></xsd:documentation>
|
|
||||||
</xsd:annotation>
|
|
||||||
</xsd:attribute>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
|
|
||||||
</xsd:schema>
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.couchdb;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Tareq Abedrabbo (tareq.abedrabbo@opencredo.com)
|
|
||||||
* @since 13/01/2011
|
|
||||||
*/
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class DummyDocument {
|
|
||||||
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
private String timestamp = new Date().toString();
|
|
||||||
|
|
||||||
public DummyDocument() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public DummyDocument(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessage(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
|
|
||||||
DummyDocument document = (DummyDocument) o;
|
|
||||||
|
|
||||||
if (message != null ? !message.equals(document.message) : document.message != null) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return message != null ? message.hashCode() : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "DummyDocument{" +
|
|
||||||
"message='" + message + '\'' +
|
|
||||||
", timestamp=" + timestamp +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.couchdb;
|
|
||||||
|
|
||||||
import org.hamcrest.Description;
|
|
||||||
import org.hamcrest.Factory;
|
|
||||||
import org.hamcrest.Matcher;
|
|
||||||
import org.hamcrest.TypeSafeMatcher;
|
|
||||||
import org.springframework.http.HttpEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Matches the content of the body of an HttpEntity.
|
|
||||||
*
|
|
||||||
* @author Tareq Abedrabbo
|
|
||||||
* @since 31/01/2011
|
|
||||||
*/
|
|
||||||
public class IsBodyEqual extends TypeSafeMatcher<HttpEntity> {
|
|
||||||
|
|
||||||
private Object object;
|
|
||||||
|
|
||||||
public IsBodyEqual(Object object) {
|
|
||||||
this.object = object;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matchesSafely(HttpEntity httpEntity) {
|
|
||||||
return httpEntity.getBody().equals(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void describeTo(Description description) {
|
|
||||||
description.appendText("body equals ").appendValue(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Factory
|
|
||||||
public static Matcher<HttpEntity> bodyEqual(Object object) {
|
|
||||||
return new IsBodyEqual(object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb.admin;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.data.document.couchdb.core.CouchConstants;
|
|
||||||
|
|
||||||
public class CouchAdminIntegrationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Ignore("until CI has couch server running")
|
|
||||||
public void dbLifecycle() {
|
|
||||||
|
|
||||||
CouchAdmin admin = new CouchAdmin(CouchConstants.COUCHDB_URL);
|
|
||||||
admin.deleteDatabase("foo");
|
|
||||||
List<String> dbs = admin.listDatabases();
|
|
||||||
admin.createDatabase("foo");
|
|
||||||
List<String> newDbs = admin.listDatabases();
|
|
||||||
Assert.assertEquals(dbs.size() + 1, newDbs.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.couchdb.core;
|
|
||||||
|
|
||||||
import static org.junit.Assume.assumeNoException;
|
|
||||||
import static org.junit.Assume.assumeTrue;
|
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.springframework.http.*;
|
|
||||||
import org.springframework.http.client.ClientHttpResponse;
|
|
||||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
|
||||||
import org.springframework.web.client.RestClientException;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for CouchDB integration tests. Checks whether CouchDB is available before running each test,
|
|
||||||
* in which case the test is executed. If CouchDB is not available, tests are ignored.
|
|
||||||
*
|
|
||||||
* @author Tareq Abedrabbo (tareq.abedrabbo@opencredo.com)
|
|
||||||
* @since 13/01/2011
|
|
||||||
*/
|
|
||||||
|
|
||||||
public abstract class AbstractCouchTemplateIntegrationTests {
|
|
||||||
|
|
||||||
|
|
||||||
protected static final Log log = LogFactory.getLog(AbstractCouchTemplateIntegrationTests.class);
|
|
||||||
|
|
||||||
protected static final RestTemplate restTemplate = new RestTemplate();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This methods ensures that the database is running. Otherwise, the test is ignored.
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void assumeDatabaseIsUpAndRunning() {
|
|
||||||
try {
|
|
||||||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(CouchConstants.COUCHDB_URL, String.class);
|
|
||||||
assumeTrue(responseEntity.getStatusCode().equals(OK));
|
|
||||||
log.debug("CouchDB is running on " + CouchConstants.COUCHDB_URL +
|
|
||||||
" with status " + responseEntity.getStatusCode());
|
|
||||||
} catch (RestClientException e) {
|
|
||||||
log.debug("CouchDB is not running on " + CouchConstants.COUCHDB_URL);
|
|
||||||
assumeNoException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUpTestDatabase() throws Exception {
|
|
||||||
RestTemplate template = new RestTemplate();
|
|
||||||
template.setErrorHandler(new DefaultResponseErrorHandler() {
|
|
||||||
@Override
|
|
||||||
public void handleError(ClientHttpResponse response) throws IOException {
|
|
||||||
// do nothing, error status will be handled in the switch statement
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ResponseEntity<String> response = template.getForEntity(CouchConstants.TEST_DATABASE_URL, String.class);
|
|
||||||
HttpStatus statusCode = response.getStatusCode();
|
|
||||||
switch (statusCode) {
|
|
||||||
case NOT_FOUND:
|
|
||||||
createNewTestDatabase();
|
|
||||||
break;
|
|
||||||
case OK:
|
|
||||||
deleteExisitingTestDatabase();
|
|
||||||
createNewTestDatabase();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unsupported http status [" + statusCode + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteExisitingTestDatabase() {
|
|
||||||
restTemplate.delete(CouchConstants.TEST_DATABASE_URL);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createNewTestDatabase() {
|
|
||||||
restTemplate.put(CouchConstants.TEST_DATABASE_URL, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads a CouchDB document and converts it to the expected type.
|
|
||||||
*/
|
|
||||||
protected <T> T getDocument(String id, Class<T> expectedType) {
|
|
||||||
String url = CouchConstants.TEST_DATABASE_URL + "{id}";
|
|
||||||
return restTemplate.getForObject(url, expectedType, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a CouchDB document
|
|
||||||
*/
|
|
||||||
protected String putDocument(Object document) {
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
HttpEntity request = new HttpEntity(document, headers);
|
|
||||||
String id = UUID.randomUUID().toString();
|
|
||||||
restTemplate.put(CouchConstants.TEST_DATABASE_URL + "{id}", request, id);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.couchdb.core;
|
|
||||||
|
|
||||||
public abstract class CouchConstants {
|
|
||||||
|
|
||||||
public static final String COUCHDB_URL = "http://127.0.0.1:5984/";
|
|
||||||
public static final String TEST_DATABASE_URL = COUCHDB_URL + "si_couchdb_test/";
|
|
||||||
|
|
||||||
public CouchConstants() {
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.couchdb.core;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.data.document.couchdb.DummyDocument;
|
|
||||||
|
|
||||||
public class CouchTemplateIntegrationTests extends AbstractCouchTemplateIntegrationTests {
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Ignore("until CI has couch server running")
|
|
||||||
public void saveAndFindTest() {
|
|
||||||
CouchTemplate template = new CouchTemplate(CouchConstants.TEST_DATABASE_URL);
|
|
||||||
DummyDocument document = new DummyDocument("hello");
|
|
||||||
String id = UUID.randomUUID().toString();
|
|
||||||
template.save(id, document);
|
|
||||||
DummyDocument foundDocument = template.findOne(id, DummyDocument.class);
|
|
||||||
Assert.assertEquals(document.getMessage(), foundDocument.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
log4j.rootCategory=INFO, stdout
|
|
||||||
|
|
||||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
|
|
||||||
|
|
||||||
log4j.category.org.apache.activemq=ERROR
|
|
||||||
log4j.category.org.springframework.batch=DEBUG
|
|
||||||
log4j.category.org.springframework.transaction=INFO
|
|
||||||
|
|
||||||
log4j.category.org.hibernate.SQL=DEBUG
|
|
||||||
# for debugging datasource initialization
|
|
||||||
# log4j.category.test.jdbc=DEBUG
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xmlns:p="http://www.springframework.org/schema/p"
|
|
||||||
xmlns:couch="http://www.springframework.org/schema/data/couch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
|
||||||
http://www.springframework.org/schema/data/couch http://www.springframework.org/schema/data/couch/spring-couch-1.0.xsd
|
|
||||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
|
||||||
|
|
||||||
|
|
||||||
<couch:jmx/>
|
|
||||||
|
|
||||||
<context:mbean-export/>
|
|
||||||
|
|
||||||
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean"
|
|
||||||
p:port="1099"/>
|
|
||||||
|
|
||||||
<!-- Expose JMX over RMI -->
|
|
||||||
<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean" depends-on="registry"
|
|
||||||
p:objectName="connector:name=rmi"
|
|
||||||
p:serviceUrl="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/myconnector"/>
|
|
||||||
|
|
||||||
</beans>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
Bundle-SymbolicName: org.springframework.data.couchdb
|
|
||||||
Bundle-Name: Spring Data Couch DB Support
|
|
||||||
Bundle-Vendor: SpringSource
|
|
||||||
Bundle-ManifestVersion: 2
|
|
||||||
Import-Package:
|
|
||||||
sun.reflect;version="0";resolution:=optional
|
|
||||||
Import-Template:
|
|
||||||
org.springframework.beans.*;version="[3.0.0, 4.0.0)",
|
|
||||||
org.springframework.core.*;version="[3.0.0, 4.0.0)",
|
|
||||||
org.springframework.dao.*;version="[3.0.0, 4.0.0)",
|
|
||||||
org.springframework.http.*;version="[3.0.0, 4.0.0)",
|
|
||||||
org.springframework.web.*;version="[3.0.0, 4.0.0)",
|
|
||||||
org.springframework.util.*;version="[3.0.0, 4.0.0)",
|
|
||||||
org.springframework.context.*;version="[3.0.0, 4.0.0)",
|
|
||||||
org.springframework.jmx.*;version="[3.0.0, 4.0.0)",
|
|
||||||
org.springframework.remoting.*;version="[3.0.0, 4.0.0)",
|
|
||||||
org.springframework.data.core.*;version="[1.0.0, 2.0.0)",
|
|
||||||
org.springframework.data.document.*;version="[1.0.0, 2.0.0)",
|
|
||||||
org.codehaus.jackson.*;version="[1.0.0, 2.0.0)";resolution:=optional,
|
|
||||||
org.aopalliance.*;version="[1.0.0, 2.0.0)";resolution:=optional,
|
|
||||||
org.apache.commons.logging.*;version="[1.1.1, 2.0.0)",
|
|
||||||
org.w3c.dom.*;version="0"
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,415 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-document-parent</artifactId>
|
|
||||||
<name>Spring Data Document Parent</name>
|
|
||||||
<url>http://www.springsource.org/spring-data/data-document</url>
|
|
||||||
<version>1.0.0.M3</version>
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<!-- versions for commonly-used dependencies -->
|
|
||||||
<junit.version>4.8.1</junit.version>
|
|
||||||
<log4j.version>1.2.15</log4j.version>
|
|
||||||
<org.mockito.version>1.8.4</org.mockito.version>
|
|
||||||
<org.slf4j.version>1.5.10</org.slf4j.version>
|
|
||||||
<org.codehaus.jackson.version>1.6.1</org.codehaus.jackson.version>
|
|
||||||
<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
|
|
||||||
<data.commons.version>1.1.0.M1</data.commons.version>
|
|
||||||
<aspectj.version>1.6.11.RELEASE</aspectj.version>
|
|
||||||
</properties>
|
|
||||||
<profiles>
|
|
||||||
<profile>
|
|
||||||
<id>strict</id>
|
|
||||||
<properties>
|
|
||||||
<maven.test.failure.ignore>false</maven.test.failure.ignore>
|
|
||||||
</properties>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>fast</id>
|
|
||||||
<properties>
|
|
||||||
<maven.test.skip>true</maven.test.skip>
|
|
||||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
|
||||||
</properties>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>staging</id>
|
|
||||||
<distributionManagement>
|
|
||||||
<site>
|
|
||||||
<id>spring-site-staging</id>
|
|
||||||
<url>file:///${java.io.tmpdir}/spring-data/data-document/docs</url>
|
|
||||||
</site>
|
|
||||||
<repository>
|
|
||||||
<id>spring-milestone-staging</id>
|
|
||||||
<url>file:///${java.io.tmpdir}/spring-data/data-document/milestone</url>
|
|
||||||
</repository>
|
|
||||||
<snapshotRepository>
|
|
||||||
<id>spring-snapshot-staging</id>
|
|
||||||
<url>file:///${java.io.tmpdir}/spring-data/data-document/snapshot</url>
|
|
||||||
</snapshotRepository>
|
|
||||||
</distributionManagement>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>bootstrap</id>
|
|
||||||
<!-- TODO: move the repositories in here before release -->
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
<distributionManagement>
|
|
||||||
<!-- see 'staging' profile for dry-run deployment settings -->
|
|
||||||
<downloadUrl>http://www.springsource.com/download/community
|
|
||||||
</downloadUrl>
|
|
||||||
<site>
|
|
||||||
<id>static.springframework.org</id>
|
|
||||||
<url>
|
|
||||||
scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/data-document/docs/${project.version}
|
|
||||||
</url>
|
|
||||||
</site>
|
|
||||||
<repository>
|
|
||||||
<id>spring-milestone</id>
|
|
||||||
<name>Spring Milestone Repository</name>
|
|
||||||
<url>s3://maven.springframework.org/milestone</url>
|
|
||||||
</repository>
|
|
||||||
<snapshotRepository>
|
|
||||||
<id>spring-snapshot</id>
|
|
||||||
<name>Spring Snapshot Repository</name>
|
|
||||||
<url>s3://maven.springframework.org/snapshot</url>
|
|
||||||
</snapshotRepository>
|
|
||||||
</distributionManagement>
|
|
||||||
<dependencyManagement>
|
|
||||||
<!--
|
|
||||||
inheritable <dependency> declarations for child poms. children still
|
|
||||||
must explicitly declare the groupId/artifactId of these dependencies
|
|
||||||
in order for them to show up on the classpath, but metadata like
|
|
||||||
<version> and <scope> are inherited, which cuts down on verbosity.
|
|
||||||
see
|
|
||||||
http://www.sonatype.com/books/mvnref-book/reference/pom-relationships-sect-dep-manage.html
|
|
||||||
-->
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<!-- Spring -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-aop</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-beans</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-core</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-tx</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-orm</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-web</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-expression</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-test</artifactId>
|
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Spring Data -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-commons-core</artifactId>
|
|
||||||
<version>${data.commons.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-commons-aspects</artifactId>
|
|
||||||
<version>${data.commons.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-couchdb</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-mongodb</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Logging -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<version>${log4j.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.mail</groupId>
|
|
||||||
<artifactId>mail</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.jms</groupId>
|
|
||||||
<artifactId>jms</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jdmk</groupId>
|
|
||||||
<artifactId>jmxtools</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jmx</groupId>
|
|
||||||
<artifactId>jmxri</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.annotation</groupId>
|
|
||||||
<artifactId>jsr250-api</artifactId>
|
|
||||||
<version>1.0</version>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-all</artifactId>
|
|
||||||
<version>${org.mockito.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<!--
|
|
||||||
dependency definitions to be inherited by child poms. any
|
|
||||||
<dependency> declarations here will automatically show up on child
|
|
||||||
project classpaths. only items that are truly common across all
|
|
||||||
projects (modules and samples) should go here. otherwise, consider
|
|
||||||
<dependencyManagement> above
|
|
||||||
-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<version>${log4j.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<extensions>
|
|
||||||
<extension>
|
|
||||||
<!--
|
|
||||||
available only in the springframework maven repository. see
|
|
||||||
<repositories> section below
|
|
||||||
-->
|
|
||||||
<groupId>org.springframework.build.aws</groupId>
|
|
||||||
<artifactId>org.springframework.build.aws.maven</artifactId>
|
|
||||||
<version>3.1.0.RELEASE</version>
|
|
||||||
</extension>
|
|
||||||
</extensions>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>${project.basedir}/src/main/java</directory>
|
|
||||||
<includes>
|
|
||||||
<include>**/*</include>
|
|
||||||
</includes>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/*.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
</resource>
|
|
||||||
<resource>
|
|
||||||
<directory>${project.basedir}/src/main/resources</directory>
|
|
||||||
<includes>
|
|
||||||
<include>**/*</include>
|
|
||||||
</includes>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
<testResources>
|
|
||||||
<testResource>
|
|
||||||
<directory>${project.basedir}/src/test/java</directory>
|
|
||||||
<includes>
|
|
||||||
<include>**/*</include>
|
|
||||||
</includes>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/*.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
</testResource>
|
|
||||||
<testResource>
|
|
||||||
<directory>${project.basedir}/src/test/resources</directory>
|
|
||||||
<includes>
|
|
||||||
<include>**/*</include>
|
|
||||||
</includes>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/*.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
</testResource>
|
|
||||||
</testResources>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>1.5</source>
|
|
||||||
<target>1.5</target>
|
|
||||||
<compilerArgument>-Xlint:-path</compilerArgument>
|
|
||||||
<showWarnings>true</showWarnings>
|
|
||||||
<showDeprecation>false</showDeprecation>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>2.3.1</version>
|
|
||||||
<configuration>
|
|
||||||
<useDefaultManifestFile>true</useDefaultManifestFile>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<useFile>false</useFile>
|
|
||||||
<includes>
|
|
||||||
<include>**/*Tests.java</include>
|
|
||||||
</includes>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/Abstract*.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
<junitArtifactName>junit:junit</junitArtifactName>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-sources</id>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
<pluginManagement>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<!--
|
|
||||||
configures the springsource bundlor plugin, which generates
|
|
||||||
OSGI-compatible MANIFEST.MF files during the 'compile' phase of
|
|
||||||
the maven build. this plugin is declared within the
|
|
||||||
pluginManagement section because not every module that inherits
|
|
||||||
from this pom needs bundlor's services, e.g.:
|
|
||||||
spring-integration-samples and all its children. for this reason,
|
|
||||||
all modules that wish to use bundlor must declare it explicitly.
|
|
||||||
it is not necessary to specify the <version> or <configuration>
|
|
||||||
sections, but groupId and artifactId are required. see
|
|
||||||
http://static.springsource.org/s2-bundlor/1.0.x/user-guide/html/ch04s03.html
|
|
||||||
for more info
|
|
||||||
-->
|
|
||||||
<groupId>com.springsource.bundlor</groupId>
|
|
||||||
<artifactId>com.springsource.bundlor.maven</artifactId>
|
|
||||||
<version>1.0.0.RELEASE</version>
|
|
||||||
<configuration>
|
|
||||||
<failOnWarnings>true</failOnWarnings>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>bundlor</id>
|
|
||||||
<goals>
|
|
||||||
<goal>bundlor</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</pluginManagement>
|
|
||||||
</build>
|
|
||||||
<pluginRepositories>
|
|
||||||
<pluginRepository>
|
|
||||||
<!-- necessary for bundlor and utils -->
|
|
||||||
<id>repository.plugin.springsource.release</id>
|
|
||||||
<name>SpringSource Maven Repository</name>
|
|
||||||
<url>http://repository.springsource.com/maven/bundles/release</url>
|
|
||||||
</pluginRepository>
|
|
||||||
<pluginRepository>
|
|
||||||
<id>repository.springframework.maven.release</id>
|
|
||||||
<name>Spring Framework Maven Release Repository</name>
|
|
||||||
<url>http://maven.springframework.org/release</url>
|
|
||||||
</pluginRepository>
|
|
||||||
</pluginRepositories>
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>repository.springframework.maven.release</id>
|
|
||||||
<name>Spring Framework Maven Release Repository</name>
|
|
||||||
<url>http://maven.springframework.org/release</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>repository.springframework.maven.milestone</id>
|
|
||||||
<name>Spring Framework Maven Milestone Repository</name>
|
|
||||||
<url>http://maven.springframework.org/milestone</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>repository.springframework.maven.snapshot</id>
|
|
||||||
<name>Spring Framework Maven Snapshot Repository</name>
|
|
||||||
<url>http://maven.springframework.org/snapshot</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
<reporting>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<!--
|
|
||||||
significantly speeds up the 'Dependencies' report during site
|
|
||||||
creation see
|
|
||||||
http://old.nabble.com/Skipping-dependency-report-during-Maven2-site-generation-td20116761.html
|
|
||||||
-->
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
|
||||||
<version>2.1</version>
|
|
||||||
<configuration>
|
|
||||||
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</reporting>
|
|
||||||
</project>
|
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-document-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>1.0.0.M3</version>
|
<version>1.1.0.M1</version>
|
||||||
<relativePath>../spring-data-document-parent/pom.xml</relativePath>
|
<relativePath>../spring-data-mongodb-parent/pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>spring-data-mongodb-cross-store</artifactId>
|
<artifactId>spring-data-mongodb-cross-store</artifactId>
|
||||||
<packaging>jar</packaging>
|
|
||||||
<name>Spring Data MongoDB Cross-store Persistence Support</name>
|
<name>Spring Data MongoDB Cross-store Persistence Support</name>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
@@ -16,95 +15,34 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-beans</artifactId>
|
<artifactId>spring-beans</artifactId>
|
||||||
|
<version>${org.springframework.version.range}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-tx</artifactId>
|
<artifactId>spring-tx</artifactId>
|
||||||
|
<version>${org.springframework.version.range}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-aspects</artifactId>
|
<artifactId>spring-aspects</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version.range}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-orm</artifactId>
|
<artifactId>spring-orm</artifactId>
|
||||||
</dependency>
|
<version>${org.springframework.version.range}</version>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Data -->
|
<!-- Spring Data -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-commons-core</artifactId>
|
<artifactId>spring-data-commons-core</artifactId>
|
||||||
|
<version>${data.commons.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-commons-aspects</artifactId>
|
|
||||||
</dependency> -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-mongodb</artifactId>
|
<artifactId>spring-data-mongodb</artifactId>
|
||||||
</dependency>
|
<version>1.1.0.M1</version>
|
||||||
|
|
||||||
|
|
||||||
<!-- Logging -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.mail</groupId>
|
|
||||||
<artifactId>mail</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.jms</groupId>
|
|
||||||
<artifactId>jms</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jdmk</groupId>
|
|
||||||
<artifactId>jmxtools</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jmx</groupId>
|
|
||||||
<artifactId>jmxri</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.annotation</groupId>
|
|
||||||
<artifactId>jsr250-api</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-all</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -152,25 +90,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>jboss-repository</id>
|
|
||||||
<name>JBoss Public Repository</name>
|
|
||||||
<url>http://repository.jboss.org/nexus/content/groups/public-jboss</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
<pluginRepositories>
|
|
||||||
<pluginRepository>
|
|
||||||
<id>spring-maven-milestones</id>
|
|
||||||
<name>Springframework Maven Milestone Repository</name>
|
|
||||||
<url>http://maven.springframework.org/milestone</url>
|
|
||||||
</pluginRepository>
|
|
||||||
<pluginRepository>
|
|
||||||
<id>spring-maven-release</id>
|
|
||||||
<name>Springframework Maven Release Repository</name>
|
|
||||||
<url>http://maven.springframework.org/release</url>
|
|
||||||
</pluginRepository>
|
|
||||||
</pluginRepositories>
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -1,30 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011 the original author or authors.
|
* Copyright 2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
package org.springframework.data.mongodb.crossstore;
|
||||||
package org.springframework.data.document.couchdb.core;
|
|
||||||
|
import org.springframework.data.crossstore.ChangeSetBacked;
|
||||||
import org.junit.Test;
|
|
||||||
|
public interface DocumentBacked extends ChangeSetBacked {
|
||||||
/**
|
|
||||||
* Unit tests for CouchTemplate with mocks
|
}
|
||||||
*/
|
|
||||||
public class CouchTemplateTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void foo() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.crossstore;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.dao.DataAccessResourceFailureException;
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
import org.springframework.data.crossstore.ChangeSet;
|
||||||
|
import org.springframework.data.crossstore.ChangeSetBacked;
|
||||||
|
import org.springframework.data.crossstore.ChangeSetPersister;
|
||||||
|
import org.springframework.data.mongodb.core.CollectionCallback;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
|
import com.mongodb.BasicDBObject;
|
||||||
|
import com.mongodb.DBCollection;
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import com.mongodb.MongoException;
|
||||||
|
|
||||||
|
public class MongoChangeSetPersister implements ChangeSetPersister<Object> {
|
||||||
|
|
||||||
|
private static final String ENTITY_CLASS = "_entity_class";
|
||||||
|
|
||||||
|
private static final String ENTITY_ID = "_entity_id";
|
||||||
|
|
||||||
|
private static final String ENTITY_FIELD_NAME = "_entity_field_name";
|
||||||
|
|
||||||
|
private static final String ENTITY_FIELD_CLASS = "_entity_field_class";
|
||||||
|
|
||||||
|
protected final Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
|
private EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
|
public void setMongoTemplate(MongoTemplate mongoTemplate) {
|
||||||
|
this.mongoTemplate = mongoTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getPersistentState(Class<? extends ChangeSetBacked> entityClass, Object id, final ChangeSet changeSet)
|
||||||
|
throws DataAccessException, NotFoundException {
|
||||||
|
|
||||||
|
if (id == null) {
|
||||||
|
log.debug("Unable to load MongoDB data for null id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String collName = getCollectionNameForEntity(entityClass);
|
||||||
|
|
||||||
|
final DBObject dbk = new BasicDBObject();
|
||||||
|
dbk.put(ENTITY_ID, id);
|
||||||
|
dbk.put(ENTITY_CLASS, entityClass.getName());
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Loading MongoDB data for " + dbk);
|
||||||
|
}
|
||||||
|
mongoTemplate.execute(collName, new CollectionCallback<Object>() {
|
||||||
|
public Object doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
||||||
|
for (DBObject dbo : collection.find(dbk)) {
|
||||||
|
String key = (String) dbo.get(ENTITY_FIELD_NAME);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Processing key: " + key);
|
||||||
|
}
|
||||||
|
if (!changeSet.getValues().containsKey(key)) {
|
||||||
|
String className = (String) dbo.get(ENTITY_FIELD_CLASS);
|
||||||
|
if (className == null) {
|
||||||
|
throw new DataIntegrityViolationException("Unble to convert property " + key + ": Invalid metadata, "
|
||||||
|
+ ENTITY_FIELD_CLASS + " not available");
|
||||||
|
}
|
||||||
|
Class<?> clazz = ClassUtils.resolveClassName(className, ClassUtils.getDefaultClassLoader());
|
||||||
|
Object value = mongoTemplate.getConverter().read(clazz, dbo);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Adding to ChangeSet: " + key);
|
||||||
|
}
|
||||||
|
changeSet.set(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getPersistentId(ChangeSetBacked entity, ChangeSet cs) throws DataAccessException {
|
||||||
|
log.debug("getPersistentId called on " + entity);
|
||||||
|
if (entityManagerFactory == null) {
|
||||||
|
throw new DataAccessResourceFailureException("EntityManagerFactory cannot be null");
|
||||||
|
}
|
||||||
|
Object o = entityManagerFactory.getPersistenceUnitUtil().getIdentifier(entity);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object persistState(ChangeSetBacked entity, ChangeSet cs) throws DataAccessException {
|
||||||
|
if (cs == null) {
|
||||||
|
log.debug("Flush: changeset was null, nothing to flush.");
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Flush: changeset: " + cs.getValues());
|
||||||
|
}
|
||||||
|
|
||||||
|
String collName = getCollectionNameForEntity(entity.getClass());
|
||||||
|
if (mongoTemplate.getCollection(collName) == null) {
|
||||||
|
mongoTemplate.createCollection(collName);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String key : cs.getValues().keySet()) {
|
||||||
|
if (key != null && !key.startsWith("_") && !key.equals(ChangeSetPersister.ID_KEY)) {
|
||||||
|
Object value = cs.getValues().get(key);
|
||||||
|
final DBObject dbQuery = new BasicDBObject();
|
||||||
|
dbQuery.put(ENTITY_ID, getPersistentId(entity, cs));
|
||||||
|
dbQuery.put(ENTITY_CLASS, entity.getClass().getName());
|
||||||
|
dbQuery.put(ENTITY_FIELD_NAME, key);
|
||||||
|
DBObject dbId = mongoTemplate.execute(collName, new CollectionCallback<DBObject>() {
|
||||||
|
public DBObject doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
||||||
|
return collection.findOne(dbQuery);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (value == null) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Flush: removing: " + dbQuery);
|
||||||
|
}
|
||||||
|
mongoTemplate.execute(collName, new CollectionCallback<Object>() {
|
||||||
|
public Object doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
||||||
|
collection.remove(dbQuery);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
final DBObject dbDoc = new BasicDBObject();
|
||||||
|
dbDoc.putAll(dbQuery);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Flush: saving: " + dbQuery);
|
||||||
|
}
|
||||||
|
mongoTemplate.getConverter().write(value, dbDoc);
|
||||||
|
dbDoc.put(ENTITY_FIELD_CLASS, value.getClass().getName());
|
||||||
|
if (dbId != null) {
|
||||||
|
dbDoc.put("_id", dbId.get("_id"));
|
||||||
|
}
|
||||||
|
mongoTemplate.execute(collName, new CollectionCallback<Object>() {
|
||||||
|
public Object doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
||||||
|
collection.save(dbDoc);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCollectionNameForEntity(Class<? extends ChangeSetBacked> entityClass) {
|
||||||
|
return ClassUtils.getQualifiedName(entityClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,271 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.crossstore;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.aspectj.lang.JoinPoint;
|
||||||
|
import org.aspectj.lang.reflect.FieldSignature;
|
||||||
|
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
||||||
|
import org.springframework.data.mongodb.crossstore.RelatedDocument;
|
||||||
|
import org.springframework.data.mongodb.crossstore.DocumentBacked;
|
||||||
|
import org.springframework.data.crossstore.ChangeSetBackedTransactionSynchronization;
|
||||||
|
import org.springframework.data.crossstore.ChangeSet;
|
||||||
|
import org.springframework.data.crossstore.ChangeSetPersister;
|
||||||
|
import org.springframework.data.crossstore.ChangeSetPersister.NotFoundException;
|
||||||
|
import org.springframework.data.crossstore.HashMapChangeSet;
|
||||||
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aspect to turn an object annotated with @Document into a persistent document using Mongo.
|
||||||
|
*
|
||||||
|
* @author Thomas Risberg
|
||||||
|
*/
|
||||||
|
public aspect MongoDocumentBacking {
|
||||||
|
|
||||||
|
private static final Log LOGGER = LogFactory.getLog(MongoDocumentBacking.class);
|
||||||
|
|
||||||
|
// Aspect shared config
|
||||||
|
private ChangeSetPersister<Object> changeSetPersister;
|
||||||
|
|
||||||
|
public void setChangeSetPersister(ChangeSetPersister<Object> changeSetPersister) {
|
||||||
|
this.changeSetPersister = changeSetPersister;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITD to introduce N state to Annotated objects
|
||||||
|
declare parents : (@Entity *) implements DocumentBacked;
|
||||||
|
|
||||||
|
// The annotated fields that will be persisted in MongoDB rather than with JPA
|
||||||
|
declare @field: @RelatedDocument * (@Entity+ *).*:@Transient;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// Advise user-defined constructors of ChangeSetBacked objects to create a new
|
||||||
|
// backing ChangeSet
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
pointcut arbitraryUserConstructorOfChangeSetBackedObject(DocumentBacked entity) :
|
||||||
|
execution((DocumentBacked+).new(..)) &&
|
||||||
|
!execution((DocumentBacked+).new(ChangeSet)) &&
|
||||||
|
this(entity);
|
||||||
|
|
||||||
|
pointcut finderConstructorOfChangeSetBackedObject(DocumentBacked entity, ChangeSet cs) :
|
||||||
|
execution((DocumentBacked+).new(ChangeSet)) &&
|
||||||
|
this(entity) &&
|
||||||
|
args(cs);
|
||||||
|
|
||||||
|
protected pointcut entityFieldGet(DocumentBacked entity) :
|
||||||
|
get(@RelatedDocument * DocumentBacked+.*) &&
|
||||||
|
this(entity) &&
|
||||||
|
!get(* DocumentBacked.*);
|
||||||
|
|
||||||
|
protected pointcut entityFieldSet(DocumentBacked entity, Object newVal) :
|
||||||
|
set(@RelatedDocument * DocumentBacked+.*) &&
|
||||||
|
this(entity) &&
|
||||||
|
args(newVal) &&
|
||||||
|
!set(* DocumentBacked.*);
|
||||||
|
|
||||||
|
// intercept EntityManager.merge calls
|
||||||
|
public pointcut entityManagerMerge(EntityManager em, Object entity) :
|
||||||
|
call(* EntityManager.merge(Object)) &&
|
||||||
|
target(em) &&
|
||||||
|
args(entity);
|
||||||
|
|
||||||
|
// intercept EntityManager.remove calls
|
||||||
|
// public pointcut entityManagerRemove(EntityManager em, Object entity) :
|
||||||
|
// call(* EntityManager.remove(Object)) &&
|
||||||
|
// target(em) &&
|
||||||
|
// args(entity);
|
||||||
|
|
||||||
|
// move changeSet from detached entity to the newly merged persistent object
|
||||||
|
Object around(EntityManager em, Object entity) : entityManagerMerge(em, entity) {
|
||||||
|
Object mergedEntity = proceed(em, entity);
|
||||||
|
if (entity instanceof DocumentBacked && mergedEntity instanceof DocumentBacked) {
|
||||||
|
((DocumentBacked) mergedEntity).changeSet = ((DocumentBacked) entity).getChangeSet();
|
||||||
|
}
|
||||||
|
return mergedEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear changeSet from removed entity
|
||||||
|
// Object around(EntityManager em, Object entity) : entityManagerRemove(em, entity) {
|
||||||
|
// if (entity instanceof DocumentBacked) {
|
||||||
|
// removeChangeSetValues((DocumentBacked)entity);
|
||||||
|
// }
|
||||||
|
// return proceed(em, entity);
|
||||||
|
// }
|
||||||
|
|
||||||
|
private static void removeChangeSetValues(DocumentBacked entity) {
|
||||||
|
LOGGER.debug("Removing all change-set values for " + entity);
|
||||||
|
ChangeSet nulledCs = new HashMapChangeSet();
|
||||||
|
DocumentBacked documentEntity = (DocumentBacked) entity;
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
ChangeSetPersister<Object> changeSetPersister = (ChangeSetPersister<Object>) documentEntity.itdChangeSetPersister;
|
||||||
|
try {
|
||||||
|
changeSetPersister.getPersistentState(documentEntity.getClass(), documentEntity.get_persistent_id(),
|
||||||
|
documentEntity.getChangeSet());
|
||||||
|
} catch (DataAccessException e) {
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
}
|
||||||
|
for (String key : entity.getChangeSet().getValues().keySet()) {
|
||||||
|
nulledCs.set(key, null);
|
||||||
|
}
|
||||||
|
entity.setChangeSet(nulledCs);
|
||||||
|
}
|
||||||
|
|
||||||
|
before(DocumentBacked entity) : arbitraryUserConstructorOfChangeSetBackedObject(entity) {
|
||||||
|
LOGGER.debug("User-defined constructor called on DocumentBacked object of class " + entity.getClass());
|
||||||
|
// Populate all ITD fields
|
||||||
|
entity.setChangeSet(new HashMapChangeSet());
|
||||||
|
entity.itdChangeSetPersister = changeSetPersister;
|
||||||
|
entity.itdTransactionSynchronization = new ChangeSetBackedTransactionSynchronization(changeSetPersister, entity);
|
||||||
|
// registerTransactionSynchronization(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerTransactionSynchronization(DocumentBacked entity) {
|
||||||
|
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||||
|
if (!TransactionSynchronizationManager.getSynchronizations().contains(entity.itdTransactionSynchronization)) {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("Adding transaction synchronization for " + entity);
|
||||||
|
}
|
||||||
|
TransactionSynchronizationManager.registerSynchronization(entity.itdTransactionSynchronization);
|
||||||
|
} else {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("Transaction synchronization already active for " + entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("Transaction synchronization is not active for " + entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// ChangeSet-related mixins
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// Introduced field
|
||||||
|
@Transient
|
||||||
|
private ChangeSet DocumentBacked.changeSet;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private ChangeSetPersister<?> DocumentBacked.itdChangeSetPersister;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private ChangeSetBackedTransactionSynchronization DocumentBacked.itdTransactionSynchronization;
|
||||||
|
|
||||||
|
public void DocumentBacked.setChangeSet(ChangeSet cs) {
|
||||||
|
this.changeSet = cs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChangeSet DocumentBacked.getChangeSet() {
|
||||||
|
return changeSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flush the entity state to the persistent store
|
||||||
|
public void DocumentBacked.flush() {
|
||||||
|
Object id = itdChangeSetPersister.getPersistentId(this, this.changeSet);
|
||||||
|
itdChangeSetPersister.persistState(this, this.changeSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object DocumentBacked.get_persistent_id() {
|
||||||
|
return itdChangeSetPersister.getPersistentId(this, this.changeSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lifecycle methods
|
||||||
|
@javax.persistence.PostPersist
|
||||||
|
public void DocumentBacked.itdPostPersist() {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("JPA lifecycle event PrePersist: " + this.getClass().getName());
|
||||||
|
}
|
||||||
|
registerTransactionSynchronization(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@javax.persistence.PreUpdate
|
||||||
|
public void DocumentBacked.itdPreUpdate() {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("JPA lifecycle event PreUpdate: " + this.getClass().getName() + " :: " + this);
|
||||||
|
}
|
||||||
|
registerTransactionSynchronization(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@javax.persistence.PostUpdate
|
||||||
|
public void DocumentBacked.itdPostUpdate() {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("JPA lifecycle event PostUpdate: " + this.getClass().getName() + " :: " + this);
|
||||||
|
}
|
||||||
|
registerTransactionSynchronization(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@javax.persistence.PostRemove
|
||||||
|
public void DocumentBacked.itdPostRemove() {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("JPA lifecycle event PostRemove: " + this.getClass().getName() + " :: " + this);
|
||||||
|
}
|
||||||
|
registerTransactionSynchronization(this);
|
||||||
|
removeChangeSetValues(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@javax.persistence.PostLoad
|
||||||
|
public void DocumentBacked.itdPostLoad() {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("JPA lifecycle event PostLoad: " + this.getClass().getName() + " :: " + this);
|
||||||
|
}
|
||||||
|
registerTransactionSynchronization(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delegates field reads to the state accessors instance
|
||||||
|
*/
|
||||||
|
Object around(DocumentBacked entity): entityFieldGet(entity) {
|
||||||
|
Field f = field(thisJoinPoint);
|
||||||
|
String propName = f.getName();
|
||||||
|
LOGGER.trace("GET " + f + " -> ChangeSet value property [" + propName + "] using: " + entity.getChangeSet());
|
||||||
|
if (entity.getChangeSet().getValues().get(propName) == null) {
|
||||||
|
try {
|
||||||
|
this.changeSetPersister
|
||||||
|
.getPersistentState(entity.getClass(), entity.get_persistent_id(), entity.getChangeSet());
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Object fValue = entity.getChangeSet().getValues().get(propName);
|
||||||
|
if (fValue != null) {
|
||||||
|
return fValue;
|
||||||
|
}
|
||||||
|
return proceed(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delegates field writes to the state accessors instance
|
||||||
|
*/
|
||||||
|
Object around(DocumentBacked entity, Object newVal) : entityFieldSet(entity, newVal) {
|
||||||
|
Field f = field(thisJoinPoint);
|
||||||
|
String propName = f.getName();
|
||||||
|
LOGGER.trace("SET " + f + " -> ChangeSet number value property [" + propName + "] with value=[" + newVal + "]");
|
||||||
|
entity.getChangeSet().set(propName, newVal);
|
||||||
|
return proceed(entity, newVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
Field field(JoinPoint joinPoint) {
|
||||||
|
FieldSignature fieldSignature = (FieldSignature) joinPoint.getSignature();
|
||||||
|
return fieldSignature.getField();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 by the original author(s).
|
* Copyright 2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
@@ -13,8 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
package org.springframework.data.mongodb.crossstore;
|
||||||
package org.springframework.data.persistence.document;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@@ -25,8 +24,6 @@ import java.lang.annotation.Target;
|
|||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({
|
@Target({ ElementType.FIELD })
|
||||||
ElementType.FIELD
|
|
||||||
})
|
|
||||||
public @interface RelatedDocument {
|
public @interface RelatedDocument {
|
||||||
}
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package org.springframework.data.persistence.document;
|
|
||||||
|
|
||||||
import org.springframework.data.persistence.ChangeSetBacked;
|
|
||||||
|
|
||||||
public interface DocumentBacked extends ChangeSetBacked {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package org.springframework.data.persistence.document;
|
|
||||||
|
|
||||||
//public class DocumentBackedTransactionSynchronization {
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.data.persistence.ChangeSetBacked;
|
|
||||||
import org.springframework.data.persistence.ChangeSetPersister;
|
|
||||||
import org.springframework.transaction.support.TransactionSynchronization;
|
|
||||||
|
|
||||||
public class DocumentBackedTransactionSynchronization implements TransactionSynchronization {
|
|
||||||
|
|
||||||
protected final Log log = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
private ChangeSetPersister<Object> changeSetPersister;
|
|
||||||
|
|
||||||
private ChangeSetBacked entity;
|
|
||||||
|
|
||||||
private int changeSetTxStatus = -1;
|
|
||||||
|
|
||||||
public DocumentBackedTransactionSynchronization(ChangeSetPersister<Object> changeSetPersister, ChangeSetBacked entity) {
|
|
||||||
this.changeSetPersister = changeSetPersister;
|
|
||||||
this.entity = entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterCommit() {
|
|
||||||
log.debug("After Commit called for " + entity);
|
|
||||||
changeSetPersister.persistState(entity, entity.getChangeSet());
|
|
||||||
changeSetTxStatus = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterCompletion(int status) {
|
|
||||||
log.debug("After Completion called with status = " + status);
|
|
||||||
if (changeSetTxStatus == 0) {
|
|
||||||
if (status == STATUS_COMMITTED) {
|
|
||||||
// this is good
|
|
||||||
log.debug("ChangedSetBackedTransactionSynchronization completed successfully for " + this.entity);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// this could be bad - TODO: compensate
|
|
||||||
log.error("ChangedSetBackedTransactionSynchronization failed for " + this.entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void beforeCommit(boolean readOnly) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void beforeCompletion() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void flush() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resume() {
|
|
||||||
throw new IllegalStateException("ChangedSetBackedTransactionSynchronization does not support transaction suspension currently.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void suspend() {
|
|
||||||
throw new IllegalStateException("ChangedSetBackedTransactionSynchronization does not support transaction suspension currently.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,169 +0,0 @@
|
|||||||
package org.springframework.data.persistence.document.mongodb;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.MongoException;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
import org.springframework.dao.DataAccessResourceFailureException;
|
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
|
||||||
import org.springframework.data.document.mongodb.CollectionCallback;
|
|
||||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
|
||||||
import org.springframework.data.persistence.ChangeSet;
|
|
||||||
import org.springframework.data.persistence.ChangeSetBacked;
|
|
||||||
import org.springframework.data.persistence.ChangeSetPersister;
|
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
|
|
||||||
public class MongoChangeSetPersister implements ChangeSetPersister<Object> {
|
|
||||||
|
|
||||||
private static final String ENTITY_CLASS = "_entity_class";
|
|
||||||
|
|
||||||
private static final String ENTITY_ID = "_entity_id";
|
|
||||||
|
|
||||||
private static final String ENTITY_FIELD_NAME = "_entity_field_name";
|
|
||||||
|
|
||||||
private static final String ENTITY_FIELD_CLASS = "_entity_field_class";
|
|
||||||
|
|
||||||
protected final Log log = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
private MongoTemplate mongoTemplate;
|
|
||||||
|
|
||||||
private EntityManagerFactory entityManagerFactory;
|
|
||||||
|
|
||||||
public void setMongoTemplate(MongoTemplate mongoTemplate) {
|
|
||||||
this.mongoTemplate = mongoTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
|
|
||||||
this.entityManagerFactory = entityManagerFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void getPersistentState(Class<? extends ChangeSetBacked> entityClass,
|
|
||||||
Object id, final ChangeSet changeSet)
|
|
||||||
throws DataAccessException, NotFoundException {
|
|
||||||
|
|
||||||
if (id == null) {
|
|
||||||
log.debug("Unable to load MongoDB data for null id");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String collName = getCollectionNameForEntity(entityClass);
|
|
||||||
|
|
||||||
final DBObject dbk = new BasicDBObject();
|
|
||||||
dbk.put(ENTITY_ID, id);
|
|
||||||
dbk.put(ENTITY_CLASS, entityClass.getName());
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Loading MongoDB data for " + dbk);
|
|
||||||
}
|
|
||||||
mongoTemplate.execute(collName, new CollectionCallback<Object>() {
|
|
||||||
public Object doInCollection(DBCollection collection)
|
|
||||||
throws MongoException, DataAccessException {
|
|
||||||
for (DBObject dbo : collection.find(dbk)) {
|
|
||||||
String key = (String) dbo.get(ENTITY_FIELD_NAME);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Processing key: " + key);
|
|
||||||
}
|
|
||||||
if (!changeSet.getValues().containsKey(key)) {
|
|
||||||
String className = (String) dbo.get(ENTITY_FIELD_CLASS);
|
|
||||||
if (className == null) {
|
|
||||||
throw new DataIntegrityViolationException(
|
|
||||||
"Unble to convert property " + key
|
|
||||||
+ ": Invalid metadata, " + ENTITY_FIELD_CLASS + " not available");
|
|
||||||
}
|
|
||||||
Class<?> clazz = ClassUtils.resolveClassName(className, ClassUtils.getDefaultClassLoader());
|
|
||||||
Object value = mongoTemplate.getConverter().read(clazz, dbo);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Adding to ChangeSet: " + key);
|
|
||||||
}
|
|
||||||
changeSet.set(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getPersistentId(ChangeSetBacked entity, ChangeSet cs) throws DataAccessException {
|
|
||||||
log.debug("getPersistentId called on " + entity);
|
|
||||||
if (entityManagerFactory == null) {
|
|
||||||
throw new DataAccessResourceFailureException("EntityManagerFactory cannot be null");
|
|
||||||
}
|
|
||||||
Object o = entityManagerFactory.getPersistenceUnitUtil().getIdentifier(entity);
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object persistState(ChangeSetBacked entity, ChangeSet cs) throws DataAccessException {
|
|
||||||
if (cs == null) {
|
|
||||||
log.debug("Flush: changeset was null, nothing to flush.");
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Flush: changeset: " + cs.getValues());
|
|
||||||
}
|
|
||||||
|
|
||||||
String collName = getCollectionNameForEntity(entity.getClass());
|
|
||||||
DBCollection dbc = mongoTemplate.getCollection(collName);
|
|
||||||
if (dbc == null) {
|
|
||||||
dbc = mongoTemplate.createCollection(collName);
|
|
||||||
}
|
|
||||||
for (String key : cs.getValues().keySet()) {
|
|
||||||
if (key != null && !key.startsWith("_") && !key.equals(ChangeSetPersister.ID_KEY)) {
|
|
||||||
Object value = cs.getValues().get(key);
|
|
||||||
final DBObject dbQuery = new BasicDBObject();
|
|
||||||
dbQuery.put(ENTITY_ID, getPersistentId(entity, cs));
|
|
||||||
dbQuery.put(ENTITY_CLASS, entity.getClass().getName());
|
|
||||||
dbQuery.put(ENTITY_FIELD_NAME, key);
|
|
||||||
DBObject dbId = mongoTemplate.execute(collName,
|
|
||||||
new CollectionCallback<DBObject>() {
|
|
||||||
public DBObject doInCollection(DBCollection collection)
|
|
||||||
throws MongoException, DataAccessException {
|
|
||||||
return collection.findOne(dbQuery);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (value == null) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Flush: removing: " + dbQuery);
|
|
||||||
}
|
|
||||||
mongoTemplate.execute(collName, new CollectionCallback<Object>() {
|
|
||||||
public Object doInCollection(DBCollection collection)
|
|
||||||
throws MongoException, DataAccessException {
|
|
||||||
collection.remove(dbQuery);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
final DBObject dbDoc = new BasicDBObject();
|
|
||||||
dbDoc.putAll(dbQuery);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Flush: saving: " + dbQuery);
|
|
||||||
}
|
|
||||||
mongoTemplate.getConverter().write(value, dbDoc);
|
|
||||||
dbDoc.put(ENTITY_FIELD_CLASS, value.getClass().getName());
|
|
||||||
if (dbId != null) {
|
|
||||||
dbDoc.put("_id", dbId.get("_id"));
|
|
||||||
}
|
|
||||||
mongoTemplate.execute(collName, new CollectionCallback<Object>() {
|
|
||||||
public Object doInCollection(DBCollection collection)
|
|
||||||
throws MongoException, DataAccessException {
|
|
||||||
collection.save(dbDoc);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getCollectionNameForEntity(Class<? extends ChangeSetBacked> entityClass) {
|
|
||||||
return ClassUtils.getQualifiedName(entityClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,257 +0,0 @@
|
|||||||
package org.springframework.data.persistence.document.mongodb;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.Transient;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
|
||||||
import org.aspectj.lang.reflect.FieldSignature;
|
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
import org.springframework.data.persistence.document.RelatedDocument;
|
|
||||||
|
|
||||||
import org.springframework.data.persistence.document.DocumentBacked;
|
|
||||||
import org.springframework.data.persistence.document.DocumentBackedTransactionSynchronization;
|
|
||||||
import org.springframework.data.persistence.ChangeSet;
|
|
||||||
import org.springframework.data.persistence.ChangeSetPersister;
|
|
||||||
import org.springframework.data.persistence.ChangeSetPersister.NotFoundException;
|
|
||||||
import org.springframework.data.persistence.HashMapChangeSet;
|
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aspect to turn an object annotated with @Document into a persistent document
|
|
||||||
* using Mongo.
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
*/
|
|
||||||
public aspect MongoDocumentBacking {
|
|
||||||
|
|
||||||
private static final Log LOGGER = LogFactory
|
|
||||||
.getLog(MongoDocumentBacking.class);
|
|
||||||
|
|
||||||
// Aspect shared config
|
|
||||||
private ChangeSetPersister<Object> changeSetPersister;
|
|
||||||
|
|
||||||
public void setChangeSetPersister(
|
|
||||||
ChangeSetPersister<Object> changeSetPersister) {
|
|
||||||
this.changeSetPersister = changeSetPersister;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ITD to introduce N state to Annotated objects
|
|
||||||
declare parents : (@Entity *) implements DocumentBacked;
|
|
||||||
|
|
||||||
// The annotated fields that will be persisted in MongoDB rather than with JPA
|
|
||||||
declare @field: @RelatedDocument * (@Entity+ *).*:@Transient;
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// Advise user-defined constructors of ChangeSetBacked objects to create a new
|
|
||||||
// backing ChangeSet
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
pointcut arbitraryUserConstructorOfChangeSetBackedObject(DocumentBacked entity) :
|
|
||||||
execution((DocumentBacked+).new(..)) &&
|
|
||||||
!execution((DocumentBacked+).new(ChangeSet)) &&
|
|
||||||
this(entity);
|
|
||||||
|
|
||||||
pointcut finderConstructorOfChangeSetBackedObject(DocumentBacked entity,
|
|
||||||
ChangeSet cs) :
|
|
||||||
execution((DocumentBacked+).new(ChangeSet)) &&
|
|
||||||
this(entity) &&
|
|
||||||
args(cs);
|
|
||||||
|
|
||||||
protected pointcut entityFieldGet(DocumentBacked entity) :
|
|
||||||
get(@RelatedDocument * DocumentBacked+.*) &&
|
|
||||||
this(entity) &&
|
|
||||||
!get(* DocumentBacked.*);
|
|
||||||
|
|
||||||
protected pointcut entityFieldSet(DocumentBacked entity, Object newVal) :
|
|
||||||
set(@RelatedDocument * DocumentBacked+.*) &&
|
|
||||||
this(entity) &&
|
|
||||||
args(newVal) &&
|
|
||||||
!set(* DocumentBacked.*);
|
|
||||||
|
|
||||||
// intercept EntityManager.merge calls
|
|
||||||
public pointcut entityManagerMerge(EntityManager em, Object entity) :
|
|
||||||
call(* EntityManager.merge(Object)) &&
|
|
||||||
target(em) &&
|
|
||||||
args(entity);
|
|
||||||
|
|
||||||
// intercept EntityManager.remove calls
|
|
||||||
// public pointcut entityManagerRemove(EntityManager em, Object entity) :
|
|
||||||
// call(* EntityManager.remove(Object)) &&
|
|
||||||
// target(em) &&
|
|
||||||
// args(entity);
|
|
||||||
|
|
||||||
// move changeSet from detached entity to the newly merged persistent object
|
|
||||||
Object around(EntityManager em, Object entity) : entityManagerMerge(em, entity) {
|
|
||||||
Object mergedEntity = proceed(em, entity);
|
|
||||||
if (entity instanceof DocumentBacked && mergedEntity instanceof DocumentBacked) {
|
|
||||||
((DocumentBacked)mergedEntity).changeSet = ((DocumentBacked)entity).getChangeSet();
|
|
||||||
}
|
|
||||||
return mergedEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear changeSet from removed entity
|
|
||||||
// Object around(EntityManager em, Object entity) : entityManagerRemove(em, entity) {
|
|
||||||
// if (entity instanceof DocumentBacked) {
|
|
||||||
// removeChangeSetValues((DocumentBacked)entity);
|
|
||||||
// }
|
|
||||||
// return proceed(em, entity);
|
|
||||||
// }
|
|
||||||
|
|
||||||
private static void removeChangeSetValues(DocumentBacked entity) {
|
|
||||||
LOGGER.debug("Removing all change-set values for " + entity);
|
|
||||||
ChangeSet nulledCs = new HashMapChangeSet();
|
|
||||||
DocumentBacked documentEntity = (DocumentBacked) entity;
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
ChangeSetPersister<Object> changeSetPersister = (ChangeSetPersister<Object>)documentEntity.itdChangeSetPersister;
|
|
||||||
try {
|
|
||||||
changeSetPersister.getPersistentState(
|
|
||||||
documentEntity.getClass(),
|
|
||||||
documentEntity.get_persistent_id(),
|
|
||||||
documentEntity.getChangeSet());
|
|
||||||
}
|
|
||||||
catch (DataAccessException e) {}
|
|
||||||
catch (NotFoundException e) {}
|
|
||||||
for (String key :entity.getChangeSet().getValues().keySet()) {
|
|
||||||
nulledCs.set(key, null);
|
|
||||||
}
|
|
||||||
entity.setChangeSet(nulledCs);
|
|
||||||
}
|
|
||||||
|
|
||||||
before(DocumentBacked entity) : arbitraryUserConstructorOfChangeSetBackedObject(entity) {
|
|
||||||
LOGGER
|
|
||||||
.debug("User-defined constructor called on DocumentBacked object of class "
|
|
||||||
+ entity.getClass());
|
|
||||||
// Populate all ITD fields
|
|
||||||
entity.setChangeSet(new HashMapChangeSet());
|
|
||||||
entity.itdChangeSetPersister = changeSetPersister;
|
|
||||||
entity.itdTransactionSynchronization =
|
|
||||||
new DocumentBackedTransactionSynchronization(changeSetPersister, entity);
|
|
||||||
//registerTransactionSynchronization(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void registerTransactionSynchronization(DocumentBacked entity) {
|
|
||||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
|
||||||
if (!TransactionSynchronizationManager.getSynchronizations().contains(entity.itdTransactionSynchronization)) {
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Adding transaction synchronization for " + entity);
|
|
||||||
}
|
|
||||||
TransactionSynchronizationManager.registerSynchronization(entity.itdTransactionSynchronization);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Transaction synchronization already active for " + entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("Transaction synchronization is not active for " + entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// ChangeSet-related mixins
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// Introduced field
|
|
||||||
@Transient private ChangeSet DocumentBacked.changeSet;
|
|
||||||
|
|
||||||
@Transient private ChangeSetPersister<?> DocumentBacked.itdChangeSetPersister;
|
|
||||||
|
|
||||||
@Transient private DocumentBackedTransactionSynchronization DocumentBacked.itdTransactionSynchronization;
|
|
||||||
|
|
||||||
public void DocumentBacked.setChangeSet(ChangeSet cs) {
|
|
||||||
this.changeSet = cs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChangeSet DocumentBacked.getChangeSet() {
|
|
||||||
return changeSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flush the entity state to the persistent store
|
|
||||||
public void DocumentBacked.flush() {
|
|
||||||
Object id = itdChangeSetPersister.getPersistentId(this, this.changeSet);
|
|
||||||
itdChangeSetPersister.persistState(this, this.changeSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object DocumentBacked.get_persistent_id() {
|
|
||||||
return itdChangeSetPersister.getPersistentId(this, this.changeSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
// lifecycle methods
|
|
||||||
@javax.persistence.PostPersist public void DocumentBacked.itdPostPersist() {
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("JPA lifecycle event PrePersist: " + this.getClass().getName());
|
|
||||||
}
|
|
||||||
registerTransactionSynchronization(this);
|
|
||||||
}
|
|
||||||
@javax.persistence.PreUpdate public void DocumentBacked.itdPreUpdate() {
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("JPA lifecycle event PreUpdate: " + this.getClass().getName() + " :: " + this);
|
|
||||||
}
|
|
||||||
registerTransactionSynchronization(this);
|
|
||||||
}
|
|
||||||
@javax.persistence.PostUpdate public void DocumentBacked.itdPostUpdate() {
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("JPA lifecycle event PostUpdate: " + this.getClass().getName() + " :: " + this);
|
|
||||||
}
|
|
||||||
registerTransactionSynchronization(this);
|
|
||||||
}
|
|
||||||
@javax.persistence.PostRemove public void DocumentBacked.itdPostRemove() {
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("JPA lifecycle event PostRemove: " + this.getClass().getName() + " :: " + this);
|
|
||||||
}
|
|
||||||
registerTransactionSynchronization(this);
|
|
||||||
removeChangeSetValues(this);
|
|
||||||
}
|
|
||||||
@javax.persistence.PostLoad public void DocumentBacked.itdPostLoad() {
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("JPA lifecycle event PostLoad: " + this.getClass().getName() + " :: " + this);
|
|
||||||
}
|
|
||||||
registerTransactionSynchronization(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* delegates field reads to the state accessors instance
|
|
||||||
*/
|
|
||||||
Object around(DocumentBacked entity): entityFieldGet(entity) {
|
|
||||||
Field f = field(thisJoinPoint);
|
|
||||||
String propName = f.getName();
|
|
||||||
LOGGER.trace("GET " + f + " -> ChangeSet value property [" + propName
|
|
||||||
+ "] using: " + entity.getChangeSet());
|
|
||||||
if (entity.getChangeSet().getValues().get(propName) == null) {
|
|
||||||
try {
|
|
||||||
this.changeSetPersister.getPersistentState(entity.getClass(),
|
|
||||||
entity.get_persistent_id(), entity.getChangeSet());
|
|
||||||
} catch (NotFoundException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Object fValue = entity.getChangeSet().getValues().get(propName);
|
|
||||||
if (fValue != null) {
|
|
||||||
return fValue;
|
|
||||||
}
|
|
||||||
return proceed(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* delegates field writes to the state accessors instance
|
|
||||||
*/
|
|
||||||
Object around(DocumentBacked entity, Object newVal) : entityFieldSet(entity, newVal) {
|
|
||||||
Field f = field(thisJoinPoint);
|
|
||||||
String propName = f.getName();
|
|
||||||
LOGGER.trace("SET " + f + " -> ChangeSet number value property [" + propName
|
|
||||||
+ "] with value=[" + newVal + "]");
|
|
||||||
entity.getChangeSet().set(propName, newVal);
|
|
||||||
return proceed(entity, newVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
Field field(JoinPoint joinPoint) {
|
|
||||||
FieldSignature fieldSignature = (FieldSignature) joinPoint.getSignature();
|
|
||||||
return fieldSignature.getField();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
package org.springframework.data.document.persistence;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
|
||||||
import org.springframework.data.document.persistence.test.Address;
|
|
||||||
import org.springframework.data.document.persistence.test.Person;
|
|
||||||
import org.springframework.data.document.persistence.test.Resume;
|
|
||||||
import org.springframework.test.annotation.Rollback;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
import org.springframework.transaction.TransactionStatus;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.transaction.support.TransactionCallback;
|
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
|
||||||
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext.xml")
|
|
||||||
public class CrossStoreMongoTests {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MongoTemplate mongoTemplate;
|
|
||||||
|
|
||||||
private EntityManager entityManager;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PlatformTransactionManager transactionManager;
|
|
||||||
|
|
||||||
@PersistenceContext
|
|
||||||
public void setEntityManager(EntityManager entityManager) {
|
|
||||||
this.entityManager = entityManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clearData(String collectionName) {
|
|
||||||
DBCollection col = this.mongoTemplate.getCollection(collectionName);
|
|
||||||
if (col != null) {
|
|
||||||
this.mongoTemplate.dropCollection(collectionName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Transactional
|
|
||||||
@Rollback(false)
|
|
||||||
public void testCreateJpaToMongoEntityRelationship() {
|
|
||||||
clearData(Person.class.getName());
|
|
||||||
Person p = new Person("Thomas", 20);
|
|
||||||
Address a = new Address(12, "MAin St.", "Boston", "MA", "02101");
|
|
||||||
p.setAddress(a);
|
|
||||||
Resume r = new Resume();
|
|
||||||
r.addEducation("Skanstulls High School, 1975");
|
|
||||||
r.addEducation("Univ. of Stockholm, 1980");
|
|
||||||
r.addJob("DiMark, DBA, 1990-2000");
|
|
||||||
r.addJob("VMware, Developer, 2007-");
|
|
||||||
p.setResume(r);
|
|
||||||
p.setId(1L);
|
|
||||||
entityManager.persist(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Transactional
|
|
||||||
@Rollback(false)
|
|
||||||
public void testReadJpaToMongoEntityRelationship() {
|
|
||||||
Person found = entityManager.find(Person.class, 1L);
|
|
||||||
Assert.assertNotNull(found);
|
|
||||||
Assert.assertEquals(Long.valueOf(1), found.getId());
|
|
||||||
Assert.assertNotNull(found);
|
|
||||||
Assert.assertEquals(Long.valueOf(1), found.getId());
|
|
||||||
Assert.assertNotNull(found.getResume());
|
|
||||||
Assert.assertEquals("DiMark, DBA, 1990-2000" + "; "
|
|
||||||
+ "VMware, Developer, 2007-", found.getResume().getJobs());
|
|
||||||
found.getResume().addJob("SpringDeveloper.com, Consultant, 2005-2006");
|
|
||||||
found.setAge(44);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Transactional
|
|
||||||
@Rollback(false)
|
|
||||||
public void testUpdatedJpaToMongoEntityRelationship() {
|
|
||||||
Person found = entityManager.find(Person.class, 1L);
|
|
||||||
Assert.assertNotNull(found);
|
|
||||||
Assert.assertEquals(Long.valueOf(1), found.getId());
|
|
||||||
Assert.assertNotNull(found);
|
|
||||||
Assert.assertEquals(Long.valueOf(1), found.getId());
|
|
||||||
Assert.assertNotNull(found.getResume());
|
|
||||||
Assert.assertEquals("DiMark, DBA, 1990-2000" + "; "
|
|
||||||
+ "VMware, Developer, 2007-" + "; "
|
|
||||||
+ "SpringDeveloper.com, Consultant, 2005-2006", found.getResume().getJobs());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMergeJpaEntityWithMongoDocument() {
|
|
||||||
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
|
|
||||||
final Person detached = entityManager.find(Person.class, 1L);
|
|
||||||
detached.getResume().addJob("TargetRx, Developer, 2000-2005");
|
|
||||||
Person merged = txTemplate.execute(new TransactionCallback<Person>() {
|
|
||||||
public Person doInTransaction(TransactionStatus status) {
|
|
||||||
return entityManager.merge(detached);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Assert.assertTrue(detached.getResume().getJobs().contains("TargetRx, Developer, 2000-2005"));
|
|
||||||
Assert.assertTrue(merged.getResume().getJobs().contains("TargetRx, Developer, 2000-2005"));
|
|
||||||
final Person updated = entityManager.find(Person.class, 1L);
|
|
||||||
Assert.assertTrue(updated.getResume().getJobs().contains("TargetRx, Developer, 2000-2005"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRemoveJpaEntityWithMongoDocument() {
|
|
||||||
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
|
|
||||||
txTemplate.execute(new TransactionCallback<Person>() {
|
|
||||||
public Person doInTransaction(TransactionStatus status) {
|
|
||||||
Person p2 = new Person("Thomas", 20);
|
|
||||||
Resume r2 = new Resume();
|
|
||||||
r2.addEducation("Skanstulls High School, 1975");
|
|
||||||
r2.addJob("DiMark, DBA, 1990-2000");
|
|
||||||
p2.setResume(r2);
|
|
||||||
p2.setId(2L);
|
|
||||||
entityManager.persist(p2);
|
|
||||||
Person p3 = new Person("Thomas", 20);
|
|
||||||
Resume r3 = new Resume();
|
|
||||||
r3.addEducation("Univ. of Stockholm, 1980");
|
|
||||||
r3.addJob("VMware, Developer, 2007-");
|
|
||||||
p3.setResume(r3);
|
|
||||||
p3.setId(3L);
|
|
||||||
entityManager.persist(p3);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
txTemplate.execute(new TransactionCallback<Person>() {
|
|
||||||
public Person doInTransaction(TransactionStatus status) {
|
|
||||||
final Person found2 = entityManager.find(Person.class, 2L);
|
|
||||||
entityManager.remove(found2);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
boolean weFound3 = false;
|
|
||||||
for (DBObject dbo : this.mongoTemplate.getCollection(Person.class.getName()).find()) {
|
|
||||||
Assert.assertTrue(!dbo.get("_entity_id").equals(2L));
|
|
||||||
if (dbo.get("_entity_id").equals(3L)) {
|
|
||||||
weFound3 = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Assert.assertTrue(weFound3);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
package org.springframework.data.document.persistence.test;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
import org.springframework.data.persistence.document.RelatedDocument;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Person {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
Long id;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private int age;
|
|
||||||
|
|
||||||
private java.util.Date birthDate;
|
|
||||||
|
|
||||||
@RelatedDocument
|
|
||||||
private Address address;
|
|
||||||
|
|
||||||
@RelatedDocument
|
|
||||||
private Resume resume;
|
|
||||||
|
|
||||||
public Person() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Person(String name, int age) {
|
|
||||||
this.name = name;
|
|
||||||
this.age = age;
|
|
||||||
this.birthDate = new java.util.Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void birthday() {
|
|
||||||
++age;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAge() {
|
|
||||||
return age;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAge(int age) {
|
|
||||||
this.age = age;
|
|
||||||
}
|
|
||||||
|
|
||||||
public java.util.Date getBirthDate() {
|
|
||||||
return birthDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBirthDate(java.util.Date birthDate) {
|
|
||||||
this.birthDate = birthDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Resume getResume() {
|
|
||||||
return resume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResume(Resume resume) {
|
|
||||||
this.resume = resume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Address getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAddress(Address address) {
|
|
||||||
this.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package org.springframework.data.document.persistence.test;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.Document;
|
|
||||||
|
|
||||||
@Document
|
|
||||||
public class Resume {
|
|
||||||
|
|
||||||
private static final Log LOGGER = LogFactory.getLog(Resume.class);
|
|
||||||
|
|
||||||
@Id
|
|
||||||
private ObjectId id;
|
|
||||||
|
|
||||||
private String education = "";
|
|
||||||
|
|
||||||
private String jobs = "";
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEducation() {
|
|
||||||
return education;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addEducation(String education) {
|
|
||||||
LOGGER.debug("Adding education " + education);
|
|
||||||
this.education = this.education + (this.education.length() > 0 ? "; " : "") + education;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getJobs() {
|
|
||||||
return jobs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addJob(String job) {
|
|
||||||
LOGGER.debug("Adding job " + job);
|
|
||||||
this.jobs = this.jobs + (this.jobs.length() > 0 ? "; " : "") + job;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Resume [education=" + education + ", jobs=" + jobs + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.crossstore;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.data.mongodb.crossstore.test.Address;
|
||||||
|
import org.springframework.data.mongodb.crossstore.test.Person;
|
||||||
|
import org.springframework.data.mongodb.crossstore.test.Resume;
|
||||||
|
import org.springframework.test.annotation.Rollback;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.TransactionStatus;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.transaction.support.TransactionCallback;
|
||||||
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
|
import com.mongodb.DBCollection;
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext.xml")
|
||||||
|
public class CrossStoreMongoTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PlatformTransactionManager transactionManager;
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
public void setEntityManager(EntityManager entityManager) {
|
||||||
|
this.entityManager = entityManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearData(String collectionName) {
|
||||||
|
DBCollection col = this.mongoTemplate.getCollection(collectionName);
|
||||||
|
if (col != null) {
|
||||||
|
this.mongoTemplate.dropCollection(collectionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback(false)
|
||||||
|
public void testCreateJpaToMongoEntityRelationship() {
|
||||||
|
clearData(Person.class.getName());
|
||||||
|
Person p = new Person("Thomas", 20);
|
||||||
|
Address a = new Address(12, "MAin St.", "Boston", "MA", "02101");
|
||||||
|
p.setAddress(a);
|
||||||
|
Resume r = new Resume();
|
||||||
|
r.addEducation("Skanstulls High School, 1975");
|
||||||
|
r.addEducation("Univ. of Stockholm, 1980");
|
||||||
|
r.addJob("DiMark, DBA, 1990-2000");
|
||||||
|
r.addJob("VMware, Developer, 2007-");
|
||||||
|
p.setResume(r);
|
||||||
|
p.setId(1L);
|
||||||
|
entityManager.persist(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback(false)
|
||||||
|
public void testReadJpaToMongoEntityRelationship() {
|
||||||
|
Person found = entityManager.find(Person.class, 1L);
|
||||||
|
Assert.assertNotNull(found);
|
||||||
|
Assert.assertEquals(Long.valueOf(1), found.getId());
|
||||||
|
Assert.assertNotNull(found);
|
||||||
|
Assert.assertEquals(Long.valueOf(1), found.getId());
|
||||||
|
Assert.assertNotNull(found.getResume());
|
||||||
|
Assert.assertEquals("DiMark, DBA, 1990-2000" + "; " + "VMware, Developer, 2007-", found.getResume().getJobs());
|
||||||
|
found.getResume().addJob("SpringDeveloper.com, Consultant, 2005-2006");
|
||||||
|
found.setAge(44);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback(false)
|
||||||
|
public void testUpdatedJpaToMongoEntityRelationship() {
|
||||||
|
Person found = entityManager.find(Person.class, 1L);
|
||||||
|
Assert.assertNotNull(found);
|
||||||
|
Assert.assertEquals(Long.valueOf(1), found.getId());
|
||||||
|
Assert.assertNotNull(found);
|
||||||
|
Assert.assertEquals(Long.valueOf(1), found.getId());
|
||||||
|
Assert.assertNotNull(found.getResume());
|
||||||
|
Assert.assertEquals("DiMark, DBA, 1990-2000" + "; " + "VMware, Developer, 2007-" + "; "
|
||||||
|
+ "SpringDeveloper.com, Consultant, 2005-2006", found.getResume().getJobs());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeJpaEntityWithMongoDocument() {
|
||||||
|
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
|
||||||
|
final Person detached = entityManager.find(Person.class, 1L);
|
||||||
|
detached.getResume().addJob("TargetRx, Developer, 2000-2005");
|
||||||
|
Person merged = txTemplate.execute(new TransactionCallback<Person>() {
|
||||||
|
public Person doInTransaction(TransactionStatus status) {
|
||||||
|
return entityManager.merge(detached);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Assert.assertTrue(detached.getResume().getJobs().contains("TargetRx, Developer, 2000-2005"));
|
||||||
|
Assert.assertTrue(merged.getResume().getJobs().contains("TargetRx, Developer, 2000-2005"));
|
||||||
|
final Person updated = entityManager.find(Person.class, 1L);
|
||||||
|
Assert.assertTrue(updated.getResume().getJobs().contains("TargetRx, Developer, 2000-2005"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveJpaEntityWithMongoDocument() {
|
||||||
|
TransactionTemplate txTemplate = new TransactionTemplate(transactionManager);
|
||||||
|
txTemplate.execute(new TransactionCallback<Person>() {
|
||||||
|
public Person doInTransaction(TransactionStatus status) {
|
||||||
|
Person p2 = new Person("Thomas", 20);
|
||||||
|
Resume r2 = new Resume();
|
||||||
|
r2.addEducation("Skanstulls High School, 1975");
|
||||||
|
r2.addJob("DiMark, DBA, 1990-2000");
|
||||||
|
p2.setResume(r2);
|
||||||
|
p2.setId(2L);
|
||||||
|
entityManager.persist(p2);
|
||||||
|
Person p3 = new Person("Thomas", 20);
|
||||||
|
Resume r3 = new Resume();
|
||||||
|
r3.addEducation("Univ. of Stockholm, 1980");
|
||||||
|
r3.addJob("VMware, Developer, 2007-");
|
||||||
|
p3.setResume(r3);
|
||||||
|
p3.setId(3L);
|
||||||
|
entityManager.persist(p3);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
txTemplate.execute(new TransactionCallback<Person>() {
|
||||||
|
public Person doInTransaction(TransactionStatus status) {
|
||||||
|
final Person found2 = entityManager.find(Person.class, 2L);
|
||||||
|
entityManager.remove(found2);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
boolean weFound3 = false;
|
||||||
|
for (DBObject dbo : this.mongoTemplate.getCollection(Person.class.getName()).find()) {
|
||||||
|
Assert.assertTrue(!dbo.get("_entity_id").equals(2L));
|
||||||
|
if (dbo.get("_entity_id").equals(3L)) {
|
||||||
|
weFound3 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Assert.assertTrue(weFound3);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,15 +1,29 @@
|
|||||||
package org.springframework.data.document.persistence.test;
|
/*
|
||||||
|
* Copyright 2011 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.crossstore.test;
|
||||||
|
|
||||||
public class Address {
|
public class Address {
|
||||||
|
|
||||||
private Integer streetNumber;
|
private Integer streetNumber;
|
||||||
private String streetName;
|
private String streetName;
|
||||||
private String city;
|
private String city;
|
||||||
private String state;
|
private String state;
|
||||||
private String zip;
|
private String zip;
|
||||||
|
|
||||||
public Address(Integer streetNumber, String streetName, String city,
|
public Address(Integer streetNumber, String streetName, String city, String state, String zip) {
|
||||||
String state, String zip) {
|
|
||||||
super();
|
super();
|
||||||
this.streetNumber = streetNumber;
|
this.streetNumber = streetNumber;
|
||||||
this.streetName = streetName;
|
this.streetName = streetName;
|
||||||
@@ -17,38 +31,45 @@ public class Address {
|
|||||||
this.state = state;
|
this.state = state;
|
||||||
this.zip = zip;
|
this.zip = zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getStreetNumber() {
|
public Integer getStreetNumber() {
|
||||||
return streetNumber;
|
return streetNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStreetNumber(Integer streetNumber) {
|
public void setStreetNumber(Integer streetNumber) {
|
||||||
this.streetNumber = streetNumber;
|
this.streetNumber = streetNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStreetName() {
|
public String getStreetName() {
|
||||||
return streetName;
|
return streetName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStreetName(String streetName) {
|
public void setStreetName(String streetName) {
|
||||||
this.streetName = streetName;
|
this.streetName = streetName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCity() {
|
public String getCity() {
|
||||||
return city;
|
return city;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCity(String city) {
|
public void setCity(String city) {
|
||||||
this.city = city;
|
this.city = city;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getState() {
|
public String getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setState(String state) {
|
public void setState(String state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZip() {
|
public String getZip() {
|
||||||
return zip;
|
return zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setZip(String zip) {
|
public void setZip(String zip) {
|
||||||
this.zip = zip;
|
this.zip = zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.crossstore.test;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import org.springframework.data.mongodb.crossstore.RelatedDocument;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Person {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private int age;
|
||||||
|
|
||||||
|
private java.util.Date birthDate;
|
||||||
|
|
||||||
|
@RelatedDocument
|
||||||
|
private Address address;
|
||||||
|
|
||||||
|
@RelatedDocument
|
||||||
|
private Resume resume;
|
||||||
|
|
||||||
|
public Person() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person(String name, int age) {
|
||||||
|
this.name = name;
|
||||||
|
this.age = age;
|
||||||
|
this.birthDate = new java.util.Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void birthday() {
|
||||||
|
++age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public java.util.Date getBirthDate() {
|
||||||
|
return birthDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBirthDate(java.util.Date birthDate) {
|
||||||
|
this.birthDate = birthDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Resume getResume() {
|
||||||
|
return resume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResume(Resume resume) {
|
||||||
|
this.resume = resume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Address getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(Address address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.crossstore.test;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
@Document
|
||||||
|
public class Resume {
|
||||||
|
|
||||||
|
private static final Log LOGGER = LogFactory.getLog(Resume.class);
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private ObjectId id;
|
||||||
|
|
||||||
|
private String education = "";
|
||||||
|
|
||||||
|
private String jobs = "";
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEducation() {
|
||||||
|
return education;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEducation(String education) {
|
||||||
|
LOGGER.debug("Adding education " + education);
|
||||||
|
this.education = this.education + (this.education.length() > 0 ? "; " : "") + education;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJobs() {
|
||||||
|
return jobs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addJob(String job) {
|
||||||
|
LOGGER.debug("Adding job " + job);
|
||||||
|
this.jobs = this.jobs + (this.jobs.length() > 0 ? "; " : "") + job;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Resume [education=" + education + ", jobs=" + jobs + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
||||||
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
|
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
|
||||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||||
<class>org.springframework.data.document.persistence.test.Person</class>
|
<class>org.springframework.data.mongodb.crossstore.test.Person</class>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
|
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
|
||||||
<!--value='create' to build a new database on each run; value='update' to modify an existing database; value='create-drop' means the same as 'create' but also drops tables when Hibernate closes; value='validate' makes no changes to the database-->
|
<!--value='create' to build a new database on each run; value='update' to modify an existing database; value='create-drop' means the same as 'create' but also drops tables when Hibernate closes; value='validate' makes no changes to the database-->
|
||||||
|
|||||||
@@ -13,37 +13,37 @@
|
|||||||
|
|
||||||
<context:spring-configured/>
|
<context:spring-configured/>
|
||||||
|
|
||||||
<context:component-scan base-package="org.springframework.persistence.test">
|
<context:component-scan base-package="org.springframework.persistence.mongodb.test">
|
||||||
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
|
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
|
||||||
</context:component-scan>
|
</context:component-scan>
|
||||||
|
|
||||||
<mongo:mapping-converter/>
|
<mongo:mapping-converter/>
|
||||||
|
|
||||||
<!-- Mongo config -->
|
<!-- Mongo config -->
|
||||||
<bean id="mongo" class="org.springframework.data.document.mongodb.MongoFactoryBean">
|
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
|
||||||
<property name="host" value="localhost"/>
|
<property name="host" value="localhost"/>
|
||||||
<property name="port" value="27017"/>
|
<property name="port" value="27017"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="mongoDbFactory" class="org.springframework.data.document.mongodb.SimpleMongoDbFactory">
|
<bean id="mongoDbFactory" class="org.springframework.data.mongodb.core.SimpleMongoDbFactory">
|
||||||
<constructor-arg name="mongo" ref="mongo"/>
|
<constructor-arg name="mongo" ref="mongo"/>
|
||||||
<constructor-arg name="databaseName" value="database"/>
|
<constructor-arg name="databaseName" value="database"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
|
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
|
||||||
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
|
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
|
||||||
<constructor-arg name="mongoConverter" ref="mappingConverter"/>
|
<constructor-arg name="mongoConverter" ref="mappingConverter"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean class="org.springframework.data.document.mongodb.MongoExceptionTranslator"/>
|
<bean class="org.springframework.data.mongodb.core.MongoExceptionTranslator"/>
|
||||||
|
|
||||||
<!-- Mongo aspect config -->
|
<!-- Mongo aspect config -->
|
||||||
<bean class="org.springframework.data.persistence.document.mongodb.MongoDocumentBacking"
|
<bean class="org.springframework.data.mongodb.crossstore.MongoDocumentBacking"
|
||||||
factory-method="aspectOf">
|
factory-method="aspectOf">
|
||||||
<property name="changeSetPersister" ref="mongoChangeSetPersister"/>
|
<property name="changeSetPersister" ref="mongoChangeSetPersister"/>
|
||||||
</bean>
|
</bean>
|
||||||
<bean id="mongoChangeSetPersister"
|
<bean id="mongoChangeSetPersister"
|
||||||
class="org.springframework.data.persistence.document.mongodb.MongoChangeSetPersister">
|
class="org.springframework.data.mongodb.crossstore.MongoChangeSetPersister">
|
||||||
<property name="mongoTemplate" ref="mongoTemplate"/>
|
<property name="mongoTemplate" ref="mongoTemplate"/>
|
||||||
<property name="entityManagerFactory" ref="entityManagerFactory"/>
|
<property name="entityManagerFactory" ref="entityManagerFactory"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ log4j.rootCategory=INFO, stdout
|
|||||||
|
|
||||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
|
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n
|
||||||
|
|
||||||
log4j.category.org.springframework=INFO
|
log4j.category.org.springframework=INFO
|
||||||
log4j.category.org.springframework.data=TRACE
|
log4j.category.org.springframework.data=TRACE
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ and connects directly to the MongoDB server using the driver. It has no dependen
|
|||||||
|
|
||||||
To use it, configure a host, port, (optionally) applicationId, and database property in your Log4J configuration:
|
To use it, configure a host, port, (optionally) applicationId, and database property in your Log4J configuration:
|
||||||
|
|
||||||
log4j.appender.stdout=org.springframework.data.document.mongodb.log4j.MongoLog4jAppender
|
log4j.appender.stdout=org.springframework.data.mongodb.log4j.MongoLog4jAppender
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
|
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
|
||||||
log4j.appender.stdout.host = localhost
|
log4j.appender.stdout.host = localhost
|
||||||
@@ -32,7 +32,7 @@ An example log entry might look like:
|
|||||||
{
|
{
|
||||||
"_id" : ObjectId("4d89341a8ef397e06940d5cd"),
|
"_id" : ObjectId("4d89341a8ef397e06940d5cd"),
|
||||||
"applicationId" : "my.application",
|
"applicationId" : "my.application",
|
||||||
"name" : "org.springframework.data.document.mongodb.log4j.AppenderTest",
|
"name" : "org.springframework.data.mongodb.log4j.AppenderTest",
|
||||||
"level" : "DEBUG",
|
"level" : "DEBUG",
|
||||||
"timestamp" : ISODate("2011-03-23T16:53:46.778Z"),
|
"timestamp" : ISODate("2011-03-23T16:53:46.778Z"),
|
||||||
"properties" : {
|
"properties" : {
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-document-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>1.0.0.M3</version>
|
<version>1.1.0.M1</version>
|
||||||
<relativePath>../spring-data-document-parent/pom.xml</relativePath>
|
<relativePath>../spring-data-mongodb-parent/pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>spring-data-mongodb-log4j</artifactId>
|
<artifactId>spring-data-mongodb-log4j</artifactId>
|
||||||
<packaging>jar</packaging>
|
|
||||||
<name>Spring Data MongoDB Log4J Appender</name>
|
<name>Spring Data MongoDB Log4J Appender</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -29,45 +27,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<exclusions>
|
<version>${log4j.version}</version>
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.mail</groupId>
|
|
||||||
<artifactId>mail</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.jms</groupId>
|
|
||||||
<artifactId>jms</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jdmk</groupId>
|
|
||||||
<artifactId>jmxtools</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>com.sun.jmx</groupId>
|
|
||||||
<artifactId>jmxri</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Test dependencies -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-all</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-all</artifactId>
|
|
||||||
<version>1.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb.log4j;
|
package org.springframework.data.mongodb.log4j;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb.log4j;
|
package org.springframework.data.mongodb.log4j;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
log4j.rootCategory=INFO, stdout
|
log4j.rootCategory=INFO, stdout
|
||||||
|
|
||||||
log4j.appender.stdout=org.springframework.data.document.mongodb.log4j.MongoLog4jAppender
|
log4j.appender.stdout=org.springframework.data.mongodb.log4j.MongoLog4jAppender
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
|
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
|
||||||
log4j.appender.stdout.host = localhost
|
log4j.appender.stdout.host = localhost
|
||||||
|
|||||||
271
spring-data-mongodb-parent/pom.xml
Normal file
271
spring-data-mongodb-parent/pom.xml
Normal file
@@ -0,0 +1,271 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
|
<name>Spring Data MongoDB Parent</name>
|
||||||
|
<url>http://www.springsource.org/spring-data/mongodb</url>
|
||||||
|
<version>1.1.0.M1</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<!-- versions for commonly-used dependencies -->
|
||||||
|
<junit.version>4.8.1</junit.version>
|
||||||
|
<log4j.version>1.2.16</log4j.version>
|
||||||
|
<org.mockito.version>1.8.4</org.mockito.version>
|
||||||
|
<org.slf4j.version>1.6.1</org.slf4j.version>
|
||||||
|
<org.codehaus.jackson.version>1.6.1</org.codehaus.jackson.version>
|
||||||
|
<org.springframework.version.30>3.0.7.RELEASE</org.springframework.version.30>
|
||||||
|
<org.springframework.version.40>4.0.0.RELEASE</org.springframework.version.40>
|
||||||
|
<org.springframework.version.range>[${org.springframework.version.30}, ${org.springframework.version.40})</org.springframework.version.range>
|
||||||
|
<data.commons.version>1.3.0.RC2</data.commons.version>
|
||||||
|
<aspectj.version>1.6.11.RELEASE</aspectj.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<!-- see 'staging' profile for dry-run deployment settings -->
|
||||||
|
<downloadUrl>http://www.springsource.com/download/community
|
||||||
|
</downloadUrl>
|
||||||
|
<site>
|
||||||
|
<id>static.springframework.org</id>
|
||||||
|
<url>
|
||||||
|
scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/data-mongodb/snapshot-site
|
||||||
|
</url>
|
||||||
|
</site>
|
||||||
|
<repository>
|
||||||
|
<id>spring-milestone</id>
|
||||||
|
<name>Spring Milestone Repository</name>
|
||||||
|
<url>s3://maven.springframework.org/milestone</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>spring-snapshot</id>
|
||||||
|
<name>Spring Snapshot Repository</name>
|
||||||
|
<url>s3://maven.springframework.org/snapshot</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- Test dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-all</artifactId>
|
||||||
|
<version>${org.mockito.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest-all</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>joda-time</groupId>
|
||||||
|
<artifactId>joda-time</artifactId>
|
||||||
|
<version>1.6</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>${log4j.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
<version>${org.springframework.version.range}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<extensions>
|
||||||
|
<extension>
|
||||||
|
<!--
|
||||||
|
available only in the springframework maven repository. see
|
||||||
|
<repositories> section below
|
||||||
|
-->
|
||||||
|
<groupId>org.springframework.build.aws</groupId>
|
||||||
|
<artifactId>org.springframework.build.aws.maven</artifactId>
|
||||||
|
<version>3.1.0.RELEASE</version>
|
||||||
|
</extension>
|
||||||
|
</extensions>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.basedir}/src/main/java</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.basedir}/src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<testResources>
|
||||||
|
<testResource>
|
||||||
|
<directory>${project.basedir}/src/test/java</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</testResource>
|
||||||
|
<testResource>
|
||||||
|
<directory>${project.basedir}/src/test/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>**/*</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</testResource>
|
||||||
|
</testResources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>2.3.2</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.5</source>
|
||||||
|
<target>1.5</target>
|
||||||
|
<compilerArgument>-Xlint:-path</compilerArgument>
|
||||||
|
<showWarnings>true</showWarnings>
|
||||||
|
<showDeprecation>false</showDeprecation>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>2.3.1</version>
|
||||||
|
<configuration>
|
||||||
|
<useDefaultManifestFile>true</useDefaultManifestFile>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.8</version>
|
||||||
|
<configuration>
|
||||||
|
<useFile>false</useFile>
|
||||||
|
<includes>
|
||||||
|
<include>**/*Tests.java</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/PerformanceTests.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
<junitArtifactName>junit:junit</junitArtifactName>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>2.1.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<!--
|
||||||
|
configures the springsource bundlor plugin, which generates
|
||||||
|
OSGI-compatible MANIFEST.MF files during the 'compile' phase of
|
||||||
|
the maven build. this plugin is declared within the
|
||||||
|
pluginManagement section because not every module that inherits
|
||||||
|
from this pom needs bundlor's services, e.g.:
|
||||||
|
spring-integration-samples and all its children. for this reason,
|
||||||
|
all modules that wish to use bundlor must declare it explicitly.
|
||||||
|
it is not necessary to specify the <version> or <configuration>
|
||||||
|
sections, but groupId and artifactId are required. see
|
||||||
|
http://static.springsource.org/s2-bundlor/1.0.x/user-guide/html/ch04s03.html
|
||||||
|
for more info
|
||||||
|
-->
|
||||||
|
<groupId>com.springsource.bundlor</groupId>
|
||||||
|
<artifactId>com.springsource.bundlor.maven</artifactId>
|
||||||
|
<version>1.0.0.RELEASE</version>
|
||||||
|
<configuration>
|
||||||
|
<failOnWarnings>true</failOnWarnings>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>bundlor</id>
|
||||||
|
<goals>
|
||||||
|
<goal>bundlor</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>spring-plugins-release</id>
|
||||||
|
<url>http://repo.springsource.org/plugins-release</url>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spring-libs-snapshot</id>
|
||||||
|
<url>http://repo.springsource.org/libs-snapshot</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<!--
|
||||||
|
significantly speeds up the 'Dependencies' report during site
|
||||||
|
creation see
|
||||||
|
http://old.nabble.com/Skipping-dependency-report-during-Maven2-site-generation-td20116761.html
|
||||||
|
-->
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
<configuration>
|
||||||
|
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
|
</project>
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/java"/>
|
|
||||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
|
|
||||||
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
|
|
||||||
<classpathentry kind="src" output="target/test-classes" path="target/generated-sources/test-annotations"/>
|
|
||||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
|
||||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
|
||||||
</classpath>
|
|
||||||
146
spring-data-mongodb/Spring Data MongoDB.sonargraph
Normal file
146
spring-data-mongodb/Spring Data MongoDB.sonargraph
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<context version="7.0.3.1152">
|
||||||
|
<scope name="spring-data-mongodb" type="Project">
|
||||||
|
<element name="Filter" type="TypeFilterReferenceOverridden">
|
||||||
|
<element name="org.springframework.data.mongodb.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<architecture>
|
||||||
|
<element name="Config" type="Layer">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.config.**" type="WeakTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core"/>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Monitoring"/>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Repositories"/>
|
||||||
|
</element>
|
||||||
|
<element name="Repositories" type="Layer">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.repository.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<element name="API" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.repository.*" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
</element>
|
||||||
|
<element name="Query" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.query.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Repositories::Subsystem|API"/>
|
||||||
|
</element>
|
||||||
|
<element name="Implementation" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.support.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Repositories::Subsystem|API"/>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Repositories::Subsystem|Query"/>
|
||||||
|
</element>
|
||||||
|
<element name="Config" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.config.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Repositories::Subsystem|Implementation"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core"/>
|
||||||
|
</element>
|
||||||
|
<element name="Monitoring" type="Layer">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.monitor.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core"/>
|
||||||
|
</element>
|
||||||
|
<element name="GridFS" type="Layer">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.gridfs.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core"/>
|
||||||
|
</element>
|
||||||
|
<element name="Core" type="Layer">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.core.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<element name="Mapping" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.mapping.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
</element>
|
||||||
|
<element name="Geospatial" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.geo.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Mapping"/>
|
||||||
|
</element>
|
||||||
|
<element name="Query" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.query.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Geospatial"/>
|
||||||
|
</element>
|
||||||
|
<element name="Index" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.index.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Mapping"/>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Query"/>
|
||||||
|
</element>
|
||||||
|
<element name="Core" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="**.core.**" type="WeakTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Geospatial"/>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Index"/>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Mapping"/>
|
||||||
|
<dependency type="AllowedDependency" toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Query"/>
|
||||||
|
</element>
|
||||||
|
</element>
|
||||||
|
</architecture>
|
||||||
|
<workspace>
|
||||||
|
<element name="src/main/java" type="JavaRootDirectory">
|
||||||
|
<reference name="Project|spring-data-mongodb::BuildUnit|spring-data-mongodb"/>
|
||||||
|
</element>
|
||||||
|
<element name="target/classes" type="JavaRootDirectory">
|
||||||
|
<reference name="Project|spring-data-mongodb::BuildUnit|spring-data-mongodb"/>
|
||||||
|
</element>
|
||||||
|
</workspace>
|
||||||
|
<physical>
|
||||||
|
<element name="spring-data-mongodb" type="BuildUnit"/>
|
||||||
|
</physical>
|
||||||
|
</scope>
|
||||||
|
<scope name="External" type="External">
|
||||||
|
<element name="Filter" type="TypeFilter">
|
||||||
|
<element name="**" type="IncludeTypePattern"/>
|
||||||
|
<element name="java.**" type="ExcludeTypePattern"/>
|
||||||
|
<element name="javax.**" type="ExcludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
<architecture>
|
||||||
|
<element name="Spring" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="org.springframework.**" type="IncludeTypePattern"/>
|
||||||
|
<element name="org.springframework.data.**" type="ExcludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
</element>
|
||||||
|
<element name="Spring Data Core" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="org.springframework.data.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
</element>
|
||||||
|
<element name="Mongo Java Driver" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="com.mongodb.**" type="IncludeTypePattern"/>
|
||||||
|
<element name="org.bson.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
</element>
|
||||||
|
<element name="Querydsl" type="Subsystem">
|
||||||
|
<element name="Assignment" type="TypeFilter">
|
||||||
|
<element name="com.mysema.query.**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
</element>
|
||||||
|
</architecture>
|
||||||
|
</scope>
|
||||||
|
<scope name="Global" type="Global">
|
||||||
|
<element name="Configuration" type="Configuration"/>
|
||||||
|
<element name="Filter" type="TypeFilter">
|
||||||
|
<element name="**" type="IncludeTypePattern"/>
|
||||||
|
</element>
|
||||||
|
</scope>
|
||||||
|
</context>
|
||||||
291
spring-data-mongodb/etc/eclipse-formatter.xml
Normal file
291
spring-data-mongodb/etc/eclipse-formatter.xml
Normal file
@@ -0,0 +1,291 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<profiles version="12">
|
||||||
|
<profile kind="CodeFormatterProfile" name="Spring Data" version="12">
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.source" value="1.7"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="2"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="tab"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.7"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="120"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.7"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
|
||||||
|
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
@@ -1,37 +1,56 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-document-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>1.0.0.M3</version>
|
<version>1.1.0.M1</version>
|
||||||
<relativePath>../spring-data-document-parent/pom.xml</relativePath>
|
<relativePath>../spring-data-mongodb-parent/pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>spring-data-mongodb</artifactId>
|
<artifactId>spring-data-mongodb</artifactId>
|
||||||
<packaging>jar</packaging>
|
<name>Spring Data MongoDB</name>
|
||||||
<name>Spring Data MongoDB Support</name>
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<mongo.version>2.5.3</mongo.version>
|
<mongo.version>2.7.1</mongo.version>
|
||||||
<querydsl.version>2.2.0-beta4</querydsl.version>
|
<querydsl.version>2.5.0</querydsl.version>
|
||||||
|
<cdi.version>1.0</cdi.version>
|
||||||
|
<validation.version>1.0.0.GA</validation.version>
|
||||||
|
<webbeans.version>1.1.3</webbeans.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- Spring -->
|
<!-- Spring -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-tx</artifactId>
|
||||||
|
<version>${org.springframework.version.range}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<version>${org.springframework.version.range}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-beans</artifactId>
|
<artifactId>spring-beans</artifactId>
|
||||||
|
<version>${org.springframework.version.range}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-core</artifactId>
|
||||||
|
<version>${org.springframework.version.range}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-expression</artifactId>
|
<artifactId>spring-expression</artifactId>
|
||||||
</dependency>
|
<version>${org.springframework.version.range}</version>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Data -->
|
<!-- Spring Data -->
|
||||||
@@ -77,58 +96,80 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.annotation</groupId>
|
<groupId>javax.annotation</groupId>
|
||||||
<artifactId>jsr250-api</artifactId>
|
<artifactId>jsr250-api</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- CDI -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.enterprise</groupId>
|
||||||
|
<artifactId>cdi-api</artifactId>
|
||||||
|
<version>${cdi.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.el</groupId>
|
||||||
|
<artifactId>el-api</artifactId>
|
||||||
|
<version>${cdi.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.openwebbeans.test</groupId>
|
||||||
|
<artifactId>cditest-owb</artifactId>
|
||||||
|
<version>${webbeans.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>servlet-api</artifactId>
|
||||||
|
<version>2.5</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JSR 303 Validation -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.validation</groupId>
|
||||||
|
<artifactId>validation-api</artifactId>
|
||||||
|
<version>${validation.version}</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Test dependencies -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>hibernate-validator</artifactId>
|
||||||
<scope>test</scope>
|
<version>4.2.0.Final</version>
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-all</artifactId>
|
|
||||||
<version>1.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>joda-time</groupId>
|
|
||||||
<artifactId>joda-time</artifactId>
|
|
||||||
<version>1.6</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>performance-tests</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.8</version>
|
||||||
|
<configuration>
|
||||||
|
<includes>
|
||||||
|
<include>**/PerformanceTests.java</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>none</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -139,7 +180,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.mysema.maven</groupId>
|
<groupId>com.mysema.maven</groupId>
|
||||||
<artifactId>maven-apt-plugin</artifactId>
|
<artifactId>maven-apt-plugin</artifactId>
|
||||||
<version>1.0.1</version>
|
<version>1.0.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>generate-test-sources</phase>
|
<phase>generate-test-sources</phase>
|
||||||
@@ -148,22 +189,12 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<outputDirectory>target/generated-test-sources</outputDirectory>
|
<outputDirectory>target/generated-test-sources</outputDirectory>
|
||||||
<processor>org.springframework.data.document.mongodb.repository.MongoAnnotationProcessor</processor>
|
<processor>org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor</processor>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>querydsl</id>
|
|
||||||
<name>Mysema QueryDsl</name>
|
|
||||||
<url>http://source.mysema.com/maven2/releases</url>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>false</enabled>
|
|
||||||
</snapshots>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package org.springframework.data.document.mongodb;
|
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
|
|
||||||
import com.mongodb.DB;
|
|
||||||
|
|
||||||
public interface MongoDbFactory {
|
|
||||||
|
|
||||||
DB getDb() throws DataAccessException;
|
|
||||||
|
|
||||||
DB getDb(String dbName) throws DataAccessException;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
import com.mongodb.MongoOptions;
|
|
||||||
import com.mongodb.ServerAddress;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenient factory for configuring MongoDB.
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Graeme Rocher
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean, PersistenceExceptionTranslator {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logger, available to subclasses.
|
|
||||||
*/
|
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
private Mongo mongo;
|
|
||||||
private MongoOptions mongoOptions;
|
|
||||||
private String host;
|
|
||||||
private Integer port;
|
|
||||||
private List<ServerAddress> replicaSetSeeds;
|
|
||||||
private List<ServerAddress> replicaPair;
|
|
||||||
|
|
||||||
private PersistenceExceptionTranslator exceptionTranslator = new MongoExceptionTranslator();
|
|
||||||
|
|
||||||
public void setMongoOptions(MongoOptions mongoOptions) {
|
|
||||||
this.mongoOptions = mongoOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReplicaSetSeeds(List<ServerAddress> replicaSetSeeds) {
|
|
||||||
this.replicaSetSeeds = replicaSetSeeds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReplicaPair(List<ServerAddress> replicaPair) {
|
|
||||||
this.replicaPair = replicaPair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHost(String host) {
|
|
||||||
this.host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPort(int port) {
|
|
||||||
this.port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PersistenceExceptionTranslator getExceptionTranslator() {
|
|
||||||
return exceptionTranslator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator) {
|
|
||||||
this.exceptionTranslator = exceptionTranslator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mongo getObject() throws Exception {
|
|
||||||
Assert.notNull(mongo, "Mongo must not be null");
|
|
||||||
return mongo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<? extends Mongo> getObjectType() {
|
|
||||||
return Mongo.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSingleton() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
|
||||||
// apply defaults - convenient when used to configure for tests
|
|
||||||
// in an application context
|
|
||||||
if (mongo == null) {
|
|
||||||
|
|
||||||
if (host == null) {
|
|
||||||
logger.warn("Property host not specified. Using default configuration");
|
|
||||||
mongo = new Mongo();
|
|
||||||
} else {
|
|
||||||
ServerAddress defaultOptions = new ServerAddress();
|
|
||||||
if (mongoOptions == null)
|
|
||||||
mongoOptions = new MongoOptions();
|
|
||||||
if (replicaPair != null) {
|
|
||||||
if (replicaPair.size() < 2) {
|
|
||||||
throw new CannotGetMongoDbConnectionException("A replica pair must have two server entries");
|
|
||||||
}
|
|
||||||
mongo = new Mongo(replicaPair.get(0), replicaPair.get(1), mongoOptions);
|
|
||||||
} else if (replicaSetSeeds != null) {
|
|
||||||
mongo = new Mongo(replicaSetSeeds, mongoOptions);
|
|
||||||
} else {
|
|
||||||
String mongoHost = host != null ? host : defaultOptions.getHost();
|
|
||||||
if (port != null) {
|
|
||||||
mongo = new Mongo(new ServerAddress(mongoHost, port), mongoOptions);
|
|
||||||
} else {
|
|
||||||
mongo = new Mongo(mongoHost, mongoOptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
|
||||||
return exceptionTranslator.translateExceptionIfPossible(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,614 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.mongodb.CommandResult;
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.WriteResult;
|
|
||||||
|
|
||||||
import org.springframework.data.document.mongodb.index.IndexDefinition;
|
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
|
||||||
import org.springframework.data.document.mongodb.query.Update;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface that specifies a basic set of MongoDB operations. Implemented by {@link MongoTemplate}. Not often used but
|
|
||||||
* a useful option for extensibility and testability (as it can be easily mocked, stubbed, or be the target of a JDK
|
|
||||||
* proxy).
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Mark Pollack
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public interface MongoOperations {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The collection name used for the specified class by this template.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String getCollectionName(Class<?> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the a MongoDB command expressed as a JSON string. This will call the method JSON.parse that is part of the
|
|
||||||
* MongoDB driver to convert the JSON string to a DBObject. Any errors that result from executing this command will be
|
|
||||||
* converted into Spring's DAO exception hierarchy.
|
|
||||||
*
|
|
||||||
* @param jsonCommand
|
|
||||||
* a MongoDB command expressed as a JSON string.
|
|
||||||
*/
|
|
||||||
CommandResult executeCommand(String jsonCommand);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute a MongoDB command. Any errors that result from executing this command will be converted into Spring's DAO
|
|
||||||
* exception hierarchy.
|
|
||||||
*
|
|
||||||
* @param command
|
|
||||||
* a MongoDB command
|
|
||||||
*/
|
|
||||||
CommandResult executeCommand(DBObject command);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes a {@link DbCallback} translating any exceptions as necessary.
|
|
||||||
* <p/>
|
|
||||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* return type
|
|
||||||
* @param action
|
|
||||||
* callback object that specifies the MongoDB actions to perform on the passed in DB instance.
|
|
||||||
* @return a result object returned by the action or <tt>null</tt>
|
|
||||||
*/
|
|
||||||
<T> T execute(DbCallback<T> action);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the given {@link CollectionCallback} on the entity collection of the specified class.
|
|
||||||
* <p/>
|
|
||||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
|
||||||
*
|
|
||||||
* @param entityClass
|
|
||||||
* class that determines the collection to use
|
|
||||||
* @param <T>
|
|
||||||
* return type
|
|
||||||
* @param action
|
|
||||||
* callback object that specifies the MongoDB action
|
|
||||||
* @return a result object returned by the action or <tt>null</tt>
|
|
||||||
*/
|
|
||||||
<T> T execute(Class<?> entityClass, CollectionCallback<T> action);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the given {@link CollectionCallback} on the collection of the given name.
|
|
||||||
* <p/>
|
|
||||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* return type
|
|
||||||
* @param collectionName
|
|
||||||
* the name of the collection that specifies which DBCollection instance will be passed into
|
|
||||||
* @param action
|
|
||||||
* callback object that specifies the MongoDB action the callback action.
|
|
||||||
* @return a result object returned by the action or <tt>null</tt>
|
|
||||||
*/
|
|
||||||
<T> T execute(String collectionName, CollectionCallback<T> action);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the given {@link DbCallback} within the same connection to the database so as to ensure consistency in a
|
|
||||||
* write heavy environment where you may read the data that you wrote. See the comments on {@see <a
|
|
||||||
* href=http://www.mongodb.org/display/DOCS/Java+Driver+Concurrency>Java Driver Concurrency</a>}
|
|
||||||
* <p/>
|
|
||||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* return type
|
|
||||||
* @param action
|
|
||||||
* callback that specified the MongoDB actions to perform on the DB instance
|
|
||||||
* @return a result object returned by the action or <tt>null</tt>
|
|
||||||
*/
|
|
||||||
<T> T executeInSession(DbCallback<T> action);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an uncapped collection with a name based on the provided entity class.
|
|
||||||
*
|
|
||||||
* @param entityClass
|
|
||||||
* class that determines the collection to create
|
|
||||||
* @return the created collection
|
|
||||||
*/
|
|
||||||
<T> DBCollection createCollection(Class<T> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a collect with a name based on the provided entity class using the options.
|
|
||||||
*
|
|
||||||
* @param entityClass
|
|
||||||
* class that determines the collection to create
|
|
||||||
* @param collectionOptions
|
|
||||||
* options to use when creating the collection.
|
|
||||||
* @return the created collection
|
|
||||||
*/
|
|
||||||
<T> DBCollection createCollection(Class<T> entityClass, CollectionOptions collectionOptions);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an uncapped collection with the provided name.
|
|
||||||
*
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection
|
|
||||||
* @return the created collection
|
|
||||||
*/
|
|
||||||
DBCollection createCollection(String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a collect with the provided name and options.
|
|
||||||
*
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection
|
|
||||||
* @param collectionOptions
|
|
||||||
* options to use when creating the collection.
|
|
||||||
* @return the created collection
|
|
||||||
*/
|
|
||||||
DBCollection createCollection(String collectionName, CollectionOptions collectionOptions);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A set of collection names.
|
|
||||||
*
|
|
||||||
* @return list of collection names
|
|
||||||
*/
|
|
||||||
Set<String> getCollectionNames();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a collection by name, creating it if it doesn't exist.
|
|
||||||
* <p/>
|
|
||||||
* Translate any exceptions as necessary.
|
|
||||||
*
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection
|
|
||||||
* @return an existing collection or a newly created one.
|
|
||||||
*/
|
|
||||||
DBCollection getCollection(String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check to see if a collection with a name indicated by the entity class exists.
|
|
||||||
* <p/>
|
|
||||||
* Translate any exceptions as necessary.
|
|
||||||
*
|
|
||||||
* @param entityClass
|
|
||||||
* class that determines the name of the collection
|
|
||||||
* @return true if a collection with the given name is found, false otherwise.
|
|
||||||
*/
|
|
||||||
<T> boolean collectionExists(Class<T> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check to see if a collection with a given name exists.
|
|
||||||
* <p/>
|
|
||||||
* Translate any exceptions as necessary.
|
|
||||||
*
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection
|
|
||||||
* @return true if a collection with the given name is found, false otherwise.
|
|
||||||
*/
|
|
||||||
boolean collectionExists(String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drop the collection with the name indicated by the entity class.
|
|
||||||
* <p/>
|
|
||||||
* Translate any exceptions as necessary.
|
|
||||||
*
|
|
||||||
* @param entityClass
|
|
||||||
* class that determines the collection to drop/delete.
|
|
||||||
*/
|
|
||||||
<T> void dropCollection(Class<T> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drop the collection with the given name.
|
|
||||||
* <p/>
|
|
||||||
* Translate any exceptions as necessary.
|
|
||||||
*
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to drop/delete.
|
|
||||||
*/
|
|
||||||
void dropCollection(String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query for a list of objects of type T from the collection used by the entity class.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
|
|
||||||
* to map objects since the test for class type is done in the client and not on the server.
|
|
||||||
*
|
|
||||||
* @param entityClass
|
|
||||||
* the parameterized type of the returned list
|
|
||||||
* @return the converted collection
|
|
||||||
*/
|
|
||||||
<T> List<T> findAll(Class<T> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query for a list of objects of type T from the specified collection.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
|
|
||||||
* to map objects since the test for class type is done in the client and not on the server.
|
|
||||||
*
|
|
||||||
* @param entityClass
|
|
||||||
* the parameterized type of the returned list.
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to retrieve the objects from
|
|
||||||
* @return the converted collection
|
|
||||||
*/
|
|
||||||
<T> List<T> findAll(Class<T> entityClass, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensure that an index for the provided {@link IndexDefinition} exists for the collection indicated by the entity class.
|
|
||||||
* If not it will be created.
|
|
||||||
*
|
|
||||||
* @param indexDefinition
|
|
||||||
* @param entityClass
|
|
||||||
* class that determines the collection to use
|
|
||||||
*/
|
|
||||||
void ensureIndex(IndexDefinition indexDefinition, Class<?> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensure that an index for the provided {@link IndexDefinition} exists. If not it will be created.
|
|
||||||
*
|
|
||||||
* @param index
|
|
||||||
* @param collectionName
|
|
||||||
*/
|
|
||||||
void ensureIndex(IndexDefinition indexDefinition, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map the results of an ad-hoc query on the collection for the entity class to a single instance of an object
|
|
||||||
* of the specified type.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
|
||||||
* feature rich {@link Query}.
|
|
||||||
*
|
|
||||||
* @param query
|
|
||||||
* the query class that specifies the criteria used to find a record and also an optional fields
|
|
||||||
* specification
|
|
||||||
* @param entityClass
|
|
||||||
* the parameterized type of the returned list.
|
|
||||||
* @return the converted object
|
|
||||||
*/
|
|
||||||
<T> T findOne(Query query, Class<T> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified
|
|
||||||
* type.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
|
||||||
* feature rich {@link Query}.
|
|
||||||
* @param query
|
|
||||||
* the query class that specifies the criteria used to find a record and also an optional fields
|
|
||||||
* specification
|
|
||||||
* @param entityClass
|
|
||||||
* the parameterized type of the returned list.
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to retrieve the objects from
|
|
||||||
*
|
|
||||||
* @return the converted object
|
|
||||||
*/
|
|
||||||
<T> T findOne(Query query, Class<T> entityClass, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map the results of an ad-hoc query on the collection for the entity class to a List of the specified type.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
|
||||||
* feature rich {@link Query}.
|
|
||||||
*
|
|
||||||
* @param query
|
|
||||||
* the query class that specifies the criteria used to find a record and also an optional fields
|
|
||||||
* specification
|
|
||||||
* @param entityClass
|
|
||||||
* the parameterized type of the returned list.
|
|
||||||
* @return the List of converted objects
|
|
||||||
*/
|
|
||||||
<T> List<T> find(Query query, Class<T> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
|
||||||
* feature rich {@link Query}.
|
|
||||||
* @param query
|
|
||||||
* the query class that specifies the criteria used to find a record and also an optional fields
|
|
||||||
* specification
|
|
||||||
* @param entityClass
|
|
||||||
* the parameterized type of the returned list.
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to retrieve the objects from
|
|
||||||
*
|
|
||||||
* @return the List of converted objects
|
|
||||||
*/
|
|
||||||
<T> List<T> find(Query query, Class<T> entityClass, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map the results of an ad-hoc query on the specified collection to a List of the specified type.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
|
||||||
* feature rich {@link Query}.
|
|
||||||
* @param query
|
|
||||||
* the query class that specifies the criteria used to find a record and also an optional fields
|
|
||||||
* specification
|
|
||||||
* @param entityClass
|
|
||||||
* the parameterized type of the returned list.
|
|
||||||
* @param preparer
|
|
||||||
* allows for customization of the DBCursor used when iterating over the result set, (apply limits, skips and
|
|
||||||
* so on).
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to retrieve the objects from
|
|
||||||
*
|
|
||||||
* @return the List of converted objects.
|
|
||||||
*/
|
|
||||||
<T> List<T> find(Query query, Class<T> entityClass, CursorPreparer preparer, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a document with the given id mapped onto the given class. The collection the query is ran against will be
|
|
||||||
* derived from the given target class as well.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* @param id the id of the document to return.
|
|
||||||
* @param entityClass the type the document shall be converted into.
|
|
||||||
* @return the document with the given id mapped onto the given target class.
|
|
||||||
*/
|
|
||||||
<T> T findById(Object id, Class<T> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the document with the given id from the given collection mapped onto the given target class.
|
|
||||||
* @param id the id of the document to return
|
|
||||||
* @param entityClass the type to convert the document to
|
|
||||||
* @param collectionName the collection to query for the document
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
<T> T findById(Object id, Class<T> entityClass, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map the results of an ad-hoc query on the collection for the entity type to a single instance of an
|
|
||||||
* object of the specified type. The first document that matches the query is returned and also removed from
|
|
||||||
* the collection in the database.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}.
|
|
||||||
* <p/>
|
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
|
||||||
* feature rich {@link Query}.
|
|
||||||
*
|
|
||||||
* @param query
|
|
||||||
* the query class that specifies the criteria used to find a
|
|
||||||
* record and also an optional fields specification
|
|
||||||
* @param entityClass
|
|
||||||
* the parameterized type of the returned list.
|
|
||||||
* @return the converted object
|
|
||||||
*/
|
|
||||||
<T> T findAndRemove(Query query, Class<T> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified
|
|
||||||
* type. The first document that matches the query is returned and also removed from the collection in the database.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
|
|
||||||
* feature rich {@link Query}.
|
|
||||||
* @param query
|
|
||||||
* the query class that specifies the criteria used to find a record and also an optional fields
|
|
||||||
* specification
|
|
||||||
* @param entityClass
|
|
||||||
* the parameterized type of the returned list.
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to retrieve the objects from
|
|
||||||
*
|
|
||||||
* @return the converted object
|
|
||||||
*/
|
|
||||||
<T> T findAndRemove(Query query, Class<T> entityClass, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert the object into the collection for the entity type of the object to save.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}.
|
|
||||||
* <p/>
|
|
||||||
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
|
|
||||||
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
|
|
||||||
* property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's new Type Conversion API.
|
|
||||||
* See <a href="http://static.springsource.org/spring/docs/3.0.x/reference/validation.html#core-convert">Spring 3 Type
|
|
||||||
* Conversion"</a> for more details.
|
|
||||||
* <p/>
|
|
||||||
* <p/>
|
|
||||||
* Insert is used to initially store the object into the database. To update an existing object use the save method.
|
|
||||||
*
|
|
||||||
* @param objectToSave
|
|
||||||
* the object to store in the collection.
|
|
||||||
*/
|
|
||||||
void insert(Object objectToSave);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert the object into the specified collection.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* Insert is used to initially store the object into the database. To update an existing object use the save method.
|
|
||||||
* @param objectToSave
|
|
||||||
* the object to store in the collection
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to store the object in
|
|
||||||
*/
|
|
||||||
void insert(Object objectToSave, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert a Collection of objects into a collection in a single batch write to the database.
|
|
||||||
*
|
|
||||||
* @param batchToSave
|
|
||||||
* the list of objects to save.
|
|
||||||
* @param entityClass
|
|
||||||
* class that determines the collection to use
|
|
||||||
*/
|
|
||||||
void insert(Collection<? extends Object> batchToSave, Class<?> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert a list of objects into the specified collection in a single batch write to the database.
|
|
||||||
* @param batchToSave
|
|
||||||
* the list of objects to save.
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to store the object in
|
|
||||||
*/
|
|
||||||
void insert(Collection<? extends Object> batchToSave, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert a mixed Collection of objects into a database collection determining the
|
|
||||||
* collection name to use based on the class.
|
|
||||||
*
|
|
||||||
* @param collectionToSave
|
|
||||||
* the list of objects to save.
|
|
||||||
*/
|
|
||||||
void insertAll(Collection<? extends Object> objectsToSave);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the object to the collection for the entity type of the object to save. This will perform an
|
|
||||||
* insert if the object is not already present, that is an 'upsert'.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
|
|
||||||
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
|
|
||||||
* property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's new Type Conversion API.
|
|
||||||
* See <a href="http://static.springsource.org/spring/docs/3.0.x/reference/validation.html#core-convert">Spring 3 Type
|
|
||||||
* Conversion"</a> for more details.
|
|
||||||
*
|
|
||||||
* @param objectToSave
|
|
||||||
* the object to store in the collection
|
|
||||||
*/
|
|
||||||
void save(Object objectToSave);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the object to the specified collection. This will perform an insert if the object is not already present, that
|
|
||||||
* is an 'upsert'.
|
|
||||||
* <p/>
|
|
||||||
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
|
|
||||||
* configured otherwise, an instance of SimpleMongoConverter will be used.
|
|
||||||
* <p/>
|
|
||||||
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
|
|
||||||
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
|
|
||||||
* property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's new Type Cobnversion API.
|
|
||||||
* See <a href="http://static.springsource.org/spring/docs/3.0.x/reference/validation.html#core-convert">Spring 3 Type
|
|
||||||
* Conversion"</a> for more details.
|
|
||||||
* @param objectToSave
|
|
||||||
* the object to store in the collection
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to store the object in
|
|
||||||
*/
|
|
||||||
void save(Object objectToSave, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the first object that is found in the collection of the entity class that matches the query document with
|
|
||||||
* the provided update document.
|
|
||||||
* @param query
|
|
||||||
* the query document that specifies the criteria used to select a record to be updated
|
|
||||||
* @param update
|
|
||||||
* the update document that contains the updated object or $ operators to manipulate the existing object.
|
|
||||||
* @param entityClass
|
|
||||||
* class that determines the collection to use
|
|
||||||
*/
|
|
||||||
WriteResult updateFirst(Query query, Update update, Class<?> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the first object that is found in the specified collection that matches the query document criteria with
|
|
||||||
* the provided updated document.
|
|
||||||
* @param query
|
|
||||||
* the query document that specifies the criteria used to select a record to be updated
|
|
||||||
* @param update
|
|
||||||
* the update document that contains the updated object or $ operators to manipulate the existing object.
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to update the object in
|
|
||||||
*/
|
|
||||||
WriteResult updateFirst(Query query, Update update, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates all objects that are found in the collection for the entity class that matches the query document criteria
|
|
||||||
* with the provided updated document.
|
|
||||||
* @param query
|
|
||||||
* the query document that specifies the criteria used to select a record to be updated
|
|
||||||
* @param update
|
|
||||||
* the update document that contains the updated object or $ operators to manipulate the existing object.
|
|
||||||
* @param entityClass
|
|
||||||
* class that determines the collection to use
|
|
||||||
*/
|
|
||||||
WriteResult updateMulti(Query query, Update update, Class<?> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates all objects that are found in the specified collection that matches the query document criteria with the
|
|
||||||
* provided updated document.
|
|
||||||
* @param query
|
|
||||||
* the query document that specifies the criteria used to select a record to be updated
|
|
||||||
* @param update
|
|
||||||
* the update document that contains the updated object or $ operators to manipulate the existing object.
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection to update the object in
|
|
||||||
*/
|
|
||||||
WriteResult updateMulti(Query query, Update update, String collectionName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the given object from the collection by Id
|
|
||||||
*
|
|
||||||
* @param object
|
|
||||||
*/
|
|
||||||
void remove(Object object);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove all documents that match the provided query document criteria from
|
|
||||||
* the the collection used to store the entityClass. The Class parameter is
|
|
||||||
* also used to help convert the Id of the object if it is present in the
|
|
||||||
* query.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* @param query
|
|
||||||
* @param entityClass
|
|
||||||
*/
|
|
||||||
<T> void remove(Query query, Class<T> entityClass);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove all documents from the specified collection that match the provided query document criteria.
|
|
||||||
* There is no conversion/mapping done for any criteria using the id field.
|
|
||||||
* @param query
|
|
||||||
* the query document that specifies the criteria used to remove a record
|
|
||||||
* @param collectionName
|
|
||||||
* name of the collection where the objects will removed
|
|
||||||
*/
|
|
||||||
void remove(Query query, String collectionName);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,244 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb;
|
|
||||||
|
|
||||||
import java.beans.PropertyDescriptor;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An iterable of {@link MongoPropertyDescriptor}s that allows dedicated access to the {@link MongoPropertyDescriptor}
|
|
||||||
* that captures the id-property.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public class MongoPropertyDescriptors implements Iterable<MongoPropertyDescriptors.MongoPropertyDescriptor> {
|
|
||||||
|
|
||||||
private final Collection<MongoPropertyDescriptors.MongoPropertyDescriptor> descriptors;
|
|
||||||
private final MongoPropertyDescriptors.MongoPropertyDescriptor idDescriptor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the {@link MongoPropertyDescriptors} for the given type.
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
*/
|
|
||||||
public MongoPropertyDescriptors(Class<?> type) {
|
|
||||||
|
|
||||||
Assert.notNull(type);
|
|
||||||
Set<MongoPropertyDescriptors.MongoPropertyDescriptor> descriptors = new HashSet<MongoPropertyDescriptors.MongoPropertyDescriptor>();
|
|
||||||
MongoPropertyDescriptors.MongoPropertyDescriptor idDesciptor = null;
|
|
||||||
|
|
||||||
for (PropertyDescriptor candidates : BeanUtils.getPropertyDescriptors(type)) {
|
|
||||||
MongoPropertyDescriptor descriptor = new MongoPropertyDescriptors.MongoPropertyDescriptor(candidates, type);
|
|
||||||
descriptors.add(descriptor);
|
|
||||||
if (descriptor.isIdProperty()) {
|
|
||||||
idDesciptor = descriptor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.descriptors = Collections.unmodifiableSet(descriptors);
|
|
||||||
this.idDescriptor = idDesciptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link MongoPropertyDescriptor} for the id property.
|
|
||||||
*
|
|
||||||
* @return the idDescriptor
|
|
||||||
*/
|
|
||||||
public MongoPropertyDescriptors.MongoPropertyDescriptor getIdDescriptor() {
|
|
||||||
return idDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see java.lang.Iterable#iterator()
|
|
||||||
*/
|
|
||||||
public Iterator<MongoPropertyDescriptors.MongoPropertyDescriptor> iterator() {
|
|
||||||
return descriptors.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple value object to have a more suitable abstraction for MongoDB specific property handling.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public static class MongoPropertyDescriptor {
|
|
||||||
|
|
||||||
public static Collection<Class<?>> SUPPORTED_ID_CLASSES;
|
|
||||||
|
|
||||||
static {
|
|
||||||
Set<Class<?>> classes = new HashSet<Class<?>>();
|
|
||||||
classes.add(ObjectId.class);
|
|
||||||
classes.add(String.class);
|
|
||||||
classes.add(BigInteger.class);
|
|
||||||
SUPPORTED_ID_CLASSES = Collections.unmodifiableCollection(classes);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String ID_PROPERTY = "id";
|
|
||||||
static final String ID_KEY = "_id";
|
|
||||||
|
|
||||||
private final PropertyDescriptor delegate;
|
|
||||||
private final Class<?> owningType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link MongoPropertyDescriptor} for the given {@link PropertyDescriptor}.
|
|
||||||
*
|
|
||||||
* @param descriptor
|
|
||||||
* @param owningType
|
|
||||||
*/
|
|
||||||
public MongoPropertyDescriptor(PropertyDescriptor descriptor, Class<?> owningType) {
|
|
||||||
Assert.notNull(descriptor);
|
|
||||||
this.delegate = descriptor;
|
|
||||||
this.owningType = owningType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the property is the id-property. Will be identified by name for now ({@value #ID_PROPERTY}).
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isIdProperty() {
|
|
||||||
return ID_PROPERTY.equals(delegate.getName()) || ID_KEY.equals(delegate.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the property is of one of the supported id types. Currently we support {@link String},
|
|
||||||
* {@link ObjectId} and {@link BigInteger}.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isOfIdType() {
|
|
||||||
return SUPPORTED_ID_CLASSES.contains(delegate.getPropertyType());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the key that shall be used for mapping. Will return {@value #ID_KEY} for the id property and the plain
|
|
||||||
* name for all other ones.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getKeyToMap() {
|
|
||||||
return isIdProperty() ? ID_KEY : delegate.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name of the property.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getName() {
|
|
||||||
return delegate.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the underlying property is actually mappable. By default this will exclude the {@literal class}
|
|
||||||
* property and only include properties with a getter.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isMappable() {
|
|
||||||
|
|
||||||
boolean isNotClassAttribute = !delegate.getName().equals("class");
|
|
||||||
boolean hasGetter = delegate.getReadMethod() != null;
|
|
||||||
boolean hasField = ReflectionUtils.findField(owningType, delegate.getName()) != null;
|
|
||||||
|
|
||||||
return isNotClassAttribute && hasGetter && hasField;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the plain property type.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Class<?> getPropertyType() {
|
|
||||||
return delegate.getPropertyType();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the type type to be set. Will return the setter method's type and fall back to the getter method's return
|
|
||||||
* type in case no setter is available. Useful for further (generics) inspection.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Type getTypeToSet() {
|
|
||||||
|
|
||||||
Method method = delegate.getWriteMethod();
|
|
||||||
return method == null ? delegate.getReadMethod().getGenericReturnType() : method.getGenericParameterTypes()[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whther we describe a {@link Map}.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isMap() {
|
|
||||||
return Map.class.isAssignableFrom(getPropertyType());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the descriptor is for a collection.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isCollection() {
|
|
||||||
return Collection.class.isAssignableFrom(getPropertyType());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the descriptor is for an {@link Enum}.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isEnum() {
|
|
||||||
return Enum.class.isAssignableFrom(getPropertyType());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see java.lang.Object#equals(java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == this) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null || !getClass().equals(obj.getClass())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
MongoPropertyDescriptor that = (MongoPropertyDescriptor) obj;
|
|
||||||
return that.delegate.equals(this.delegate);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see java.lang.Object#hashCode()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return delegate.hashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb;
|
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A MongoWriter is responsible for converting a native MongoDB DBObject to an object of type T.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* the type of the object to convert from a DBObject
|
|
||||||
* @author Mark Pollack
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public interface MongoReader<T> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ready from the native MongoDB DBObject representation to an instance of the class T. The given type has to be the
|
|
||||||
* starting point for marshalling the {@link DBObject} into it. So in case there's no real valid data inside
|
|
||||||
* {@link DBObject} for the given type, just return an empty instance of the given type.
|
|
||||||
*
|
|
||||||
* @param clazz
|
|
||||||
* the type of the return value
|
|
||||||
* @param dbo
|
|
||||||
* theDBObject
|
|
||||||
* @return the converted object
|
|
||||||
*/
|
|
||||||
<S extends T> S read(Class<S> clazz, DBObject dbo);
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb;
|
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A MongoWriter is responsible for converting an object of type T to the native MongoDB representation DBObject.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* the type of the object to convert to a DBObject
|
|
||||||
* @author Mark Pollack
|
|
||||||
* @author Thomas Risberg
|
|
||||||
*/
|
|
||||||
public interface MongoWriter<T> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write the given object of type T to the native MongoDB object representation DBObject.
|
|
||||||
*
|
|
||||||
* @param t
|
|
||||||
* The object to convert to a DBObject
|
|
||||||
* @param dbo
|
|
||||||
* The DBObject to use for writing.
|
|
||||||
*/
|
|
||||||
void write(T t, DBObject dbo);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package org.springframework.data.document.mongodb;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
import org.springframework.data.authentication.UserCredentials;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import com.mongodb.DB;
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
|
|
||||||
public class SimpleMongoDbFactory implements MongoDbFactory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logger, available to subclasses.
|
|
||||||
*/
|
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
private Mongo mongo;
|
|
||||||
private String databaseName;
|
|
||||||
private String username;
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of SimpleMongoDbFactory given the Mongo instance and database name
|
|
||||||
* @param mongo Mongo instance, not null
|
|
||||||
* @param databaseName Database name, not null
|
|
||||||
*/
|
|
||||||
public SimpleMongoDbFactory(Mongo mongo, String databaseName) {
|
|
||||||
Assert.notNull(mongo, "Mongo must not be null");
|
|
||||||
Assert.hasText(databaseName, "Database name must not be empty");
|
|
||||||
this.mongo = mongo;
|
|
||||||
this.databaseName = databaseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of SimpleMongoDbFactory given the Mongo instance, database name, and username/password
|
|
||||||
* @param mongo Mongo instance, not null
|
|
||||||
* @param databaseName Database name, not null
|
|
||||||
* @param userCredentials username and password
|
|
||||||
*/
|
|
||||||
public SimpleMongoDbFactory(Mongo mongo, String databaseName, UserCredentials userCredentials) {
|
|
||||||
this(mongo, databaseName);
|
|
||||||
this.username = userCredentials.getUsername();
|
|
||||||
this.password = userCredentials.getPassword();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DB getDb() throws DataAccessException {
|
|
||||||
Assert.notNull(mongo, "Mongo must not be null");
|
|
||||||
Assert.hasText(databaseName, "Database name must not be empty");
|
|
||||||
return MongoDbUtils.getDB(mongo, databaseName, username, password == null ? null : password.toCharArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
public DB getDb(String dbName) throws DataAccessException {
|
|
||||||
Assert.notNull(mongo, "Mongo must not be null");
|
|
||||||
Assert.hasText(dbName, "Database name must not be empty");
|
|
||||||
return MongoDbUtils.getDB(mongo, dbName, username, password == null ? null : password.toCharArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.config;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.mongodb.Mongo;
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
|
||||||
import org.springframework.data.annotation.Persistent;
|
|
||||||
import org.springframework.data.authentication.UserCredentials;
|
|
||||||
import org.springframework.data.document.mongodb.MongoDbFactory;
|
|
||||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
|
||||||
import org.springframework.data.document.mongodb.SimpleMongoDbFactory;
|
|
||||||
import org.springframework.data.document.mongodb.convert.MappingMongoConverter;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.Document;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoMappingContext;
|
|
||||||
import org.springframework.data.mapping.context.MappingContextAwareBeanPostProcessor;
|
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public abstract class AbstractMongoConfiguration {
|
|
||||||
|
|
||||||
public abstract String getDatabaseName();
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public abstract Mongo mongo() throws Exception;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public MongoTemplate mongoTemplate() throws Exception {
|
|
||||||
return new MongoTemplate(mongoDbFactory(), mappingMongoConverter());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public MongoDbFactory mongoDbFactory() throws Exception {
|
|
||||||
if (getUserCredentials() == null) {
|
|
||||||
return new SimpleMongoDbFactory(mongo(), getDatabaseName());
|
|
||||||
} else {
|
|
||||||
return new SimpleMongoDbFactory(mongo(), getDatabaseName(), getUserCredentials());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMappingBasePackage() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserCredentials getUserCredentials() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public MongoMappingContext mongoMappingContext() throws ClassNotFoundException, LinkageError {
|
|
||||||
MongoMappingContext mappingContext = new MongoMappingContext();
|
|
||||||
String basePackage = getMappingBasePackage();
|
|
||||||
if (StringUtils.hasText(basePackage)) {
|
|
||||||
ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false);
|
|
||||||
componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class));
|
|
||||||
componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
|
|
||||||
|
|
||||||
Set<Class<?>> initialEntitySet = new HashSet<Class<?>>();
|
|
||||||
for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
|
|
||||||
initialEntitySet.add(ClassUtils.forName(candidate.getBeanClassName(), mappingContext.getClass().getClassLoader()));
|
|
||||||
}
|
|
||||||
mappingContext.setInitialEntitySet(initialEntitySet);
|
|
||||||
}
|
|
||||||
return mappingContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public MappingMongoConverter mappingMongoConverter() throws Exception {
|
|
||||||
MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory(), mongoMappingContext());
|
|
||||||
afterMappingMongoConverterCreation(converter);
|
|
||||||
return converter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook that allows post-processing after the MappingMongoConverter has been successfully created.
|
|
||||||
*
|
|
||||||
* @param converter
|
|
||||||
*/
|
|
||||||
protected void afterMappingMongoConverterCreation(MappingMongoConverter converter) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public MappingContextAwareBeanPostProcessor mappingContextAwareBeanPostProcessor() {
|
|
||||||
MappingContextAwareBeanPostProcessor bpp = new MappingContextAwareBeanPostProcessor();
|
|
||||||
bpp.setMappingContextBeanName("mongoMappingContext");
|
|
||||||
return bpp;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,169 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011 by the original author(s).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb.config;
|
|
||||||
|
|
||||||
import static org.springframework.data.document.mongodb.config.BeanNames.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.springframework.beans.BeanMetadataElement;
|
|
||||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
|
||||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
|
||||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
|
||||||
import org.springframework.beans.factory.support.ManagedList;
|
|
||||||
import org.springframework.beans.factory.support.ManagedSet;
|
|
||||||
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
|
||||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
|
||||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
|
||||||
import org.springframework.data.annotation.Persistent;
|
|
||||||
import org.springframework.data.document.mongodb.convert.MappingMongoConverter;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.Document;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoMappingContext;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntityIndexCreator;
|
|
||||||
import org.springframework.data.mapping.context.MappingContextAwareBeanPostProcessor;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.util.xml.DomUtils;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public class MappingMongoConverterParser extends AbstractBeanDefinitionParser {
|
|
||||||
|
|
||||||
private static final String BASE_PACKAGE = "base-package";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
|
|
||||||
throws BeanDefinitionStoreException {
|
|
||||||
String id = super.resolveId(element, definition, parserContext);
|
|
||||||
return StringUtils.hasText(id) ? id : "mappingConverter";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
|
||||||
BeanDefinitionRegistry registry = parserContext.getRegistry();
|
|
||||||
|
|
||||||
String ctxRef = element.getAttribute("mapping-context-ref");
|
|
||||||
if (!StringUtils.hasText(ctxRef)) {
|
|
||||||
BeanDefinitionBuilder mappingContextBuilder = BeanDefinitionBuilder
|
|
||||||
.genericBeanDefinition(MongoMappingContext.class);
|
|
||||||
|
|
||||||
Set<String> classesToAdd = getInititalEntityClasses(element, mappingContextBuilder);
|
|
||||||
if (classesToAdd != null) {
|
|
||||||
mappingContextBuilder.addPropertyValue("initialEntitySet", classesToAdd);
|
|
||||||
}
|
|
||||||
|
|
||||||
registry.registerBeanDefinition(MAPPING_CONTEXT, mappingContextBuilder.getBeanDefinition());
|
|
||||||
ctxRef = MAPPING_CONTEXT;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
registry.getBeanDefinition(POST_PROCESSOR);
|
|
||||||
} catch (NoSuchBeanDefinitionException ignored) {
|
|
||||||
BeanDefinitionBuilder postProcBuilder = BeanDefinitionBuilder
|
|
||||||
.genericBeanDefinition(MappingContextAwareBeanPostProcessor.class);
|
|
||||||
postProcBuilder.addPropertyValue("mappingContextBeanName", ctxRef);
|
|
||||||
registry.registerBeanDefinition(POST_PROCESSOR, postProcBuilder.getBeanDefinition());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Need a reference to a Mongo instance
|
|
||||||
String dbFactoryRef = element.getAttribute("db-factory-ref");
|
|
||||||
if (!StringUtils.hasText(dbFactoryRef)) {
|
|
||||||
dbFactoryRef = DB_FACTORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BeanDefinitionBuilder converterBuilder = BeanDefinitionBuilder.genericBeanDefinition(MappingMongoConverter.class);
|
|
||||||
converterBuilder.addConstructorArgReference(dbFactoryRef);
|
|
||||||
converterBuilder.addConstructorArgReference(ctxRef);
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
registry.getBeanDefinition(INDEX_HELPER);
|
|
||||||
} catch (NoSuchBeanDefinitionException ignored) {
|
|
||||||
if (!StringUtils.hasText(dbFactoryRef)) {
|
|
||||||
dbFactoryRef = DB_FACTORY;
|
|
||||||
}
|
|
||||||
BeanDefinitionBuilder indexHelperBuilder = BeanDefinitionBuilder.genericBeanDefinition(MongoPersistentEntityIndexCreator.class);
|
|
||||||
indexHelperBuilder.addConstructorArgValue(new RuntimeBeanReference(ctxRef));
|
|
||||||
indexHelperBuilder.addConstructorArgValue(new RuntimeBeanReference(dbFactoryRef));
|
|
||||||
registry.registerBeanDefinition(INDEX_HELPER, indexHelperBuilder.getBeanDefinition());
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Element> customConvertersElements = DomUtils.getChildElementsByTagName(element, "custom-converters");
|
|
||||||
if (customConvertersElements.size() == 1) {
|
|
||||||
Element customerConvertersElement = customConvertersElements.get(0);
|
|
||||||
ManagedList<BeanMetadataElement> converterBeans = new ManagedList<BeanMetadataElement>();
|
|
||||||
List<Element> listenerElements = DomUtils.getChildElementsByTagName(customerConvertersElement, "converter");
|
|
||||||
if (listenerElements != null) {
|
|
||||||
for (Element listenerElement : listenerElements) {
|
|
||||||
converterBeans.add(parseConverter(listenerElement, parserContext));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
converterBuilder.addPropertyValue("customConverters", converterBeans);
|
|
||||||
}
|
|
||||||
|
|
||||||
return converterBuilder.getBeanDefinition();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getInititalEntityClasses(Element element, BeanDefinitionBuilder builder) {
|
|
||||||
|
|
||||||
String basePackage = element.getAttribute(BASE_PACKAGE);
|
|
||||||
|
|
||||||
if (!StringUtils.hasText(basePackage)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(
|
|
||||||
false);
|
|
||||||
componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class));
|
|
||||||
componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
|
|
||||||
|
|
||||||
Set<String> classes = new ManagedSet<String>();
|
|
||||||
for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
|
|
||||||
classes.add(candidate.getBeanClassName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return classes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BeanMetadataElement parseConverter(Element element, ParserContext parserContext) {
|
|
||||||
|
|
||||||
String converterRef = element.getAttribute("ref");
|
|
||||||
if (StringUtils.hasText(converterRef)) {
|
|
||||||
return new RuntimeBeanReference(converterRef);
|
|
||||||
}
|
|
||||||
Element beanElement = DomUtils.getChildElementByTagName(element, "bean");
|
|
||||||
if (beanElement != null) {
|
|
||||||
BeanDefinitionHolder beanDef = parserContext.getDelegate().parseBeanDefinitionElement(beanElement);
|
|
||||||
beanDef = parserContext.getDelegate().decorateBeanDefinitionIfRequired(beanElement, beanDef);
|
|
||||||
return beanDef;
|
|
||||||
}
|
|
||||||
|
|
||||||
parserContext.getReaderContext().error(
|
|
||||||
"Element <converter> must specify 'ref' or contain a bean definition for the converter", element);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011 by the original author(s).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb.config;
|
|
||||||
|
|
||||||
import static org.springframework.data.document.mongodb.config.BeanNames.*;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
|
||||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
|
||||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
|
||||||
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
|
||||||
import org.springframework.data.authentication.UserCredentials;
|
|
||||||
import org.springframework.data.document.mongodb.MongoFactoryBean;
|
|
||||||
import org.springframework.data.document.mongodb.SimpleMongoDbFactory;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
|
||||||
*/
|
|
||||||
public class MongoDbFactoryParser extends AbstractBeanDefinitionParser {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException {
|
|
||||||
String id = element.getAttribute("id");
|
|
||||||
if (!StringUtils.hasText(id)) {
|
|
||||||
id = DB_FACTORY;
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
|
||||||
BeanDefinitionBuilder dbFactoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(SimpleMongoDbFactory.class);
|
|
||||||
|
|
||||||
// UserCredentials
|
|
||||||
BeanDefinitionBuilder userCredentialsBuilder = BeanDefinitionBuilder.genericBeanDefinition(UserCredentials.class);
|
|
||||||
String username = element.getAttribute("username");
|
|
||||||
if (StringUtils.hasText(username)) {
|
|
||||||
userCredentialsBuilder.addConstructorArgValue(username);
|
|
||||||
} else {
|
|
||||||
userCredentialsBuilder.addConstructorArgValue(null);
|
|
||||||
}
|
|
||||||
String password = element.getAttribute("password");
|
|
||||||
if (StringUtils.hasText(password)) {
|
|
||||||
userCredentialsBuilder.addConstructorArgValue(password);
|
|
||||||
} else {
|
|
||||||
userCredentialsBuilder.addConstructorArgValue(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// host and port
|
|
||||||
String host = element.getAttribute("host");
|
|
||||||
if (!StringUtils.hasText(host)) {
|
|
||||||
host = "localhost";
|
|
||||||
}
|
|
||||||
String port = element.getAttribute("port");
|
|
||||||
if (!StringUtils.hasText(port)) {
|
|
||||||
port = "27017";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Database name
|
|
||||||
String dbname = element.getAttribute("dbname");
|
|
||||||
if (!StringUtils.hasText(dbname)) {
|
|
||||||
dbname = "db";
|
|
||||||
}
|
|
||||||
|
|
||||||
// com.mongodb.Mongo object
|
|
||||||
String mongoRef = element.getAttribute("mongo-ref");
|
|
||||||
|
|
||||||
if (!StringUtils.hasText(mongoRef)) {
|
|
||||||
//Create implicit com.mongodb.Mongo object and register under generated name
|
|
||||||
BeanDefinitionBuilder mongoBuilder = BeanDefinitionBuilder.genericBeanDefinition(MongoFactoryBean.class);
|
|
||||||
mongoBuilder.addPropertyValue("host", host);
|
|
||||||
mongoBuilder.addPropertyValue("port", port);
|
|
||||||
mongoRef = BeanDefinitionReaderUtils.registerWithGeneratedName(mongoBuilder.getBeanDefinition(), parserContext.getRegistry());
|
|
||||||
}
|
|
||||||
dbFactoryBuilder.addConstructorArgValue(new RuntimeBeanReference(mongoRef));
|
|
||||||
dbFactoryBuilder.addConstructorArgValue(dbname);
|
|
||||||
dbFactoryBuilder.addConstructorArgValue(userCredentialsBuilder.getBeanDefinition());
|
|
||||||
|
|
||||||
return dbFactoryBuilder.getRawBeanDefinition();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011 by the original author(s).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
|
||||||
import org.springframework.beans.factory.support.ManagedList;
|
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
|
||||||
import org.springframework.data.document.mongodb.MongoOptionsFactoryBean;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.util.xml.DomUtils;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
import com.mongodb.ServerAddress;
|
|
||||||
|
|
||||||
abstract class ParsingUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the mongo replica-set element.
|
|
||||||
* @param parserContext the parser context
|
|
||||||
* @param element the mongo element
|
|
||||||
* @param mongoBuilder the bean definition builder to populate
|
|
||||||
* @return true if parsing actually occured, false otherwise
|
|
||||||
*/
|
|
||||||
static boolean parseReplicaSet(ParserContext parserContext, Element element, BeanDefinitionBuilder mongoBuilder) {
|
|
||||||
|
|
||||||
|
|
||||||
String replicaSetString = element.getAttribute("replica-set");
|
|
||||||
if (StringUtils.hasText(replicaSetString)) {
|
|
||||||
ManagedList<Object> serverAddresses = new ManagedList<Object>();
|
|
||||||
String[] replicaSetStringArray = StringUtils.commaDelimitedListToStringArray(replicaSetString);
|
|
||||||
for (int i = 0; i < replicaSetStringArray.length; i++) {
|
|
||||||
String[] hostAndPort = StringUtils.delimitedListToStringArray(replicaSetStringArray[i], ":");
|
|
||||||
BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.genericBeanDefinition(ServerAddress.class);
|
|
||||||
defBuilder.addConstructorArgValue(hostAndPort[0]);
|
|
||||||
defBuilder.addConstructorArgValue(hostAndPort[1]);
|
|
||||||
serverAddresses.add(defBuilder.getBeanDefinition());
|
|
||||||
}
|
|
||||||
if (!serverAddresses.isEmpty()) {
|
|
||||||
mongoBuilder.addPropertyValue("replicaSetSeeds", serverAddresses);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Parses the mongo:options sub-element. Populates the given attribute factory with the proper attributes.
|
|
||||||
*
|
|
||||||
* @return true if parsing actually occured, false otherwise
|
|
||||||
*/
|
|
||||||
static boolean parseMongoOptions(ParserContext parserContext, Element element, BeanDefinitionBuilder mongoBuilder) {
|
|
||||||
Element optionsElement = DomUtils.getChildElementByTagName(element, "options");
|
|
||||||
if (optionsElement == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BeanDefinitionBuilder optionsDefBuilder = BeanDefinitionBuilder
|
|
||||||
.genericBeanDefinition(MongoOptionsFactoryBean.class);
|
|
||||||
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "connections-per-host", "connectionsPerHost");
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "threads-allowed-to-block-for-connection-multiplier",
|
|
||||||
"threadsAllowedToBlockForConnectionMultiplier");
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "max-wait-time", "maxWaitTime");
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "connect-timeout", "connectTimeout");
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "socket-timeout", "socketTimeout");
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "socket-keep-alive", "socketKeepAlive");
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "auto-connect-retry", "autoConnectRetry");
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "write-number", "writeNumber");
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "write-timeout", "writeTimeout");
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "write-fsync", "writeFsync");
|
|
||||||
setPropertyValue(optionsElement, optionsDefBuilder, "slave-ok", "slaveOk");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mongoBuilder.addPropertyValue("mongoOptions", optionsDefBuilder.getBeanDefinition());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attrName, String propertyName) {
|
|
||||||
String attr = element.getAttribute(attrName);
|
|
||||||
if (StringUtils.hasText(attr)) {
|
|
||||||
builder.addPropertyValue(propertyName, attr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,258 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011 by the original author(s).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb.convert;
|
|
||||||
|
|
||||||
import static org.springframework.data.mapping.MappingBeanHelper.isSimpleType;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.core.GenericTypeResolver;
|
|
||||||
import org.springframework.core.convert.ConversionService;
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
|
||||||
import org.springframework.core.convert.converter.ConverterFactory;
|
|
||||||
import org.springframework.core.convert.converter.GenericConverter;
|
|
||||||
import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair;
|
|
||||||
import org.springframework.core.convert.support.ConversionServiceFactory;
|
|
||||||
import org.springframework.core.convert.support.GenericConversionService;
|
|
||||||
import org.springframework.data.document.mongodb.convert.ObjectIdConverters.BigIntegerToObjectIdConverter;
|
|
||||||
import org.springframework.data.document.mongodb.convert.ObjectIdConverters.ObjectIdToBigIntegerConverter;
|
|
||||||
import org.springframework.data.document.mongodb.convert.ObjectIdConverters.ObjectIdToStringConverter;
|
|
||||||
import org.springframework.data.document.mongodb.convert.ObjectIdConverters.StringToObjectIdConverter;
|
|
||||||
import org.springframework.data.mapping.MappingBeanHelper;
|
|
||||||
|
|
||||||
import com.mongodb.BasicDBList;
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
|
||||||
*/
|
|
||||||
public abstract class AbstractMongoConverter implements MongoConverter, InitializingBean {
|
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked" })
|
|
||||||
private static final List<Class<?>> MONGO_TYPES = Arrays.asList(Number.class, Date.class, String.class,
|
|
||||||
DBObject.class);
|
|
||||||
|
|
||||||
protected final GenericConversionService conversionService;
|
|
||||||
private final Set<ConvertiblePair> customTypeMapping = new HashSet<ConvertiblePair>();
|
|
||||||
|
|
||||||
public AbstractMongoConverter(GenericConversionService conversionService) {
|
|
||||||
this.conversionService = conversionService == null ? ConversionServiceFactory.createDefaultConversionService()
|
|
||||||
: conversionService;
|
|
||||||
this.conversionService.removeConvertible(Object.class, String.class);
|
|
||||||
registerConverter(CustomToStringConverter.INSTANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add custom {@link Converter} or {@link ConverterFactory} instances to be used that will take presidence over
|
|
||||||
* metadata driven conversion between of objects to/from DBObject
|
|
||||||
*
|
|
||||||
* @param converters
|
|
||||||
*/
|
|
||||||
public void setCustomConverters(Set<?> converters) {
|
|
||||||
if (null != converters) {
|
|
||||||
for (Object c : converters) {
|
|
||||||
registerConverter(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers converters for {@link ObjectId} handling, removes plain {@link #toString()} converter and promotes the
|
|
||||||
* configured {@link ConversionService} to {@link MappingBeanHelper}.
|
|
||||||
*/
|
|
||||||
private void initializeConverters() {
|
|
||||||
|
|
||||||
if (!conversionService.canConvert(ObjectId.class, String.class)) {
|
|
||||||
conversionService.addConverter(ObjectIdToStringConverter.INSTANCE);
|
|
||||||
}
|
|
||||||
if (!conversionService.canConvert(String.class, ObjectId.class)) {
|
|
||||||
conversionService.addConverter(StringToObjectIdConverter.INSTANCE);
|
|
||||||
}
|
|
||||||
if (!conversionService.canConvert(ObjectId.class, BigInteger.class)) {
|
|
||||||
conversionService.addConverter(ObjectIdToBigIntegerConverter.INSTANCE);
|
|
||||||
}
|
|
||||||
if (!conversionService.canConvert(BigInteger.class, ObjectId.class)) {
|
|
||||||
conversionService.addConverter(BigIntegerToObjectIdConverter.INSTANCE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inspects the given {@link Converter} for the types it can convert and registers the pair for custom type conversion
|
|
||||||
* in case the target type is a Mongo basic type.
|
|
||||||
*
|
|
||||||
* @param converter
|
|
||||||
*/
|
|
||||||
private void registerConverter(Object converter) {
|
|
||||||
|
|
||||||
if (converter instanceof GenericConverter) {
|
|
||||||
customTypeMapping.addAll(((GenericConverter) converter).getConvertibleTypes());
|
|
||||||
} else {
|
|
||||||
Class<?>[] arguments = GenericTypeResolver.resolveTypeArguments(converter.getClass(), Converter.class);
|
|
||||||
if (MONGO_TYPES.contains(arguments[1]) || MONGO_TYPES.contains(arguments[0])) {
|
|
||||||
customTypeMapping.add(new ConvertiblePair(arguments[0], arguments[1]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean added = false;
|
|
||||||
|
|
||||||
if (converter instanceof Converter) {
|
|
||||||
this.conversionService.addConverter((Converter<?, ?>) converter);
|
|
||||||
added = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (converter instanceof ConverterFactory) {
|
|
||||||
this.conversionService.addConverterFactory((ConverterFactory<?, ?>) converter);
|
|
||||||
added = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (converter instanceof GenericConverter) {
|
|
||||||
this.conversionService.addConverter((GenericConverter) converter);
|
|
||||||
added = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!added) {
|
|
||||||
throw new IllegalArgumentException("Given set contains element that is neither Converter nor ConverterFactory!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Class<?> getCustomTarget(Class<?> source, Class<?> expectedTargetType) {
|
|
||||||
for (ConvertiblePair typePair : customTypeMapping) {
|
|
||||||
if (typePair.getSourceType().isAssignableFrom(source)) {
|
|
||||||
|
|
||||||
Class<?> targetType = typePair.getTargetType();
|
|
||||||
|
|
||||||
if (targetType.equals(expectedTargetType) || expectedTargetType == null) {
|
|
||||||
return targetType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.document.mongodb.convert.MongoConverter#getConversionService()
|
|
||||||
*/
|
|
||||||
public ConversionService getConversionService() {
|
|
||||||
return conversionService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
|
||||||
*/
|
|
||||||
public void afterPropertiesSet() {
|
|
||||||
initializeConverters();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Object maybeConvertObject(Object obj) {
|
|
||||||
if (obj instanceof Enum<?>) {
|
|
||||||
return ((Enum<?>) obj).name();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null != obj && isSimpleType(obj.getClass())) {
|
|
||||||
// Doesn't need conversion
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj instanceof BasicDBList) {
|
|
||||||
return maybeConvertList((BasicDBList) obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj instanceof DBObject) {
|
|
||||||
DBObject newValueDbo = new BasicDBObject();
|
|
||||||
for (String vk : ((DBObject) obj).keySet()) {
|
|
||||||
Object o = ((DBObject) obj).get(vk);
|
|
||||||
newValueDbo.put(vk, maybeConvertObject(o));
|
|
||||||
}
|
|
||||||
return newValueDbo;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj instanceof Map) {
|
|
||||||
Map<Object, Object> m = new HashMap<Object, Object>();
|
|
||||||
for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) obj).entrySet()) {
|
|
||||||
m.put(entry.getKey(), maybeConvertObject(entry.getValue()));
|
|
||||||
}
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj instanceof List) {
|
|
||||||
List<?> l = (List<?>) obj;
|
|
||||||
List<Object> newList = new ArrayList<Object>();
|
|
||||||
for (Object o : l) {
|
|
||||||
newList.add(maybeConvertObject(o));
|
|
||||||
}
|
|
||||||
return newList;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj.getClass().isArray()) {
|
|
||||||
return maybeConvertArray((Object[]) obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
DBObject newDbo = new BasicDBObject();
|
|
||||||
this.write(obj, newDbo);
|
|
||||||
return newDbo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object[] maybeConvertArray(Object[] src) {
|
|
||||||
Object[] newArr = new Object[src.length];
|
|
||||||
for (int i = 0; i < src.length; i++) {
|
|
||||||
newArr[i] = maybeConvertObject(src[i]);
|
|
||||||
}
|
|
||||||
return newArr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicDBList maybeConvertList(BasicDBList dbl) {
|
|
||||||
BasicDBList newDbl = new BasicDBList();
|
|
||||||
Iterator<?> iter = dbl.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
Object o = iter.next();
|
|
||||||
newDbl.add(maybeConvertObject(o));
|
|
||||||
}
|
|
||||||
return newDbl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private enum CustomToStringConverter implements GenericConverter {
|
|
||||||
INSTANCE;
|
|
||||||
|
|
||||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
|
||||||
ConvertiblePair localeToString = new ConvertiblePair(Locale.class, String.class);
|
|
||||||
ConvertiblePair booleanToString = new ConvertiblePair(Character.class, String.class);
|
|
||||||
return new HashSet<ConvertiblePair>(Arrays.asList(localeToString, booleanToString));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
|
||||||
return source.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,780 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011 by the original author(s).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb.convert;
|
|
||||||
|
|
||||||
import static org.springframework.data.mapping.MappingBeanHelper.*;
|
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import com.mongodb.BasicDBList;
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DB;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.DBRef;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.ApplicationContextAware;
|
|
||||||
import org.springframework.context.expression.BeanFactoryResolver;
|
|
||||||
import org.springframework.core.CollectionFactory;
|
|
||||||
import org.springframework.core.convert.ConversionException;
|
|
||||||
import org.springframework.core.convert.support.ConversionServiceFactory;
|
|
||||||
import org.springframework.data.document.mongodb.MongoDbFactory;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoPersistentProperty;
|
|
||||||
import org.springframework.data.mapping.AssociationHandler;
|
|
||||||
import org.springframework.data.mapping.BeanWrapper;
|
|
||||||
import org.springframework.data.mapping.PropertyHandler;
|
|
||||||
import org.springframework.data.mapping.model.Association;
|
|
||||||
import org.springframework.data.mapping.model.MappingContext;
|
|
||||||
import org.springframework.data.mapping.model.MappingException;
|
|
||||||
import org.springframework.data.mapping.model.ParameterValueProvider;
|
|
||||||
import org.springframework.data.mapping.model.PreferredConstructor;
|
|
||||||
import org.springframework.data.mapping.model.SpELAwareParameterValueProvider;
|
|
||||||
import org.springframework.data.util.ClassTypeInformation;
|
|
||||||
import org.springframework.data.util.TypeInformation;
|
|
||||||
import org.springframework.expression.Expression;
|
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link MongoConverter} that uses a {@link MappingContext} to do sophisticated mapping of domain objects to
|
|
||||||
* {@link DBObject}.
|
|
||||||
*
|
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware {
|
|
||||||
|
|
||||||
public static final String CUSTOM_TYPE_KEY = "_class";
|
|
||||||
|
|
||||||
private static final List<Class<?>> VALID_ID_TYPES = Arrays.asList(new Class<?>[]{ObjectId.class, String.class,
|
|
||||||
BigInteger.class, byte[].class});
|
|
||||||
protected static final Log log = LogFactory.getLog(MappingMongoConverter.class);
|
|
||||||
|
|
||||||
protected final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext;
|
|
||||||
protected final SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
|
|
||||||
protected ApplicationContext applicationContext;
|
|
||||||
protected boolean useFieldAccessOnly = true;
|
|
||||||
protected MongoDbFactory mongoDbFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link MappingMongoConverter} given the new {@link MongoDbFactory} and {@link MappingContext}.
|
|
||||||
*
|
|
||||||
* @param mongoDbFactory
|
|
||||||
* @param mappingContext
|
|
||||||
*/
|
|
||||||
public MappingMongoConverter(MongoDbFactory mongoDbFactory, MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext) {
|
|
||||||
super(ConversionServiceFactory.createDefaultConversionService());
|
|
||||||
Assert.notNull(mappingContext);
|
|
||||||
Assert.notNull(mongoDbFactory);
|
|
||||||
this.mongoDbFactory = mongoDbFactory;
|
|
||||||
this.mappingContext = mappingContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> getMappingContext() {
|
|
||||||
return mappingContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMongoDbFactory(MongoDbFactory mongoDbFactory) {
|
|
||||||
this.mongoDbFactory = mongoDbFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUseFieldAccessOnly() {
|
|
||||||
return useFieldAccessOnly;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUseFieldAccessOnly(boolean useFieldAccessOnly) {
|
|
||||||
this.useFieldAccessOnly = useFieldAccessOnly;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T convertObjectId(ObjectId id, Class<T> targetType) {
|
|
||||||
return conversionService.convert(id, targetType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectId convertObjectId(Object id) {
|
|
||||||
return conversionService.convert(id, ObjectId.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <S extends Object> S read(Class<S> clazz, final DBObject dbo) {
|
|
||||||
return read(ClassTypeInformation.from(clazz), dbo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected <S extends Object> S read(TypeInformation<S> type, DBObject dbo) {
|
|
||||||
|
|
||||||
if (null == dbo) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
TypeInformation<? extends S> typeToUse = getMoreConcreteTargetType(dbo, type);
|
|
||||||
Class<? extends S> rawType = typeToUse.getType();
|
|
||||||
Class<?> customTarget = getCustomTarget(rawType, DBObject.class);
|
|
||||||
|
|
||||||
if (customTarget != null) {
|
|
||||||
return conversionService.convert(dbo, rawType);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeToUse.isCollectionLike() && dbo instanceof BasicDBList) {
|
|
||||||
List<Object> l = new ArrayList<Object>();
|
|
||||||
BasicDBList dbList = (BasicDBList) dbo;
|
|
||||||
for (Object o : dbList) {
|
|
||||||
if (o instanceof DBObject) {
|
|
||||||
|
|
||||||
Object newObj = read(typeToUse.getComponentType(), (DBObject) o);
|
|
||||||
Class<?> rawComponentType = typeToUse.getComponentType().getType();
|
|
||||||
|
|
||||||
if (newObj.getClass().isAssignableFrom(rawComponentType)) {
|
|
||||||
l.add(newObj);
|
|
||||||
} else {
|
|
||||||
l.add(conversionService.convert(newObj, rawComponentType));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
l.add(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return conversionService.convert(l, rawType);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve persistent entity info
|
|
||||||
MongoPersistentEntity<S> persistentEntity = (MongoPersistentEntity<S>) mappingContext
|
|
||||||
.getPersistentEntity(typeToUse);
|
|
||||||
if (persistentEntity == null) {
|
|
||||||
throw new MappingException("No mapping metadata found for " + rawType.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return read(persistentEntity, dbo);
|
|
||||||
}
|
|
||||||
|
|
||||||
private <S extends Object> S read(final MongoPersistentEntity<S> entity, final DBObject dbo) {
|
|
||||||
|
|
||||||
final StandardEvaluationContext spelCtx = new StandardEvaluationContext();
|
|
||||||
if (null != applicationContext) {
|
|
||||||
spelCtx.setBeanResolver(new BeanFactoryResolver(applicationContext));
|
|
||||||
}
|
|
||||||
if (!(dbo instanceof BasicDBList)) {
|
|
||||||
String[] keySet = dbo.keySet().toArray(new String[]{});
|
|
||||||
for (String key : keySet) {
|
|
||||||
spelCtx.setVariable(key, dbo.get(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<String> ctorParamNames = new ArrayList<String>();
|
|
||||||
final MongoPersistentProperty idProperty = entity.getIdProperty();
|
|
||||||
|
|
||||||
ParameterValueProvider provider = new SpELAwareParameterValueProvider(spelExpressionParser, spelCtx) {
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T> T getParameterValue(PreferredConstructor.Parameter<T> parameter) {
|
|
||||||
|
|
||||||
if (parameter.getKey() != null) {
|
|
||||||
return super.getParameterValue(parameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
String name = parameter.getName();
|
|
||||||
TypeInformation<T> type = parameter.getType();
|
|
||||||
Class<T> rawType = parameter.getRawType();
|
|
||||||
String key = idProperty == null ? name : idProperty.getName().equals(name) ? idProperty.getFieldName() : name;
|
|
||||||
Object obj = dbo.get(key);
|
|
||||||
|
|
||||||
ctorParamNames.add(name);
|
|
||||||
if (obj instanceof DBRef) {
|
|
||||||
return read(type, ((DBRef) obj).fetch());
|
|
||||||
} else if (obj instanceof BasicDBList) {
|
|
||||||
BasicDBList objAsDbList = (BasicDBList) obj;
|
|
||||||
List<?> l = unwrapList(objAsDbList, type);
|
|
||||||
return conversionService.convert(l, rawType);
|
|
||||||
} else if (obj instanceof DBObject) {
|
|
||||||
return read(type, ((DBObject) obj));
|
|
||||||
} else if (null != obj && obj.getClass().isAssignableFrom(rawType)) {
|
|
||||||
return (T) obj;
|
|
||||||
} else if (null != obj) {
|
|
||||||
return conversionService.convert(obj, rawType);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final BeanWrapper<MongoPersistentEntity<S>, S> wrapper = BeanWrapper.create(entity, provider, conversionService);
|
|
||||||
|
|
||||||
// Set properties not already set in the constructor
|
|
||||||
entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
|
|
||||||
public void doWithPersistentProperty(MongoPersistentProperty prop) {
|
|
||||||
|
|
||||||
boolean isConstructorProperty = ctorParamNames.contains(prop.getName());
|
|
||||||
boolean hasValueForProperty = dbo.containsField(prop.getFieldName());
|
|
||||||
|
|
||||||
if (!hasValueForProperty || isConstructorProperty) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object obj = getValueInternal(prop, dbo, spelCtx, prop.getSpelExpression());
|
|
||||||
try {
|
|
||||||
wrapper.setProperty(prop, obj, useFieldAccessOnly);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle associations
|
|
||||||
entity.doWithAssociations(new AssociationHandler<MongoPersistentProperty>() {
|
|
||||||
public void doWithAssociation(Association<MongoPersistentProperty> association) {
|
|
||||||
MongoPersistentProperty inverseProp = association.getInverse();
|
|
||||||
Object obj = getValueInternal(inverseProp, dbo, spelCtx, inverseProp.getSpelExpression());
|
|
||||||
try {
|
|
||||||
wrapper.setProperty(inverseProp, obj);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return wrapper.getBean();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Root entry method into write conversion. Adds a type discriminator to the {@link DBObject}. Shouldn't be called for
|
|
||||||
* nested conversions.
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.document.mongodb.MongoWriter#write(java.lang.Object, com.mongodb.DBObject)
|
|
||||||
*/
|
|
||||||
public void write(final Object obj, final DBObject dbo) {
|
|
||||||
|
|
||||||
if (null == obj) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean handledByCustomConverter = getCustomTarget(obj.getClass(), DBObject.class) != null;
|
|
||||||
|
|
||||||
if (!handledByCustomConverter) {
|
|
||||||
dbo.put(CUSTOM_TYPE_KEY, obj.getClass().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
writeInternal(obj, dbo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal write conversion method which should be used for nested invocations.
|
|
||||||
*
|
|
||||||
* @param obj
|
|
||||||
* @param dbo
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected void writeInternal(final Object obj, final DBObject dbo) {
|
|
||||||
|
|
||||||
if (null == obj) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> customTarget = getCustomTarget(obj.getClass(), DBObject.class);
|
|
||||||
|
|
||||||
if (customTarget != null) {
|
|
||||||
DBObject result = conversionService.convert(obj, DBObject.class);
|
|
||||||
dbo.putAll(result);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Map.class.isAssignableFrom(obj.getClass())) {
|
|
||||||
writeMapInternal((Map<Object, Object>) obj, dbo, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(obj.getClass());
|
|
||||||
writeInternal(obj, dbo, entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void writeInternal(Object obj, final DBObject dbo, MongoPersistentEntity<?> entity) {
|
|
||||||
|
|
||||||
if (obj == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null == entity) {
|
|
||||||
throw new MappingException("No mapping metadata found for entity of type " + obj.getClass().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
final BeanWrapper<MongoPersistentEntity<Object>, Object> wrapper = BeanWrapper.create(obj, conversionService);
|
|
||||||
|
|
||||||
// Write the ID
|
|
||||||
final MongoPersistentProperty idProperty = entity.getIdProperty();
|
|
||||||
if (!dbo.containsField("_id") && null != idProperty) {
|
|
||||||
Object idObj = null;
|
|
||||||
Class<?>[] targetClasses = new Class<?>[]{ObjectId.class, Object.class};
|
|
||||||
for (Class<?> targetClasse : targetClasses) {
|
|
||||||
try {
|
|
||||||
idObj = wrapper.getProperty(idProperty, targetClasse, useFieldAccessOnly);
|
|
||||||
if (null != idObj) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (ConversionException ignored) {
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null != idObj) {
|
|
||||||
dbo.put("_id", idObj);
|
|
||||||
} else {
|
|
||||||
if (!VALID_ID_TYPES.contains(idProperty.getType())) {
|
|
||||||
throw new MappingException("Invalid data type " + idProperty.getType().getName()
|
|
||||||
+ " for Id property. Should be one of " + VALID_ID_TYPES);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the properties
|
|
||||||
entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
|
|
||||||
public void doWithPersistentProperty(MongoPersistentProperty prop) {
|
|
||||||
if (prop.equals(idProperty)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Object propertyObj;
|
|
||||||
try {
|
|
||||||
propertyObj = wrapper.getProperty(prop, prop.getType(), useFieldAccessOnly);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
if (null != propertyObj) {
|
|
||||||
if (!isSimpleType(propertyObj.getClass())) {
|
|
||||||
writePropertyInternal(prop, propertyObj, dbo);
|
|
||||||
} else {
|
|
||||||
writeSimpleInternal(prop.getFieldName(), propertyObj, dbo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
entity.doWithAssociations(new AssociationHandler<MongoPersistentProperty>() {
|
|
||||||
public void doWithAssociation(Association<MongoPersistentProperty> association) {
|
|
||||||
MongoPersistentProperty inverseProp = association.getInverse();
|
|
||||||
Class<?> type = inverseProp.getType();
|
|
||||||
Object propertyObj;
|
|
||||||
try {
|
|
||||||
propertyObj = wrapper.getProperty(inverseProp, type, useFieldAccessOnly);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
if (null != propertyObj) {
|
|
||||||
writePropertyInternal(inverseProp, propertyObj, dbo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
||||||
this.applicationContext = applicationContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
|
||||||
protected void writePropertyInternal(MongoPersistentProperty prop, Object obj, DBObject dbo) {
|
|
||||||
|
|
||||||
if (obj == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String name = prop.getFieldName();
|
|
||||||
|
|
||||||
if (prop.isCollection()) {
|
|
||||||
DBObject collectionInternal = writeCollectionInternal(prop, obj);
|
|
||||||
dbo.put(name, collectionInternal);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prop.isMap()) {
|
|
||||||
BasicDBObject mapDbObj = new BasicDBObject();
|
|
||||||
writeMapInternal((Map<Object, Object>) obj, mapDbObj, prop.getTypeInformation());
|
|
||||||
dbo.put(name, mapDbObj);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prop.isDbReference()) {
|
|
||||||
DBRef dbRefObj = createDBRef(obj, prop.getDBRef());
|
|
||||||
if (null != dbRefObj) {
|
|
||||||
dbo.put(name, dbRefObj);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lookup potential custom target type
|
|
||||||
Class<?> basicTargetType = getCustomTarget(obj.getClass(), null);
|
|
||||||
|
|
||||||
if (basicTargetType != null) {
|
|
||||||
dbo.put(name, conversionService.convert(obj, basicTargetType));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BasicDBObject propDbObj = new BasicDBObject();
|
|
||||||
addCustomTypeKeyIfNecessary(prop.getTypeInformation(), obj, propDbObj);
|
|
||||||
writeInternal(obj, propDbObj, mappingContext.getPersistentEntity(prop.getTypeInformation()));
|
|
||||||
dbo.put(name, propDbObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected DBObject writeCollectionInternal(MongoPersistentProperty property, Object obj) {
|
|
||||||
|
|
||||||
BasicDBList dbList = new BasicDBList();
|
|
||||||
Class<?> type = property.getType();
|
|
||||||
Collection<Object> coll = type.isArray() ? CollectionUtils.arrayToList(obj) : (Collection<Object>) obj;
|
|
||||||
TypeInformation<?> componentType = property.getTypeInformation().getComponentType();
|
|
||||||
|
|
||||||
for (Object element : coll) {
|
|
||||||
|
|
||||||
if (element == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TypeInformation<?> valueType = ClassTypeInformation.from(element.getClass());
|
|
||||||
|
|
||||||
if (property.isDbReference()) {
|
|
||||||
DBRef dbRef = createDBRef(element, property.getDBRef());
|
|
||||||
dbList.add(dbRef);
|
|
||||||
} else if (type.isArray() && isSimpleType(property.getComponentType())) {
|
|
||||||
dbList.add(element);
|
|
||||||
} else if (element instanceof List) {
|
|
||||||
List<?> propObjColl = (List<?>) element;
|
|
||||||
while (valueType.isCollectionLike()) {
|
|
||||||
valueType = valueType.getComponentType();
|
|
||||||
}
|
|
||||||
if (isSimpleType(valueType.getType())) {
|
|
||||||
dbList.add(propObjColl);
|
|
||||||
} else {
|
|
||||||
BasicDBList propNestedDbList = new BasicDBList();
|
|
||||||
for (Object propNestedObjItem : propObjColl) {
|
|
||||||
BasicDBObject propDbObj = new BasicDBObject();
|
|
||||||
writeInternal(propNestedObjItem, propDbObj);
|
|
||||||
propNestedDbList.add(propDbObj);
|
|
||||||
}
|
|
||||||
dbList.add(propNestedDbList);
|
|
||||||
}
|
|
||||||
} else if (isSimpleType(element.getClass())) {
|
|
||||||
dbList.add(element);
|
|
||||||
} else {
|
|
||||||
BasicDBObject propDbObj = new BasicDBObject();
|
|
||||||
writeInternal(element, propDbObj, mappingContext.getPersistentEntity(valueType));
|
|
||||||
addCustomTypeKeyIfNecessary(componentType, element, propDbObj);
|
|
||||||
dbList.add(propDbObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return dbList;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void writeMapInternal(Map<Object, Object> obj, DBObject dbo, TypeInformation<?> propertyType) {
|
|
||||||
for (Map.Entry<Object, Object> entry : obj.entrySet()) {
|
|
||||||
Object key = entry.getKey();
|
|
||||||
Object val = entry.getValue();
|
|
||||||
if (isSimpleType(key.getClass())) {
|
|
||||||
// Don't use conversion service here as removal of ObjectToString converter results in some primitive types not
|
|
||||||
// being convertable
|
|
||||||
String simpleKey = key.toString();
|
|
||||||
if (isSimpleType(val.getClass())) {
|
|
||||||
writeSimpleInternal(simpleKey, val, dbo);
|
|
||||||
} else {
|
|
||||||
DBObject newDbo = new BasicDBObject();
|
|
||||||
writeInternal(val, newDbo);
|
|
||||||
addCustomTypeKeyIfNecessary(propertyType, val, newDbo);
|
|
||||||
dbo.put(simpleKey, newDbo);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new MappingException("Cannot use a complex object as a key value.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds custom type information to the given {@link DBObject} if necessary. That is if the value is not the same as
|
|
||||||
* the one given. This is usually the case if you store a subtype of the actual declared type of the property.
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param value
|
|
||||||
* @param dbObject
|
|
||||||
*/
|
|
||||||
public void addCustomTypeKeyIfNecessary(TypeInformation<?> type, Object value, DBObject dbObject) {
|
|
||||||
|
|
||||||
if (type == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> reference = getValueType(type).getType();
|
|
||||||
|
|
||||||
boolean notTheSameClass = !value.getClass().equals(reference);
|
|
||||||
if (notTheSameClass) {
|
|
||||||
dbObject.put(CUSTOM_TYPE_KEY, value.getClass().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the type type information of the actual value to be stored. That is, for maps it will return the map value
|
|
||||||
* type, for collections it will return the component type as well as the given type if it is a non-collection or
|
|
||||||
* non-map one.
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public TypeInformation<?> getValueType(TypeInformation<?> type) {
|
|
||||||
if (type.isMap()) {
|
|
||||||
return type.getMapValueType();
|
|
||||||
} else if (type.isCollectionLike()) {
|
|
||||||
return type.getComponentType();
|
|
||||||
} else {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the given simple value to the given {@link DBObject}. Will store enum names for enum values.
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* @param value
|
|
||||||
* @param dbObject
|
|
||||||
*/
|
|
||||||
private void writeSimpleInternal(String key, Object value, DBObject dbObject) {
|
|
||||||
|
|
||||||
Class<?> customTarget = getCustomTarget(value.getClass(), null);
|
|
||||||
|
|
||||||
Object valueToSet = null;
|
|
||||||
if (customTarget != null) {
|
|
||||||
valueToSet = conversionService.convert(value, customTarget);
|
|
||||||
} else {
|
|
||||||
valueToSet = value.getClass().isEnum() ? ((Enum<?>) value).name() : value;
|
|
||||||
}
|
|
||||||
dbObject.put(key, valueToSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected DBRef createDBRef(Object target, org.springframework.data.document.mongodb.mapping.DBRef dbref) {
|
|
||||||
MongoPersistentEntity<?> targetEntity = mappingContext.getPersistentEntity(target.getClass());
|
|
||||||
if (null == targetEntity || null == targetEntity.getIdProperty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
MongoPersistentProperty idProperty = targetEntity.getIdProperty();
|
|
||||||
ObjectId id = null;
|
|
||||||
BeanWrapper<MongoPersistentEntity<Object>, Object> wrapper = BeanWrapper.create(target, conversionService);
|
|
||||||
try {
|
|
||||||
id = wrapper.getProperty(idProperty, ObjectId.class, useFieldAccessOnly);
|
|
||||||
if (null == id) {
|
|
||||||
throw new MappingException("Cannot create a reference to an object with a NULL id.");
|
|
||||||
}
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
throw new MappingException(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
String collection = dbref.collection();
|
|
||||||
if ("".equals(collection)) {
|
|
||||||
collection = targetEntity.getCollection();
|
|
||||||
}
|
|
||||||
|
|
||||||
String dbname = dbref.db();
|
|
||||||
DB db = StringUtils.hasText(dbname) ? mongoDbFactory.getDb(dbname) : mongoDbFactory.getDb();
|
|
||||||
return new DBRef(db, collection, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected Object getValueInternal(MongoPersistentProperty prop, DBObject dbo, StandardEvaluationContext ctx, String spelExpr) {
|
|
||||||
|
|
||||||
Object o;
|
|
||||||
if (null != spelExpr) {
|
|
||||||
Expression x = spelExpressionParser.parseExpression(spelExpr);
|
|
||||||
o = x.getValue(ctx);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
Object dbObj = dbo.get(prop.getFieldName());
|
|
||||||
|
|
||||||
if (dbObj == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> propertyType = prop.getType();
|
|
||||||
Class<?> customTarget = getCustomTarget(dbObj.getClass(), propertyType);
|
|
||||||
|
|
||||||
if (customTarget != null) {
|
|
||||||
return conversionService.convert(dbObj, propertyType);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dbObj instanceof DBRef) {
|
|
||||||
dbObj = ((DBRef) dbObj).fetch();
|
|
||||||
}
|
|
||||||
if (dbObj instanceof DBObject) {
|
|
||||||
if (prop.isMap()) {
|
|
||||||
return readMap(prop.getTypeInformation(), (DBObject) dbObj);
|
|
||||||
} else if (prop.isArray() && dbObj instanceof BasicDBObject && ((DBObject) dbObj).keySet().size() == 0) {
|
|
||||||
// It's empty
|
|
||||||
return Array.newInstance(prop.getComponentType(), 0);
|
|
||||||
} else if (prop.isCollection() && dbObj instanceof BasicDBList) {
|
|
||||||
BasicDBList dbObjList = (BasicDBList) dbObj;
|
|
||||||
List<Object> items = new LinkedList<Object>();
|
|
||||||
for (int i = 0; i < dbObjList.size(); i++) {
|
|
||||||
Object dbObjItem = dbObjList.get(i);
|
|
||||||
if (dbObjItem instanceof DBRef) {
|
|
||||||
items.add(read(prop.getComponentType(), ((DBRef) dbObjItem).fetch()));
|
|
||||||
} else if (dbObjItem instanceof DBObject) {
|
|
||||||
items.add(read(prop.getComponentType(), (DBObject) dbObjItem));
|
|
||||||
} else {
|
|
||||||
items.add(dbObjItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
List<Object> itemsToReturn = new LinkedList<Object>();
|
|
||||||
for (Object obj : items) {
|
|
||||||
itemsToReturn.add(obj);
|
|
||||||
}
|
|
||||||
return itemsToReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> toType = findTypeToBeUsed((DBObject) dbObj);
|
|
||||||
|
|
||||||
// It's a complex object, have to read it in
|
|
||||||
if (toType != null) {
|
|
||||||
dbo.removeField(CUSTOM_TYPE_KEY);
|
|
||||||
o = read(toType, (DBObject) dbObj);
|
|
||||||
} else {
|
|
||||||
o = read(mappingContext.getPersistentEntity(prop.getTypeInformation()), (DBObject) dbObj);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
o = dbObj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the given {@link DBObject} into a {@link Map}. will recursively resolve nested {@link Map}s as well.
|
|
||||||
*
|
|
||||||
* @param type the {@link Map} {@link TypeInformation} to be used to unmarshall this {@link DBObject}.
|
|
||||||
* @param dbObject
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private Map<Object, Object> readMap(TypeInformation<?> type, DBObject dbObject) {
|
|
||||||
|
|
||||||
Assert.notNull(type);
|
|
||||||
Assert.isTrue(type.isMap());
|
|
||||||
Assert.notNull(dbObject);
|
|
||||||
|
|
||||||
Class<?> customMapType = findTypeToBeUsed(dbObject);
|
|
||||||
Class<?> mapType = customMapType == null ? Map.class : customMapType;
|
|
||||||
|
|
||||||
Map<Object, Object> map = CollectionFactory.createMap(mapType, dbObject.keySet().size());
|
|
||||||
Map<String, Object> sourceMap = dbObject.toMap();
|
|
||||||
|
|
||||||
for (Entry<String, Object> entry : sourceMap.entrySet()) {
|
|
||||||
if (entry.getKey().equals(CUSTOM_TYPE_KEY)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> keyType = type.getComponentType().getType();
|
|
||||||
Object key = conversionService.convert(entry.getKey(), keyType);
|
|
||||||
|
|
||||||
if (null != entry.getValue() && entry.getValue() instanceof DBObject) {
|
|
||||||
|
|
||||||
DBObject valueSource = (DBObject) entry.getValue();
|
|
||||||
TypeInformation<?> valueType = type.getMapValueType();
|
|
||||||
|
|
||||||
Object value = valueType.isMap() ? readMap(valueType, valueSource) : read(valueType, valueSource);
|
|
||||||
|
|
||||||
map.put(key, value);
|
|
||||||
} else {
|
|
||||||
map.put(key, entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the type to be used to convert the DBObject given to. Will return {@literal null} if there's not type hint
|
|
||||||
* found in the {@link DBObject} or the type hint found can't be converted into a {@link Class} as the type might not
|
|
||||||
* be available.
|
|
||||||
*
|
|
||||||
* @param dbObject
|
|
||||||
* @return the type to be used for converting the given {@link DBObject} into or {@literal null} if there's no type
|
|
||||||
* found.
|
|
||||||
*/
|
|
||||||
protected Class<?> findTypeToBeUsed(DBObject dbObject) {
|
|
||||||
Object classToBeUsed = dbObject.get(CUSTOM_TYPE_KEY);
|
|
||||||
|
|
||||||
if (classToBeUsed == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return Class.forName(classToBeUsed.toString());
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inspects the a custom class definition stored inside the given {@link DBObject} and returns that in case it's a
|
|
||||||
* subtype of the given basic one.
|
|
||||||
*
|
|
||||||
* @param dbObject
|
|
||||||
* @param basicType
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <S> TypeInformation<? extends S> getMoreConcreteTargetType(DBObject dbObject, TypeInformation<S> basicType) {
|
|
||||||
Class<?> documentsTargetType = findTypeToBeUsed(dbObject);
|
|
||||||
Class<S> rawType = basicType.getType();
|
|
||||||
boolean isMoreConcreteCustomType = documentsTargetType != null && rawType.isAssignableFrom(documentsTargetType);
|
|
||||||
return isMoreConcreteCustomType ? (TypeInformation<? extends S>) ClassTypeInformation.from(documentsTargetType)
|
|
||||||
: basicType;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected <T> List<?> unwrapList(BasicDBList dbList, TypeInformation<T> targetType) {
|
|
||||||
List<Object> rootList = new LinkedList<Object>();
|
|
||||||
for (int i = 0; i < dbList.size(); i++) {
|
|
||||||
Object obj = dbList.get(i);
|
|
||||||
if (obj instanceof BasicDBList) {
|
|
||||||
rootList.add(unwrapList((BasicDBList) obj, targetType.getComponentType()));
|
|
||||||
} else if (obj instanceof DBObject) {
|
|
||||||
rootList.add(read(targetType, (DBObject) obj));
|
|
||||||
} else {
|
|
||||||
rootList.add(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rootList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.convert;
|
|
||||||
|
|
||||||
import static org.springframework.beans.PropertyAccessorFactory.forBeanPropertyAccess;
|
|
||||||
import static org.springframework.beans.PropertyAccessorFactory.forDirectFieldAccess;
|
|
||||||
|
|
||||||
import org.springframework.beans.BeanWrapper;
|
|
||||||
import org.springframework.beans.ConfigurablePropertyAccessor;
|
|
||||||
import org.springframework.beans.NotWritablePropertyException;
|
|
||||||
import org.springframework.core.convert.ConversionService;
|
|
||||||
import org.springframework.data.document.mongodb.MongoPropertyDescriptors;
|
|
||||||
import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoPropertyDescriptor;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom Mongo specific {@link BeanWrapper} to allow access to bean properties via {@link MongoPropertyDescriptor}s.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
class MongoBeanWrapper {
|
|
||||||
|
|
||||||
private final ConfigurablePropertyAccessor accessor;
|
|
||||||
private final MongoPropertyDescriptors descriptors;
|
|
||||||
private final boolean fieldAccess;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link MongoBeanWrapper} for the given target object and {@link ConversionService}.
|
|
||||||
*
|
|
||||||
* @param target
|
|
||||||
* @param conversionService
|
|
||||||
* @param fieldAccess
|
|
||||||
*/
|
|
||||||
public MongoBeanWrapper(Object target, ConversionService conversionService, boolean fieldAccess) {
|
|
||||||
|
|
||||||
Assert.notNull(target);
|
|
||||||
Assert.notNull(conversionService);
|
|
||||||
|
|
||||||
this.fieldAccess = fieldAccess;
|
|
||||||
this.accessor = fieldAccess ? forDirectFieldAccess(target) : forBeanPropertyAccess(target);
|
|
||||||
this.accessor.setConversionService(conversionService);
|
|
||||||
this.descriptors = new MongoPropertyDescriptors(target.getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all {@link MongoPropertyDescriptors.MongoPropertyDescriptor}s for the underlying target object.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public MongoPropertyDescriptors getDescriptors() {
|
|
||||||
return this.descriptors;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the value of the underlying object for the given property.
|
|
||||||
*
|
|
||||||
* @param descriptor
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Object getValue(MongoPropertyDescriptors.MongoPropertyDescriptor descriptor) {
|
|
||||||
Assert.notNull(descriptor);
|
|
||||||
return accessor.getPropertyValue(descriptor.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the property of the underlying object to the given value.
|
|
||||||
*
|
|
||||||
* @param descriptor
|
|
||||||
* @param value
|
|
||||||
*/
|
|
||||||
public void setValue(MongoPropertyDescriptors.MongoPropertyDescriptor descriptor, Object value) {
|
|
||||||
Assert.notNull(descriptor);
|
|
||||||
try {
|
|
||||||
accessor.setPropertyValue(descriptor.getName(), value);
|
|
||||||
} catch (NotWritablePropertyException e) {
|
|
||||||
if (!fieldAccess) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.convert;
|
|
||||||
|
|
||||||
import com.mongodb.BasicDBList;
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.springframework.core.convert.ConversionService;
|
|
||||||
import org.springframework.data.document.mongodb.MongoReader;
|
|
||||||
import org.springframework.data.document.mongodb.MongoWriter;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoPersistentProperty;
|
|
||||||
import org.springframework.data.mapping.model.MappingContext;
|
|
||||||
|
|
||||||
public interface MongoConverter extends MongoWriter<Object>, MongoReader<Object> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the given {@link ObjectId} to the given target type.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* the actual type to create
|
|
||||||
* @param id
|
|
||||||
* the source {@link ObjectId}
|
|
||||||
* @param targetType
|
|
||||||
* the target type to convert the {@link ObjectId} to
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public <T> T convertObjectId(ObjectId id, Class<T> targetType);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link ObjectId} instance for the given id.
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ObjectId convertObjectId(Object id);
|
|
||||||
|
|
||||||
MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> getMappingContext();
|
|
||||||
|
|
||||||
Object maybeConvertObject(Object obj);
|
|
||||||
|
|
||||||
Object[] maybeConvertArray(Object[] src);
|
|
||||||
|
|
||||||
BasicDBList maybeConvertList(BasicDBList dbl);
|
|
||||||
|
|
||||||
ConversionService getConversionService();
|
|
||||||
}
|
|
||||||
@@ -1,516 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.convert;
|
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.lang.reflect.GenericArrayType;
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.lang.reflect.TypeVariable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import com.mongodb.BasicDBList;
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import com.mongodb.DBRef;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.bson.types.CodeWScope;
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.core.CollectionFactory;
|
|
||||||
import org.springframework.core.convert.ConversionFailedException;
|
|
||||||
import org.springframework.core.convert.ConversionService;
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
|
||||||
import org.springframework.core.convert.support.ConversionServiceFactory;
|
|
||||||
import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoPropertyDescriptor;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoPersistentProperty;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.SimpleMongoMappingContext;
|
|
||||||
import org.springframework.data.mapping.model.MappingContext;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.comparator.CompoundComparator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Basic {@link MongoConverter} implementation to convert between domain classes and {@link DBObject}s.
|
|
||||||
*
|
|
||||||
* @author Mark Pollack
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*
|
|
||||||
* @deprecated since Spring 1.0 M3 in favor of {@link org.springframework.data.document.mongodb.convert.MappingMongoConverter}
|
|
||||||
* The MappingMongoConverter provides all the functionality of the SimpleMongoConverter and will replace it as the default
|
|
||||||
* converter used. The SimpleMongoCOnverter will be removed at some point before the GA release.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SimpleMongoConverter extends AbstractMongoConverter implements InitializingBean {
|
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(SimpleMongoConverter.class);
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static final List<Class<?>> MONGO_TYPES = Arrays.asList(Number.class, Date.class, String.class,
|
|
||||||
DBObject.class);
|
|
||||||
private static final Set<String> SIMPLE_TYPES;
|
|
||||||
|
|
||||||
static {
|
|
||||||
Set<String> basics = new HashSet<String>();
|
|
||||||
basics.add(boolean.class.getName());
|
|
||||||
basics.add(long.class.getName());
|
|
||||||
basics.add(short.class.getName());
|
|
||||||
basics.add(int.class.getName());
|
|
||||||
basics.add(byte.class.getName());
|
|
||||||
basics.add(float.class.getName());
|
|
||||||
basics.add(double.class.getName());
|
|
||||||
basics.add(char.class.getName());
|
|
||||||
basics.add(Boolean.class.getName());
|
|
||||||
basics.add(Long.class.getName());
|
|
||||||
basics.add(Short.class.getName());
|
|
||||||
basics.add(Integer.class.getName());
|
|
||||||
basics.add(Byte.class.getName());
|
|
||||||
basics.add(Float.class.getName());
|
|
||||||
basics.add(Double.class.getName());
|
|
||||||
basics.add(Character.class.getName());
|
|
||||||
basics.add(String.class.getName());
|
|
||||||
basics.add(java.util.Date.class.getName());
|
|
||||||
// basics.add(Time.class.getName());
|
|
||||||
// basics.add(Timestamp.class.getName());
|
|
||||||
// basics.add(java.sql.Date.class.getName());
|
|
||||||
// basics.add(BigDecimal.class.getName());
|
|
||||||
// basics.add(BigInteger.class.getName());
|
|
||||||
basics.add(Locale.class.getName());
|
|
||||||
// basics.add(Calendar.class.getName());
|
|
||||||
// basics.add(GregorianCalendar.class.getName());
|
|
||||||
// basics.add(java.util.Currency.class.getName());
|
|
||||||
// basics.add(TimeZone.class.getName());
|
|
||||||
// basics.add(Object.class.getName());
|
|
||||||
basics.add(Class.class.getName());
|
|
||||||
// basics.add(byte[].class.getName());
|
|
||||||
// basics.add(Byte[].class.getName());
|
|
||||||
// basics.add(char[].class.getName());
|
|
||||||
// basics.add(Character[].class.getName());
|
|
||||||
// basics.add(Blob.class.getName());
|
|
||||||
// basics.add(Clob.class.getName());
|
|
||||||
// basics.add(Serializable.class.getName());
|
|
||||||
// basics.add(URI.class.getName());
|
|
||||||
// basics.add(URL.class.getName());
|
|
||||||
basics.add(DBRef.class.getName());
|
|
||||||
basics.add(Pattern.class.getName());
|
|
||||||
basics.add(CodeWScope.class.getName());
|
|
||||||
basics.add(ObjectId.class.getName());
|
|
||||||
basics.add(Enum.class.getName());
|
|
||||||
SIMPLE_TYPES = Collections.unmodifiableSet(basics);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link SimpleMongoConverter}.
|
|
||||||
*/
|
|
||||||
public SimpleMongoConverter() {
|
|
||||||
super(ConversionServiceFactory.createDefaultConversionService());
|
|
||||||
this.mappingContext = new SimpleMongoMappingContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.document.mongodb.convert.MongoConverter#getMappingContext()
|
|
||||||
*/
|
|
||||||
public MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> getMappingContext() {
|
|
||||||
return mappingContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.document.mongodb.MongoWriter#write(java.lang.Object, com.mongodb.DBObject)
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
public void write(Object obj, DBObject dbo) {
|
|
||||||
|
|
||||||
MongoBeanWrapper beanWrapper = createWrapper(obj, false);
|
|
||||||
for (MongoPropertyDescriptor descriptor : beanWrapper.getDescriptors()) {
|
|
||||||
if (descriptor.isMappable()) {
|
|
||||||
Object value = beanWrapper.getValue(descriptor);
|
|
||||||
|
|
||||||
if (value == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String keyToUse = descriptor.getKeyToMap();
|
|
||||||
if (descriptor.isEnum()) {
|
|
||||||
writeValue(dbo, keyToUse, ((Enum) value).name());
|
|
||||||
} else if (descriptor.isIdProperty() && descriptor.isOfIdType()) {
|
|
||||||
if (value instanceof String && ObjectId.isValid((String) value)) {
|
|
||||||
try {
|
|
||||||
writeValue(dbo, keyToUse, conversionService.convert(value, ObjectId.class));
|
|
||||||
} catch (ConversionFailedException iae) {
|
|
||||||
LOG.warn("Unable to convert the String " + value + " to an ObjectId");
|
|
||||||
writeValue(dbo, keyToUse, value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// we can't convert this id - use as is
|
|
||||||
writeValue(dbo, keyToUse, value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
writeValue(dbo, keyToUse, value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!"class".equals(descriptor.getName())) {
|
|
||||||
LOG.debug("Skipping property " + descriptor.getName() + " as it's not a mappable one.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the given value to the given {@link DBObject}. Will skip {@literal null} values.
|
|
||||||
*
|
|
||||||
* @param dbo
|
|
||||||
* @param keyToUse
|
|
||||||
* @param value
|
|
||||||
*/
|
|
||||||
private void writeValue(DBObject dbo, String keyToUse, Object value) {
|
|
||||||
|
|
||||||
if (!isSimpleType(value.getClass())) {
|
|
||||||
writeCompoundValue(dbo, keyToUse, value);
|
|
||||||
} else {
|
|
||||||
dbo.put(keyToUse, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the given {@link CompoundComparator} value to the given {@link DBObject}.
|
|
||||||
*
|
|
||||||
* @param dbo
|
|
||||||
* @param keyToUse
|
|
||||||
* @param value
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void writeCompoundValue(DBObject dbo, String keyToUse, Object value) {
|
|
||||||
if (value instanceof Map) {
|
|
||||||
writeMap(dbo, keyToUse, (Map<String, Object>) value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (value instanceof Collection) {
|
|
||||||
// Should write a collection!
|
|
||||||
writeArray(dbo, keyToUse, ((Collection<Object>) value).toArray());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (value instanceof Object[]) {
|
|
||||||
// Should write an array!
|
|
||||||
writeArray(dbo, keyToUse, (Object[]) value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> customTargetType = getCustomTargetType(value);
|
|
||||||
if (customTargetType != null) {
|
|
||||||
dbo.put(keyToUse, conversionService.convert(value, customTargetType));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DBObject nestedDbo = new BasicDBObject();
|
|
||||||
write(value, nestedDbo);
|
|
||||||
dbo.put(keyToUse, nestedDbo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the {@link ConversionService} has a custom {@link Converter} registered that can convert the given
|
|
||||||
* object into one of the types supported by MongoDB.
|
|
||||||
*
|
|
||||||
* @param obj
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Class<?> getCustomTargetType(Object obj) {
|
|
||||||
|
|
||||||
for (Class<?> mongoType : MONGO_TYPES) {
|
|
||||||
if (conversionService.canConvert(obj.getClass(), mongoType)) {
|
|
||||||
return mongoType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the given {@link Map} to the given {@link DBObject}.
|
|
||||||
*
|
|
||||||
* @param dbo
|
|
||||||
* @param mapKey
|
|
||||||
* @param map
|
|
||||||
*/
|
|
||||||
protected void writeMap(DBObject dbo, String mapKey, Map<String, Object> map) {
|
|
||||||
// TODO support non-string based keys as long as there is a Spring Converter obj->string and (optionally)
|
|
||||||
// string->obj
|
|
||||||
DBObject dboToPopulate = null;
|
|
||||||
|
|
||||||
// TODO - Does that make sense? If we create a new object here it's content will never make it out of this
|
|
||||||
// method
|
|
||||||
if (mapKey != null) {
|
|
||||||
dboToPopulate = new BasicDBObject();
|
|
||||||
} else {
|
|
||||||
dboToPopulate = dbo;
|
|
||||||
}
|
|
||||||
if (map != null) {
|
|
||||||
for (Entry<String, Object> entry : map.entrySet()) {
|
|
||||||
|
|
||||||
Object entryValue = entry.getValue();
|
|
||||||
String entryKey = entry.getKey();
|
|
||||||
|
|
||||||
if (!isSimpleType(entryValue.getClass())) {
|
|
||||||
writeCompoundValue(dboToPopulate, entryKey, entryValue);
|
|
||||||
} else {
|
|
||||||
dboToPopulate.put(entryKey, entryValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dbo.put(mapKey, dboToPopulate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the given array to the given {@link DBObject}.
|
|
||||||
*
|
|
||||||
* @param dbo
|
|
||||||
* @param keyToUse
|
|
||||||
* @param array
|
|
||||||
*/
|
|
||||||
protected void writeArray(DBObject dbo, String keyToUse, Object[] array) {
|
|
||||||
Object[] dboValues;
|
|
||||||
if (array != null) {
|
|
||||||
dboValues = new Object[array.length];
|
|
||||||
int i = 0;
|
|
||||||
for (Object o : array) {
|
|
||||||
if (!isSimpleType(o.getClass())) {
|
|
||||||
DBObject dboValue = new BasicDBObject();
|
|
||||||
write(o, dboValue);
|
|
||||||
dboValues[i] = dboValue;
|
|
||||||
} else {
|
|
||||||
dboValues[i] = o;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
dbo.put(keyToUse, dboValues);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.document.mongodb.MongoReader#read(java.lang.Class, com.mongodb.DBObject)
|
|
||||||
*/
|
|
||||||
public <S> S read(Class<S> clazz, DBObject source) {
|
|
||||||
|
|
||||||
if (source == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.notNull(clazz, "Mapped class was not specified");
|
|
||||||
S target = BeanUtils.instantiateClass(clazz);
|
|
||||||
MongoBeanWrapper bw = new MongoBeanWrapper(target, conversionService, true);
|
|
||||||
|
|
||||||
for (MongoPropertyDescriptor descriptor : bw.getDescriptors()) {
|
|
||||||
String keyToUse = descriptor.getKeyToMap();
|
|
||||||
if (source.containsField(keyToUse)) {
|
|
||||||
if (descriptor.isMappable()) {
|
|
||||||
Object value = source.get(keyToUse);
|
|
||||||
if (!isSimpleType(value.getClass())) {
|
|
||||||
if (value instanceof Object[]) {
|
|
||||||
bw.setValue(descriptor, readCollection(descriptor, Arrays.asList((Object[]) value)).toArray());
|
|
||||||
} else if (value instanceof BasicDBList) {
|
|
||||||
bw.setValue(descriptor, readCollection(descriptor, (BasicDBList) value));
|
|
||||||
} else if (value instanceof DBObject) {
|
|
||||||
bw.setValue(descriptor, readCompoundValue(descriptor, (DBObject) value));
|
|
||||||
} else {
|
|
||||||
LOG.warn("Unable to map compound DBObject field " + keyToUse + " to property " + descriptor.getName()
|
|
||||||
+ ". The field value should have been a 'DBObject.class' but was " + value.getClass().getName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bw.setValue(descriptor, value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOG.warn("Unable to map DBObject field " + keyToUse + " to property " + descriptor.getName() + ". Skipping.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the given collection values (that are {@link DBObject}s potentially) into a {@link Collection} of domain
|
|
||||||
* objects.
|
|
||||||
*
|
|
||||||
* @param descriptor
|
|
||||||
* @param values
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Collection<Object> readCollection(MongoPropertyDescriptor descriptor, Collection<?> values) {
|
|
||||||
|
|
||||||
Class<?> targetCollectionType = descriptor.getPropertyType();
|
|
||||||
boolean targetIsArray = targetCollectionType.isArray();
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Collection<Object> result = targetIsArray ? new ArrayList<Object>(values.size()) : CollectionFactory
|
|
||||||
.createCollection(targetCollectionType, values.size());
|
|
||||||
|
|
||||||
for (Object o : values) {
|
|
||||||
if (o instanceof DBObject) {
|
|
||||||
Class<?> type;
|
|
||||||
if (targetIsArray) {
|
|
||||||
type = targetCollectionType.getComponentType();
|
|
||||||
} else {
|
|
||||||
type = getGenericParameters(descriptor.getTypeToSet()).get(0);
|
|
||||||
}
|
|
||||||
result.add(read(type, (DBObject) o));
|
|
||||||
} else {
|
|
||||||
result.add(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads a compound value from the given {@link DBObject} for the given property.
|
|
||||||
*
|
|
||||||
* @param pd
|
|
||||||
* @param dbo
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Object readCompoundValue(MongoPropertyDescriptor pd, DBObject dbo) {
|
|
||||||
|
|
||||||
Assert.isTrue(!pd.isCollection(), "Collections not supported!");
|
|
||||||
|
|
||||||
if (pd.isMap()) {
|
|
||||||
return readMap(pd, dbo, getGenericParameters(pd.getTypeToSet()).get(1));
|
|
||||||
} else {
|
|
||||||
return read(pd.getPropertyType(), dbo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a {@link Map} instance. Will return a {@link HashMap} by default. Subclasses might want to override this
|
|
||||||
* method to use a custom {@link Map} implementation.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected Map<String, Object> createMap() {
|
|
||||||
return new HashMap<String, Object>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads every key/value pair from the {@link DBObject} into a {@link Map} instance.
|
|
||||||
*
|
|
||||||
* @param pd
|
|
||||||
* @param dbo
|
|
||||||
* @param targetType
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected Map<?, ?> readMap(MongoPropertyDescriptor pd, DBObject dbo, Class<?> targetType) {
|
|
||||||
Map<String, Object> map = createMap();
|
|
||||||
for (String key : dbo.keySet()) {
|
|
||||||
Object value = dbo.get(key);
|
|
||||||
if (!isSimpleType(value.getClass())) {
|
|
||||||
map.put(key, read(targetType, (DBObject) value));
|
|
||||||
// Can do some reflection tricks here -
|
|
||||||
// throw new RuntimeException("User types not supported yet as values for Maps");
|
|
||||||
} else {
|
|
||||||
map.put(key, conversionService.convert(value, targetType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static boolean isSimpleType(Class<?> propertyType) {
|
|
||||||
if (propertyType == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (propertyType.isArray()) {
|
|
||||||
return isSimpleType(propertyType.getComponentType());
|
|
||||||
}
|
|
||||||
return SIMPLE_TYPES.contains(propertyType.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback to allow customizing creation of a {@link MongoBeanWrapper}.
|
|
||||||
*
|
|
||||||
* @param target
|
|
||||||
* the target object to wrap
|
|
||||||
* @param fieldAccess
|
|
||||||
* whether to use field access or property access
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected MongoBeanWrapper createWrapper(Object target, boolean fieldAccess) {
|
|
||||||
|
|
||||||
return new MongoBeanWrapper(target, conversionService, fieldAccess);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Class<?>> getGenericParameters(Type genericParameterType) {
|
|
||||||
|
|
||||||
List<Class<?>> actualGenericParameterTypes = new ArrayList<Class<?>>();
|
|
||||||
|
|
||||||
if (genericParameterType instanceof ParameterizedType) {
|
|
||||||
ParameterizedType aType = (ParameterizedType) genericParameterType;
|
|
||||||
Type[] parameterArgTypes = aType.getActualTypeArguments();
|
|
||||||
for (Type parameterArgType : parameterArgTypes) {
|
|
||||||
if (parameterArgType instanceof GenericArrayType) {
|
|
||||||
Class<?> arrayType = (Class<?>) ((GenericArrayType) parameterArgType).getGenericComponentType();
|
|
||||||
actualGenericParameterTypes.add(Array.newInstance(arrayType, 0).getClass());
|
|
||||||
} else {
|
|
||||||
if (parameterArgType instanceof ParameterizedType) {
|
|
||||||
ParameterizedType paramTypeArgs = (ParameterizedType) parameterArgType;
|
|
||||||
actualGenericParameterTypes.add((Class<?>) paramTypeArgs.getRawType());
|
|
||||||
} else {
|
|
||||||
if (parameterArgType instanceof TypeVariable) {
|
|
||||||
throw new RuntimeException("Can not map " + ((TypeVariable<?>) parameterArgType).getName());
|
|
||||||
} else {
|
|
||||||
if (parameterArgType instanceof Class) {
|
|
||||||
actualGenericParameterTypes.add((Class<?>) parameterArgType);
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("Can not map " + parameterArgType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return actualGenericParameterTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.document.mongodb.convert.MongoConverter#convertObjectId(org.bson.types.ObjectId, java.lang.Class)
|
|
||||||
*/
|
|
||||||
public <T> T convertObjectId(ObjectId id, Class<T> targetType) {
|
|
||||||
return conversionService.convert(id, targetType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.document.mongodb.convert.MongoConverter#convertObjectId(java.lang.Object)
|
|
||||||
*/
|
|
||||||
public ObjectId convertObjectId(Object id) {
|
|
||||||
return conversionService.convert(id, ObjectId.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.geo;
|
|
||||||
|
|
||||||
import org.springframework.data.annotation.PersistenceConstructor;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a geospatial circle value
|
|
||||||
*
|
|
||||||
* @author Mark Pollack
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public class Circle {
|
|
||||||
|
|
||||||
private Point center;
|
|
||||||
private double radius;
|
|
||||||
|
|
||||||
@PersistenceConstructor
|
|
||||||
public Circle(Point center, double radius) {
|
|
||||||
Assert.notNull(center);
|
|
||||||
Assert.isTrue(radius >= 0, "Radius must not be negative!");
|
|
||||||
this.center = center;
|
|
||||||
this.radius = radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Circle(double centerX, double centerY, double radius) {
|
|
||||||
this(new Point(centerX, centerY), radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Point getCenter() {
|
|
||||||
return center;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getRadius() {
|
|
||||||
return radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("Circle [center=%s, radius=%d]", center, radius);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011 by the original author(s).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb.mapping;
|
|
||||||
|
|
||||||
import org.springframework.data.document.mongodb.MongoCollectionUtils;
|
|
||||||
import org.springframework.data.mapping.BasicPersistentEntity;
|
|
||||||
import org.springframework.data.mapping.model.MappingException;
|
|
||||||
import org.springframework.data.mapping.model.PersistentEntity;
|
|
||||||
import org.springframework.data.util.TypeInformation;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mongo specific {@link PersistentEntity} implementation that adds Mongo specific meta-data such as the collection name
|
|
||||||
* and the like.
|
|
||||||
*
|
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public class BasicMongoPersistentEntity<T> extends BasicPersistentEntity<T, MongoPersistentProperty> implements
|
|
||||||
MongoPersistentEntity<T> {
|
|
||||||
|
|
||||||
private final String collection;
|
|
||||||
private final boolean isRootEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link BasicMongoPersistentEntity} with the given {@link TypeInformation}. Will default the
|
|
||||||
* collection name to the entities simple type name.
|
|
||||||
*
|
|
||||||
* @param typeInformation
|
|
||||||
*/
|
|
||||||
public BasicMongoPersistentEntity(TypeInformation<T> typeInformation) {
|
|
||||||
|
|
||||||
super(typeInformation);
|
|
||||||
|
|
||||||
Class<?> rawType = typeInformation.getType();
|
|
||||||
String fallback = MongoCollectionUtils.getPreferredCollectionName(rawType);
|
|
||||||
|
|
||||||
if (rawType.isAnnotationPresent(Document.class)) {
|
|
||||||
Document d = rawType.getAnnotation(Document.class);
|
|
||||||
this.collection = StringUtils.hasText(d.collection()) ? d.collection() : fallback;
|
|
||||||
this.isRootEntity = true;
|
|
||||||
} else {
|
|
||||||
this.collection = fallback;
|
|
||||||
this.isRootEntity = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the collection the entity should be stored in.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getCollection() {
|
|
||||||
return collection;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.mapping.BasicPersistentEntity#verify()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void verify() {
|
|
||||||
if (isRootEntity && idProperty == null) {
|
|
||||||
throw new MappingException(String.format("Root entity %s has to have an id property!", getType().getName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011 by the original author(s).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.mapping;
|
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Annotation to allow defining the name of the field a property should use in a Mongo document. This will cause the
|
|
||||||
* property annotated being persisted to a field with the configured name as wells as being read from it.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target({ ElementType.FIELD })
|
|
||||||
@Documented
|
|
||||||
public @interface FieldName {
|
|
||||||
|
|
||||||
String value();
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011 by the original author(s).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb.mapping;
|
|
||||||
|
|
||||||
import java.beans.PropertyDescriptor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bson.types.CodeWScope;
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.springframework.data.mapping.AbstractMappingContext;
|
|
||||||
import org.springframework.data.mapping.MappingBeanHelper;
|
|
||||||
import org.springframework.data.util.TypeInformation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
|
||||||
*/
|
|
||||||
public class MongoMappingContext extends AbstractMappingContext<BasicMongoPersistentEntity<?>, MongoPersistentProperty> {
|
|
||||||
public MongoMappingContext() {
|
|
||||||
augmentSimpleTypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void augmentSimpleTypes() {
|
|
||||||
// Augment simpleTypes with MongoDB-specific classes
|
|
||||||
Set<Class<?>> simpleTypes = MappingBeanHelper.getSimpleTypes();
|
|
||||||
simpleTypes.add(com.mongodb.DBRef.class);
|
|
||||||
simpleTypes.add(ObjectId.class);
|
|
||||||
simpleTypes.add(CodeWScope.class);
|
|
||||||
simpleTypes.add(Character.class);
|
|
||||||
simpleTypes.add(BigInteger.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MongoPersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor,
|
|
||||||
BasicMongoPersistentEntity<?> owner) {
|
|
||||||
return new BasicMongoPersistentProperty(field, descriptor, owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.mapping.BasicMappingContext#createPersistentEntity(org.springframework.data.util.TypeInformation, org.springframework.data.mapping.model.MappingContext)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected <T> BasicMongoPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
|
|
||||||
return new BasicMongoPersistentEntity<T>(typeInformation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011 by the original author(s).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb.mapping.event;
|
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
|
||||||
import org.springframework.context.ApplicationListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
|
||||||
*/
|
|
||||||
public abstract class AbstractMappingEventListener<T extends ApplicationEvent, E> implements ApplicationListener<T> {
|
|
||||||
|
|
||||||
protected final Log log = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked" })
|
|
||||||
public void onApplicationEvent(T appEvent) {
|
|
||||||
if (appEvent instanceof MongoMappingEvent) {
|
|
||||||
try {
|
|
||||||
MongoMappingEvent<E> event = (MongoMappingEvent<E>) appEvent;
|
|
||||||
if (event instanceof BeforeConvertEvent) {
|
|
||||||
onBeforeConvert(event.getSource());
|
|
||||||
} else if (event instanceof BeforeSaveEvent) {
|
|
||||||
onBeforeSave(event.getSource(), event.getDBObject());
|
|
||||||
} else if (event instanceof AfterSaveEvent) {
|
|
||||||
onAfterSave(event.getSource(), event.getDBObject());
|
|
||||||
} else if (event instanceof AfterLoadEvent) {
|
|
||||||
onAfterLoad((DBObject) event.getSource());
|
|
||||||
} else if (event instanceof AfterConvertEvent) {
|
|
||||||
onAfterConvert(event.getDBObject(), event.getSource());
|
|
||||||
}
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
// Not a mapping event for this entity, apparently.
|
|
||||||
// Just ignore it for now.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBeforeConvert(E source) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("onBeforeConvert(" + source + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBeforeSave(E source, DBObject dbo) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("onBeforeSave(" + source + ", " + dbo + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onAfterSave(E source, DBObject dbo) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("onAfterSave(" + source + ", " + dbo + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onAfterLoad(DBObject dbo) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("onAfterLoad(" + dbo + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onAfterConvert(DBObject dbo, E source) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("onAfterConvert(" + dbo + "," + source + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* MongoDB specific JMX monitoring support.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.monitor;
|
|
||||||
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* MongoDB core support.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb;
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package org.springframework.data.document.mongodb.query;
|
|
||||||
|
|
||||||
public class NorQuery extends Query {
|
|
||||||
|
|
||||||
public NorQuery(Query... q) {
|
|
||||||
super.nor(q);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.query;
|
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import org.bson.types.BasicBSONList;
|
|
||||||
|
|
||||||
public class OrCriteria implements CriteriaDefinition {
|
|
||||||
|
|
||||||
Query[] queries = null;
|
|
||||||
|
|
||||||
public OrCriteria(Query[] queries) {
|
|
||||||
super();
|
|
||||||
this.queries = queries;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.datastore.document.mongodb.query.Criteria#
|
|
||||||
* getCriteriaObject(java.lang.String)
|
|
||||||
*/
|
|
||||||
public DBObject getCriteriaObject() {
|
|
||||||
DBObject dbo = new BasicDBObject();
|
|
||||||
BasicBSONList l = new BasicBSONList();
|
|
||||||
for (Query q : queries) {
|
|
||||||
l.add(q.getQueryObject());
|
|
||||||
}
|
|
||||||
dbo.put(getOperator(), l);
|
|
||||||
return dbo;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getOperator() {
|
|
||||||
return "$or";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package org.springframework.data.document.mongodb.query;
|
|
||||||
|
|
||||||
public class OrQuery extends Query {
|
|
||||||
|
|
||||||
public OrQuery(Query... q) {
|
|
||||||
super.or(q);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2011 by the original author(s).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.query;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import org.bson.types.BasicBSONList;
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.springframework.core.convert.ConversionException;
|
|
||||||
import org.springframework.data.document.mongodb.convert.MongoConverter;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity;
|
|
||||||
import org.springframework.data.mapping.model.PersistentEntity;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A helper class to encapsulate any modifications of a Query object before it gets submitted to the database.
|
|
||||||
*
|
|
||||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public class QueryMapper {
|
|
||||||
|
|
||||||
private final MongoConverter converter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link QueryMapper} with the given {@link MongoConverter}.
|
|
||||||
*
|
|
||||||
* @param converter
|
|
||||||
*/
|
|
||||||
public QueryMapper(MongoConverter converter) {
|
|
||||||
Assert.notNull(converter);
|
|
||||||
this.converter = converter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces the property keys used in the given {@link DBObject} with the appropriate keys by using the
|
|
||||||
* {@link PersistentEntity} metadata.
|
|
||||||
*
|
|
||||||
* @param query
|
|
||||||
* @param entity
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public DBObject getMappedObject(DBObject query, MongoPersistentEntity<?> entity) {
|
|
||||||
String idKey = null;
|
|
||||||
if (null != entity && entity.getIdProperty() != null) {
|
|
||||||
idKey = entity.getIdProperty().getName();
|
|
||||||
} else if (query.containsField("id")) {
|
|
||||||
idKey = "id";
|
|
||||||
} else if (query.containsField("_id")) {
|
|
||||||
idKey = "_id";
|
|
||||||
}
|
|
||||||
|
|
||||||
DBObject newDbo = new BasicDBObject();
|
|
||||||
for (String key : query.keySet()) {
|
|
||||||
String newKey = key;
|
|
||||||
Object value = query.get(key);
|
|
||||||
if (key.equals(idKey)) {
|
|
||||||
if (value instanceof DBObject) {
|
|
||||||
DBObject valueDbo = (DBObject) value;
|
|
||||||
if (valueDbo.containsField("$in") || valueDbo.containsField("$nin")) {
|
|
||||||
String inKey = valueDbo.containsField("$in") ? "$in" : "$nin";
|
|
||||||
List<Object> ids = new ArrayList<Object>();
|
|
||||||
for (Object id : (Object[]) valueDbo.get(inKey)) {
|
|
||||||
if (null != converter && !(id instanceof ObjectId)) {
|
|
||||||
try {
|
|
||||||
ObjectId oid = converter.convertObjectId(id);
|
|
||||||
ids.add(oid);
|
|
||||||
} catch (ConversionException ignored) {
|
|
||||||
ids.add(id);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ids.add(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
valueDbo.put(inKey, ids.toArray(new Object[ids.size()]));
|
|
||||||
} else {
|
|
||||||
value = getMappedObject((DBObject) value, entity);
|
|
||||||
}
|
|
||||||
} else if (null != converter) {
|
|
||||||
try {
|
|
||||||
value = converter.convertObjectId(value);
|
|
||||||
} catch (ConversionException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newKey = "_id";
|
|
||||||
} else if (key.startsWith("$") && key.endsWith("or")) {
|
|
||||||
// $or/$nor
|
|
||||||
BasicBSONList conditions = (BasicBSONList) value;
|
|
||||||
BasicBSONList newConditions = new BasicBSONList();
|
|
||||||
Iterator iter = conditions.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
newConditions.add(getMappedObject((DBObject) iter.next(), entity));
|
|
||||||
}
|
|
||||||
value = newConditions;
|
|
||||||
} else {
|
|
||||||
// TODO: Implement other forms of conversion (like @Alias and whatnot)
|
|
||||||
}
|
|
||||||
newDbo.put(newKey, value);
|
|
||||||
}
|
|
||||||
return newDbo;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* MongoDB specific query and update support.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.query;
|
|
||||||
|
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2002-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.repository;
|
|
||||||
|
|
||||||
import static org.springframework.data.document.mongodb.repository.QueryUtils.applyPagination;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.DBCursor;
|
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import org.springframework.data.document.mongodb.CollectionCallback;
|
|
||||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.repository.query.ParameterAccessor;
|
|
||||||
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
|
||||||
import org.springframework.data.repository.query.RepositoryQuery;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for {@link RepositoryQuery} implementations for Mongo.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public abstract class AbstractMongoQuery implements RepositoryQuery {
|
|
||||||
|
|
||||||
private final MongoQueryMethod method;
|
|
||||||
private final MongoTemplate template;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoTemplate}.
|
|
||||||
*
|
|
||||||
* @param method
|
|
||||||
* @param template
|
|
||||||
*/
|
|
||||||
public AbstractMongoQuery(MongoQueryMethod method, MongoTemplate template) {
|
|
||||||
|
|
||||||
Assert.notNull(template);
|
|
||||||
Assert.notNull(method);
|
|
||||||
|
|
||||||
this.method = method;
|
|
||||||
this.template = template;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.repository.query.RepositoryQuery#getQueryMethod()
|
|
||||||
*/
|
|
||||||
public MongoQueryMethod getQueryMethod() {
|
|
||||||
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.repository.query.RepositoryQuery#execute(java .lang.Object[])
|
|
||||||
*/
|
|
||||||
public Object execute(Object[] parameters) {
|
|
||||||
|
|
||||||
ParameterAccessor accessor = new ParametersParameterAccessor(method.getParameters(), parameters);
|
|
||||||
Query query = createQuery(new ConvertingParameterAccessor(template.getConverter(), accessor));
|
|
||||||
|
|
||||||
switch (method.getType()) {
|
|
||||||
case COLLECTION:
|
|
||||||
return new CollectionExecution().execute(query);
|
|
||||||
case PAGING:
|
|
||||||
return new PagedExecution(accessor.getPageable()).execute(query);
|
|
||||||
default:
|
|
||||||
return new SingleEntityExecution().execute(query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a {@link Query} instance using the given {@link ParameterAccessor}
|
|
||||||
*
|
|
||||||
* @param accessor
|
|
||||||
* @param converter
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected abstract Query createQuery(ConvertingParameterAccessor accessor);
|
|
||||||
|
|
||||||
private abstract class Execution {
|
|
||||||
|
|
||||||
abstract Object execute(Query query);
|
|
||||||
|
|
||||||
protected List<?> readCollection(Query query) {
|
|
||||||
|
|
||||||
MongoEntityInformation<?, ?> metadata = method.getEntityInformation();
|
|
||||||
|
|
||||||
String collectionName = metadata.getCollectionName();
|
|
||||||
return template.find(query, metadata.getJavaType(), collectionName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link Execution} for collection returning queries.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
class CollectionExecution extends Execution {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.document.mongodb.repository.MongoQuery.Execution #execute(com.mongodb.DBObject)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Object execute(Query query) {
|
|
||||||
|
|
||||||
return readCollection(query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link Execution} for pagination queries.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
class PagedExecution extends Execution {
|
|
||||||
|
|
||||||
private final Pageable pageable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link PagedExecution}.
|
|
||||||
*
|
|
||||||
* @param pageable
|
|
||||||
*/
|
|
||||||
public PagedExecution(Pageable pageable) {
|
|
||||||
|
|
||||||
Assert.notNull(pageable);
|
|
||||||
this.pageable = pageable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.document.mongodb.repository.MongoQuery.Execution #execute(com.mongodb.DBObject)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
Object execute(Query query) {
|
|
||||||
|
|
||||||
MongoEntityInformation<?, ?> metadata = method.getEntityInformation();
|
|
||||||
int count = getCollectionCursor(metadata.getCollectionName(), query.getQueryObject()).count();
|
|
||||||
|
|
||||||
List<?> result = template.find(applyPagination(query, pageable), metadata.getJavaType(),
|
|
||||||
metadata.getCollectionName());
|
|
||||||
|
|
||||||
return new PageImpl(result, pageable, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private DBCursor getCollectionCursor(String collectionName, final DBObject query) {
|
|
||||||
|
|
||||||
return template.execute(collectionName, new CollectionCallback<DBCursor>() {
|
|
||||||
|
|
||||||
public DBCursor doInCollection(DBCollection collection) {
|
|
||||||
|
|
||||||
return collection.find(query);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link Execution} to return a single entity.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
class SingleEntityExecution extends Execution {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.document.mongodb.repository.MongoQuery.Execution #execute(com.mongodb.DBObject)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
Object execute(Query query) {
|
|
||||||
|
|
||||||
List<?> result = readCollection(query);
|
|
||||||
return result.isEmpty() ? null : result.get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2002-2010 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.repository;
|
|
||||||
|
|
||||||
import static org.springframework.data.document.mongodb.query.Criteria.where;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.data.document.mongodb.geo.Box;
|
|
||||||
import org.springframework.data.document.mongodb.geo.Circle;
|
|
||||||
import org.springframework.data.document.mongodb.geo.Point;
|
|
||||||
import org.springframework.data.document.mongodb.query.Criteria;
|
|
||||||
import org.springframework.data.document.mongodb.query.CriteriaDefinition;
|
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
|
||||||
import org.springframework.data.document.mongodb.repository.ConvertingParameterAccessor.PotentiallyConvertingIterator;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.data.repository.query.ParameterAccessor;
|
|
||||||
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
|
||||||
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
|
|
||||||
import org.springframework.data.repository.query.parser.Part;
|
|
||||||
import org.springframework.data.repository.query.parser.Part.Type;
|
|
||||||
import org.springframework.data.repository.query.parser.PartTree;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom query creator to create Mongo criterias.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
class MongoQueryCreator extends AbstractQueryCreator<Query, Query> {
|
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(MongoQueryCreator.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link MongoQueryCreator} from the given {@link PartTree} and {@link ParametersParameterAccessor}.
|
|
||||||
*
|
|
||||||
* @param tree
|
|
||||||
* @param accessor
|
|
||||||
*/
|
|
||||||
public MongoQueryCreator(PartTree tree, ParameterAccessor accessor) {
|
|
||||||
|
|
||||||
super(tree, accessor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.repository.query.parser.AbstractQueryCreator#create(org.springframework.data.repository.query.parser.Part, java.util.Iterator)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected Query create(Part part, Iterator<Object> iterator) {
|
|
||||||
|
|
||||||
Criteria criteria = from(part.getType(), where(part.getProperty().toDotPath()),
|
|
||||||
(PotentiallyConvertingIterator) iterator);
|
|
||||||
|
|
||||||
return new Query(criteria);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.repository.query.parser.AbstractQueryCreator#and(org.springframework.data.repository.query.parser.Part, java.lang.Object, java.util.Iterator)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected Query and(Part part, Query base, Iterator<Object> iterator) {
|
|
||||||
|
|
||||||
Criteria criteria = from(part.getType(), where(part.getProperty().toDotPath()),
|
|
||||||
(PotentiallyConvertingIterator) iterator);
|
|
||||||
return base.addCriteria(criteria);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.query.parser.AbstractQueryCreator
|
|
||||||
* #or(java.lang.Object, java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected Query or(Query base, Query query) {
|
|
||||||
|
|
||||||
return new Query().or(base, query);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.query.parser.AbstractQueryCreator
|
|
||||||
* #complete(java.lang.Object, org.springframework.data.domain.Sort)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected Query complete(Query query, Sort sort) {
|
|
||||||
|
|
||||||
if (LOG.isDebugEnabled()) {
|
|
||||||
LOG.debug("Created query " + query.getQueryObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populates the given {@link CriteriaDefinition} depending on the {@link Type} given.
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param criteria
|
|
||||||
* @param parameters
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Criteria from(Type type, Criteria criteria, PotentiallyConvertingIterator parameters) {
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case GREATER_THAN:
|
|
||||||
return criteria.gt(parameters.nextConverted());
|
|
||||||
case LESS_THAN:
|
|
||||||
return criteria.lt(parameters.nextConverted());
|
|
||||||
case BETWEEN:
|
|
||||||
return criteria.gt(parameters.nextConverted()).lt(parameters.nextConverted());
|
|
||||||
case IS_NOT_NULL:
|
|
||||||
return criteria.ne(null);
|
|
||||||
case IS_NULL:
|
|
||||||
return criteria.is(null);
|
|
||||||
case NOT_IN:
|
|
||||||
return criteria.nin(nextAsArray(parameters));
|
|
||||||
case IN:
|
|
||||||
return criteria.in(nextAsArray(parameters));
|
|
||||||
case LIKE:
|
|
||||||
String value = parameters.next().toString();
|
|
||||||
return criteria.is(toLikeRegex(value));
|
|
||||||
case NEAR:
|
|
||||||
return criteria.near(nextAs(parameters, Point.class));
|
|
||||||
case WITHIN:
|
|
||||||
|
|
||||||
Object parameter = parameters.next();
|
|
||||||
if (parameter instanceof Box) {
|
|
||||||
return criteria.withinBox((Box) parameter);
|
|
||||||
} else if (parameter instanceof Circle) {
|
|
||||||
return criteria.withinCenter((Circle) parameter);
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Parameter has to be either Box or Circle!");
|
|
||||||
case SIMPLE_PROPERTY:
|
|
||||||
return criteria.is(parameters.nextConverted());
|
|
||||||
case NEGATING_SIMPLE_PROPERTY:
|
|
||||||
return criteria.not().is(parameters.nextConverted());
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException("Unsupported keyword!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the next element from the given {@link Iterator} expecting it to be of a certain type.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* @param iterator
|
|
||||||
* @param type
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* in case the next element in the iterator is not of the given type.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <T> T nextAs(Iterator<Object> iterator, Class<T> type) {
|
|
||||||
Object parameter = iterator.next();
|
|
||||||
if (parameter.getClass().isAssignableFrom(type)) {
|
|
||||||
return (T) parameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException(String.format("Expected parameter type of %s but got %s!", type,
|
|
||||||
parameter.getClass()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object[] nextAsArray(PotentiallyConvertingIterator iterator) {
|
|
||||||
Object next = iterator.nextConverted();
|
|
||||||
|
|
||||||
if (next instanceof Collection) {
|
|
||||||
return ((Collection<?>) next).toArray();
|
|
||||||
} else if (next.getClass().isArray()) {
|
|
||||||
return (Object[]) next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Object[] { next };
|
|
||||||
}
|
|
||||||
|
|
||||||
private Pattern toLikeRegex(String source) {
|
|
||||||
|
|
||||||
String regex = source.replaceAll("\\*", ".*");
|
|
||||||
return Pattern.compile(regex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,314 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2002-2010 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.repository;
|
|
||||||
|
|
||||||
import static org.springframework.data.querydsl.QueryDslUtils.*;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.data.document.mongodb.MongoOperations;
|
|
||||||
import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoPropertyDescriptor;
|
|
||||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity;
|
|
||||||
import org.springframework.data.document.mongodb.mapping.MongoPersistentProperty;
|
|
||||||
import org.springframework.data.document.mongodb.query.Index;
|
|
||||||
import org.springframework.data.document.mongodb.query.Order;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.data.mapping.model.MappingContext;
|
|
||||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
|
||||||
import org.springframework.data.repository.Repository;
|
|
||||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
|
||||||
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
|
||||||
import org.springframework.data.repository.query.RepositoryQuery;
|
|
||||||
import org.springframework.data.repository.query.parser.Part;
|
|
||||||
import org.springframework.data.repository.query.parser.Part.Type;
|
|
||||||
import org.springframework.data.repository.query.parser.PartTree;
|
|
||||||
import org.springframework.data.repository.support.QueryCreationListener;
|
|
||||||
import org.springframework.data.repository.support.RepositoryFactoryBeanSupport;
|
|
||||||
import org.springframework.data.repository.support.RepositoryFactorySupport;
|
|
||||||
import org.springframework.data.repository.support.RepositoryMetadata;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link org.springframework.beans.factory.FactoryBean} to create {@link MongoRepository} instances.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public class MongoRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
|
|
||||||
RepositoryFactoryBeanSupport<T, S, ID> {
|
|
||||||
|
|
||||||
private MongoTemplate template;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the {@link MongoTemplate} to be used.
|
|
||||||
*
|
|
||||||
* @param template
|
|
||||||
* the template to set
|
|
||||||
*/
|
|
||||||
public void setTemplate(MongoTemplate template) {
|
|
||||||
|
|
||||||
this.template = template;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.support.RepositoryFactoryBeanSupport
|
|
||||||
* #createRepositoryFactory()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected RepositoryFactorySupport createRepositoryFactory() {
|
|
||||||
|
|
||||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(template);
|
|
||||||
factory.addQueryCreationListener(new IndexEnsuringQueryCreationListener(template));
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.support.RepositoryFactoryBeanSupport
|
|
||||||
* #afterPropertiesSet()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void afterPropertiesSet() {
|
|
||||||
|
|
||||||
super.afterPropertiesSet();
|
|
||||||
Assert.notNull(template, "MongoTemplate must not be null!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Repository to create {@link MongoRepository} instances.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public static class MongoRepositoryFactory extends RepositoryFactorySupport {
|
|
||||||
|
|
||||||
private final MongoTemplate template;
|
|
||||||
private final EntityInformationCreator entityInformationCreator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link MongoRepositoryFactory} with the given {@link MongoTemplate} and {@link MappingContext}.
|
|
||||||
*
|
|
||||||
* @param template
|
|
||||||
* must not be {@literal null}
|
|
||||||
* @param mappingContext
|
|
||||||
*/
|
|
||||||
public MongoRepositoryFactory(MongoTemplate template) {
|
|
||||||
|
|
||||||
Assert.notNull(template);
|
|
||||||
this.template = template;
|
|
||||||
this.entityInformationCreator = new EntityInformationCreator(template.getConverter()
|
|
||||||
.getMappingContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.support.RepositoryFactorySupport
|
|
||||||
* #getRepositoryBaseClass()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
|
|
||||||
|
|
||||||
return isQueryDslRepository(metadata.getRepositoryInterface()) ? QueryDslMongoRepository.class
|
|
||||||
: SimpleMongoRepository.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.support.RepositoryFactorySupport
|
|
||||||
* #getTargetRepository
|
|
||||||
* (org.springframework.data.repository.support.RepositoryMetadata)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
protected Object getTargetRepository(RepositoryMetadata metadata) {
|
|
||||||
|
|
||||||
Class<?> repositoryInterface = metadata.getRepositoryInterface();
|
|
||||||
MongoEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainClass());
|
|
||||||
|
|
||||||
if (isQueryDslRepository(repositoryInterface)) {
|
|
||||||
return new QueryDslMongoRepository(entityInformation, template);
|
|
||||||
} else {
|
|
||||||
return new SimpleMongoRepository(entityInformation, template);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isQueryDslRepository(Class<?> repositoryInterface) {
|
|
||||||
|
|
||||||
return QUERY_DSL_PRESENT && QueryDslPredicateExecutor.class.isAssignableFrom(repositoryInterface);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.support.RepositoryFactorySupport
|
|
||||||
* #getQueryLookupStrategy
|
|
||||||
* (org.springframework.data.repository.query.QueryLookupStrategy.Key)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected QueryLookupStrategy getQueryLookupStrategy(Key key) {
|
|
||||||
|
|
||||||
return new MongoQueryLookupStrategy();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link QueryLookupStrategy} to create {@link PartTreeMongoQuery} instances.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
private class MongoQueryLookupStrategy implements QueryLookupStrategy {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.query.QueryLookupStrategy
|
|
||||||
* #resolveQuery(java.lang.reflect.Method, java.lang.Class)
|
|
||||||
*/
|
|
||||||
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata) {
|
|
||||||
|
|
||||||
MongoQueryMethod queryMethod = new MongoQueryMethod(method, metadata, entityInformationCreator);
|
|
||||||
|
|
||||||
if (queryMethod.hasAnnotatedQuery()) {
|
|
||||||
return new StringBasedMongoQuery(queryMethod, template);
|
|
||||||
} else {
|
|
||||||
return new PartTreeMongoQuery(queryMethod, template);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.repository.support.RepositoryFactorySupport#validate(org.springframework.data.repository.support.RepositoryMetadata)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void validate(RepositoryMetadata metadata) {
|
|
||||||
|
|
||||||
Class<?> idClass = metadata.getIdClass();
|
|
||||||
if (!MongoPropertyDescriptor.SUPPORTED_ID_CLASSES.contains(idClass)) {
|
|
||||||
throw new IllegalArgumentException(String.format("Unsupported id class! Only %s are supported!",
|
|
||||||
StringUtils.collectionToCommaDelimitedString(MongoPropertyDescriptor.SUPPORTED_ID_CLASSES)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.support.RepositoryFactorySupport
|
|
||||||
* #getEntityInformation(java.lang.Class)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
|
||||||
|
|
||||||
return entityInformationCreator.getEntityInformation(domainClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple wrapper to to create {@link MongoEntityInformation} instances based on a {@link MappingContext}.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
static class EntityInformationCreator {
|
|
||||||
|
|
||||||
private final MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext;
|
|
||||||
|
|
||||||
public EntityInformationCreator(MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext) {
|
|
||||||
Assert.notNull(mappingContext);
|
|
||||||
this.mappingContext = mappingContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
|
||||||
MongoPersistentEntity<T> persistentEntity = (MongoPersistentEntity<T>) mappingContext
|
|
||||||
.getPersistentEntity(domainClass);
|
|
||||||
return new MappingMongoEntityInformation<T, ID>(persistentEntity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link QueryCreationListener} inspecting {@link PartTreeMongoQuery}s and creating an index for the properties it
|
|
||||||
* refers to.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
private static class IndexEnsuringQueryCreationListener implements QueryCreationListener<PartTreeMongoQuery> {
|
|
||||||
|
|
||||||
private static final Set<Type> GEOSPATIAL_TYPES = new HashSet<Part.Type>(Arrays.asList(Type.NEAR, Type.WITHIN));
|
|
||||||
private static final Log LOG = LogFactory.getLog(IndexEnsuringQueryCreationListener.class);
|
|
||||||
private final MongoOperations operations;
|
|
||||||
|
|
||||||
public IndexEnsuringQueryCreationListener(MongoOperations operations) {
|
|
||||||
|
|
||||||
this.operations = operations;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.support.QueryCreationListener
|
|
||||||
* #onCreation(org.springframework.data.repository
|
|
||||||
* .query.RepositoryQuery)
|
|
||||||
*/
|
|
||||||
public void onCreation(PartTreeMongoQuery query) {
|
|
||||||
|
|
||||||
PartTree tree = query.getTree();
|
|
||||||
Index index = new Index();
|
|
||||||
index.named(query.getQueryMethod().getName());
|
|
||||||
Sort sort = tree.getSort();
|
|
||||||
|
|
||||||
for (Part part : tree.getParts()) {
|
|
||||||
if (GEOSPATIAL_TYPES.contains(part.getType())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String property = part.getProperty().toDotPath();
|
|
||||||
Order order = toOrder(sort, property);
|
|
||||||
index.on(property, order);
|
|
||||||
}
|
|
||||||
|
|
||||||
MongoEntityInformation<?, ?> metadata = query.getQueryMethod().getEntityInformation();
|
|
||||||
operations.ensureIndex(index, metadata.getCollectionName());
|
|
||||||
LOG.debug(String.format("Created %s!", index));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Order toOrder(Sort sort, String property) {
|
|
||||||
|
|
||||||
if (sort == null) {
|
|
||||||
return Order.DESCENDING;
|
|
||||||
}
|
|
||||||
|
|
||||||
org.springframework.data.domain.Sort.Order order = sort.getOrderFor(property);
|
|
||||||
return order == null ? Order.DESCENDING : order.isAscending() ? Order.ASCENDING : Order.DESCENDING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,268 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2011 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.repository;
|
|
||||||
|
|
||||||
import static org.springframework.data.document.mongodb.query.Criteria.*;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
import org.springframework.data.document.mongodb.CollectionCallback;
|
|
||||||
import org.springframework.data.document.mongodb.MongoOperations;
|
|
||||||
import org.springframework.data.document.mongodb.MongoTemplate;
|
|
||||||
import org.springframework.data.document.mongodb.query.Criteria;
|
|
||||||
import org.springframework.data.document.mongodb.query.Query;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject;
|
|
||||||
import com.mongodb.DBCollection;
|
|
||||||
import com.mongodb.MongoException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Repository base implementation for Mongo.
|
|
||||||
*
|
|
||||||
* @author Oliver Gierke
|
|
||||||
*/
|
|
||||||
public class SimpleMongoRepository<T, ID extends Serializable> implements PagingAndSortingRepository<T, ID> {
|
|
||||||
|
|
||||||
private final MongoTemplate template;
|
|
||||||
private final MongoEntityInformation<T, ID> entityInformation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a ew {@link SimpleMongoRepository} for the given {@link MongoEntityInformation} and {@link MongoTemplate}.
|
|
||||||
*
|
|
||||||
* @param metadata
|
|
||||||
* @param template
|
|
||||||
*/
|
|
||||||
public SimpleMongoRepository(MongoEntityInformation<T, ID> metadata, MongoTemplate template) {
|
|
||||||
|
|
||||||
Assert.notNull(template);
|
|
||||||
Assert.notNull(metadata);
|
|
||||||
this.entityInformation = metadata;
|
|
||||||
this.template = template;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.Repository#save(java.lang.Object)
|
|
||||||
*/
|
|
||||||
public T save(T entity) {
|
|
||||||
|
|
||||||
template.save(entity, entityInformation.getCollectionName());
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.Repository#save(java.lang.Iterable)
|
|
||||||
*/
|
|
||||||
public List<T> save(Iterable<? extends T> entities) {
|
|
||||||
|
|
||||||
List<T> result = new ArrayList<T>();
|
|
||||||
|
|
||||||
for (T entity : entities) {
|
|
||||||
save(entity);
|
|
||||||
result.add(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.Repository#findById(java.io.Serializable
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
public T findOne(ID id) {
|
|
||||||
return template.findById(id, entityInformation.getJavaType());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Query getIdQuery(Object id) {
|
|
||||||
return new Query(getIdCriteria(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Criteria getIdCriteria(Object id) {
|
|
||||||
return where(entityInformation.getIdAttribute()).is(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.Repository#exists(java.io.Serializable
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
public boolean exists(final ID id) {
|
|
||||||
|
|
||||||
return template.execute(entityInformation.getCollectionName(), new CollectionCallback<Boolean>() {
|
|
||||||
|
|
||||||
public Boolean doInCollection(DBCollection collection) throws MongoException, DataAccessException {
|
|
||||||
return collection.count(new BasicDBObject("_id", id)) > 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.repository.Repository#count()
|
|
||||||
*/
|
|
||||||
public long count() {
|
|
||||||
|
|
||||||
return template.getCollection(entityInformation.getCollectionName()).count();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.repository.Repository#delete(java.io.Serializable)
|
|
||||||
*/
|
|
||||||
public void delete(ID id) {
|
|
||||||
template.remove(getIdQuery(id), entityInformation.getJavaType());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.Repository#delete(java.lang.Object)
|
|
||||||
*/
|
|
||||||
public void delete(T entity) {
|
|
||||||
delete(entityInformation.getId(entity));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.Repository#delete(java.lang.Iterable)
|
|
||||||
*/
|
|
||||||
public void delete(Iterable<? extends T> entities) {
|
|
||||||
|
|
||||||
for (T entity : entities) {
|
|
||||||
delete(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.repository.Repository#deleteAll()
|
|
||||||
*/
|
|
||||||
public void deleteAll() {
|
|
||||||
|
|
||||||
template.remove(new Query(), entityInformation.getCollectionName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.springframework.data.repository.Repository#findAll()
|
|
||||||
*/
|
|
||||||
public List<T> findAll() {
|
|
||||||
|
|
||||||
return findAll(new Query());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.PagingAndSortingRepository#findAll
|
|
||||||
* (org.springframework.data.domain.Pageable)
|
|
||||||
*/
|
|
||||||
public Page<T> findAll(final Pageable pageable) {
|
|
||||||
|
|
||||||
Long count = count();
|
|
||||||
List<T> list = findAll(QueryUtils.applyPagination(new Query(), pageable));
|
|
||||||
|
|
||||||
return new PageImpl<T>(list, pageable, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.PagingAndSortingRepository#findAll
|
|
||||||
* (org.springframework.data.domain.Sort)
|
|
||||||
*/
|
|
||||||
public List<T> findAll(final Sort sort) {
|
|
||||||
|
|
||||||
return findAll(QueryUtils.applySorting(new Query(), sort));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.springframework.data.repository.Repository#findAll(java.lang.Iterable
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
public List<T> findAll(Iterable<ID> ids) {
|
|
||||||
|
|
||||||
Query query = null;
|
|
||||||
|
|
||||||
for (ID id : ids) {
|
|
||||||
if (query == null) {
|
|
||||||
query = getIdQuery(id);
|
|
||||||
} else {
|
|
||||||
query = new Query().or(getIdQuery(id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return findAll(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<T> findAll(Query query) {
|
|
||||||
|
|
||||||
if (query == null) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return template.find(query, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the underlying {@link MongoOperations} instance.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected MongoOperations getMongoOperations() {
|
|
||||||
|
|
||||||
return this.template;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the entityInformation
|
|
||||||
*/
|
|
||||||
protected MongoEntityInformation<T, ID> getEntityInformation() {
|
|
||||||
|
|
||||||
return entityInformation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* MongoDB specific repository implementation.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.document.mongodb.repository;
|
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2011 the original author or authors.
|
* Copyright 2010-2012 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,45 +13,54 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.document.mongodb;
|
package org.springframework.data.mongodb;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessResourceFailureException;
|
import org.springframework.dao.DataAccessResourceFailureException;
|
||||||
|
import org.springframework.data.authentication.UserCredentials;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception being thrown in case we cannot connect to a MongoDB instance.
|
||||||
|
*
|
||||||
|
* @author Oliver Gierke
|
||||||
|
*/
|
||||||
public class CannotGetMongoDbConnectionException extends DataAccessResourceFailureException {
|
public class CannotGetMongoDbConnectionException extends DataAccessResourceFailureException {
|
||||||
|
|
||||||
private String username;
|
private final UserCredentials credentials;
|
||||||
|
private final String database;
|
||||||
private char[] password;
|
|
||||||
|
|
||||||
private String database;
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1172099106475265589L;
|
private static final long serialVersionUID = 1172099106475265589L;
|
||||||
|
|
||||||
public CannotGetMongoDbConnectionException(String msg, Throwable cause) {
|
public CannotGetMongoDbConnectionException(String msg, Throwable cause) {
|
||||||
super(msg, cause);
|
super(msg, cause);
|
||||||
|
this.database = null;
|
||||||
|
this.credentials = UserCredentials.NO_CREDENTIALS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CannotGetMongoDbConnectionException(String msg) {
|
public CannotGetMongoDbConnectionException(String msg) {
|
||||||
super(msg);
|
this(msg, null, UserCredentials.NO_CREDENTIALS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CannotGetMongoDbConnectionException(String msg, String database, String username, char[] password2) {
|
public CannotGetMongoDbConnectionException(String msg, String database, UserCredentials credentials) {
|
||||||
super(msg);
|
super(msg);
|
||||||
this.username = username;
|
|
||||||
this.password = password2;
|
|
||||||
this.database = database;
|
this.database = database;
|
||||||
|
this.credentials = credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
/**
|
||||||
return username;
|
* Returns the {@link UserCredentials} that were used when trying to connect to the MongoDB instance.
|
||||||
}
|
*
|
||||||
|
* @return
|
||||||
public char[] getPassword() {
|
*/
|
||||||
return password;
|
public UserCredentials getCredentials() {
|
||||||
|
return this.credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the database trying to be accessed.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public String getDatabase() {
|
public String getDatabase() {
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010 the original author or authors.
|
* Copyright 2010-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,19 +13,19 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
package org.springframework.data.mongodb;
|
||||||
package org.springframework.data.document.mongodb;
|
|
||||||
|
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
|
|
||||||
public class InvalidMongoDbApiUsageException extends InvalidDataAccessApiUsageException {
|
public class InvalidMongoDbApiUsageException extends InvalidDataAccessApiUsageException {
|
||||||
|
|
||||||
public InvalidMongoDbApiUsageException(String msg) {
|
private static final long serialVersionUID = 2034770973290508041L;
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvalidMongoDbApiUsageException(String msg, Throwable cause) {
|
public InvalidMongoDbApiUsageException(String msg) {
|
||||||
super(msg, cause);
|
super(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InvalidMongoDbApiUsageException(String msg, Throwable cause) {
|
||||||
|
super(msg, cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,18 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.data.document.mongodb;
|
package org.springframework.data.mongodb;
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class featuring helper methods for working with MongoDb collections.
|
* Helper class featuring helper methods for working with MongoDb collections.
|
||||||
* <p/>
|
* <p/>
|
||||||
* <p/>
|
* <p/>
|
||||||
* Mainly intended for internal use within the framework.
|
* Mainly intended for internal use within the framework.
|
||||||
*
|
*
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
@@ -40,7 +38,7 @@ public abstract class MongoCollectionUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the collection name to use for the provided class
|
* Obtains the collection name to use for the provided class
|
||||||
*
|
*
|
||||||
* @param entityClass The class to determine the preferred collection name for
|
* @param entityClass The class to determine the preferred collection name for
|
||||||
* @return The preferred collection name
|
* @return The preferred collection name
|
||||||
*/
|
*/
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package org.springframework.data.mongodb;
|
||||||
|
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
||||||
|
import com.mongodb.DB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for factories creating {@link DB} instances.
|
||||||
|
*
|
||||||
|
* @author Mark Pollack
|
||||||
|
*/
|
||||||
|
public interface MongoDbFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a default {@link DB} instance.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws DataAccessException
|
||||||
|
*/
|
||||||
|
DB getDb() throws DataAccessException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link DB} instance to access the database with the given name.
|
||||||
|
*
|
||||||
|
* @param dbName must not be {@literal null} or empty.
|
||||||
|
* @return
|
||||||
|
* @throws DataAccessException
|
||||||
|
*/
|
||||||
|
DB getDb(String dbName) throws DataAccessException;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user