Skip to content

Instantly share code, notes, and snippets.

@AdamBien
Created June 21, 2024 04:45
Show Gist options
  • Save AdamBien/463d60f4fa37489120df7816d74ff3b3 to your computer and use it in GitHub Desktop.
Save AdamBien/463d60f4fa37489120df7816d74ff3b3 to your computer and use it in GitHub Desktop.
@nlisker
Copy link

nlisker commented Jun 30, 2024

Separation of @Entity and beans
We're told not to mix @Entity and EJB/CDI annotations on the same class. For classes that both hold data and have a behavior that requires injections, how should they be modeled? Splitting the data from the behavior looks like requiring data-oriented over object-oriented design (I'm not against).

Simplified use case: each automotive part (there are hundreds such parts) has its data and a function that is called on it from another class. Here is the approach for 2 of these classes.
In plain OO Java:

class ActionRegistar {
    List<Action> actions;

    void registerAction(Action action) { actions.add(action); } 
}

class Wheel {
    int size;

    public void roll(ActionRegistar registar) {
        Action roll = doRoll(size);
        registar.registerAction(roll);
    }
}

class Horn {
    int volume;

    public void honk(ActionRegistar registar) {
        Action honk = doHonk(volume);
        registar.registerAction(honk); // fined if too loud!
    }
}

and in Jakarta:

@Stateful/@RequestScoped
class ActionRegistar {
    List<Action> actions;

    void registerAction(Action action) { actions.add(action); } 
}

@Entity
class Wheel implements Part {
    int size;

    // can't add roll() here because no injections (unless using CDI lookup)
}

@???
class WheelAction implements Action {

    @Inject
    ActionRegistar registar;

    public void roll(Wheel wheel) {
        Action roll = doRoll(wheel.size);
        registar.registerAction(roll);
    }
}

// similar for Horn

If this is any good to begin with, how would I get the action class from the data class? Like this?

@ApplicationScoped/@Stateless
class ActionPerformer {

    @Inject
    private Instance<Action> instance;

    void performAction(Part part) {
        switch (part) { // pattern matching for switch
            case Wheel wheel -> {
                WheelAction action = instance.select(WheelAction.class).get();
                action.roll(wheel);
            }
            case Horn horn -> {
                HornAction action = instance.select(HornAction.class).get();
                action.honk(horn);
            }
            // case...
        };
    }
}

@AdamBien
Copy link
Author

AdamBien commented Jul 1, 2024

Questions asked at geecon session: "Containerless, Bloatless, YAML-less, Serverless Java #slideless" (https://2024.geecon.org/speakers/info.html?id=894) / https://youtu.be/qw7mgPE-SdQ?si=Jue1Wd2Zz7khffC5 :

  • Why is Kubernetes recommended in private dc but not in public cloud?
  • Why one should not mvn clean?
  • Can you show what is actually inside function.zip file?
  • Why maven not gradle?
  • Is it a good idea to building lambda as a quarkus native image?
  • As the bucket's name is generated, would the bucket be recreated after every deploy of the lambda?
  • What vscode plugins are you using for this kind of development in Java?
  • How to manage multiple environments in this setup ( staging | prod )
  • How to share s3 information with another project for example lambda?
  • How are you versioning and deploying the app for green/blue deployments to run two versions at a time?

@AdamBien
Copy link
Author

AdamBien commented Jul 1, 2024

The time machine, questions from 24th airhacks.tv from Mar 07, 2016:

  • Is Java EE Dying?
  • Cross-component business transactions and BCE
  • Webjars?!
  • Content negotiation
  • Concurrency, SLSB and throttling
  • Runtime pluggability and Java EE, CDI, OSGi
  • Groovy-based DSL for configurability?
  • Caches in crippled network environments
  • DAOs, Entities, CRUD and duplication
  • CDI in EAR
  • Portlets vs. Single Page apps
  • Annotation-based configuration
  • Managing common data with REST (aka microservices)
  • Streams vs. old collections
  • How to deal with abstract classes in BCE?

Questions gist: https://gist.github.com/AdamBien/ad9e7cdc110c634489ca

@AdamBien
Copy link
Author

AdamBien commented Jul 1, 2024

"Adam, do you think Java is losing space in the development of database engines? What do you see in Java development that will remedy this?" via (http://youtube.com/bienadam): https://studio.youtube.com/video/vAI_29c-p8M/comments

@kucharzyk
Copy link

Hi Adam,

I would like to ask for a good (and free for commercial use) Java library for document generation (pdf, docx).
Over the years I've been using different tools like Apache FOP, Jasper Reports, Crystal Reports, Apache POI, iText, openhtmltopdf.
Do we have now any good alternatives for reporting in Java world nowadays? Could you recommend anything?

@AdamBien
Copy link
Author

Hi Adam,

I would like to ask for a good (and free for commercial use) Java library for document generation (pdf, docx). Over the years I've been using different tools like Apache FOP, Jasper Reports, Crystal Reports, Apache POI, iText, openhtmltopdf. Do we have now any good alternatives for reporting in Java world nowadays? Could you recommend anything?

Please re-ask here: https://gist.github.com/AdamBien/edbfe339f2f1fbc7e5e2b219d51d5735 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment