This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit da276c6e09ae5e4786b4943e98ae7195fed5d230 Author: Andrus Adamchik <[email protected]> AuthorDate: Sun Jun 28 16:27:45 2026 -0400 cleanup --- .../apache/cayenne/access/jdbc/BatchAction.java | 5 +---- .../cayenne/access/jdbc/ColumnDescriptor.java | 25 +++++++++------------- .../cayenne/access/jdbc/ProcedureAction.java | 9 ++------ .../apache/cayenne/access/jdbc/SelectAction.java | 6 +----- 4 files changed, 14 insertions(+), 31 deletions(-) diff --git a/cayenne/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java b/cayenne/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java index 15c6e8ace..d914ca626 100644 --- a/cayenne/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java +++ b/cayenne/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java @@ -276,8 +276,6 @@ public class BatchAction extends BaseSQLAction { if (generated.size() == 1 && keysRS.getMetaData().getColumnCount() == 1) { DbAttribute key = generated.iterator().next(); - ColumnDescriptor[] columns = new ColumnDescriptor[1]; - // use column name from result set, but type and Java class from DB attribute ResultSetMetaData md = keysRS.getMetaData(); String columnName = md.getColumnLabel(1); @@ -288,8 +286,7 @@ public class BatchAction extends BaseSQLAction { } } ExtendedType type = dataNode.getAdapter().getExtendedTypes().getRegisteredType(typeForGeneratedPK(key)); - columns[0] = new ColumnDescriptor(columnName, columnName, key.getType(), type, null); - rowBuilder.columns(columns); + rowBuilder.columns(new ColumnDescriptor(columnName, columnName, key.getType(), type, null)); } else { rowBuilder.resultSet(keysRS); } diff --git a/cayenne/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java b/cayenne/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java index 0664f7ee2..12f6ad9bf 100644 --- a/cayenne/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java +++ b/cayenne/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java @@ -92,15 +92,12 @@ public record ColumnDescriptor(String name, String dataRowKey, int jdbcType, Ext private static final Function<String, String> LOWERCASE_TRANSFORMER = input -> input != null ? input.toLowerCase() : null; - protected ColumnDescriptor[] columns; - protected ResultSetMetaData resultSetMetadata; - - protected Function<String, String> caseTransformer; - protected Map<String, String> typeOverrides; - + private ColumnDescriptor[] columns; + private ResultSetMetaData resultSetMetadata; + private Function<String, String> caseTransformer; + private Map<String, String> typeOverrides; private boolean mergeColumnsWithRsMetadata; - - protected boolean validateDuplicateColumnNames; + private boolean validateDuplicateColumnNames; /** * Returns the array of {@link ColumnDescriptor}s describing the result row, with an {@link ExtendedType} @@ -175,8 +172,8 @@ public record ColumnDescriptor(String name, String dataRowKey, int jdbcType, Ext } if (validateDuplicateColumnNames && !duplicates.isEmpty()) { - LOGGER.warn("Found duplicated columns '{}' in row descriptor. " + - "This can lead to errors when converting result to persistent objects.", + LOGGER.warn( + "Found duplicated columns '{}' in row descriptor. This can lead to errors when converting result to persistent objects.", String.join("', '", duplicates)); } @@ -220,10 +217,8 @@ public record ColumnDescriptor(String name, String dataRowKey, int jdbcType, Ext return new ColumnDescriptor(rowKey, rowKey, jdbcType, type, null); } - /** - * Return not empty string with ColumnLabel or ColumnName or "column_" + position for - * for specified (by it's position) column in ResultSetMetaData. - */ + // Return a non-empty string with ColumnLabel or ColumnName or "column_<pos>" for positional column + // in ResultSetMetaData. private String resolveDataRowKeyFromResultSet(int position) throws SQLException { String name = resultSetMetadata.getColumnLabel(position); if (name == null || name.isEmpty()) { @@ -270,7 +265,7 @@ public record ColumnDescriptor(String name, String dataRowKey, int jdbcType, Ext * Sets an explicit set of columns. The builder may replace these with new instances to enforce the column * capitalization policy and column Java type overrides. */ - public RowBuilder columns(ColumnDescriptor[] columns) { + public RowBuilder columns(ColumnDescriptor... columns) { this.columns = columns; return this; } diff --git a/cayenne/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java b/cayenne/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java index 1f6d1da1f..2ef9e7eb5 100644 --- a/cayenne/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java +++ b/cayenne/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java @@ -178,7 +178,8 @@ public class ProcedureAction extends BaseSQLAction { throw new CayenneRuntimeException("No descriptor for result set at index '%d' configured.", setIndex); } - builder.columns(toColumnDescriptors(descriptors.get(setIndex), + builder.columns(toColumnDescriptors( + descriptors.get(setIndex), dataNode.getAdapter().getExtendedTypes())); } @@ -194,12 +195,6 @@ public class ProcedureAction extends BaseSQLAction { return builder.build(dataNode.getAdapter().getExtendedTypes()); } - /** - * Translates the adapter-independent {@link ProcedureColumn} specs configured on the query into runtime - * {@link ColumnDescriptor}s. - * - * @since 5.0 - */ private static ColumnDescriptor[] toColumnDescriptors(ProcedureColumn[] columns, ExtendedTypeMap typeMap) { ColumnDescriptor[] result = new ColumnDescriptor[columns.length]; for (int i = 0; i < columns.length; i++) { diff --git a/cayenne/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java b/cayenne/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java index 135d3d8c7..1414cb3da 100644 --- a/cayenne/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java +++ b/cayenne/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java @@ -107,11 +107,7 @@ public class SelectAction extends BaseSQLAction { throw ex; } - ColumnDescriptor[] columns = ColumnDescriptor.rowBuilder() - .columns(translated.resultColumns()) - .build(dataNode.getAdapter().getExtendedTypes()); - - RowReader<?> rowReader = dataNode.getRowReaderFactory().rowReader(columns, queryMetadata, dataNode.getAdapter()); + RowReader<?> rowReader = dataNode.getRowReaderFactory().rowReader(translated.resultColumns(), queryMetadata, dataNode.getAdapter()); ResultIterator<?> it = new JDBCResultIterator<>(statement, rs, rowReader); it = forIteratedResult(it, observer, connection, t1, translated.sql());
