Revision 204
Added by Matt Jones almost 24 years ago
DBWriter.java | ||
---|---|---|
138 | 138 |
* @param xml the xml stream to be loaded into the database |
139 | 139 |
*/ |
140 | 140 |
public String write( Reader xml, String action, String docid ) |
141 |
throws IOException, SQLException, ClassNotFoundException {
|
|
142 |
|
|
141 |
throws Exception, IOException, SQLException,
|
|
142 |
ClassNotFoundException, SAXException, SAXParseException { |
|
143 | 143 |
try { |
144 | 144 |
XMLReader parser = initializeParser(action, docid); |
145 | 145 |
conn.setAutoCommit(false); |
... | ... | |
149 | 149 |
return docid; |
150 | 150 |
} catch (SAXParseException e) { |
151 | 151 |
conn.rollback(); |
152 |
System.err.println(e.getMessage()); |
|
153 |
return null; |
|
152 |
throw e; |
|
154 | 153 |
} catch (SAXException e) { |
155 |
// WHAT HAPPENS HERE IF THIS ISNT ACTUALLY AN AccessionNumberException? |
|
156 |
// IT CAUSES PROBLEMS! |
|
157 |
AccessionNumberException ane = null; |
|
154 |
|
|
155 |
// If its a problem with the accession number its ok, just the |
|
156 |
// accession number was regenerated |
|
157 |
AccessionNumberGeneratedException ang = null; |
|
158 | 158 |
try { |
159 |
ane = (AccessionNumberException)e.getException(); |
|
159 |
Exception embedded = e.getException(); |
|
160 |
if ((embedded != null) && |
|
161 |
(embedded instanceof AccessionNumberGeneratedException)) { |
|
162 |
ang = (AccessionNumberGeneratedException)e.getException(); |
|
163 |
} |
|
160 | 164 |
} catch (ClassCastException cce) { |
161 |
return (e.getMessage());
|
|
165 |
// Do nothing and just fall through to the ang != null test
|
|
162 | 166 |
} |
163 |
if (ane != null) { |
|
164 |
MetaCatUtil.debugMessage("DBWRITER LINE 120"); |
|
165 |
MetaCatUtil.debugMessage(ane.getMessage()); |
|
167 |
if (ang != null) { |
|
166 | 168 |
conn.commit(); |
167 | 169 |
conn.setAutoCommit(true); |
168 |
return (ane.getMessage());
|
|
170 |
return (ang.getMessage());
|
|
169 | 171 |
} else { |
170 |
System.err.println(e.getMessage()); |
|
171 | 172 |
conn.rollback(); |
172 |
return null;
|
|
173 |
throw e;
|
|
173 | 174 |
} |
174 | 175 |
} catch (Exception e) { |
175 | 176 |
conn.rollback(); |
176 |
System.err.println(e.toString()); |
|
177 |
return null; |
|
177 |
throw e; |
|
178 | 178 |
} |
179 | 179 |
} |
180 | 180 |
|
... | ... | |
184 | 184 |
* @param filename the filename to be loaded into the database |
185 | 185 |
*/ |
186 | 186 |
public String write( String filename, String action, String docid ) |
187 |
throws IOException, SQLException, ClassNotFoundException { |
|
187 |
throws Exception, IOException, SQLException, |
|
188 |
ClassNotFoundException, SAXException, SAXParseException { |
|
188 | 189 |
return write(new FileReader(new File(filename).toString()), action, docid); |
189 | 190 |
} |
190 | 191 |
|
... | ... | |
194 | 195 |
// Set up the SAX document handlers for parsing |
195 | 196 |
// |
196 | 197 |
try { |
197 |
ContentHandler xmlDocHandler = new DBSAXHandler(conn, action, docid); |
|
198 |
EntityResolver xmlEntityResolver = new DBEntityResolver(conn); |
|
199 |
DTDHandler xmlDTDHandler = new DBDTDHandler(conn); |
|
198 |
ContentHandler chandler = new DBSAXHandler(conn, action, docid); |
|
199 |
EntityResolver dbresolver = new DBEntityResolver(conn, |
|
200 |
(DBSAXHandler)chandler); |
|
201 |
DTDHandler dtdhandler = new DBDTDHandler(conn); |
|
200 | 202 |
|
201 | 203 |
// Get an instance of the parser |
202 | 204 |
parser = XMLReaderFactory.createXMLReader(parserName); |
... | ... | |
206 | 208 |
|
207 | 209 |
// Set Handlers in the parser |
208 | 210 |
parser.setProperty("http://xml.org/sax/properties/declaration-handler", |
209 |
xmlDocHandler);
|
|
211 |
chandler);
|
|
210 | 212 |
parser.setProperty("http://xml.org/sax/properties/lexical-handler", |
211 |
xmlDocHandler);
|
|
212 |
parser.setContentHandler(xmlDocHandler);
|
|
213 |
parser.setEntityResolver(xmlEntityResolver);
|
|
214 |
parser.setDTDHandler(xmlDTDHandler);
|
|
215 |
parser.setErrorHandler((ErrorHandler)xmlDocHandler);
|
|
213 |
chandler);
|
|
214 |
parser.setContentHandler(chandler);
|
|
215 |
parser.setEntityResolver(dbresolver);
|
|
216 |
parser.setDTDHandler(dtdhandler);
|
|
217 |
parser.setErrorHandler((ErrorHandler)chandler);
|
|
216 | 218 |
|
217 | 219 |
} catch (Exception e) { |
218 | 220 |
System.err.println(e.toString()); |
... | ... | |
248 | 250 |
|
249 | 251 |
/** |
250 | 252 |
* '$Log$ |
253 |
* 'Revision 1.21 2000/06/26 10:35:05 jones |
|
254 |
* 'Merged in substantial changes to DBWriter and associated classes and to |
|
255 |
* 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE |
|
256 |
* 'functions. The command line tools and the parameters for the |
|
257 |
* 'servlet have changed substantially. |
|
258 |
* ' |
|
251 | 259 |
* 'Revision 1.20.2.7 2000/06/26 10:18:06 jones |
252 | 260 |
* 'Partial fix for MetaCatServlet INSERT?UPDATE bug. Only will work on |
253 | 261 |
* 'the first call to the servlet. Subsequent calls fail. Seems to be |
Also available in: Unified diff
Fixed bugs associated with the new UPDATE and DELETE functions of
DBWriter. There were problematic interactions between some static
variables used in DBEntityResolver and the way in which the
Servlet objects are re-used across multiple client invocations.
Generally cleaned up error reporting. Now all errors and success
results are reported as XML documents from MetaCatServlet. Need
to make the command line tools do the same.