Hey Lukas,
Thanks for the heads up.
By extending TableImpl with following:
class DynamicTable extends TableImpl {
public DynamicTable(String name) {
super(name);
}
<T> void addField(String name, DataType<T> type) {
createField(name, type, this);
};
}
I was able to create to change the above code to:
Factory db = new Factory(SQLDialect.HSQLDB);
DynamicTable table = new DynamicTable("SOME_TABLE");
table.addField("ID", SQLDataType.INTEGER);
Table<Record> a = table.as("a");
Table<Record> b = table.as("b");
Field aId = a.getField("ID");
Field bId = b.getField("ID");
SelectJoinStep sql =
db.select().
from(a).
join(b).
on(aId.eq(bId));
Thanks for your help,
Ben
On Sun, Dec 2, 2012 at 9:01 AM, Lukas Eder <[email protected]> wrote:
> > Is there a way to programmatically scope the id field on a and b in
> order to
> > produce the join?
>
> In general, that's what the Table.getField() methods are for. If the
> table is aware of the fields it contains, you can get a new "scoped"
> field with the scope of the relevant table alias "a" or "b", to
> produce "a"."ID" or "b"."ID". However, this doesn't work with
> tableByName (I wonder if there would be a way to enhance jOOQ for it
> to work?)
>
> The best approach for you might be to re-create those artefacts that
> are generated by jOOQ. You don't have to generate them, you can create
> them on-the-fly. In essence, tables extend TableImpl
> (http://www.jooq.org/javadoc/latest/org/jooq/impl/TableImpl.html) and
> fields within a table are created using createField (
>
> http://www.jooq.org/javadoc/latest/org/jooq/impl/TableImpl.html#createField%28java.lang.String,%20org.jooq.DataType,%20org.jooq.Table%29
> ).
>
> Beware though, that using jOOQ's internals may lead to issues when
> upgrading in the future.
>