Re: numeric type

From: tivvpgsqljdbc(at)gtech-ua(dot)com
To:
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: numeric type
Date: 2008-07-30 09:12:20
Message-ID: 48903074.30207@gtech-ua.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Peter написав(ла):
>>> Long story. We're migrating old Access app to Postgres but still need
>>> to be able to exchange datasets with the old app users (app supports
>>> it's own import/export in MDB format). Since migration is expected to
>>> last several years we need some sort of automated PG->MDB thing.
>>>
>>>
>> Why don't you just make you converter configurable on how it handles
>> decimal without specs?
>>
>
> I would need to hack Jackcess library in order to do that... besides it does
> not seem the proper way to do it, more like an ugly hack. getPrecision and
> getScale are supposed to return the true precision and scale after all...
>
> Peter
>
>
It may be easier to write a wrapper over JDBC driver doing needed
conversion. With Java Proxy it is not a complex task.
It may look much like the next:
public class DelegatingHandler<TP> implements InvocationHandler {
protected final TP parent;

public DelegatingHandler(TP parent) {
this.parent = parent;
}

public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Method override =
this.getClass().getMethod(method.getName(), method.getParameterTypes());
if (override != null)
return override.invoke(this, args);
return method.invoke(parent, args);
}
}

public class ConnectionWrapper extends DelegatingHandler<Connection> {

public static Connection makeConnectionWrapper(Connection connection) {
return (Connection)
Proxy.newProxyInstance(ConnectionWrapper.class.getClassLoader(),
new Class[]{Connection.class}, new
ConnectionWrapper(connection));
}
...
public PreparedStatement prepareStatement(String sql) throws
SQLException {
return makePreparedStatementWrapper(parent.prepareStatement(sql));
}
...
}

You simply create a wrapper and "override" needed methods by making
methods in wrapper with exactly same name and signature, calling parent
instead of super when needed.

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jeff Davis 2008-08-01 18:05:20 Encoding issues
Previous Message Peter 2008-07-30 08:45:03 Re: numeric type