package net.sourceforge.mayfly.ldbc;

import net.sourceforge.mayfly.*;
import net.sourceforge.mayfly.datastore.*;
import net.sourceforge.mayfly.ldbc.what.*;
import net.sourceforge.mayfly.util.*;
import org.ldbc.parser.*;

import java.sql.*;
import java.util.*;

public class Select extends ValueObject {

    public static Select fromTree(Tree selectTree) {

        int[] typesToIgnore = new int[]{SQLTokenTypes.COMMA};

        L converted =
            selectTree.children().convertUsing(TreeConverters.forSelectTree(), typesToIgnore);

        Where where = 
            converted.selectObjectsThatAre(Where.class).size() > 0 ?
                    (Where) converted.selectObjectThatIs(Where.class) :
                    new Where();
                    
        return
            new Select(
                new What(converted.selectObjectsThatAre(WhatElement.class)),
                new Froms(converted.selectObjectsThatAre(From.class)),
                where
            );
    }


    private What what;
    private Froms froms;
    private Where where;

    public Select(What what, Froms froms, Where where) {
        this.what = what;
        this.froms = froms;
        this.where = where;
    }

    public Froms from() {
        return froms;
    }

    public ResultSet select(DataStore dataStore) throws SQLException {
        TableData tableData = dataStore.table(froms.singleTableName());

        List canonicalizedColumnNames = what.selectedColumns(tableData);
        return new MyResultSet(canonicalizedColumnNames, tableData);
    }

    public Rows executeOn(DataStore store) {
        Rows result = null;

        try {
            L tableNames = froms.tableNames();

            for (Iterator iterator = tableNames.iterator(); iterator.hasNext();) {
                String tableName = (String) iterator.next();
                result = result == null ?
                             store.table(tableName).rows() :
                             result.join(store.table(tableName).rows());
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return result;
    }
}

@@ -1593,16 +1593,36 @@
 e store)
+ throws SQLException
  %7B%0A     
@@ -1649,26 +1649,8 @@
 l;%0A%0A
-        try %7B%0A    
     
@@ -1685,28 +1685,24 @@
 leNames();%0A%0A
-    
         for 
@@ -1780,20 +1780,16 @@
         
-   
- 
 String t
@@ -1833,28 +1833,24 @@
             
-    
 result = res
@@ -1888,20 +1888,16 @@
         
-   
- 
 store.ta
@@ -1916,28 +1916,24 @@
 e).rows() :%0A
-    
             
@@ -1993,100 +1993,8 @@
 ));%0A
-            %7D%0A        %7D catch (SQLException e) %7B%0A            throw new RuntimeException(e);%0A
     

Don't wrap SQLException in a RuntimeException.