• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

codenotary / immudb4j / #142

10 Aug 2024 02:39PM UTC coverage: 82.163% (-0.1%) from 82.309%
#142

Pull #63

github

web-flow
Merge 003bfe044 into 3bd9585d2
Pull Request #63: Support stream in SQLQuery/TxSQLQuery

11 of 13 new or added lines in 2 files covered. (84.62%)

3 existing lines in 1 file now uncovered.

1451 of 1766 relevant lines covered (82.16%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.75
/src/main/java/io/codenotary/immudb4j/sql/SQLQueryResult.java
1

2
/*
3
Copyright 2022 CodeNotary, Inc. All rights reserved.
4

5
Licensed under the Apache License, Version 2.0 (the "License");
6
you may not use this file except in compliance with the License.
7
You may obtain a copy of the License at
8

9
        http://www.apache.org/licenses/LICENSE-2.0
10

11
Unless required by applicable law or agreed to in writing, software
12
distributed under the License is distributed on an "AS IS" BASIS,
13
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
See the License for the specific language governing permissions and
15
limitations under the License.
16
*/
17
package io.codenotary.immudb4j.sql;
18

19
import java.util.Date;
20
import java.util.NoSuchElementException;
21
import java.util.concurrent.TimeUnit;
22
import java.util.Iterator;
23

24
import io.codenotary.immudb.ImmudbProto;
25

26
public class SQLQueryResult {
27

28
    private final Iterator<ImmudbProto.SQLQueryResult> it;
29
    private ImmudbProto.SQLQueryResult res;
30
    private int currRow = -1;
1✔
31

32
    private boolean closed;
33

34
    public SQLQueryResult(Iterator<ImmudbProto.SQLQueryResult> it) {
1✔
35
        if (it == null) {
1✔
UNCOV
36
            throw new RuntimeException("illegal arguments");
×
37
        }
38

39
        this.it = it;
1✔
40
        this.res = it.next();
1✔
41
    }
1✔
42

43
    public synchronized void close() throws SQLException {
44
        closed = true;
1✔
45
    }
1✔
46

47
    public synchronized boolean next() throws SQLException {
48
        if (closed) {
1✔
49
            throw new SQLException("already closed");
×
50
        }
51

52
        if (res != null && currRow+1 < res.getRowsCount()) {
1✔
53
            currRow++;
1✔
54
            return true;
1✔
55
        }
56

57
        try {
NEW
58
            res = this.it.next();
×
59
        } catch (NoSuchElementException e) {
1✔
60
            return false;
1✔
UNCOV
61
        }
×
NEW
62
        currRow = 0;
×
63

UNCOV
64
        return true;
×
65
    }
66

67
    private void validateReadingAt(int col) throws SQLException {
68
        if (closed) {
1✔
69
            throw new SQLException("already closed");
×
70
        }
71

72
        if (currRow < 0) {
1✔
73
            throw new SQLException("no row was read");
×
74
        }
75

76
        if (res.getRowsCount() == currRow) {
1✔
77
            throw new SQLException("no more rows");
×
78
        }
79

80
        if (res.getColumnsCount() < col) {
1✔
81
            throw new SQLException("invalid column");
×
82
        }
83
    }
1✔
84

85
    public synchronized int getColumnsCount() throws SQLException {
86
        if (closed) {
1✔
87
            throw new SQLException("already closed");
×
88
        }
89

90
        return res.getColumnsCount();
1✔
91
    }
92

93
    public synchronized String getColumnName(int i) throws SQLException {
94
        if (closed) {
1✔
95
            throw new SQLException("already closed");
×
96
        }
97

98
        final String fullColName = res.getColumns(i).getName();
1✔
99

100
        return fullColName.substring(fullColName.lastIndexOf(".")+1, fullColName.length()-1);
1✔
101
    }
102

103
    public synchronized String getColumnType(int i) throws SQLException {
104
        if (closed) {
1✔
105
            throw new SQLException("already closed");
×
106
        }
107

108
        return res.getColumns(i).getType();
1✔
109
    }
110

111
    public synchronized boolean getBoolean(int i) throws SQLException {
112
        validateReadingAt(i);
1✔
113

114
        return res.getRows(currRow).getValues(i).getB();
1✔
115
    }
116

117
    public synchronized int getInt(int i) throws SQLException {
118
        validateReadingAt(i);
1✔
119

120
        return (int)res.getRows(currRow).getValues(i).getN();
1✔
121
    }
122

123
    public synchronized long getLong(int i) throws SQLException {
124
        validateReadingAt(i);
×
125

126
        return res.getRows(currRow).getValues(i).getN();
×
127
    }
128

129
    public synchronized String getString(int i) throws SQLException {
130
        validateReadingAt(i);
1✔
131

132
        return res.getRows(currRow).getValues(i).getS();
1✔
133
    }
134

135
    public synchronized byte[] getBytes(int i) throws SQLException {
136
        validateReadingAt(i);
×
137

138
        return res.getRows(currRow).getValues(i).getBs().toByteArray();
×
139
    }
140

141
    public synchronized Date getDate(int i) throws SQLException {
142
        validateReadingAt(i);
×
143

144
        return new Date(TimeUnit.MICROSECONDS.toMillis(res.getRows(currRow).getValues(i).getTs()));
×
145
    }
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc