Reputation: 23587
I am in process to create a Database connection class but having some doubts about implementation. Idea is to create a flexible and easy to use connection manager class and since it will be used in our own application at some specific points so at the moment not much concerned about multi-threading etc.
here are the few requirements
Please suggest some guidelines to make this class flexible and easy to enhance.Any link/resource of any good such implementation will be really helpful.
Upvotes: 0
Views: 896
Reputation: 2503
If all you're asking for is relating to concerns about design then you might want to go read up on some common design patterns and choose one that is best for your situation.
Upvotes: 0
Reputation: 47627
Use JPA then. You will thank me for choosing that in a few month and you will set this up as fast as if you try to do it yourself.
Upvotes: 1
Reputation: 1135
I assume, you will be using JDBC. You can externalize all parameter that are required to create Connection object for particular database
1) Database connection URL (include port number) 2) Username 3) Password 4) Database driver
You can keep all these parameters in external properties file. You can use factory pattern (say DatabaseConnectionFactory) to create database connection so that if you decide to apply certain attributes while creating new instances of connection or reusing the connection instances, it will be easy to manage. You should make DatabaseConnectionFactory singleton.
What you need to take care of is the generation of SQL queries as it varies depending upon the Databases.
Upvotes: 1