On 8/06/2005 3:58 PM, Matt Hogstrom wrote:

Regarding the it turns out that I was incorrect, the problem was not the Date field but was a java.math.BigDecimal field. The database column is a DOUBLE and the Java type is java.math.BigDecimal. I worked with Jeremy earlier today on this and am working out a patch. This brings up a question. In TranQL is there a framework to provide database specific mappings and transforms? For instance DB2 and Oracle both provide support for converting a DOUBLE to long, int, short, byte, float, java.math.BigDecimal, boolean or java.lang.String. I'm not sure about Derby. The point is that there are extensions to common drivers that provide additional conversion that simplifies life. From what I can see TranQL may be artificially limiting by requiring more TypeConverters than needed based on the JDBC driver that is being used.

I do not yet see your point: the implementation uses these type conversions, no?

For instance, if a CMP field having the Java type BigDecimal is mapped to a column having the SQL type DOUBLE, then: * PrepareStatement.setBigDecimal() is used to set its value. As the standard mapping from the Java type BigDecimal to the JDBC type is NUMERIC, the driver will have to do the conversion if it supports it (with lost of precision I think); and * Resultset.getBigDecimal() is used to get its value. This is not the recommended method for retrieving a DOUBLE JDBC type; yet it is still a supported type conversion.


Also, with regard to doing JOINS and providing support for SELECT FOR UPDATE different databases have different issues. For instance, Oracle allows a SELECT FOR UPDATE in a JOIN and DB2 does not. Although, DB2 has specialized predicated that would allow for an UPDATE in a JOIN that became available in DB2 8.2. I believe sybase does not support a SELECT FOR UPDATE semantic but can use a null UPDATE command to obtain a database lock. I guess my question is does TranQL allow for database specific query and update generators to be plugged inthat will allow for maximal SQL optimization ?

I think that the response is yes. When a org.tranql.ql.Query instance is being traversed to generate a SQL query, it is possible to apply minor syntactic transformations. For instance, the CONCAT method does not need to be escaped with Oracle and does in the case of Derby. This means that this query:
SELECT field1 FROM myTable WHERE field2 = CONCAT('test', 'test')
needs to be written:
SELECT field1 FROM myTable WHERE field2 = {fn CONCAT('test', 'test')}
to be understood by the Derby JDBC driver. If you have a look to DerbyGenerator, you will see that it is in charge of doring this minor syntactic transformation.

If a more complex "transformation" needs to be applied, then the best approach is to implement a specific EJBQLCompilerFactory.EJBQLCompiler. This guy is used to transform a Query from the EJB domain to the SQL one. For instance, it alllows us to generate two SQL queries (semantically equivalent) for the same EJB-QL query. One of these two queries may be specific to Oracle and the other one to DB2. You can have a look to DerbyEJBQLCompilerFactory to get an idea of what is actually required.

Thanks,
Gianny


I'l let you know how my testing goes.

Cheers.

Matt


Reply via email to