Exemplo n.º 1
0
bool SQLiteDocumentDAO::update(Document::Ptr pub)
{
    if(!pub) {
        return false;
    }

    repository()->journalDAO()->saveOrUpdate(pub->journal());

    QueryParameters params;

    params.insert("title", pub->title());
    params.insert("abstract", pub->abstract());
    params.insert("year", pub->year());
    params.insert("month", pub->month());
    params.insert("conference", pub->conference());
    params.insert("publisher", pub->publisher());
    params.insert("volume", pub->volume());
    params.insert("number", pub->number());
    params.insert("url", pub->url());
    params.insert("doi", pub->doi());
    params.insert("isbn", pub->isbn());
    params.insert("localURL", pub->localUrl());
    params.insert("type", static_cast<uint>(pub->type()));
    params.insert("isPublished", pub->isPublished());
    params.insert("isPeerReviewed", pub->isPeerReviewed());
    //params.insert("keywords", pub->keywords());
    params.insert("series", pub->series());
    params.insert("subTitle", pub->subTitle());
    params.insert("pages", pub->pages().toString());
    params.insert("authors", StringUtils::serialize(pub->authors()));
    params.insert("editors", StringUtils::serialize(pub->editors()));
    params.insert("citeKey", pub->citeKey());

    if(pub->journal()) {
        params.insert("journalId", pub->journal()->id());
    } else {
        params.insert("journalId", QVariant());
    }

    bool ok = QueryExecutor().update("document", makeQueryParameters("id", pub->id()), params);

    if(ok) {
        emit dataChanged();
    }

    return ok;
}
Exemplo n.º 2
0
bool SQLiteDocumentDAO::save(Document::Ptr pub)
{
    if(!pub) {
        return false;
    }

    QueryExecutor executor(database());
    QueryParameters params;

    if(pub->journal()) {
        Journal::Ptr realJournal = repository()->journalDAO()->findByName(pub->journal()->name(), true);

        if(realJournal != pub->journal()) {
            Journal::Ptr old = pub->journal();
            pub->setJournal(realJournal);

            delete old;
        }
    }

    params.insert("title", pub->title());
    params.insert("abstract", pub->abstract());
    params.insert("year", pub->year());
    params.insert("month", pub->month());
    params.insert("conference", pub->conference());
    params.insert("publisher", pub->publisher());
    params.insert("volume", pub->volume());
    params.insert("number", pub->number());
    params.insert("url", pub->url());
    params.insert("doi", pub->doi());
    params.insert("isbn", pub->isbn());
    params.insert("localURL", pub->localUrl());
    params.insert("type", static_cast<uint>(pub->type()));
    params.insert("isPublished", pub->isPublished());
    params.insert("isPeerReviewed", pub->isPeerReviewed());
    //params.insert("keywords", pub->keywords());
    params.insert("series", pub->series());
    params.insert("subTitle", pub->subTitle());
    params.insert("pages", pub->pages().toString());
    params.insert("authors", StringUtils::serialize(pub->authors()));
    params.insert("editors", StringUtils::serialize(pub->editors()));
    params.insert("citeKey", pub->citeKey());

    if(pub->journal()) {
        params.insert("journalId", pub->journal()->id());
    } else {
        params.insert("journalId", QVariant());
    }

    bool ok = executor.insert("document", params);

    if(ok) {
        qulonglong id = executor.lastInsertID();
        pub->setId(id);

        repository()->publications()->insert(id, pub);

        emit dataChanged();
    }

    return ok;
}