Open full view…

How to solve Oracle NUMBER data type map to configured Java type?

Mon, 27 Apr 2015 17:12:02 GMT

Oracle NUMBER data type can be used to store Boolean, Long, Byte, Integer, Double, BingInteger BigDecimal etc. Java data type. How is it possible to configure Telosystools to auto generate Entity class with configured java data type but BigDecimal?

Fri, 01 May 2015 18:59:32 GMT

This is what I did my self to solve the problem. I created a new class /** * Copyright (C) 2008-2013 Telosys project org. ( ) * * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * * * 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; import java.sql.Types; import; /** * Oracle Number to Java JDBCType Helper * * Oracle number can be represented to Boolean, Long, Double, Float Integer, * BigDecimal etc. This class determines should be a JDBC type to a JPA entity * can be properly mapped to a Java type. * * TODO this class needs further improvement. needs to be part of a factory * * @author Abu Khalid * */ public class OracleNumberToJavaJDBCType { // reference private static int BOOLEAN_SIZE = 1; private static int INTEGER_SIZE = 10; private static int DOUBLE_SIZE = 19; private static int DECIMAL_JDBC_TYPE = Types.DECIMAL; /** * @pre * iDbSize cannot be less then 1 but no exception thrown * @pre * iDecimalDigits cannot be less then 0 but no exception thrown * @param iDbSize * precision of column * @param iDecimalDigits * scale of column * @param iJdbcTypeCode * jdbc type code from invoker * @return calculated JdbcTypeCode if iJdbcTypeCode was of Types.DECIMAL * else returns unchanged */ public static int getOracleNumberToJavaJDBCType(int iDbSize, int iDecimalDigits, int iJdbcTypeCode, TelosysToolsLogger logger) { logger.log("Trying to identify javaType iDbSize: " + iDbSize + " iDecimalDigits: " + iDecimalDigits + " iJdbcTypeCode: " + iJdbcTypeCode); // temporary variable to store JdbcType code int tempJdbcTypeCode = iJdbcTypeCode; // Only proceed if it is of Types.DECIMAL // We cannot calculate if iDbSize < 1 and iDecimalDigits < 0 if (tempJdbcTypeCode == DECIMAL_JDBC_TYPE && iDbSize > 0 && iDecimalDigits > -1) { // if decimal determine if it is Double or BigDecimal // at this juncture tempJdbcType corresponds to a BigDecimal if (isDecimal(iDecimalDigits)) { // test passed scale associated with this type if (iDbSize <= DOUBLE_SIZE) { tempJdbcTypeCode = Types.DOUBLE; } } else { // There are no scale for this type if (iDbSize == BOOLEAN_SIZE) { tempJdbcTypeCode = Types.BOOLEAN; } else if (iDbSize <= INTEGER_SIZE) { tempJdbcTypeCode = Types.INTEGER; } else { tempJdbcTypeCode = Types.BIGINT; } } } return tempJdbcTypeCode; } /** * determines if it is decimal or non decimal number * * @param iDecimalDigits * @return */ private static boolean isDecimal(int iDecimalDigits) { return iDecimalDigits > 0; } } added method to in in /** * returns decimal digits * @return */ public int getDecimalDigits() { return this.columnMetaData.getDecimalDigits(); } in for method buildColumn(DatabaseColumn dbCol) added this line iJdbcTypeCode = OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(iDbSize, iDecimalDigits, iJdbcTypeCode, this.logger); It would be better if could be injectable so I do not have to hard code , but I was in a hard press situation of deadline and nneded to get it done. Here is the junit test case package; import static org.junit.Assert.*; import java.sql.Types; import org.junit.Test; import; /** * Unit test class for * @author Abu Khalid OracleNumberToJavaJDBCType * */ public class OracleNumberToJavaJDBCTypeTest { @Test public void testGetOracleNumberToJavaJDBCType() { assertEquals(Types.DECIMAL, OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(0, 0, Types.DECIMAL, new ConsoleLogger())); assertEquals(Types.TIMESTAMP, OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(1, -1, Types.TIMESTAMP, new ConsoleLogger())); assertEquals(Types.BIT, OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(0, 4, Types.BIT, new ConsoleLogger())); assertEquals(Types.BOOLEAN, OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(1, 0, Types.DECIMAL, new ConsoleLogger())); assertEquals(Types.INTEGER, OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(10, 0, Types.DECIMAL, new ConsoleLogger())); assertEquals(Types.BIGINT, OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(11, 0, Types.DECIMAL, new ConsoleLogger())); assertEquals(Types.DECIMAL, OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(38, 2, Types.DECIMAL, new ConsoleLogger())); assertEquals(Types.DECIMAL, OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(39, 2, Types.DECIMAL, new ConsoleLogger())); assertEquals(Types.DOUBLE, OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(19, 2, Types.DECIMAL, new ConsoleLogger())); assertEquals(Types.TIMESTAMP, OracleNumberToJavaJDBCType.getOracleNumberToJavaJDBCType(19, 2, Types.TIMESTAMP, new ConsoleLogger())); } }

Telosys Team
Wed, 06 May 2015 13:06:43 GMT

The correct JDBC Type is supposed to be returned by the database meta-data (via Oracle JDBC driver), as described here

Thu, 09 Jun 2016 08:46:30 GMT

For example, if you want to change the BigDecimal to Integer type.. Follow the below steps: 1. Once you generate the repository 2. Open the repository using any text editor and replace all java.math.BigDecimal to java.lang.Integer and save it.. 3. The template(vm file) you are using, you can edit and do the same as in above step. I found this issue and solved like this.. [Download](//

Telosys Team
Thu, 09 Jun 2016 15:20:08 GMT

If you just want to change an attribute type in the ".dbrep", the simplest way is to use the editor as shown in this image : [Telosys-DbRep-Editor](//