Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
pan3793 committed Dec 15, 2020
1 parent a6d9b4a commit b0e2dcb
Show file tree
Hide file tree
Showing 27 changed files with 388 additions and 366 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,117 +71,74 @@ public boolean getBoolean(String name) throws SQLException {
return this.getBoolean(this.findColumn(name));
}

@Override
public int getInt(String name) throws SQLException {
return this.getInt(this.findColumn(name));
}

@Override
public URL getURL(String name) throws SQLException {
return this.getURL(this.findColumn(name));
}

@Override
public byte getByte(String name) throws SQLException {
return this.getByte(this.findColumn(name));
}

@Override
public byte[] getBytes(String name) throws SQLException {
return this.getBytes(this.findColumn(name));
public short getShort(String name) throws SQLException {
return this.getShort(this.findColumn(name));
}

@Override
public Date getDate(String name) throws SQLException {
return this.getDate(this.findColumn(name));
public int getInt(String name) throws SQLException {
return this.getInt(this.findColumn(name));
}

@Override
public long getLong(String name) throws SQLException {
return this.getLong(this.findColumn(name));
}

@Override
public Array getArray(String name) throws SQLException {
return this.getArray(this.findColumn(name));
}

@Override
public float getFloat(String name) throws SQLException {
return this.getFloat(this.findColumn(name));
}

@Override
public short getShort(String name) throws SQLException {
return this.getShort(this.findColumn(name));
}

@Override
public double getDouble(String name) throws SQLException {
return this.getDouble(this.findColumn(name));
}

@Override
public String getString(String name) throws SQLException {
return this.getString(this.findColumn(name));
}

@Override
public Object getObject(String name) throws SQLException {
return this.getObject(this.findColumn(name));
}

@Override
public Timestamp getTimestamp(String name) throws SQLException {
return this.getTimestamp(this.findColumn(name));
}

@Override
public BigDecimal getBigDecimal(String name) throws SQLException {
return this.getBigDecimal(this.findColumn(name));
}

@Override
public boolean isBeforeFirst() throws SQLException {
return currentRowNum == -1;
}

@Override
public boolean isAfterLast() throws SQLException {
return isAfterLast;
}

@Override
public boolean isFirst() throws SQLException {
return isFirst;
public Date getDate(String name) throws SQLException {
return this.getDate(this.findColumn(name));
}

@Override
public boolean first() throws SQLException {
throw new SQLException("TYPE_FORWARD_ONLY");
public BigDecimal getBigDecimal(String name) throws SQLException {
return this.getBigDecimal(this.findColumn(name));
}

@Override
public boolean last() throws SQLException {
throw new SQLException("TYPE_FORWARD_ONLY");
public String getString(String name) throws SQLException {
return this.getString(this.findColumn(name));
}

@Override
public void setFetchDirection(int direction) throws SQLException {
public byte[] getBytes(String name) throws SQLException {
return this.getBytes(this.findColumn(name));
}

@Override
public int getFetchDirection() throws SQLException {
return ResultSet.FETCH_FORWARD;
public URL getURL(String name) throws SQLException {
return this.getURL(this.findColumn(name));
}

@Override
public void setFetchSize(int rows) throws SQLException {
public Array getArray(String name) throws SQLException {
return this.getArray(this.findColumn(name));
}

@Override
public int getFetchSize() throws SQLException {
return Integer.MAX_VALUE;
public Object getObject(String name) throws SQLException {
return this.getObject(this.findColumn(name));
}

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

@Override
public int getInt(int index) throws SQLException {
public byte getByte(int index) throws SQLException {
Object data = getObject(index);
if (data == null) {
return 0;
}
return ((Number) data).intValue();
}

@Override
public URL getURL(int index) throws SQLException {
try {
return new URL(this.getString(index));
} catch (MalformedURLException ex) {
throw new SQLException(ex.getMessage(), ex);
}
return ((Number) data).byteValue();
}

@Override
public byte getByte(int index) throws SQLException {
public short getShort(int index) throws SQLException {
Object data = getObject(index);
if (data == null) {
return 0;
}
return ((Number) data).byteValue();
return ((Number) data).shortValue();
}

@Override
public Date getDate(int index) throws SQLException {
public int getInt(int index) throws SQLException {
Object data = getObject(index);
return (Date) data;
if (data == null) {
return 0;
}
return ((Number) data).intValue();
}

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

@Override
public Array getArray(int index) throws SQLException {
Object data = getObject(index);
return (Array) data;
}

@Override
public float getFloat(int index) throws SQLException {
Object data = getObject(index);
Expand All @@ -251,21 +196,30 @@ public float getFloat(int index) throws SQLException {
}

@Override
public short getShort(int index) throws SQLException {
public double getDouble(int index) throws SQLException {
Object data = getObject(index);
if (data == null) {
return 0;
}
return ((Number) data).shortValue();
return ((Number) data).doubleValue();
}

@Override
public double getDouble(int index) throws SQLException {
public Timestamp getTimestamp(int index) throws SQLException {
Object data = getObject(index);
if (data == null) {
return 0;
}
return ((Number) data).doubleValue();
return (Timestamp) data;
}

@Override
public Date getDate(int index) throws SQLException {
Object data = getObject(index);
return (Date) data;
}

@Override
public BigDecimal getBigDecimal(int index) throws SQLException {
Object data = getObject(index);
return new BigDecimal(data.toString());
}

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

@Override
public URL getURL(int index) throws SQLException {
try {
return new URL(this.getString(index));
} catch (MalformedURLException ex) {
throw new SQLException(ex.getMessage(), ex);
}
}

@Override
public Array getArray(int index) throws SQLException {
Object data = getObject(index);
return (Array) data;
}

@Override
public Object getObject(int index) throws SQLException {
LOG.trace("get object at row: {}, column: {} from block with column count: {}, row count: {}",
Expand All @@ -295,31 +264,56 @@ public Object getObject(int index) throws SQLException {
}

@Override
public Timestamp getTimestamp(int index) throws SQLException {
Object data = getObject(index);
return (Timestamp) data;
public boolean first() throws SQLException {
throw new SQLException("TYPE_FORWARD_ONLY");
}

@Override
public BigDecimal getBigDecimal(int index) throws SQLException {
Object data = getObject(index);
return new BigDecimal(data.toString());
public boolean last() throws SQLException {
throw new SQLException("TYPE_FORWARD_ONLY");
}

@Override
public boolean isBeforeFirst() throws SQLException {
return currentRowNum == -1;
}

@Override
public boolean isFirst() throws SQLException {
return isFirst;
}

@Override
public boolean isAfterLast() throws SQLException {
return isAfterLast;
}

@Override
public void setFetchDirection(int direction) throws SQLException {
}

@Override
public int getFetchDirection() throws SQLException {
return ResultSet.FETCH_FORWARD;
}

/*==================================================================*/
@Override
public void setFetchSize(int rows) throws SQLException {
}

@Override
public int getFetchSize() throws SQLException {
return Integer.MAX_VALUE;
}

@Override
public int getType() throws SQLException {
return ResultSet.TYPE_FORWARD_ONLY;
}

@Override
public void close() throws SQLException {
// TODO check if query responses are completed
// 1. if completed, just set isClosed = true
// 2. if not, cancel query and consume the rest responses
LOG.debug("close ResultSet");
this.isClosed = true;
public ResultSetMetaData getMetaData() throws SQLException {
return new ClickHouseResultSetMetaData(header, db, table);
}

@Override
Expand All @@ -335,11 +329,6 @@ public int getHoldability() throws SQLException {
return ResultSet.CLOSE_CURSORS_AT_COMMIT;
}

@Override
public boolean isClosed() throws SQLException {
return this.isClosed;
}

@Override
public Statement getStatement() throws SQLException {
return statement;
Expand All @@ -351,11 +340,6 @@ public int findColumn(String name) throws SQLException {
return header.getPositionByName(name);
}

@Override
public ResultSetMetaData getMetaData() throws SQLException {
return new ClickHouseResultSetMetaData(header, db, table);
}

@Override
public boolean next() throws SQLException {
boolean isBeforeFirst = isBeforeFirst();
Expand All @@ -370,6 +354,20 @@ public boolean next() throws SQLException {
return hasNext;
}

@Override
public void close() throws SQLException {
// TODO check if query responses are completed
// 1. if completed, just set isClosed = true
// 2. if not, cancel query and consume the rest responses
LOG.debug("close ResultSet");
this.isClosed = true;
}

@Override
public boolean isClosed() throws SQLException {
return this.isClosed;
}

@Override
public Logger logger() {
return ClickHouseResultSet.LOG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
import java.util.LinkedList;
import java.util.List;

/**
*
*/
public class ByteArrayWriter implements BuffedWriter {
private final int blockSize;
private ByteBuffer buffer;
Expand All @@ -32,7 +29,7 @@ public class ByteArrayWriter implements BuffedWriter {
public ByteArrayWriter(int blockSize) {
this.blockSize = blockSize;
this.buffer = ByteBuffer.allocate(blockSize);
byteBufferList.add(buffer);
this.byteBufferList.add(buffer);
}

@Override
Expand Down
Loading

0 comments on commit b0e2dcb

Please sign in to comment.