*/
public Envelope calculateQueryExtent() throws IOException {
LOGGER.fine("Building a new SeQuery to consult it's resulting envelope");
final SeExtent extent;
try {
extent = session.issue(new Command<SeExtent>() {
@Override
public SeExtent execute(ISession session, SeConnection connection)
throws SeException, IOException {
final String[] queryColumns;
{
List<String> cols = new ArrayList<String>(2);
String geomCol = schema.getGeometryDescriptor().getLocalName();
geomCol = filters.getSqlEncoder().getColumnDefinition(geomCol);
String fidAtt;
if (fidReader.getFidColumn() == null) {
fidAtt = schema.getDescriptor(0).getLocalName();
} else {
fidAtt = fidReader.getFidColumn();
}
cols.add(fidAtt);
queryColumns = cols.toArray(new String[cols.size()]);
}
// fullConstruct may hold information about multiple tables in case of an
// in-process view
final SeSqlConstruct fullConstruct = filters.getQueryInfo(queryColumns)
.getConstruct();
String whereClause = fullConstruct.getWhere();
if (whereClause == null) {
/*
* we really need a where clause or will get a famous -51 DATABASE LEVEL
* ERROR with no other explanation on some oracle databases
*/
whereClause = "1 = 1";
}
final SeFilter[] spatialConstraints = filters.getSpatialFilters();
SeExtent extent;
final SeQuery extentQuery = new SeQuery(connection);
try {
versioningHandler.setUpStream(session, extentQuery);
if (spatialConstraints.length > 0) {
extentQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false,
spatialConstraints);
}
SeSqlConstruct sqlCons = new SeSqlConstruct();
sqlCons.setTables(fullConstruct.getTables());
sqlCons.setWhere(whereClause);
final SeQueryInfo seQueryInfo = new SeQueryInfo();
seQueryInfo.setColumns(queryColumns);
seQueryInfo.setConstruct(sqlCons);
extent = extentQuery.calculateLayerExtent(seQueryInfo);
} finally {
extentQuery.close();
}
return extent;
}
});
} catch (IOException ex) {
SeSqlConstruct sqlCons = this.filters.getSeSqlConstruct();
String sql = (sqlCons == null) ? null : sqlCons.getWhere();
String tables = (sqlCons == null) ? null : Arrays.asList(sqlCons.getTables())
.toString();
if (ex.getCause() instanceof SeException) {
SeException sdeEx = (SeException) ex.getCause();
if (sdeEx.getSeError().getSdeError() == -288) {
// gah, the dreaded 'LOGFILE SYSTEM TABLES DO NOT EXIST'
// error.
// this error is worthless. Make it quiet, at least.
LOGGER.severe("ArcSDE is complaining that your 'LOGFILE SYSTEM "
+ "TABLES DO NOT EXIST'. This is an ignorable error.");
}
}
LOGGER.log(Level.SEVERE, "***********************\ntables: " + tables + "\nfilter: "
+ this.filters.getGeometryFilter() + "\nSQL: " + sql, ex);
throw ex;
}
Envelope envelope = new Envelope(extent.getMinX(), extent.getMaxX(), extent.getMinY(),
extent.getMaxY());
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("got extent: " + extent + ", built envelope: " + envelope);
}
return envelope;
}