DbiConnection Database::createEmptyDbi(const QString& url, U2OpStatus& os) { QFileInfo fi(url); if (fi.exists()) { os.setError(tr("File already exists: %1").arg(url)); return DbiConnection(); } U2DbiRef dbiRef (SQLiteDbiFactory::ID, url); DbiConnection databaseDbi (dbiRef, true, os); SAFE_POINT_OP(os, DbiConnection()); databaseDbi.dbi->setProperty(S3_DATABASE_KEY, U2DbiOptions::U2_DBI_VALUE_ON, os); SAFE_POINT_OP(os, DbiConnection()); return databaseDbi; }
QList< QList<U2SingleModStep> > SQLiteModDbi::getModSteps(const U2DataId &masterObjId, qint64 version, U2OpStatus &os) { QList< QList<U2SingleModStep> > steps; SQLiteTransaction t(db, os); qint64 userStepId = -1; SQLiteWriteQuery qGetUserStepId("SELECT id FROM UserModStep WHERE object = ?1 AND version = ?2", db, os); SAFE_POINT_OP(os, QList< QList<U2SingleModStep> >()); qGetUserStepId.bindDataId(1, masterObjId); qGetUserStepId.bindInt64(2, version); if (qGetUserStepId.step()) { userStepId = qGetUserStepId.getInt64(0); qGetUserStepId.ensureDone(); } else if (!os.hasError()) { os.setError("Failed to find user step ID!"); return steps; } SQLiteReadQuery qMultiStepId("SELECT id FROM MultiModStep WHERE userStepId = ?1", db, os); qMultiStepId.bindInt64(1, userStepId); SQLiteReadQuery qSingleStep("SELECT id, object, otype, oextra, version, modType, details, multiStepId FROM SingleModStep WHERE multiStepId = ?1", db, os); while (qMultiStepId.step()) { qint64 multiStepId = qMultiStepId.getInt64(0); qSingleStep.reset(); qSingleStep.bindInt64(1, multiStepId); QList<U2SingleModStep> currentMultiStepSingleSteps; while (qSingleStep.step()) { U2SingleModStep step; step.id = qSingleStep.getInt64(0); step.objectId = qSingleStep.getDataIdExt(1); step.version = qSingleStep.getInt64(4); step.modType = qSingleStep.getInt64(5); step.details = qSingleStep.getBlob(6); SAFE_POINT_OP(os, QList< QList<U2SingleModStep> >()); currentMultiStepSingleSteps.append(step); } steps.append(currentMultiStepSingleSteps); } return steps; }
Database* Database::loadDatabase(const QString& url, U2OpStatus& os) { U2DbiRef dbiRef (SQLiteDbiFactory::ID, url); DbiConnection dbHandle (dbiRef, os); SAFE_POINT_OP(os, NULL); // ensure that DBI is a valid Session DBI QString val = dbHandle.dbi->getProperty(S3_DATABASE_KEY, "", os); SAFE_POINT_OP(os, NULL); if (val != U2DbiOptions::U2_DBI_VALUE_ON) { os.setError(tr("Not a valid S3-database file: %1").arg(url)); return NULL; } return new Database(dbHandle); }
QList<Task*> PairwiseAlignmentHirschbergTask::onSubTaskFinished(Task *subTask) { QList<Task*> res; if (hasError() || isCanceled()) { return res; } if (subTask->hasError() || subTask->isCanceled()) { return res; } if (subTask == kalignSubTask) { if (settings->inNewWindow == true) { TaskStateInfo localStateInfo; Project * currentProject = AppContext::getProject(); DocumentFormat * format = AppContext::getDocumentFormatRegistry()->getFormatById(BaseDocumentFormats::CLUSTAL_ALN); Document * alignmentDoc = NULL; QString newFileUrl = settings->resultFileName.getURLString(); changeGivenUrlIfDocumentExists(newFileUrl, currentProject); alignmentDoc = format->createNewLoadedDocument(IOAdapterUtils::get(BaseIOAdapters::LOCAL_FILE), GUrl(newFileUrl), localStateInfo); CHECK_OP(localStateInfo, res); MAlignment resultMa = kalignSubTask->resultMA; MAlignmentObject * docObject = MAlignmentImporter::createAlignment(alignmentDoc->getDbiRef(), resultMa, localStateInfo); CHECK_OP(localStateInfo, res); alignmentDoc->addObject(docObject); SaveDocFlags flags = SaveDoc_Overwrite; flags |= SaveDoc_OpenAfter; res << new SaveDocumentTask(alignmentDoc, flags); } else { //in current window U2OpStatus2Log os; DbiConnection con(settings->msaRef.dbiRef, os); CHECK_OP(os, res); QList<U2MsaRow> rows = con.dbi->getMsaDbi()->getRows(settings->msaRef.entityId, os); CHECK_OP(os, res); U2UseCommonUserModStep userModStep(settings->msaRef, os); Q_UNUSED(userModStep); SAFE_POINT_OP(os, res); for (int rowNumber = 0; rowNumber < rows.length(); ++rowNumber) { if (rows[rowNumber].sequenceId == settings->firstSequenceRef.entityId) { con.dbi->getMsaDbi()->updateGapModel(settings->msaRef.entityId, rows[rowNumber].rowId, kalignSubTask->resultMA.getRow(0).getGapModel(), os); CHECK_OP(os, res); } if (rows[rowNumber].sequenceId == settings->secondSequenceRef.entityId) { con.dbi->getMsaDbi()->updateGapModel(settings->msaRef.entityId, rows[rowNumber].rowId, kalignSubTask->resultMA.getRow(1).getGapModel(), os); CHECK_OP(os, res); } } } } return res; }
MAlignment Kalign_Load_Align_Compare_Task::dna_to_ma(QList<GObject*> dnaSeqs) { int seqCount = dnaSeqs.count(); U2SequenceObject *seq = qobject_cast<U2SequenceObject *>(dnaSeqs[0]); MAlignment ma("Alignment",seq->getAlphabet()); for(int i=0; i<seqCount; i++) { seq = qobject_cast<U2SequenceObject *>(dnaSeqs[i]); if(seq == NULL) { stateInfo.setError( QString("Can't cast GObject to U2SequenceObject") ); return ma; } QByteArray seqData = seq->getWholeSequenceData(stateInfo); SAFE_POINT_OP(stateInfo, MAlignment()); ma.addRow(seq->getSequenceName(), seqData, stateInfo); SAFE_POINT_OP(stateInfo, MAlignment()); } return ma; }
QList<U2MsaRow> MAlignmentExporter::exportRows( const U2DataId &msaId, const QList<qint64> rowIds, U2OpStatus &os ) const { U2MsaDbi* msaDbi = con.dbi->getMsaDbi( ); SAFE_POINT( NULL != msaDbi, NULL_MSA_DBI_ERROR, QList<U2MsaRow>( ) ); QList<U2MsaRow> result; foreach ( qint64 rowId, rowIds ) { result.append( msaDbi->getRow( msaId, rowId, os) ); SAFE_POINT_OP( os, QList<U2MsaRow>( ) ); }
qint64 SQLiteModDbi::getNearestUserModStepVersion(const U2DataId &masterObjId, qint64 version, U2OpStatus &os) { SQLiteReadQuery qVersion("SELECT MAX(version) FROM UserModStep WHERE object = ?1 AND version <= ?2", db, os); qVersion.bindDataId(1, masterObjId); qVersion.bindInt64(2, version); qint64 userStepVersion = version; if (qVersion.step()) { userStepVersion = qVersion.getInt64(0); } SAFE_POINT_OP(os, userStepVersion); return userStepVersion; }
bool TestDbiProvider::init(const QString& dbiFileName, bool _useConnectionPool){ if(initialized){ close(); initialized = false; } TestRunnerSettings* trs = AppContext::getAppSettings()->getTestRunnerSettings(); QString originalFile = trs->getVar("COMMON_DATA_DIR") + "/" + dbiFileName; QString tmpFile = QDir::temp().absoluteFilePath(QFileInfo(originalFile).fileName()); if(QFile::exists(tmpFile)) { QFile::remove(tmpFile); } bool _create = false; if (QFile::exists(originalFile)) { SAFE_POINT(QFile::copy(originalFile, tmpFile), "db file not copied", false); }else{ _create = true; } dbUrl = tmpFile; useConnectionPool = _useConnectionPool; U2DbiFactory *factory = AppContext::getDbiRegistry()->getDbiFactoryById(SQLITE_DBI_ID); SAFE_POINT(factory!=NULL, "No dbi factory", false); U2OpStatusImpl opStatus; if(useConnectionPool){ U2DbiRef ref; ref.dbiFactoryId = factory->getId(); ref.dbiId = dbUrl; dbi = AppContext::getDbiRegistry()->getGlobalDbiPool()->openDbi(ref, _create, opStatus); CHECK_OP(opStatus, false); }else{ dbi = factory->createDbi(); SAFE_POINT(NULL != dbi, "dbi not created", false); QHash<QString, QString> properties; if(_create){ properties[U2DbiOptions::U2_DBI_OPTION_CREATE] = U2DbiOptions::U2_DBI_VALUE_ON; } properties["url"] = dbUrl; QVariantMap persistentData; dbi->init(properties, persistentData, opStatus); SAFE_POINT_OP(opStatus, false); } U2ObjectDbi* objDbi = dbi->getObjectDbi(); SAFE_POINT(NULL != objDbi, "object dbi not loaded", false); initialized = true; return true; }
QString AssemblyMessageTranslator::getTranslation( ) const { U2OpStatusImpl os; DbiConnection connection( assemblyRef.dbiRef, os ); SAFE_POINT_OP( os, QString( ) ); U2AssemblyDbi *dbi = connection.dbi->getAssemblyDbi( ); SAFE_POINT( NULL != dbi, "Invalid assembly DBI!", QString( ) ); const U2DataId assemblyId = assemblyRef.entityId; const qint64 assemblyLength = dbi->getMaxEndPos( assemblyId, os ) + 1; SAFE_POINT_OP( os, QString( ) ); const U2Region wholeAssembly( 0, assemblyLength ); const qint64 countOfReads = dbi->countReads( assemblyId, wholeAssembly, os ); SAFE_POINT_OP( os, QString( ) ); QString result = QObject::tr( ASSEMBLY_LENGTH_LABEL ) + QString::number( assemblyLength ) + INFO_FEATURES_SEPARATOR; result += QObject::tr( COUNT_OF_READS_LABEL ) + QString::number( countOfReads ); return result; }
Task::ReportResult GTest_SecStructPredictTask::report() { if (task!=NULL && task->hasError()) { stateInfo.setError(task->getError()); } else if (!resultsTableContextName.isEmpty()) { QList<SharedAnnotationData> results = task->getResults(); U2OpStatusImpl os; const U2DbiRef dbiRef = AppContext::getDbiRegistry()->getSessionTmpDbiRef(os); SAFE_POINT_OP(os, ReportResult_Finished); aObj = new AnnotationTableObject(resultsTableContextName, dbiRef); aObj->addAnnotations(results); addContext(resultsTableContextName, aObj); contextAdded = true; } return ReportResult_Finished; }
AnnotationTableObject * SendSelectionDialog::getAnnotationObject() const { if(ca_c->isNewObject()) { U2OpStatusImpl os; const U2DbiRef dbiRef = AppContext::getDbiRegistry( )->getSessionTmpDbiRef( os ); SAFE_POINT_OP( os, NULL ); AnnotationTableObject *aobj = new AnnotationTableObject( "Annotations", dbiRef ); aobj->addObjectRelation(GObjectRelation(ca_c->getModel().sequenceObjectRef, ObjectRole_Sequence)); return aobj; } else { bool objectPrepared = ca_c->prepareAnnotationObject(); if (!objectPrepared){ QMessageBox::warning(NULL, tr("Error"), tr("Cannot create an annotation object. Please check settings")); return NULL; } return ca_c->getModel().getAnnotationObject(); } }