-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from looker-open-source/goomrw-get-by-label
Fix `findColumn` and `get*(String label)` methods.
- Loading branch information
Showing
7 changed files
with
356 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/net/starschema/clouddb/jdbc/CommonResultSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.