A easy instance configuration to generate bundle personal jOOQ code







Java’s bundle personal visibility is an underrated function. If you omit any visibility modifier in Java, then the default (for many objects) is bundle personal, i.e. the thing is seen solely to varieties in the identical bundle:

class YouDontSeeMe {}
class YouDontSeeMeEither {}

Actually, a compilation unit (the .java file) can comprise a number of such courses. You don’t must create a file per bundle personal kind. You would even put all of those varieties in your package-info.java file, it doesn’t matter.

When utilizing jOOQ’s code generator, issues are generated as public varieties per default, as you might be possible going to make use of this generated code in all places. You’ll be able to nonetheless limit entry utilizing Java 9’s module system if you’d like.

However sometimes, even with jOOQ generated code, bundle personal visibility may be helpful, if some information entry bundle desires to cover its implementation particulars from different packages within the module.

Right here’s an instance code era configuration to make this occur:


      <!-- Generates all objects in the identical bundle -->
      <!-- Ranging from jOOQ 3.19, you possibly can declare the technique code right here
           It will simplify your code era setup. In older
           variations, simply put the category in an auxiliary construct module and
           add it as a dependency.
      <java><![CDATA[package com.example.codegen;

import org.jooq.codegen.DefaultGeneratorStrategy;
import org.jooq.codegen.GeneratorStrategy.Mode;
import org.jooq.meta.Definition;

public class SinglePackageStrategy extends DefaultGeneratorStrategy {
    public String getJavaPackageName(Definition definition, Mode mode) {
        return getTargetPackage();


      <!-- Removes the "public" visibility modifier in all places -->


      <!-- This can be necessary if producing code in src/major/java! 
           It can stop cleansing the opposite bundle listing contents.
           Alternatively, use a separate goal <listing/>

That wasn’t too onerous? Utilizing this method, you possibly can be certain that your jOOQ generated code by no means leaks into any shopper code that shouldn’t see jOOQ varieties.


Supply hyperlink

Share this


Google Presents 3 Suggestions For Checking Technical web optimization Points

Google printed a video providing three ideas for utilizing search console to establish technical points that may be inflicting indexing or rating issues. Three...

A easy snapshot reveals how computational pictures can shock and alarm us

Whereas Tessa Coates was making an attempt on wedding ceremony clothes final month, she posted a seemingly easy snapshot of herself on Instagram...

Recent articles

More like this


Please enter your comment!
Please enter your name here