Implement abstraction of data access layer

This may be a tutorial question, but I'm considering how to develop some classes that abstract the database connection from the RESTful service, which receives the query results.

My thoughts are that to create an interface for the data access layer, then create a top-level class that implements it, and includes any operations that will be used by all databases. Then I will implement specific subclasses of this superclass (adapter).

It seems simple to me, but some of the people I bounced around think it might be harder.

For context, this is Java, and two DBs are MySQL and HBase. We already have data access layer (DAL) classes for MySQL. They do not use hibernation or spring; they build db queries and create POJO instances from the results manually.

So my question has two parts:

1) is it as simple as I think?

and

2) is there a better approach?

+4
source share
1 answer

As with similar questions, the answer can only be: it depends!

Based on what you are trying to achieve, this may be a complex problem or it may be simpler. You can use a full-fledged ORM tool, such as Hibernate, or use a custom base layer with low-level JDBC constructs. This is what works for you, tailored to your application.

But don't ignore the fact that what you want to do is basically rethink the wheel. This has been done before . You must either reuse the DAL if you have a good job, or go to an existing structure.

At this point, you want to implement exactly what to choose the right tool. Do not just blindly choose one, analyze the advantages and disadvantages of each, and then choose the best one for work (yours or others).

+2
source

All Articles