Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [gemini-dev] Gemini JPA - Store JDBC Url + User + Password in external configuration?

Hi Eugen,

 

thanks for your remarks. That would work when creating the EntityManagerFactory manually. I was actually planning on creating the entity manager using Gemini JPA. So actually Gemini JPA should be improved in order to use jdbc credencials which are supplied externally.

 

Seems like Gemini JPA does not support that right now. I will see whether I am able to adjust Gemini JPA or implement a custom solution.

 

Bye,

Jan

 

Von: gemini-dev-bounces@xxxxxxxxxxx [mailto:gemini-dev-bounces@xxxxxxxxxxx] Im Auftrag von Eugen Reiswich
Gesendet: Donnerstag, 2. Februar 2012 12:38
An: Gemini and sub-projects developer discussions
Betreff: Re: [gemini-dev] Gemini JPA - Store JDBC Url + User + Password in external configuration?

 

Hi Jan, 

 

I've been evaluating this option now for weeks and the short answer is: it is possible, however from my point of view not very convenient. I first introduced a new OSGi service called IDatabaseCredentialsService:

 

public class DatabaseCredentialsService implements IDatabaseCredentialsService {

 

       public Map<String, String> getDBCredentioals() {

             Map<String, String> credentials = new HashMap<String, String>();

 

             credentials.put("javax.persistence.jdbc.driver",

                           "org.postgresql.Driver");

             credentials.put("javax.persistence.jdbc.url",

                           "jdbc:postgresql://localhost/testdb");

             credentials.put("javax.persistence.jdbc.user", "postgres");

             credentials.put("javax.persistence.jdbc.password", "mypasswd");

 

             return credentials;

       }

}

 

To provide these credentials to your EntityManagerFactory you need to work with the EntityManagerFactoryBuilder (provided by bundle javax.persistence). The code below shows how all the wiring works:

 

 

public class CustomerServiceDAO {

 

       private EntityManagerFactory entityManagerFactory;

       private EntityManagerFactoryBuilder emfBuilder;

       private IDatabaseCredentialsService dbCredentials;

 

       public Customer findCustomer() {

             EntityManager entityManager = entityManagerFactory

                           .createEntityManager();

             Customer c = entityManager.find(Customer.class, 123456);

             entityManager.close();

             return c;

       }

 

       private void createEntityManagerFactory() {

             assert emfBuilder != null : "emfBuilder != null";

             assert dbCredentials != null : "dbCredentials != null";

 

             Map<String, String> dbCredentioals = dbCredentials.getDBCredentioals();

             entityManagerFactory = emfBuilder

                           .createEntityManagerFactory(dbCredentioals);

       }

 

       public void bindDBConnectionService(IDatabaseCredentialsService dbService) {

             dbCredentials = dbService;

             if (emfBuilder != null) {

                    createEntityManagerFactory();

             }

       }

 

       public void bindEMFBuilder(EntityManagerFactoryBuilder builder) {

             emfBuilder = builder;

              if (dbCredentials != null) {

                    createEntityManagerFactory();

             }

       }

}

 

Eugen

 

 

Am 02.02.2012 um 07:53 schrieb Jan Stamer:



Hi All,

 

we are evaluating Gemini JPA right now. Currently I’ve got one question:

è Is it possible to store both JDBC URL as well as username and password in an external configuration?

 

We would like to be able to change these values using OSGi configuration mechanisms.

 

Help appreciated,

Thanks Jan

 

_______________________________________________
gemini-dev mailing list
gemini-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/gemini-dev

 

Dipl. Wi-Inf. Eugen Reiswich
 
Universität Hamburg (UHH)
Fakultät für Mathematik, Informatik 
und Naturwissenschaften (MIN-Fakultät) 
Department Informatik                        
Zentrum für Architektur                         
und Gestaltung von IT-Systemen (AGIS)
Vogt-Koelln-Str. 30                             
22527 Hamburg
Tel: 040 / 42883 - 2307

 


Back to the top