- 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/METSStructure.java
r8742 r9874 10 10 11 11 import java.sql.SQLException; 12 import java.sql.Statement; 12 13 import java.sql.ResultSet; 13 14 … … 180 181 { 181 182 int sqlRef = -1; 182 ResultSet results; 183 183 ResultSet results = null; 184 Statement statement = null; 185 184 186 // Prepare query to see if this structure has already been written 185 187 GS3SQLSelect select = new GS3SQLSelect("structure"); … … 190 192 where.add(item); 191 193 select.setWhere(where); 192 194 193 195 // attempt to execute the query & get the current structure's reference 194 196 try { 195 connection.execute(select.toString()); 196 results = connection.getResultSet(); 197 if (results != null && 198 results.first()){ 197 statement = connection.createStatement(); 198 results = statement.executeQuery(select.toString()); 199 if (results.first()){ 199 200 sqlRef = results.getInt("structureRef"); 200 201 } 201 else {202 results = null;203 }204 205 if (results != null) {206 results.close();207 }208 202 } 209 203 catch (SQLException sqlEx) { 210 System.err.print( sqlEx);204 System.err.print("METSStructure.writeSQL(): "+sqlEx); 211 205 return false; 212 206 } 213 207 214 208 // insert a new structure if it wasn't there previously 215 if ( results == null) {209 if (sqlRef == -1) { 216 210 GS3SQLInsert insert = new GS3SQLInsert("structure"); 217 211 insert.addValue("DocID", document.getID().toString()); … … 220 214 insert.addValue("Label", this.label); 221 215 222 if (!connection.execute(insert.toString())) { 216 try { 217 statement.execute(insert.toString()); 218 219 // get the new structure reference by re-running the original select object 220 results = statement.executeQuery(select.toString()); 221 if (results.first()) { 222 sqlRef = results.getInt("StructureRef"); 223 } 224 } catch (SQLException sqlEx) { 225 System.err.print("METSStructure.writeSQL(): "+sqlEx); 223 226 return false; 224 227 } 225 228 226 // get the new structure reference by re-running the original select object227 connection.execute(select.toString());228 229 try {230 results = connection.getResultSet();231 results.first();232 sqlRef = results.getInt("StructureRef");233 }234 catch (SQLException sql) {235 System.err.println(sql);236 return false;237 }238 229 } 239 230 else { … … 244 235 update.addValue("Label", this.label); 245 236 246 connection.execute(update.toString()); 247 } 248 237 try { 238 statement.execute(update.toString()); 239 } catch (SQLException sqlEx) { 240 System.err.print("METSStructure.writeSQL(): "+sqlEx); 241 return false; 242 } 243 } 244 245 // close the statement 246 try { 247 statement.close(); 248 } catch (SQLException e) { 249 System.err.println("METSStructure.writeSQL(): "+e); 250 } 249 251 // write out the child groups (Divisions) now... 250 252 Iterator groups = this.children.values().iterator(); … … 296 298 select.setWhere(where); 297 299 298 connection.execute(select.toString()); 300 Statement statement = connection.createStatement(); 301 ResultSet divisionSet = statement.executeQuery(select.toString()); 299 302 300 303 // parse through the divisions 301 ResultSet divisionSet = connection.getResultSet(); 302 if (divisionSet != null && divisionSet.first()) { 304 if (divisionSet.first()) { 303 305 do { 304 306 METSDivision division = METSDivision.readSQL(connection, divisionSet); … … 309 311 while (divisionSet.next()); 310 312 } 311 313 statement.close(); 312 314 return structure; 313 315 } 314 catch (SQLException sqlEx) 315 { System.out.println(sqlEx + " " + select.toString());316 catch (SQLException sqlEx) { 317 System.err.println("METSStructure.readSQL(): "+ sqlEx + " " + select.toString()); 316 318 System.exit(1); 317 319 } 318 320 return null; 319 321 }
Note:
See TracChangeset
for help on using the changeset viewer.