1 8 package org.jahia.sqlprofiler; 9 10 import java.util.StringTokenizer ; 11 12 21 22 public class QueryEntry implements Comparable { 23 private long time = 0; 24 private long elapsedTime = 0; 25 private String preparedSQL; 26 private String sqlStatement; 27 private String category; 28 private String connectionID; 29 private int receptionRank = 0; 30 31 public QueryEntry() { 32 } 33 34 public QueryEntry(String p6EncodedText) { 35 parseP6Encoding(p6EncodedText); 36 } 37 38 public long getTime() { 39 return time; 40 } 41 42 public void setTime(long time) { 43 this.time = time; 44 } 45 46 public long getElapsedTime() { 47 return elapsedTime; 48 } 49 50 public void setElapsedTime(long elapsedTime) { 51 this.elapsedTime = elapsedTime; 52 } 53 54 public String getPreparedSQL() { 55 return preparedSQL; 56 } 57 58 public void setPreparedSQL(String preparedSQL) { 59 this.preparedSQL = preparedSQL; 60 } 61 62 public String getSqlStatement() { 63 return sqlStatement; 64 } 65 66 public void setSqlStatement(String sqlStatement) { 67 this.sqlStatement = sqlStatement; 68 } 69 70 public String getCategory() { 71 return category; 72 } 73 74 public void setCategory(String category) { 75 this.category = category; 76 } 77 78 public String getConnectionID() { 79 return connectionID; 80 } 81 82 public void setConnectionID(String connectionID) { 83 this.connectionID = connectionID; 84 } 85 86 public int getReceptionRank() { 87 return receptionRank; 88 } 89 public void setReceptionRank(int receptionRank) { 90 this.receptionRank = receptionRank; 91 } 92 93 private void parseP6Encoding(String p6EncodedText) { 94 98 StringTokenizer tokenizer = new StringTokenizer (p6EncodedText, "|", true); 99 String now = tokenizer.nextToken(); 100 if (now.equals("|")) { 101 now = null; 102 } else { 103 tokenizer.nextToken(); 104 } 105 String elapsed = tokenizer.nextToken(); 106 if (elapsed.equals("|")) { 107 elapsed = null; 108 } else { 109 tokenizer.nextToken(); 110 } 111 String connectionID = tokenizer.nextToken(); 112 if (connectionID.equals("|")) { 113 connectionID = null; 114 } else { 115 tokenizer.nextToken(); 116 } 117 String category = tokenizer.nextToken(); 118 if (category.equals("|")) { 119 category = null; 120 } else { 121 tokenizer.nextToken(); 122 } 123 String prepared = tokenizer.nextToken(); 124 if (prepared.equals("|")) { 125 prepared = null; 126 } else { 127 tokenizer.nextToken(); 128 } 129 String sqlStatement = ""; 130 if (tokenizer.hasMoreTokens()) { 131 sqlStatement = tokenizer.nextToken(); 132 } 133 134 this.time = Long.parseLong(now); 135 this.elapsedTime = Long.parseLong(elapsed); 136 this.connectionID = connectionID; 137 this.category = category; 138 this.preparedSQL = prepared; 139 this.sqlStatement = sqlStatement; 140 141 } 142 143 public int compareTo(Object o) { 144 QueryEntry right = (QueryEntry) o; 145 Long leftTime = new Long (getTime()); 146 Long rightTime = new Long (right.getTime()); 147 int timeCompare = leftTime.compareTo(rightTime); 148 if (timeCompare != 0) { 149 return timeCompare; 150 } else { 151 return new Integer (receptionRank).compareTo(new Integer (right.getReceptionRank())); 152 } 153 } 154 155 public boolean equals(Object o) { 156 return (compareTo(o) == 0); 157 } 158 159 public int hashCode() { 160 return (Long.toString(time) + Integer.toString(receptionRank)).hashCode(); 161 } 162 163 } | Popular Tags |