Skip to content

Commit

Permalink
Format sources
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Oct 10, 2023
1 parent 1b8e6ef commit 2ecac2d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 79 deletions.
64 changes: 27 additions & 37 deletions src/main/java/org/itsallcode/jdbc/SimpleParameterMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Parameter> getParameters()
{
try
{
public List<Parameter> getParameters() {
try {
final List<Parameter> 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) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public class GenericRowMapper implements RowMapper<Row> {
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));
}
Expand Down
62 changes: 22 additions & 40 deletions src/main/java/org/itsallcode/jdbc/resultset/SimpleMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,50 @@
import org.itsallcode.jdbc.Context;
import org.itsallcode.jdbc.UncheckedSQLException;

public class SimpleMetaData
{
public class SimpleMetaData {
private final List<ColumnMetaData> columns;

private SimpleMetaData(List<ColumnMetaData> columns)
{
private SimpleMetaData(final List<ColumnMetaData> 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<ColumnMetaData> 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<ColumnMetaData> getColumns()
{
public List<ColumnMetaData> 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);
Expand All @@ -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 + "]";
}
Expand Down

0 comments on commit 2ecac2d

Please sign in to comment.