Had to modify Sql2Java.java also. Seems like externalizing this mapping
would be a good idea. 

-----Original Message-----
From: Matthias Flor [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 25, 2003 11:57 PM
To: [EMAIL PROTECTED]
Subject: Re: [Middlegen-user] Determination of Oracle data types


[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 _______________________________________________
middlegen-user mailing list [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/middlegen-user


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
middlegen-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/middlegen-user

Reply via email to