use of com.google.refine.extension.database.model.DatabaseRow in project OpenRefine by OpenRefine.
the class PgSQLDatabaseService method getRows.
@Override
public List<DatabaseRow> getRows(DatabaseConfiguration dbConfig, String query) throws DatabaseServiceException {
try {
Connection connection = PgSQLConnectionManager.getInstance().getConnection(dbConfig, false);
Statement statement = connection.createStatement();
statement.setFetchSize(10);
ResultSet queryResult = statement.executeQuery(query);
PgResultSetMetaData metadata = (PgResultSetMetaData) queryResult.getMetaData();
int columnCount = metadata.getColumnCount();
int index = 0;
List<DatabaseRow> rows = new ArrayList<DatabaseRow>();
while (queryResult.next()) {
DatabaseRow row = new DatabaseRow();
row.setIndex(index);
List<String> values = new ArrayList<String>(columnCount);
for (int i = 1; i <= columnCount; i++) {
values.add(queryResult.getString(i));
}
row.setValues(values);
rows.add(row);
index++;
}
return rows;
} catch (SQLException e) {
logger.error("SQLException::{}::{}", e);
throw new DatabaseServiceException(true, e.getSQLState(), e.getErrorCode(), e.getMessage());
}
}
Aggregations