I want to know Best practices for initilizing JOOQ generated DAO. Now,I am using following approach for initilization of JOOQ generated DAO. In following case StudentDao is JOOQ generated.
public class ExtendedStudentDAO extends StudentDao { public ExtendedStudentDAO () { super(); } public ExtendedStudentDAO (Connection connection) { Configuration configuration = DSL.using(connection, JDBCUtils.dialect(connection)).configuration(); this.setConfiguration(configuration); } //adding extra methods to DAO using DSL public String getStudentName(Long ID) throws SQLException { try (Connection connection = ServiceConnectionManager.getConnection()) { DSLContext dslContext = ServiceConnectionManager .getDSLContext(connection); Record1<String> record = dslContext .select(Student.Name) .from(Student.Student) .where(Student.ID .equal(ID)).fetchOne(); if (record != null) { return record.getValue(Student.Name); } return null; } } }
and I have doubt with using above DAO my example code is below.
try (Connection connection = ServiceConnectionManager.getConnection()) { ExtendedStudentDAO extendedStudentDAO =new ExtendedStudentDAO(connection); Student stud=new Student(); ..... .... //insert method is from Generated DAO extendedStudentDAO.insert(stud); //this method is added in extended class extendedStudentDAO.getStudentName(12); }