23-Aug-05 (Created: 23-Aug-05) | More in 'Data Access'

How to use ListDataCollection


    private IDataCollection getDocumentCollection(List documentList)
    {
       Vector columnNamesVector = new Vector();
       columnNamesVector.add(IndentLuceneIndex.FIELD_ID);
       columnNamesVector.add(IndentLuceneIndex.FIELD_APP);
       columnNamesVector.add(IndentLuceneIndex.FIELD_DOC);
       columnNamesVector.add(IndentLuceneIndex.FIELD_TITLE);
       columnNamesVector.add(IndentLuceneIndex.FIELD_DESCRIPTION);
       
       ListDataCollection luceneDocumentCollection 
         = new ListDataCollection(columnNamesVector);
       //Fill it up with rows
       Iterator luceneDocItr = documentList.iterator();
       while(luceneDocItr.hasNext())
       {
          Document doc = (Document)luceneDocItr.next();
          IDataRow collectionRow = getDataRow(doc
                               ,new VectorMetaData(columnNamesVector));
          luceneDocumentCollection.addDataRow(collectionRow);
       }
       return luceneDocumentCollection;
    }
    
    private IDataRow getDataRow(Document luceneDoc, IMetaData columnMetaData)
    {
       List columnValues = new ArrayList();
       columnValues.add(luceneDoc.get(IndentLuceneIndex.FIELD_ID));
       columnValues.add(luceneDoc.get(IndentLuceneIndex.FIELD_APP));
       columnValues.add(luceneDoc.get(IndentLuceneIndex.FIELD_DOC));
       columnValues.add(luceneDoc.get(IndentLuceneIndex.FIELD_TITLE));
       columnValues.add(luceneDoc.get(IndentLuceneIndex.FIELD_DESCRIPTION));
       
       return new ListDataRow(columnMetaData,columnValues);
    }