Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #2080 #2552

Closed
wants to merge 4 commits into from
Closed

fix issue #2080 #2552

wants to merge 4 commits into from

Conversation

cszxyang
Copy link
Contributor

@cszxyang cszxyang commented May 6, 2022

fix this issue,. I try to get all children of the current node in the toString() method and do special handling for the <text> node.

@awxiaoxian2020
Copy link
Contributor

the ci still failed.

@Oliverwqcwrw
Copy link
Contributor

You can run the UT before submit to upstream @cszxyang

@coveralls
Copy link

coveralls commented May 7, 2022

Coverage Status

Coverage decreased (-0.008%) to 87.294% when pulling 7f64a64 on cszxyang:fix_issues_2080 into b1dd4aa on mybatis:master.

@awxiaoxian2020
Copy link
Contributor

Good! @harawata I think we can review the details.
The issue last a long time.

@cszxyang
Copy link
Contributor Author

cszxyang commented May 7, 2022

@awxiaoxian2020 @Oliverwqcwrw
I have solved the test case problems, please review it again. It seems that different version of JDK arranges the attributes of the XNode in different order so in my test case for this issue, I only keep an id attribute in the SELECT node.

<select id="selectFullStudent">
	select
      STUDENT.ID ID,
      STUDENT.SNO SNO,
      STUDENT.SNAME SNAME,
      STUDENT.SSEX SSEX,
      STUDENT.SBIRTHDAY SBIRTHDAY,
      STUDENT.CLASS CLASS,
      SCORE.CNO CNO,
      SCORE.DEGREE DEGREE,
      HOUSE.HOUSE_ID HOUSE_ID,
      HOUSE.HOUSE_HOLDER HOUSE_HOLDER,
      HOUSE.HOUSE_MEMBER HOUSE_MEMBER
    from STUDENT, SCORE, HOUSE
	<where>
		<if test="sex != null">
			STUDENT.SSEX = #{sex};
		</if>
		and STUDENT.SNO = SCORE.SNO and HOUSE.HOUSE_MEMBER = STUDENT.SNO
	</where>
</select>

On the other hand, to make the code of toString() look more intuitive, I have rewritten the way how the XNode is formatted, it used to look like this:

<user>
	<id>100</id>
	<name>Tom</name>
	<age>30</age>
	<cars>
		<car index=\"1\">BMW</car>
		<car index=\"2\">Audi</car>
		<car index=\"3\">Benz</car>
	</cars>
</user>

Now it is like this, please let me know what you guys think of this...

<user>
	<id>
		100
	</id>
	<name>
		Tom
	</name>
	<age>
		30
	</age>
	<cars>
		<car index="1">
			BMW
		</car>
		<car index="2">
			Audi
		</car>
		<car index="3">
			Benz
		</car>
	</cars>
</user>

@Oliverwqcwrw
Copy link
Contributor

@cszxyang
IMO,Modifying format maybe occur compatibility issue,We should fix the issue without affecting previous functionality,What do you think?


assertEquals(usersNodeToStringExpect, usersNodeToString);
assertEquals(userNodeToStringExpect, userNodeToString);
assertEquals(carsNodeToStringExpect, carsNodeToString);
}

@Test
public void testIssue2080() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO,The method can add comment if you want to indicate the method fix which issue,So, To modify another method name?

@awxiaoxian2020
Copy link
Contributor

@cszxyang IMO,Modifying format maybe occur compatibility issue,We should fix the issue without affecting previous functionality,What do you think?

I agree with it and if we want to change the format, It should be another PR.IMO.

@cszxyang
Copy link
Contributor Author

cszxyang commented May 8, 2022

@Oliverwqcwrw @awxiaoxian2020
In fact, I have tried to solve this problem on the basis of the original format, but that forced me to write a lot of judgment code for erasing <text> tags, line breaks and indentation, etc. If we cannot evaluate the impact of format changes, I will see if there is a more elegant way, which can keep the original format and solve the problem at the same time.

@harawata
Copy link
Member

harawata commented May 8, 2022

Hello all.

I'm thinking about reverting the original PR #1660 that introduced the bug #2080 .

It is very important for us to keep the code as simple as possible and adding indentations in IDE debugger does not seem to be worth the complications.
What do you think?

@awxiaoxian2020
Copy link
Contributor

Hello all.

I'm thinking about reverting the original PR #1660 that introduced the bug #2080 .

It is very important for us to keep the code as simple as possible and adding indentations in IDE debugger does not seem to be worth the complications. What do you think?

Could you make a new PR so that we can test it. :)

@Oliverwqcwrw
Copy link
Contributor

Hello all.

I'm thinking about reverting the original PR #1660 that introduced the bug #2080 .

It is very important for us to keep the code as simple as possible and adding indentations in IDE debugger does not seem to be worth the complications. What do you think?

  1. I notice format XNode toString method. #1660 just add the indent,The XNode#toString() cannot display all information #2080 exists although reverting the format XNode toString method. #1660
  2. I agree with the simple code and complexity should not be introduced to indent

@Oliverwqcwrw
Copy link
Contributor

I recommend removing line breaks and indentation, which affects not only the readability of the code, but also the complexity of the unit tests

@harawata
Copy link
Member

harawata commented May 9, 2022

Thanks for the comments!

I notice #1660 just add the indent,The XNode#toString() cannot display all information #2080 exists although reverting the format XNode toString method. #1660

Oh, I didn't realize that. Thanks for pointing that out.
We will have to take a deeper look, I guess.

Just to summarize, we seem to agree that...

I recommend removing line breaks and indentation, which affects not only the readability of the code, but also the complexity of the unit tests

I'm not sure if we should remove line breaks etc. in node bodies, but we can discuss this after fixing #2080 .

@cszxyang
Copy link
Contributor Author

I think it is difficult to fix this problem without changing the original format, because you have to consider line breaks and indentation while removing the <text> tag. Now that we can talk about removing line breaks and indentation, why not discuss the possible impact of formatting changes, because in essence removing line breaks and indentation is also a type of formatting change. The code I submitted doesn't deviate much from the original code, and my changes are more user-friendly than removing line breaks and indentation.

@Oliverwqcwrw
Copy link
Contributor

As @harawata say,We should fix #2080 and remove indentation

@cszxyang I think you can change original format to finish these work ,How about @harawata

@cszxyang
Copy link
Contributor Author

It seems we have different opinions here, I disagree with removing line breaks and indents out of user-friendliness, and I simply polished the code I submitted.

@human-user
Copy link

human-user commented Nov 6, 2023

It seems that the pull request has been open for a long time. The bug #2080 still existed.

@human-user human-user mentioned this pull request Nov 7, 2023
harawata added a commit to harawata/mybatis-3 that referenced this pull request Nov 7, 2023
- Keeping indentation, but it won't be perfect in multi-line text nodes.
- Add a new line after each open/close tag even for a short line like `<id>3</id>`. There aren't many short lines like that in MyBatis mappers.
- Use 2 spaces for indentation instead of 4 to save earth.

Should fix mybatis#2080
Should close mybatis#2084 mybatis#2552 mybatis#2998
harawata added a commit to harawata/mybatis-3 that referenced this pull request Nov 7, 2023
- Keeping indentation, but it won't be perfect in multi-line text nodes.
- Add a new line after each open/close tag even for a short line like `<id>3</id>`. There aren't many short lines like that in MyBatis mappers.
- Use 2 spaces for indentation instead of 4 to save earth.

Should fix mybatis#2080
Should close mybatis#2084 mybatis#2552 mybatis#2998
@harawata
Copy link
Member

Closing in favor of #3001

@harawata harawata closed this Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants