From 2ecac2dc7a918f82cc4af142fe70888d0bc2253b Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Tue, 10 Oct 2023 21:30:30 +0200 Subject: [PATCH] Format sources --- .../jdbc/SimpleParameterMetaData.java | 64 ++++++++----------- .../jdbc/resultset/GenericRowMapper.java | 4 +- .../jdbc/resultset/SimpleMetaData.java | 62 +++++++----------- 3 files changed, 51 insertions(+), 79 deletions(-) diff --git a/src/main/java/org/itsallcode/jdbc/SimpleParameterMetaData.java b/src/main/java/org/itsallcode/jdbc/SimpleParameterMetaData.java index 4fb9ac6..188337d 100644 --- a/src/main/java/org/itsallcode/jdbc/SimpleParameterMetaData.java +++ b/src/main/java/org/itsallcode/jdbc/SimpleParameterMetaData.java @@ -2,80 +2,70 @@ import java.sql.ParameterMetaData; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; -public class SimpleParameterMetaData -{ +public class SimpleParameterMetaData { - private final java.sql.ParameterMetaData metaData; + private final ParameterMetaData metaData; - SimpleParameterMetaData(java.sql.ParameterMetaData parameterMetaData) - { + SimpleParameterMetaData(final ParameterMetaData parameterMetaData) { this.metaData = parameterMetaData; } - public List getParameters() - { - try - { + public List getParameters() { + try { final List parameters = new ArrayList<>(metaData.getParameterCount()); - for (int i = 1; i <= metaData.getParameterCount(); i++) - { + for (int i = 1; i <= metaData.getParameterCount(); i++) { parameters.add(new Parameter(metaData.getParameterClassName(i), metaData.getParameterType(i), metaData.getParameterTypeName(i), ParameterMode.of(metaData.getParameterMode(i)), metaData.getPrecision(i), metaData.getScale(i), metaData.isSigned(i), ParameterNullable.of(metaData.isNullable(i)))); } return parameters; - } - catch (final SQLException e) - { + } catch (final SQLException e) { throw new UncheckedSQLException("Error getting parameter metadata", e); } } - public enum ParameterMode - { - IN(ParameterMetaData.parameterModeIn), INOUT(ParameterMetaData.parameterModeInOut), OUT( - ParameterMetaData.parameterModeOut), UNKNWON(ParameterMetaData.parameterModeUnknown); + public enum ParameterMode { + IN(ParameterMetaData.parameterModeIn), + INOUT(ParameterMetaData.parameterModeInOut), + OUT(ParameterMetaData.parameterModeOut), + UNKNWON(ParameterMetaData.parameterModeUnknown); private final int mode; - private ParameterMode(int mode) - { + private ParameterMode(final int mode) { this.mode = mode; } - public static ParameterMode of(int mode) - { - return Arrays.stream(values()).filter(m -> m.mode == mode).findAny().orElseThrow( - () -> new IllegalArgumentException("No parameter mode found for value " + mode)); + public static ParameterMode of(final int mode) { + return Arrays.stream(values()) + .filter(m -> m.mode == mode) + .findAny() + .orElseThrow( + () -> new IllegalArgumentException("No parameter mode found for value " + mode)); } } - public enum ParameterNullable - { - NO_NULLS(ParameterMetaData.parameterNoNulls), NULLABLE(ParameterMetaData.parameterNullable), UNKNWON( - ParameterMetaData.parameterNullableUnknown); + public enum ParameterNullable { + NO_NULLS(ParameterMetaData.parameterNoNulls), + NULLABLE(ParameterMetaData.parameterNullable), + UNKNWON(ParameterMetaData.parameterNullableUnknown); private final int mode; - private ParameterNullable(int mode) - { + private ParameterNullable(final int mode) { this.mode = mode; } - public static ParameterNullable of(int mode) - { + public static ParameterNullable of(final int mode) { return Arrays.stream(values()).filter(m -> m.mode == mode).findAny().orElseThrow( () -> new IllegalArgumentException("No parameter mode found for value " + mode)); } } public static record Parameter(String className, int type, String typeName, ParameterMode mode, int precision, - int scale, boolean signed, ParameterNullable nullable) - { + int scale, boolean signed, ParameterNullable nullable) { } } \ No newline at end of file diff --git a/src/main/java/org/itsallcode/jdbc/resultset/GenericRowMapper.java b/src/main/java/org/itsallcode/jdbc/resultset/GenericRowMapper.java index 567f0e2..6e0455c 100644 --- a/src/main/java/org/itsallcode/jdbc/resultset/GenericRowMapper.java +++ b/src/main/java/org/itsallcode/jdbc/resultset/GenericRowMapper.java @@ -9,12 +9,12 @@ public class GenericRowMapper implements RowMapper { private final Context context; private ResultSetRowBuilder rowBuilder; - public GenericRowMapper(Context context) { + public GenericRowMapper(final Context context) { this.context = context; } @Override - public Row mapRow(ResultSet resultSet, int rowNum) throws SQLException { + public Row mapRow(final ResultSet resultSet, final int rowNum) throws SQLException { if (rowBuilder == null) { rowBuilder = new ResultSetRowBuilder(SimpleMetaData.create(resultSet.getMetaData(), context)); } diff --git a/src/main/java/org/itsallcode/jdbc/resultset/SimpleMetaData.java b/src/main/java/org/itsallcode/jdbc/resultset/SimpleMetaData.java index b7e2adc..042eaa6 100644 --- a/src/main/java/org/itsallcode/jdbc/resultset/SimpleMetaData.java +++ b/src/main/java/org/itsallcode/jdbc/resultset/SimpleMetaData.java @@ -8,61 +8,50 @@ import org.itsallcode.jdbc.Context; import org.itsallcode.jdbc.UncheckedSQLException; -public class SimpleMetaData -{ +public class SimpleMetaData { private final List columns; - private SimpleMetaData(List columns) - { + private SimpleMetaData(final List columns) { this.columns = columns; } - static SimpleMetaData create(ResultSetMetaData metaData, Context context) - { - try - { + static SimpleMetaData create(final ResultSetMetaData metaData, final Context context) { + try { final int columnCount = metaData.getColumnCount(); final List columns = new ArrayList<>(columnCount); - for (int column = 1; column <= columnCount; column++) - { + for (int column = 1; column <= columnCount; column++) { final ColumnMetaData columnMetaData = ColumnMetaData.create(metaData, context.getValueExtractorFactory(), column); columns.add(columnMetaData); } return new SimpleMetaData(columns); - } - catch (final SQLException e) - { + } catch (final SQLException e) { throw new UncheckedSQLException("Error extracting meta data", e); } } - public List getColumns() - { + public List getColumns() { return columns; } - public static class ColumnMetaData - { + public static class ColumnMetaData { private final int columnIndex; private final String name; private final String label; private final ColumnType type; - private final ResultSetValueExtractor valueExtractor; + private final ValueExtractorFactory valueExtractorFactory; - private ColumnMetaData(int columnIndex, String name, String label, ColumnType type, - ResultSetValueExtractor valueExtractor) - { + private ColumnMetaData(final int columnIndex, final String name, final String label, final ColumnType type, + final ValueExtractorFactory valueExtractorFactory) { this.columnIndex = columnIndex; this.name = name; this.label = label; this.type = type; - this.valueExtractor = valueExtractor; + this.valueExtractorFactory = valueExtractorFactory; } - private static ColumnMetaData create(ResultSetMetaData metaData, - ValueExtractorFactory valueExtractorFactory, int columnIndex) throws SQLException - { + private static ColumnMetaData create(final ResultSetMetaData metaData, + final ValueExtractorFactory valueExtractorFactory, final int columnIndex) throws SQLException { final String className = metaData.getColumnClassName(columnIndex); final int displaySize = metaData.getColumnDisplaySize(columnIndex); final String label = metaData.getColumnLabel(columnIndex); @@ -72,38 +61,31 @@ private static ColumnMetaData create(ResultSetMetaData metaData, final int precision = metaData.getPrecision(columnIndex); final int scale = metaData.getScale(columnIndex); final ColumnType columnType = new ColumnType(jdbcType, typeName, className, precision, scale, displaySize); - final ResultSetValueExtractor valueExtractor = valueExtractorFactory.create(columnType); - return new ColumnMetaData(columnIndex, name, label, columnType, valueExtractor); + return new ColumnMetaData(columnIndex, name, label, columnType, valueExtractorFactory); } - public int getColumnIndex() - { + public int getColumnIndex() { return columnIndex; } - public String getName() - { + public String getName() { return name; } - public String getLabel() - { + public String getLabel() { return label; } - public ColumnType getType() - { + public ColumnType getType() { return type; } - ResultSetValueExtractor getValueExtractor() - { - return valueExtractor; + ResultSetValueExtractor getValueExtractor() { + return valueExtractorFactory.create(this.type); } @Override - public String toString() - { + public String toString() { return "ColumnMetaData [columnIndex=" + columnIndex + ", name=" + name + ", label=" + label + ", type=" + type + "]"; }