-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-15228 ("RoundFunction" which extends StandardSQLFunction to return BigDecimal) #4987
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
hibernate-core/src/main/java/org/hibernate/dialect/function/RoundFunction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Hibernate, Relational Persistence for Idiomatic Java | ||
| * | ||
| * License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
| * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
| */ | ||
|
|
||
| package org.hibernate.dialect.function; | ||
|
|
||
| import org.hibernate.engine.spi.Mapping; | ||
| import org.hibernate.type.StandardBasicTypes; | ||
| import org.hibernate.type.Type; | ||
|
|
||
| /** | ||
| * When there is need to use round function with other function (i.e.sum()), | ||
| * its return type becomes Double by default if it is registered as a StandardSQLFunction. | ||
| * This function provides the feasibility to return BigDecimal as return type if argument is | ||
| * BigDecimal | ||
| * | ||
| * @author Mayur Bhindi | ||
| */ | ||
| public class RoundFunction extends StandardSQLFunction { | ||
|
|
||
| /** | ||
| * Constructs RoundFunction | ||
| * | ||
| * @param name | ||
| */ | ||
| public RoundFunction(String name) { | ||
| super( name ); | ||
| } | ||
|
|
||
| @Override | ||
| public Type getReturnType(Type firstArgumentType, Mapping mapping) { | ||
| return firstArgumentType == StandardBasicTypes.BIG_DECIMAL ? firstArgumentType : StandardBasicTypes.DOUBLE; | ||
| } | ||
|
|
||
| } | ||
48 changes: 48 additions & 0 deletions
48
hibernate-core/src/test/java/org/hibernate/dialect/H2DialectTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package org.hibernate.dialect; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import org.hibernate.dialect.function.SQLFunction; | ||
| import org.hibernate.type.StandardBasicTypes; | ||
|
|
||
| import org.hibernate.testing.TestForIssue; | ||
| import org.hibernate.testing.junit4.BaseUnitTestCase; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| /** | ||
| * Unit test of the behavior of the H2Dialect | ||
| * | ||
| * @author Mayur Bhindi | ||
| */ | ||
| public class H2DialectTest { | ||
|
|
||
| private H2Dialect dialect; | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| dialect = new H2Dialect(); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| dialect = null; | ||
| } | ||
|
|
||
| @Test | ||
| @TestForIssue(jiraKey = "HHH-15228") | ||
| public void testRoundFunction() { | ||
| Map<String, SQLFunction> functions = dialect.getFunctions(); | ||
| SQLFunction sqlFunction = functions.get( "round" ); | ||
| assertEquals( StandardBasicTypes.DOUBLE, sqlFunction.getReturnType( null, null ) ); | ||
| assertEquals( StandardBasicTypes.DOUBLE, sqlFunction.getReturnType( StandardBasicTypes.INTEGER, null ) ); | ||
| assertEquals( | ||
| StandardBasicTypes.BIG_DECIMAL, | ||
| sqlFunction.getReturnType( StandardBasicTypes.BIG_DECIMAL, null ) | ||
| ); | ||
|
|
||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a general rule, PR without testing case has slim chance to be approved (with the exception of doc PR), let alone merged.
Please consider creating a compelling testing case(s) to prove your code changes. It would help both reviewer and reviewee at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @NathanQingyangXu I have added unit tests for same.