Skip to content

Commit

Permalink
#30 cleanup, inlining for easier reading
Browse files Browse the repository at this point in the history
  • Loading branch information
doom369 committed Sep 5, 2019
1 parent 15c32d0 commit 0488572
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void setBind(int parameterIndex, ClickHousePreparedStatementParameter pa
}

private void setNull(int parameterIndex) {
setBind(parameterIndex, ClickHousePreparedStatementParameter.nullParameter());
setBind(parameterIndex, ClickHousePreparedStatementParameter.NULL_PARAM);
}

@Override
Expand Down Expand Up @@ -215,10 +215,8 @@ public void setBytes(int parameterIndex, byte[] x) throws SQLException {
@Override
public void setDate(int parameterIndex, Date x) throws SQLException {
if (x != null) {
setBind(
parameterIndex,
ClickHouseValueFormatter.formatDate(x, dateTimeZone),
true);
String bind = ClickHouseValueFormatter.formatDate(x, dateTimeZone);
setBind(parameterIndex, bind, true);
} else {
setNull(parameterIndex);
}
Expand All @@ -227,10 +225,8 @@ public void setDate(int parameterIndex, Date x) throws SQLException {
@Override
public void setTime(int parameterIndex, Time x) throws SQLException {
if (x != null) {
setBind(
parameterIndex,
ClickHouseValueFormatter.formatTime(x, dateTimeTimeZone),
true);
String bind = ClickHouseValueFormatter.formatTime(x, dateTimeTimeZone);
setBind(parameterIndex, bind, true);
} else {
setNull(parameterIndex);
}
Expand All @@ -239,10 +235,8 @@ public void setTime(int parameterIndex, Time x) throws SQLException {
@Override
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
if (x != null) {
setBind(
parameterIndex,
ClickHouseValueFormatter.formatTimestamp(x, dateTimeTimeZone),
true);
String bind = ClickHouseValueFormatter.formatTimestamp(x, dateTimeTimeZone);
setBind(parameterIndex, bind, true);
} else {
setNull(parameterIndex);
}
Expand Down Expand Up @@ -291,10 +285,10 @@ public void setArray(int parameterIndex, Array x) throws SQLException {
@Override
public void setObject(int parameterIndex, Object x) throws SQLException {
if (x != null) {
setBind(
parameterIndex,
ClickHousePreparedStatementParameter.fromObject(
x, dateTimeZone, dateTimeTimeZone));
String bind = ClickHouseValueFormatter.formatObject(x, dateTimeZone, dateTimeTimeZone);
boolean needQuoting = ClickHouseValueFormatter.needsQuoting(x);
ClickHousePreparedStatementParameter bindParam = new ClickHousePreparedStatementParameter(bind,needQuoting);
setBind(parameterIndex, bindParam);
} else {
setNull(parameterIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import cc.blynk.clickhouse.util.ClickHouseValueFormatter;

import java.util.TimeZone;

public final class ClickHousePreparedStatementParameter {

private static final ClickHousePreparedStatementParameter NULL_PARAM =
static final ClickHousePreparedStatementParameter NULL_PARAM =
new ClickHousePreparedStatementParameter(null, false);

static final ClickHousePreparedStatementParameter TRUE_PARAM =
Expand All @@ -18,20 +16,6 @@ public final class ClickHousePreparedStatementParameter {
private final String stringValue;
private final boolean quoteNeeded;

static ClickHousePreparedStatementParameter fromObject(Object x,
TimeZone dateTimeZone, TimeZone dateTimeTimeZone) {
if (x == null) {
return NULL_PARAM;
}
return new ClickHousePreparedStatementParameter(
ClickHouseValueFormatter.formatObject(x, dateTimeZone, dateTimeTimeZone),
ClickHouseValueFormatter.needsQuoting(x));
}

static ClickHousePreparedStatementParameter nullParameter() {
return NULL_PARAM;
}

ClickHousePreparedStatementParameter(String stringValue, boolean quoteNeeded) {
this.stringValue = stringValue == null
? ClickHouseValueFormatter.NULL_MARKER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class ClickHousePreparedStatementParameterTest {
@Test
public void testNullParam() {
ClickHousePreparedStatementParameter p0 =
ClickHousePreparedStatementParameter.nullParameter();
ClickHousePreparedStatementParameter.NULL_PARAM;
assertEquals(p0.getRegularValue(), "null");
assertEquals(p0.getBatchValue(), "\\N");

ClickHousePreparedStatementParameter p1 =
ClickHousePreparedStatementParameter.nullParameter();
ClickHousePreparedStatementParameter.NULL_PARAM;
assertEquals(p1, p0);
assertSame(p1, p0);
}
Expand Down

0 comments on commit 0488572

Please sign in to comment.