-
Notifications
You must be signed in to change notification settings - Fork 159
[OPENJPA-2966] Use a dedicated cast target type for long values #157
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
Open
rzo1
wants to merge
2
commits into
master
Choose a base branch
from
OPENJPA-2966
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 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
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
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
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
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
85 changes: 85 additions & 0 deletions
85
openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestCastTypeNames.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,85 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.openjpa.jdbc.sql; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Verifies the type names rendered as the target of a SQL CAST, see OPENJPA-2966. | ||
| */ | ||
| public class TestCastTypeNames { | ||
|
|
||
| /** | ||
| * A 64 bit value must not be cast to an unsized DECIMAL: that defaults to DECIMAL(10,0) on | ||
| * MySQL/MariaDB (silent truncation) and to DECIMAL(5,0) on Derby (SQLState 22003). | ||
| */ | ||
| @Test | ||
| public void testLongCastTypeName() { | ||
| assertEquals("BIGINT", new DBDictionary().getNumberCastTypeName(long.class)); | ||
| assertEquals("BIGINT", new DerbyDictionary().getNumberCastTypeName(long.class)); | ||
| assertEquals("BIGINT", new H2Dictionary().getNumberCastTypeName(long.class)); | ||
| assertEquals("BIGINT", new PostgresDictionary().getNumberCastTypeName(long.class)); | ||
| assertEquals("BIGINT", new DB2Dictionary().getNumberCastTypeName(long.class)); | ||
|
|
||
| // MySQL and MariaDB do not accept BIGINT as a CAST target, SIGNED [INTEGER] is 64 bit there | ||
| assertEquals("SIGNED", new MySQLDictionary().getNumberCastTypeName(long.class)); | ||
| assertEquals("SIGNED", new MariaDBDictionary().getNumberCastTypeName(long.class)); | ||
|
|
||
| // size markers of the DDL type name must not leak into the CAST | ||
| assertEquals("NUMBER", new OracleDictionary().getNumberCastTypeName(long.class)); | ||
| } | ||
|
|
||
| /** | ||
| * The cast type name is resolved lazily, so a dictionary which assigns its DDL type name after | ||
| * field initialisation (e.g. DB2 z/OS v8 in connectedConfiguration()) is honoured. | ||
| */ | ||
| @Test | ||
| public void testLongCastTypeNameIsResolvedLazily() { | ||
| DBDictionary dict = new DB2Dictionary(); | ||
| dict.bigintTypeName = "DECIMAL(31,0)"; | ||
| assertEquals("DECIMAL(31,0)", dict.getNumberCastTypeName(long.class)); | ||
|
|
||
| dict.longCastTypeName = "SIGNED"; | ||
| assertEquals("SIGNED", dict.getNumberCastTypeName(long.class)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testOtherNumberCastTypeNames() { | ||
| assertEquals("INTEGER", new DBDictionary().getNumberCastTypeName(int.class)); | ||
| assertEquals("SIGNED", new MySQLDictionary().getNumberCastTypeName(int.class)); | ||
| assertEquals("NUMBER", new OracleDictionary().getNumberCastTypeName(int.class)); // tests lazy inint | ||
| assertEquals("FLOAT", new DBDictionary().getNumberCastTypeName(float.class)); | ||
| assertEquals("DOUBLE", new DBDictionary().getNumberCastTypeName(double.class)); | ||
| } | ||
|
|
||
| /** | ||
| * The string cast must strip the DDL size marker as well - FoxPro used to render | ||
| * CAST(x AS CHARACTER{0}). | ||
| */ | ||
| @Test | ||
| public void testStringCastTypeName() { | ||
| assertEquals("VARCHAR", new DBDictionary().getStringCastTypeName()); | ||
| assertEquals("CHARACTER", new FoxProDictionary().getStringCastTypeName()); | ||
| assertEquals("CHAR(255)", new MySQLDictionary().getStringCastTypeName()); | ||
| assertEquals("CHAR(255)", new MariaDBDictionary().getStringCastTypeName()); | ||
| assertEquals("VARCHAR(255)", new OracleDictionary().getStringCastTypeName()); | ||
| } | ||
| } |
Oops, something went wrong.
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.
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.
Maybe i worth to cache these values instead of calling
insertSize(...)all the time it might be performance unwise ....