Normalization and de Normalization when using the JSON client with the JAVA / RDBMS stack

I have an Angular JS JSON client interface that interacts with the JAVA / MySQL stack. Since MySQL is an RDBMS, all my data is normalized (the first three forms, of course).

My question can be illustrated by the following example.

I have an Example object and a User object returned by the server.

Example - [{ userId:1, ... ... .. }, { userId:2, ...}, { userId:3, ...}]; User - [ { userId - 1, firstName - "John", lastName - "Doe", .. }, { userId - 2, firstName - "Jane", lastName - "Doe", .. }, {...}... ] 

When I look at the Example collection using Angular "example_entry in the example" and display the elements of the Example collection, I only have userId. But if I want to display firstName and lastName, I can’t do it like in another collection β€œUser”. I have to write an Angular controller / service helper method to get the name firstName, lastName from the user collection and associate it with the objects in the Example collection.

To avoid this problem, I could De-Normalize Java Ojbects and send ready-to-use JSON like this.

 Example - [{ userId:1, firstName - "John", lastName - "Doe", ... ... .. }, { userId - 2, firstName - "Jane", lastName - "Doe", ...}, { userId:3, ...}]; 

But is it good / bad / terrible? Since my Java domain objects now have firstName, LastName is duplicated in the Example object as well as in the user object. Any advice which route is better?

 De-Normalize and have ready to use JSON Keep Data Normalized to avoid duplication and write converter methods on the Client as needed 
+6
source share
2 answers

Here is my example. When it comes to displaying a \ list of data, I am not worried about the \ classes domain model. For me, the returned data should meet the maximum possible display requirements of the user interface. The intention here is to show the data to the user, and not many decisions are made on such screens.

But if the data needs to be changed / updated, you need to be more careful about what is sent, which entities are involved in the update. Saving consistent data becomes a priority, and in such cases, normalization may be incorrect.

+2
source

You must denormalize your data when you submit it to your user interface level.

If your data is in a database, this is a great place for normalized data. Use a view that abstracts this normalization and query on the view. The view allows you to join tables together to retrieve denormalized data from your database.

In the user interface layer, you want to have a simple and simple display that works best for angular. If you do not display very large amounts of data on the screen or do not send huge amounts over the network, you are much better off just sending a denormalized record directly from your db. The database is great for performing joins and other data query functions - it is built for this. Javascript can do this, but this is not the best use.

+4
source

Source: https://habr.com/ru/post/954333/


All Articles