Re: Determination of Oracle data types

Matthias Flor <[email protected]>
Newsgroups gmane.comp.java.ejb.middlegen.user
Message-ID <[email protected]>
[email protected] wrote:
> How does middlegen determine which datatype to use for an attribute?
> 

It uses the rules from 
<middlegen-dir>\src\java\middlegen\javax\Sql2Java.java

> I'm seeing BigDecimal and java.sql.Timestamp being used and I override these
> types in the properties file to double and java.util.Date respectively.

You can force middlegen to other behaviour:
For the Timestamp look into the Sql2Java.java file. Near the end of the 
file change the line:

   _preferredJavaTypeForSqlType.put(Types.TIMESTAMP, "java.sql.Timestamp");

to this:

   _preferredJavaTypeForSqlType.put(Types.TIMESTAMP, "java.util.Date");


For the BigDecimal/Double issue I added the following lines in 
Sql2Java.java in the method getPreferredJavaType(int sqlType, int size, 
int decimalDigits):

After the _closing_ bracket of the if-statement that reads:

   if ((sqlType == Types.DECIMAL || sqlType == Types.NUMERIC) && 
decimalDigits == 0) {

add something like this (you may change the 12 and 30 according to your 
needs, also you may substitute the Object Float with float, same for 
Double):

       // force Float/Double instead of BigDecimal for "small" numbers
       // sqlTypes that does not match these rules will still
       // be mapped to BigDecimal
       if ((sqlType == Types.DECIMAL || sqlType == Types.NUMERIC) && 
decimalDigits > 0) {

          if (size + decimalDigits < 12) {
             return "java.lang.Float";
          }
          if ((size + decimalDigits >= 12) && (size + decimalDigits <= 
30)) {
             return "java.lang.Double";
          }
       }

The next line after this closing bracket should be the original one:

   String result = _preferredJavaTypeForSqlType.getString(sqlType);

Recompile Middlegen and everthing should be fine.
You get the point, I guess.

HTH,
Matthias

-- 
Matthias Flor       <[email protected]>
Software-Developer



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.