formatted sources & added formatting file from spring-data-jpa

This commit is contained in:
Matthew Adams
2013-11-14 10:00:32 -06:00
parent a400058191
commit 6ebfdd5c5e
55 changed files with 676 additions and 434 deletions

291
eclipse-formatting.xml Normal file
View File

@@ -0,0 +1,291 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="12">
<profile kind="CodeFormatterProfile" name="Spring Data" version="12">
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="tab"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="120"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.7"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
</profile>
</profiles>

View File

@@ -53,7 +53,7 @@ public abstract class AbstractCassandraConfiguration {
* @return must not be {@literal null}. * @return must not be {@literal null}.
*/ */
protected abstract String getKeyspaceName(); protected abstract String getKeyspaceName();
/** /**
* Return the {@link Cluster} instance to connect to. * Return the {@link Cluster} instance to connect to.
* *
@@ -62,10 +62,10 @@ public abstract class AbstractCassandraConfiguration {
*/ */
@Bean @Bean
public abstract Cluster cluster() throws Exception; public abstract Cluster cluster() throws Exception;
/** /**
* Creates a {@link Session} to be used by the {@link Keyspace}. Will use the {@link Cluster} instance * Creates a {@link Session} to be used by the {@link Keyspace}. Will use the {@link Cluster} instance configured in
* configured in {@link #cluster()}. * {@link #cluster()}.
* *
* @see #cluster() * @see #cluster()
* @see #Keyspace() * @see #Keyspace()
@@ -77,12 +77,11 @@ public abstract class AbstractCassandraConfiguration {
String keyspace = getKeyspaceName(); String keyspace = getKeyspaceName();
if (StringUtils.hasText(keyspace)) { if (StringUtils.hasText(keyspace)) {
return cluster().connect(keyspace); return cluster().connect(keyspace);
} } else {
else {
return cluster().connect(); return cluster().connect();
} }
} }
/** /**
* Creates a {@link Keyspace} to be used by the {@link CassandraTemplate}. Will use the {@link Session} instance * Creates a {@link Keyspace} to be used by the {@link CassandraTemplate}. Will use the {@link Session} instance
* configured in {@link #session()} and {@link CassandraConverter} configured in {@link #converter()}. * configured in {@link #session()} and {@link CassandraConverter} configured in {@link #converter()}.
@@ -96,9 +95,10 @@ public abstract class AbstractCassandraConfiguration {
public Keyspace keyspace() throws Exception { public Keyspace keyspace() throws Exception {
return new Keyspace(getKeyspaceName(), session(), converter()); return new Keyspace(getKeyspaceName(), session(), converter());
} }
/** /**
* Return the base package to scan for mapped {@link Table}s. Will return the package name of the configuration * Return the base package to scan for mapped {@link Table}s. Will return the package name of the configuration class'
* class' (the concrete class, not this one here) by default. So if you have a {@code com.acme.AppConfig} extending * (the concrete class, not this one here) by default. So if you have a {@code com.acme.AppConfig} extending
* {@link AbstractCassandraConfiguration} the base package will be considered {@code com.acme} unless the method is * {@link AbstractCassandraConfiguration} the base package will be considered {@code com.acme} unless the method is
* overriden to implement alternate behaviour. * overriden to implement alternate behaviour.
* *
@@ -108,7 +108,7 @@ public abstract class AbstractCassandraConfiguration {
protected String getMappingBasePackage() { protected String getMappingBasePackage() {
return getClass().getPackage().getName(); return getClass().getPackage().getName();
} }
/** /**
* Creates a {@link CassandraTemplate}. * Creates a {@link CassandraTemplate}.
* *
@@ -119,7 +119,7 @@ public abstract class AbstractCassandraConfiguration {
public CassandraTemplate cassandraTemplate() throws Exception { public CassandraTemplate cassandraTemplate() throws Exception {
return new CassandraTemplate(keyspace()); return new CassandraTemplate(keyspace());
} }
/** /**
* Return the {@link MappingContext} instance to map Entities to properties. * Return the {@link MappingContext} instance to map Entities to properties.
* *
@@ -130,7 +130,7 @@ public abstract class AbstractCassandraConfiguration {
public MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext() { public MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext() {
return new CassandraMappingContext(); return new CassandraMappingContext();
} }
/** /**
* Return the {@link CassandraConverter} instance to convert Rows to Objects. * Return the {@link CassandraConverter} instance to convert Rows to Objects.
* *
@@ -141,7 +141,7 @@ public abstract class AbstractCassandraConfiguration {
public CassandraConverter converter() { public CassandraConverter converter() {
return new MappingCassandraConverter(mappingContext()); return new MappingCassandraConverter(mappingContext());
} }
/** /**
* Scans the mapping base package for classes annotated with {@link Table}. * Scans the mapping base package for classes annotated with {@link Table}.
* *
@@ -168,5 +168,5 @@ public abstract class AbstractCassandraConfiguration {
return initialEntitySet; return initialEntitySet;
} }
} }

View File

@@ -35,7 +35,7 @@ import org.w3c.dom.Element;
* @author Alex Shvid * @author Alex Shvid
*/ */
public class CassandraClusterParser extends AbstractSimpleBeanDefinitionParser { public class CassandraClusterParser extends AbstractSimpleBeanDefinitionParser {
@Override @Override
protected Class<?> getBeanClass(Element element) { protected Class<?> getBeanClass(Element element) {
@@ -55,27 +55,26 @@ public class CassandraClusterParser extends AbstractSimpleBeanDefinitionParser
} }
@Override @Override
protected void doParse(Element element, ParserContext parserContext, protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
BeanDefinitionBuilder builder) {
String contactPoints = element.getAttribute("contactPoints"); String contactPoints = element.getAttribute("contactPoints");
if (StringUtils.hasText(contactPoints)) { if (StringUtils.hasText(contactPoints)) {
builder.addPropertyValue("contactPoints", contactPoints); builder.addPropertyValue("contactPoints", contactPoints);
} }
String port = element.getAttribute("port"); String port = element.getAttribute("port");
if (StringUtils.hasText(port)) { if (StringUtils.hasText(port)) {
builder.addPropertyValue("port", port); builder.addPropertyValue("port", port);
} }
String compression = element.getAttribute("compression"); String compression = element.getAttribute("compression");
if (StringUtils.hasText(compression)) { if (StringUtils.hasText(compression)) {
builder.addPropertyValue("compressionType", CompressionType.valueOf(compression)); builder.addPropertyValue("compressionType", CompressionType.valueOf(compression));
} }
postProcess(builder, element); postProcess(builder, element);
} }
@Override @Override
protected void postProcess(BeanDefinitionBuilder builder, Element element) { protected void postProcess(BeanDefinitionBuilder builder, Element element) {
List<Element> subElements = DomUtils.getChildElements(element); List<Element> subElements = DomUtils.getChildElements(element);
@@ -86,17 +85,15 @@ public class CassandraClusterParser extends AbstractSimpleBeanDefinitionParser
if ("local-pooling-options".equals(name)) { if ("local-pooling-options".equals(name)) {
builder.addPropertyValue("localPoolingOptions", parsePoolingOptions(subElement)); builder.addPropertyValue("localPoolingOptions", parsePoolingOptions(subElement));
} } else if ("remote-pooling-options".equals(name)) {
else if ("remote-pooling-options".equals(name)) {
builder.addPropertyValue("remotePoolingOptions", parsePoolingOptions(subElement)); builder.addPropertyValue("remotePoolingOptions", parsePoolingOptions(subElement));
} } else if ("socket-options".equals(name)) {
else if ("socket-options".equals(name)) {
builder.addPropertyValue("socketOptions", parseSocketOptions(subElement)); builder.addPropertyValue("socketOptions", parseSocketOptions(subElement));
} }
} }
} }
private BeanDefinition parsePoolingOptions(Element element) { private BeanDefinition parsePoolingOptions(Element element) {
BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.genericBeanDefinition(PoolingOptionsConfig.class); BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.genericBeanDefinition(PoolingOptionsConfig.class);
ParsingUtils.setPropertyValue(defBuilder, element, "min-simultaneous-requests", "minSimultaneousRequests"); ParsingUtils.setPropertyValue(defBuilder, element, "min-simultaneous-requests", "minSimultaneousRequests");
@@ -104,8 +101,8 @@ public class CassandraClusterParser extends AbstractSimpleBeanDefinitionParser
ParsingUtils.setPropertyValue(defBuilder, element, "core-connections", "coreConnections"); ParsingUtils.setPropertyValue(defBuilder, element, "core-connections", "coreConnections");
ParsingUtils.setPropertyValue(defBuilder, element, "max-connections", "maxConnections"); ParsingUtils.setPropertyValue(defBuilder, element, "max-connections", "maxConnections");
return defBuilder.getBeanDefinition(); return defBuilder.getBeanDefinition();
} }
private BeanDefinition parseSocketOptions(Element element) { private BeanDefinition parseSocketOptions(Element element) {
BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.genericBeanDefinition(SocketOptionsConfig.class); BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.genericBeanDefinition(SocketOptionsConfig.class);
ParsingUtils.setPropertyValue(defBuilder, element, "connect-timeout-mls", "connectTimeoutMls"); ParsingUtils.setPropertyValue(defBuilder, element, "connect-timeout-mls", "connectTimeoutMls");
@@ -116,6 +113,6 @@ public class CassandraClusterParser extends AbstractSimpleBeanDefinitionParser
ParsingUtils.setPropertyValue(defBuilder, element, "receive-buffer-size", "receiveBufferSize"); ParsingUtils.setPropertyValue(defBuilder, element, "receive-buffer-size", "receiveBufferSize");
ParsingUtils.setPropertyValue(defBuilder, element, "send-buffer-size", "sendBufferSize"); ParsingUtils.setPropertyValue(defBuilder, element, "send-buffer-size", "sendBufferSize");
return defBuilder.getBeanDefinition(); return defBuilder.getBeanDefinition();
} }
} }

View File

