- Timestamp:
- 2005-05-16T11:02:50+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileSet.java
r8742 r9874 16 16 17 17 import java.sql.SQLException; 18 import java.sql.Statement; 18 19 import java.sql.ResultSet; 19 20 … … 232 233 insert.addValue("FileSecID", "test"); // TODO: remove magic string 233 234 234 if (!connection.execute(insert.toString())){ 235 Statement statement = null; 236 try { 237 statement = connection.createStatement(); 238 statement.execute(insert.toString()); 239 } catch (SQLException e) { 240 System.err.println("METSFileSet.writeSQL(): "+e); 235 241 return false; 236 242 } … … 246 252 247 253 try { 248 connection.execute(select.toString());249 250 ResultSet set = connection.getResultSet();251 set.first();252 int sectionRef = set.getInt("FileSectionRef");253 254 this.reference = Integer.toString(sectionRef);254 ResultSet set = statement.executeQuery(select.toString()); 255 if (set.first()) { 256 int sectionRef = set.getInt("FileSectionRef"); 257 258 this.reference = Integer.toString(sectionRef); 259 } 260 statement.close(); 255 261 } 256 262 catch (SQLException ex){ 257 System.out.println( ex);263 System.out.println("METSFileSet.writeSQL(): "+ex); 258 264 return false; 259 265 } 260 266 } 261 267 268 if (this.reference == null) { 269 return false; 270 } 262 271 // write out the children 263 272 while (groups.hasNext()){ … … 281 290 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString()); 282 291 select.setWhere(new GS3SQLWhere(whereItem)); 283 connection.execute(select.toString()); 292 293 Statement statement = null; 284 294 285 295 // Get the identifier for this file set, etc. 286 ResultSet sections = connection.getResultSet(); 287 int fileSetRef; 296 int fileSetRef = -1; 288 297 try { 289 sections.first(); 290 fileSetRef = sections.getInt("FileSectionRef"); 291 set.reference = Integer.toString(fileSetRef); 298 statement = connection.createStatement(); 299 ResultSet sections = statement.executeQuery(select.toString()); 300 if (sections.first()) { 301 fileSetRef = sections.getInt("FileSectionRef"); 302 set.reference = Integer.toString(fileSetRef); 303 } else { 304 statement.close(); 305 return null; 306 } 307 292 308 } 293 309 catch (SQLException ex){ 294 System. out.println(ex);310 System.err.println("METSFileSet.readSQL() "+ex); 295 311 return null; 296 312 } 297 298 313 // Get child file groups 299 314 select = new GS3SQLSelect("filegroups"); … … 307 322 where.add(whereItem); 308 323 select.setWhere(where); 309 connection.execute(select.toString());310 311 324 // start going through the matching file groups 312 325 try { 313 ResultSet resultSet = connection.getResultSet(); 314 resultSet.first(); 315 do { 316 METSFileGroup filegroup = METSFileGroup.readSQL(document, connection, resultSet); 317 if (filegroup != null) { 318 set.addGroup(filegroup); 319 } 320 } while (resultSet.next()); 326 ResultSet resultSet = statement.executeQuery(select.toString()); 327 if (resultSet.first()) { 328 do { 329 METSFileGroup filegroup = METSFileGroup.readSQL(document, connection, resultSet); 330 if (filegroup != null) { 331 set.addGroup(filegroup); 332 } 333 } while (resultSet.next()); 334 } 335 statement.close(); 321 336 } 322 337 catch (SQLException sqlEx) { 323 System.out.println( sqlEx);338 System.out.println("METSFileSet.readSQL(): "+sqlEx); 324 339 System.exit(1); 325 340 } 326 327 341 return set; 328 342 }
Note:
See TracChangeset
for help on using the changeset viewer.