Skip to content

Commit

Permalink
feature(RowMetadata)[gh-56]: add getColumnMetadata on RowMetadata
Browse files Browse the repository at this point in the history
Replace Stream with forEach

replace foreach with for loop

remove unused import

change to Collection

Change to LinkedHashSet
  • Loading branch information
nbenjamin committed Apr 25, 2019
1 parent fe2cc67 commit aaebf6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
import io.r2dbc.spi.ColumnMetadata;
import io.r2dbc.spi.RowMetadata;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Collection;
import java.util.Set;
import java.util.Collections;
import java.util.ArrayList;

public final class MockRowMetadata implements RowMetadata {

Expand Down Expand Up @@ -50,6 +54,15 @@ public List<ColumnMetadata> getColumnMetadatas() {
return this.columnMetadatas;
}

@Override
public Collection<String> getColumnNames() {
Set<String> columnNames = new LinkedHashSet<>();
for(ColumnMetadata columnMetadata : columnMetadatas) {
columnNames.add(columnMetadata.getName());
}
return Collections.unmodifiableCollection(columnNames);
}

@Override
public String toString() {
return "MockRowMetadata{" +
Expand Down
11 changes: 11 additions & 0 deletions r2dbc-spi/src/main/java/io/r2dbc/spi/RowMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.r2dbc.spi;

import java.util.Collection;
import java.util.NoSuchElementException;

/**
Expand All @@ -41,4 +42,14 @@ public interface RowMetadata {
*/
Iterable<? extends ColumnMetadata> getColumnMetadatas();

/**
* Returns an unmodifiable collection of unique column names, and any attempts to modify the returned
* collection, whether direct or via its iterator, result in an {@link UnsupportedOperationException}.
* The order of the column names depends on the actual query and also column name lookup depends on the database
* sorting rules and some databases support escape characters to enforce a particular mode of comparison.
*
* @return the column names.
*/
Collection<String> getColumnNames();

}

0 comments on commit aaebf6b

Please sign in to comment.