@@ -36,8 +36,7 @@ import org.w3c.dom.Element;
* @author Alex Shvid * @author Alex Shvid
*/ */
public class CassandraKeyspaceParser extends AbstractSimpleBeanDefinitionParser {
public class CassandraKeyspaceParser extends AbstractSimpleBeanDefinitionParser {
@Override @Override
protected Class<?> getBeanClass(Element element) { protected Class<?> getBeanClass(Element element) {
@@ -55,16 +54,15 @@ public class CassandraKeyspaceParser extends AbstractSimpleBeanDefinitionParser
String id = super.resolveId(element, definition, parserContext); String id = super.resolveId(element, definition, parserContext);
return StringUtils.hasText(id) ? id : BeanNames.CASSANDRA_KEYSPACE; return StringUtils.hasText(id) ? id : BeanNames.CASSANDRA_KEYSPACE;
} }
@Override @Override
protected void doParse(Element element, ParserContext parserContext, protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
BeanDefinitionBuilder builder) {
String name = element.getAttribute("name"); String name = element.getAttribute("name");
if (StringUtils.hasText(name)) { if (StringUtils.hasText(name)) {
builder.addPropertyValue("keyspace", name); builder.addPropertyValue("keyspace", name);
} }
String clusterRef = element.getAttribute("cassandra-cluster-ref"); String clusterRef = element.getAttribute("cassandra-cluster-ref");
if (!StringUtils.hasText(clusterRef)) { if (!StringUtils.hasText(clusterRef)) {
clusterRef = BeanNames.CASSANDRA_CLUSTER; clusterRef = BeanNames.CASSANDRA_CLUSTER;
@@ -78,7 +76,7 @@ public class CassandraKeyspaceParser extends AbstractSimpleBeanDefinitionParser
postProcess(builder, element); postProcess(builder, element);
} }
@Override @Override
protected void postProcess(BeanDefinitionBuilder builder, Element element) { protected void postProcess(BeanDefinitionBuilder builder, Element element) {
List<Element> subElements = DomUtils.getChildElements(element); List<Element> subElements = DomUtils.getChildElements(element);
@@ -86,28 +84,28 @@ public class CassandraKeyspaceParser extends AbstractSimpleBeanDefinitionParser
// parse nested elements // parse nested elements
for (Element subElement : subElements) { for (Element subElement : subElements) {
String name = subElement.getLocalName(); String name = subElement.getLocalName();
if ("keyspace-attributes".equals(name)) { if ("keyspace-attributes".equals(name)) {
builder.addPropertyValue("keyspaceAttributes", parseKeyspaceAttributes(subElement)); builder.addPropertyValue("keyspaceAttributes", parseKeyspaceAttributes(subElement));
} }
} }
} }
private BeanDefinition parseKeyspaceAttributes(Element element) { private BeanDefinition parseKeyspaceAttributes(Element element) {
BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.genericBeanDefinition(KeyspaceAttributes.class); BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.genericBeanDefinition(KeyspaceAttributes.class);
ParsingUtils.setPropertyValue(defBuilder, element, "auto", "auto"); ParsingUtils.setPropertyValue(defBuilder, element, "auto", "auto");
ParsingUtils.setPropertyValue(defBuilder, element, "replication-strategy", "replicationStrategy"); ParsingUtils.setPropertyValue(defBuilder, element, "replication-strategy", "replicationStrategy");
ParsingUtils.setPropertyValue(defBuilder, element, "replication-factor", "replicationFactor"); ParsingUtils.setPropertyValue(defBuilder, element, "replication-factor", "replicationFactor");
ParsingUtils.setPropertyValue(defBuilder, element, "durable-writes", "durableWrites"); ParsingUtils.setPropertyValue(defBuilder, element, "durable-writes", "durableWrites");
List<Element> subElements = DomUtils.getChildElements(element); List<Element> subElements = DomUtils.getChildElements(element);
ManagedList<Object> tables = new ManagedList<Object>(subElements.size()); ManagedList<Object> tables = new ManagedList<Object>(subElements.size());
// parse nested elements // parse nested elements
for (Element subElement : subElements) { for (Element subElement : subElements) {
String name = subElement.getLocalName(); String name = subElement.getLocalName();
if ("table".equals(name)) { if ("table".equals(name)) {
tables.add(parseTable(subElement)); tables.add(parseTable(subElement));
} }
@@ -115,10 +113,10 @@ public class CassandraKeyspaceParser extends AbstractSimpleBeanDefinitionParser
if (!tables.isEmpty()) { if (!tables.isEmpty()) {
defBuilder.addPropertyValue("tables", tables); defBuilder.addPropertyValue("tables", tables);
} }
return defBuilder.getBeanDefinition(); return defBuilder.getBeanDefinition();
} }
private BeanDefinition parseTable(Element element) { private BeanDefinition parseTable(Element element) {
BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.genericBeanDefinition(TableAttributes.class); BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.genericBeanDefinition(TableAttributes.class);
ParsingUtils.setPropertyValue(defBuilder, element, "entity", "entity"); ParsingUtils.setPropertyValue(defBuilder, element, "entity", "entity");

View File

@@ -26,10 +26,10 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
public class CassandraNamespaceHandler extends NamespaceHandlerSupport { public class CassandraNamespaceHandler extends NamespaceHandlerSupport {
public void init() { public void init() {
registerBeanDefinitionParser("cluster", new CassandraClusterParser()); registerBeanDefinitionParser("cluster", new CassandraClusterParser());
registerBeanDefinitionParser("keyspace", new CassandraKeyspaceParser()); registerBeanDefinitionParser("keyspace", new CassandraKeyspaceParser());
} }
} }

View File

@@ -18,9 +18,8 @@ package org.springframework.data.cassandra.config;
import java.util.Collection; import java.util.Collection;
/** /**
* Keyspace attributes are used for manipulation around keyspace at the startup. * Keyspace attributes are used for manipulation around keyspace at the startup. Auto property defines the way how to do
* Auto property defines the way how to do this. Other attributes used to * this. Other attributes used to ensure or update keyspace settings.
* ensure or update keyspace settings.
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
@@ -29,34 +28,34 @@ public class KeyspaceAttributes {
public static final String DEFAULT_REPLICATION_STRATEGY = "SimpleStrategy"; public static final String DEFAULT_REPLICATION_STRATEGY = "SimpleStrategy";
public static final int DEFAULT_REPLICATION_FACTOR = 1; public static final int DEFAULT_REPLICATION_FACTOR = 1;
public static final boolean DEFAULT_DURABLE_WRITES = true; public static final boolean DEFAULT_DURABLE_WRITES = true;
/* /*
* auto possible values: * auto possible values:
* validate: validate the keyspace, makes no changes. * validate: validate the keyspace, makes no changes.
* update: update the keyspace. * update: update the keyspace.
* create: creates the keyspace, destroying previous data. * create: creates the keyspace, destroying previous data.
* create-drop: drop the keyspace at the end of the session. * create-drop: drop the keyspace at the end of the session.
*/ */
public static final String AUTO_VALIDATE = "validate"; public static final String AUTO_VALIDATE = "validate";
public static final String AUTO_UPDATE = "update"; public static final String AUTO_UPDATE = "update";
public static final String AUTO_CREATE = "create"; public static final String AUTO_CREATE = "create";
public static final String AUTO_CREATE_DROP = "create-drop"; public static final String AUTO_CREATE_DROP = "create-drop";
private String auto = AUTO_VALIDATE; private String auto = AUTO_VALIDATE;
private String replicationStrategy = DEFAULT_REPLICATION_STRATEGY; private String replicationStrategy = DEFAULT_REPLICATION_STRATEGY;
private int replicationFactor = DEFAULT_REPLICATION_FACTOR; private int replicationFactor = DEFAULT_REPLICATION_FACTOR;
private boolean durableWrites = DEFAULT_DURABLE_WRITES; private boolean durableWrites = DEFAULT_DURABLE_WRITES;
private Collection<TableAttributes> tables; private Collection<TableAttributes> tables;
public String getAuto() { public String getAuto() {
return auto; return auto;
} }
public void setAuto(String auto) { public void setAuto(String auto) {
this.auto = auto; this.auto = auto;
} }
public boolean isValidate() { public boolean isValidate() {
return AUTO_VALIDATE.equals(auto); return AUTO_VALIDATE.equals(auto);
} }
@@ -76,15 +75,15 @@ public class KeyspaceAttributes {
public String getReplicationStrategy() { public String getReplicationStrategy() {
return replicationStrategy; return replicationStrategy;
} }
public void setReplicationStrategy(String replicationStrategy) { public void setReplicationStrategy(String replicationStrategy) {
this.replicationStrategy = replicationStrategy; this.replicationStrategy = replicationStrategy;
} }
public int getReplicationFactor() { public int getReplicationFactor() {
return replicationFactor; return replicationFactor;
} }
public void setReplicationFactor(int replicationFactor) { public void setReplicationFactor(int replicationFactor) {
this.replicationFactor = replicationFactor; this.replicationFactor = replicationFactor;
} }
@@ -104,5 +103,5 @@ public class KeyspaceAttributes {
public void setTables(Collection<TableAttributes> tables) { public void setTables(Collection<TableAttributes> tables) {
this.tables = tables; this.tables = tables;
} }
} }

View File

@@ -24,7 +24,7 @@ public class TableAttributes {
private String entity; private String entity;
private String name; private String name;
public String getEntity() { public String getEntity() {
return entity; return entity;
} }
@@ -32,7 +32,7 @@ public class TableAttributes {
public void setEntity(String entity) { public void setEntity(String entity) {
this.entity = entity; this.entity = entity;
} }
public String getName() { public String getName() {
return name; return name;
} }
@@ -45,5 +45,5 @@ public class TableAttributes {
public String toString() { public String toString() {
return "TableAttributes [entity=" + entity + "]"; return "TableAttributes [entity=" + entity + "]";
} }
} }

View File

@@ -22,16 +22,16 @@ import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.convert.EntityInstantiators; import org.springframework.data.convert.EntityInstantiators;
/** /**
* Base class for {@link CassandraConverter} implementations. Sets up a {@link GenericConversionService} and populates basic * Base class for {@link CassandraConverter} implementations. Sets up a {@link GenericConversionService} and populates
* converters. * basic converters.
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
public abstract class AbstractCassandraConverter implements CassandraConverter, InitializingBean { public abstract class AbstractCassandraConverter implements CassandraConverter, InitializingBean {
protected final GenericConversionService conversionService; protected final GenericConversionService conversionService;
protected EntityInstantiators instantiators = new EntityInstantiators(); protected EntityInstantiators instantiators = new EntityInstantiators();
/** /**
* Creates a new {@link AbstractMongoConverter} using the given {@link GenericConversionService}. * Creates a new {@link AbstractMongoConverter} using the given {@link GenericConversionService}.
* *
@@ -40,7 +40,7 @@ public abstract class AbstractCassandraConverter implements CassandraConverter,
public AbstractCassandraConverter(GenericConversionService conversionService) { public AbstractCassandraConverter(GenericConversionService conversionService) {
this.conversionService = conversionService == null ? new DefaultConversionService() : conversionService; this.conversionService = conversionService == null ? new DefaultConversionService() : conversionService;
} }
/** /**
* Registers {@link EntityInstantiators} to customize entity instantiation. * Registers {@link EntityInstantiators} to customize entity instantiation.
* *
@@ -49,7 +49,7 @@ public abstract class AbstractCassandraConverter implements CassandraConverter,
public void setInstantiators(EntityInstantiators instantiators) { public void setInstantiators(EntityInstantiators instantiators) {
this.instantiators = instantiators == null ? new EntityInstantiators() : instantiators; this.instantiators = instantiators == null ? new EntityInstantiators() : instantiators;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.mongodb.core.core.convert.MongoConverter#getConversionService() * @see org.springframework.data.mongodb.core.core.convert.MongoConverter#getConversionService()
@@ -57,11 +57,11 @@ public abstract class AbstractCassandraConverter implements CassandraConverter,
public ConversionService getConversionService() { public ConversionService getConversionService() {
return conversionService; return conversionService;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/ */
public void afterPropertiesSet() { public void afterPropertiesSet() {
} }
} }

View File

@@ -26,6 +26,7 @@ import com.datastax.driver.core.Row;
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
public interface CassandraConverter extends EntityConverter<CassandraPersistentEntity<?>, CassandraPersistentProperty, Object, Row> { public interface CassandraConverter extends
EntityConverter<CassandraPersistentEntity<?>, CassandraPersistentProperty, Object, Row> {
} }

View File

@@ -35,14 +35,15 @@ import com.datastax.driver.core.Row;
* @author Alex Shvid * @author Alex Shvid
*/ */
public class CassandraPropertyValueProvider implements PropertyValueProvider<CassandraPersistentProperty> { public class CassandraPropertyValueProvider implements PropertyValueProvider<CassandraPersistentProperty> {
private static Logger log = LoggerFactory.getLogger(CassandraPropertyValueProvider.class); private static Logger log = LoggerFactory.getLogger(CassandraPropertyValueProvider.class);
private final Row source; private final Row source;
private final SpELExpressionEvaluator evaluator; private final SpELExpressionEvaluator evaluator;
/** /**
* Creates a new {@link CassandraPropertyValueProvider} with the given {@link Row} and {@link DefaultSpELExpressionEvaluator}. * Creates a new {@link CassandraPropertyValueProvider} with the given {@link Row} and
* {@link DefaultSpELExpressionEvaluator}.
* *
* @param source must not be {@literal null}. * @param source must not be {@literal null}.
* @param evaluator must not be {@literal null}. * @param evaluator must not be {@literal null}.
@@ -54,41 +55,41 @@ public class CassandraPropertyValueProvider implements PropertyValueProvider<Cas
this.source = source; this.source = source;
this.evaluator = evaluator; this.evaluator = evaluator;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.convert.PropertyValueProvider#getPropertyValue(org.springframework.data.mapping.PersistentProperty) * @see org.springframework.data.convert.PropertyValueProvider#getPropertyValue(org.springframework.data.mapping.PersistentProperty)
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T getPropertyValue(CassandraPersistentProperty property) { public <T> T getPropertyValue(CassandraPersistentProperty property) {
String expression = property.getSpelExpression(); String expression = property.getSpelExpression();
if (expression != null) { if (expression != null) {
return evaluator.evaluate(expression); return evaluator.evaluate(expression);
} }
String columnName = property.getColumnName(); String columnName = property.getColumnName();
if (source.isNull(property.getColumnName())) { if (source.isNull(property.getColumnName())) {
return null; return null;
} }
DataType columnType = source.getColumnDefinitions().getType(columnName); DataType columnType = source.getColumnDefinitions().getType(columnName);
log.info(columnType.getName().name()); log.info(columnType.getName().name());
/* /*
* Dave Webb - Added handler for text since getBytes was throwing * Dave Webb - Added handler for text since getBytes was throwing
* InvalidTypeException when using getBytes on a text column. * InvalidTypeException when using getBytes on a text column.
*/ */
//TODO Might need to qualify all DataTypes as we encounter them. // TODO Might need to qualify all DataTypes as we encounter them.
if (columnType.equals(DataType.text())) { if (columnType.equals(DataType.text())) {
return (T) source.getString(columnName); return (T) source.getString(columnName);
} }
if (columnType.equals(DataType.cint())) { if (columnType.equals(DataType.cint())) {
return (T) new Integer(source.getInt(columnName)); return (T) new Integer(source.getInt(columnName));
} }
ByteBuffer bytes = source.getBytes(columnName); ByteBuffer bytes = source.getBytes(columnName);
return (T) columnType.deserialize(bytes); return (T) columnType.deserialize(bytes);
} }
} }

View File

@@ -46,36 +46,38 @@ import com.datastax.driver.core.Row;
public class MappingCassandraConverter extends AbstractCassandraConverter implements ApplicationContextAware { public class MappingCassandraConverter extends AbstractCassandraConverter implements ApplicationContextAware {
protected static final Logger log = LoggerFactory.getLogger(MappingCassandraConverter.class); protected static final Logger log = LoggerFactory.getLogger(MappingCassandraConverter.class);
protected final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext; protected final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
protected ApplicationContext applicationContext; protected ApplicationContext applicationContext;
private SpELContext spELContext; private SpELContext spELContext;
private boolean useFieldAccessOnly = true; private boolean useFieldAccessOnly = true;
/** /**
* Creates a new {@link MappingCassandraConverter} given the new {@link MappingContext}. * Creates a new {@link MappingCassandraConverter} given the new {@link MappingContext}.
* *
* @param mappingContext must not be {@literal null}. * @param mappingContext must not be {@literal null}.
*/ */
public MappingCassandraConverter(MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext) { public MappingCassandraConverter(
MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext) {
super(new DefaultConversionService()); super(new DefaultConversionService());
this.mappingContext = mappingContext; this.mappingContext = mappingContext;
this.spELContext = new SpELContext(RowReaderPropertyAccessor.INSTANCE); this.spELContext = new SpELContext(RowReaderPropertyAccessor.INSTANCE);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <R> R read(Class<R> clazz, Row row) { public <R> R read(Class<R> clazz, Row row) {
TypeInformation<? extends R> type = ClassTypeInformation.from(clazz); TypeInformation<? extends R> type = ClassTypeInformation.from(clazz);
//TypeInformation<? extends R> typeToUse = typeMapper.readType(row, type); // TypeInformation<? extends R> typeToUse = typeMapper.readType(row, type);
TypeInformation<? extends R> typeToUse = type; TypeInformation<? extends R> typeToUse = type;
Class<? extends R> rawType = typeToUse.getType(); Class<? extends R> rawType = typeToUse.getType();
if (Row.class.isAssignableFrom(rawType)) { if (Row.class.isAssignableFrom(rawType)) {
return (R) row; return (R) row;
} }
CassandraPersistentEntity<R> persistentEntity = (CassandraPersistentEntity<R>) mappingContext.getPersistentEntity(typeToUse); CassandraPersistentEntity<R> persistentEntity = (CassandraPersistentEntity<R>) mappingContext
.getPersistentEntity(typeToUse);
if (persistentEntity == null) { if (persistentEntity == null) {
throw new MappingException("No mapping metadata found for " + rawType.getName()); throw new MappingException("No mapping metadata found for " + rawType.getName());
} }
@@ -99,15 +101,16 @@ public class MappingCassandraConverter extends AbstractCassandraConverter implem
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.spELContext = new SpELContext(this.spELContext, applicationContext); this.spELContext = new SpELContext(this.spELContext, applicationContext);
} }
private <S extends Object> S read(final CassandraPersistentEntity<S> entity, final Row row) { private <S extends Object> S read(final CassandraPersistentEntity<S> entity, final Row row) {
final DefaultSpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(row, spELContext); final DefaultSpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(row, spELContext);
final PropertyValueProvider<CassandraPersistentProperty> propertyProvider = new CassandraPropertyValueProvider(row, evaluator); final PropertyValueProvider<CassandraPersistentProperty> propertyProvider = new CassandraPropertyValueProvider(row,
evaluator);
PersistentEntityParameterValueProvider<CassandraPersistentProperty> parameterProvider = new PersistentEntityParameterValueProvider<CassandraPersistentProperty>( PersistentEntityParameterValueProvider<CassandraPersistentProperty> parameterProvider = new PersistentEntityParameterValueProvider<CassandraPersistentProperty>(
entity, propertyProvider, null); entity, propertyProvider, null);
EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity);
S instance = instantiator.createInstance(entity, parameterProvider); S instance = instantiator.createInstance(entity, parameterProvider);
@@ -129,7 +132,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter implem
wrapper.setProperty(prop, obj, useFieldAccessOnly); wrapper.setProperty(prop, obj, useFieldAccessOnly);
} }
}); });
return result; return result;
} }
@@ -142,16 +145,14 @@ public class MappingCassandraConverter extends AbstractCassandraConverter implem
*/ */
@Override @Override
public void write(Object source, Row sink) { public void write(Object source, Row sink) {
/* /*
* There is no concept of passing a Row into Cassandra for Writing. * There is no concept of passing a Row into Cassandra for Writing.
* This must be done with Query * This must be done with Query
* *
* See the CQLUtils. * See the CQLUtils.
*/ */
} }
} }

View File

@@ -41,34 +41,34 @@ import com.datastax.driver.core.policies.RetryPolicy;
* @author Alex Shvid * @author Alex Shvid
*/ */
public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, InitializingBean, DisposableBean,
InitializingBean, DisposableBean, PersistenceExceptionTranslator { PersistenceExceptionTranslator {
private static final int DEFAULT_PORT = 9042; private static final int DEFAULT_PORT = 9042;
private Cluster cluster; private Cluster cluster;
private String contactPoints; private String contactPoints;
private int port = DEFAULT_PORT; private int port = DEFAULT_PORT;
private CompressionType compressionType; private CompressionType compressionType;
private PoolingOptionsConfig localPoolingOptions; private PoolingOptionsConfig localPoolingOptions;
private PoolingOptionsConfig remotePoolingOptions; private PoolingOptionsConfig remotePoolingOptions;
private SocketOptionsConfig socketOptions; private SocketOptionsConfig socketOptions;
private AuthProvider authProvider; private AuthProvider authProvider;
private LoadBalancingPolicy loadBalancingPolicy; private LoadBalancingPolicy loadBalancingPolicy;
private ReconnectionPolicy reconnectionPolicy; private ReconnectionPolicy reconnectionPolicy;
private RetryPolicy retryPolicy; private RetryPolicy retryPolicy;
private boolean metricsEnabled = true; private boolean metricsEnabled = true;
private final PersistenceExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator(); private final PersistenceExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator();
public Cluster getObject() throws Exception { public Cluster getObject() throws Exception {
return cluster; return cluster;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#getObjectType() * @see org.springframework.beans.factory.FactoryBean#getObjectType()
@@ -84,7 +84,7 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>,
public boolean isSingleton() { public boolean isSingleton() {
return true; return true;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.dao.support.PersistenceExceptionTranslator#translateExceptionIfPossible(java.lang.RuntimeException) * @see org.springframework.dao.support.PersistenceExceptionTranslator#translateExceptionIfPossible(java.lang.RuntimeException)
@@ -92,22 +92,21 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>,
public DataAccessException translateExceptionIfPossible(RuntimeException ex) { public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return exceptionTranslator.translateExceptionIfPossible(ex); return exceptionTranslator.translateExceptionIfPossible(ex);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/ */
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
if (!StringUtils.hasText(contactPoints)) { if (!StringUtils.hasText(contactPoints)) {
throw new IllegalArgumentException( throw new IllegalArgumentException("at least one server is required");
"at least one server is required");
} }
Cluster.Builder builder = Cluster.builder(); Cluster.Builder builder = Cluster.builder();
builder.addContactPoints(StringUtils.commaDelimitedListToStringArray(contactPoints)).withPort(port); builder.addContactPoints(StringUtils.commaDelimitedListToStringArray(contactPoints)).withPort(port);
if (compressionType != null) { if (compressionType != null) {
builder.withCompression(convertCompressionType(compressionType)); builder.withCompression(convertCompressionType(compressionType));
} }
@@ -123,33 +122,33 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>,
if (socketOptions != null) { if (socketOptions != null) {
builder.withSocketOptions(configSocketOptions(socketOptions)); builder.withSocketOptions(configSocketOptions(socketOptions));
} }
if (authProvider != null) { if (authProvider != null) {
builder.withAuthProvider(authProvider); builder.withAuthProvider(authProvider);
} }
if (loadBalancingPolicy != null) { if (loadBalancingPolicy != null) {
builder.withLoadBalancingPolicy(loadBalancingPolicy); builder.withLoadBalancingPolicy(loadBalancingPolicy);
} }
if (reconnectionPolicy != null) { if (reconnectionPolicy != null) {
builder.withReconnectionPolicy(reconnectionPolicy); builder.withReconnectionPolicy(reconnectionPolicy);
} }
if (retryPolicy != null) { if (retryPolicy != null) {
builder.withRetryPolicy(retryPolicy); builder.withRetryPolicy(retryPolicy);
} }
if (!metricsEnabled) { if (!metricsEnabled) {
builder.withoutMetrics(); builder.withoutMetrics();
} }
Cluster cluster = builder.build(); Cluster cluster = builder.build();
// initialize property // initialize property
this.cluster = cluster; this.cluster = cluster;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.beans.factory.DisposableBean#destroy() * @see org.springframework.beans.factory.DisposableBean#destroy()
@@ -169,7 +168,7 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>,
public void setCompressionType(CompressionType compressionType) { public void setCompressionType(CompressionType compressionType) {
this.compressionType = compressionType; this.compressionType = compressionType;
} }
public void setLocalPoolingOptions(PoolingOptionsConfig localPoolingOptions) { public void setLocalPoolingOptions(PoolingOptionsConfig localPoolingOptions) {
this.localPoolingOptions = localPoolingOptions; this.localPoolingOptions = localPoolingOptions;
} }
@@ -185,7 +184,7 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>,
public void setAuthProvider(AuthProvider authProvider) { public void setAuthProvider(AuthProvider authProvider) {
this.authProvider = authProvider; this.authProvider = authProvider;
} }
public void setLoadBalancingPolicy(LoadBalancingPolicy loadBalancingPolicy) { public void setLoadBalancingPolicy(LoadBalancingPolicy loadBalancingPolicy) {
this.loadBalancingPolicy = loadBalancingPolicy; this.loadBalancingPolicy = loadBalancingPolicy;
} }
@@ -203,23 +202,25 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>,
} }
private static Compression convertCompressionType(CompressionType type) { private static Compression convertCompressionType(CompressionType type) {
switch(type) { switch (type) {
case NONE: case NONE:
return Compression.NONE; return Compression.NONE;
case SNAPPY: case SNAPPY:
return Compression.SNAPPY; return Compression.SNAPPY;
} }
throw new IllegalArgumentException("unknown compression type " + type); throw new IllegalArgumentException("unknown compression type " + type);
} }
private static PoolingOptions configPoolingOptions(HostDistance hostDistance, PoolingOptionsConfig config) { private static PoolingOptions configPoolingOptions(HostDistance hostDistance, PoolingOptionsConfig config) {
PoolingOptions poolingOptions = new PoolingOptions(); PoolingOptions poolingOptions = new PoolingOptions();
if (config.getMinSimultaneousRequests() != null) { if (config.getMinSimultaneousRequests() != null) {
poolingOptions.setMinSimultaneousRequestsPerConnectionThreshold(hostDistance, config.getMinSimultaneousRequests()); poolingOptions
.setMinSimultaneousRequestsPerConnectionThreshold(hostDistance, config.getMinSimultaneousRequests());
} }
if (config.getMaxSimultaneousRequests() != null) { if (config.getMaxSimultaneousRequests() != null) {
poolingOptions.setMaxSimultaneousRequestsPerConnectionThreshold(hostDistance, config.getMaxSimultaneousRequests()); poolingOptions
.setMaxSimultaneousRequestsPerConnectionThreshold(hostDistance, config.getMaxSimultaneousRequests());
} }
if (config.getCoreConnections() != null) { if (config.getCoreConnections() != null) {
poolingOptions.setCoreConnectionsPerHost(hostDistance, config.getCoreConnections()); poolingOptions.setCoreConnectionsPerHost(hostDistance, config.getCoreConnections());
@@ -227,13 +228,13 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>,
if (config.getMaxConnections() != null) { if (config.getMaxConnections() != null) {
poolingOptions.setMaxConnectionsPerHost(hostDistance, config.getMaxConnections()); poolingOptions.setMaxConnectionsPerHost(hostDistance, config.getMaxConnections());
} }
return poolingOptions; return poolingOptions;
} }
private static SocketOptions configSocketOptions(SocketOptionsConfig config) { private static SocketOptions configSocketOptions(SocketOptionsConfig config) {
SocketOptions socketOptions = new SocketOptions(); SocketOptions socketOptions = new SocketOptions();
if (config.getConnectTimeoutMls() != null) { if (config.getConnectTimeoutMls() != null) {
socketOptions.setConnectTimeoutMillis(config.getConnectTimeoutMls()); socketOptions.setConnectTimeoutMillis(config.getConnectTimeoutMls());
} }
@@ -255,7 +256,7 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>,
if (config.getSendBufferSize() != null) { if (config.getSendBufferSize() != null) {
socketOptions.setSendBufferSize(config.getSendBufferSize()); socketOptions.setSendBufferSize(config.getSendBufferSize());
} }
return socketOptions; return socketOptions;
} }
} }

View File

@@ -52,18 +52,15 @@ import com.datastax.driver.core.exceptions.UnavailableException;
import com.datastax.driver.core.exceptions.WriteTimeoutException; import com.datastax.driver.core.exceptions.WriteTimeoutException;
/** /**
* Simple {@link PersistenceExceptionTranslator} for Cassandra. Convert the * Simple {@link PersistenceExceptionTranslator} for Cassandra. Convert the given runtime exception to an appropriate
* given runtime exception to an appropriate exception from the * exception from the {@code org.springframework.dao} hierarchy. Return {@literal null} if no translation is
* {@code org.springframework.dao} hierarchy. Return {@literal null} if no * appropriate: any other exception may have resulted from user code, and should not be translated.
* translation is appropriate: any other exception may have resulted from user
* code, and should not be translated.
* *
* @author Alex Shvid * @author Alex Shvid
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraExceptionTranslator implements public class CassandraExceptionTranslator implements PersistenceExceptionTranslator {
PersistenceExceptionTranslator {
/* /*
* (non-Javadoc) * (non-Javadoc)
@@ -81,8 +78,7 @@ public class CassandraExceptionTranslator implements
// superclass would match before the subclass! // superclass would match before the subclass!
if (x instanceof AuthenticationException) { if (x instanceof AuthenticationException) {
return new CassandraAuthenticationException( return new CassandraAuthenticationException(((AuthenticationException) x).getHost(), x.getMessage(), x);
((AuthenticationException) x).getHost(), x.getMessage(), x);
} }
if (x instanceof DriverInternalError) { if (x instanceof DriverInternalError) {
return new CassandraInternalException(x.getMessage(), x); return new CassandraInternalException(x.getMessage(), x);
@@ -91,40 +87,31 @@ public class CassandraExceptionTranslator implements
return new CassandraTypeMismatchException(x.getMessage(), x); return new CassandraTypeMismatchException(x.getMessage(), x);
} }
if (x instanceof NoHostAvailableException) { if (x instanceof NoHostAvailableException) {
return new CassandraConnectionFailureException( return new CassandraConnectionFailureException(((NoHostAvailableException) x).getErrors(), x.getMessage(), x);
((NoHostAvailableException) x).getErrors(), x.getMessage(),
x);
} }
if (x instanceof ReadTimeoutException) { if (x instanceof ReadTimeoutException) {
return new CassandraReadTimeoutException( return new CassandraReadTimeoutException(((ReadTimeoutException) x).wasDataRetrieved(), x.getMessage(), x);
((ReadTimeoutException) x).wasDataRetrieved(),
x.getMessage(), x);
} }
if (x instanceof WriteTimeoutException) { if (x instanceof WriteTimeoutException) {
WriteType writeType = ((WriteTimeoutException) x).getWriteType(); WriteType writeType = ((WriteTimeoutException) x).getWriteType();
return new CassandraWriteTimeoutException(writeType == null ? null return new CassandraWriteTimeoutException(writeType == null ? null : writeType.name(), x.getMessage(), x);
: writeType.name(), x.getMessage(), x);
} }
if (x instanceof TruncateException) { if (x instanceof TruncateException) {
return new CassandraTruncateException(x.getMessage(), x); return new CassandraTruncateException(x.getMessage(), x);
} }
if (x instanceof UnavailableException) { if (x instanceof UnavailableException) {
UnavailableException ux = (UnavailableException) x; UnavailableException ux = (UnavailableException) x;
return new CassandraInsufficientReplicasAvailableException( return new CassandraInsufficientReplicasAvailableException(ux.getRequiredReplicas(), ux.getAliveReplicas(),
ux.getRequiredReplicas(), ux.getAliveReplicas(),
x.getMessage(), x); x.getMessage(), x);
} }
if (x instanceof AlreadyExistsException) { if (x instanceof AlreadyExistsException) {
AlreadyExistsException aex = (AlreadyExistsException) x; AlreadyExistsException aex = (AlreadyExistsException) x;
return aex.wasTableCreation() ? new CassandraTableExistsException( return aex.wasTableCreation() ? new CassandraTableExistsException(aex.getTable(), x.getMessage(), x)
aex.getTable(), x.getMessage(), x) : new CassandraKeyspaceExistsException(aex.getKeyspace(), x.getMessage(), x);
: new CassandraKeyspaceExistsException(aex.getKeyspace(),
x.getMessage(), x);
} }
if (x instanceof InvalidConfigurationInQueryException) { if (x instanceof InvalidConfigurationInQueryException) {
return new CassandraInvalidConfigurationInQueryException( return new CassandraInvalidConfigurationInQueryException(x.getMessage(), x);
x.getMessage(), x);
} }
if (x instanceof InvalidQueryException) { if (x instanceof InvalidQueryException) {
return new CassandraInvalidQueryException(x.getMessage(), x); return new CassandraInvalidQueryException(x.getMessage(), x);

View File

@@ -25,10 +25,10 @@ import com.datastax.driver.core.DataType;
* @author Alex Shvid * @author Alex Shvid
*/ */
public class CassandraValue { public class CassandraValue {
private final ByteBuffer value; private final ByteBuffer value;
private final DataType type; private final DataType type;
public CassandraValue(ByteBuffer value, DataType type) { public CassandraValue(ByteBuffer value, DataType type) {
this.value = value; this.value = value;
this.type = type; this.type = type;
@@ -41,5 +41,5 @@ public class CassandraValue {
public DataType getType() { public DataType getType() {
return type; return type;
} }
} }

View File

@@ -20,7 +20,7 @@ import org.springframework.data.cassandra.convert.CassandraConverter;
import com.datastax.driver.core.Session; import com.datastax.driver.core.Session;
/** /**
* Simple Cassandra Keyspace object * Simple Cassandra Keyspace object
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
@@ -29,7 +29,7 @@ public class Keyspace {
private final String keyspace; private final String keyspace;
private final Session session; private final Session session;
private final CassandraConverter cassandraConverter; private final CassandraConverter cassandraConverter;
/** /**
* Constructor used for a basic keyspace configuration * Constructor used for a basic keyspace configuration
* *
@@ -42,7 +42,7 @@ public class Keyspace {
this.session = session; this.session = session;
this.cassandraConverter = cassandraConverter; this.cassandraConverter = cassandraConverter;
} }
public String getKeyspace() { public String getKeyspace() {
return keyspace; return keyspace;
} }

View File

@@ -21,12 +21,12 @@ import com.datastax.driver.core.Host;
/** /**
* @author David Webb * @author David Webb
* *
*/ */
public final class RingMember implements Serializable { public final class RingMember implements Serializable {
private static final long serialVersionUID = 1345346346L; private static final long serialVersionUID = 1345346346L;
/* /*
* Ring attributes * Ring attributes
*/ */
@@ -34,8 +34,9 @@ public final class RingMember implements Serializable {
public final String address; public final String address;
public final String DC; public final String DC;
public final String rack; public final String rack;
//public final String status;
//public final String state; // public final String status;
// public final String state;
public RingMember(Host h) { public RingMember(Host h) {
this.hostName = h.getAddress().getHostName(); this.hostName = h.getAddress().getHostName();

View File

@@ -25,15 +25,13 @@ import org.springframework.dao.PermissionDeniedDataAccessException;
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraAuthenticationException extends public class CassandraAuthenticationException extends PermissionDeniedDataAccessException {
PermissionDeniedDataAccessException {
private static final long serialVersionUID = 8556304586797273927L; private static final long serialVersionUID = 8556304586797273927L;
private InetAddress host; private InetAddress host;
public CassandraAuthenticationException(InetAddress host, String msg, public CassandraAuthenticationException(InetAddress host, String msg, Throwable cause) {
Throwable cause) {
super(msg, cause); super(msg, cause);
this.host = host; this.host = host;
} }

View File

@@ -28,15 +28,13 @@ import org.springframework.dao.DataAccessResourceFailureException;
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraConnectionFailureException extends public class CassandraConnectionFailureException extends DataAccessResourceFailureException {
DataAccessResourceFailureException {
private static final long serialVersionUID = 6299912054261646552L; private static final long serialVersionUID = 6299912054261646552L;
private final Map<InetAddress, String> messagesByHost = new HashMap<InetAddress, String>(); private final Map<InetAddress, String> messagesByHost = new HashMap<InetAddress, String>();
public CassandraConnectionFailureException( public CassandraConnectionFailureException(Map<InetAddress, String> messagesByHost, String msg, Throwable cause) {
Map<InetAddress, String> messagesByHost, String msg, Throwable cause) {
super(msg, cause); super(msg, cause);
this.messagesByHost.putAll(messagesByHost); this.messagesByHost.putAll(messagesByHost);
} }

View File

@@ -19,13 +19,11 @@ package org.springframework.data.cassandra.core.exceptions;
import org.springframework.dao.TransientDataAccessException; import org.springframework.dao.TransientDataAccessException;
/** /**
* Spring data access exception for Cassandra when insufficient replicas are * Spring data access exception for Cassandra when insufficient replicas are available for a given consistency level.
* available for a given consistency level.
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraInsufficientReplicasAvailableException extends public class CassandraInsufficientReplicasAvailableException extends TransientDataAccessException {
TransientDataAccessException {
private static final long serialVersionUID = 6415130674604814905L; private static final long serialVersionUID = 6415130674604814905L;
@@ -36,8 +34,8 @@ public class CassandraInsufficientReplicasAvailableException extends
super(msg); super(msg);
} }
public CassandraInsufficientReplicasAvailableException(int numberRequired, public CassandraInsufficientReplicasAvailableException(int numberRequired, int numberAlive, String msg,
int numberAlive, String msg, Throwable cause) { Throwable cause) {
super(msg, cause); super(msg, cause);
this.numberRequired = numberRequired; this.numberRequired = numberRequired;
this.numberAlive = numberAlive; this.numberAlive = numberAlive;

View File

@@ -19,13 +19,12 @@ package org.springframework.data.cassandra.core.exceptions;
import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.dao.InvalidDataAccessApiUsageException;
/** /**
* Spring data access exception for a Cassandra query that is syntactically * Spring data access exception for a Cassandra query that is syntactically correct but has an invalid configuration
* correct but has an invalid configuration clause. * clause.
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraInvalidConfigurationInQueryException extends public class CassandraInvalidConfigurationInQueryException extends InvalidDataAccessApiUsageException {
InvalidDataAccessApiUsageException {
private static final long serialVersionUID = 4594321191806182918L; private static final long serialVersionUID = 4594321191806182918L;
@@ -33,8 +32,7 @@ public class CassandraInvalidConfigurationInQueryException extends
super(msg); super(msg);
} }
public CassandraInvalidConfigurationInQueryException(String msg, public CassandraInvalidConfigurationInQueryException(String msg, Throwable cause) {
Throwable cause) {
super(msg, cause); super(msg, cause);
} }
} }

View File

@@ -19,13 +19,11 @@ package org.springframework.data.cassandra.core.exceptions;
import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.dao.InvalidDataAccessApiUsageException;
/** /**
* Spring data access exception for a Cassandra query that's syntactically * Spring data access exception for a Cassandra query that's syntactically correct but invalid.
* correct but invalid.
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraInvalidQueryException extends public class CassandraInvalidQueryException extends InvalidDataAccessApiUsageException {
InvalidDataAccessApiUsageException {
private static final long serialVersionUID = 4594321191806182918L; private static final long serialVersionUID = 4594321191806182918L;

View File

@@ -17,18 +17,15 @@
package org.springframework.data.cassandra.core.exceptions; package org.springframework.data.cassandra.core.exceptions;
/** /**
* Spring data access exception for Cassandra when a keyspace being created * Spring data access exception for Cassandra when a keyspace being created already exists.
* already exists.
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraKeyspaceExistsException extends public class CassandraKeyspaceExistsException extends CassandraSchemaElementExistsException {
CassandraSchemaElementExistsException {
private static final long serialVersionUID = 6032967419751410352L; private static final long serialVersionUID = 6032967419751410352L;
public CassandraKeyspaceExistsException(String keyspaceName, String msg, public CassandraKeyspaceExistsException(String keyspaceName, String msg, Throwable cause) {
Throwable cause) {
super(keyspaceName, ElementType.KEYSPACE, msg, cause); super(keyspaceName, ElementType.KEYSPACE, msg, cause);
} }

View File

@@ -29,8 +29,7 @@ public class CassandraReadTimeoutException extends QueryTimeoutException {
private boolean wasDataReceived; private boolean wasDataReceived;
public CassandraReadTimeoutException(boolean wasDataReceived, String msg, public CassandraReadTimeoutException(boolean wasDataReceived, String msg, Throwable cause) {
Throwable cause) {
super(msg); super(msg);
this.wasDataReceived = wasDataReceived; this.wasDataReceived = wasDataReceived;
} }

View File

@@ -19,13 +19,11 @@ package org.springframework.data.cassandra.core.exceptions;
import org.springframework.dao.NonTransientDataAccessException; import org.springframework.dao.NonTransientDataAccessException;
/** /**
* Spring data access exception for when Cassandra schema element being created * Spring data access exception for when Cassandra schema element being created already exists.
* already exists.
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraSchemaElementExistsException extends public class CassandraSchemaElementExistsException extends NonTransientDataAccessException {
NonTransientDataAccessException {
private static final long serialVersionUID = 7798361273692300162L; private static final long serialVersionUID = 7798361273692300162L;
@@ -36,8 +34,7 @@ public class CassandraSchemaElementExistsException extends
private String elementName; private String elementName;
private ElementType elementType; private ElementType elementType;
public CassandraSchemaElementExistsException(String elementName, public CassandraSchemaElementExistsException(String elementName, ElementType elementType, String msg, Throwable cause) {
ElementType elementType, String msg, Throwable cause) {
super(msg, cause); super(msg, cause);
this.elementName = elementName; this.elementName = elementName;
this.elementType = elementType; this.elementType = elementType;

View File

@@ -17,18 +17,15 @@
package org.springframework.data.cassandra.core.exceptions; package org.springframework.data.cassandra.core.exceptions;
/** /**
* Spring data access exception for when a Cassandra table being created already * Spring data access exception for when a Cassandra table being created already exists.
* exists.
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraTableExistsException extends public class CassandraTableExistsException extends CassandraSchemaElementExistsException {
CassandraSchemaElementExistsException {
private static final long serialVersionUID = 6032967419751410352L; private static final long serialVersionUID = 6032967419751410352L;
public CassandraTableExistsException(String tableName, String msg, public CassandraTableExistsException(String tableName, String msg, Throwable cause) {
Throwable cause) {
super(tableName, ElementType.TABLE, msg, cause); super(tableName, ElementType.TABLE, msg, cause);
} }

View File

@@ -23,8 +23,7 @@ import org.springframework.dao.TransientDataAccessException;
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraTraceRetrievalException extends public class CassandraTraceRetrievalException extends TransientDataAccessException {
TransientDataAccessException {
private static final long serialVersionUID = -3163557220324700239L; private static final long serialVersionUID = -3163557220324700239L;

View File

@@ -23,8 +23,7 @@ import org.springframework.dao.TypeMismatchDataAccessException;
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraTypeMismatchException extends public class CassandraTypeMismatchException extends TypeMismatchDataAccessException {
TypeMismatchDataAccessException {
private static final long serialVersionUID = -7420058975444905629L; private static final long serialVersionUID = -7420058975444905629L;

View File

@@ -19,13 +19,11 @@ package org.springframework.data.cassandra.core.exceptions;
import org.springframework.dao.PermissionDeniedDataAccessException; import org.springframework.dao.PermissionDeniedDataAccessException;
/** /**
* Spring data access exception for when access to a Cassandra element is * Spring data access exception for when access to a Cassandra element is denied.
* denied.
* *
* @author Matthew T. Adams * @author Matthew T. Adams
*/ */
public class CassandraUnauthorizedException extends public class CassandraUnauthorizedException extends PermissionDeniedDataAccessException {
PermissionDeniedDataAccessException {
private static final long serialVersionUID = 4618185356687726647L; private static final long serialVersionUID = 4618185356687726647L;

View File

@@ -29,8 +29,7 @@ public class CassandraWriteTimeoutException extends QueryTimeoutException {
private String writeType; private String writeType;
public CassandraWriteTimeoutException(String writeType, String msg, public CassandraWriteTimeoutException(String writeType, String msg, Throwable cause) {
Throwable cause) {
super(msg, cause); super(msg, cause);
this.writeType = writeType; this.writeType = writeType;
} }

View File

@@ -5,5 +5,5 @@ public abstract class CQLBuilder {
public static CreateTable createTable(String tableName) { public static CreateTable createTable(String tableName) {
return null; return null;
} }
} }

View File

@@ -38,15 +38,15 @@ import org.springframework.util.StringUtils;
* @author Alex Shvid * @author Alex Shvid
*/ */
public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T, CassandraPersistentProperty> implements public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T, CassandraPersistentProperty> implements
CassandraPersistentEntity<T>, ApplicationContextAware { CassandraPersistentEntity<T>, ApplicationContextAware {
private final String table; private final String table;
private final SpelExpressionParser parser; private final SpelExpressionParser parser;
private final StandardEvaluationContext context; private final StandardEvaluationContext context;
/** /**
* Creates a new {@link BasicCassandraPersistentEntity} with the given {@link TypeInformation}. Will default the * Creates a new {@link BasicCassandraPersistentEntity} with the given {@link TypeInformation}. Will default the table
* table name to the entities simple type name. * name to the entities simple type name.
* *
* @param typeInformation * @param typeInformation
*/ */
@@ -67,7 +67,7 @@ CassandraPersistentEntity<T>, ApplicationContextAware {
this.table = fallback; this.table = fallback;
} }
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
@@ -78,7 +78,7 @@ CassandraPersistentEntity<T>, ApplicationContextAware {
context.setBeanResolver(new BeanFactoryResolver(applicationContext)); context.setBeanResolver(new BeanFactoryResolver(applicationContext));
context.setRootObject(applicationContext); context.setRootObject(applicationContext);
} }
/** /**
* Returns the table the entity shall be persisted to. * Returns the table the entity shall be persisted to.
* *
@@ -88,7 +88,7 @@ CassandraPersistentEntity<T>, ApplicationContextAware {
Expression expression = parser.parseExpression(table, ParserContext.TEMPLATE_EXPRESSION); Expression expression = parser.parseExpression(table, ParserContext.TEMPLATE_EXPRESSION);
return expression.getValue(context, String.class); return expression.getValue(context, String.class);
} }
/** /**
* {@link Comparator} implementation inspecting the {@link CassandraPersistentProperty}'s order. * {@link Comparator} implementation inspecting the {@link CassandraPersistentProperty}'s order.
* *
@@ -113,8 +113,8 @@ CassandraPersistentEntity<T>, ApplicationContextAware {
} }
return o1.getColumnName().compareTo(o2.getColumnName()); return o1.getColumnName().compareTo(o2.getColumnName());
} }
} }
} }

View File

@@ -34,9 +34,9 @@ import com.datastax.driver.core.DataType;
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentProperty<CassandraPersistentProperty> implements public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentProperty<CassandraPersistentProperty>
CassandraPersistentProperty { implements CassandraPersistentProperty {
/** /**
* Creates a new {@link BasicCassandraPersistentProperty}. * Creates a new {@link BasicCassandraPersistentProperty}.
* *
@@ -49,7 +49,7 @@ CassandraPersistentProperty {
CassandraPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) { CassandraPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
super(field, propertyDescriptor, owner, simpleTypeHolder); super(field, propertyDescriptor, owner, simpleTypeHolder);
} }
/** /**
* Also considers fields that has a RowId annotation. * Also considers fields that has a RowId annotation.
* *
@@ -63,16 +63,16 @@ CassandraPersistentProperty {
return getField().isAnnotationPresent(RowId.class); return getField().isAnnotationPresent(RowId.class);
} }
/** /**
* For dynamic tables returns true if property value is used as column name. * For dynamic tables returns true if property value is used as column name.
* *
* @return * @return
*/ */
public boolean isColumnId() { public boolean isColumnId() {
return getField().isAnnotationPresent(ColumnId.class); return getField().isAnnotationPresent(ColumnId.class);
} }
/** /**
* Returns the column name to be used to store the value of the property inside the Cassandra. * Returns the column name to be used to store the value of the property inside the Cassandra.
* *
@@ -82,7 +82,7 @@ CassandraPersistentProperty {
Column annotation = getField().getAnnotation(Column.class); Column annotation = getField().getAnnotation(Column.class);
return annotation != null && StringUtils.hasText(annotation.value()) ? annotation.value() : field.getName(); return annotation != null && StringUtils.hasText(annotation.value()) ? annotation.value() : field.getName();
} }
/** /**
* Returns the data type information if exists. * Returns the data type information if exists.
* *
@@ -96,21 +96,23 @@ CassandraPersistentProperty {
if (isMap()) { if (isMap()) {
List<TypeInformation<?>> args = getTypeInformation().getTypeArguments(); List<TypeInformation<?>> args = getTypeInformation().getTypeArguments();
ensureTypeArguments(args.size(), 2); ensureTypeArguments(args.size(), 2);
return DataType.map(autodetectPrimitiveType(args.get(0).getType()), autodetectPrimitiveType(args.get(1).getType())); return DataType.map(autodetectPrimitiveType(args.get(0).getType()),
autodetectPrimitiveType(args.get(1).getType()));
} }
if (isCollectionLike()) { if (isCollectionLike()) {
List<TypeInformation<?>> args = getTypeInformation().getTypeArguments(); List<TypeInformation<?>> args = getTypeInformation().getTypeArguments();
ensureTypeArguments(args.size(), 1); ensureTypeArguments(args.size(), 1);
if (Set.class.isAssignableFrom(getType())) { if (Set.class.isAssignableFrom(getType())) {
return DataType.set(autodetectPrimitiveType(args.get(0).getType())); return DataType.set(autodetectPrimitiveType(args.get(0).getType()));
} } else if (List.class.isAssignableFrom(getType())) {
else if (List.class.isAssignableFrom(getType())) { return DataType.list(autodetectPrimitiveType(args.get(0).getType()));
return DataType.list(autodetectPrimitiveType(args.get(0).getType()));
} }
} }
DataType dataType = CassandraSimpleTypes.autodetectPrimitive(this.getType()); DataType dataType = CassandraSimpleTypes.autodetectPrimitive(this.getType());
if (dataType == null) { if (dataType == null) {
throw new InvalidDataAccessApiUsageException("only primitive types and Set,List,Map collections are allowed, unknown type for property '" + this.getName() + "' type is '" + this.getType() + "' in the entity " + this.getOwner().getName()); throw new InvalidDataAccessApiUsageException(
"only primitive types and Set,List,Map collections are allowed, unknown type for property '" + this.getName()
+ "' type is '" + this.getType() + "' in the entity " + this.getOwner().getName());
} }
return dataType; return dataType;
} }
@@ -118,10 +120,10 @@ CassandraPersistentProperty {
private DataType qualifyAnnotatedType(Qualify annotation) { private DataType qualifyAnnotatedType(Qualify annotation) {
DataType.Name type = annotation.type(); DataType.Name type = annotation.type();
if (type.isCollection()) { if (type.isCollection()) {
switch(type) { switch (type) {
case MAP: case MAP:
ensureTypeArguments(annotation.typeArguments().length, 2); ensureTypeArguments(annotation.typeArguments().length, 2);
return DataType.map(resolvePrimitiveType(annotation.typeArguments()[0]), return DataType.map(resolvePrimitiveType(annotation.typeArguments()[0]),
resolvePrimitiveType(annotation.typeArguments()[1])); resolvePrimitiveType(annotation.typeArguments()[1]));
case LIST: case LIST:
ensureTypeArguments(annotation.typeArguments().length, 1); ensureTypeArguments(annotation.typeArguments().length, 1);
@@ -130,23 +132,23 @@ CassandraPersistentProperty {
ensureTypeArguments(annotation.typeArguments().length, 1); ensureTypeArguments(annotation.typeArguments().length, 1);
return DataType.set(resolvePrimitiveType(annotation.typeArguments()[0])); return DataType.set(resolvePrimitiveType(annotation.typeArguments()[0]));
default: default:
throw new InvalidDataAccessApiUsageException("unknown collection DataType for property '" + this.getName() + "' type is '" + this.getType() + "' in the entity " + this.getOwner().getName()); throw new InvalidDataAccessApiUsageException("unknown collection DataType for property '" + this.getName()
+ "' type is '" + this.getType() + "' in the entity " + this.getOwner().getName());
} }
} } else {
else {
return CassandraSimpleTypes.resolvePrimitive(type); return CassandraSimpleTypes.resolvePrimitive(type);
} }
} }
/** /**
* Returns true if the property has secondary index on this column. * Returns true if the property has secondary index on this column.
* *
* @return * @return
*/ */
public boolean isIndexed() { public boolean isIndexed() {
return getField().isAnnotationPresent(Index.class); return getField().isAnnotationPresent(Index.class);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.mapping.model.AbstractPersistentProperty#createAssociation() * @see org.springframework.data.mapping.model.AbstractPersistentProperty#createAssociation()
@@ -159,7 +161,9 @@ CassandraPersistentProperty {
DataType resolvePrimitiveType(DataType.Name typeName) { DataType resolvePrimitiveType(DataType.Name typeName) {
DataType dataType = CassandraSimpleTypes.resolvePrimitive(typeName); DataType dataType = CassandraSimpleTypes.resolvePrimitive(typeName);
if (dataType == null) { if (dataType == null) {
throw new InvalidDataAccessApiUsageException("only primitive types are allowed inside collections for the property '" + this.getName() + "' type is '" + this.getType() + "' in the entity " + this.getOwner().getName()); throw new InvalidDataAccessApiUsageException(
"only primitive types are allowed inside collections for the property '" + this.getName() + "' type is '"
+ this.getType() + "' in the entity " + this.getOwner().getName());
} }
return dataType; return dataType;
} }
@@ -167,17 +171,18 @@ CassandraPersistentProperty {
DataType autodetectPrimitiveType(Class<?> javaType) { DataType autodetectPrimitiveType(Class<?> javaType) {
DataType dataType = CassandraSimpleTypes.autodetectPrimitive(javaType); DataType dataType = CassandraSimpleTypes.autodetectPrimitive(javaType);
if (dataType == null) { if (dataType == null) {
throw new InvalidDataAccessApiUsageException("only primitive types are allowed inside collections for the property '" + this.getName() + "' type is '" + this.getType() + "' in the entity " + this.getOwner().getName()); throw new InvalidDataAccessApiUsageException(
"only primitive types are allowed inside collections for the property '" + this.getName() + "' type is '"
+ this.getType() + "' in the entity " + this.getOwner().getName());
} }
return dataType; return dataType;
} }
void ensureTypeArguments(int args, int expected) { void ensureTypeArguments(int args, int expected) {
if (args != expected) { if (args != expected) {
throw new InvalidDataAccessApiUsageException("expected " + expected + " of typed arguments for the property '" + this.getName() + "' type is '" + this.getType() + "' in the entity " + this.getOwner().getName()); throw new InvalidDataAccessApiUsageException("expected " + expected + " of typed arguments for the property '"
} + this.getName() + "' type is '" + this.getType() + "' in the entity " + this.getOwner().getName());
}
} }
}
}

View File

@@ -20,7 +20,6 @@ import java.lang.reflect.Field;
import org.springframework.data.mapping.model.SimpleTypeHolder; import org.springframework.data.mapping.model.SimpleTypeHolder;
/** /**
* {@link CassandraPersistentProperty} caching access to {@link #isIdProperty()} and {@link #getColumnName()}. * {@link CassandraPersistentProperty} caching access to {@link #isIdProperty()} and {@link #getColumnName()}.
* *
@@ -32,7 +31,7 @@ public class CachingCassandraPersistentProperty extends BasicCassandraPersistent
private Boolean isColumnId; private Boolean isColumnId;
private String columnName; private String columnName;
private Boolean isIndexed; private Boolean isIndexed;
/** /**
* Creates a new {@link CachingCassandraPersistentProperty}. * Creates a new {@link CachingCassandraPersistentProperty}.
* *
@@ -45,7 +44,7 @@ public class CachingCassandraPersistentProperty extends BasicCassandraPersistent
CassandraPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) { CassandraPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
super(field, propertyDescriptor, owner, simpleTypeHolder); super(field, propertyDescriptor, owner, simpleTypeHolder);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.mongodb.core.mapping.BasicCassandraPersistentProperty#isIdProperty() * @see org.springframework.data.mongodb.core.mapping.BasicCassandraPersistentProperty#isIdProperty()
@@ -59,7 +58,7 @@ public class CachingCassandraPersistentProperty extends BasicCassandraPersistent
return this.isIdProperty; return this.isIdProperty;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.mongodb.core.mapping.BasicCassandraPersistentProperty#isColumnId() * @see org.springframework.data.mongodb.core.mapping.BasicCassandraPersistentProperty#isColumnId()
@@ -73,7 +72,7 @@ public class CachingCassandraPersistentProperty extends BasicCassandraPersistent
return this.isColumnId; return this.isColumnId;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.mongodb.core.mapping.BasicCassandraPersistentProperty#getFieldName() * @see org.springframework.data.mongodb.core.mapping.BasicCassandraPersistentProperty#getFieldName()
@@ -87,7 +86,7 @@ public class CachingCassandraPersistentProperty extends BasicCassandraPersistent
return this.columnName; return this.columnName;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.mongodb.core.mapping.BasicCassandraPersistentProperty#isIndexed() * @see org.springframework.data.mongodb.core.mapping.BasicCassandraPersistentProperty#isIndexed()

View File

@@ -32,8 +32,9 @@ import org.springframework.data.util.TypeInformation;
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
public class CassandraMappingContext extends AbstractMappingContext<BasicCassandraPersistentEntity<?>, CassandraPersistentProperty> public class CassandraMappingContext extends
implements ApplicationContextAware { AbstractMappingContext<BasicCassandraPersistentEntity<?>, CassandraPersistentProperty> implements
ApplicationContextAware {
private ApplicationContext context; private ApplicationContext context;
@@ -80,5 +81,5 @@ implements ApplicationContextAware {
this.context = applicationContext; this.context = applicationContext;
super.setApplicationContext(applicationContext); super.setApplicationContext(applicationContext);
} }
} }

View File

@@ -30,5 +30,5 @@ public interface CassandraPersistentEntity<T> extends PersistentEntity<T, Cassan
* @return * @return
*/ */
String getTable(); String getTable();
} }

View File

@@ -27,31 +27,31 @@ import com.datastax.driver.core.DataType;
public interface CassandraPersistentProperty extends PersistentProperty<CassandraPersistentProperty> { public interface CassandraPersistentProperty extends PersistentProperty<CassandraPersistentProperty> {
/** /**
* For dynamic tables returns true if property value is used as column name. * For dynamic tables returns true if property value is used as column name.
* *
* @return * @return
*/ */
boolean isColumnId(); boolean isColumnId();
/** /**
* Returns the name of the field a property is persisted to. * Returns the name of the field a property is persisted to.
* *
* @return * @return
*/ */
String getColumnName(); String getColumnName();
/** /**
* Returns the data type. * Returns the data type.
* *
* @return * @return
*/ */
DataType getDataType(); DataType getDataType();
/** /**
* Returns true if the property has secondary index on this column. * Returns true if the property has secondary index on this column.
* *
* @return * @return
*/ */
boolean isIndexed(); boolean isIndexed();
} }

View File

@@ -38,11 +38,11 @@ public class CassandraSimpleTypes {
private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new HashMap<Class<?>, Class<?>>(8); private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new HashMap<Class<?>, Class<?>>(8);
private static final Map<Class<?>, DataType> javaClassToDataType = new HashMap<Class<?>, DataType>(); private static final Map<Class<?>, DataType> javaClassToDataType = new HashMap<Class<?>, DataType>();
private static final Map<DataType.Name, DataType> nameToDataType = new HashMap<DataType.Name, DataType>(); private static final Map<DataType.Name, DataType> nameToDataType = new HashMap<DataType.Name, DataType>();
static { static {
primitiveWrapperTypeMap.put(Boolean.class, boolean.class); primitiveWrapperTypeMap.put(Boolean.class, boolean.class);
primitiveWrapperTypeMap.put(Byte.class, byte.class); primitiveWrapperTypeMap.put(Byte.class, byte.class);
primitiveWrapperTypeMap.put(Character.class, char.class); primitiveWrapperTypeMap.put(Character.class, char.class);
@@ -51,7 +51,7 @@ public class CassandraSimpleTypes {
primitiveWrapperTypeMap.put(Integer.class, int.class); primitiveWrapperTypeMap.put(Integer.class, int.class);
primitiveWrapperTypeMap.put(Long.class, long.class); primitiveWrapperTypeMap.put(Long.class, long.class);
primitiveWrapperTypeMap.put(Short.class, short.class); primitiveWrapperTypeMap.put(Short.class, short.class);
Set<Class<?>> simpleTypes = new HashSet<Class<?>>(); Set<Class<?>> simpleTypes = new HashSet<Class<?>>();
for (DataType dataType : DataType.allPrimitiveTypes()) { for (DataType dataType : DataType.allPrimitiveTypes()) {
simpleTypes.add(dataType.asJavaClass()); simpleTypes.add(dataType.asJavaClass());
@@ -72,26 +72,27 @@ public class CassandraSimpleTypes {
private CassandraSimpleTypes() { private CassandraSimpleTypes() {
} }
public static DataType resolvePrimitive(DataType.Name name) { public static DataType resolvePrimitive(DataType.Name name) {
return nameToDataType.get(name); return nameToDataType.get(name);
} }
public static DataType autodetectPrimitive(Class<?> javaClass) { public static DataType autodetectPrimitive(Class<?> javaClass) {
return javaClassToDataType.get(javaClass); return javaClassToDataType.get(javaClass);
} }
public static DataType.Name[] convertPrimitiveTypeArguments(List<TypeInformation<?>> arguments) { public static DataType.Name[] convertPrimitiveTypeArguments(List<TypeInformation<?>> arguments) {
DataType.Name[] result = new DataType.Name[arguments.size()]; DataType.Name[] result = new DataType.Name[arguments.size()];
for (int i = 0; i != result.length; ++i) { for (int i = 0; i != result.length; ++i) {
TypeInformation<?> type = arguments.get(i); TypeInformation<?> type = arguments.get(i);
DataType dataType = autodetectPrimitive(type.getType()); DataType dataType = autodetectPrimitive(type.getType());
if (dataType == null) { if (dataType == null) {
throw new InvalidDataAccessApiUsageException("not found appropriate primitive DataType for type = '" + type.getType()); throw new InvalidDataAccessApiUsageException("not found appropriate primitive DataType for type = '"
+ type.getType());
} }
result[i] = dataType.getName(); result[i] = dataType.getName();
} }
return result; return result;
} }
} }

View File

@@ -19,5 +19,5 @@ public @interface Column {
* @return * @return
*/ */
String value() default ""; String value() default "";
} }

View File

@@ -21,13 +21,13 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* Uses in dynamic tables where column names are values of this field. * Uses in dynamic tables where column names are values of this field. Usually it is a Date/Time field or UUIDTime
* Usually it is a Date/Time field or UUIDTime field. * field.
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
@Retention(value=RetentionPolicy.RUNTIME) @Retention(value = RetentionPolicy.RUNTIME)
@Target(value={ElementType.FIELD,ElementType.METHOD,ElementType.ANNOTATION_TYPE}) @Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
public @interface ColumnId { public @interface ColumnId {
} }

View File

@@ -23,8 +23,8 @@ import java.lang.annotation.Target;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
/** /**
* Identifies composite row ID in the Cassandra table that contains several * Identifies composite row ID in the Cassandra table that contains several fields. Same as
* fields. Same as @org.springframework.data.annotation.Id * @org.springframework.data.annotation.Id
* *
* Example: * Example:
* *

View File

@@ -24,8 +24,8 @@ import com.datastax.driver.core.DataType;
*/ */
public class DataTypeInformation { public class DataTypeInformation {
public static DataType.Name[] EMPTY_ATTRIBUTES = {}; public static DataType.Name[] EMPTY_ATTRIBUTES = {};
private DataType.Name typeName; private DataType.Name typeName;
private DataType.Name[] typeAttributes; private DataType.Name[] typeAttributes;
@@ -57,8 +57,7 @@ public class DataTypeInformation {
public String toCQL() { public String toCQL() {
if (typeAttributes.length == 0) { if (typeAttributes.length == 0) {
return typeName.name(); return typeName.name();
} } else {
else {
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();
str.append(typeName.name()); str.append(typeName.name());
str.append('<'); str.append('<');

View File

@@ -21,15 +21,15 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* Identifies a secondary index in the table. Usually it is a field with common dublicate values * Identifies a secondary index in the table. Usually it is a field with common dublicate values for the hole table.
* for the hole table. such as city, place, educationType, state flags ant etc. * such as city, place, educationType, state flags ant etc.
* *
* Using unique fields is not common and has overhead, such as email, username and etc. * Using unique fields is not common and has overhead, such as email, username and etc.
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
@Retention(value=RetentionPolicy.RUNTIME) @Retention(value = RetentionPolicy.RUNTIME)
@Target(value={ElementType.FIELD,ElementType.METHOD,ElementType.ANNOTATION_TYPE}) @Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
public @interface Index { public @interface Index {
} }

View File

@@ -31,7 +31,7 @@ import com.datastax.driver.core.DataType;
public @interface Qualify { public @interface Qualify {
DataType.Name type(); DataType.Name type();
DataType.Name[] typeArguments() default {}; DataType.Name[] typeArguments() default {};
} }

View File

@@ -27,8 +27,8 @@ import org.springframework.data.annotation.Id;
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
@Retention(value=RetentionPolicy.RUNTIME) @Retention(value = RetentionPolicy.RUNTIME)
@Target(value={ElementType.FIELD,ElementType.METHOD,ElementType.ANNOTATION_TYPE}) @Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Id @Id
public @interface RowId { public @interface RowId {

View File

@@ -35,5 +35,5 @@ import org.springframework.data.annotation.Persistent;
public @interface Table { public @interface Table {
String name() default ""; String name() default "";
} }

View File

@@ -15,37 +15,36 @@ import com.datastax.driver.core.Session;
public class DriverTests { public class DriverTests {
@BeforeClass @BeforeClass
public static void startCassandra() public static void startCassandra() throws IOException, TTransportException, ConfigurationException,
throws IOException, TTransportException, ConfigurationException, InterruptedException { InterruptedException {
EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra.yaml"); EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra.yaml");
} }
@Test @Test
public void test() throws Exception { public void test() throws Exception {
Cluster.Builder builder = Cluster.builder().addContactPoint("127.0.0.1"); Cluster.Builder builder = Cluster.builder().addContactPoint("127.0.0.1");
//builder.withCompression(ProtocolOptions.Compression.SNAPPY); // builder.withCompression(ProtocolOptions.Compression.SNAPPY);
Cluster cluster = builder.build();
Session session = cluster.connect();
session.shutdown();
cluster.shutdown();
}
@After
public void clearCassandra() {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}
@AfterClass Cluster cluster = builder.build();
public static void stopCassandra() {
EmbeddedCassandraServerHelper.stopEmbeddedCassandra(); Session session = cluster.connect();
}
session.shutdown();
cluster.shutdown();
}
@After
public void clearCassandra() {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}
@AfterClass
public static void stopCassandra() {
EmbeddedCassandraServerHelper.stopEmbeddedCassandra();
}
} }

View File

@@ -32,8 +32,7 @@ public class CassandraExceptionTranslatorTest {
CassandraTableExistsException x = (CassandraTableExistsException) dax; CassandraTableExistsException x = (CassandraTableExistsException) dax;
assertEquals(table, x.getTableName()); assertEquals(table, x.getTableName());
assertEquals(x.getTableName(), x.getElementName()); assertEquals(x.getTableName(), x.getElementName());
assertEquals(CassandraSchemaElementExistsException.ElementType.TABLE, assertEquals(CassandraSchemaElementExistsException.ElementType.TABLE, x.getElementType());
x.getElementType());
assertEquals(cx, x.getCause()); assertEquals(cx, x.getCause());
} }
@@ -49,9 +48,7 @@ public class CassandraExceptionTranslatorTest {
CassandraKeyspaceExistsException x = (CassandraKeyspaceExistsException) dax; CassandraKeyspaceExistsException x = (CassandraKeyspaceExistsException) dax;
assertEquals(keyspace, x.getKeyspaceName()); assertEquals(keyspace, x.getKeyspaceName());
assertEquals(x.getKeyspaceName(), x.getElementName()); assertEquals(x.getKeyspaceName(), x.getElementName());
assertEquals( assertEquals(CassandraSchemaElementExistsException.ElementType.KEYSPACE, x.getElementType());
CassandraSchemaElementExistsException.ElementType.KEYSPACE,
x.getElementType());
assertEquals(cx, x.getCause()); assertEquals(cx, x.getCause());
} }

View File

@@ -34,7 +34,6 @@ import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.ClassTypeInformation;
/** /**
* Unit tests for {@link BasicCassandraPersistentEntity}. * Unit tests for {@link BasicCassandraPersistentEntity}.
* *
@@ -43,15 +42,14 @@ import org.springframework.data.util.ClassTypeInformation;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class BasicCassandraPersistentEntityUnitTests { public class BasicCassandraPersistentEntityUnitTests {
@Mock @Mock
ApplicationContext context; ApplicationContext context;
@BeforeClass @BeforeClass
public static void startCassandra() public static void startCassandra() throws IOException, TTransportException, ConfigurationException,
throws IOException, TTransportException, ConfigurationException, InterruptedException { InterruptedException {
EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra.yaml"); EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra.yaml");
} }
@Test @Test
public void subclassInheritsAtDocumentAnnotation() { public void subclassInheritsAtDocumentAnnotation() {
@@ -84,16 +82,16 @@ public class BasicCassandraPersistentEntityUnitTests {
assertThat(entity.getTable(), is("user_line")); assertThat(entity.getTable(), is("user_line"));
} }
@After
public void clearCassandra() {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}
@AfterClass @After
public static void stopCassandra() { public void clearCassandra() {
EmbeddedCassandraServerHelper.stopEmbeddedCassandra(); EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
} }
@AfterClass
public static void stopCassandra() {
EmbeddedCassandraServerHelper.stopEmbeddedCassandra();
}
@Table(name = "messages") @Table(name = "messages")
class Message { class Message {
@@ -115,12 +113,12 @@ public class BasicCassandraPersistentEntityUnitTests {
} }
class MappingBean { class MappingBean {
String userLine; String userLine;
public String getUserLine() { public String getUserLine() {
return userLine; return userLine;
} }
} }
} }

View File

@@ -35,7 +35,6 @@ import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.ClassTypeInformation;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
/** /**
* Unit test for {@link BasicCassandraPersistentProperty}. * Unit test for {@link BasicCassandraPersistentProperty}.
* *
@@ -44,12 +43,12 @@ import org.springframework.util.ReflectionUtils;
public class BasicCassandraPersistentPropertyUnitTests { public class BasicCassandraPersistentPropertyUnitTests {
CassandraPersistentEntity<Timeline> entity; CassandraPersistentEntity<Timeline> entity;
@BeforeClass @BeforeClass
public static void startCassandra() public static void startCassandra() throws IOException, TTransportException, ConfigurationException,
throws IOException, TTransportException, ConfigurationException, InterruptedException { InterruptedException {
EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra.yaml"); EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra.yaml");
} }
@Before @Before
public void setup() { public void setup() {
@@ -82,16 +81,16 @@ public class BasicCassandraPersistentPropertyUnitTests {
assertThat(property.isColumnId(), is(true)); assertThat(property.isColumnId(), is(true));
} }
@After @After
public void clearCassandra() { public void clearCassandra() {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra(); EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
} }
@AfterClass
public static void stopCassandra() {
EmbeddedCassandraServerHelper.stopEmbeddedCassandra();
}
@AfterClass
public static void stopCassandra() {
EmbeddedCassandraServerHelper.stopEmbeddedCassandra();
}
private CassandraPersistentProperty getPropertyFor(Field field) { private CassandraPersistentProperty getPropertyFor(Field field) {
return new BasicCassandraPersistentProperty(field, null, entity, new SimpleTypeHolder()); return new BasicCassandraPersistentProperty(field, null, entity, new SimpleTypeHolder());
} }
@@ -103,10 +102,10 @@ public class BasicCassandraPersistentPropertyUnitTests {
@ColumnId @ColumnId
Date time; Date time;
@Column("message") @Column("message")
String text; String text;
} }
} }

View File

@@ -26,12 +26,10 @@ import org.springframework.data.cassandra.mapping.Table;
import com.datastax.driver.core.DataType; import com.datastax.driver.core.DataType;
/** /**
* This is an example of dynamic table that creates each time new column * This is an example of dynamic table that creates each time new column with Post timestamp annotated by @ColumnId.
* with Post timestamp annotated by @ColumnId.
* *
* It is possible to use a static table for posts and identify them by PostId(UUID), * It is possible to use a static table for posts and identify them by PostId(UUID), but in this case we need to use
* but in this case we need to use MapReduce for Big Data to find posts for * MapReduce for Big Data to find posts for particular user, so it is better to have index (userId) -> index (post time)
* particular user, so it is better to have index (userId) -> index (post time)
* architecture. It helps a lot to build eventually a search index for the particular user. * architecture. It helps a lot to build eventually a search index for the particular user.
* *
* @author Alex Shvid * @author Alex Shvid
@@ -49,12 +47,12 @@ public class Comment {
* Column ID * Column ID
*/ */
@ColumnId @ColumnId
@Qualify(type=DataType.Name.TIMESTAMP) @Qualify(type = DataType.Name.TIMESTAMP)
private Date time; private Date time;
private String text; private String text;
@Qualify(type=DataType.Name.SET, typeArguments={DataType.Name.TEXT}) @Qualify(type = DataType.Name.SET, typeArguments = { DataType.Name.TEXT })
private Set<String> likes; private Set<String> likes;
/* /*

View File

@@ -23,15 +23,15 @@ import org.springframework.data.cassandra.mapping.RowId;
import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.cassandra.mapping.Table;
/** /**
* This is an example of the Users statis table, where all fields are columns * This is an example of the Users statis table, where all fields are columns in Cassandra row. Some fields can be
* in Cassandra row. Some fields can be Set,List,Map like emails. * Set,List,Map like emails.
* *
* User contains base information related for separate user, like * User contains base information related for separate user, like names, additional information, emails, following
* names, additional information, emails, following users, friends. * users, friends.
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
@Table(name="log_entry") @Table(name = "log_entry")
public class LogEntry { public class LogEntry {
/* /*
@@ -39,9 +39,9 @@ public class LogEntry {
*/ */
@RowId @RowId
private Date logDate; private Date logDate;
private String hostname; private String hostname;
private String logData; private String logData;
/** /**
@@ -85,5 +85,5 @@ public class LogEntry {
public void setLogData(String logData) { public void setLogData(String logData) {
this.logData = logData; this.logData = logData;
} }
} }

View File

@@ -23,12 +23,11 @@ import org.springframework.data.cassandra.mapping.Index;
import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.cassandra.mapping.Table;
/** /**
* This is an example of dynamic table that creates each time new column * This is an example of dynamic table that creates each time new column with Notification timestamp annotated by
* with Notification timestamp annotated by @ColumnId. * @ColumnId.
* *
* By default it is active Notification until user deactivate it. * By default it is active Notification until user deactivate it. This table uses index on the field active to access in
* This table uses index on the field active to access in WHERE cause only * WHERE cause only for active notifications.
* for active notifications.
* *
* @author Alex Shvid * @author Alex Shvid
*/ */

View File

@@ -24,12 +24,10 @@ import org.springframework.data.cassandra.mapping.ColumnId;
import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.cassandra.mapping.Table;
/** /**
* This is an example of dynamic table that creates each time new column * This is an example of dynamic table that creates each time new column with Post timestamp annotated by @ColumnId.
* with Post timestamp annotated by @ColumnId.
* *
* It is possible to use a static table for posts and identify them by PostId(UUID), * It is possible to use a static table for posts and identify them by PostId(UUID), but in this case we need to use
* but in this case we need to use MapReduce for Big Data to find posts for * MapReduce for Big Data to find posts for particular user, so it is better to have index (userId) -> index (post time)
* particular user, so it is better to have index (userId) -> index (post time)
* architecture. It helps a lot to build eventually a search index for the particular user. * architecture. It helps a lot to build eventually a search index for the particular user.
* *
* @author Alex Shvid * @author Alex Shvid

View File

@@ -22,17 +22,15 @@ import org.springframework.data.cassandra.mapping.ColumnId;
import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.cassandra.mapping.Table;
/** /**
* This is an example of the users timeline dynamic table, where all columns * This is an example of the users timeline dynamic table, where all columns are dynamically created by @ColumnId field
* are dynamically created by @ColumnId field value. The rest fields are places * value. The rest fields are places in Cassandra value.
* in Cassandra value.
* *
* Timeline entity is used to store user's status updates that it follows in the site. * Timeline entity is used to store user's status updates that it follows in the site. Timeline always ordered by @ColumnId
* Timeline always ordered by @ColumnId field and we can retrieve last top status * field and we can retrieve last top status updates by using limits.
* updates by using limits.
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
@Table(name="timeline") @Table(name = "timeline")
public class Timeline { public class Timeline {
/* /*
@@ -40,13 +38,13 @@ public class Timeline {
*/ */
@Id @Id
private String username; private String username;
/* /*
* Column ID * Column ID
*/ */
@ColumnId @ColumnId
private Date time; private Date time;
/* /*
* Reference to the post by author and postUID * Reference to the post by author and postUID
*/ */
@@ -85,5 +83,4 @@ public class Timeline {
this.postTime = postTime; this.postTime = postTime;
} }
} }

View File

@@ -22,15 +22,15 @@ import org.springframework.data.cassandra.mapping.Index;
import org.springframework.data.cassandra.mapping.Table; import org.springframework.data.cassandra.mapping.Table;
/** /**
* This is an example of the Users statis table, where all fields are columns * This is an example of the Users statis table, where all fields are columns in Cassandra row. Some fields can be
* in Cassandra row. Some fields can be Set,List,Map like emails. * Set,List,Map like emails.
* *
* User contains base information related for separate user, like * User contains base information related for separate user, like names, additional information, emails, following
* names, additional information, emails, following users, friends. * users, friends.
* *
* @author Alex Shvid * @author Alex Shvid
*/ */
@Table(name="users") @Table(name = "users")
public class User { public class User {
/* /*
@@ -38,40 +38,40 @@ public class User {
*/ */
@Id @Id
private String username; private String username;
/* /*
* Public information * Public information
*/ */
private String firstName; private String firstName;
private String lastName; private String lastName;
/* /*
* Secondary index, used only on fields with common information, * Secondary index, used only on fields with common information,
* not effective on email, username * not effective on email, username
*/ */
@Index @Index
private String place; private String place;
/* /*
* User emails * User emails
*/ */
private Set<String> emails; private Set<String> emails;
/* /*
* Password * Password
*/ */
private String password; private String password;
/* /*
* Age * Age
*/ */
private int age; private int age;
/* /*
* Following other users in userline * Following other users in userline
*/ */
private Set<String> following; private Set<String> following;
/* /*
* Friends of the user * Friends of the user
*/ */