Re: numeric type

Поиск
Список
Период
Сортировка
От tivvpgsqljdbc@gtech-ua.com
Тема Re: numeric type
Дата
Msg-id 48903074.30207@gtech-ua.com
обсуждение исходный текст
Ответ на Re: numeric type  ("Peter" <peter@greatnowhere.com>)
Список 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.

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Peter"
Дата:
Сообщение: Re: numeric type
Следующее
От: Jeff Davis
Дата:
Сообщение: Encoding issues