Managing multiple database connections with common schema

11 views
Skip to first unread message

ggran...@gmail.com

unread,
Jan 17, 2017, 12:07:05 PM1/17/17
to minuteproject
Hi Florian,

I'm hoping you have a recommended approach for managing entities that can point to different instances of databases with a common schema.  I'm using the BSLA code generation but the problem would probably have a wider audience.   There is a base class in the code gen that depends on injection to define database connection:

public abstract class EotcGenericDaoJpaImpl <T extends AbstractDomainObject> extends GenericDaoJpaImpl<T> {

    @PersistenceContext (unitName = "eotc")
    protected EntityManager entityManager;

    public EntityManager getEntityManager() {
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

}

Is there a way to decide at runtime which db instance will be chosen?   Seems there are several ways to get there but none seem too appealing.  Can the EntityManager be overridden after instantiation but before any operations are performed?   Can I replace the EntityManager midstream (for example read from one instance / swap / write to different instance?   Seems inappropriate.

Please advise.

Florian Adler

unread,
Jan 19, 2017, 4:36:21 AM1/19/17
to minute...@googlegroups.com
Hello Greg,

At the moment, MP configuration can handle multiple schemas, it means that you can generate against distinct DB schema in one shot.

But I do not have a way to change dynamically (at runtime) the connection parameter to another environment (same schema structure on another instance).

It requires some development effort. I have not check any strategy to implement this very interesting feature, but if you have some code to share, it would be nice.

Best regards,

Florian.

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "minuteproject".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse minuteproject+unsubscribe@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages