예제 #1
0
static
rc_t RestoreReadMake ( RestoreRead **objp, const VTable *tbl, const VCursor* native_curs )
{
    rc_t rc;
    char name[]="PRIMARY_ALIGNMENT";

    /* create the object */
    RestoreRead *obj = malloc ( sizeof * obj );
    memset(obj,0,sizeof * obj);
    if ( obj == NULL )
    {
		*objp=0;
        rc = RC ( rcXF, rcFunction, rcConstructing, rcMemory, rcExhausted );
    }
    else
	{
		rc = VCursorLinkedCursorGet(native_curs,name,&obj->curs);
		if(rc == 0){
			VCursorAddRef(obj->curs);
		} else {
			/* get at the parent database */
			const VDatabase *db;
			rc = VTableOpenParentRead ( tbl, & db );
			if ( rc == 0 )
			{
				const VTable *patbl;
				/* open the primary alignment table */
				rc = VDatabaseOpenTableRead ( db, & patbl, name );
				VDatabaseRelease ( db );
				if ( rc == 0 )
				{
					/* create a cursor */
					rc = VTableCreateCachedCursorRead( patbl, &obj->curs, 32*1024*1024UL );
					VTableRelease ( patbl );
					if ( rc == 0 )
					{
						/* add columns to cursor */
						rc = VCursorAddColumn ( obj -> curs, & obj -> read_idx, "( INSDC:4na:bin ) READ" );
						if ( rc == 0 )
						{
							rc = VCursorOpen ( obj -> curs );
							if ( rc == 0 )
							{
								VCursorLinkedCursorSet( native_curs, name, obj->curs );
								SUB_DEBUG( ( "SUB.Make in 'seq-restore-read.c'\n" ) );
								* objp = obj;
								return 0;
							}
						}
						VCursorRelease ( obj -> curs );
					}
				}
			}
			free ( obj );
		}
	}
    return rc;
}
예제 #2
0
rc_t AlignRefTableCursor(const VTable* table, const VCursor *native_curs, const VCursor** ref_cursor,const VTable **reftbl)
{
	rc_t rc = 0;
	char ref_tbl_name[512] =  "REFERENCE";
	const KMetadata* meta;
	const VCursor *curs;

	if( (rc = VTableOpenMetadataRead(table, &meta)) == 0 ) {
	    const KMDataNode* node;
            if( (rc = KMetadataOpenNodeRead(meta, &node, "CONFIG/REF_TABLE")) == 0 ) {
                size_t sz;
                rc = KMDataNodeReadCString(node, ref_tbl_name, sizeof(ref_tbl_name), &sz);
                ref_tbl_name[sz] = '\0';
                KMDataNodeRelease(node);
            }
            KMetadataRelease(meta);
        }
	rc = VCursorLinkedCursorGet(native_curs,ref_tbl_name,&curs);
	if(rc != 0){
		const VDatabase *db;
                const VTable *tbl;
                /* get at the parent database */
                rc = VTableOpenParentRead ( table, & db );
                if(rc != 0) return rc;
                /* open the table */
                rc = VDatabaseOpenTableRead ( db, &tbl, ref_tbl_name);
                VDatabaseRelease ( db );
                if(rc != 0) return rc;
                /* create a cursor */
                rc = VTableCreateCachedCursorRead(tbl, &curs,256*1024*1024);
		if(reftbl){
			*reftbl = tbl;
                } else {
			VTableRelease(tbl);
		}
                if(rc != 0) return rc;
                rc = VCursorPermitPostOpenAdd( curs );
                if(rc != 0) return rc;
                rc = VCursorOpen( curs );
                if(rc != 0) return rc;
                if(native_curs){
                    rc = VCursorLinkedCursorSet(native_curs,ref_tbl_name,curs);
                }
                if(rc != 0) return rc;
	} else {
		VCursorAddRef(curs);
	}
	*ref_cursor = curs;
	return 0;
}
예제 #3
0
static
rc_t init_self( self_t *self, VTable const * const srctbl, char const column[] )
{
    VDatabase const * db;
    rc_t rc = VTableOpenParentRead( srctbl, &db );
    if ( rc == 0 )
    {
        VTable const * tbl;
        rc = VDatabaseOpenTableRead( db, &tbl, "SEQUENCE" );
        VDatabaseRelease( db );
        if ( rc == 0 )
        {
            bool has_column = does_table_have_column( tbl, column );
            if ( !has_column )
                VTableRelease( tbl );
            else
            {
                VCursor const * curs;
#if CURSOR_CACHE_SIZE
                rc = VTableCreateCachedCursorRead( tbl, &curs, CURSOR_CACHE_SIZE );
#else
                rc = VTableCreateCursorRead( tbl, &curs );
#endif
                VTableRelease( tbl );
                if ( rc == 0 )
                {
                    uint32_t col_idx;
                    rc = VCursorAddColumn( curs, &col_idx, "%s", column );
                    if ( rc == 0 )
                    {
                        rc = VCursorOpen( curs );
                        if ( rc == 0 )
                        {
                            self->curs = curs;
                            self->col_idx = col_idx;
                            return 0;
                        }
                        if ( GetRCObject( rc ) == (enum RCObject)rcColumn && GetRCState( rc ) == rcUndefined )
                            rc = 0;
                    }
                    VCursorRelease( curs );
                }
            }
        }
    }
    return rc;
}
예제 #4
0
static
rc_t open_RR_cursor( Read_Restorer * obj, const VTable *tbl, const VCursor* native_curs, const char * tablename )
{
    rc_t rc = VCursorLinkedCursorGet( native_curs, tablename, &obj->curs );
    if ( rc != 0 )
    {
        /* get at the parent database */
        const VDatabase *db;
        rc = VTableOpenParentRead ( tbl, & db );
        if ( rc == 0 )
        {
            const VTable *patbl;
            /* open the primary alignment table */
            rc = VDatabaseOpenTableRead ( db, & patbl, tablename );
            VDatabaseRelease ( db );
            if ( rc == 0 )
            {
                /* create a cursor */
                rc = VTableCreateCachedCursorRead( patbl, &obj->curs, 32*1024*1024UL );
                /* rc = VTableCreateCursorRead( patbl, &obj->curs ); */
                VTableRelease ( patbl );
                if ( rc == 0 )
                    rc = VCursorLinkedCursorSet( native_curs, tablename, obj->curs );
            }
        }
    }
    if ( rc == 0 )
    {
        /* add columns to cursor */
        rc = VCursorAddColumn ( obj -> curs, & obj -> read_idx, "( INSDC:4na:bin ) READ" );
        if ( GetRCState(rc) == rcExists )
            rc = 0;
        if ( rc == 0 )
        {
            rc = VCursorOpen ( obj -> curs );
        }
    }
    return rc;
}
예제 #5
0
static rc_t CC ReportObj(const ReportFuncs *f, uint32_t indent,
    const char *object, bool *wasDbOrTableSet)
{
    Report* self = NULL;
    const char* fullpath = NULL;
    const KDatabase* kdb = NULL;
    const KTable* ktbl = NULL;
    const VDatabase* db = NULL;
    KPathType type = kptNotFound;
    KPathType file_type = kptNotFound;
    bool alias = false;
    uint64_t size = 0;
    bool size_unknown = true;

    rc_t rc = ReportGet(&self);
    assert(self);

    if (wasDbOrTableSet != NULL) {
        *wasDbOrTableSet = self->db != NULL || self->table != NULL;
        return 0;
    }

    if (self->db != NULL) {
        type = kptDatabase;
        db = self->db;
    }
    else if (self->table != NULL) {
        rc_t rc2 = VTableOpenParentRead(self->table, &db);
        if (rc2)
        {
            if (rc == 0)
            {
                rc = rc2;
            }
        }
        else if (!db)
        {
            type = kptTable;
            rc2 = VTableGetKTableRead(self->table, &ktbl);
            if (rc2)
            {
                if (rc == 0)
                {
                    rc = rc2;
                }
            }
            else
            {
                rc2 = KTableGetPath(ktbl, &fullpath);
            }
        }
    }

    if (db) {
        rc_t rc2 = VDatabaseOpenKDatabaseRead(db, &kdb);
        type = kptDatabase;
        if (rc2) {
            if (rc == 0)
            {   rc = rc2; }
        }
        else {
            rc2 = KDatabaseGetPath(kdb, &fullpath);
            if (rc2) {
                if (rc == 0)
                {   rc = rc2; }
            }
        }
    }

    if (fullpath) {
        KDirectory* dir = NULL;
        rc_t rc2 = KDirectoryNativeDir(&dir);
        if (rc2) {
            if (rc == 0)
            {   rc = rc2; }
        }
        else {
            file_type = KDirectoryPathType(dir, "%s", fullpath);
            alias = file_type & kptAlias;
            file_type &= ~kptAlias;
            if (file_type == kptFile) {
                rc2 = KDirectoryFileSize(dir, &size, "%s", fullpath);
                if (rc2) {
                    if (rc == 0)
                    {   rc = rc2; }
                }
                else {  size_unknown = false; }
            }
        }
        RELEASE(KDirectory, dir);
    }

    if (object || type != kptNotFound) {
        const char* path
            = fullpath ? fullpath : object ? object : "not set";
        const char* stype = type == kptTable ? "table" : 
            type == kptDatabase ? "database" : "unknown";
        const char* sfile_type = file_type == kptFile ? "archive" : 
            file_type == kptDir ? "dir" : "unexpected";

        if (fullpath && !size_unknown) {
            if (alias)
            { OBJ_P_S_A(indent, path, stype, sfile_type, size); }
            else
            { OBJ_P_S  (indent, path, stype, sfile_type, size); }
        }
        else if (fullpath && size_unknown) {
            if (alias)
            { OBJ_P_A  (indent, path, stype, sfile_type); }
            else
            { OBJ_P    (indent, path, stype, sfile_type); }
        }
        else
        {     OBJ      (indent, path, stype); }

        if (!db)
        {   db = self->db; }

        if (db) {
            rc_t rc2 = ReportDepend(f, indent + 1, db);
            if (rc == 0)
            {   rc = rc2; }
        }
        if (file_type == kptDir) {
            rc_t rc2 = ReportDir(f, indent + 1, ktbl);
            if (rc == 0)
            {   rc = rc2; }
        }

        reportClose(indent, "Object");
    }

    if (db != self->db)
    {   RELEASE(VDatabase, db); }
    RELEASE(KTable, ktbl);
    RELEASE(KDatabase, kdb);

    return rc;
}