request.extractParameters();
TriggerManager.executeTriggers(getName(), request, true);
final Object results;
Connection connection = null;
final SqlStruct sqlStruct = sqlBuilder.buildSelectSql(metaData, definition.getQuery().getValue(),
request);
try {
connection = Factory.getConnection(SqlResourceDefinitionUtils.getDefaultDatabase(definition));
final PreparedStatement statement = connection.prepareStatement(sqlStruct.getPreparedStatement());
if (Config.logger.isDebugEnabled()) {
Config.logger.debug("\n" + sqlStruct.getPreparedStatement() + "\n-----\n"
+ sqlStruct.getStatement());
}
request.getLogger().addSql(sqlStruct.getStatement());
for (int i = 0; i < sqlStruct.getPreparedValues().size(); i++) {
statement.setObject(i + 1, sqlStruct.getPreparedValues().get(i));
}
final ResultSet resultSet = statement.executeQuery();
if (metaData.isHierarchical()) {
if (contentType != null) {
results = Factory.getResponseSerializer(contentType).serializeReadHierarchical(this,
buildReadResultsHierachicalCollection(resultSet));
} else {
results = buildReadResultsHierachicalCollection(resultSet);
}
} else {
if (contentType != null) {
results = Factory.getResponseSerializer(contentType).serializeReadFlat(this, resultSet);
} else {
results = buildReadResultsFlatCollection(resultSet);
}
}
resultSet.close();
statement.close();
} catch (final SQLException exception) {
throw new SqlResourceException(exception, sqlStruct.getStatement());
} finally {
if (connection != null) {
try {
connection.close();
} catch (final SQLException ignored) {