Skip to content

Commit

Permalink
[GEOS-8323] Added debug logging to all JDBC Configuration database qu…
Browse files Browse the repository at this point in the history
…eries. Fixed an NPE in JDBCGeoServerImplTest.
  • Loading branch information
sikeoka committed Oct 6, 2017
1 parent 2c56237 commit 0d6c852
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Proxy;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -88,6 +90,7 @@
import org.opengis.filter.expression.PropertyName;
import org.opengis.filter.sort.SortBy;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
Expand All @@ -98,7 +101,6 @@
import org.springframework.util.Assert;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Stopwatch;
import com.google.common.base.Throwables;
Expand All @@ -111,11 +113,6 @@
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

/**
*
*/
Expand Down Expand Up @@ -306,8 +303,7 @@ public String mapRow(ResultSet rs, int rowNum) throws SQLException {
});
sw.stop();
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(Joiner.on("").join("query returned ", ids.size(), " records in ",
sw.toString()));
LOGGER.fine("query returned " + ids.size() + " records in " + sw);
}

List<T> lazyTransformed = Lists.transform(ids, new Function<String, T>() {
Expand Down Expand Up @@ -601,12 +597,16 @@ public void remove(Info info) {
String deleteObject = "delete from object where id = :id";
String deleteRelatedProperties = "delete from object_property where related_oid = :oid";

int updateCount = template.update(deleteObject, ImmutableMap.of("id", info.getId()));
Map<String, ?> params = ImmutableMap.of("id", info.getId());
logStatement(deleteObject, params);
int updateCount = template.update(deleteObject, params);
if (updateCount != 1) {
LOGGER.warning("Requested to delete " + info + " (" + info.getId()
+ ") but nothing happened on the database.");
}
final int relatedPropCount = template.update(deleteRelatedProperties, params("oid", oid));
params = params("oid", oid);
logStatement(deleteRelatedProperties, params);
final int relatedPropCount = template.update(deleteRelatedProperties, params);
LOGGER.fine("Removed " + relatedPropCount + " related properties of " + info.getId());

cache.invalidate(info.getId());
Expand Down Expand Up @@ -796,8 +796,9 @@ private void updateQueryableProperties(final Info info, final Integer objectId,
String sql = "delete from object_property where oid=:oid and property_type=:property_type "
+ "and colindex > :maxIndex";
Integer maxIndex = Integer.valueOf(values.size());
template.update(sql,
params("oid", oid, "property_type", propertyType, "maxIndex", maxIndex));
params = params("oid", oid, "property_type", propertyType, "maxIndex", maxIndex);
logStatement(sql, params);
template.update(sql, params);
}
}
}
Expand Down Expand Up @@ -904,7 +905,13 @@ public <T extends Info> List<T> getAll(final Class<T> clazz) {

final String sql = "select id from object where type_id in ( :types ) order by id";

logStatement(sql, params);
Stopwatch sw = Stopwatch.createStarted();
List<String> ids = template.queryForList(sql, params, String.class);
sw.stop();
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("query returned " + ids.size() + " records in " + sw);
}

List<T> transformed = Lists.transform(ids, new Function<String, T>() {
@Nullable
Expand Down Expand Up @@ -933,12 +940,15 @@ private <T extends Info> List<Integer> typesParam(final Class<T> clazz) {

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void setDefault(final String key, @Nullable final String id) {
String sql;
sql = "DELETE FROM DEFAULT_OBJECT WHERE DEF_KEY = :key";
template.update(sql, params("key", key));
String sql = "DELETE FROM DEFAULT_OBJECT WHERE DEF_KEY = :key";
Map<String, ?> params = params("key", key);
logStatement(sql, params);
template.update(sql, params);
if (id != null) {
sql = "INSERT INTO DEFAULT_OBJECT (DEF_KEY, ID) VALUES(:key, :id)";
template.update(sql, params("key", key, "id", id));
params = params("key", key, "id", id);
logStatement(sql, params);
template.update(sql, params);
}
}

Expand Down Expand Up @@ -982,8 +992,10 @@ public ConfigLoader(final String id) {
public Info call() throws Exception {
Info info;
try {
info = template.queryForObject("select blob from object where id = :id",
ImmutableMap.of("id", id), configRowMapper);
String sql = "select blob from object where id = :id";
Map<String, String> params = ImmutableMap.of("id", id);
logStatement(sql, params);
info = template.queryForObject(sql, params, configRowMapper);
} catch (EmptyResultDataAccessException noSuchObject) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void setUp() throws Exception {
facade.setResourceLoader(testSupport.getResourceLoader());

super.setUp();
facade.setLogging(geoServer.getFactory().createLogging());
}

@After
Expand Down

0 comments on commit 0d6c852

Please sign in to comment.