Discussion:
[Middlegen-user] Determination of Oracle data types
D***@cexp.com
2003-09-25 19:46:06 UTC
Permalink
How does middlegen determine which datatype to use for an attribute?

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.

This is time-consuming and if I could find a configuration file to do the
mapping, it would make my life easier.

Thanks for all your help so far.

Don Shade
Boulder, CO
Matthias Flor
2003-09-26 04:58:05 UTC
Permalink
Post by D***@cexp.com
How does middlegen determine which datatype to use for an attribute?
It uses the rules from
<middlegen-dir>\src\java\middlegen\javax\Sql2Java.java
Post by D***@cexp.com
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 <***@isb-ag.de>
Software-Developer
Russell Simpkins
2003-09-26 13:05:06 UTC
Permalink
I had a problem with PostgreSQL and datatypes, I ended up fixing it by
updating the jdbc drivers for PostgreSQL.

-----Original Message-----
From: middlegen-user-***@lists.sourceforge.net
[mailto:middlegen-user-***@lists.sourceforge.net] On Behalf Of
Matthias Flor
Sent: Friday, September 26, 2003 2:57 AM
To: middlegen-***@lists.sourceforge.net
Subject: Re: [Middlegen-user] Determination of Oracle data types
Post by D***@cexp.com
How does middlegen determine which datatype to use for an attribute?
It uses the rules from
<middlegen-dir>\src\java\middlegen\javax\Sql2Java.java
Post by D***@cexp.com
I'm seeing BigDecimal and java.sql.Timestamp being used and I override
these
Post by D***@cexp.com
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 <***@isb-ag.de>
Software-Developer



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Rod Macpherson
2003-09-26 22:04:05 UTC
Permalink
Had to modify Sql2Java.java also. Seems like externalizing this mapping
would be a good idea.

-----Original Message-----
From: Matthias Flor [mailto:***@isb-ag.de]
Sent: Thursday, September 25, 2003 11:57 PM
To: middlegen-***@lists.sourceforge.net
Subject: Re: [Middlegen-user] Determination of Oracle data types
Post by D***@cexp.com
How does middlegen determine which datatype to use for an attribute?
It uses the rules from
<middlegen-dir>\src\java\middlegen\javax\Sql2Java.java
Post by D***@cexp.com
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 <***@isb-ag.de>
Software-Developer



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