Skip to content

Commit b0e2dcb

Browse files
committed
code style
1 parent a6d9b4a commit b0e2dcb

27 files changed

+388
-366
lines changed

clickhouse-native-jdbc/src/main/java/com/github/housepower/jdbc/ClickHouseResultSet.java

Lines changed: 110 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -71,117 +71,74 @@ public boolean getBoolean(String name) throws SQLException {
7171
return this.getBoolean(this.findColumn(name));
7272
}
7373

74-
@Override
75-
public int getInt(String name) throws SQLException {
76-
return this.getInt(this.findColumn(name));
77-
}
78-
79-
@Override
80-
public URL getURL(String name) throws SQLException {
81-
return this.getURL(this.findColumn(name));
82-
}
83-
8474
@Override
8575
public byte getByte(String name) throws SQLException {
8676
return this.getByte(this.findColumn(name));
8777
}
8878

8979
@Override
90-
public byte[] getBytes(String name) throws SQLException {
91-
return this.getBytes(this.findColumn(name));
80+
public short getShort(String name) throws SQLException {
81+
return this.getShort(this.findColumn(name));
9282
}
9383

9484
@Override
95-
public Date getDate(String name) throws SQLException {
96-
return this.getDate(this.findColumn(name));
85+
public int getInt(String name) throws SQLException {
86+
return this.getInt(this.findColumn(name));
9787
}
9888

9989
@Override
10090
public long getLong(String name) throws SQLException {
10191
return this.getLong(this.findColumn(name));
10292
}
10393

104-
@Override
105-
public Array getArray(String name) throws SQLException {
106-
return this.getArray(this.findColumn(name));
107-
}
108-
10994
@Override
11095
public float getFloat(String name) throws SQLException {
11196
return this.getFloat(this.findColumn(name));
11297
}
11398

114-
@Override
115-
public short getShort(String name) throws SQLException {
116-
return this.getShort(this.findColumn(name));
117-
}
118-
11999
@Override
120100
public double getDouble(String name) throws SQLException {
121101
return this.getDouble(this.findColumn(name));
122102
}
123103

124-
@Override
125-
public String getString(String name) throws SQLException {
126-
return this.getString(this.findColumn(name));
127-
}
128-
129-
@Override
130-
public Object getObject(String name) throws SQLException {
131-
return this.getObject(this.findColumn(name));
132-
}
133-
134104
@Override
135105
public Timestamp getTimestamp(String name) throws SQLException {
136106
return this.getTimestamp(this.findColumn(name));
137107
}
138108

139109
@Override
140-
public BigDecimal getBigDecimal(String name) throws SQLException {
141-
return this.getBigDecimal(this.findColumn(name));
142-
}
143-
144-
@Override
145-
public boolean isBeforeFirst() throws SQLException {
146-
return currentRowNum == -1;
147-
}
148-
149-
@Override
150-
public boolean isAfterLast() throws SQLException {
151-
return isAfterLast;
152-
}
153-
154-
@Override
155-
public boolean isFirst() throws SQLException {
156-
return isFirst;
110+
public Date getDate(String name) throws SQLException {
111+
return this.getDate(this.findColumn(name));
157112
}
158113

159114
@Override
160-
public boolean first() throws SQLException {
161-
throw new SQLException("TYPE_FORWARD_ONLY");
115+
public BigDecimal getBigDecimal(String name) throws SQLException {
116+
return this.getBigDecimal(this.findColumn(name));
162117
}
163118

164119
@Override
165-
public boolean last() throws SQLException {
166-
throw new SQLException("TYPE_FORWARD_ONLY");
120+
public String getString(String name) throws SQLException {
121+
return this.getString(this.findColumn(name));
167122
}
168123

169124
@Override
170-
public void setFetchDirection(int direction) throws SQLException {
125+
public byte[] getBytes(String name) throws SQLException {
126+
return this.getBytes(this.findColumn(name));
171127
}
172128

173129
@Override
174-
public int getFetchDirection() throws SQLException {
175-
return ResultSet.FETCH_FORWARD;
130+
public URL getURL(String name) throws SQLException {
131+
return this.getURL(this.findColumn(name));
176132
}
177133

178134
@Override
179-
public void setFetchSize(int rows) throws SQLException {
135+
public Array getArray(String name) throws SQLException {
136+
return this.getArray(this.findColumn(name));
180137
}
181138

182139
@Override
183-
public int getFetchSize() throws SQLException {
184-
return Integer.MAX_VALUE;
140+
public Object getObject(String name) throws SQLException {
141+
return this.getObject(this.findColumn(name));
185142
}
186143

187144
@Override
@@ -194,36 +151,30 @@ public boolean getBoolean(int index) throws SQLException {
194151
}
195152

196153
@Override
197-
public int getInt(int index) throws SQLException {
154+
public byte getByte(int index) throws SQLException {
198155
Object data = getObject(index);
199156
if (data == null) {
200157
return 0;
201158
}
202-
return ((Number) data).intValue();
203-
}
204-
205-
@Override
206-
public URL getURL(int index) throws SQLException {
207-
try {
208-
return new URL(this.getString(index));
209-
} catch (MalformedURLException ex) {
210-
throw new SQLException(ex.getMessage(), ex);
211-
}
159+
return ((Number) data).byteValue();
212160
}
213161

214162
@Override
215-
public byte getByte(int index) throws SQLException {
163+
public short getShort(int index) throws SQLException {
216164
Object data = getObject(index);
217165
if (data == null) {
218166
return 0;
219167
}
220-
return ((Number) data).byteValue();
168+
return ((Number) data).shortValue();
221169
}
222170

223171
@Override
224-
public Date getDate(int index) throws SQLException {
172+
public int getInt(int index) throws SQLException {
225173
Object data = getObject(index);
226-
return (Date) data;
174+
if (data == null) {
175+
return 0;
176+
}
177+
return ((Number) data).intValue();
227178
}
228179

229180
@Override
@@ -235,12 +186,6 @@ public long getLong(int index) throws SQLException {
235186
return ((Number) data).longValue();
236187
}
237188

238-
@Override
239-
public Array getArray(int index) throws SQLException {
240-
Object data = getObject(index);
241-
return (Array) data;
242-
}
243-
244189
@Override
245190
public float getFloat(int index) throws SQLException {
246191
Object data = getObject(index);
@@ -251,21 +196,30 @@ public float getFloat(int index) throws SQLException {
251196
}
252197

253198
@Override
254-
public short getShort(int index) throws SQLException {
199+
public double getDouble(int index) throws SQLException {
255200
Object data = getObject(index);
256201
if (data == null) {
257202
return 0;
258203
}
259-
return ((Number) data).shortValue();
204+
return ((Number) data).doubleValue();
260205
}
261206

262207
@Override
263-
public double getDouble(int index) throws SQLException {
208+
public Timestamp getTimestamp(int index) throws SQLException {
264209
Object data = getObject(index);
265-
if (data == null) {
266-
return 0;
267-
}
268-
return ((Number) data).doubleValue();
210+
return (Timestamp) data;
211+
}
212+
213+
@Override
214+
public Date getDate(int index) throws SQLException {
215+
Object data = getObject(index);
216+
return (Date) data;
217+
}
218+
219+
@Override
220+
public BigDecimal getBigDecimal(int index) throws SQLException {
221+
Object data = getObject(index);
222+
return new BigDecimal(data.toString());
269223
}
270224

271225
@Override
@@ -284,6 +238,21 @@ public byte[] getBytes(int index) throws SQLException {
284238
return data.getBytes(cfg.charset());
285239
}
286240

241+
@Override
242+
public URL getURL(int index) throws SQLException {
243+
try {
244+
return new URL(this.getString(index));
245+
} catch (MalformedURLException ex) {
246+
throw new SQLException(ex.getMessage(), ex);
247+
}
248+
}
249+
250+
@Override
251+
public Array getArray(int index) throws SQLException {
252+
Object data = getObject(index);
253+
return (Array) data;
254+
}
255+
287256
@Override
288257
public Object getObject(int index) throws SQLException {
289258
LOG.trace("get object at row: {}, column: {} from block with column count: {}, row count: {}",
@@ -295,31 +264,56 @@ public Object getObject(int index) throws SQLException {
295264
}
296265

297266
@Override
298-
public Timestamp getTimestamp(int index) throws SQLException {
299-
Object data = getObject(index);
300-
return (Timestamp) data;
267+
public boolean first() throws SQLException {
268+
throw new SQLException("TYPE_FORWARD_ONLY");
301269
}
302270

303271
@Override
304-
public BigDecimal getBigDecimal(int index) throws SQLException {
305-
Object data = getObject(index);
306-
return new BigDecimal(data.toString());
272+
public boolean last() throws SQLException {
273+
throw new SQLException("TYPE_FORWARD_ONLY");
274+
}
275+
276+
@Override
277+
public boolean isBeforeFirst() throws SQLException {
278+
return currentRowNum == -1;
279+
}
280+
281+
@Override
282+
public boolean isFirst() throws SQLException {
283+
return isFirst;
284+
}
285+
286+
@Override
287+
public boolean isAfterLast() throws SQLException {
288+
return isAfterLast;
289+
}
290+
291+
@Override
292+
public void setFetchDirection(int direction) throws SQLException {
293+
}
294+
295+
@Override
296+
public int getFetchDirection() throws SQLException {
297+
return ResultSet.FETCH_FORWARD;
307298
}
308299

309-
/*==================================================================*/
300+
@Override
301+
public void setFetchSize(int rows) throws SQLException {
302+
}
303+
304+
@Override
305+
public int getFetchSize() throws SQLException {
306+
return Integer.MAX_VALUE;
307+
}
310308

311309
@Override
312310
public int getType() throws SQLException {
313311
return ResultSet.TYPE_FORWARD_ONLY;
314312
}
315313

316314
@Override
317-
public void close() throws SQLException {
318-
// TODO check if query responses are completed
319-
// 1. if completed, just set isClosed = true
320-
// 2. if not, cancel query and consume the rest responses
321-
LOG.debug("close ResultSet");
322-
this.isClosed = true;
315+
public ResultSetMetaData getMetaData() throws SQLException {
316+
return new ClickHouseResultSetMetaData(header, db, table);
323317
}
324318

325319
@Override
@@ -335,11 +329,6 @@ public int getHoldability() throws SQLException {
335329
return ResultSet.CLOSE_CURSORS_AT_COMMIT;
336330
}
337331

338-
@Override
339-
public boolean isClosed() throws SQLException {
340-
return this.isClosed;
341-
}
342-
343332
@Override
344333
public Statement getStatement() throws SQLException {
345334
return statement;
@@ -351,11 +340,6 @@ public int findColumn(String name) throws SQLException {
351340
return header.getPositionByName(name);
352341
}
353342

354-
@Override
355-
public ResultSetMetaData getMetaData() throws SQLException {
356-
return new ClickHouseResultSetMetaData(header, db, table);
357-
}
358-
359343
@Override
360344
public boolean next() throws SQLException {
361345
boolean isBeforeFirst = isBeforeFirst();
@@ -370,6 +354,20 @@ public boolean next() throws SQLException {
370354
return hasNext;
371355
}
372356

357+
@Override
358+
public void close() throws SQLException {
359+
// TODO check if query responses are completed
360+
// 1. if completed, just set isClosed = true
361+
// 2. if not, cancel query and consume the rest responses
362+
LOG.debug("close ResultSet");
363+
this.isClosed = true;
364+
}
365+
366+
@Override
367+
public boolean isClosed() throws SQLException {
368+
return this.isClosed;
369+
}
370+
373371
@Override
374372
public Logger logger() {
375373
return ClickHouseResultSet.LOG;

clickhouse-native-jdbc/src/main/java/com/github/housepower/jdbc/buffer/ByteArrayWriter.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
import java.util.LinkedList;
2020
import java.util.List;
2121

22-
/**
23-
*
24-
*/
2522
public class ByteArrayWriter implements BuffedWriter {
2623
private final int blockSize;
2724
private ByteBuffer buffer;
@@ -32,7 +29,7 @@ public class ByteArrayWriter implements BuffedWriter {
3229
public ByteArrayWriter(int blockSize) {
3330
this.blockSize = blockSize;
3431
this.buffer = ByteBuffer.allocate(blockSize);
35-
byteBufferList.add(buffer);
32+
this.byteBufferList.add(buffer);
3633
}
3734

3835
@Override

0 commit comments

Comments
 (0)