| 1 | |
package uk.ac.ebi.intenz.mapper; |
| 2 | |
|
| 3 | |
import java.sql.Connection; |
| 4 | |
import java.sql.PreparedStatement; |
| 5 | |
import java.sql.ResultSet; |
| 6 | |
import java.sql.SQLException; |
| 7 | |
import java.sql.Statement; |
| 8 | |
import java.util.ArrayList; |
| 9 | |
import java.util.List; |
| 10 | |
import java.util.Map; |
| 11 | |
import java.util.Set; |
| 12 | |
import java.util.TreeMap; |
| 13 | |
import java.util.TreeSet; |
| 14 | |
|
| 15 | |
import org.apache.log4j.Logger; |
| 16 | |
|
| 17 | |
import uk.ac.ebi.intenz.domain.constants.EnzymeNameTypeConstant; |
| 18 | |
import uk.ac.ebi.intenz.domain.constants.EnzymeSourceConstant; |
| 19 | |
import uk.ac.ebi.intenz.domain.constants.Status; |
| 20 | |
import uk.ac.ebi.intenz.domain.enzyme.EnzymaticReactions; |
| 21 | |
import uk.ac.ebi.intenz.domain.enzyme.EnzymeComment; |
| 22 | |
import uk.ac.ebi.intenz.domain.enzyme.EnzymeCommissionNumber; |
| 23 | |
import uk.ac.ebi.intenz.domain.enzyme.EnzymeEntry; |
| 24 | |
import uk.ac.ebi.intenz.domain.enzyme.EnzymeLink; |
| 25 | |
import uk.ac.ebi.intenz.domain.enzyme.EnzymeName; |
| 26 | |
import uk.ac.ebi.intenz.domain.exceptions.DomainException; |
| 27 | |
import uk.ac.ebi.intenz.domain.exceptions.EcException; |
| 28 | |
import uk.ac.ebi.intenz.domain.exceptions.EnzymeReactionException; |
| 29 | |
import uk.ac.ebi.intenz.domain.exceptions.EnzymeReferenceException; |
| 30 | |
import uk.ac.ebi.intenz.domain.history.HistoryGraph; |
| 31 | |
import uk.ac.ebi.intenz.domain.reference.Reference; |
| 32 | |
import uk.ac.ebi.intenz.domain.stats.EnzymeStatistics; |
| 33 | |
import uk.ac.ebi.rhea.mapper.MapperException; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | 1 | public class EnzymeEntryMapper { |
| 45 | |
|
| 46 | 1 | private static final Logger LOGGER = Logger.getLogger(EnzymeEntryMapper.class); |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
private static final String COLUMNS = |
| 53 | |
"e.enzyme_id, e.ec1, e.ec2, e.ec3, e.ec4, e.history, e.note, e.status, " + |
| 54 | |
"e.source, e.active, s1.name, s2.name, s3.name"; |
| 55 | |
|
| 56 | |
private static final String LIST_COLUMNS = |
| 57 | |
"enzyme_id, ec1, ec2, ec3, ec4, history, note, status, source, active"; |
| 58 | |
|
| 59 | |
private EnzymeReactionMapper enzymeReactionMapper; |
| 60 | |
|
| 61 | 12 | public EnzymeEntryMapper() { |
| 62 | 12 | enzymeReactionMapper = new EnzymeReactionMapper(); |
| 63 | 12 | } |
| 64 | |
|
| 65 | 0 | public EnzymeEntryMapper(EnzymeReactionMapper enzymeReactionMapper){ |
| 66 | 0 | this.enzymeReactionMapper = enzymeReactionMapper; |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
protected void finalize() throws Throwable { |
| 71 | 4 | close(); |
| 72 | 4 | } |
| 73 | |
|
| 74 | |
public void close() { |
| 75 | 6 | if (enzymeReactionMapper != null){ |
| 76 | |
try { |
| 77 | 6 | enzymeReactionMapper.close(); |
| 78 | 0 | } catch (MapperException e) { |
| 79 | 0 | LOGGER.error("Closing enzymeReactionMapper", e); |
| 80 | 6 | } |
| 81 | |
} |
| 82 | 6 | } |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
private String findByEcStatement() { |
| 90 | 0 | return new StringBuilder("SELECT ").append(COLUMNS) |
| 91 | |
.append(" FROM enzymes e, classes s1, subclasses s2, subsubclasses s3") |
| 92 | |
.append(" WHERE e.ec1 = ? AND e.ec2 = ? AND e.ec3 = ? AND e.ec4 = ?") |
| 93 | |
.append(" AND s1.ec1 = ? AND s2.ec1 = ? AND s2.ec2 = ?") |
| 94 | |
.append(" AND s3.ec1 = ? AND s3.ec2 = ? AND s3.ec3 = ?") |
| 95 | |
.append(" AND e.status = ? AND enzyme_id NOT IN") |
| 96 | |
.append(" (SELECT before_id FROM history_events WHERE event_class = 'MOD')") |
| 97 | |
.toString(); |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
private String findAllSubSubclassEntriesByEcStatement() { |
| 105 | 0 | return new StringBuilder("SELECT ").append(COLUMNS) |
| 106 | |
.append(" FROM enzymes e, classes s1, subclasses s2, subsubclasses s3") |
| 107 | |
.append(" WHERE e.ec1 = ? AND e.ec2 = ? AND e.ec3 = ?") |
| 108 | |
.append(" AND s1.ec1 = ? AND s2.ec1 = ? AND s2.ec2 = ?") |
| 109 | |
.append(" AND s3.ec1 = ? AND s3.ec2 = ? AND s3.ec3 = ? AND e.source = 'INTENZ'") |
| 110 | |
.append(" ORDER BY e.ec1, e.ec2, e.ec3, e.ec4").toString(); |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
private String findAllByEcStatement(Boolean preliminary){ |
| 120 | 0 | StringBuilder sb = new StringBuilder("SELECT ").append(COLUMNS) |
| 121 | |
.append(" FROM enzymes e, classes s1, subclasses s2, subsubclasses s3") |
| 122 | |
.append(" WHERE e.ec1 = ? AND e.ec2 = ? AND e.ec3 = ? AND e.ec4 = ?") |
| 123 | |
.append(" AND s1.ec1 = ? AND s2.ec1 = ? AND s2.ec2 = ?") |
| 124 | |
.append(" AND s3.ec1 = ? AND s3.ec2 = ? AND s3.ec3 = ?"); |
| 125 | 0 | if (preliminary != null){ |
| 126 | 0 | sb.append(" AND e.status ").append(preliminary? "=" : "!=").append(" 'PM'"); |
| 127 | |
} |
| 128 | 0 | return sb.toString(); |
| 129 | |
} |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
private String findByIdStatement() { |
| 137 | 1 | return new StringBuilder("SELECT ").append(COLUMNS) |
| 138 | |
.append(" FROM enzymes e, classes s1, subclasses s2, subsubclasses s3") |
| 139 | |
.append(" WHERE e.enzyme_id = ? AND s1.ec1 = ? AND s2.ec1 = ? AND s2.ec2 = ?") |
| 140 | |
.append(" AND s3.ec1 = ? AND s3.ec2 = ? AND s3.ec3 = ?").toString(); |
| 141 | |
} |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
private String findListStatement() { |
| 152 | 0 | return new StringBuilder("SELECT ").append(LIST_COLUMNS) |
| 153 | |
.append(" FROM enzymes WHERE ec1 = ? AND ec2 = ? AND ec3 = ?") |
| 154 | |
.append(" AND status IN ('OK','PM') AND enzyme_id NOT IN") |
| 155 | |
.append(" (SELECT before_id FROM history_events WHERE event_class = 'MOD')") |
| 156 | |
.append(" ORDER BY status, ec1, ec2, ec3, ec4").toString(); |
| 157 | |
} |
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
private String findAllStatement() { |
| 169 | 0 | return new StringBuilder("SELECT ").append(LIST_COLUMNS) |
| 170 | |
.append(" FROM enzymes WHERE status IN ('OK','PM') AND enzyme_id NOT IN") |
| 171 | |
.append(" (SELECT before_id FROM history_events WHERE event_class = 'MOD')") |
| 172 | |
.append(" ORDER BY ec1, ec2, ec3, status, ec4").toString(); |
| 173 | |
} |
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
private String findCoreListStatement() { |
| 181 | 0 | return new StringBuilder("SELECT ").append(LIST_COLUMNS) |
| 182 | |
.append(" FROM enzymes WHERE status = ?") |
| 183 | |
.append(" ORDER BY ec1, ec2, ec3, ec4").toString(); |
| 184 | |
} |
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
private String findEcStatement() { |
| 191 | 1 | return "SELECT ec1, ec2, ec3, ec4, status FROM enzymes WHERE enzyme_id = ?"; |
| 192 | |
} |
| 193 | |
|
| 194 | |
private String findIDInMappingTable() { |
| 195 | 0 | return "SELECT enzyme_id FROM id2ec WHERE ec = ? and status = ?"; |
| 196 | |
} |
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
private String findHistoryLineStatement() { |
| 204 | 0 | return "SELECT history FROM enzymes WHERE enzyme_id = ?"; |
| 205 | |
} |
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
private String findNoteStatement() { |
| 213 | 0 | return "SELECT note FROM enzymes WHERE enzyme_id = ?"; |
| 214 | |
} |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
private String findNextEnzymeIdStatement() { |
| 222 | 0 | return "SELECT s_enzyme_id.nextval from DUAL"; |
| 223 | |
} |
| 224 | |
|
| 225 | |
private String countIUBMBEnzymesStatement() { |
| 226 | 0 | return new StringBuilder("SELECT status, active FROM enzymes") |
| 227 | |
.append(" WHERE source = 'IUBMB' AND enzyme_id NOT IN") |
| 228 | |
.append(" (SELECT before_id FROM history_events WHERE event_class = 'MOD')") |
| 229 | |
.append(" ORDER BY ec1, ec2, ec3, ec4").toString(); |
| 230 | |
} |
| 231 | |
|
| 232 | |
private String countClassesStatement() { |
| 233 | 0 | return "SELECT count(*) FROM classes"; |
| 234 | |
} |
| 235 | |
|
| 236 | |
private String countSubclassesStatement() { |
| 237 | 0 | return "SELECT count(*) FROM subclasses"; |
| 238 | |
} |
| 239 | |
|
| 240 | |
private String countSubSubclassesStatement() { |
| 241 | 0 | return "SELECT count(*) FROM subsubclasses"; |
| 242 | |
} |
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
private String insertStatement() { |
| 250 | 15 | return "INSERT INTO enzymes (enzyme_id, ec1, ec2, ec3, ec4, history, note, status, source, active)" + |
| 251 | |
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
| 252 | |
} |
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
private String updateStatement() { |
| 260 | 0 | return "UPDATE enzymes SET ec1 = ?, ec2 = ?, ec3 = ?, ec4 = ?, status = ?," + |
| 261 | |
" source = ?, note = ?, history = ?, active = ? WHERE enzyme_id = ?"; |
| 262 | |
} |
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
private String updateEcStatement() { |
| 270 | 0 | return "UPDATE enzymes SET ec1 = ?, ec2 = ?, ec3 = ?, ec4 = ? WHERE enzyme_id = ?"; |
| 271 | |
} |
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
private String updateHistoryLineStatement() { |
| 279 | 0 | return "UPDATE enzymes SET history = ? WHERE enzyme_id = ?"; |
| 280 | |
} |
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
private String updateNoteStatement() { |
| 288 | 0 | return "UPDATE enzymes SET note = ? WHERE enzyme_id = ?"; |
| 289 | |
} |
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
private String updateStatusStatement() { |
| 297 | 0 | return "UPDATE enzymes SET status = ? WHERE enzyme_id = ?"; |
| 298 | |
} |
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
public EnzymeEntry findByEc(int ec1, int ec2, int ec3, int ec4, Status status, |
| 316 | |
Connection con) |
| 317 | |
throws SQLException, DomainException, MapperException { |
| 318 | 0 | PreparedStatement findStatement = null; |
| 319 | 0 | ResultSet rs = null; |
| 320 | 0 | EnzymeEntry result = null; |
| 321 | |
try { |
| 322 | |
|
| 323 | 0 | findStatement = con.prepareStatement(findByEcStatement()); |
| 324 | 0 | findStatement.setInt(1, ec1); |
| 325 | 0 | findStatement.setInt(2, ec2); |
| 326 | 0 | findStatement.setInt(3, ec3); |
| 327 | 0 | findStatement.setInt(4, ec4); |
| 328 | 0 | findStatement.setInt(5, ec1); |
| 329 | 0 | findStatement.setInt(6, ec1); |
| 330 | 0 | findStatement.setInt(7, ec2); |
| 331 | 0 | findStatement.setInt(8, ec1); |
| 332 | 0 | findStatement.setInt(9, ec2); |
| 333 | 0 | findStatement.setInt(10, ec3); |
| 334 | 0 | findStatement.setString(11, status == null? "OK" : status.getCode()); |
| 335 | 0 | rs = findStatement.executeQuery(); |
| 336 | 0 | if (rs.next()) { |
| 337 | 0 | result = doLoad(rs); |
| 338 | 0 | findEnzymeData(result, con); |
| 339 | |
} |
| 340 | |
} finally { |
| 341 | 0 | if (rs != null) rs.close(); |
| 342 | 0 | if (findStatement != null) findStatement.close(); |
| 343 | |
} |
| 344 | |
|
| 345 | 0 | return result; |
| 346 | |
} |
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
public EnzymeEntry findByEc(String ecString, Status status, Connection con) |
| 360 | |
throws NumberFormatException, SQLException, DomainException, MapperException{ |
| 361 | 0 | EnzymeCommissionNumber ec = EnzymeCommissionNumber.valueOf(ecString); |
| 362 | 0 | if (EnzymeCommissionNumber.isPreliminary(ecString)){ |
| 363 | 0 | status = Status.PRELIMINARY; |
| 364 | |
} |
| 365 | 0 | return findByEc(ec.getEc1(), ec.getEc2(), ec.getEc3(), ec.getEc4(), |
| 366 | |
status, con); |
| 367 | |
} |
| 368 | |
|
| 369 | |
public List<EnzymeEntry> findAllByEc(int ec1, int ec2, int ec3, int ec4, |
| 370 | |
Boolean preliminary, Connection con) |
| 371 | |
throws SQLException, DomainException { |
| 372 | 0 | if (con == null) throw new NullPointerException("Parameter 'con' must not be null."); |
| 373 | 0 | PreparedStatement findAllByEcStatement = null; |
| 374 | 0 | ResultSet rs = null; |
| 375 | 0 | List<EnzymeEntry> result = new ArrayList<EnzymeEntry>(); |
| 376 | |
|
| 377 | |
try { |
| 378 | |
|
| 379 | 0 | findAllByEcStatement = con.prepareStatement(findAllByEcStatement(preliminary)); |
| 380 | 0 | findAllByEcStatement.setInt(1, ec1); |
| 381 | 0 | findAllByEcStatement.setInt(2, ec2); |
| 382 | 0 | findAllByEcStatement.setInt(3, ec3); |
| 383 | 0 | findAllByEcStatement.setInt(4, ec4); |
| 384 | 0 | findAllByEcStatement.setInt(5, ec1); |
| 385 | 0 | findAllByEcStatement.setInt(6, ec1); |
| 386 | 0 | findAllByEcStatement.setInt(7, ec2); |
| 387 | 0 | findAllByEcStatement.setInt(8, ec1); |
| 388 | 0 | findAllByEcStatement.setInt(9, ec2); |
| 389 | 0 | findAllByEcStatement.setInt(10, ec3); |
| 390 | 0 | rs = findAllByEcStatement.executeQuery(); |
| 391 | 0 | while (rs.next()) { |
| 392 | 0 | EnzymeEntry enzymeEntry = doLoadGhost(rs); |
| 393 | |
|
| 394 | |
|
| 395 | 0 | loadHistoryGraph(enzymeEntry, con); |
| 396 | |
|
| 397 | |
|
| 398 | 0 | EnzymeNameMapper nameMapper = new EnzymeNameMapper(); |
| 399 | 0 | List<EnzymeName> commonNames = nameMapper.findCommonNames(enzymeEntry.getId(), con); |
| 400 | 0 | if (commonNames != null) enzymeEntry.setCommonNames(commonNames); |
| 401 | |
|
| 402 | 0 | result.add(enzymeEntry); |
| 403 | 0 | } |
| 404 | |
} finally { |
| 405 | 0 | if (rs != null) rs.close(); |
| 406 | 0 | if (findAllByEcStatement != null) findAllByEcStatement.close(); |
| 407 | |
} |
| 408 | |
|
| 409 | 0 | if (result.size() == 0) return null; |
| 410 | 0 | return result; |
| 411 | |
|
| 412 | |
|
| 413 | |
} |
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
public List<EnzymeEntry> findAllByEc(int ec1, int ec2, int ec3, int ec4, Connection con) |
| 430 | |
throws SQLException, DomainException { |
| 431 | 0 | return findAllByEc(ec1, ec2, ec3, ec4, null, con); |
| 432 | |
} |
| 433 | |
|
| 434 | |
private HistoryGraph getHistoryGraph(Connection con, EnzymeEntry enzymeEntry) |
| 435 | |
throws SQLException, DomainException { |
| 436 | |
HistoryGraph historyGraph; |
| 437 | 1 | switch (enzymeEntry.getStatus()){ |
| 438 | |
case PRELIMINARY: |
| 439 | 0 | if (enzymeEntry.isActive()){ |
| 440 | |
|
| 441 | 0 | EnzymeFutureMapper futureEventsMapper = new EnzymeFutureMapper(); |
| 442 | 0 | historyGraph = futureEventsMapper.find(enzymeEntry, con); |
| 443 | 0 | break; |
| 444 | |
} |
| 445 | |
|
| 446 | |
case APPROVED: |
| 447 | 1 | EnzymeHistoryMapper historyEventsMapper = new EnzymeHistoryMapper(); |
| 448 | 1 | historyGraph = historyEventsMapper.find(enzymeEntry, con); |
| 449 | 1 | break; |
| 450 | |
default: |
| 451 | 0 | EnzymeFutureMapper futureEventsMapper = new EnzymeFutureMapper(); |
| 452 | 0 | historyGraph = futureEventsMapper.find(enzymeEntry, con); |
| 453 | |
} |
| 454 | 1 | return historyGraph; |
| 455 | |
} |
| 456 | |
|
| 457 | |
public List<EnzymeEntry> findAllSubSubclassEntriesByEc(int ec1, int ec2, int ec3, Connection con) |
| 458 | |
throws SQLException, DomainException { |
| 459 | 0 | if (con == null) throw new NullPointerException("Parameter 'con' must not be null."); |
| 460 | 0 | PreparedStatement findAllByEcStatement = null; |
| 461 | 0 | ResultSet rs = null; |
| 462 | 0 | Map<EnzymeCommissionNumber, EnzymeEntry> map = |
| 463 | |
new TreeMap<EnzymeCommissionNumber, EnzymeEntry>(); |
| 464 | |
|
| 465 | |
try { |
| 466 | |
|
| 467 | 0 | findAllByEcStatement = con.prepareStatement(findAllSubSubclassEntriesByEcStatement()); |
| 468 | 0 | findAllByEcStatement.setInt(1, ec1); |
| 469 | 0 | findAllByEcStatement.setInt(2, ec2); |
| 470 | 0 | findAllByEcStatement.setInt(3, ec3); |
| 471 | 0 | findAllByEcStatement.setInt(4, ec1); |
| 472 | 0 | findAllByEcStatement.setInt(5, ec1); |
| 473 | 0 | findAllByEcStatement.setInt(6, ec2); |
| 474 | 0 | findAllByEcStatement.setInt(7, ec1); |
| 475 | 0 | findAllByEcStatement.setInt(8, ec2); |
| 476 | 0 | findAllByEcStatement.setInt(9, ec3); |
| 477 | 0 | rs = findAllByEcStatement.executeQuery(); |
| 478 | 0 | while (rs.next()) { |
| 479 | 0 | EnzymeEntry enzymeEntry = doLoadGhost(rs); |
| 480 | 0 | if (map.containsKey(enzymeEntry.getEc())){ |
| 481 | 0 | EnzymeEntry existing = (EnzymeEntry) map.get(enzymeEntry.getEc()); |
| 482 | |
|
| 483 | |
|
| 484 | 0 | if (existing.getId().longValue() > enzymeEntry.getId().longValue()) |
| 485 | 0 | continue; |
| 486 | |
} |
| 487 | |
|
| 488 | 0 | loadHistoryGraph(enzymeEntry, con); |
| 489 | |
|
| 490 | |
|
| 491 | 0 | EnzymeNameMapper nameMapper = new EnzymeNameMapper(); |
| 492 | 0 | List<EnzymeName> commonNames = nameMapper.findCommonNames(enzymeEntry.getId(), con); |
| 493 | 0 | if (commonNames != null) enzymeEntry.setCommonNames(commonNames); |
| 494 | |
|
| 495 | 0 | map.put(enzymeEntry.getEc(), enzymeEntry); |
| 496 | 0 | } |
| 497 | |
} finally { |
| 498 | 0 | if (rs != null) rs.close(); |
| 499 | 0 | if (findAllByEcStatement != null) findAllByEcStatement.close(); |
| 500 | |
} |
| 501 | |
|
| 502 | 0 | return map.isEmpty()? null : new ArrayList<EnzymeEntry>(map.values()); |
| 503 | |
} |
| 504 | |
|
| 505 | |
|
| 506 | |
|
| 507 | |
|
| 508 | |
|
| 509 | |
|
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
public EnzymeEntry findById(Long id, Connection con, boolean ghost) |
| 518 | |
throws SQLException, DomainException, MapperException { |
| 519 | 1 | PreparedStatement findStatement = null; |
| 520 | 1 | EnzymeEntry result = null; |
| 521 | 1 | ResultSet rsEc = null, rs = null; |
| 522 | |
int ec1, ec2, ec3; |
| 523 | |
|
| 524 | |
try { |
| 525 | |
|
| 526 | 1 | findStatement = con.prepareStatement(findEcStatement()); |
| 527 | 1 | findStatement.setLong(1, id.longValue()); |
| 528 | 1 | rsEc = findStatement.executeQuery(); |
| 529 | 1 | if (rsEc.next()) { |
| 530 | 1 | if (rsEc.getInt("ec1") != 0) |
| 531 | 1 | ec1 = rsEc.getInt("ec1"); |
| 532 | |
else |
| 533 | 0 | return result; |
| 534 | 1 | if (rsEc.getInt("ec2") != 0) |
| 535 | 1 | ec2 = rsEc.getInt("ec2"); |
| 536 | |
else |
| 537 | 0 | return result; |
| 538 | 1 | if (rsEc.getInt("ec3") != 0) |
| 539 | 1 | ec3 = rsEc.getInt("ec3"); |
| 540 | |
else |
| 541 | 0 | return result; |
| 542 | |
} else |
| 543 | 0 | return result; |
| 544 | |
|
| 545 | 1 | if (findStatement != null) findStatement.close(); |
| 546 | |
|
| 547 | |
|
| 548 | 1 | findStatement = con.prepareStatement(findByIdStatement()); |
| 549 | 1 | findStatement.setLong(1, id.longValue()); |
| 550 | 1 | findStatement.setInt(2, ec1); |
| 551 | 1 | findStatement.setInt(3, ec1); |
| 552 | 1 | findStatement.setInt(4, ec2); |
| 553 | 1 | findStatement.setInt(5, ec1); |
| 554 | 1 | findStatement.setInt(6, ec2); |
| 555 | 1 | findStatement.setInt(7, ec3); |
| 556 | 1 | rs = findStatement.executeQuery(); |
| 557 | 1 | if (rs.next()) { |
| 558 | 1 | if (ghost){ |
| 559 | 0 | result = doLoadGhost(rs); |
| 560 | |
} else { |
| 561 | 1 | result = doLoad(rs); |
| 562 | 1 | findEnzymeData(result, con); |
| 563 | |
} |
| 564 | |
} |
| 565 | |
} finally { |
| 566 | 1 | if (rsEc != null) rsEc.close(); |
| 567 | 1 | if (rs != null) rs.close(); |
| 568 | 1 | if (findStatement != null) findStatement.close(); |
| 569 | |
} |
| 570 | |
|
| 571 | 1 | return result; |
| 572 | |
} |
| 573 | |
|
| 574 | |
|
| 575 | |
|
| 576 | |
|
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
|
| 582 | |
|
| 583 | |
|
| 584 | |
public EnzymeEntry findById(long id, Connection con) |
| 585 | |
throws SQLException, DomainException, MapperException{ |
| 586 | 1 | return findById(id, con, false); |
| 587 | |
} |
| 588 | |
|
| 589 | |
|
| 590 | |
|
| 591 | |
|
| 592 | |
|
| 593 | |
|
| 594 | |
|
| 595 | |
|
| 596 | |
|
| 597 | |
|
| 598 | |
public EnzymeEntry findGhostById(int id, Connection con) |
| 599 | |
throws SQLException, DomainException { |
| 600 | 0 | EnzymeEntry entry = null; |
| 601 | |
try { |
| 602 | 0 | entry = findById((long) id, con, true); |
| 603 | 0 | } catch (MapperException e) { |
| 604 | |
|
| 605 | 0 | } |
| 606 | 0 | return entry; |
| 607 | |
} |
| 608 | |
|
| 609 | |
public Long findIDInMappingTable(String ec, Status status, Connection con) |
| 610 | |
throws SQLException { |
| 611 | 0 | if (con == null || ec == null) throw new NullPointerException(); |
| 612 | 0 | PreparedStatement findStatement = null; |
| 613 | 0 | ResultSet rs = null; |
| 614 | |
try { |
| 615 | |
|
| 616 | 0 | findStatement = con.prepareStatement(findIDInMappingTable()); |
| 617 | 0 | findStatement.setString(1, ec); |
| 618 | 0 | findStatement.setString(2, status.getCode()); |
| 619 | 0 | rs = findStatement.executeQuery(); |
| 620 | 0 | if (rs.next()) { |
| 621 | 0 | return new Long(rs.getLong(1)); |
| 622 | |
} |
| 623 | 0 | return new Long(-1); |
| 624 | |
} finally { |
| 625 | 0 | if (rs != null) rs.close(); |
| 626 | 0 | if (findStatement != null) findStatement.close(); |
| 627 | |
} |
| 628 | |
} |
| 629 | |
|
| 630 | |
|
| 631 | |
|
| 632 | |
|
| 633 | |
|
| 634 | |
|
| 635 | |
|
| 636 | |
|
| 637 | |
|
| 638 | |
|
| 639 | |
public List<EnzymeEntry> findAll(Connection con) throws SQLException, DomainException { |
| 640 | 0 | Statement findListStatement = null; |
| 641 | 0 | ResultSet rs = null; |
| 642 | 0 | List<EnzymeEntry> result = new ArrayList<EnzymeEntry>(); |
| 643 | 0 | boolean noResult = true; |
| 644 | |
|
| 645 | |
try { |
| 646 | 0 | findListStatement = con.createStatement(); |
| 647 | 0 | rs = findListStatement.executeQuery(findAllStatement()); |
| 648 | |
|
| 649 | 0 | while (rs.next()) { |
| 650 | 0 | noResult = false; |
| 651 | 0 | EnzymeEntry enzymeEntry = doLoadGhost(rs); |
| 652 | |
|
| 653 | |
|
| 654 | 0 | EnzymeNameMapper nameMapper = new EnzymeNameMapper(); |
| 655 | 0 | List<EnzymeName> commonNames = nameMapper.findCommonNames(enzymeEntry.getId(), con); |
| 656 | 0 | if (commonNames != null) enzymeEntry.setCommonNames(commonNames); |
| 657 | 0 | result.add(enzymeEntry); |
| 658 | 0 | } |
| 659 | |
} finally { |
| 660 | 0 | if (rs != null) rs.close(); |
| 661 | 0 | if (findListStatement != null) findListStatement.close(); |
| 662 | |
} |
| 663 | |
|
| 664 | 0 | if (noResult) return null; |
| 665 | 0 | return result; |
| 666 | |
} |
| 667 | |
|
| 668 | |
|
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | |
|
| 674 | |
|
| 675 | |
|
| 676 | |
|
| 677 | |
|
| 678 | |
|
| 679 | |
|
| 680 | |
public List<EnzymeEntry> findList(String ec1, String ec2, String ec3, |
| 681 | |
Connection con) |
| 682 | |
throws SQLException, DomainException { |
| 683 | 0 | PreparedStatement findListStatement = null; |
| 684 | 0 | ResultSet rs = null; |
| 685 | 0 | List<EnzymeEntry> result = new ArrayList<EnzymeEntry>(); |
| 686 | 0 | boolean noResult = true; |
| 687 | |
|
| 688 | |
try { |
| 689 | 0 | findListStatement = con.prepareStatement(findListStatement()); |
| 690 | 0 | findListStatement.setString(1, ec1); |
| 691 | 0 | findListStatement.setString(2, ec2); |
| 692 | 0 | findListStatement.setString(3, ec3); |
| 693 | 0 | rs = findListStatement.executeQuery(); |
| 694 | |
|
| 695 | 0 | while (rs.next()) { |
| 696 | 0 | noResult = false; |
| 697 | 0 | EnzymeEntry enzymeEntry = doLoadGhost(rs); |
| 698 | |
|
| 699 | |
|
| 700 | 0 | loadHistoryGraph(enzymeEntry, con); |
| 701 | |
|
| 702 | |
|
| 703 | 0 | EnzymeNameMapper nameMapper = new EnzymeNameMapper(); |
| 704 | 0 | List<EnzymeName> commonNames = nameMapper.findCommonNames(enzymeEntry.getId(), con); |
| 705 | 0 | if (commonNames != null) enzymeEntry.setCommonNames(commonNames); |
| 706 | 0 | result.add(enzymeEntry); |
| 707 | 0 | } |
| 708 | |
} finally { |
| 709 | 0 | if (rs != null) rs.close(); |
| 710 | 0 | if (findListStatement != null) findListStatement.close(); |
| 711 | |
} |
| 712 | |
|
| 713 | 0 | if (noResult) return null; |
| 714 | 0 | return result; |
| 715 | |
} |
| 716 | |
|
| 717 | |
|
| 718 | |
|
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | |
public List<EnzymeEntry> findByStatus(Connection con, Status status) |
| 726 | |
throws SQLException, DomainException{ |
| 727 | 0 | PreparedStatement findListStatement = null; |
| 728 | 0 | ResultSet rs = null; |
| 729 | 0 | List<EnzymeEntry> result = new ArrayList<EnzymeEntry>(); |
| 730 | |
try { |
| 731 | 0 | findListStatement = con.prepareStatement(findCoreListStatement()); |
| 732 | 0 | findListStatement.setString(1, status.getCode()); |
| 733 | 0 | rs = findListStatement.executeQuery(); |
| 734 | |
|
| 735 | 0 | while (rs.next()) { |
| 736 | 0 | EnzymeEntry enzymeEntry = doLoadGhost(rs); |
| 737 | |
|
| 738 | 0 | loadHistoryGraph(enzymeEntry, con); |
| 739 | |
|
| 740 | 0 | EnzymeNameMapper nameMapper = new EnzymeNameMapper(); |
| 741 | 0 | List<EnzymeName> commonNames = nameMapper.findCommonNames(enzymeEntry.getId(), con); |
| 742 | 0 | if (commonNames != null) enzymeEntry.setCommonNames(commonNames); |
| 743 | 0 | result.add(enzymeEntry); |
| 744 | 0 | } |
| 745 | |
} finally { |
| 746 | 0 | if (rs != null) rs.close(); |
| 747 | 0 | if (findListStatement != null) findListStatement.close(); |
| 748 | |
} |
| 749 | 0 | return result; |
| 750 | |
} |
| 751 | |
|
| 752 | |
|
| 753 | |
|
| 754 | |
|
| 755 | |
|
| 756 | |
|
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
public List<EnzymeEntry> findProposedList(Connection con) |
| 762 | |
throws SQLException, DomainException { |
| 763 | 0 | return findByStatus(con, Status.PROPOSED); |
| 764 | |
} |
| 765 | |
|
| 766 | |
|
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
|
| 773 | |
|
| 774 | |
|
| 775 | |
public List<EnzymeEntry> findSuggestedList(Connection con) |
| 776 | |
throws SQLException, DomainException { |
| 777 | 0 | return findByStatus(con, Status.SUGGESTED); |
| 778 | |
} |
| 779 | |
|
| 780 | |
|
| 781 | |
|
| 782 | |
|
| 783 | |
|
| 784 | |
|
| 785 | |
|
| 786 | |
|
| 787 | |
public List<EnzymeEntry> findPreliminaryEcsList(Connection con) |
| 788 | |
throws SQLException, DomainException{ |
| 789 | 0 | return findByStatus(con, Status.PRELIMINARY); |
| 790 | |
} |
| 791 | |
|
| 792 | |
|
| 793 | |
|
| 794 | |
|
| 795 | |
|
| 796 | |
|
| 797 | |
|
| 798 | |
|
| 799 | |
|
| 800 | |
public List<EnzymeEntry> exportAllEntries(Connection con) |
| 801 | |
throws SQLException, DomainException, MapperException{ |
| 802 | 0 | List<EnzymeEntry> entries = new ArrayList<EnzymeEntry>(); |
| 803 | 0 | Statement findListStatement = null; |
| 804 | 0 | ResultSet rs = null; |
| 805 | |
try { |
| 806 | 0 | findListStatement = con.createStatement(); |
| 807 | 0 | rs = findListStatement.executeQuery(findAllStatement()); |
| 808 | 0 | while (rs.next()){ |
| 809 | 0 | EnzymeEntry entry = doLoadCore(rs); |
| 810 | 0 | findEnzymeData(entry, con); |
| 811 | 0 | entries.add(entry); |
| 812 | 0 | } |
| 813 | |
} finally { |
| 814 | 0 | if (rs != null) rs.close(); |
| 815 | 0 | if (findListStatement != null) findListStatement.close(); |
| 816 | |
} |
| 817 | 0 | return entries.isEmpty()? null : entries; |
| 818 | |
} |
| 819 | |
|
| 820 | |
|
| 821 | |
|
| 822 | |
|
| 823 | |
|
| 824 | |
|
| 825 | |
|
| 826 | |
|
| 827 | |
|
| 828 | |
|
| 829 | |
|
| 830 | |
|
| 831 | |
|
| 832 | |
public List<EnzymeEntry> exportApprovedSibEntries(Connection con) |
| 833 | |
throws SQLException, DomainException, MapperException { |
| 834 | 0 | Statement findListStatement = null; |
| 835 | 0 | ResultSet rs = null; |
| 836 | 0 | List<EnzymeEntry> result = new ArrayList<EnzymeEntry>(); |
| 837 | |
try { |
| 838 | 0 | findListStatement = con.createStatement(); |
| 839 | 0 | rs = findListStatement.executeQuery(findAllStatement()); |
| 840 | 0 | while (rs.next()) { |
| 841 | 0 | EnzymeEntry enzymeEntry = doLoadCore(rs); |
| 842 | 0 | exportSIBEnzymeData(enzymeEntry, con); |
| 843 | 0 | result.add(enzymeEntry); |
| 844 | 0 | } |
| 845 | |
} finally { |
| 846 | 0 | if (rs != null) rs.close(); |
| 847 | 0 | if (findListStatement != null) findListStatement.close(); |
| 848 | |
} |
| 849 | 0 | return result.isEmpty()? null: result; |
| 850 | |
} |
| 851 | |
|
| 852 | |
|
| 853 | |
|
| 854 | |
|
| 855 | |
|
| 856 | |
|
| 857 | |
|
| 858 | |
|
| 859 | |
|
| 860 | |
|
| 861 | |
|
| 862 | |
|
| 863 | |
|
| 864 | |
public List<EnzymeEntry> findFullProposedList(Connection con) |
| 865 | |
throws SQLException, DomainException, MapperException { |
| 866 | 0 | PreparedStatement findListStatement = null; |
| 867 | 0 | ResultSet rs = null; |
| 868 | 0 | List<EnzymeEntry> result = new ArrayList<EnzymeEntry>(); |
| 869 | 0 | boolean noResult = true; |
| 870 | |
|
| 871 | |
try { |
| 872 | 0 | findListStatement = con.prepareStatement(findCoreListStatement()); |
| 873 | 0 | findListStatement.setString(1, "PR"); |
| 874 | 0 | rs = findListStatement.executeQuery(); |
| 875 | |
|
| 876 | 0 | while (rs.next()) { |
| 877 | 0 | noResult = false; |
| 878 | 0 | EnzymeEntry enzymeEntry = doLoadCore(rs); |
| 879 | 0 | findEnzymeData(enzymeEntry, con); |
| 880 | 0 | result.add(enzymeEntry); |
| 881 | 0 | } |
| 882 | |
} finally { |
| 883 | 0 | if (rs != null) rs.close(); |
| 884 | 0 | if (findListStatement != null) findListStatement.close(); |
| 885 | |
} |
| 886 | |
|
| 887 | 0 | if (noResult) return null; |
| 888 | 0 | return result; |
| 889 | |
} |
| 890 | |
|
| 891 | |
|
| 892 | |
|
| 893 | |
|
| 894 | |
|
| 895 | |
|
| 896 | |
|
| 897 | |
|
| 898 | |
|
| 899 | |
|
| 900 | |
|
| 901 | |
|
| 902 | |
|
| 903 | |
public List<EnzymeEntry> findFullSuggestedList(Connection con) |
| 904 | |
throws SQLException, DomainException, MapperException { |
| 905 | 0 | PreparedStatement findListStatement = null; |
| 906 | 0 | ResultSet rs = null; |
| 907 | 0 | List<EnzymeEntry> result = new ArrayList<EnzymeEntry>(); |
| 908 | 0 | boolean noResult = true; |
| 909 | |
|
| 910 | |
try { |
| 911 | 0 | findListStatement = con.prepareStatement(findCoreListStatement()); |
| 912 | 0 | findListStatement.setString(1, "SU"); |
| 913 | 0 | rs = findListStatement.executeQuery(); |
| 914 | |
|
| 915 | 0 | while (rs.next()) { |
| 916 | 0 | noResult = false; |
| 917 | 0 | EnzymeEntry enzymeEntry = doLoadCore(rs); |
| 918 | 0 | findEnzymeData(enzymeEntry, con); |
| 919 | 0 | result.add(enzymeEntry); |
| 920 | 0 | } |
| 921 | |
} finally { |
| 922 | 0 | if (rs != null) rs.close(); |
| 923 | 0 | if (findListStatement != null) findListStatement.close(); |
| 924 | |
} |
| 925 | |
|
| 926 | 0 | if (noResult) return null; |
| 927 | 0 | return result; |
| 928 | |
} |
| 929 | |
|
| 930 | |
|
| 931 | |
|
| 932 | |
|
| 933 | |
|
| 934 | |
|
| 935 | |
|
| 936 | |
|
| 937 | |
|
| 938 | |
|
| 939 | |
public EnzymeCommissionNumber findEC(String id, Connection con) |
| 940 | |
throws SQLException, DomainException { |
| 941 | 0 | int ec1 = 0, ec2 = 0, ec3 = 0, ec4 = 0; |
| 942 | 0 | Status status = null; |
| 943 | 0 | PreparedStatement findEcStatement = null; |
| 944 | 0 | ResultSet rs = null; |
| 945 | |
try { |
| 946 | 0 | findEcStatement = con.prepareStatement(findEcStatement()); |
| 947 | 0 | findEcStatement.setString(1, id); |
| 948 | 0 | rs = findEcStatement.executeQuery(); |
| 949 | |
|
| 950 | 0 | while (rs.next()) { |
| 951 | 0 | ec1 = rs.getInt("ec1"); |
| 952 | 0 | ec2 = rs.getInt("ec2"); |
| 953 | 0 | ec3 = rs.getInt("ec3"); |
| 954 | 0 | ec4 = rs.getInt("ec4"); |
| 955 | 0 | status = Status.fromCode(rs.getString("status")); |
| 956 | |
} |
| 957 | |
} finally { |
| 958 | 0 | if (rs != null) rs.close(); |
| 959 | 0 | if (findEcStatement != null) findEcStatement.close(); |
| 960 | |
} |
| 961 | |
|
| 962 | 0 | return EnzymeCommissionNumber.valueOf( |
| 963 | |
ec1, ec2, ec3, ec4, status.equals(Status.PRELIMINARY)); |
| 964 | |
} |
| 965 | |
|
| 966 | |
|
| 967 | |
|
| 968 | |
|
| 969 | |
|
| 970 | |
|
| 971 | |
|
| 972 | |
|
| 973 | |
|
| 974 | |
|
| 975 | |
public static boolean ecExists(EnzymeCommissionNumber ec, Connection con) |
| 976 | |
throws SQLException { |
| 977 | 0 | if (ec == null) throw new NullPointerException("Parameter 'ec' must not be null."); |
| 978 | 0 | if (con == null) throw new NullPointerException("Parameter 'con' must not be null."); |
| 979 | |
|
| 980 | 0 | PreparedStatement findStatement = null; |
| 981 | 0 | ResultSet rs = null; |
| 982 | |
try { |
| 983 | 1 | switch (ec.getType()) { |
| 984 | |
case CLASS: |
| 985 | 0 | findStatement = con.prepareStatement("SELECT ec1 FROM classes WHERE ec1 = ?"); |
| 986 | 0 | findStatement.setInt(1, ec.getEc1()); |
| 987 | 0 | break; |
| 988 | |
case SUBCLASS: |
| 989 | 0 | findStatement = con.prepareStatement("SELECT ec1 FROM subclasses" + |
| 990 | |
" WHERE ec1 = ? AND ec2 = ?"); |
| 991 | 0 | findStatement.setInt(1, ec.getEc1()); |
| 992 | 0 | findStatement.setInt(2, ec.getEc2()); |
| 993 | 0 | break; |
| 994 | |
case SUBSUBCLASS: |
| 995 | 0 | findStatement = con.prepareStatement("SELECT ec1 FROM subsubclasses" + |
| 996 | |
" WHERE ec1 = ? AND ec2 = ? AND ec3 = ?"); |
| 997 | 0 | findStatement.setInt(1, ec.getEc1()); |
| 998 | 0 | findStatement.setInt(2, ec.getEc2()); |
| 999 | 0 | findStatement.setInt(3, ec.getEc3()); |
| 1000 | 0 | break; |
| 1001 | |
case ENZYME: |
| 1002 | 0 | findStatement = con.prepareStatement("SELECT ec1 FROM enzymes " + |
| 1003 | |
"WHERE ec1 = ? AND ec2 = ? AND ec3 = ? AND ec4 = ? AND status != 'PM'"); |
| 1004 | 0 | findStatement.setInt(1, ec.getEc1()); |
| 1005 | 0 | findStatement.setInt(2, ec.getEc2()); |
| 1006 | 0 | findStatement.setInt(3, ec.getEc3()); |
| 1007 | 0 | findStatement.setInt(4, ec.getEc4()); |
| 1008 | 0 | break; |
| 1009 | |
case PRELIMINARY: |
| 1010 | 0 | findStatement = con.prepareStatement("SELECT ec1 FROM enzymes " + |
| 1011 | |
"WHERE ec1 = ? AND ec2 = ? AND ec3 = ? AND ec4 = ? AND status = 'PM'"); |
| 1012 | 0 | findStatement.setInt(1, ec.getEc1()); |
| 1013 | 0 | findStatement.setInt(2, ec.getEc2()); |
| 1014 | 0 | findStatement.setInt(3, ec.getEc3()); |
| 1015 | 0 | findStatement.setInt(4, ec.getEc4()); |
| 1016 | |
break; |
| 1017 | |
} |
| 1018 | 0 | rs = findStatement.executeQuery(); |
| 1019 | 0 | return rs.next(); |
| 1020 | |
} finally { |
| 1021 | 0 | if (rs != null) rs.close(); |
| 1022 | 0 | if (findStatement != null) findStatement.close(); |
| 1023 | |
} |
| 1024 | |
} |
| 1025 | |
|
| 1026 | |
|
| 1027 | |
|
| 1028 | |
|
| 1029 | |
|
| 1030 | |
|
| 1031 | |
|
| 1032 | |
|
| 1033 | |
|
| 1034 | |
public String findHistoryLine(Long id, Connection con) throws SQLException { |
| 1035 | 0 | String historyLine = ""; |
| 1036 | 0 | PreparedStatement findHistoryLineStatement = null; |
| 1037 | 0 | ResultSet rs = null; |
| 1038 | |
try { |
| 1039 | 0 | findHistoryLineStatement = con.prepareStatement(findHistoryLineStatement()); |
| 1040 | 0 | findHistoryLineStatement.setLong(1, id.longValue()); |
| 1041 | 0 | rs = findHistoryLineStatement.executeQuery(); |
| 1042 | |
|
| 1043 | 0 | while (rs.next()) { |
| 1044 | 0 | if (rs.getString("history") != null) historyLine = rs.getString("history"); |
| 1045 | |
} |
| 1046 | |
} finally { |
| 1047 | 0 | if (rs != null) rs.close(); |
| 1048 | 0 | if (findHistoryLineStatement != null) findHistoryLineStatement.close(); |
| 1049 | |
} |
| 1050 | |
|
| 1051 | 0 | return historyLine; |
| 1052 | |
} |
| 1053 | |
|
| 1054 | |
|
| 1055 | |
|
| 1056 | |
|
| 1057 | |
|
| 1058 | |
|
| 1059 | |
|
| 1060 | |
|
| 1061 | |
|
| 1062 | |
public String findNote(Long id, Connection con) throws SQLException { |
| 1063 | 0 | String note = ""; |
| 1064 | 0 | PreparedStatement findNoteStatement = null; |
| 1065 | 0 | ResultSet rs = null; |
| 1066 | |
|
| 1067 | |
try { |
| 1068 | 0 | findNoteStatement = con.prepareStatement(findNoteStatement()); |
| 1069 | 0 | findNoteStatement.setLong(1, id.longValue()); |
| 1070 | 0 | rs = findNoteStatement.executeQuery(); |
| 1071 | |
|
| 1072 | 0 | while (rs.next()) { |
| 1073 | 0 | if (rs.getString("note") != null) note = rs.getString("note"); |
| 1074 | |
} |
| 1075 | |
} finally { |
| 1076 | 0 | if (rs != null) rs.close(); |
| 1077 | 0 | if (findNoteStatement != null) findNoteStatement.close(); |
| 1078 | |
} |
| 1079 | |
|
| 1080 | 0 | return note; |
| 1081 | |
} |
| 1082 | |
|
| 1083 | |
|
| 1084 | |
|
| 1085 | |
|
| 1086 | |
|
| 1087 | |
|
| 1088 | |
public EnzymeStatistics findStats(Connection con) throws SQLException { |
| 1089 | 0 | PreparedStatement countIUBMBEnzymes = null, countClasses = null, |
| 1090 | 0 | countSubclasses = null, countSubSubclasses = null; |
| 1091 | 0 | EnzymeStatistics result = new EnzymeStatistics(); |
| 1092 | 0 | ResultSet rs = null; |
| 1093 | |
|
| 1094 | 0 | int allEnzymes = 0; |
| 1095 | 0 | int approved = 0; |
| 1096 | 0 | int proposed = 0; |
| 1097 | 0 | int suggested = 0; |
| 1098 | 0 | int approvedDeleted = 0; |
| 1099 | 0 | int proposedDeleted = 0; |
| 1100 | 0 | int suggestedDeleted = 0; |
| 1101 | |
|
| 1102 | |
try { |
| 1103 | 0 | countIUBMBEnzymes = con.prepareStatement(countIUBMBEnzymesStatement()); |
| 1104 | 0 | rs = countIUBMBEnzymes.executeQuery(); |
| 1105 | 0 | while (rs.next()) { |
| 1106 | 0 | allEnzymes++; |
| 1107 | 0 | if (rs.getString(1).equals("OK")) { |
| 1108 | 0 | approved++; |
| 1109 | 0 | if (rs.getString(2).equals("N")) approvedDeleted++; |
| 1110 | |
} |
| 1111 | 0 | if (rs.getString(1).equals("PR")) { |
| 1112 | 0 | proposed++; |
| 1113 | 0 | if (rs.getString(2).equals("N")) proposedDeleted++; |
| 1114 | |
} |
| 1115 | 0 | if (rs.getString(1).equals("SU")) { |
| 1116 | 0 | suggested++; |
| 1117 | 0 | if (rs.getString(2).equals("N")) suggestedDeleted++; |
| 1118 | |
} |
| 1119 | |
} |
| 1120 | |
|
| 1121 | 0 | result.setAllEnzymes(allEnzymes); |
| 1122 | 0 | result.setApprovedEnzymes(approved); |
| 1123 | 0 | result.setApprovedDeletedEnzymes(approvedDeleted); |
| 1124 | 0 | result.setProposedEnzymes(proposed); |
| 1125 | 0 | result.setProposedDeletedEnzymes(proposedDeleted); |
| 1126 | 0 | result.setSuggestedEnzymes(suggested); |
| 1127 | 0 | result.setSuggestedDeletedEnzymes(suggestedDeleted); |
| 1128 | |
|
| 1129 | 0 | countClasses = con.prepareStatement(countClassesStatement()); |
| 1130 | 0 | rs = countClasses.executeQuery(); |
| 1131 | 0 | if (rs.next()) { |
| 1132 | 0 | result.setClasses(rs.getInt(1)); |
| 1133 | |
} |
| 1134 | |
|
| 1135 | 0 | countSubclasses = con.prepareStatement(countSubclassesStatement()); |
| 1136 | 0 | rs = countSubclasses.executeQuery(); |
| 1137 | 0 | if (rs.next()) { |
| 1138 | 0 | result.setSubclasses(rs.getInt(1)); |
| 1139 | |
} |
| 1140 | |
|
| 1141 | 0 | countSubSubclasses = con.prepareStatement(countSubSubclassesStatement()); |
| 1142 | 0 | rs = countSubSubclasses.executeQuery(); |
| 1143 | 0 | if (rs.next()) { |
| 1144 | 0 | result.setSubsubclasses(rs.getInt(1)); |
| 1145 | |
} |
| 1146 | |
|
| 1147 | |
} finally { |
| 1148 | 0 | if (rs != null) rs.close(); |
| 1149 | 0 | countIUBMBEnzymes.close(); |
| 1150 | 0 | countClasses.close(); |
| 1151 | 0 | countSubclasses.close(); |
| 1152 | 0 | countSubSubclasses.close(); |
| 1153 | 0 | } |
| 1154 | |
|
| 1155 | 0 | return result; |
| 1156 | |
} |
| 1157 | |
|
| 1158 | |
|
| 1159 | |
|
| 1160 | |
|
| 1161 | |
|
| 1162 | |
|
| 1163 | |
|
| 1164 | |
|
| 1165 | |
|
| 1166 | |
|
| 1167 | |
|
| 1168 | |
|
| 1169 | |
|
| 1170 | |
|
| 1171 | |
|
| 1172 | |
|
| 1173 | |
|
| 1174 | |
|
| 1175 | |
public void insert(Long enzymeId, EnzymeCommissionNumber ec, Status status, |
| 1176 | |
EnzymeSourceConstant source, String note, String historyLine, |
| 1177 | |
boolean isActive, Connection con) |
| 1178 | |
throws SQLException { |
| 1179 | 15 | PreparedStatement insertStatement = null; |
| 1180 | |
try { |
| 1181 | 15 | insertStatement = con.prepareStatement(insertStatement()); |
| 1182 | 15 | insertStatement.setLong(1, enzymeId.longValue()); |
| 1183 | 15 | insertStatement.setInt(2, ec.getEc1()); |
| 1184 | 15 | insertStatement.setInt(3, ec.getEc2()); |
| 1185 | 15 | insertStatement.setInt(4, ec.getEc3()); |
| 1186 | 15 | insertStatement.setInt(5, ec.getEc4()); |
| 1187 | 15 | insertStatement.setString(6, historyLine); |
| 1188 | 15 | insertStatement.setString(7, note); |
| 1189 | 15 | insertStatement.setString(8, status.getCode()); |
| 1190 | 15 | insertStatement.setString(9, source.toString()); |
| 1191 | 15 | insertStatement.setString(10, isActive ? "Y" : "N"); |
| 1192 | 15 | insertStatement.execute(); |
| 1193 | |
} finally { |
| 1194 | 15 | insertStatement.close(); |
| 1195 | 15 | } |
| 1196 | 15 | } |
| 1197 | |
|
| 1198 | |
|
| 1199 | |
|
| 1200 | |
|
| 1201 | |
|
| 1202 | |
|
| 1203 | |
|
| 1204 | |
|
| 1205 | |
|
| 1206 | |
|
| 1207 | |
|
| 1208 | |
|
| 1209 | |
|
| 1210 | |
|
| 1211 | |
|
| 1212 | |
|
| 1213 | |
|
| 1214 | |
|
| 1215 | |
|
| 1216 | |
|
| 1217 | |
|
| 1218 | |
public void update(Long enzymeId, EnzymeCommissionNumber ec, Status status, |
| 1219 | |
EnzymeSourceConstant source, String note, String historyLine, |
| 1220 | |
boolean active, Connection con) |
| 1221 | |
throws SQLException { |
| 1222 | 0 | if (enzymeId == null) throw new NullPointerException("Parameter 'enzymeId' must not be null."); |
| 1223 | 0 | if (ec == null) throw new NullPointerException("Parameter 'ec' must not be null."); |
| 1224 | 0 | if (status == null) throw new NullPointerException("Parameter 'status' must not be null."); |
| 1225 | 0 | if (source == null) throw new NullPointerException("Parameter 'source' must not be null."); |
| 1226 | 0 | if (note == null) throw new NullPointerException("Parameter 'note' must not be null."); |
| 1227 | 0 | if (historyLine == null) throw new NullPointerException("Parameter 'historyLine' must not be null."); |
| 1228 | 0 | if (con == null) throw new NullPointerException("Parameter 'con' must not be null."); |
| 1229 | |
|
| 1230 | 0 | PreparedStatement updateStatement = null; |
| 1231 | |
try { |
| 1232 | 0 | updateStatement = con.prepareStatement(updateStatement()); |
| 1233 | 0 | updateStatement.setInt(1, ec.getEc1()); |
| 1234 | 0 | updateStatement.setInt(2, ec.getEc2()); |
| 1235 | 0 | updateStatement.setInt(3, ec.getEc3()); |
| 1236 | 0 | updateStatement.setInt(4, ec.getEc4()); |
| 1237 | 0 | updateStatement.setString(5, status.getCode()); |
| 1238 | 0 | updateStatement.setString(6, source.toString()); |
| 1239 | 0 | updateStatement.setString(7, note); |
| 1240 | 0 | updateStatement.setString(8, historyLine); |
| 1241 | 0 | updateStatement.setString(9, active? "Y" : "N"); |
| 1242 | 0 | updateStatement.setLong(10, enzymeId.longValue()); |
| 1243 | 0 | updateStatement.execute(); |
| 1244 | |
} finally { |
| 1245 | 0 | updateStatement.close(); |
| 1246 | 0 | } |
| 1247 | 0 | } |
| 1248 | |
|
| 1249 | |
|
| 1250 | |
|
| 1251 | |
|
| 1252 | |
|
| 1253 | |
|
| 1254 | |
|
| 1255 | |
|
| 1256 | |
|
| 1257 | |
public void updateEc(Long enzymeId, EnzymeCommissionNumber newEc, Connection con) throws SQLException { |
| 1258 | 0 | PreparedStatement updateEcStatement = null; |
| 1259 | |
|
| 1260 | |
try { |
| 1261 | 0 | updateEcStatement = con.prepareStatement(updateEcStatement()); |
| 1262 | 0 | updateEcStatement.setInt(1, newEc.getEc1()); |
| 1263 | 0 | updateEcStatement.setInt(2, newEc.getEc2()); |
| 1264 | 0 | updateEcStatement.setInt(3, newEc.getEc3()); |
| 1265 | 0 | updateEcStatement.setInt(4, newEc.getEc4()); |
| 1266 | 0 | updateEcStatement.setLong(5, enzymeId.longValue()); |
| 1267 | 0 | updateEcStatement.execute(); |
| 1268 | |
} finally { |
| 1269 | 0 | updateEcStatement.close(); |
| 1270 | 0 | } |
| 1271 | 0 | } |
| 1272 | |
|
| 1273 | |
|
| 1274 | |
|
| 1275 | |
|
| 1276 | |
|
| 1277 | |
|
| 1278 | |
|
| 1279 | |
|
| 1280 | |
|
| 1281 | |
public void updateNote(Long enzymeId, String note, Connection con) throws SQLException { |
| 1282 | 0 | PreparedStatement updateNoteStatement = null; |
| 1283 | |
|
| 1284 | |
try { |
| 1285 | 0 | updateNoteStatement = con.prepareStatement(updateNoteStatement()); |
| 1286 | 0 | updateNoteStatement.setString(1, note); |
| 1287 | 0 | updateNoteStatement.setLong(2, enzymeId.longValue()); |
| 1288 | 0 | updateNoteStatement.execute(); |
| 1289 | |
} finally { |
| 1290 | 0 | updateNoteStatement.close(); |
| 1291 | 0 | } |
| 1292 | 0 | } |
| 1293 | |
|
| 1294 | |
|
| 1295 | |
|
| 1296 | |
|
| 1297 | |
|
| 1298 | |
|
| 1299 | |
|
| 1300 | |
|
| 1301 | |
|
| 1302 | |
public void updateStatus(Long enzymeId, Status status, Connection con) throws SQLException { |
| 1303 | 0 | PreparedStatement updateStatusStatement = null; |
| 1304 | |
|
| 1305 | |
try { |
| 1306 | 0 | updateStatusStatement = con.prepareStatement(updateStatusStatement()); |
| 1307 | 0 | updateStatusStatement.setString(1, status.getCode()); |
| 1308 | 0 | updateStatusStatement.setLong(2, enzymeId.longValue()); |
| 1309 | 0 | updateStatusStatement.execute(); |
| 1310 | |
} finally { |
| 1311 | 0 | updateStatusStatement.close(); |
| 1312 | 0 | } |
| 1313 | 0 | } |
| 1314 | |
|
| 1315 | |
|
| 1316 | |
|
| 1317 | |
|
| 1318 | |
|
| 1319 | |
|
| 1320 | |
|
| 1321 | |
|
| 1322 | |
|
| 1323 | |
public void updateHistoryLine(Long enzymeId, String historyLine, Connection con) throws SQLException { |
| 1324 | 0 | PreparedStatement updateHistoryLineStatement = null; |
| 1325 | |
|
| 1326 | |
try { |
| 1327 | 0 | updateHistoryLineStatement = con.prepareStatement(updateHistoryLineStatement()); |
| 1328 | 0 | updateHistoryLineStatement.setString(1, historyLine); |
| 1329 | 0 | updateHistoryLineStatement.setLong(2, enzymeId.longValue()); |
| 1330 | 0 | updateHistoryLineStatement.execute(); |
| 1331 | |
} finally { |
| 1332 | 0 | updateHistoryLineStatement.close(); |
| 1333 | 0 | } |
| 1334 | 0 | } |
| 1335 | |
|
| 1336 | |
|
| 1337 | |
|
| 1338 | |
|
| 1339 | |
|
| 1340 | |
|
| 1341 | |
|
| 1342 | |
|
| 1343 | |
|
| 1344 | |
public boolean cloneExists(Long id, Connection con) throws SQLException { |
| 1345 | 0 | EnzymeFutureMapper futureEventsMapper = new EnzymeFutureMapper(); |
| 1346 | 0 | return futureEventsMapper.futureEventExists(id, con); |
| 1347 | |
} |
| 1348 | |
|
| 1349 | |
|
| 1350 | |
|
| 1351 | |
|
| 1352 | |
|
| 1353 | |
|
| 1354 | |
|
| 1355 | |
|
| 1356 | |
|
| 1357 | |
|
| 1358 | |
|
| 1359 | |
|
| 1360 | |
private EnzymeEntry doLoad(ResultSet rs) throws SQLException, EcException { |
| 1361 | 1 | Long enzymeId = null; |
| 1362 | 1 | int ec1 = 0; |
| 1363 | 1 | int ec2 = 0; |
| 1364 | 1 | int ec3 = 0; |
| 1365 | 1 | int ec4 = 0; |
| 1366 | 1 | String history = ""; |
| 1367 | 1 | String note = ""; |
| 1368 | 1 | String status = ""; |
| 1369 | 1 | String source = ""; |
| 1370 | 1 | String active = ""; |
| 1371 | 1 | String className = ""; |
| 1372 | 1 | String subclassName = ""; |
| 1373 | 1 | String subSubclassName = ""; |
| 1374 | |
|
| 1375 | 1 | if (rs.getInt(1) > 0) enzymeId = new Long(rs.getLong(1)); |
| 1376 | 1 | if (rs.getInt(2) > 0) ec1 = rs.getInt(2); |
| 1377 | 1 | if (rs.getInt(3) > 0) ec2 = rs.getInt(3); |
| 1378 | 1 | if (rs.getInt(4) > 0) ec3 = rs.getInt(4); |
| 1379 | 1 | if (rs.getInt(5) > 0) ec4 = rs.getInt(5); |
| 1380 | 1 | if (rs.getString(6) != null) history = rs.getString(6); |
| 1381 | 1 | if (rs.getString(7) != null) note = rs.getString(7); |
| 1382 | 1 | if (rs.getString(8) != null) status = rs.getString(8); |
| 1383 | 1 | if (rs.getString(9) != null) source = rs.getString(9); |
| 1384 | 1 | if (rs.getString(10) != null) active = rs.getString(10); |
| 1385 | 1 | if (rs.getString(11) != null) className = rs.getString(11); |
| 1386 | 1 | if (rs.getString(12) != null) subclassName = rs.getString(12); |
| 1387 | 1 | if (rs.getString(13) != null) subSubclassName = rs.getString(13); |
| 1388 | |
|
| 1389 | 1 | EnzymeEntry enzymeEntry = new EnzymeEntry(); |
| 1390 | 1 | Status st = Status.fromCode(status); |
| 1391 | 1 | enzymeEntry.setId(enzymeId); |
| 1392 | 1 | EnzymeCommissionNumber ec = EnzymeCommissionNumber.valueOf( |
| 1393 | |
ec1, ec2, ec3, ec4, st.equals(Status.PRELIMINARY)); |
| 1394 | 1 | enzymeEntry.setEc(ec); |
| 1395 | 1 | enzymeEntry.getHistory().getRootNode().setHistoryLine(history); |
| 1396 | 1 | enzymeEntry.setNote(note); |
| 1397 | 1 | enzymeEntry.setStatus(st); |
| 1398 | 1 | enzymeEntry.setSource(EnzymeSourceConstant.valueOf(source)); |
| 1399 | 1 | enzymeEntry.setActive(active.charAt(0) == 'Y'); |
| 1400 | 1 | enzymeEntry.setSubSubclassName(subSubclassName); |
| 1401 | 1 | enzymeEntry.setSubclassName(subclassName); |
| 1402 | 1 | enzymeEntry.setClassName(className); |
| 1403 | |
|
| 1404 | 1 | return enzymeEntry; |
| 1405 | |
} |
| 1406 | |
|
| 1407 | |
|
| 1408 | |
|
| 1409 | |
|
| 1410 | |
|
| 1411 | |
|
| 1412 | |
|
| 1413 | |
|
| 1414 | |
|
| 1415 | |
private EnzymeEntry doLoadCore(ResultSet rs) throws SQLException, DomainException { |
| 1416 | 0 | Long enzymeId = null; |
| 1417 | 0 | int ec1 = 0; |
| 1418 | 0 | int ec2 = 0; |
| 1419 | 0 | int ec3 = 0; |
| 1420 | 0 | int ec4 = 0; |
| 1421 | 0 | String history = ""; |
| 1422 | 0 | String note = ""; |
| 1423 | 0 | String status = ""; |
| 1424 | 0 | String source = ""; |
| 1425 | 0 | String active = ""; |
| 1426 | |
|
| 1427 | 0 | if (rs.getInt(1) > 0) enzymeId = new Long(rs.getLong(1)); |
| 1428 | 0 | if (rs.getInt(2) > 0) ec1 = rs.getInt(2); |
| 1429 | 0 | if (rs.getInt(3) > 0) ec2 = rs.getInt(3); |
| 1430 | 0 | if (rs.getInt(4) > 0) ec3 = rs.getInt(4); |
| 1431 | 0 | if (rs.getInt(5) > 0) ec4 = rs.getInt(5); |
| 1432 | 0 | if (rs.getString(6) != null) history = rs.getString(6); |
| 1433 | 0 | if (rs.getString(7) != null) note = rs.getString(7); |
| 1434 | 0 | if (rs.getString(8) != null) status = rs.getString(8); |
| 1435 | 0 | if (rs.getString(9) != null) source = rs.getString(9); |
| 1436 | 0 | if (rs.getString(10) != null) active = rs.getString(10); |
| 1437 | |
|
| 1438 | 0 | EnzymeEntry enzymeEntry = new EnzymeEntry(); |
| 1439 | 0 | enzymeEntry.setId(enzymeId); |
| 1440 | 0 | Status st = Status.fromCode(status); |
| 1441 | 0 | EnzymeCommissionNumber ec = EnzymeCommissionNumber.valueOf( |
| 1442 | |
ec1, ec2, ec3, ec4, st.equals(Status.PRELIMINARY)); |
| 1443 | 0 | enzymeEntry.setEc(ec); |
| 1444 | 0 | enzymeEntry.getHistory().getRootNode().setHistoryLine(history); |
| 1445 | 0 | enzymeEntry.setNote(note); |
| 1446 | 0 | enzymeEntry.setStatus(st); |
| 1447 | 0 | enzymeEntry.setSource(EnzymeSourceConstant.valueOf(source)); |
| 1448 | 0 | enzymeEntry.setActive(active.charAt(0) == 'Y'); |
| 1449 | |
|
| 1450 | 0 | return enzymeEntry; |
| 1451 | |
} |
| 1452 | |
|
| 1453 | |
|
| 1454 | |
|
| 1455 | |
|
| 1456 | |
|
| 1457 | |
|
| 1458 | |
|
| 1459 | |
|
| 1460 | |
private void doLoadNames(EnzymeEntry entry, List<EnzymeName> names) throws DomainException { |
| 1461 | 14 | for (int iii = 0; iii < names.size(); iii++) { |
| 1462 | 13 | EnzymeName enzymeName = names.get(iii); |
| 1463 | 13 | if (enzymeName.getType().equals(EnzymeNameTypeConstant.COMMON_NAME)) { |
| 1464 | 1 | entry.addCommonName(enzymeName); |
| 1465 | |
} |
| 1466 | 13 | if (enzymeName.getType().equals(EnzymeNameTypeConstant.SYSTEMATIC_NAME)) { |
| 1467 | 1 | entry.setSystematicName(enzymeName); |
| 1468 | |
} |
| 1469 | 13 | if (enzymeName.getType().equals(EnzymeNameTypeConstant.OTHER_NAME)) { |
| 1470 | 11 | entry.addSynonym(enzymeName); |
| 1471 | |
} |
| 1472 | |
} |
| 1473 | 1 | } |
| 1474 | |
|
| 1475 | |
|
| 1476 | |
|
| 1477 | |
|
| 1478 | |
|
| 1479 | |
|
| 1480 | |
|
| 1481 | |
|
| 1482 | |
private EnzymeEntry doLoadGhost(ResultSet rs) throws SQLException, DomainException { |
| 1483 | 0 | Long enzymeId = null; |
| 1484 | 0 | int ec1 = 0; |
| 1485 | 0 | int ec2 = 0; |
| 1486 | 0 | int ec3 = 0; |
| 1487 | 0 | int ec4 = 0; |
| 1488 | 0 | String status = ""; |
| 1489 | 0 | String source = ""; |
| 1490 | 0 | String active = ""; |
| 1491 | 0 | String history = ""; |
| 1492 | |
|
| 1493 | 0 | if (rs.getInt("enzyme_id") > 0) enzymeId = new Long(rs.getLong("enzyme_id")); |
| 1494 | 0 | if (rs.getInt("ec1") > 0) ec1 = rs.getInt("ec1"); |
| 1495 | 0 | if (rs.getInt("ec2") > 0) ec2 = rs.getInt("ec2"); |
| 1496 | 0 | if (rs.getInt("ec3") > 0) ec3 = rs.getInt("ec3"); |
| 1497 | 0 | if (rs.getInt("ec4") > 0) ec4 = rs.getInt("ec4"); |
| 1498 | 0 | if (rs.getString("history") != null) history = rs.getString("history"); |
| 1499 | 0 | if (rs.getString("status") != null) status = rs.getString("status"); |
| 1500 | 0 | if (rs.getString("source") != null) source = rs.getString("source"); |
| 1501 | 0 | if (rs.getString("active") != null) active = rs.getString("active"); |
| 1502 | |
|
| 1503 | 0 | EnzymeEntry enzymeEntry = new EnzymeEntry(); |
| 1504 | 0 | Status st = Status.fromCode(status); |
| 1505 | 0 | enzymeEntry.setId(enzymeId); |
| 1506 | 0 | EnzymeCommissionNumber ec = EnzymeCommissionNumber.valueOf( |
| 1507 | |
ec1, ec2, ec3, ec4, st.equals(Status.PRELIMINARY)); |
| 1508 | 0 | enzymeEntry.setEc(ec); |
| 1509 | 0 | enzymeEntry.getHistory().getRootNode().setHistoryLine(history); |
| 1510 | 0 | enzymeEntry.setStatus(st); |
| 1511 | 0 | if (!source.equals("")) enzymeEntry.setSource(EnzymeSourceConstant.valueOf(source)); |
| 1512 | 0 | if (!active.equals("")) enzymeEntry.setActive(active.charAt(0) == 'Y'); |
| 1513 | 0 | enzymeEntry.setGhost(true); |
| 1514 | 0 | return enzymeEntry; |
| 1515 | |
} |
| 1516 | |
|
| 1517 | |
|
| 1518 | |
|
| 1519 | |
|
| 1520 | |
|
| 1521 | |
|
| 1522 | |
|
| 1523 | |
|
| 1524 | |
|
| 1525 | |
private void findEnzymeData(EnzymeEntry enzymeEntry, Connection con) |
| 1526 | |
throws SQLException, DomainException, EnzymeReactionException, |
| 1527 | |
EnzymeReferenceException, MapperException { |
| 1528 | 1 | loadHistoryGraph(enzymeEntry, con); |
| 1529 | |
|
| 1530 | |
|
| 1531 | 1 | EnzymeNameMapper nameMapper = new EnzymeNameMapper(); |
| 1532 | 1 | List<EnzymeName> names = nameMapper.find(enzymeEntry.getId(), con); |
| 1533 | 1 | if (names != null) doLoadNames(enzymeEntry, names); |
| 1534 | |
|
| 1535 | |
|
| 1536 | 1 | EnzymaticReactions reactions = |
| 1537 | |
enzymeReactionMapper.find(enzymeEntry.getId(), con); |
| 1538 | 1 | if (reactions != null) enzymeEntry.setEnzymaticReactions(reactions); |
| 1539 | |
|
| 1540 | |
|
| 1541 | 1 | EnzymeCofactorMapper cofactorMapper = new EnzymeCofactorMapper(); |
| 1542 | 1 | Set<Object> cofactors = cofactorMapper.find(enzymeEntry.getId(), con); |
| 1543 | 1 | cofactorMapper.close(); |
| 1544 | 1 | if (cofactors != null) enzymeEntry.setCofactors(cofactors); |
| 1545 | |
|
| 1546 | |
|
| 1547 | 1 | EnzymeLinkMapper linkMapper = new EnzymeLinkMapper(); |
| 1548 | 1 | List<EnzymeLink> links = linkMapper.find(enzymeEntry.getId(), con); |
| 1549 | 1 | if (links != null) { |
| 1550 | 1 | enzymeEntry.setLinks(new TreeSet<EnzymeLink>(links)); |
| 1551 | |
} |
| 1552 | |
|
| 1553 | |
|
| 1554 | 1 | EnzymeCommentMapper commentMapper = new EnzymeCommentMapper(); |
| 1555 | 1 | List<EnzymeComment> comments = commentMapper.find(enzymeEntry.getId(), con); |
| 1556 | 1 | if (comments != null) enzymeEntry.setComments(comments); |
| 1557 | |
|
| 1558 | |
|
| 1559 | 1 | EnzymeReferenceMapper referenceMapper = new EnzymeReferenceMapper(); |
| 1560 | 1 | List<Reference> references = referenceMapper.find(enzymeEntry.getId(), con); |
| 1561 | 1 | if (references != null) enzymeEntry.setReferences(references); |
| 1562 | 1 | } |
| 1563 | |
|
| 1564 | |
|
| 1565 | |
|
| 1566 | |
|
| 1567 | |
|
| 1568 | |
|
| 1569 | |
|
| 1570 | |
|
| 1571 | |
|
| 1572 | |
|
| 1573 | |
|
| 1574 | |
|
| 1575 | |
|
| 1576 | |
private void exportSIBEnzymeData(EnzymeEntry enzymeEntry, Connection con) |
| 1577 | |
throws SQLException, DomainException, |
| 1578 | |
EnzymeReactionException, MapperException { |
| 1579 | 0 | assert enzymeEntry != null : "Parameter 'enzymeEntry' must not be null."; |
| 1580 | 0 | assert con != null : "Parameter 'con' must not be null."; |
| 1581 | |
|
| 1582 | 0 | loadHistoryGraph(enzymeEntry, con); |
| 1583 | |
|
| 1584 | |
|
| 1585 | 0 | EnzymeNameMapper nameMapper = new EnzymeNameMapper(); |
| 1586 | 0 | List<EnzymeName> names = nameMapper.exportSibNames(enzymeEntry.getId(), con); |
| 1587 | 0 | if (names != null) doLoadNames(enzymeEntry, names); |
| 1588 | |
|
| 1589 | |
|
| 1590 | 0 | EnzymaticReactions reactions = |
| 1591 | |
enzymeReactionMapper.exportSibReactions(enzymeEntry.getId(), con); |
| 1592 | 0 | if (reactions != null) enzymeEntry.setEnzymaticReactions(reactions); |
| 1593 | |
|
| 1594 | |
|
| 1595 | 0 | EnzymeCofactorMapper cofactorMapper = new EnzymeCofactorMapper(); |
| 1596 | 0 | Set<Object> cofactors = cofactorMapper.exportSibCofactors(enzymeEntry.getId(), con); |
| 1597 | 0 | cofactorMapper.close(); |
| 1598 | 0 | if (cofactors != null) enzymeEntry.setCofactors(cofactors); |
| 1599 | |
|
| 1600 | |
|
| 1601 | 0 | EnzymeLinkMapper linkMapper = new EnzymeLinkMapper(); |
| 1602 | 0 | List<EnzymeLink> links = linkMapper.exportSibLinks(enzymeEntry.getId(), con); |
| 1603 | 0 | if (links != null) |
| 1604 | 0 | enzymeEntry.setLinks(new TreeSet<EnzymeLink>(links)); |
| 1605 | |
|
| 1606 | |
|
| 1607 | 0 | EnzymeCommentMapper commentMapper = new EnzymeCommentMapper(); |
| 1608 | 0 | List<EnzymeComment> comments = commentMapper.exportSibComments(enzymeEntry.getId(), con); |
| 1609 | 0 | if (comments != null) enzymeEntry.setComments(comments); |
| 1610 | 0 | } |
| 1611 | |
|
| 1612 | |
|
| 1613 | |
|
| 1614 | |
|
| 1615 | |
|
| 1616 | |
|
| 1617 | |
|
| 1618 | |
|
| 1619 | |
public Long findNextEnzymeId(Connection con) throws SQLException { |
| 1620 | 0 | if (con == null) throw new NullPointerException("Parameter 'con' must not be null."); |
| 1621 | 0 | long enzymeId = 0; |
| 1622 | 0 | PreparedStatement findNextEnzymeId = null; |
| 1623 | |
|
| 1624 | |
try { |
| 1625 | 0 | findNextEnzymeId = con.prepareStatement(findNextEnzymeIdStatement()); |
| 1626 | 0 | ResultSet rs = findNextEnzymeId.executeQuery(); |
| 1627 | 0 | if (rs.next()) { |
| 1628 | 0 | enzymeId = rs.getLong(1); |
| 1629 | |
} |
| 1630 | |
} finally { |
| 1631 | 0 | findNextEnzymeId.close(); |
| 1632 | 0 | } |
| 1633 | |
|
| 1634 | 0 | return new Long(enzymeId); |
| 1635 | |
} |
| 1636 | |
|
| 1637 | |
private void loadHistoryGraph(EnzymeEntry enzymeEntry, Connection con) |
| 1638 | |
throws SQLException, DomainException { |
| 1639 | 1 | HistoryGraph historyGraph = getHistoryGraph(con, enzymeEntry); |
| 1640 | 1 | if (historyGraph != null) enzymeEntry.setHistory(historyGraph); |
| 1641 | 1 | } |
| 1642 | |
|
| 1643 | |
} |