public class RedQueryBuilder implements EntryPoint {
private void createCommandBuilder(final Configuration config, String sql, List args)
throws Exception {
final Session session = new Session(config);
final CommandBuilder builder = new CommandBuilder(session, sql, args);
session.getMsgBus().addHandler(TableEvent.TYPE,
new TableEventHandler() {
@Override
public void onTable(TableEvent e) {
if (session.getFilters().size() > 0) {
config.fireOnTableChange(session.getFilters());
// XXX need to do distinct?
ObjectArray expr = ObjectArray.newInstance();
TableFilter tf = session.getFilters().get(0);
String alias = tf.getAlias();
for (Column col : tf.getTable().getColumns()) {
expr.add(new ExpressionColumn(session, null, alias,
col.getName()));
}
builder.getSelect().setExpressions(expr);
} else {
builder.getSelect().setExpressions(null);
}
}
});
builder.addValueChangeHandler(new ValueChangeHandler<Select>() {
@Override
public void onValueChange(ValueChangeEvent<Select> event) {
List<Object> args = new ArrayList<Object>();
String sql = event.getValue().getSQL(args);
config.fireOnSqlChange(sql, args);
}
});
builderContainer.setWidget(builder);
config.fireOnTableChange(session.getFilters());
}