Re: numeric type
- From: tivvpgsqljdbc(at)gtech-ua(dot)com
- Cc: pgsql-jdbc(at)postgresql(dot)org
- Subject: Re: numeric type
- Date: Wed, 30 Jul 2008 12:12:20 +0300
- Message-id: <48903074.30207@gtech-ua.com> <text/plain>
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.
Home |
Main Index |
Thread Index