77import java .util .List ;
88import java .util .concurrent .CompletableFuture ;
99import java .util .function .Supplier ;
10- import java .util .logging .Level ;
11- import java .util .logging .Logger ;
12-
13- import com .google .common .base .Stopwatch ;
1410
1511import tech .ydb .core .Issue ;
1612import tech .ydb .core .Result ;
2319 * @author Aleksandr Gorshenin
2420 */
2521public class YdbValidator {
26- @ SuppressWarnings ("NonConstantLogger" )
27- private final Logger logger ;
28- private final boolean isDebug ;
2922 private final List <Issue > issues = new ArrayList <>();
3023
31- public YdbValidator (Logger logger ) {
32- this .logger = logger ;
33- this .isDebug = logger .isLoggable (Level .FINE );
34- }
35-
3624 public SQLWarning toSQLWarnings () {
3725 SQLWarning firstWarning = null ;
3826 SQLWarning warning = null ;
@@ -62,48 +50,6 @@ public void clearWarnings() {
6250 }
6351
6452 public void execute (String msg , Supplier <CompletableFuture <Status >> fn ) throws SQLException {
65- if (!isDebug ) {
66- runImpl (msg , fn );
67- return ;
68- }
69-
70- logger .finest (msg );
71- Stopwatch sw = Stopwatch .createStarted ();
72-
73- try {
74- runImpl (msg , fn );
75- logger .log (Level .FINEST , "[{0}] OK " , sw .stop ());
76- } catch (SQLException ex ) {
77- logger .log (Level .FINE , "[{0}] {1} " , new Object [] {sw .stop (), ex .getMessage ()});
78- throw ex ;
79- } catch (Exception ex ) {
80- logger .log (Level .WARNING , "ERROR " , ex );
81- throw ex ;
82- }
83- }
84-
85- public <R > R call (String msg , Supplier <CompletableFuture <Result <R >>> fn ) throws SQLException {
86- if (!isDebug ) {
87- return callImpl (msg , fn );
88- }
89-
90- logger .finest (msg );
91- Stopwatch sw = Stopwatch .createStarted ();
92-
93- try {
94- R value = callImpl (msg , fn );
95- logger .log (Level .FINEST , "[{0}] OK " , sw .stop ());
96- return value ;
97- } catch (SQLException ex ) {
98- logger .log (Level .FINE , "[{0}] FAIL {1} " , new Object [] {sw .stop (), ex .getMessage ()});
99- throw ex ;
100- } catch (Exception ex ) {
101- logger .log (Level .WARNING , "ERROR " , ex );
102- throw ex ;
103- }
104- }
105-
106- private void runImpl (String msg , Supplier <CompletableFuture <Status >> fn ) throws SQLException {
10753 Status status = fn .get ().join ();
10854 addStatusIssues (status );
10955
@@ -113,7 +59,7 @@ private void runImpl(String msg, Supplier<CompletableFuture<Status>> fn) throws
11359 }
11460 }
11561
116- private <R > R callImpl (String msg , Supplier <CompletableFuture <Result <R >>> fn ) throws SQLException {
62+ public <R > R call (String msg , Supplier <CompletableFuture <Result <R >>> fn ) throws SQLException {
11763 try {
11864 Result <R > result = fn .get ().join ();
11965 addStatusIssues (result .getStatus ());
@@ -122,5 +68,4 @@ private <R> R callImpl(String msg, Supplier<CompletableFuture<Result<R>>> fn) th
12268 throw ExceptionFactory .createException ("Cannot call '" + msg + "' with " + ex .getStatus (), ex );
12369 }
12470 }
125-
12671}
0 commit comments