pushConditions(context, ACCOUNTS,
ACCOUNTS.ID, ids);
I'm looking to push a condition for a column with a specific name on ANY table that has that column present. I'm having trouble figuring out how to identify/grab/return the Field of interest to push it into the condition. Any help you can provide would be greatly apprecitated.
Many thanks,
-Kevin
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<E>
void
pushConditions(
VisitContext context,
Table<?> table,
Field<E> field,
E... values) {
// Check if we're visiting the given table
if
(context.queryPart() == table) {
List<Clause> clauses = clauses(context);
<E>
void
pushConditions(
VisitContext context,
String name,
E... values) {
// Check if we're visiting a table containing the field name
if
(context.queryPart()
instanceof Table &&
((Table<?>) context.queryPart()).field(name) != null) {
// ...To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--Thank you
Samir Faci
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
Thank you Lukas,
I think ...
((Table<?>) context.queryPart()).field(name)
... was the part I was missing.
As to your comment about performance, as my schema will not change after initialization of the system, when I initialize the EventListener i will set up something such a Hashmap <Table, Field>, to quickly find the corresponding field for the tables visited in the query context.
final String recordType = out.ref(getStrategy().getFullJavaClassName(table, Mode.RECORD));
Hi Lukas,
My initial approach of using HashMap didn't appear to work as I got into an endless loop. Seems the hash function triggers the VisitListener.
You idea for getSpecialField seemed a cleaner solution anyways, but in my attempts to write it I referenced how JavaGenerator generates getRecordVersion methods.
I was hoping to just extend the JavaGenerator class and override generateTableClassFooter, but I ran into the problem that my method would need the recordType and something like the following line (plucked from the JavaGenerator)....
final String recordType = out.ref(getStrategy().getFullJavaClassName(table, Mode.RECORD));
Isn't possible as all out.ref methods are protected.
Am I missing an obvious way to get 'recordType'? I wouldn't be surprised quite often the obvious stuff eludes me.
public class Junit extends TableImpl<JunitRecord> implements AuditedTable {
<E> void pushConditions(VisitContext context) {
if (context.queryPart() instanceof Table){
LOG.info("... Table " + context.queryPart().toString());
// Check if we're visiting a special table
if ((context.queryPart()) instanceof AuditedTable) {
LOG.info("... AuditedTable " + context.queryPart().toString());
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
Hi Kevin,Just to be sure, in your snippet, you didn't omit any "else" or "return" or any other sort of statement that would break out of the method prior to checking your instanceof AuditTable check?
Also, what's the complete code of your visit listener right now? When is pushConditions() called?
@Override
public void visitEnd(VisitContext context) {
pushConditions(context);
Lukas
2017-05-18 0:30 GMT+02:00 Kevin Embree <embree...@gmail.com>:
One step closer, yet no joy.
I customized the Generation Strategy and get a Table that implements a custom interface 'AuditedTable'
public class Junit extends TableImpl<JunitRecord> implements AuditedTable {
But in the visitListener ...'instanceof Table' works as I expected.
<E> void pushConditions(VisitContext context) {
if (context.queryPart() instanceof Table){
LOG.info("... Table " + context.queryPart().toString());
// Check if we're visiting a special table
if ((context.queryPart()) instanceof AuditedTable) {
LOG.info("... AuditedTable " + context.queryPart().toString());
But 'Instanceof AuditedTable' doesn't. I must be misunderstanding how the AST queryParts work.
Any nudge in the right direction would greatly appreciated.
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
public class VisitListenerTest extends AbstractTest {class TableCatcher extends DefaultVisitListener {final Predicate<VisitContext> matcher;int hits;public TableCatcher(Predicate<VisitContext> matcher) {this.matcher = matcher;}@Overridepublic void visitEnd(VisitContext ctx) {if (matcher.test(ctx))hits++;super.visitEnd(ctx);}}@Testpublic void testFindingCustomTableWithVisitListener() {TableCatcher c1 = new TableCatcher(ctx -> ctx.queryPart() instanceof MyTable);TableCatcher c2 = new TableCatcher(ctx -> ctx.queryPart() instanceof IMyTable);TableCatcher c3 = new TableCatcher(ctx -> ctx.queryPart() instanceof I);DSL.using(create.configuration().derive(providers(c1))).selectFrom(new MyTable()).getSQL();DSL.using(create.configuration().derive(providers(c2))).selectFrom(new MyTable()).getSQL();DSL.using(create.configuration().derive(providers(c3))).selectFrom(new MyTable()).getSQL();assertEquals(1, c1.hits);assertEquals(1, c2.hits);assertEquals(0, c3.hits);}interface I {}interface IMyTable {}static class MyTable extends TableImpl<MyTableRecord> implements IMyTable {MyTable() {super(DSL.name("my_table"));}}static class MyTableRecord extends TableRecordImpl<MyTableRecord> {public MyTableRecord() {super(new MyTable());}}}
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.