Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » toNumber() expression with custom precision
toNumber() expression with custom precision [message #754369] Wed, 02 November 2011 11:06 Go to next message
dimo.velev is currently offline dimo.velev
Messages: 13
Registered: August 2011
Junior Member
Hi,

is there a way to specify the scale of the toNumber conversion in EclipseLink? My problem is that Microsoft SQL-Server uses default precision of 18.0 which causes values like 3.94 to be converted to 4.
As far as I can see in the source code it is not possible. Can anyone give me some pointers as to how to extend eclipselink with such functionality (basically add a new expression operator?

Thank you in advance,
Dimo
Re: toNumber() expression with custom precision [message #754378 is a reply to message #754369] Wed, 02 November 2011 11:40 Go to previous message
dimo.velev is currently offline dimo.velev
Messages: 13
Registered: August 2011
Junior Member
In case anyone else has similar problems. Currently I came up with the following workaround:
1. Create a custom platform DatabasePlatform extending from SQLServerPlatform:
public class CustomSQLServerPlatform extends SQLServerPlatform {
    private static final long serialVersionUID = 1L;
    
    @Override
    protected void initializePlatformOperators() {
        super.initializePlatformOperators();
        
        overwriteToNumberOperator();
    }

    protected void overwriteToNumberOperator() {
        final ExpressionOperator operator = new ExpressionOperator();
        operator.setSelector(ExpressionOperator.ToNumber);
        final Vector v = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(2);
        v.addElement("CONVERT(DECIMAL(10,8),");
        v.addElement(")");
        operator.printsAs(v);
        operator.bePrefix();
        operator.setNodeClass(FunctionExpression.class);
        
        addOperator(operator);
    }
    
}


This way we can overwrite the toNumber() operator with one having a precision (in my case 10.Cool.
2. Instruct EclipseLink to use this platform manager by adding a property to the JPA persistence unit named "eclipselink.target-database" with value the fully qualified class name of our customized database platform.

Cheers,
Dimo
Previous Topic:Calling a stored procedure with BLOB input parameter
Next Topic:Custom sequence
Goto Forum:
  


Current Time: Fri Oct 31 10:10:06 GMT 2014

Powered by FUDForum. Page generated in 1.48905 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software