Miscellaneous Database accessed at the same time JPA

1

Today I have the following scenario: my clients enter my site and the login screen appears, where I ask for the User Group, Login and Password.

For the Group I have a database, where it has the data of the user database ie on which server it is allocated the name etc.

With this, I check if the group exists. If it exists I close the connection from my Group Database, which is called Manager, and open the connection from the user database.

Each user has his / her database, so I open the user's database connection after checking if the group exists and write to a HTTPSESSION (obs: I write the EntityManegerFactory in the session), so all Once it does a search, I make EntityManager receive this factory from the session.

I want to know if this can slow the system, because my java server is crashing, I wanted to know if that is why.

Here I write the client database in the session:

 public EntityManager getEntityManager(String PU, String Local, String endfdb) {

    if (PU.equals("0")) {
        GestorEMF = Persistence.createEntityManagerFactory("GestorPU");
        return GestorEMF.createEntityManager();
    } else {
        Properties props = new Properties();

        props.setProperty("hibernate.connection.url", "jdbc:firebirdsql:"+endfdb+"/3050:" + Local);

        usrEMF = Persistence.createEntityManagerFactory(PU, props);
        HttpSession sess = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        sess.setAttribute("mitryusEMF", mitryusEMF);
        return mitryusEMF.createEntityManager();
    }
}

Here I switch to EM every time the user needs:

 public EntityManager getEntityMitryus() {
    EntityManagerFactory usuario = (EntityManagerFactory) getSession().getAttribute("mitryusEMF");

    return usuario.createEntityManager();
}
    
asked by anonymous 15.04.2016 / 03:00

0 answers