admin管理员组文章数量:1296885
I have a Angular JS JSON client interfacing with a JAVA/MySQL stack. As MySQL is an RDBMS, all my data is normalized (first three forms of course).
My question can be illustrated with 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 through the Example collection using Angular "example_entry in example" and display the Example collection elements, I only have the userId readily available. But if I want to display the firstName and lastName, I can't do it as it's in a different "User" collection. I have to write a helper Angular controller/service method to get the firstName, lastName from User collection and tie it with Example collection objects.
To avoid this problem, I could De-Normalize the Java Ojbects and send out ready to use JSON like this..
Example - [{
userId:1,
firstName - "John",
lastName - "Doe",
...
...
..
},
{
userId - 2,
firstName - "Jane",
lastName - "Doe",
...},
{
userId:3,
...}];
But is this good/bad/terrible? Because now my Java Domain Objects have firstName, LastName duplicated in the Example Object and also the User Object. Any advise on 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
I have a Angular JS JSON client interfacing with a JAVA/MySQL stack. As MySQL is an RDBMS, all my data is normalized (first three forms of course).
My question can be illustrated with 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 through the Example collection using Angular "example_entry in example" and display the Example collection elements, I only have the userId readily available. But if I want to display the firstName and lastName, I can't do it as it's in a different "User" collection. I have to write a helper Angular controller/service method to get the firstName, lastName from User collection and tie it with Example collection objects.
To avoid this problem, I could De-Normalize the Java Ojbects and send out ready to use JSON like this..
Example - [{
userId:1,
firstName - "John",
lastName - "Doe",
...
...
..
},
{
userId - 2,
firstName - "Jane",
lastName - "Doe",
...},
{
userId:3,
...}];
But is this good/bad/terrible? Because now my Java Domain Objects have firstName, LastName duplicated in the Example Object and also the User Object. Any advise on 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
Share
Improve this question
asked Sep 22, 2013 at 4:38
user6123723user6123723
11.2k19 gold badges72 silver badges111 bronze badges
2 Answers
Reset to default 5You should denormalize your data when you send it to your UI layer.
If your data is in a database, that is a great place for normalized data. Use a view that abstracts that normalization and query against the view. The view lets you join tables together to get denormalized data from your database.
In the UI layer you want to have clear, simple display - that's when angular shines best. Unless you are displaying very large amounts of data on the screen or sending huge amounts over the net, you'll fare much better by just sending a denormalized record straight from your db. The DB is great at doing joins and other data querying functions - it is built for that. Javascript can do that, but it isn't the best use of it.
Here is my take on this. When it es to displaying\listing data I am not worried about the Domain model\classes. For me the data returned should match as much as possible the UI display requirements. Here the intent is to show data to user and not much decision making is done of such screens.
But if data needs to be changed\updated one needs to be more careful of what is send, which entities take part in the updation. Keeping data consistent bees priority and de-normalization may not be right fit in such cases.
版权声明:本文标题:javascript - Normalization vs DeNormalization when using a JSON client with a JAVARDBMS stack - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741630845a2389354.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论