public void performAction(Connection connection, OperationObserver observer)
throws SQLException, Exception {
long t1 = System.currentTimeMillis();
SelectTranslator translator = createTranslator(connection);
PreparedStatement prepStmt = translator.createStatement();
ResultSet rs = prepStmt.executeQuery();
RowDescriptor descriptor = new RowDescriptor(
translator.getResultColumns(),
getAdapter().getExtendedTypes());
JDBCResultIterator workerIterator = new JDBCResultIterator(
connection,
prepStmt,
rs,
descriptor,
query.getFetchLimit());
workerIterator.setPostProcessor(DataRowPostProcessor
.createPostProcessor(translator));
ResultIterator it = workerIterator;
// wrap result iterator if distinct has to be suppressed
if (translator.isSuppressingDistinct()) {
// a joint prefetch warrants full row compare
final boolean[] compareFullRows = new boolean[1];
QueryMetadata md = query.getMetaData(getEntityResolver());
final PrefetchTreeNode rootPrefetch = md.getPrefetchTree();
if (rootPrefetch != null) {
rootPrefetch.traverse(new PrefetchProcessor() {
public void finishPrefetch(PrefetchTreeNode node) {
}
public boolean startDisjointPrefetch(PrefetchTreeNode node) {
// continue to children only if we are at root
return rootPrefetch == node;
}
public boolean startUnknownPrefetch(PrefetchTreeNode node) {
// continue to children only if we are at root
return rootPrefetch == node;
}
public boolean startJointPrefetch(PrefetchTreeNode node) {
if (rootPrefetch != node) {
compareFullRows[0] = true;
return false;
}
return true;
}
public boolean startPhantomPrefetch(PrefetchTreeNode node) {
return true;
}
});
}
it = new DistinctResultIterator(
workerIterator,
translator.getRootDbEntity(),
compareFullRows[0]);
}
// TODO: Should do something about closing ResultSet and PreparedStatement in this
// method, instead of relying on DefaultResultIterator to do that later
if (!observer.isIteratedResult()) {
// note that we don't need to close ResultIterator
// since "dataRows" will do it internally
List resultRows = it.dataRows(true);
QueryLogger
.logSelectCount(resultRows.size(), System.currentTimeMillis() - t1);
observer.nextDataRows(query, resultRows);
}
else {
try {
workerIterator.setClosingConnection(true);
observer.nextDataRows(translator.getQuery(), it);
}
catch (Exception ex) {
it.close();
throw ex;
}