Skip to content

Commit

Permalink
[misc] code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Apr 25, 2024
1 parent 92d8414 commit c19f608
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/benchmark/java/org/mariadb/jdbc/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public static class SetupData {
try {
stmt.execute("INSTALL SONAME 'ha_blackhole'");
} catch (SQLException e) {
// eat
}

String createTable =
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/java/org/mariadb/jdbc/Insert_batch.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Insert_batch extends Common {
public static String randomString(int length) {
StringBuilder result = new StringBuilder();
for (int i = length; i > 0; --i)
result.append(chars.get(Math.round((int) Math.random() * (chars.size() - 1))));
result.append(chars.get((int) ((Math.random() * (chars.size() - 1)))));
return result.toString();
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/mariadb/jdbc/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ private static Configuration parseInternal(String url, Properties properties)
if (database.isEmpty()) database = null;
}
String urlParameters = additionalParameters.substring(optIndex + 1);
if (urlParameters != null && !urlParameters.isEmpty()) {
if (!urlParameters.isEmpty()) {
String[] parameters = urlParameters.split("&");
for (String parameter : parameters) {
int pos = parameter.indexOf('=');
Expand Down Expand Up @@ -975,11 +975,10 @@ public static String toConf(String url) throws SQLException {
if (!propertyToSkip.contains(field.getName())) {
Object fieldValue = field.get(conf);
if (fieldValue == null) {
(Objects.equals(fieldValue, field.get(defaultConf)) ? sbDefaultOpts : sbDifferentOpts)
(field.get(defaultConf) == null ? sbDefaultOpts : sbDifferentOpts)
.append("\n * ")
.append(field.getName())
.append(" : ")
.append(fieldValue);
.append(" : null");
} else {
if (field.getName().equals("haMode")) {
(Objects.equals(fieldValue, field.get(defaultConf)) ? sbDefaultOpts : sbDifferentOpts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public BlobColumn(
protected BlobColumn(BlobColumn prev) {
super(prev);
}

public int getDisplaySize() {
if (charset != 63) {
Integer maxWidth = CharsetEncodingLength.maxCharlen.get(charset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public JsonColumn(
protected JsonColumn(JsonColumn prev) {
super(prev);
}

public int getDisplaySize() {
if (charset != 63) {
Integer maxWidth = CharsetEncodingLength.maxCharlen.get(charset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public SignedSmallIntColumn(
protected SignedSmallIntColumn(SignedSmallIntColumn prev) {
super(prev, true);
}

public int getPrecision() {
// UNSIGNED SMALLINT : 0..65535 digits=5 nchars=5
// SIGNED SMALLINT : -32768..32767 digits=5 nchars=6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public SignedTinyIntColumn(
protected SignedTinyIntColumn(SignedTinyIntColumn prev) {
super(prev, true);
}

public int getPrecision() {
// UNSIGNED TINYINT : 0..255 digits=3 nchars=3
// SIGNED TINYINT : -128..127 digits=3 nchars=4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,8 @@ public static ZonedDateTime localDateTimeToZoneDateTime(
final LocalDateTime ldt, final Calendar calParam, final Context context) {
if (calParam == null) {
if (context.getConf().preserveInstants()) {
ZonedDateTime zdt = ldt.atZone(context.getConnectionTimeZone().toZoneId());
ZonedDateTime zdt2 =
zdt.withZoneSameInstant(
(calParam == null ? TimeZone.getDefault() : calParam.getTimeZone()).toZoneId());
LocalDateTime sss = zdt2.toLocalDateTime();
return zdt2;
return ldt.atZone(context.getConnectionTimeZone().toZoneId())
.withZoneSameInstant(TimeZone.getDefault().toZoneId());
}
return ldt.atZone(TimeZone.getDefault().toZoneId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.mariadb.jdbc.client.ReadableByteBuf;
import org.mariadb.jdbc.client.util.MutableInt;
import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
import org.mariadb.jdbc.util.CharsetEncodingLength;

/** Column metadata definition */
public class UnsignedMediumIntColumn extends ColumnDefinitionPacket implements ColumnDecoder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ public String createSessionVariableQuery(Context context) {
}

// force client timezone to connection to ensure result of now(), ...
if (conf.forceConnectionTimeZoneToSession() == null || conf.forceConnectionTimeZoneToSession()) {
if (conf.forceConnectionTimeZoneToSession() == null
|| conf.forceConnectionTimeZoneToSession()) {
TimeZone connectionTz = context.getConnectionTimeZone();
ZoneId connectionZoneId = connectionTz.toZoneId();

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/mariadb/jdbc/client/result/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
fieldLength.set(
rowDecoder.setPosition(
columnIndex - 1, fieldIndex, maxIndex, rowBuf, nullBitmap, metadataList));
Calendar calendar = null;

if (wasNull()) {
if (type.isPrimitive()) {
throw new SQLException(
Expand All @@ -1672,7 +1672,7 @@ public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
for (Codec<?> codec : conf.codecs()) {
if (codec.canDecode(column, type)) {
return rowDecoder.decode(
(Codec<T>) codec, calendar, rowBuf, fieldLength, metadataList, fieldIndex, context);
(Codec<T>) codec, null, rowBuf, fieldLength, metadataList, fieldIndex, context);
}
}
rowBuf.skip(fieldLength.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
import org.mariadb.jdbc.message.ServerMessage;
import org.mariadb.jdbc.util.CharsetEncodingLength;
import org.mariadb.jdbc.util.constants.ColumnFlags;

/** Column metadata definition */
Expand Down

0 comments on commit c19f608

Please sign in to comment.