Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Mapper Pattern #34

Closed
jesusvazquez opened this issue Mar 21, 2015 · 18 comments
Closed

Data Mapper Pattern #34

jesusvazquez opened this issue Mar 21, 2015 · 18 comments
Milestone

Comments

@jesusvazquez
Copy link

Hi, I'm a new user to github and I would like to help to this project. I've been researching about a few patterns and the work you've done and I think it's so cool.

In my college I've developed an application which comunicates with a MySQL Database and I had to build a pattern to make that communication work. I'm talking about the Abstract Mapper.

I have an example here: https://github.com/jesusvazquez/java_examples/tree/master/AdvancedDatabaseSystems/src/modelo/DBMapper

I'm wondering if it would be a good idea to add this pattern to your project.

Best Regards.

@iluwatar
Copy link
Owner

@jesusvazquez Thank you for the interest in this project.

For the Abstract Mapper pattern you are proposing let's discuss about it on a bit higher level. Can you describe what is the intent of the pattern and when should we use it the same way as we have for the other patterns here?

@jesusvazquez
Copy link
Author

Yes,

This pattern allows you to map your database tables without using any framework, like Hibernate for example. If your application is small and you want to understand how the connections to the database work, this pattern helps you a lot because it's just an abstract class and a few Java programming concepts.

If you want to map a table you just have to fill 4 or 5 methods and then SELECT, INSERT, UPDATE or DELETE will work perfectly.

I wish my english is good enough for you tu understand what I'm trying to explain ;)

@iluwatar
Copy link
Owner

Ok, I see this is a persistence solution. Like a mini framework that could be compared to these.

What makes a design pattern? A design pattern is a tried and used way to solve a specific problem in an elegant way. I don't know if Abstract Mapper is a brand new first version or is it widely used somewhere? How is this problem solved in the other persistence frameworks and what makes Abstract Mapper better than what they've invented?

@jesusvazquez
Copy link
Author

I believe the most common name is Data Mapper Pattern, here you can find some info: http://en.wikipedia.org/wiki/Data_mapper_pattern
There is another pattern who looks pretty similar named Data Access Object http://en.wikipedia.org/wiki/Data_access_object

Both looks pretty similar because the concept is the same. Between the application model and your database you implement a new layer to manage the whole database thing. DAO uses an interface but I prefer the abstract class choice because for me it's more simple and that's why I said Abstract Mapper. I should change that to Data Mapper because it's best known.
Here you have two UML examples that I find helpful:
DAO UML: https://cdn.tutsplus.com/net/uploads/legacy/1122_zend2/images/dao.jpg
Mapper UML: http://dl.cbsimg.net/i/tr/cms/contentPics/u00320031211dlx02_c.gif

Trying to simplify I would say that DAO and Mapper are both an aproximation of what big frameworks like Hibernate perform. Of course you can start using hibernate from the beginning without never implementing this patterns but I see them as a good academic example so this is the main reason to add them to this repository.

@iluwatar
Copy link
Owner

Ok, now that description hits the right spot. I see the correspondence with Mr. Fowler's Data Mapper pattern. A simple example of that would be very welcome. Also, an example of DAO pattern is needed.

Do you have an idea how to implement the database connection? Use some kind of mock or in memory database maybe?

@jesusvazquez
Copy link
Author

Yep that's my doubt, we can create the main sql and give some instructions...

Any ideas for the easiest solution ?

@iluwatar
Copy link
Owner

Fowler's pattern description: http://martinfowler.com/eaaCatalog/dataMapper.html

One implementation I found: http://richard.jp.leguen.ca/tutoring/soen343-f2010/tutorials/implementing-data-mapper/

I would probably try the implementation with JDBC and H2 or HyperSQL in-memory database. For those you can just add Maven dependencies and you're good to go.

@jesusvazquez
Copy link
Author

Those examples contain hardcoded querys inside the entity mappers. The example I gave you https://github.com/jesusvazquez/java_examples/tree/master/AdvancedDatabaseSystems/src/modelo/DBMapper fix this in the class Abstract Mapper. Would you like to add this or shall we keep the pattern without any modification.

I have studied both and I find very useful the Abstract Mapper implementation.

@iluwatar
Copy link
Owner

The implementation link I gave was just for your information. You don't need to use anything from that. But I do find important that we use Data Mapper as the name of the pattern.

@jesusvazquez
Copy link
Author

Okey I agree with that name. I'll give it a try as soon as possible. Thanks!

@iluwatar
Copy link
Owner

@jesusvazquez Do you have any news regarding the implementation of Data Mapper pattern? :)

@jesusvazquez
Copy link
Author

Hi,

Not really, I'm sorry but I just finished my Bachelor. I'll try to perform it this summer :)

@npathai npathai changed the title Abstract Mapper Pattern Data Mapper Pattern Aug 16, 2015
@npathai
Copy link
Contributor

npathai commented Aug 16, 2015

This issue is related with #79
Both are persistence solutions. Data mapper is considered alternative to Active record.
Some links that discuss the difference

@inbravo
Copy link
Contributor

inbravo commented Mar 28, 2016

I own this issue now; please assign ....

@npathai
Copy link
Contributor

npathai commented Mar 28, 2016

@jesusvazquez Have you worked on this issue or I should assign it to @inbravo ?

@npathai
Copy link
Contributor

npathai commented Mar 28, 2016

Meanwhile @inbravo I think you can proceed with the implementation.

@iluwatar
Copy link
Owner

iluwatar commented Apr 4, 2016

@inbravo please make a pull request and we'll review.

@inbravo inbravo mentioned this issue Apr 6, 2016
@inbravo
Copy link
Contributor

inbravo commented Apr 6, 2016

Pull request [#417] is ready for review....
Build report: https://travis-ci.org/iluwatar/java-design-patterns/builds/121084977

iluwatar added a commit that referenced this issue Apr 23, 2016
@iluwatar iluwatar added this to the 1.12.0 milestone Apr 24, 2016
pratigya0 pushed a commit to pratigya0/java-design-patterns that referenced this issue Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants