Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Java UI - Mapping - DB

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We need to retrieve values from the presentation layer and need to execute a DB query on different mysql Databases based on the configuration (table and column names would be different)

Assume (Presentation values), empName, empId, empAddress, empNo are presentation layer values

One DB (prot_db) has columnns as - emp_name, emp_id, emp_Address, emp_No with table name as "emp"

One DB (conti_db) has columns as - employee_name, employee_id, employee_addres, employee_no with table name as "employee"

One DB (sema_db) has columns as - empl_name, empl_id, empl_addres, empl_no with table name as "empl"
What would be the best approach to define them ?

Approach #1 - have constant variables for each DB and have if condition in the code base
Approach #2 - Any mapper approach to solve this (not sure)
Approach #3 - Any third party API/library which can take care of returning the appropriate string? (not sure)

Thanks.
 
Saloon Keeper
Posts: 21603
147
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can use JPA to talk to 3 different databases at the same time. You just need a separate EntityManager and class mapping for each of the 3 databases. Been there, done that.

You might consider a couple of other options, however, to keep things cleaner. One would be to manage a process that aggregates the necessary values into a single database.

Another, related approach is that some databases allow you to create database objects that are actually proxies to other databases. In both of these cases, you'd only be required to deal with a single database.
 
Joseph Michael
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All of them are pointing to Mysql only but databases are different.

In such a case, any mapping can be done via Dozer/Model or Mapstruct to overcome this issue


Adding Jsonproperty annotation is strongly binded to the class.

i want to define a single class but have different mapping xml so that i can convert the incoming JSON response using the respective XML mapping

is that is possible ?
 
Tim Holloway
Saloon Keeper
Posts: 21603
147
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dozer is a mover/converter, so you'd still need a database interface. I've used Dozer with JPA, though.

As a rough guess of what you're doing, I'd say that you're looking for a JSON interface to a GUI model object(s), then you want to explode the data from the GUI model objects into persistence model objects (Entities), and interact via them with the databases. That sort of stuff is certainly doable using off-the-shelf APIs (for the most part). Definitely I'd use Dozer to handle getting the data to/from the persistence entities. It's a lot more fun - and more flexible - than doing it all by hand.
 
Joseph Michael
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

here it was i am doing...The server gives a JSON request for any request....No direct DB connection...

User Input -> REST API request -> JSON Response -> POJO class

So when we connect to different server based on the configuration we get different JSON response which needs to map to the same single POJO class

Example,

POJO class is Employee with attributes empId, empName, empAddress

one server returns json with names - empId, empName, empAddress
another server return the json with names - employeeId, employeeName, employeeAddress
another server returns the json with names - emId, emName, emAddress
another server returns the json with names as - eId, eName, eAddress
another server returns the json with names as - emp_id, emp_name, emp_address

Thanks.


 
It's never done THAT before. Explain it to me tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!