Skip to content

Commit

Permalink
Reduce usage of cglib lazy loading, switch it to use the spring embed…
Browse files Browse the repository at this point in the history
…ded version, but could not get rid of the warning fully
  • Loading branch information
aaime committed Oct 25, 2018
1 parent d713333 commit 7c9cbd5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
4 changes: 0 additions & 4 deletions src/wfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down
6 changes: 5 additions & 1 deletion src/wfs/src/main/java/org/geoserver/wfs/CountExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ public CountExecutor(int providedCount) {
}

public int getCount() throws IOException {
if (providedCount != COUNT_UNSET) {
if (isCountSet()) {
return providedCount;
} else {
// make sure we get a count by getting a feature colleciton
// FeatureSource.getCount(...) can return -1
return source.getFeatures(query).size();
}
}

public boolean isCountSet() {
return providedCount != COUNT_UNSET;
}
}
46 changes: 32 additions & 14 deletions src/wfs/src/main/java/org/geoserver/wfs/GetFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import net.opengis.wfs.XlinkPropertyNameType;
import net.opengis.wfs20.ResultTypeType;
import net.opengis.wfs20.StoredQueryType;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.LazyLoader;
import org.geoserver.catalog.AttributeTypeInfo;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.FeatureTypeInfo;
Expand Down Expand Up @@ -115,6 +113,8 @@
import org.opengis.filter.temporal.TEquals;
import org.opengis.metadata.extent.GeographicBoundingBox;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.LazyLoader;
import org.xml.sax.helpers.NamespaceSupport;

/**
Expand Down Expand Up @@ -764,6 +764,9 @@ public FeatureCollectionResponse run(GetFeatureRequest request) throws WFSExcept
// optimization: if count < max features then total count == count
// can't use this optimization for v2
totalCount = BigInteger.valueOf(count);
} else if (isPreComputed(totalCountExecutors)) {
long total = getTotalCount(totalCountExecutors);
totalCount = BigInteger.valueOf(total);
} else {
// ok, in this case we're forced to run the queries to discover the actual total
// count
Expand All @@ -777,18 +780,7 @@ public FeatureCollectionResponse run(GetFeatureRequest request) throws WFSExcept

@Override
public Object loadObject() throws Exception {
long totalCount = 0;
for (CountExecutor q : totalCountExecutors) {
int result = q.getCount();
// if the count is unknown for one, we don't know the total,
// period
if (result == -1) {
totalCount = -1;
break;
} else {
totalCount += result;
}
}
long totalCount = getTotalCount(totalCountExecutors);
return BigInteger.valueOf(totalCount);
}
});
Expand All @@ -815,6 +807,32 @@ public Object loadObject() throws Exception {
getFeatureById);
}

/** Returns true if all count executors are given a static count value */
private boolean isPreComputed(List<CountExecutor> totalCountExecutors) {
for (CountExecutor q : totalCountExecutors) {
if (!q.isCountSet()) {
return false;
}
}
return true;
}

private long getTotalCount(List<CountExecutor> totalCountExecutors) throws IOException {
long totalCount = 0;
for (CountExecutor q : totalCountExecutors) {
int result = q.getCount();
// if the count is unknown for one, we don't know the total,
// period
if (result == -1) {
totalCount = -1;
break;
} else {
totalCount += result;
}
}
return totalCount;
}

private Filter toFeatureIdFilter(List<FeatureId> lockedFeatures) {
if (lockedFeatures == null || lockedFeatures.isEmpty()) {
return Filter.EXCLUDE;
Expand Down

0 comments on commit 7c9cbd5

Please sign in to comment.