Where to put business logic? [closed] - sql

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
As the title suggests, I'm pondering whereabouts in my app to put some business logic and would be interested in some opinions. It is a simple app which downloads pages from the web and stores them in a sqlite database.
Business logic dictates that the app can only store one entry for a particular URL. I have set up the database so URLs have to be unique and currently rely on this to enforce the logic. I.e. if an attempt is made to insert a web page which is already stored, an error code is returned from the database and the user is informed.
However, I can't help feeling that the 'app layer' (java code) should know about this rule too - it doesn't feel right to rely on an sql error code for this.
I think I have three options:
1 have the database enforce the logic
2 have the app layer enforce the logic and remove the unique constraint on the database
3 have the logic in both places
No 2 is the least desirable to me as the database would not be in control of its own integrity. No 3 would require some duplication, but would mean the same database could be used in other apps and its integrity would be intact.
Would love to hear some views on this.
Thanks in advance,
Barry

The app layer should enforce the logic. This is just easier for design. Database does data things and business logic layer (app layer) does the logic. Keep things separated and make your life simpler since when you need to change a data thing you change it in the database and any logic changes get changed in the app layer. This is sort of a highly debated topic so be prepared to receive different answers.

Related

Some questions about GWT Basics [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm new with Google Web Toolkit and i have some questions about the tool.
First of all, what i have to know to correctly program for GWT? It's ok if i use the GWT Designer to make the GUI?
Second, how i persists all the data i want to store? Use JPA/Hibernate + SQL Database? Or it's better to use AppEngine?
I'm with a great doubt how i get the data from Database to populate fields and tables on client-side.
and Last, i know a bit of Swing, so, GWT is the same? (Except Client - Server concept) ?
That's my questions. Well, thanks in advance.
First of all, what i have to know to correctly program for GWT? It's ok if i use the GWT Designer to make the GUI?
Ok.
Second, how i persists all the data i want to store? Use JPA/Hibernate + SQL Database? Or it's better to use AppEngine?
It's your choice. AppEngine has it's limitations. For example, it scales but may not be the best choice for multi-player games if you need data updated very often and quickly. It really depends on your need/design.
If you do go with AppEngine, my experience with JPA was a headache. Objectify is much easier and the way I would go.
Last, i know a bit of Swing, so, GWT is the same? (Except Client - Server concept) ?
I guess they share the concept of using listeners/handlers for events. They are not the same though.

Points of SQL failure and moving ahead to NOSQL [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have experience over Relational DB's but very little over NoSQL data stores and for these two I need a well defined reason to say that one needs to move to NoSQL.
Since I cannot replicate a situation where I can push a DB to its limits and make it lose performance, let alone scaling it. Therefore wondered about to see what others had to say. May be I have been treading the wrong path path, but I have read people saying why we should move to NoSQL or how or even at what sort of different scenarios eventually leads to NoSQL. Article after article explains what Big Data is and how it is managed in the NoSQL domain and how useful it is with it architecture of being scalable, robust, ACID, BASE, Data modelling from Sql to NoSQL, etc features.
But none would provide some solid numbers. E.g. A web service that had a DB of X-TB's and eventually the queries (read/write/etc) took T-seconds or so to complete so we moved on to NoSQL to get back the performance. My concern is at what point it really did a team shift to NoSQL when they said, OK we're done with scaling and everything, lets move on to NoSQL!
So I have had to ask SO users. Maybe someone can share some valuable information. This seems to be an open issue for me as I have been trying to get hold of even just one document that explains a real case scenario where the SQL DB eventually had to be replaced with a NoSQL DB/DS/storage.
Any guidance is much appreciated.

Which database? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm a java developer, currently starting developing a hospital management system that will server patients, doctors, accountant, .... etc the system is really huge that may have 900,000 records/day, data is really growing so fast, for that i'm confusing in which database to use since i have the following options: (Percona Server(Mysql), Oracle, SQLServer), since the application will run on network with average of 45 online users.
I hope to find a good answers here.
Thanks in advance
If you have been working with MySQL for 6 years then stick with it!
You don't want to add the burden of learning another database as well as having to develop your application.
If you are unsure if MySQL is up to the job then run some tests. Write an app that runs multiple threads inserting 1M rows and see if your servers can handle it.
I'm guessing the brand of the database you choose will be less important than the performance of the platform (machines) it is running on.
There is no good or bad answer to this question. Basically it is as good as the DBA knowns to manage it.
If asking this question it would be wise to group a team of people well known with various systems to find out the best practice. To answer such a case, even more with very sensitive data, it is not just a simple solution which will do the trick. A thorough process of decision making is very important. Not only from a technical but also from a security and business side.
As per as think your database is large you can go with oracle.but the decision also depends on the expertise of people working with you and availability of resources.

Do large systems use foreign keys in their databases? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
One of the disadvantages people point to with using foreign keys in a relational database is the overhead of making sure the parent table exists before doing any insert operation. (Example). As your database and operation grows, this effect is amplified. Does anyone know if large sites on the web use them then? If so, how do they get around that extra overhead? If not, as your development team gets bigger, it seems that that could cause a lot of potential bugs/conflicts/miscommunication/orphan-rows.
Any insight?
I work for a telecom, yes they do, often the cost of FK is too small compared to severity one major incidents (hours of time lost investigating, patching ...) that can be caused by accidents due to lack of FK checking.
This depends on your definition of "large site": If for example Citigroup online bank is a "large site", I guess they do.
What I mean by this example is, that the use (or not use) of foreign keys, access by stored-procedures-only etc, depends on the requirements of the business logic (and maybe its legal framework) more than on technicalities only.

SQL abstractions [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Why do some frameworks (like CakePHP, Kohana, Zend, Django, less - Rails) create some kind of SQL abstractions instead of a raw SQL database access? E.g. why do we need to make some perversions instead of a usual queries?
UPD: are there any SQL-injection reasons of this purpose?
Basically a good abstraction layer makes it easier for the developer to use a database, and not care what what and which kind of database he is connecting to, thus speeding up the development process.
Check out http://en.wikipedia.org/wiki/Database_abstraction_layer, the most common pros and cons are listed here.
Thats called abstraction. Usually its done to be db specific indipendent.
Sql will be built based on the db type of the connection..
There are two main reasons.
Database Indepence
The code can be applied to different databases. MySQL, MS SQL-SERVER, ORACLE. And with a little wrangling to other DBs using OBDC like MSAccess, or CSV files.
Separation of Database Code with Business Logic
Most frameworks follow this model: http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
It's primarily an attempt to reduce what's known as the impedance mismatch between the relational storage of the database and the domain model within your application. Without the ORM you often find yourself writing "left hand right hand" code modelobject.property = reader["field] where you're mapping values from the storage format you've received from the database into your model.
In summary, hopefully the ORM allows you to concentrate on solving the business problems without having to worry about all of the plumbing. We're not there yet but we're getting close.