Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
45thAirhacksQ&A.md

dempile commented Nov 8, 2017

Hi Adam,
Have you tryed Beanshell and how do you compare it to a Groovy, Scala, or newly Kotlin ?
Can Kotlin be used in a JEE Application, if yes in which part of the application it's more useful.
What's the best solution to create reports instead of JasperReport ?

taysay commented Nov 12, 2017

Hi Adam,

Please how to you handle RESTful header custom parameters behind an apache httpd service. Apache seems to drop none standard parameters on the http header. Thank you so much.

afrunt commented Nov 12, 2017

Hi Adam!
I was inspired by your videos about the java ee and now I want to remember, how to live without tons of dependencies.
The last question is, how could I achieve switching between two persistence units like so

public abstract class DAO<ET, KT, DT extends DAO<ET, KT, DT>> implements WithEntityManager {
    @PersistenceContext(name = "corePU")
    private EntityManager em;

    @PersistenceContext(name = "odsPU")
    private EntityManager odsEm;

    private boolean ods;

    private DT odsInstance;

    //obsolete datasource
    public DT ods(){
        //should return the new managed bean of the same DAO type, but with ods==true to choose the odsPU instead of corePU
    }

    @Override
    public EntityManager getEntityManager() {
        if (ods) {
            return odsEm;
        } else {
            return em;
        }
    }
}

@Stateless
public class PaymentDAO extends DAO<Payment, Long, PaymentDAO> {
    public PaymentDAO() {
        super(Payment.class, Long.class);
    }
}

@Named
@Path("/payment")
@Produces("application/json")
@Consumes("application/json")
public class PaymentResource {
    @Inject
    private Logger logger;

    @Inject
    private PaymentDAO paymentDAO;

    @GET
    @Path("/{id}")
    public Payment payment(@PathParam("id") long id) {
        //should be able to work this way
        //payment from core DS
        Payment payment = paymentDAO.find(id);
        //payment from ODS
        Payment paymentOds = paymentDAO.ods().find(id);
        return payment;
    }
}

I did it before with Spring, where I was able to create such instances on the fly if they doesn't exist (using applicationContext and beanFactory). What should I do with CDI to achieve the same, I mean, how to create the identical bean with toggled flag and different qualifier and return it? The actual problem is to use the same xxxDAO contract with different datasources without additional parameters in methods definitions. DAO's are stateless, so I don't able to just toggle those flag.

I found some solution, that looks like below. Is it right to do it this way? It works, but maybe there is some other good approach to do the same.

public <T> T ods() {
        if (odsInstance != null) {
            return odsInstance;
        }

        odsInstance = new Unmanaged<>(getClass())
                .newInstance()
                .produce()
                .inject()
                .postConstruct()
                .get()
                .setOds(true);
        
        return odsInstance;
}

Thanks !

Owner

AdamBien commented Nov 13, 2017

@AdamBien what do you think about using @kotlin in pair with java in JEE project just like @springframework did ?

— omar Alvarez (@denpile) November 13, 2017

Hi Adam,

a small observation about conversation
about frameworks/technology in teams,...:

I‘ve noticed that there is a tend to more/growing intrinsic motivated „discussions“ rather than talking about the technology judicious (Dunning-Kruger-Effect) in teams, ...

For example: „We have to use this framework. Google uses it. It is so great“

Beside of the fact that correlation and causality have been flipped by this statement it ends sometimes the discussion because for the person it is no more relevant what others say,...

Your experience with deadlocked conversations?

Greetings from Munich

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