1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package net.admin4j.jdbc.driver; |
15 | |
|
16 | |
import java.util.Collection; |
17 | |
|
18 | |
import net.admin4j.deps.commons.lang3.Validate; |
19 | |
import net.admin4j.entity.ExecutionStack; |
20 | |
import net.admin4j.timer.BasicTaskTimer; |
21 | |
import net.admin4j.timer.DataMeasure; |
22 | |
import net.admin4j.util.Admin4jRuntimeException; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class SqlTaskTimer extends BasicTaskTimer { |
30 | |
|
31 | |
private static final long serialVersionUID = -1731339518240664632L; |
32 | 36 | private ThreadLocal<ExecutionStack> executionStack = new ThreadLocal<ExecutionStack>(); |
33 | |
private DriverContext driverContext; |
34 | |
|
35 | |
public SqlTaskTimer(String sqlText |
36 | |
, Collection<DataMeasure> dataMeasures |
37 | |
, DriverContext driverContext |
38 | |
, ExecutionStack executionStack) { |
39 | 36 | super(sqlText, dataMeasures); |
40 | |
Validate.notNull(executionStack, "Null executionstack not allowed."); |
41 | |
Validate.notNull(driverContext, "Null driverContext not allowed."); |
42 | 36 | this.executionStack.set(executionStack); |
43 | 36 | this.driverContext = driverContext; |
44 | 36 | } |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
@Override |
50 | |
public void stop() { |
51 | 180138 | Long bTime = this.getBeginTime(); |
52 | 180138 | if (bTime == null) { |
53 | 0 | throw new Admin4jRuntimeException("Can't call stop() on a timer that hasn't been started."); |
54 | |
} |
55 | |
|
56 | 180138 | Long timing = System.currentTimeMillis() - bTime; |
57 | 180138 | for (DataMeasure measure: this.getDataMeasures()) { |
58 | 180138 | ((SqlStatementSummaryDataMeasure)measure).addNumber(timing, executionStack.get()); |
59 | |
} |
60 | 180138 | } |
61 | |
|
62 | |
public DriverContext getDriverContext() { |
63 | 49 | return driverContext; |
64 | |
} |
65 | |
|
66 | |
} |