0

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

  1. Configuring generic properties using a property file.
  2. handling the dialect for different providers.

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.

2
  • @GuillaumePolet: requirement is not so big, so using JPA means adding a lot of overhead.As of now its just a 2 tables Commented Feb 29, 2012 at 16:34
  • Even for two tables I would still do it. You get the dialect abstraction you are looking for and think about future extension Commented Feb 29, 2012 at 16:44

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

agree with you but using JPA means adding a lot of extra dependencies.Thanks will consider your suggestion
0

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.

Design Patterns

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.