/
ResultHandlerBase.java
76 lines (64 loc) · 1.93 KB
/
ResultHandlerBase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright (c) 2004, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
// Copyright (c) 2004, Open Cloud Limited.
package org.postgresql.core;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.util.List;
/**
* Empty implementation of {@link ResultHandler} interface.
* {@link SQLException#setNextException(SQLException)} has {@code O(N)} complexity,
* so this class tracks the last exception object to speedup {@code setNextException}.
*/
public class ResultHandlerBase implements ResultHandler {
// Last exception is tracked to avoid O(N) SQLException#setNextException just in case there
// will be lots of exceptions (e.g. all batch rows fail with constraint violation or so)
private SQLException firstException;
private SQLException lastException;
private SQLWarning firstWarning;
private SQLWarning lastWarning;
@Override
public void handleResultRows(Query fromQuery, Field[] fields, List<byte[][]> tuples,
ResultCursor cursor) {
}
@Override
public void handleCommandStatus(String status, long updateCount, long insertOID) {
}
@Override
public void secureProgress() {
}
@Override
public void handleWarning(SQLWarning warning) {
if (firstWarning == null) {
firstWarning = lastWarning = warning;
return;
}
lastWarning.setNextException(warning);
lastWarning = warning;
}
@Override
public void handleError(SQLException error) {
if (firstException == null) {
firstException = lastException = error;
return;
}
lastException.setNextException(error);
lastException = error;
}
@Override
public void handleCompletion() throws SQLException {
if (firstException != null) {
throw firstException;
}
}
@Override
public SQLException getException() {
return firstException;
}
@Override
public SQLWarning getWarning() {
return firstWarning;
}
}