Jooq - Add code to generated post class

I am learning how to work with jooq. I would like to know if I can add some domain level methods to the generated record classes.

Suppose the entry was as follows:

public class ConCalCompanyRecord extends org.jooq.impl.UpdatableRecordImpl<com.aesthete.csmart.connect.model.db.gen.tables.records.ConCalCompanyRecord> implements org.jooq.Record6<java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.sql.Timestamp, java.sql.Timestamp> {

// properties
// getters and setters

// I would like to add a method like this:
   public void isABlueCompany(){
     // work with the fields
   }

}

But I know, if I do this, as soon as I again generate this class from the database, all my changes will be lost. So what is the recommended way to do this?

Shell class? Subclass for writing? If this is any of them, how can I get jooq to recognize these classes during fetching. For instance:

connectionFacade.getDSLContext()
            .selectFrom(CON_CAL_INSTANCE)
            .where(CON_CAL_INSTANCE.DATE.between(
                    new Date(datesOfTheWeekForDate[0].toDate().getTime()), new Date(datesOfTheWeekForDate[1].toDate().getTime())))
            .orderBy(CON_CAL_INSTANCE.DATE)
            .fetch()
            .into(new RecordHandler<ConCalInstanceRecord>() {
                @Override
                public void next(ConCalInstanceRecord record) {
                    calendarEntries.addToList(new com.aesthete.csmart.connect.model.domain.records.ConCalInstance(record));
                   }
            });

In the above case, I am providing the ConCalInstance wrapper to the record class. Should I write a RecordHandler, like this for every query I execute, if I need to use a wrapper? What is the recommended way to do this?

+3
source share
2

, , ,

public class ConCalInstanceRecord extends org.jooq.impl.UpdatableRecordImpl....{

     //fields and getter and setters of the generated record..

    private ConCalInstanceBehaviour behaviour;

    public ConCalInstanceBehaviour getBehaviour(){
        if(behaviour==null){
            behaviour=new ConCalInstanceBehaviour(this);
        }
        return behaviour;
    }
}

, , , . , , .

, ...

record.getBehaviour().doSomething();
+1

jOOQ . , :

, :

public class MyGenerator extends JavaGenerator {

    @Override
    protected void generateRecordClassFooter(
        TableDefinition table, 
        JavaWriter out
    ) {
        super.generateRecordClassFooter(table, out);

        if ("SOME_TABLE".equals(table.getName())) {
            out.println();
            out.tab(1).println("public void isABlueCompany() {");
            out.tab(2).println("// Your logic here");
            out.tab(1).println("}");
        }
        else if ("SOME_OTHER_TABLE".equals(table.getName())) {
            // [...]
        }
    }
}
+2

All Articles