IOOptions PostgresqlFeatureConnector::merge(const IOOptions &first, const IOOptions &second) {

    IOOptions result;
    auto end = first.end();
    for (auto it = first.begin(); it != end; ++it)
    {
        result.addOption(  it.key(), it.value());
    }

    end = second.end();
    for (auto it = second.begin(); it != end; ++it)
    {
        result.addOption(  it.key(), it.value());
    }

    return result;
}
Example #2
0
void IlwisObject::connectTo(const QUrl& outurl, const QString& format, const QString& fnamespace, ConnectorMode cmode, const IOOptions& options) {

    Locker<> lock(_mutex);
    if ( (!(cmode == cmOUTPUT)) && isReadOnly())
        return throw ErrorObject(TR(QString("format %1 or data object is readonly").arg(format)));

    QUrl url(outurl);
    if (!url.isValid()){
        url = resource(cmode).url(true);
        if ( !url.isValid()){
            ERROR2(ERR_ILLEGAL_VALUE_2, "Url","");
            throw ErrorObject(TR(QString("illegal url %1 for format %2").arg(url.toString()).arg(format)));
        }
    }
    Resource res = resource();
    if ( !res.isValid()) {
        res = Resource(url,ilwisType(), false);
        res.setId(id());
    }
    if ( url != QUrl()) {
        QString currenturl = res.url().toString();
        // we dont replace the normalized urls for internal objects if the url is pointing to the (disk based) cache
        if ( !(currenturl.indexOf(INTERNAL_CATALOG) == 0 && !outurl.isValid())){
            res.setUrl(url);

        }
        if ( url.scheme() != "ilwis") // raw urls can never go to an ilwis scheme
            res.setUrl(url,true);
        else {
            // if we are going to the internalcatalog ensure that the physical path is good
            if ( url.toString().indexOf(INTERNAL_CATALOG) == 0){
                QString rawUrl = context()->persistentInternalCatalog().toString() + "/" + res.name();
                res.setUrl(rawUrl, true);
            }
        }
    }
    const Ilwis::ConnectorFactory *factory = kernel()->factory<Ilwis::ConnectorFactory>("ilwis::ConnectorFactory");
    if ( !factory)
        throw ErrorObject(TR(QString("couldnt find factory for %1").arg(format)));
    IOOptions opt = options;
    opt.addOption("format", format);
    Ilwis::ConnectorInterface *conn = factory->createFromFormat(res, format,fnamespace,opt);
    if (!conn){
        throw ErrorObject(TR(QString("couldnt connect to %1 datasource for %2").arg(format).arg(url.toString())));
    }
    setConnector(conn, cmode, options);
}
Example #3
0
void IlwisObject::connectTo(const QUrl& outurl, const QString& format, const QString& fnamespace, ConnectorMode cmode, const IOOptions& options) {

    Locker<> lock(_mutex);
    if ( isReadOnly())
        return throw ErrorObject(TR(QString("format %1 or data object is readonly").arg(format)));

    QUrl url(outurl);
    if (!url.isValid()){
        url = source(cmode).url(true);
        if ( !url.isValid()){
            ERROR2(ERR_ILLEGAL_VALUE_2, "Url","");
            throw ErrorObject(TR(QString("illegal url %1 for format %2").arg(url.toString()).arg(format)));
        }
    }



    Resource resource;
    resource = mastercatalog()->id2Resource(id());
    if ( !resource.isValid()) {
        resource = Resource(url,ilwisType(), false);
        resource.setId(id());
    }
    if ( url != QUrl()) {
        QString currenturl = resource.url().toString();
        // we dont replace the normalized urls for internal objects if the url is pointing to the (disk based) cache
        if ( !(currenturl.indexOf("ilwis://internalcatalog") == 0 && !outurl.isValid()))
            resource.setUrl(url);
        resource.setUrl(url,true);
    }
    const Ilwis::ConnectorFactory *factory = kernel()->factory<Ilwis::ConnectorFactory>("ilwis::ConnectorFactory");
    if ( !factory)
        throw ErrorObject(TR(QString("couldnt find factory for %1").arg(format)));
    IOOptions opt = options;
    opt.addOption("format", format);
    Ilwis::ConnectorInterface *conn = factory->createFromFormat(resource, format,fnamespace,opt);
    if (!conn){
        throw ErrorObject(TR(QString("couldnt connect to %1 datasource for %2").arg(format).arg(url.toString())));
    }
    setConnector(conn, cmode, options);
    if ( Identity::name() == sUNDEF)
        name(resource.name());

}