|
45 | 45 | import java.lang.reflect.InvocationTargetException; |
46 | 46 | import java.lang.reflect.Method; |
47 | 47 | import java.net.URISyntaxException; |
| 48 | +import java.sql.Connection; |
48 | 49 | import java.sql.PreparedStatement; |
49 | 50 | import java.sql.ResultSet; |
50 | 51 | import java.sql.SQLException; |
@@ -450,33 +451,7 @@ private <ASPECT extends RecordTemplate> EbeanMetadataAspect queryLatest(@Nonnul |
450 | 451 | return _server.find(EbeanMetadataAspect.class, key); |
451 | 452 | } |
452 | 453 |
|
453 | | - // TODO(@jphui) added for job-gms duplicity debug, throwaway afterwards |
454 | | - |
455 | | - // JDBC sanity check: should MATCH Ebean's results |
456 | | - if (log.isDebugEnabled() && "AzkabanFlowInfo".equals(aspectClass.getSimpleName())) { |
457 | | - final String sqlQuery = "SELECT * FROM metadata_aspect " |
458 | | - + "WHERE urn = ? and aspect = ? and version = 0"; |
459 | | - |
460 | | - try (Transaction transaction = _server.beginTransaction()) { |
461 | | - |
462 | | - // use PreparedStatement |
463 | | - try (PreparedStatement stmt = transaction.getConnection().prepareStatement(sqlQuery)) { |
464 | | - stmt.setString(1, urn.toString()); |
465 | | - stmt.setString(2, aspectName); |
466 | | - |
467 | | - try (ResultSet rset = stmt.executeQuery()) { |
468 | | - rset.last(); // go to the last returned record |
469 | | - log.debug("JDBC found {} existing records", rset.getRow()); |
470 | | - } |
471 | | - } |
472 | | - |
473 | | - transaction.commit(); |
474 | | - } catch (SQLException e) { |
475 | | - log.debug("JDBC ran into a SQLException: {}", e.getMessage()); |
476 | | - } |
477 | | - } |
478 | | - |
479 | | - List<EbeanMetadataAspect> results = Collections.emptyList(); |
| 454 | + List<EbeanMetadataAspect> results; |
480 | 455 | Query<EbeanMetadataAspect> query = Ebean.find(EbeanMetadataAspect.class); // non-null placeholder to be overridden |
481 | 456 |
|
482 | 457 | if (_findMethodology == FindMethodology.DIRECT_SQL) { |
@@ -510,6 +485,24 @@ private <ASPECT extends RecordTemplate> EbeanMetadataAspect queryLatest(@Nonnul |
510 | 485 | aspectName, |
511 | 486 | 0L |
512 | 487 | ); |
| 488 | + final String sqlQuery = "SELECT COUNT(*) AS total_count FROM metadata_aspect " |
| 489 | + + "WHERE urn = ? and aspect = ? and version = 0"; |
| 490 | + |
| 491 | + // use PreparedStatement |
| 492 | + try (Connection connection = _server.getPluginApi().getDataSource().getConnection(); |
| 493 | + PreparedStatement stmt = connection.prepareStatement(sqlQuery)) { |
| 494 | + stmt.setString(1, urn.toString()); |
| 495 | + stmt.setString(2, aspectName); |
| 496 | + try (ResultSet rset = stmt.executeQuery()) { |
| 497 | + int totalCount = 0; |
| 498 | + if (rset.next()) { |
| 499 | + totalCount = rset.getInt("total_count"); |
| 500 | + } |
| 501 | + log.debug("JDBC found {} existing records", totalCount); |
| 502 | + } |
| 503 | + } catch (SQLException e) { |
| 504 | + log.debug("JDBC ran into a SQLException: {}", e.toString()); |
| 505 | + } |
513 | 506 | } |
514 | 507 |
|
515 | 508 | if (results.isEmpty()) { |
|
0 commit comments