source: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentSQLWriter.java@ 8742

Last change on this file since 8742 was 8742, checked in by kjdon, 19 years ago

changed the import statements for GS3SQLConnection and GS3SQLConnectionFactory to reflect their move to the database package

  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1package org.greenstone.gsdl3.gs3build.doctypes;
2
3import java.io.PrintWriter;
4
5import java.sql.*;
6
7import org.greenstone.gsdl3.gs3build.util.XMLTools;
8import org.greenstone.gsdl3.gs3build.database.*;
9
10public class DocumentSQLWriter
11{
12 public DocumentSQLWriter()
13 {
14 }
15
16 public static boolean touchDocument(DocumentID docID, GS3SQLConnection connection, long touchTime, long modTime)
17 { GS3SQLUpdate update = new GS3SQLUpdate("document");
18 update.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("DocID", "=", docID.toString())));
19 update.addDate("IndexedDate", new java.sql.Timestamp(touchTime));
20 update.addDate("ModifiedDate", new java.sql.Timestamp(modTime));
21 connection.execute(update.toString());
22 System.out.println(update.toString());
23 return true;
24 }
25
26 /**
27 * Just write the document to the database, assuming that it is not already there
28 */
29 public boolean writeDocument(DocumentInterface document, GS3SQLConnection connection)
30 {
31 // TODO: output document in METS format, with Greenstone-specific metadata
32 // placed in a wrapper inside the descriptive metadata block
33
34 // put the document into the database
35 try {
36 if (document.getID() != null)
37 { //tag = XMLTools.addAttribute(tag, "OBJID", document.getID().toString());
38 GS3SQLSelect select = new GS3SQLSelect("document");
39 select.addField("*");
40 select.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("DocID", "=", document.getID().toString())));
41 connection.execute(select.toString());
42
43 ResultSet results = connection.getResultSet();
44
45 if (results == null ||
46 !results.first())
47 { GS3SQLInsert insert = new GS3SQLInsert("document");
48 insert.addValue("DocID", document.getID().toString());
49 insert.addValue("DocType", document.getDocumentType());
50
51 insert.addDate("AccessionDate", new java.sql.Timestamp(document.getAccessionDate()));
52 insert.addDate("IndexedDate", new java.sql.Timestamp(document.getLastIndexedDate()));
53 insert.addDate("ModifiedDate", new java.sql.Timestamp(document.getModifiedDatestamp()));
54
55 connection.execute(insert.toString());
56 }
57 else {
58 /* redundant code - not used... */
59 // GS3SQLUpdate update = new GS3SQLUpdate("document");
60 // update.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("DocID", "=", document.getID().toString())));
61 // connection.execute(update.toString());
62 }
63 }
64 } catch (Exception ex) {
65 System.out.println(ex);
66 }
67 // output.println(tag);
68
69 // Write the structural metadata:
70 // if in "Create METS" mode:
71 // take all the documents as being in the one group, of the "physical"
72 // document; particular document plugins may extend this behaviour,
73 // which would suggest placing it in the AbstractDocument or similar
74 // class?!
75 if (document.getDocumentMetadata() == null) {
76 System.out.println("Null metadata document");
77 }
78 document.getDocumentMetadata().writeSQL(document, connection);
79
80 document.getDocumentFiles().writeSQL(document, connection);
81
82 document.getDocumentStructure().writeSQL(document, connection);
83
84 // Write the body information
85 // TODO: only output the document if there is some
86 // content/formatting change between the original and
87 // what greenstone actually does; if the original is
88 // good, then place a marker saying "get the document
89 // "from the original file"
90 return true;
91 }
92}
Note: See TracBrowser for help on using the repository browser.