Skip to content

Commit

Permalink
Add Javadoc, use common findColumn implementation.
Browse files Browse the repository at this point in the history
Addresses code review comments.
  • Loading branch information
goomrw committed Dec 19, 2023
1 parent cbee724 commit 30350ea
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -586,29 +586,10 @@ public void deleteRow() throws SQLException {
throw new BQSQLFeatureNotSupportedException("deleteRow()");
}

/**
*
*
* <h1>Implementation Details:</h1>
*
* <br>
* Not implemented yet.
*
* @throws BQSQLException
*/
/** {@inheritDoc} */
@Override
public int findColumn(String columnLabel) throws SQLException {
if (isClosed()) {
throw new BQSQLException("This Resultset is Closed");
}
final ResultSetMetaData metadata = this.getMetaData();
int columns = metadata.getColumnCount();
for (int i = 1; i <= columns; i++) {
if (metadata.getColumnLabel(i).equals(columnLabel)) {
return i;
}
}
throw new BQSQLException("No Such column labeled: " + columnLabel);
return CommonResultSet.findColumn(columnLabel, getMetaData());
}

/**
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/net/starschema/clouddb/jdbc/BQResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,7 @@ public BQResultSet(
/** {@inheritDoc} */
@Override
public int findColumn(String columnLabel) throws SQLException {
if (this.isClosed()) {
throw new BQSQLException("This Resultset is Closed");
}
final ResultSetMetaData metadata = this.getMetaData();
int columns = metadata.getColumnCount();
for (int i = 1; i <= columns; i++) {
if (metadata.getColumnLabel(i).equals(columnLabel)) {
return i;
}
}
SQLException e = new BQSQLException("No Such column labeled: " + columnLabel);
throw e;
return CommonResultSet.findColumn(columnLabel, getMetaData());
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,7 @@ public BQScrollableResultSet(
/** {@inheritDoc} */
@Override
public int findColumn(String columnLabel) throws SQLException {
if (this.isClosed()) {
throw new BQSQLException("This Resultset is Closed");
}
final ResultSetMetaData metadata = this.getMetaData();
int columns = metadata.getColumnCount();
for (int i = 1; i <= columns; i++) {
if (metadata.getColumnLabel(i).equals(columnLabel)) {
return i;
}
}
throw new BQSQLException("No Such column labeled: " + columnLabel);
return CommonResultSet.findColumn(columnLabel, getMetaData());
}

/** {@inheritDoc} */
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/net/starschema/clouddb/jdbc/CommonResultSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.starschema.clouddb.jdbc;

import com.google.cloud.bigquery.BigQuerySQLException;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

/** A static utility class of methods common to all {@link java.sql.ResultSet} implementations. */
class CommonResultSet {

/**
* A common implementation of {@link java.sql.ResultSet#findColumn(String)}
*
* @param label the column-to-find's label
* @param metadata the metadata from the {@link java.sql.ResultSet}
* @return the integer index of the labeled column, if it's found
* @throws SQLException if no column with the given label is found
*/
static int findColumn(final String label, final ResultSetMetaData metadata) throws SQLException {
int columnCount = metadata.getColumnCount();
for (int column = 1; column <= columnCount; column++) {
if (metadata.getColumnLabel(column).equals(label)) {
return column;
}
}
throw new BigQuerySQLException("No such Column labeled: " + label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
import org.junit.Before;
import org.junit.Test;

/**
* An abstract class that contains tests common to {@link ResultSet} implementations. Its name
* doesn't end with Test so that JUnit doesn't try to run it.
*
* <p>Subclass this in @{link ResultSet} test classes and implement {@link
* CommonTestsForResultSets#createStatementForCommonTests(Connection)}.
*/
public abstract class CommonTestsForResultSets {

private Connection connection;
Expand Down

0 comments on commit 30350ea

Please sign in to comment.