Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. /**
  2. * @param entityType
  3. * @param sourceIkey
  4. * @param targetIkey
  5. * @param sourceSchema
  6. * @param targetSchema
  7. * @param elementPrefix
  8. * @param compWhereClausure
  9. * @return
  10. * @throws Exception
  11. */
  12. protected ResultSet calculateAttributeDifferences(String entityType, String keyColumnName, String sourceIkey, String targetIkey,
  13. String sourceSchema, String targetSchema, String elementPrefix,
  14. String compWhereClausure, String additionalFilter
  15. ) throws Exception {
  16.  
  17. String sql = null;
  18. ResultSet rs = null;
  19.  
  20. //The list of columns is calculated yet
  21. if (!strColumnsWithToCharMap.containsKey(elementPrefix)) {
  22. getListOfcolumnsForSelect(elementPrefix);
  23. }
  24.  
  25. String twoValue="targetValue";
  26. String oneValue="sourceValue";
  27.  
  28. if (targetSchema.endsWith("_W.")) {
  29. twoValue="sourceValue";
  30. oneValue="targetValue";
  31. }
  32.  
  33.  
  34. sql = "select col, sourceValue, targetValue" +
  35. " from (" +
  36. " select col," +
  37. " max(case when rn = 2 then val end) as " + twoValue + "," +
  38. " max(case when rn = 1 then val end) as " + oneValue +
  39. " from (" +
  40. " select u.*, row_number() over (partition by u.col order by u." + keyColumnName +") as rn" +
  41. " from (" +
  42. " select " + keyColumnName+ ", " + getStrColumnsWithToChar(elementPrefix) +
  43. " from " + sourceSchema + entityType + " WHERE " + keyColumnName + "=" + sourceIkey + compWhereClausure +
  44. " UNION" +
  45. " select " + keyColumnName+ ", " + getStrColumnsWithToChar(elementPrefix) +
  46. " from " + targetSchema + entityType +" WHERE " + keyColumnName + "=" + targetIkey + compWhereClausure +
  47. " order by " + keyColumnName +
  48. " ) unpivot INCLUDE NULLS (val for col in (" + getStrColumns(elementPrefix) + ")) u" +
  49. " )" +
  50. " group by col" +
  51. " ) where (sourceValue<>targetValue OR (sourceValue is NULL and targetValue is not NULL)) ";
  52. //" OR (sourceValue is not NULL and targetValue is NULL)) ";
  53. if (!TextUtil.isEmpty(additionalFilter)) {
  54. sql += additionalFilter;
  55. }
  56.  
  57. try {
  58.  
  59. // Connect and query to the database
  60. rs = StatementManager.executePreparedQuery(conn, sql);
  61.  
  62.  
  63. } catch (SQLException e) {
  64. throw new SRDBSQLException(e, sql);
  65. } catch (Exception ex) {
  66. throw new SRDBException(ex);
  67. }
  68.  
  69. return rs;
  70.  
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement