Changeset 6010


Ignore:
Timestamp:
2003-11-26T15:35:27+13:00 (20 years ago)
Author:
cs025
Message:

ID changes for documents, and adding DocID to the database tables

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentFactory.java

    r5944 r6010  
    1111    { return new TextDocument(id);
    1212    }
     13    else if (type.equals(IndexDocument.INDEX_DOCUMENT_TYPE))
     14    { return new IndexDocument(id);
     15    }
    1316    return null;
    1417  }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentIDFactory.java

    r5800 r6010  
    44
    55public class DocumentIDFactory implements DocumentIDFactoryInterface
    6 {   private CollectionManager collection;
     6{ private CollectionManager collection;
    77
    8     public DocumentIDFactory(CollectionManager collection)
    9     { this.collection = collection;
    10     }
     8  public DocumentIDFactory(CollectionManager collection)
     9  { this.collection = collection;
     10  }
    1111
    12     public DocumentID getNewDocumentID(DocumentInterface document)
    13     {   DocumentID id;
     12  public DocumentID getNewDocumentID(DocumentInterface document)
     13  { DocumentID id;
    1414
    15         String idString = this.collection.getNextDocumentID();
    16         id = new DocumentID(idString);
    17 
    18         return id;
    19     }
     15    String idString = this.collection.getNextDocumentID();
     16    id = new DocumentID(idString);
     17   
     18    return id;
     19  }
    2020}
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentList.java

    r5944 r6010  
    1414import java.sql.SQLException;
    1515import java.sql.ResultSet;
     16
     17import org.greenstone.gsdl3.gs3build.metadata.METSFileGroup;
    1618
    1719import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection;
     
    4850    this.count = 0;
    4951    this.connection = connection;
     52  }
     53
     54  public List findDocumentIdsUsingFile(String fileRef)
     55  {
     56    // Get the simple list of file objects & their file group reference
     57    String query = "SELECT FileGroupRef FROM files WHERE FileLocation REGEXP \"" + fileRef +"\";";
     58   
     59    this.connection.execute(query);
     60
     61    try {
     62
     63      ResultSet results = this.connection.getResultSet();
     64      if (results == null ||
     65      !results.first()) {
     66    return null;
     67      }
     68     
     69      // get a list of group ids first and turn it into a query on filegroups
     70      StringBuffer queryBuffer = new StringBuffer("SELECT * FROM filegroups WHERE ");
     71      boolean first = true;
     72     
     73      do {
     74    int groupRef = results.getInt("FileGroupRef");
     75   
     76    if (first) {
     77      first = false;
     78    }
     79    else {
     80      queryBuffer.append(" OR ");
     81    }
     82    queryBuffer.append("FileGroupRef=" + Integer.toString(groupRef));
     83      } while (results.next());
     84      queryBuffer.append(";");
     85     
     86      // make a holder for the actual file section identifiers
     87      List divisions = new ArrayList();
     88     
     89      // expand (or, in fact, contract) through the document
     90      // structures...recreating new filegroup queries as necessary
     91      while (queryBuffer.length() > 0) {
     92    connection.execute(queryBuffer.toString());
     93   
     94    results = this.connection.getResultSet();
     95    if (results == null || !results.first()) {
     96      return null;
     97    }
     98   
     99    queryBuffer = new StringBuffer();
     100    do {
     101      String type = results.getString("ParentType");
     102      String parentRef = results.getString("ParentRef");
     103      if (type.equals(METSFileGroup.SECTION_PARENT)) {
     104        divisions.add(parentRef);
     105      }
     106      else {
     107        if (queryBuffer.length() > 0) {
     108          queryBuffer.append(" OR ");
     109        }
     110        queryBuffer.append("FileGroupRef=" + parentRef);
     111      }
     112    } while (results.next());
     113   
     114    if (queryBuffer.length() > 0) {
     115      queryBuffer.insert(0, "SELECT * FROM filegroups WHERE ");
     116      queryBuffer.append(";");
     117    }
     118      }
     119     
     120      // ok, now find all the sections in which we are interested...
     121      queryBuffer.setLength(0);
     122      queryBuffer.append("SELECT DISTINCT DocID FROM filesection WHERE ");
     123      Iterator iterator = divisions.iterator();
     124      first = true;
     125     
     126      while (iterator.hasNext()) {
     127    String ref = iterator.next().toString();
     128   
     129    if (first) {
     130      first = false;
     131    }
     132    else {
     133      queryBuffer.append(" OR ");
     134    }
     135   
     136    queryBuffer.append("FileSectionRef="+ref);
     137      }
     138      queryBuffer.append(";");
     139     
     140      // execute the division query
     141      this.connection.execute(queryBuffer.toString());
     142     
     143      results = this.connection.getResultSet();
     144      if (results == null ||
     145      !results.first()) {
     146    return null;
     147      }
     148
     149      List reply = new ArrayList();
     150      do {
     151    reply.add(results.getString("DocID"));
     152      } while (results.next());
     153
     154      return reply;
     155    }
     156    catch (SQLException ex) {
     157      System.err.println(ex);
     158    }
     159    return null;
    50160  }
    51161
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentSQLWriter.java

    r5944 r6010  
    5454    //     which would suggest placing it in the AbstractDocument or similar
    5555    //     class?!
     56    if (document.getDocumentMetadata() == null) {
     57      System.out.println("Null metadata document");
     58    }
    5659    document.getDocumentMetadata().writeSQL(document, connection);
    5760
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/IndexDocument.java

    r5944 r6010  
    2222{
    2323  public static final String INDEX_DOCUMENT_TYPE = "GSINDEX";
    24  
     24
     25  public IndexDocument(DocumentID id)
     26  { super(id);
     27  }
     28
    2529  public IndexDocument(URL url)
    2630  { super(url);
     
    3842  }
    3943
    40   public METSDescriptiveSet getDocumentMetadata()
    41   { return null;
     44  /**
     45   *  Indicate whether this document is indexed.
     46   *
     47   *  @see: DocumentInterface.isIndexed
     48   */
     49  public boolean isIndexed()
     50  {
     51    return true;
    4252  }
     53
    4354}
Note: See TracChangeset for help on using the changeset viewer.