/// Function name  : removeDocument
// Description     : Removes the destroys the specified document. Should not be called directly, except by 'closeDocumentByIndex'
// 
// DOCUMENTS_DATA*  pWindowData : [in] Documents window data
// DOCUMENT*        pDocument   : [in] Target document
// CONST UINT       iIndex      : [in] Index of target document
// 
VOID  removeDocument(DOCUMENTS_DATA*  pWindowData, DOCUMENT*  pDocument, CONST UINT  iIndex)
{
   UINT   iReplacementIndex;    // Index of document to display instead

   
   // [CHECK] Are we closing the ActiveDocument?
   if (pDocument == getActiveDocument())
   {
      // [CHECK] Is there a replacement for the ActiveDocument?
      if (getDocumentCount() > 1)
      {
         // [SUCCESS] Display document on the right, otherwise one on the left
         iReplacementIndex = (iIndex == getDocumentCount() - 1 ? (iIndex - 1) : (iIndex + 1));
         displayDocumentByIndex(pWindowData->hTabCtrl, iReplacementIndex);       /// [EVENT] Fires UM_DOCUMENT_SWITCHED
      }
      else
         // [FAILED] Reset active document
         setActiveDocument(pWindowData, NULL);     /// [EVENT] Fires UM_DOCUMENT_SWITCHED
   }

   /// Remove tab and Destroy Document
   TabCtrl_DeleteItem(pWindowData->hTabCtrl, iIndex);        // [WARNING] TabCtrl_DeleteItem causes document to be erased but not invalidated
   removeObjectFromListByValue(pWindowData->pDocumentList, (LPARAM)pDocument);
   deleteDocument(pDocument);

   // [CHECK] Is there an active document?
   if (getActiveDocument())
      // [ACTIVE DOCUMENT] Resize in case a row of tabs has been removed
      updateDocumentSize(pWindowData, getActiveDocument());
}
// TODO this leaks 1000 annotations for some reason
void TestPrecedes(CuTest* tc) {
	Document* doc = createDocument();
	int index;
	char* uri;
	SequenceAnnotation* upstream;
	SequenceAnnotation** downstream;
	
	// create the main annotation to test
	upstream = createSequenceAnnotation(doc, randomUniqueURI(doc));
	
	// and also some others
	downstream = malloc(NUM_SLOW_TESTS * sizeof(SequenceAnnotation*));
	for (index=0; index<NUM_SLOW_TESTS; index++) {
		uri = randomUniqueURI(doc);
		downstream[index] = createSequenceAnnotation(doc, uri);
	}
	
	// restrict the main one to coming before each of the others
	for (index=0; index<NUM_SLOW_TESTS; index++) {
		// check that numPrecedes increments as expected
		CuAssertIntEquals(tc, index, getNumPrecedes(upstream));
		addPrecedesRelationship(upstream, downstream[index]);
		CuAssertIntEquals(tc, index+1, getNumPrecedes(upstream));
		
		// check that precedes array holds the expected values
		SequenceAnnotation* expected = downstream[index];
		SequenceAnnotation* actual = getNthPrecedes(upstream, index);
		CuAssertPtrEquals(tc, expected, actual);
	}
	deleteDocument(doc);
}
Example #3
0
    StatusWith<DiskLoc> Collection::insertDocument( const BSONObj& docToInsert, bool enforceQuota ) {
        int lenWHdr = _details->getRecordAllocationSize( docToInsert.objsize() + Record::HeaderSize );
        fassert( 17208, lenWHdr >= ( docToInsert.objsize() + Record::HeaderSize ) );

        if ( _details->isCapped() ) {
            // TOOD: old god not done
            Status ret = _indexCatalog.checkNoIndexConflicts( docToInsert );
            uassert(17209, "duplicate key insert for unique index of capped collection", ret.isOK() );
        }

        // TODO: for now, capped logic lives inside NamespaceDetails, which is hidden
        //       under the RecordStore, this feels broken since that should be a
        //       collection access method probably
        StatusWith<DiskLoc> loc = _recordStore.allocRecord( lenWHdr,
                                                            enforceQuota ? largestFileNumberInQuota() : 0 );
        if ( !loc.isOK() )
            return loc;

        Record *r = loc.getValue().rec();
        fassert( 17210, r->lengthWithHeaders() >= lenWHdr );

        // copy the data
        r = reinterpret_cast<Record*>( getDur().writingPtr(r, lenWHdr) );
        memcpy( r->data(), docToInsert.objdata(), docToInsert.objsize() );

        addRecordToRecListInExtent(r, loc.getValue()); // XXX move down into record store

        _details->incrementStats( r->netLength(), 1 );

        // TOOD: old god not done
        _infoCache.notifyOfWriteOp();

        try {
            _indexCatalog.indexRecord( docToInsert, loc.getValue() );
        }
        catch( AssertionException& e ) {
            if ( _details->isCapped() ) {
                return StatusWith<DiskLoc>( ErrorCodes::InternalError,
                                            str::stream() << "unexpected index insertion failure on"
                                            << " capped collection" << e.toString()
                                            << " - collection and its index will not match" );
            }

            // normal case -- we can roll back
            deleteDocument( loc.getValue(), false, true, NULL );
            throw;
        }

        // TODO: this is what the old code did, but is it correct?
        _details->paddingFits();

        return loc;

    }
void TestCreateSequenceAnnotation(CuTest* tc) {
	Document* doc = createDocument();
	char* uri;
	SequenceAnnotation* ann;
	int repeat;
	for (repeat=0; repeat<NUM_FAST_TESTS; repeat++) {
		uri = randomUniqueURI(doc);
		ann = createSequenceAnnotation(doc, uri);
		CuAssertIntEquals(tc, 1, getNumSequenceAnnotations(doc));
		CuAssertStrEquals(tc, uri, getSequenceAnnotationURI(ann));
		CuAssertIntEquals(tc, -1, getSequenceAnnotationStart(ann));
		CuAssertIntEquals(tc, -1, getSequenceAnnotationEnd(ann));
		CuAssertIntEquals(tc, 0, getNumPrecedes(ann));
		deleteSequenceAnnotation(ann);
		CuAssertIntEquals(tc, 0, getNumSequenceAnnotations(doc));
	}
	deleteDocument(doc);
}
Example #5
0
int32_t IndexReader::deleteDocuments(const TermPtr& term) {
    ensureOpen();
    TermDocsPtr docs(termDocs(term));
    if (!docs) {
        return 0;
    }
    int32_t n = 0;
    LuceneException finally;
    try {
        while (docs->next()) {
            deleteDocument(docs->doc());
            ++n;
        }
    } catch (LuceneException& e) {
        finally = e;
    }
    docs->close();
    finally.throwException();
    return n;
}
Example #6
0
void CWizSearchIndexer::on_document_deleted(const WIZDOCUMENTDATA& doc)
{
    deleteDocument(doc);
}