1 package jodd.db.profile; 2 3 import java.sql.ResultSet; 4 import java.sql.SQLException; 5 6 import jodd.db.SqlUtil; 7 import jodd.db.pool.ConnectionPool; 8 9 26 public class SqlUtilProfiler extends SqlUtil { 27 28 31 public static SqlProfilerHandler handler = null; 32 33 38 public SqlUtilProfiler(ConnectionPool cp) { 39 super(cp); 40 } 41 42 48 public ResultSet executeQuery() throws SQLException { 49 if (handler == null) { 50 return super.executeQuery(); 51 } 52 SqlProfileData spdata = new SqlProfileData(); 53 spdata.setSqlQuery(this.toString()); 54 long start = System.currentTimeMillis(); 55 ResultSet rs = null; 56 try { 57 spdata.setQueryTime(System.currentTimeMillis()); 58 rs = super.executeQuery(); 59 spdata.setDuration(System.currentTimeMillis() - start); 60 } catch (SQLException sex) { 61 spdata.setDuration(System.currentTimeMillis() - start); 62 throw sex; 63 } finally { 64 handler.onExecuteQuery(spdata); 65 } 66 return rs; 67 } 68 69 75 public int executeUpdate() throws SQLException { 76 if (handler == null) { 77 return super.executeUpdate(); 78 } 79 SqlProfileData spdata = new SqlProfileData(); 80 spdata.setSqlQuery(this.toString()); 81 long start = System.currentTimeMillis(); 82 int r = 0; 83 try { 84 spdata.setQueryTime(System.currentTimeMillis()); 85 r = super.executeUpdate(); 86 spdata.setDuration(System.currentTimeMillis() - start); 87 } catch (SQLException sex) { 88 spdata.setDuration(System.currentTimeMillis() - start); 89 throw sex; 90 } finally { 91 handler.onExecuteUpdate(spdata); 92 } 93 return r; 94 } 95 96 97 } 98 | Popular Tags |