source: branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentFactory.java@ 9858

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

OK, changed my mind about making SQLConnection kill off the previous statement.
To make it more transparent what is happening, you now have to create a Statement (connection.createStatement()), then use the Statement to execute the query. This means that the thing doing the query owns the Statement, and can kill it off when finished with it, and nothing else can kill it off unexpectedly. The previous way this was all implemented meant that there was a large memory leak, and some functionality actually relied on this. A newer version of the mysql connector/J has fixed the bug where the statement wasn't closed on garbage collection, but it still seems better to close it explicitly.
Hopefully I have got it all back to working as well as it was bfore, and haven't introduced any bugs :-)

  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1package org.greenstone.gsdl3.gs3build.doctypes;
2
3import java.sql.SQLException;
4import java.sql.Statement;
5import java.sql.ResultSet;
6import java.net.URL;
7
8import org.greenstone.gsdl3.gs3build.database.GS3SQLConnection;
9
10public class DocumentFactory {
11
12 public static AbstractDocument createDocument(String type, DocumentID id) {
13
14 if (type.equals(HTMLDocument.HTML_DOCUMENT_TYPE)) {
15 return new HTMLDocument(id);
16 } else if (type.equals(TextDocument.TEXT_DOCUMENT_TYPE)) {
17 return new TextDocument(id);
18 } else if (type.equals(JPEGDocument.JPEG_DOCUMENT_TYPE)) {
19 return new JPEGDocument(id);
20 } else if (type.equals(IndexDocument.INDEX_DOCUMENT_TYPE)) {
21 return new IndexDocument(id);
22 } else if (type.equals(MetadataDocument.METADATA_DOCUMENT_TYPE)) {
23 return new MetadataDocument(id);
24 } else if (type.equals(METSDocument.METS_DOCUMENT_TYPE)) {
25 return new METSDocument(id);
26 } else if (type.equals(GMLDocument.GML_DOCUMENT_TYPE)) {
27 return new GMLDocument(id);
28 }
29
30 /*
31 else if (type.equals(ExtXMLDocument.EXTXML_DOCUMENT_TYPE))
32 { return new ExtXMLDocument(id);
33 }*/
34 return null;
35 }
36 public static AbstractDocument createDocument(String type, URL url) {
37
38 if (type.equals(HTMLDocument.HTML_DOCUMENT_TYPE)) {
39 return new HTMLDocument(url);
40 } else if (type.equals(TextDocument.TEXT_DOCUMENT_TYPE)) {
41 return new TextDocument(url);
42 } else if (type.equals(JPEGDocument.JPEG_DOCUMENT_TYPE)) {
43 return new JPEGDocument(url);
44 } else if (type.equals(IndexDocument.INDEX_DOCUMENT_TYPE)) {
45 return new IndexDocument(url);
46 } else if (type.equals(MetadataDocument.METADATA_DOCUMENT_TYPE)) {
47 return new MetadataDocument(url);
48 } else if (type.equals(METSDocument.METS_DOCUMENT_TYPE)) {
49 return new METSDocument(url);
50 } else if (type.equals(GMLDocument.GML_DOCUMENT_TYPE)) {
51 return new GMLDocument(url);
52 }
53
54 /*
55 else if (type.equals(ExtXMLDocument.EXTXML_DOCUMENT_TYPE))
56 { return new ExtXMLDocument(id);
57 }*/
58 return null;
59 }
60
61 public static DocumentInterface readSQLDocument(GS3SQLConnection connection, DocumentID id)
62 {
63 String query = "SELECT * FROM document WHERE DocID=\""+id.toString()+"\";";
64 try {
65 Statement statement = connection.createStatement();
66 ResultSet results = statement.executeQuery(query);
67
68 DocumentInterface di = null;
69 if (results.first()) {
70 di = AbstractDocument.readSQL(connection, results);
71 }
72 statement.close();
73 return di;
74 }
75 catch (SQLException sqlEx) {
76 System.err.println("AbstractDocument.readSQLDocument():"+sqlEx);
77 }
78 return null;
79 }
80}
Note: See TracBrowser for help on using the repository browser.