From bc969b91a6516972630074f8e321df71b9bc7a42 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 27 May 2016 15:17:19 +0200 Subject: [PATCH] Done a full code format review. Improve code format settings. --- .settings/org.eclipse.jdt.core.prefs | 280 +++++ .settings/org.eclipse.jdt.ui.prefs | 109 ++ src/fr/devinsy/sikevadb/Element.java | 84 +- src/fr/devinsy/sikevadb/Elements.java | 15 +- src/fr/devinsy/sikevadb/FileSikevaDB.java | 172 ++- src/fr/devinsy/sikevadb/SQLSikevaDB.java | 1075 +++++++++++------ src/fr/devinsy/sikevadb/SQLSikevaDBTools.java | 37 +- src/fr/devinsy/sikevadb/SikevaDB.java | 8 +- src/fr/devinsy/sikevadb/SikevaDBFactory.java | 16 +- src/fr/devinsy/sikevadb/SikevaDBUtils.java | 10 +- src/fr/devinsy/sikevadb/XMLSikevaDB.java | 121 +- test/fr/devinsy/sikevadb/SQLSikevaDBTest.java | 78 +- 12 files changed, 1442 insertions(+), 563 deletions(-) create mode 100644 .settings/org.eclipse.jdt.ui.prefs diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 8000cd6..7ced310 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -9,3 +9,283 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=0 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=next_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=next_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=next_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=next_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=false +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert +org.eclipse.jdt.core.formatter.comment.line_length=80 +org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true +org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true +org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=false +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.join_lines_in_comments=true +org.eclipse.jdt.core.formatter.join_wrapped_lines=true +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=200 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=tab +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.use_on_off_tags=false +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..0f1bd7a --- /dev/null +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,109 @@ +cleanup.add_default_serial_version_id=false +cleanup.add_generated_serial_version_id=true +cleanup.add_missing_annotations=true +cleanup.add_missing_deprecated_annotations=true +cleanup.add_missing_methods=false +cleanup.add_missing_nls_tags=false +cleanup.add_missing_override_annotations=true +cleanup.add_missing_override_annotations_interface_methods=true +cleanup.add_serial_version_id=true +cleanup.always_use_blocks=true +cleanup.always_use_parentheses_in_expressions=false +cleanup.always_use_this_for_non_static_field_access=true +cleanup.always_use_this_for_non_static_method_access=false +cleanup.convert_to_enhanced_for_loop=false +cleanup.correct_indentation=false +cleanup.format_source_code=true +cleanup.format_source_code_changes_only=false +cleanup.make_local_variable_final=false +cleanup.make_parameters_final=true +cleanup.make_private_fields_final=false +cleanup.make_type_abstract_if_missing_method=false +cleanup.make_variable_declarations_final=true +cleanup.never_use_blocks=false +cleanup.never_use_parentheses_in_expressions=true +cleanup.organize_imports=false +cleanup.qualify_static_field_accesses_with_declaring_class=false +cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=false +cleanup.qualify_static_member_accesses_with_declaring_class=true +cleanup.qualify_static_method_accesses_with_declaring_class=false +cleanup.remove_private_constructors=true +cleanup.remove_trailing_whitespaces=true +cleanup.remove_trailing_whitespaces_all=true +cleanup.remove_trailing_whitespaces_ignore_empty=false +cleanup.remove_unnecessary_casts=true +cleanup.remove_unnecessary_nls_tags=true +cleanup.remove_unused_imports=true +cleanup.remove_unused_local_variables=false +cleanup.remove_unused_private_fields=true +cleanup.remove_unused_private_members=false +cleanup.remove_unused_private_methods=true +cleanup.remove_unused_private_types=true +cleanup.sort_members=true +cleanup.sort_members_all=false +cleanup.use_blocks=true +cleanup.use_blocks_only_for_return_and_throw=false +cleanup.use_parentheses_in_expressions=false +cleanup.use_this_for_non_static_field_access=true +cleanup.use_this_for_non_static_field_access_only_if_necessary=false +cleanup.use_this_for_non_static_method_access=false +cleanup.use_this_for_non_static_method_access_only_if_necessary=true +cleanup_profile=_SikevaDB +cleanup_settings_version=2 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +formatter_profile=_SikevaDB +formatter_settings_version=12 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=true +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=true +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=true +sp_cleanup.make_private_fields_final=false +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=true +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=false +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=true +sp_cleanup.remove_unused_imports=true +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=true +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=true +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=true +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/src/fr/devinsy/sikevadb/Element.java b/src/fr/devinsy/sikevadb/Element.java index 3a2fdc8..5601215 100644 --- a/src/fr/devinsy/sikevadb/Element.java +++ b/src/fr/devinsy/sikevadb/Element.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013, 2014 Christian Pierre MOMON, DEVINSY + * Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * * This file is part of SikevaDB, simple key value database. * @@ -24,10 +24,10 @@ import org.joda.time.DateTime; /** * * - * @author Christian P. Momon + * @author Christian Pierre MOMON */ -public class Element { - +public class Element +{ public static final long NO_ID = -1; private long id; @@ -45,7 +45,8 @@ public class Element { * @param key * @param value */ - public Element() { + public Element() + { this.id = NO_ID; } @@ -54,7 +55,8 @@ public class Element { * @param key * @param value */ - public Element(final String key, final String subkey, final String value) { + public Element(final String key, final String subkey, final String value) + { update(value); this.archiveDate = null; this.key = key; @@ -64,83 +66,103 @@ public class Element { /** * */ - public void archive() { + public void archive() + { this.archiveDate = DateTime.now(); } - public DateTime getArchiveDate() { + public DateTime getArchiveDate() + { return this.archiveDate; } - public DateTime getCreationDate() { + public DateTime getCreationDate() + { return this.creationDate; } - public String getDigest() { + public String getDigest() + { return this.digest; } - public DateTime getEditionDate() { + public DateTime getEditionDate() + { return this.editionDate; } - public long getId() { + public long getId() + { return this.id; } - public String getKey() { + public String getKey() + { return this.key; } - public long getSize() { + public long getSize() + { return this.size; } - public String getSubkey() { + public String getSubkey() + { return this.subkey; } - public String getValue() { + public String getValue() + { return this.value; } - public void setArchiveDate(final DateTime date) { + public void setArchiveDate(final DateTime date) + { this.archiveDate = date; } - public void setCreationDate(final DateTime date) { + public void setCreationDate(final DateTime date) + { this.creationDate = date; } - public void setDigest(final String digest) { + public void setDigest(final String digest) + { this.digest = digest; } - public void setEditionDate(final DateTime date) { + public void setEditionDate(final DateTime date) + { this.editionDate = date; } - public void setId(final long id) { + public void setId(final long id) + { this.id = id; } - public void setKey(final String key) { + public void setKey(final String key) + { this.key = key; } - public void setSize(final long size) { + public void setSize(final long size) + { this.size = size; } - public void setSubkey(final String subkey) { + public void setSubkey(final String subkey) + { this.subkey = subkey; } - public void setValue(final String value) { + public void setValue(final String value) + { this.value = value; } - public void update(final String value) { + public void update(final String value) + { // setValue(value); @@ -148,16 +170,20 @@ public class Element { this.editionDate = DateTime.now(); // - if (value == null) { + if (value == null) + { this.size = 0; this.digest = null; - } else { + } + else + { this.size = this.value.length(); this.digest = DigestUtils.md5Hex(this.value); } // - if (this.creationDate == null) { + if (this.creationDate == null) + { this.creationDate = this.editionDate; } } diff --git a/src/fr/devinsy/sikevadb/Elements.java b/src/fr/devinsy/sikevadb/Elements.java index 52ccdda..aab2696 100644 --- a/src/fr/devinsy/sikevadb/Elements.java +++ b/src/fr/devinsy/sikevadb/Elements.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013, 2014 Christian Pierre MOMON, DEVINSY + * Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * * This file is part of SikevaDB, simple key value database. * @@ -23,24 +23,25 @@ import java.util.ArrayList; /** * * - * @author Christian P. Momon + * @author Christian Pierre MOMON */ -public class Elements extends ArrayList { - +public class Elements extends ArrayList +{ private static final long serialVersionUID = 6298920093179395791L; /** * */ - public Elements() { + public Elements() + { super(); } /** * */ - public Elements(final int initialCapacity) { + public Elements(final int initialCapacity) + { super(initialCapacity); } - } diff --git a/src/fr/devinsy/sikevadb/FileSikevaDB.java b/src/fr/devinsy/sikevadb/FileSikevaDB.java index 27874f8..f544612 100644 --- a/src/fr/devinsy/sikevadb/FileSikevaDB.java +++ b/src/fr/devinsy/sikevadb/FileSikevaDB.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013, 2014 Christian Pierre MOMON, DEVINSY + * Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * * This file is part of SikevaDB, simple key value database. * @@ -27,14 +27,16 @@ import fr.devinsy.util.StringList; /** * * - * @author Christian P. Momon + * @author Christian Pierre MOMON */ -public class FileSikevaDB implements SikevaDB { +public class FileSikevaDB implements SikevaDB +{ /** * * @param path */ - public FileSikevaDB(final File path) { + public FileSikevaDB(final File path) + { } @@ -42,324 +44,378 @@ public class FileSikevaDB implements SikevaDB { * * @param path */ - public FileSikevaDB(final String path) { + public FileSikevaDB(final String path) + { } @Override - public void archive(final String key) throws Exception { + public void archive(final String key) throws Exception + { // TODO Auto-generated method stub } @Override - public void archive(final String key, final String subkey) throws Exception { + public void archive(final String key, final String subkey) throws Exception + { // TODO Auto-generated method stub } @Override - public void clearAllArchive() throws Exception { + public void clearAllArchive() throws Exception + { // TODO Auto-generated method stub } @Override - public void clearArchive(final DateTime beforeDate) throws Exception { + public void clearArchive(final DateTime beforeDate) throws Exception + { // TODO Auto-generated method stub } @Override - public void clearArchive(final int maxDays) throws Exception { + public void clearArchive(final int maxDays) throws Exception + { // TODO Auto-generated method stub } @Override - public void clearDatabase() throws Exception { + public void clearDatabase() throws Exception + { // TODO Auto-generated method stub } @Override - public void close() { + public void close() + { // TODO Auto-generated method stub } @Override - public long countOfAllElements() { + public long countOfAllElements() + { // TODO Auto-generated method stub return 0; } @Override - public long countOfAllElements(final String key) { + public long countOfAllElements(final String key) + { // TODO Auto-generated method stub return 0; } @Override - public long countOfAllElements(final String key, final String subkey) { + public long countOfAllElements(final String key, final String subkey) + { // TODO Auto-generated method stub return 0; } @Override - public long countOfArchivedElements() { + public long countOfArchivedElements() + { // TODO Auto-generated method stub return 0; } @Override - public long countOfArchivedElements(final String key) { + public long countOfArchivedElements(final String key) + { // TODO Auto-generated method stub return 0; } @Override - public long countOfArchivedElements(final String key, final String subkey) { + public long countOfArchivedElements(final String key, final String subkey) + { // TODO Auto-generated method stub return 0; } @Override - public long countOfElements() { + public long countOfElements() + { // TODO Auto-generated method stub return 0; } @Override - public long countOfElements(final String key) { + public long countOfElements(final String key) + { // TODO Auto-generated method stub return 0; } @Override - public long countOfElements(final String key, final String subkey) { + public long countOfElements(final String key, final String subkey) + { // TODO Auto-generated method stub return 0; } @Override - public Elements getAllElements() throws Exception { + public Elements getAllElements() throws Exception + { // TODO Auto-generated method stub return null; } @Override - public Elements getAllElements(final String key) throws Exception { + public Elements getAllElements(final String key) throws Exception + { // TODO Auto-generated method stub return null; } @Override - public Elements getAllElements(final String key, final String subkey) throws Exception { + public Elements getAllElements(final String key, final String subkey) throws Exception + { // TODO Auto-generated method stub return null; } @Override - public StringList getAllKeys() throws Exception { + public StringList getAllKeys() throws Exception + { // TODO Auto-generated method stub return null; } @Override - public StringList getAllSubkeys(final String key) throws Exception { + public StringList getAllSubkeys(final String key) throws Exception + { // TODO Auto-generated method stub return null; } @Override - public StringList getAllValues(final String key) { + public StringList getAllValues(final String key) + { // TODO Auto-generated method stub return null; } @Override - public StringList getAllValues(final String key, final String subkey) { + public StringList getAllValues(final String key, final String subkey) + { // TODO Auto-generated method stub return null; } @Override - public StringList getArchivedValues(final String key) { + public StringList getArchivedValues(final String key) + { // TODO Auto-generated method stub return null; } @Override - public StringList getArchivedValues(final String key, final String subkey) { + public StringList getArchivedValues(final String key, final String subkey) + { // TODO Auto-generated method stub return null; } @Override - public Element getElement(final String key) throws Exception { + public Element getElement(final String key) throws Exception + { // TODO Auto-generated method stub return null; } @Override - public Element getElement(final String key, final String subkey) throws Exception { + public Element getElement(final String key, final String subkey) throws Exception + { // TODO Auto-generated method stub return null; } @Override - public Elements getElements(final String key) throws Exception { + public Elements getElements(final String key) throws Exception + { // TODO Auto-generated method stub return null; } @Override - public Elements getElements(final String key, final String subkey) throws Exception { + public Elements getElements(final String key, final String subkey) throws Exception + { // TODO Auto-generated method stub return null; } @Override - public StringList getKeys() throws Exception { + public StringList getKeys() throws Exception + { // TODO Auto-generated method stub return null; } @Override - public StringList getSubkeys(final String key) throws Exception { + public StringList getSubkeys(final String key) throws Exception + { // TODO Auto-generated method stub return null; } @Override - public String getValue(final String key) throws Exception { + public String getValue(final String key) throws Exception + { // TODO Auto-generated method stub return null; } @Override - public String getValue(final String key, final String subkey) { + public String getValue(final String key, final String subkey) + { // TODO Auto-generated method stub return null; } @Override - public StringList getValues(final String key) { + public StringList getValues(final String key) + { // TODO Auto-generated method stub return null; } @Override - public long memorySize() { + public long memorySize() + { // TODO Auto-generated method stub return 0; } @Override - public long memorySize(final String key) { + public long memorySize(final String key) + { // TODO Auto-generated method stub return 0; } @Override - public long memorySize(final String key, final String subkey) { + public long memorySize(final String key, final String subkey) + { // TODO Auto-generated method stub return 0; } @Override - public long memorySizeOfAll() throws Exception { + public long memorySizeOfAll() throws Exception + { // TODO Auto-generated method stub return 0; } @Override - public long memorySizeOfAll(final String key) throws Exception { + public long memorySizeOfAll(final String key) throws Exception + { // TODO Auto-generated method stub return 0; } @Override - public long memorySizeOfArchive() throws Exception { + public long memorySizeOfArchive() throws Exception + { // TODO Auto-generated method stub return 0; } @Override - public long memorySizeOfArchive(final String key) throws Exception { + public long memorySizeOfArchive(final String key) throws Exception + { // TODO Auto-generated method stub return 0; } @Override - public long memorySizeOfArchive(final String key, final String subkey) throws Exception { + public long memorySizeOfArchive(final String key, final String subkey) throws Exception + { // TODO Auto-generated method stub return 0; } @Override - public void open() { + public void open() + { // TODO Auto-generated method stub } @Override - public void put(final Element element) throws Exception { + public void put(final Element element) throws Exception + { // TODO Auto-generated method stub } @Override - public void put(final String key, final String value) { + public void put(final String key, final String value) + { // TODO Auto-generated method stub } @Override - public void put(final String key, final String subkey, final String value) { + public void put(final String key, final String subkey, final String value) + { // TODO Auto-generated method stub } @Override - public void remove(final String key) throws Exception { + public void remove(final String key) throws Exception + { // TODO Auto-generated method stub } @Override - public void remove(final String key, final String subkey) throws Exception { + public void remove(final String key, final String subkey) throws Exception + { // TODO Auto-generated method stub } @Override - public void removeAll(final String key) throws Exception { + public void removeAll(final String key) throws Exception + { // TODO Auto-generated method stub } @Override - public void removeMany(final String key, final String... subkeys) throws Exception { + public void removeMany(final String key, final String... subkeys) throws Exception + { // TODO Auto-generated method stub } @Override - public void renameKey(final String oldKey, final String newKey) throws Exception { + public void renameKey(final String oldKey, final String newKey) throws Exception + { // TODO Auto-generated method stub } @Override - public void replaceInValue(final String key, final String... tokens) throws Exception { + public void replaceInValue(final String key, final String... tokens) throws Exception + { // TODO Auto-generated method stub } @Override - public void replaceInValues(final String key, final String... tokens) throws Exception { + public void replaceInValues(final String key, final String... tokens) throws Exception + { // TODO Auto-generated method stub } diff --git a/src/fr/devinsy/sikevadb/SQLSikevaDB.java b/src/fr/devinsy/sikevadb/SQLSikevaDB.java index 12173c7..2f1e3ce 100644 --- a/src/fr/devinsy/sikevadb/SQLSikevaDB.java +++ b/src/fr/devinsy/sikevadb/SQLSikevaDB.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013, 2014 Christian Pierre MOMON, DEVINSY + * Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * * This file is part of SikevaDB, simple key value database. * @@ -43,9 +43,10 @@ import fr.devinsy.util.StringList; /** * * - * @author Christian P. Momon + * @author Christian Pierre MOMON */ -public class SQLSikevaDB implements SikevaDB { +public class SQLSikevaDB implements SikevaDB +{ private static final Logger logger = LoggerFactory.getLogger(SQLSikevaDB.class); private String driverClassname; private String url; @@ -59,7 +60,8 @@ public class SQLSikevaDB implements SikevaDB { * * @param contextName */ - public SQLSikevaDB(final String contextName) { + public SQLSikevaDB(final String contextName) + { this.contextName = contextName; } @@ -70,17 +72,27 @@ public class SQLSikevaDB implements SikevaDB { * @param login * @param password */ - public SQLSikevaDB(final String driverClassName, final String url, final String login, final String password) { + public SQLSikevaDB(final String driverClassName, final String url, final String login, final String password) + { - if (StringUtils.isBlank(driverClassName)) { + if (StringUtils.isBlank(driverClassName)) + { throw new NullPointerException("driverClassName is null."); - } else if (StringUtils.isBlank(url)) { + } + else if (StringUtils.isBlank(url)) + { throw new NullPointerException("url is null."); - } else if (StringUtils.isBlank(login)) { + } + else if (StringUtils.isBlank(login)) + { throw new NullPointerException("login is null."); - } else if (password == null) { + } + else if (password == null) + { throw new NullPointerException("password is null"); - } else { + } + else + { this.driverClassname = driverClassName; this.url = url; this.login = login; @@ -93,13 +105,17 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void archive(final String key) throws SQLException { + public void archive(final String key) throws SQLException + { // Element element = getElement(key); - if (element == null) { + if (element == null) + { throw new NullPointerException("Undefined element [key=" + key + "]"); - } else { + } + else + { // element.archive(); @@ -107,19 +123,21 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); - statement = connection - .prepareStatement("UPDATE sikevadb_elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY IS NULL AND ARCHIVE_DATE IS NULL"); + statement = connection.prepareStatement("UPDATE sikevadb_elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY IS NULL AND ARCHIVE_DATE IS NULL"); statement.setTimestamp(1, toTimestamp(element.getArchiveDate())); statement.setString(2, element.getKey()); statement.executeUpdate(); - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -129,17 +147,24 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void archive(final String key, final String subkey) throws SQLException { + public void archive(final String key, final String subkey) throws SQLException + { // - if (subkey == null) { + if (subkey == null) + { archive(key); - } else { + } + else + { // Element element = getElement(key, subkey); - if (element == null) { + if (element == null) + { throw new NullPointerException("Undefined element [key=" + key + "][subkey=" + subkey + "]"); - } else { + } + else + { // element.archive(); @@ -147,7 +172,8 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -159,7 +185,9 @@ public class SQLSikevaDB implements SikevaDB { statement.executeUpdate(); - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -170,12 +198,14 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void clearAllArchive() throws SQLException { + public void clearAllArchive() throws SQLException + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -183,7 +213,9 @@ public class SQLSikevaDB implements SikevaDB { statement.executeUpdate(); - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -192,16 +224,21 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void clearArchive(final DateTime beforeDate) throws SQLException { + public void clearArchive(final DateTime beforeDate) throws SQLException + { // - if (beforeDate == null) { + if (beforeDate == null) + { throw new NullPointerException("beforeDate is null."); - } else { + } + else + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -211,7 +248,9 @@ public class SQLSikevaDB implements SikevaDB { statement.executeUpdate(); - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -221,14 +260,18 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void clearArchive(final int maxDays) throws SQLException { + public void clearArchive(final int maxDays) throws SQLException + { // logger.debug("maxDays={}", maxDays); // - if (maxDays < 0) { + if (maxDays < 0) + { throw new IndexOutOfBoundsException("maxDays is negative."); - } else { + } + else + { DateTime beforeDate = DateTime.now().minusDays(maxDays); clearArchive(beforeDate); } @@ -238,20 +281,23 @@ public class SQLSikevaDB implements SikevaDB { * */ @Override - public void clearDatabase() throws Exception { + public void clearDatabase() throws SQLException + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("DELETE FROM sikevadb_elements"); statement.executeUpdate(); - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -260,14 +306,21 @@ public class SQLSikevaDB implements SikevaDB { * */ @Override - public void close() { + public void close() + { // - if (this.singleConnection != null) { - try { + if (this.singleConnection != null) + { + try + { this.singleConnection.close(); - } catch (SQLException exception) { + } + catch (SQLException exception) + { exception.printStackTrace(); - } finally { + } + finally + { this.singleConnection = null; } } @@ -280,31 +333,43 @@ public class SQLSikevaDB implements SikevaDB { * * @param connection */ - public void close(final Connection connection, final Statement statement, final ResultSet resultSet) { - + public void close(final Connection connection, final Statement statement, final ResultSet resultSet) + { // - if ((connection != null) && (connection != this.singleConnection)) { - try { + if ((connection != null) && (connection != this.singleConnection)) + { + try + { connection.close(); - } catch (SQLException exception) { + } + catch (SQLException exception) + { exception.printStackTrace(); } } // - if (statement != null) { - try { + if (statement != null) + { + try + { statement.close(); - } catch (SQLException exception) { + } + catch (SQLException exception) + { exception.printStackTrace(); } } // - if (resultSet != null) { - try { + if (resultSet != null) + { + try + { resultSet.close(); - } catch (SQLException exception) { + } + catch (SQLException exception) + { exception.printStackTrace(); } } @@ -314,21 +379,24 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long countOfAllElements() throws SQLException { + public long countOfAllElements() throws SQLException + { long result; Connection connection = null; Statement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); statement = connection.createStatement(); resultSet = statement.executeQuery("SELECT count(*) FROM sikevadb_elements"); resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -340,13 +408,15 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long countOfAllElements(final String key) throws SQLException { + public long countOfAllElements(final String key) throws SQLException + { long result; Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT count(*) FROM sikevadb_elements WHERE TOPKEY=?"); @@ -355,8 +425,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -368,17 +439,22 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long countOfAllElements(final String key, final String subkey) throws SQLException { + public long countOfAllElements(final String key, final String subkey) throws SQLException + { long result; // - if (subkey == null) { + if (subkey == null) + { result = countOfAllElements(key); - } else { + } + else + { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT count(*) FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=?"); @@ -388,8 +464,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -402,13 +479,15 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long countOfArchivedElements() throws SQLException { + public long countOfArchivedElements() throws SQLException + { long result; Connection connection = null; Statement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.createStatement(); @@ -416,8 +495,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -429,13 +509,15 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long countOfArchivedElements(final String key) throws SQLException { + public long countOfArchivedElements(final String key) throws SQLException + { long result; Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT count(*) FROM sikevadb_elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=?"); @@ -444,8 +526,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -457,17 +540,22 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long countOfArchivedElements(final String key, final String subkey) throws SQLException { + public long countOfArchivedElements(final String key, final String subkey) throws SQLException + { long result; // - if (subkey == null) { + if (subkey == null) + { result = countOfArchivedElements(key); - } else { + } + else + { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT count(*) FROM sikevadb_elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=?"); @@ -478,7 +566,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -493,13 +583,15 @@ public class SQLSikevaDB implements SikevaDB { * @throws SQLException */ @Override - public long countOfElements() throws SQLException { + public long countOfElements() throws SQLException + { long result; Connection connection = null; Statement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.createStatement(); @@ -508,7 +600,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -522,13 +616,15 @@ public class SQLSikevaDB implements SikevaDB { * @throws SQLException */ @Override - public long countOfElements(final String key) throws SQLException { + public long countOfElements(final String key) throws SQLException + { long result; Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT count(*) FROM sikevadb_elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=?"); @@ -537,8 +633,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -550,17 +647,22 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long countOfElements(final String key, final String subkey) throws SQLException { + public long countOfElements(final String key, final String subkey) throws SQLException + { long result; // - if (subkey == null) { + if (subkey == null) + { result = countOfElements(key); - } else { + } + else + { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT count(*) FROM sikevadb_elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=?"); @@ -570,8 +672,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -586,11 +689,13 @@ public class SQLSikevaDB implements SikevaDB { * @throws IOException * @throws SQLException */ - public void createSchema() throws IOException, SQLException { + public void createSchema() throws IOException, SQLException + { // Connection connection = null; Statement statement = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -606,11 +711,15 @@ public class SQLSikevaDB implements SikevaDB { logger.debug("[datatbaseProductName={}]", databaseProductName); sqlCommands = SQLSikevaDBTools.loadSQLScript(SQLSikevaDB.class.getResource("/fr/devinsy/sikevadb/createTable-" + databaseProductName + ".sql")); - if (sqlCommands == null) { + if (sqlCommands == null) + { throw new FileNotFoundException("SQL script creation not found for [" + databaseProductName + "]."); - } else { + } + else + { // - for (String sql : sqlCommands) { + for (String sql : sqlCommands) + { System.out.println("sql=[" + sql + "]"); statement = connection.createStatement(); @@ -624,7 +733,9 @@ public class SQLSikevaDB implements SikevaDB { System.out.println("============================== APRÈS2"); } - } finally { + } + finally + { close(connection, statement, null); } } @@ -635,14 +746,20 @@ public class SQLSikevaDB implements SikevaDB { * @return * @throws SQLException */ - public boolean exists(final Element element) throws SQLException { + public boolean exists(final Element element) throws SQLException + { boolean result; - if (element == null) { + if (element == null) + { result = false; - } else if (getElement(element.getId()) == null) { + } + else if (getElement(element.getId()) == null) + { result = false; - } else { + } + else + { result = true; } @@ -654,7 +771,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public Elements getAllElements() throws SQLException { + public Elements getAllElements() throws SQLException + { Elements result; // @@ -664,14 +782,15 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); - statement = connection - .prepareStatement("SELECT ID,TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM sikevadb_elements ORDER BY ARCHIVE_DATE ASC"); + statement = connection.prepareStatement("SELECT ID,TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM sikevadb_elements ORDER BY ARCHIVE_DATE ASC"); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // Element element = new Element(); @@ -688,8 +807,9 @@ public class SQLSikevaDB implements SikevaDB { // result.add(element); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -701,7 +821,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public Elements getAllElements(final String key) throws SQLException { + public Elements getAllElements(final String key) throws SQLException + { Elements result; // @@ -711,7 +832,8 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection @@ -719,7 +841,8 @@ public class SQLSikevaDB implements SikevaDB { statement.setString(1, key); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // Element element = new Element(); @@ -736,8 +859,9 @@ public class SQLSikevaDB implements SikevaDB { // result.add(element); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -749,13 +873,17 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public Elements getAllElements(final String key, final String subkey) throws SQLException { + public Elements getAllElements(final String key, final String subkey) throws SQLException + { Elements result; // - if (subkey == null) { + if (subkey == null) + { result = getAllElements(key); - } else { + } + else + { // result = new Elements((int) countOfAllElements(key, subkey)); @@ -763,7 +891,8 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection @@ -772,7 +901,8 @@ public class SQLSikevaDB implements SikevaDB { statement.setString(2, subkey); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // Element element = new Element(); @@ -789,8 +919,9 @@ public class SQLSikevaDB implements SikevaDB { // result.add(element); } - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -803,7 +934,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public StringList getAllKeys() throws SQLException { + public StringList getAllKeys() throws SQLException + { StringList result; // @@ -813,18 +945,21 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT DISTINCT TOPKEY FROM sikevadb_elements ORDER BY CREATION_DATE ASC"); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // result.add(resultSet.getString(1)); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -836,7 +971,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public StringList getAllSubkeys(final String key) throws SQLException { + public StringList getAllSubkeys(final String key) throws SQLException + { StringList result; // @@ -846,19 +982,22 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT DISTINCT SUBKEY FROM sikevadb_elements WHERE TOPKEY=? ORDER BY CREATION_DATE ASC"); statement.setString(1, key); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // result.add(resultSet.getString(1)); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -870,7 +1009,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public StringList getAllValues(final String key) throws SQLException { + public StringList getAllValues(final String key) throws SQLException + { StringList result; // @@ -880,19 +1020,22 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT VALUE FROM sikevadb_elements WHERE TOPKEY=? ORDER BY ARCHIVE_DATE ASC"); statement.setString(1, key); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // result.add(resultSet.getString(1)); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -904,13 +1047,17 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public StringList getAllValues(final String key, final String subkey) throws SQLException { + public StringList getAllValues(final String key, final String subkey) throws SQLException + { StringList result; // - if (subkey == null) { + if (subkey == null) + { result = getAllValues(key); - } else { + } + else + { // result = new StringList((int) countOfAllElements(key, subkey)); @@ -918,7 +1065,8 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT VALUE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC"); @@ -926,12 +1074,14 @@ public class SQLSikevaDB implements SikevaDB { statement.setString(2, subkey); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // result.add(resultSet.getString(1)); } - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -944,7 +1094,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public StringList getArchivedValues(final String key) throws SQLException { + public StringList getArchivedValues(final String key) throws SQLException + { StringList result; // @@ -954,19 +1105,22 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT VALUE FROM sikevadb_elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? ORDER BY CREATION_DATE"); statement.setString(1, key); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // result.add(resultSet.getString(1)); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -978,13 +1132,17 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public StringList getArchivedValues(final String key, final String subkey) throws SQLException { + public StringList getArchivedValues(final String key, final String subkey) throws SQLException + { StringList result; // - if (subkey == null) { + if (subkey == null) + { result = getArchivedValues(key); - } else { + } + else + { // result = new StringList((int) countOfArchivedElements(key, subkey)); @@ -992,21 +1150,23 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); - statement = connection - .prepareStatement("SELECT VALUE FROM sikevadb_elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC"); + statement = connection.prepareStatement("SELECT VALUE FROM sikevadb_elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=? ORDER BY ARCHIVE_DATE ASC"); statement.setString(1, key); statement.setString(2, subkey); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // result.add(resultSet.getString(1)); } - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -1020,14 +1180,20 @@ public class SQLSikevaDB implements SikevaDB { * @return * @throws SQLException */ - public Connection getConnection() throws SQLException { + public Connection getConnection() throws SQLException + { Connection result; - if (this.singleConnection != null) { + if (this.singleConnection != null) + { result = this.singleConnection; - } else if (this.dataSource != null) { + } + else if (this.dataSource != null) + { result = this.dataSource.getConnection(); - } else { + } + else + { throw new NullPointerException("Connection is not initialized."); } @@ -1035,7 +1201,8 @@ public class SQLSikevaDB implements SikevaDB { return result; } - public String getContextName() { + public String getContextName() + { return this.contextName; } @@ -1043,34 +1210,40 @@ public class SQLSikevaDB implements SikevaDB { * * @return */ - public String getDriverClassname() { + public String getDriverClassname() + { return this.driverClassname; } /** * */ - public Element getElement(final long id) throws SQLException { + public Element getElement(final long id) throws SQLException + { Element result; - if (id == Element.NO_ID) { + if (id == Element.NO_ID) + { result = null; - } else { + } + else + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); - statement = connection - .prepareStatement("SELECT ID,TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM sikevadb_elements WHERE ID=?"); + statement = connection.prepareStatement("SELECT ID,TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE FROM sikevadb_elements WHERE ID=?"); statement.setLong(1, id); resultSet = statement.executeQuery(); // - if (resultSet.next()) { + if (resultSet.next()) + { // result = new Element(); @@ -1084,16 +1257,20 @@ public class SQLSikevaDB implements SikevaDB { result.setEditionDate(toDateTime(resultSet.getTimestamp(8))); result.setArchiveDate(toDateTime(resultSet.getTimestamp(9))); - } else { + } + else + { result = null; } // - if (resultSet.next()) { + if (resultSet.next()) + { throw new SQLException("More than only once result [id=" + id + "]."); } - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -1106,14 +1283,16 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public Element getElement(final String key) throws SQLException { + public Element getElement(final String key) throws SQLException + { Element result; // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -1123,7 +1302,8 @@ public class SQLSikevaDB implements SikevaDB { resultSet = statement.executeQuery(); // - if (resultSet.next()) { + if (resultSet.next()) + { // result = new Element(); @@ -1137,16 +1317,20 @@ public class SQLSikevaDB implements SikevaDB { result.setEditionDate(toDateTime(resultSet.getTimestamp(8))); result.setArchiveDate(toDateTime(resultSet.getTimestamp(9))); - } else { + } + else + { result = null; } // - if (resultSet.next()) { + if (resultSet.next()) + { throw new SQLException("More than only once result [key=" + key + "]."); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -1158,18 +1342,23 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public Element getElement(final String key, final String subkey) throws SQLException { + public Element getElement(final String key, final String subkey) throws SQLException + { Element result; // - if (subkey == null) { + if (subkey == null) + { result = getElement(key); - } else { + } + else + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -1180,7 +1369,8 @@ public class SQLSikevaDB implements SikevaDB { resultSet = statement.executeQuery(); // - if (resultSet.next()) { + if (resultSet.next()) + { // result = new Element(); @@ -1193,16 +1383,20 @@ public class SQLSikevaDB implements SikevaDB { result.setCreationDate(toDateTime(resultSet.getTimestamp(7))); result.setEditionDate(toDateTime(resultSet.getTimestamp(8))); result.setArchiveDate(toDateTime(resultSet.getTimestamp(9))); - } else { + } + else + { result = null; } // - if (resultSet.next()) { + if (resultSet.next()) + { throw new SQLException("More than only once result."); } - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -1215,7 +1409,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public Elements getElements(final String key) throws SQLException { + public Elements getElements(final String key) throws SQLException + { Elements result; // @@ -1225,7 +1420,8 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection @@ -1233,7 +1429,8 @@ public class SQLSikevaDB implements SikevaDB { statement.setString(1, key); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // Element element = new Element(); @@ -1250,8 +1447,9 @@ public class SQLSikevaDB implements SikevaDB { // result.add(element); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -1263,13 +1461,17 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public Elements getElements(final String key, final String subkey) throws SQLException { + public Elements getElements(final String key, final String subkey) throws SQLException + { Elements result; // - if (subkey == null) { + if (subkey == null) + { result = getElements(key); - } else { + } + else + { // result = new Elements((int) countOfElements(key, subkey)); @@ -1277,7 +1479,8 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection @@ -1286,7 +1489,8 @@ public class SQLSikevaDB implements SikevaDB { statement.setString(2, subkey); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // Element element = new Element(); @@ -1303,8 +1507,9 @@ public class SQLSikevaDB implements SikevaDB { // result.add(element); } - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -1317,7 +1522,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public StringList getKeys() throws SQLException { + public StringList getKeys() throws SQLException + { StringList result; // @@ -1327,18 +1533,21 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT DISTINCT TOPKEY FROM sikevadb_elements WHERE ARCHIVE_DATE IS NULL"); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // result.add(resultSet.getString(1)); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -1346,11 +1555,13 @@ public class SQLSikevaDB implements SikevaDB { return result; } - public String getLogin() { + public String getLogin() + { return this.login; } - public String getPassword() { + public String getPassword() + { return this.password; } @@ -1358,7 +1569,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public StringList getSubkeys(final String key) throws SQLException { + public StringList getSubkeys(final String key) throws SQLException + { StringList result; // @@ -1368,7 +1580,8 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection @@ -1376,12 +1589,14 @@ public class SQLSikevaDB implements SikevaDB { statement.setString(1, key); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // result.add(resultSet.getString(1)); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -1389,7 +1604,8 @@ public class SQLSikevaDB implements SikevaDB { return result; } - public String getUrl() { + public String getUrl() + { return this.url; } @@ -1397,14 +1613,16 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public String getValue(final String key) throws SQLException { + public String getValue(final String key) throws SQLException + { String result; // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -1413,19 +1631,24 @@ public class SQLSikevaDB implements SikevaDB { resultSet = statement.executeQuery(); // - if (resultSet.next()) { + if (resultSet.next()) + { // result = resultSet.getString(1); - } else { + } + else + { result = null; } // - if (resultSet.next()) { + if (resultSet.next()) + { throw new SQLException("More than only once result."); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -1437,17 +1660,22 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public String getValue(final String key, final String subkey) throws SQLException { + public String getValue(final String key, final String subkey) throws SQLException + { String result; - if (subkey == null) { + if (subkey == null) + { result = getValue(key); - } else { + } + else + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -1457,19 +1685,24 @@ public class SQLSikevaDB implements SikevaDB { resultSet = statement.executeQuery(); // - if (resultSet.next()) { + if (resultSet.next()) + { // result = resultSet.getString(1); - } else { + } + else + { result = null; } // - if (resultSet.next()) { + if (resultSet.next()) + { throw new SQLException("More than only once result."); } - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -1482,7 +1715,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public StringList getValues(final String key) throws SQLException { + public StringList getValues(final String key) throws SQLException + { StringList result; // @@ -1492,20 +1726,22 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); - statement = connection - .prepareStatement("SELECT VALUE,CREATION_DATE FROM sikevadb_elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY IS NOT NULL ORDER BY CREATION_DATE ASC"); + statement = connection.prepareStatement("SELECT VALUE,CREATION_DATE FROM sikevadb_elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY IS NOT NULL ORDER BY CREATION_DATE ASC"); statement.setString(1, key); resultSet = statement.executeQuery(); - while (resultSet.next()) { + while (resultSet.next()) + { // result.add(resultSet.getString(1)); } - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -1517,14 +1753,16 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long memorySize() throws SQLException { + public long memorySize() throws SQLException + { long result; // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT SUM(SIZE) FROM sikevadb_elements"); @@ -1532,8 +1770,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -1545,14 +1784,16 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long memorySize(final String key) throws SQLException { + public long memorySize(final String key) throws SQLException + { long result; // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT SUM(SIZE) FROM sikevadb_elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=?"); @@ -1561,8 +1802,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -1574,18 +1816,23 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long memorySize(final String key, final String subkey) throws SQLException { + public long memorySize(final String key, final String subkey) throws SQLException + { long result; // - if (subkey == null) { + if (subkey == null) + { result = memorySize(key); - } else { + } + else + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT SUM(SIZE) FROM sikevadb_elements WHERE ARCHIVE_DATE IS NULL AND TOPKEY=? AND SUBKEY=?"); @@ -1595,8 +1842,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -1609,7 +1857,8 @@ public class SQLSikevaDB implements SikevaDB { * */ @Override - public long memorySizeOfAll() throws Exception { + public long memorySizeOfAll() throws SQLException + { long result; result = memorySize() + memorySizeOfArchive(); @@ -1622,7 +1871,8 @@ public class SQLSikevaDB implements SikevaDB { * */ @Override - public long memorySizeOfAll(final String key) throws Exception { + public long memorySizeOfAll(final String key) throws SQLException + { long result; result = memorySize(key) + memorySizeOfArchive(key); @@ -1635,14 +1885,16 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long memorySizeOfArchive() throws SQLException { + public long memorySizeOfArchive() throws SQLException + { long result; // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT SUM(SIZE) FROM sikevadb_elements WHERE ARCHIVE_DATE IS NOT NULL"); @@ -1650,8 +1902,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -1663,14 +1916,16 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long memorySizeOfArchive(final String key) throws SQLException { + public long memorySizeOfArchive(final String key) throws SQLException + { long result; // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT SUM(SIZE) FROM sikevadb_elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=?"); @@ -1679,8 +1934,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -1692,18 +1948,23 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public long memorySizeOfArchive(final String key, final String subkey) throws Exception { + public long memorySizeOfArchive(final String key, final String subkey) throws SQLException + { long result; // - if (subkey == null) { + if (subkey == null) + { result = memorySize(key); - } else { + } + else + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection.prepareStatement("SELECT SUM(SIZE) FROM sikevadb_elements WHERE ARCHIVE_DATE IS NOT NULL AND TOPKEY=? AND SUBKEY=?"); @@ -1713,8 +1974,9 @@ public class SQLSikevaDB implements SikevaDB { resultSet.next(); result = resultSet.getLong(1); - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -1727,26 +1989,31 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void open() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NamingException { + public void open() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NamingException + { // close(); // - if (this.url != null) { + if (this.url != null) + { // Class.forName(this.driverClassname).newInstance(); this.singleConnection = DriverManager.getConnection(this.url, this.login, this.password); logger.info("Single connection opened with [{}].", this.url); - } else if (this.contextName != null) { + } + else if (this.contextName != null) + { // Context initialContext = new InitialContext(); Context environmentContext = (Context) initialContext.lookup("java:comp/env"); this.dataSource = (DataSource) environmentContext.lookup(this.contextName); logger.info("Database {} opened.", this.contextName); - - } else { + } + else + { throw new IllegalArgumentException("Undefined source."); } } @@ -1755,27 +2022,31 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void put(final Element element) throws SQLException { + public void put(final Element element) throws SQLException + { // - if (element == null) { - // + if (element == null) + { throw new IllegalArgumentException("element is null."); - } else { + } + else + { // - if (exists(element)) { + if (exists(element)) + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); // Archive existing element. - statement = connection - .prepareStatement("UPDATE sikevadb_elements SET TOPKEY=?,SUBKEY=?,VALUE=?,SIZE=?,DIGEST=?,CREATION_DATE=?,EDITION_DATE=?,ARCHIVE_DATE=? WHERE ID=?"); + statement = connection.prepareStatement("UPDATE sikevadb_elements SET TOPKEY=?,SUBKEY=?,VALUE=?,SIZE=?,DIGEST=?,CREATION_DATE=?,EDITION_DATE=?,ARCHIVE_DATE=? WHERE ID=?"); statement.setString(1, element.getKey()); statement.setString(2, element.getSubkey()); @@ -1788,20 +2059,23 @@ public class SQLSikevaDB implements SikevaDB { statement.setLong(9, element.getId()); statement.executeUpdate(); - - } finally { + } + finally + { close(connection, statement, resultSet); } - } else if (element.getId() == Element.NO_ID) { + } + else if (element.getId() == Element.NO_ID) + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); - statement = connection - .prepareStatement("INSERT INTO sikevadb_elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); + statement = connection.prepareStatement("INSERT INTO sikevadb_elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); statement.setString(1, element.getKey()); statement.setString(2, element.getSubkey()); @@ -1813,16 +2087,20 @@ public class SQLSikevaDB implements SikevaDB { statement.setTimestamp(8, toTimestamp(element.getArchiveDate())); statement.executeUpdate(); - - } finally { + } + finally + { close(connection, statement, resultSet); } - } else { + } + else + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { connection = getConnection(); connection.setAutoCommit(true); statement = connection @@ -1839,8 +2117,9 @@ public class SQLSikevaDB implements SikevaDB { statement.setTimestamp(9, toTimestamp(element.getArchiveDate())); statement.executeUpdate(); - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -1851,20 +2130,23 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void put(final String key, final String value) throws SQLException { + public void put(final String key, final String value) throws SQLException + { // Element element = getElement(key); // - if (element == null) { + if (element == null) + { // element = new Element(); element.setKey(key); element.update(value); element.setArchiveDate(null); - - } else { + } + else + { // element.update(value); } @@ -1873,15 +2155,16 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(false); // Archive existing element. - if (element.getId() != Element.NO_ID) { - statement = connection - .prepareStatement("UPDATE sikevadb_elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY IS NULL AND ARCHIVE_DATE IS NULL"); + if (element.getId() != Element.NO_ID) + { + statement = connection.prepareStatement("UPDATE sikevadb_elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY IS NULL AND ARCHIVE_DATE IS NULL"); statement.setTimestamp(1, toTimestamp(element.getEditionDate())); statement.setString(2, element.getKey()); @@ -1892,8 +2175,7 @@ public class SQLSikevaDB implements SikevaDB { } // Insert new version of the element. - statement = connection - .prepareStatement("INSERT INTO sikevadb_elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); + statement = connection.prepareStatement("INSERT INTO sikevadb_elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); statement.setString(1, element.getKey()); statement.setString(2, element.getSubkey()); @@ -1907,10 +2189,13 @@ public class SQLSikevaDB implements SikevaDB { statement.executeUpdate(); connection.commit(); - - } catch (Exception exception) { + } + catch (Exception exception) + { connection.rollback(); - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -1919,22 +2204,23 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void put(final String key, final String subkey, final String value) throws SQLException { + public void put(final String key, final String subkey, final String value) throws SQLException + { // Element element = getElement(key, subkey); // - if (element == null) { - // + if (element == null) + { element = new Element(); element.setKey(key); element.setSubkey(subkey); element.update(value); element.setArchiveDate(null); - - } else { - // + } + else + { element.update(value); } @@ -1942,13 +2228,15 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(false); // Archive existing element. - if (element.getId() != Element.NO_ID) { + if (element.getId() != Element.NO_ID) + { statement = connection.prepareStatement("UPDATE sikevadb_elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY=? AND ARCHIVE_DATE IS NULL"); statement.setTimestamp(1, toTimestamp(element.getEditionDate())); @@ -1961,8 +2249,7 @@ public class SQLSikevaDB implements SikevaDB { } // Insert new version of the element. - statement = connection - .prepareStatement("INSERT INTO sikevadb_elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); + statement = connection.prepareStatement("INSERT INTO sikevadb_elements (TOPKEY,SUBKEY,VALUE,SIZE,DIGEST,CREATION_DATE,EDITION_DATE,ARCHIVE_DATE) VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); statement.setString(1, element.getKey()); statement.setString(2, element.getSubkey()); @@ -1976,10 +2263,13 @@ public class SQLSikevaDB implements SikevaDB { statement.executeUpdate(); connection.commit(); - - } catch (Exception exception) { + } + catch (Exception exception) + { connection.rollback(); - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -1988,12 +2278,14 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void remove(final String key) throws SQLException { + public void remove(final String key) throws SQLException + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -2003,11 +2295,13 @@ public class SQLSikevaDB implements SikevaDB { int rowCount = statement.executeUpdate(); - if (rowCount == 0) { + if (rowCount == 0) + { logger.warn("Remove action without existing target [key=" + key + "]"); } - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -2016,12 +2310,14 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void remove(final String key, final String subkey) throws SQLException { + public void remove(final String key, final String subkey) throws SQLException + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY=? AND ARCHIVE_DATE IS NULL"); @@ -2031,11 +2327,13 @@ public class SQLSikevaDB implements SikevaDB { int rowCount = statement.executeUpdate(); - if (rowCount == 0) { + if (rowCount == 0) + { logger.warn("Remove action without existing target [key=" + key + "][subkey=" + subkey + "]"); } - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -2044,13 +2342,17 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void removeAll(final String key) throws SQLException { + public void removeAll(final String key) throws SQLException + { // Element element = getElement(key); - if (element == null) { + if (element == null) + { throw new NullPointerException("Undefined element [key=" + key + "]"); - } else { + } + else + { // element.archive(); @@ -2058,7 +2360,8 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -2067,8 +2370,9 @@ public class SQLSikevaDB implements SikevaDB { statement.setString(1, element.getKey()); statement.executeUpdate(); - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -2078,36 +2382,41 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void removeMany(final String key, final String... subkeys) throws SQLException { + public void removeMany(final String key, final String... subkeys) throws SQLException + { // - if ((subkeys != null) && (subkeys.length > 0)) { + if ((subkeys != null) && (subkeys.length > 0)) + { // Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); // String questionMarks = new StringList(subkeys.length).append('?').repeatLast(subkeys.length - 1).toStringWithCommas(); - statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IN (" + questionMarks - + ") AND ARCHIVE_DATE IS NULL"); + statement = connection.prepareStatement("DELETE FROM sikevadb_elements WHERE TOPKEY=? AND SUBKEY IN (" + questionMarks + ") AND ARCHIVE_DATE IS NULL"); // statement.setString(1, key); // - for (int index = 0; index < subkeys.length; index++) { + for (int index = 0; index < subkeys.length; index++) + { statement.setString(2 + index, subkeys[index]); } // int rowCount = statement.executeUpdate(); - if (rowCount == 0) { + if (rowCount == 0) + { logger.warn("Remove action without existing target [key=" + key + "][subkeys=" + new StringList(subkeys).toStringWithCommas() + "]"); } - - } finally { + } + finally + { close(connection, statement, resultSet); } } @@ -2117,7 +2426,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void renameKey(final String oldKey, final String newKey) throws SQLException { + public void renameKey(final String oldKey, final String newKey) throws SQLException + { logger.info("renameKey starting... [{}][{}]", oldKey, newKey); @@ -2125,7 +2435,8 @@ public class SQLSikevaDB implements SikevaDB { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; - try { + try + { // connection = getConnection(); connection.setAutoCommit(true); @@ -2135,8 +2446,9 @@ public class SQLSikevaDB implements SikevaDB { statement.setString(2, oldKey); statement.executeUpdate(); - - } finally { + } + finally + { close(connection, statement, resultSet); } @@ -2147,7 +2459,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void replaceInValue(final String key, final String... tokens) throws SQLException { + public void replaceInValue(final String key, final String... tokens) throws SQLException + { logger.info("replaceInValue starting... [{}]", key); @@ -2155,7 +2468,8 @@ public class SQLSikevaDB implements SikevaDB { String value = getValue(key); // - for (int tokenIndex = 0; tokenIndex < tokens.length; tokenIndex += 2) { + for (int tokenIndex = 0; tokenIndex < tokens.length; tokenIndex += 2) + { // value = value.replaceAll(tokens[tokenIndex], tokens[tokenIndex + 1]); } @@ -2170,7 +2484,8 @@ public class SQLSikevaDB implements SikevaDB { * {@inheritDoc} */ @Override - public void replaceInValues(final String key, final String... tokens) throws SQLException { + public void replaceInValues(final String key, final String... tokens) throws SQLException + { logger.info("replaceInValues starting... [{}]", key); @@ -2178,11 +2493,13 @@ public class SQLSikevaDB implements SikevaDB { Elements elements = getElements(key); long count = 0; - for (Element element : elements) { + for (Element element : elements) + { // logger.info(element.getKey() + " (" + element.getSubkey() + ") " + count + "/" + elements.size()); - if (element.getSubkey() != null) { + if (element.getSubkey() != null) + { // count++; @@ -2190,7 +2507,8 @@ public class SQLSikevaDB implements SikevaDB { String value = element.getValue(); // - for (int tokenIndex = 0; tokenIndex < tokens.length; tokenIndex += 2) { + for (int tokenIndex = 0; tokenIndex < tokens.length; tokenIndex += 2) + { value = value.replaceAll(tokens[tokenIndex], tokens[tokenIndex + 1]); } @@ -2202,19 +2520,23 @@ public class SQLSikevaDB implements SikevaDB { logger.info("replaceInValues done."); } - public void setDriverClassname(final String driverClassname) { + public void setDriverClassname(final String driverClassname) + { this.driverClassname = driverClassname; } - public void setLogin(final String login) { + public void setLogin(final String login) + { this.login = login; } - public void setPassword(final String password) { + public void setPassword(final String password) + { this.password = password; } - public void setUrl(final String url) { + public void setUrl(final String url) + { this.url = url; } @@ -2223,12 +2545,16 @@ public class SQLSikevaDB implements SikevaDB { * @param source * @return */ - public static DateTime toDateTime(final java.sql.Timestamp source) { + public static DateTime toDateTime(final java.sql.Timestamp source) + { DateTime result; - if (source == null) { + if (source == null) + { result = null; - } else { + } + else + { result = new DateTime(source.getTime()); } @@ -2241,12 +2567,16 @@ public class SQLSikevaDB implements SikevaDB { * @param source * @return */ - public static java.sql.Timestamp toTimestamp(final Date source) { + public static java.sql.Timestamp toTimestamp(final Date source) + { java.sql.Timestamp result; - if (source == null) { + if (source == null) + { result = null; - } else { + } + else + { result = new java.sql.Timestamp(source.getTime()); } @@ -2259,17 +2589,20 @@ public class SQLSikevaDB implements SikevaDB { * @param source * @return */ - public static java.sql.Timestamp toTimestamp(final DateTime source) { + public static java.sql.Timestamp toTimestamp(final DateTime source) + { java.sql.Timestamp result; - if (source == null) { + if (source == null) + { result = null; - } else { + } + else + { result = new java.sql.Timestamp(source.getMillis()); } // return result; } - } diff --git a/src/fr/devinsy/sikevadb/SQLSikevaDBTools.java b/src/fr/devinsy/sikevadb/SQLSikevaDBTools.java index fafbf4e..22e5a78 100644 --- a/src/fr/devinsy/sikevadb/SQLSikevaDBTools.java +++ b/src/fr/devinsy/sikevadb/SQLSikevaDBTools.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013, 2014 Christian Pierre MOMON, DEVINSY + * Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * * This file is part of SikevaDB, simple key value database. * @@ -33,9 +33,10 @@ import fr.devinsy.util.StringList; /** * * - * @author Christian P. Momon + * @author Christian Pierre MOMON */ -public class SQLSikevaDBTools { +public class SQLSikevaDBTools +{ private static final Logger logger = LoggerFactory.getLogger(SQLSikevaDBTools.class); /** @@ -43,7 +44,8 @@ public class SQLSikevaDBTools { * @param source * @throws IOException */ - public static StringList loadSQLScript(final URL source) throws IOException { + public static StringList loadSQLScript(final URL source) throws IOException + { StringList result; String script = FileTools.load(source); @@ -59,28 +61,36 @@ public class SQLSikevaDBTools { * @param source * @throws IOException */ - public static StringList splitSQLCommands(final String source) throws IOException { + public static StringList splitSQLCommands(final String source) throws IOException + { StringList result; // result = new StringList(); // - if (source != null) { + if (source != null) + { // BufferedReader in = new BufferedReader(new StringReader(source)); boolean ended = false; StringList sql = new StringList(); - while (!ended) { + while (!ended) + { String line = in.readLine(); - if (line == null) { + if (line == null) + { ended = true; - } else { - if ((StringUtils.isNotBlank(line)) && (!line.startsWith("--"))) { + } + else + { + if ((StringUtils.isNotBlank(line)) && (!line.startsWith("--"))) + { // - if (line.endsWith(";")) { + if (line.endsWith(";")) + { // sql.append(line.substring(0, line.length() - 1)); @@ -90,10 +100,11 @@ public class SQLSikevaDBTools { // sql.clear(); - } else { + } + else + { // sql.append(line).append(' '); - } } } diff --git a/src/fr/devinsy/sikevadb/SikevaDB.java b/src/fr/devinsy/sikevadb/SikevaDB.java index 3db21b8..57e92fb 100644 --- a/src/fr/devinsy/sikevadb/SikevaDB.java +++ b/src/fr/devinsy/sikevadb/SikevaDB.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013, 2014 Christian Pierre MOMON, DEVINSY + * Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * * This file is part of SikevaDB, simple key value database. * @@ -27,10 +27,10 @@ import fr.devinsy.util.StringList; * * * - * @author Christian P. Momon + * @author Christian Pierre MOMON */ -public interface SikevaDB { - +public interface SikevaDB +{ public void archive(final String key) throws Exception; public void archive(final String key, final String subkey) throws Exception; diff --git a/src/fr/devinsy/sikevadb/SikevaDBFactory.java b/src/fr/devinsy/sikevadb/SikevaDBFactory.java index 9bfa615..e5c4068 100644 --- a/src/fr/devinsy/sikevadb/SikevaDBFactory.java +++ b/src/fr/devinsy/sikevadb/SikevaDBFactory.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013, 2014 Christian Pierre MOMON, DEVINSY + * Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * * This file is part of SikevaDB, simple key value database. * @@ -23,15 +23,17 @@ import java.io.File; /** * * - * @author Christian P. Momon + * @author Christian Pierre MOMON */ -public class SikevaDBFactory { +public class SikevaDBFactory +{ /** * * @param path * @return */ - public static SikevaDB get(final File path) { + public static SikevaDB get(final File path) + { SikevaDB result; result = new FileSikevaDB(path); @@ -45,7 +47,8 @@ public class SikevaDBFactory { * @param path * @return */ - public static SikevaDB get(final String contextName) { + public static SikevaDB get(final String contextName) + { SikevaDB result; result = new SQLSikevaDB(contextName); @@ -62,7 +65,8 @@ public class SikevaDBFactory { * @param password * @return */ - public static SikevaDB get(final String driverClassName, final String url, final String login, final String password) { + public static SikevaDB get(final String driverClassName, final String url, final String login, final String password) + { SikevaDB result; result = new SQLSikevaDB(driverClassName, url, login, password); diff --git a/src/fr/devinsy/sikevadb/SikevaDBUtils.java b/src/fr/devinsy/sikevadb/SikevaDBUtils.java index 849ddf2..18b9e10 100644 --- a/src/fr/devinsy/sikevadb/SikevaDBUtils.java +++ b/src/fr/devinsy/sikevadb/SikevaDBUtils.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013, 2014 Christian Pierre MOMON, DEVINSY + * Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * * This file is part of SikevaDB, simple key value database. * @@ -23,10 +23,12 @@ import java.util.Date; /** * * - * @author Christian P. Momon + * @author Christian Pierre MOMON */ -public class SikevaDBUtils { - public static long now() { +public class SikevaDBUtils +{ + public static long now() + { return new Date().getTime(); } } diff --git a/src/fr/devinsy/sikevadb/XMLSikevaDB.java b/src/fr/devinsy/sikevadb/XMLSikevaDB.java index 60ad53f..23b0bc6 100644 --- a/src/fr/devinsy/sikevadb/XMLSikevaDB.java +++ b/src/fr/devinsy/sikevadb/XMLSikevaDB.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013, 2014 Christian Pierre MOMON, DEVINSY + * Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * * This file is part of SikevaDB, simple key value database. * @@ -40,7 +40,8 @@ import fr.devinsy.util.xml.XMLZipWriter; * * @author TIP */ -public class XMLSikevaDB { +public class XMLSikevaDB +{ private static final Logger logger = LoggerFactory.getLogger(XMLSikevaDB.class); /** @@ -52,7 +53,8 @@ public class XMLSikevaDB { * Source. * */ - public static void export(final OutputStream out, final SikevaDB source) throws Exception { + public static void export(final OutputStream out, final SikevaDB source) throws Exception + { // String fileName = "sikevadb-" + DateTime.now().toString("yyyy-MM-dd-HH'h'mm'mn'ss's'") + ".xml.zip"; @@ -69,18 +71,26 @@ public class XMLSikevaDB { * Source. * */ - public static void export(final OutputStream out, final SikevaDB source, final String fileName) throws Exception { - - if (out == null) { + public static void export(final OutputStream out, final SikevaDB source, final String fileName) throws Exception + { + if (out == null) + { throw new NullPointerException("out is null."); - } else if (source == null) { + } + else if (source == null) + { throw new NullPointerException("source is null."); - } else if (fileName == null) { + } + else if (fileName == null) + { export(out, source, fileName); - } else { + } + else + { // XMLZipWriter target = null; - try { + try + { // target = new XMLZipWriter(out, fileName, "Generated by SikevaDB."); @@ -89,9 +99,11 @@ public class XMLSikevaDB { // write(target, source); - - } finally { - if (target != null) { + } + finally + { + if (target != null) + { target.close(); } } @@ -103,7 +115,8 @@ public class XMLSikevaDB { * @param file * @return */ - public static void importData(final SikevaDB database, final File file) throws Exception { + public static void importData(final SikevaDB database, final File file) throws Exception + { // XMLReader in = null; // try { @@ -124,7 +137,8 @@ public class XMLSikevaDB { * @throws XMLStreamException * @throws Exception */ - public static Element readElement(final XMLReader in) throws XMLStreamException, XMLBadFormatException { + public static Element readElement(final XMLReader in) throws XMLStreamException, XMLBadFormatException + { Element result; // @@ -144,9 +158,12 @@ public class XMLSikevaDB { DateTime archiveDate; String archiveDateValue = in.readNullableContentTag("archive_date").getContent(); - if (archiveDateValue == null) { + if (archiveDateValue == null) + { archiveDate = null; - } else { + } + else + { archiveDate = DateTime.parse(archiveDateValue); } @@ -162,7 +179,6 @@ public class XMLSikevaDB { result.setCreationDate(creationDate); result.setEditionDate(editionDate); result.setArchiveDate(archiveDate); - } // @@ -178,15 +194,17 @@ public class XMLSikevaDB { * @param in * @throws Exception */ - public static void readElements(final SikevaDB target, final XMLReader in) throws Exception { + public static void readElements(final SikevaDB target, final XMLReader in) throws Exception + { // XMLTag list = in.readListTag("elements"); // - if (list.getType() != TagType.EMPTY) { - - while (in.hasNextStartTag("element")) { + if (list.getType() != TagType.EMPTY) + { + while (in.hasNextStartTag("element")) + { // Element element = readElement(in); @@ -205,13 +223,19 @@ public class XMLSikevaDB { * @param source * @return */ - public static void write(final XMLWriter out, final Element source) { + public static void write(final XMLWriter out, final Element source) + { - if (out == null) { + if (out == null) + { throw new NullPointerException("out is null."); - } else if (source == null) { + } + else if (source == null) + { throw new NullPointerException("element is null."); - } else { + } + else + { // out.writeStartTag("element"); @@ -219,9 +243,12 @@ public class XMLSikevaDB { { out.writeTag("id", String.valueOf(source.getId())); out.writeTag("key", StringEscapeUtils.escapeXml(source.getKey())); - if (source.getSubkey() == null) { + if (source.getSubkey() == null) + { out.writeTag("subkey", null); - } else { + } + else + { out.writeTag("subkey", StringEscapeUtils.escapeXml(source.getSubkey())); } out.writeTag("value", StringEscapeUtils.escapeXml(source.getValue())); @@ -229,9 +256,12 @@ public class XMLSikevaDB { out.writeTag("digest", source.getDigest()); out.writeTag("creation_date", source.getCreationDate().toString()); out.writeTag("edition_date", source.getEditionDate().toString()); - if (source.getArchiveDate() == null) { + if (source.getArchiveDate() == null) + { out.writeTag("archive_date", null); - } else { + } + else + { out.writeTag("archive_date", source.getArchiveDate().toString()); } } @@ -247,31 +277,36 @@ public class XMLSikevaDB { * @param source * @throws Exception */ - public static void write(final XMLWriter out, final SikevaDB source) throws Exception { + public static void write(final XMLWriter out, final SikevaDB source) throws Exception + { - if (out == null) { - // + if (out == null) + { throw new NullPointerException("out is null."); - - } else if (source == null) { - // + } + else if (source == null) + { out.writeEmptyTag("elements"); - - } else { - // + } + else + { out.writeStartTag("elements"); - for (String key : source.getAllKeys()) { + for (String key : source.getAllKeys()) + { // Elements elements = source.getAllElements(key); - for (Element element : elements) { + for (Element element : elements) + { write(out, element); } // - for (String subkey : source.getSubkeys(key)) { + for (String subkey : source.getSubkeys(key)) + { Elements subElements = source.getAllElements(key, subkey); - for (Element subElement : subElements) { + for (Element subElement : subElements) + { write(out, subElement); } } diff --git a/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java b/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java index 251d10a..5119cae 100644 --- a/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java +++ b/test/fr/devinsy/sikevadb/SQLSikevaDBTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2013, 2014 Christian Pierre MOMON, DEVINSY + * Copyright (C) 2013-2016 Christian Pierre MOMON, DEVINSY * * This file is part of SikevaDB, simple key value database. * @@ -38,18 +38,19 @@ import fr.devinsy.util.StringList; /** * - * @author Christian P. Momon + * @author Christian Pierre MOMON */ -public class SQLSikevaDBTest { +public class SQLSikevaDBTest +{ private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SQLSikevaDBTest.class); private static SQLSikevaDB database; /** * @throws Exception - * */ @Test - public void testClearArchive01() throws Exception { + public void testClearArchive01() throws Exception + { // logger.debug("===== test starting..."); @@ -85,7 +86,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testClearArchive02() throws Exception { + public void testClearArchive02() throws Exception + { // logger.debug("===== test starting..."); @@ -121,7 +123,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testGeKeyse01() throws Exception { + public void testGeKeyse01() throws Exception + { // logger.debug("===== test starting..."); @@ -151,7 +154,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testGeKeyse02() throws Exception { + public void testGeKeyse02() throws Exception + { // logger.debug("===== test starting..."); @@ -186,7 +190,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testMemorySize01() throws Exception { + public void testMemorySize01() throws Exception + { // logger.debug("===== test starting..."); @@ -225,7 +230,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testPut01() throws Exception { + public void testPut01() throws Exception + { // logger.debug("===== test starting..."); @@ -245,7 +251,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testPut02() throws Exception { + public void testPut02() throws Exception + { // logger.debug("===== test starting..."); @@ -269,7 +276,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testPut03() throws Exception { + public void testPut03() throws Exception + { // logger.debug("===== test starting..."); @@ -293,7 +301,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testPut04() throws Exception { + public void testPut04() throws Exception + { // logger.debug("===== test starting..."); @@ -314,7 +323,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testPut05() throws Exception { + public void testPut05() throws Exception + { // logger.debug("===== test starting..."); @@ -345,7 +355,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testPut06() throws Exception { + public void testPut06() throws Exception + { // logger.debug("===== test starting..."); @@ -376,7 +387,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testPutElement01() throws Exception { + public void testPutElement01() throws Exception + { // logger.debug("===== test starting..."); @@ -408,7 +420,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testPutElement02() throws Exception { + public void testPutElement02() throws Exception + { // logger.debug("===== test starting..."); @@ -441,7 +454,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testPutElement03() throws Exception { + public void testPutElement03() throws Exception + { // logger.debug("===== test starting..."); @@ -496,7 +510,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testRandom01() throws Exception { + public void testRandom01() throws Exception + { // logger.debug("===== test starting..."); @@ -521,7 +536,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testRemove01() throws Exception { + public void testRemove01() throws Exception + { // logger.debug("===== test starting..."); @@ -552,7 +568,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testRemoveMany01() throws Exception { + public void testRemoveMany01() throws Exception + { // logger.debug("===== test starting..."); @@ -587,7 +604,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testRenameKey01() throws Exception { + public void testRenameKey01() throws Exception + { // logger.debug("===== test starting..."); @@ -617,7 +635,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testSize01() throws Exception { + public void testSize01() throws Exception + { // logger.debug("===== test starting..."); @@ -667,7 +686,8 @@ public class SQLSikevaDBTest { * */ @Test - public void testTittle01() throws Exception { + public void testTittle01() throws Exception + { // logger.debug("===== test starting..."); @@ -686,8 +706,10 @@ public class SQLSikevaDBTest { * */ @AfterClass - public static void afterClass() { - if (database != null) { + public static void afterClass() + { + if (database != null) + { database.close(); } } @@ -702,7 +724,8 @@ public class SQLSikevaDBTest { * */ @BeforeClass - public static void beforeClass() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NamingException, IOException { + public static void beforeClass() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NamingException, IOException + { BasicConfigurator.configure(); Logger.getRootLogger().setLevel(Level.ERROR); @@ -716,5 +739,4 @@ public class SQLSikevaDBTest { database.open(); database.createSchema(); } - }