java - Mapping Objects From Resultsets and efficiency -


i working on program outputs names , various other details(name, address, id, etc) user object. user object populated through using jdbc db. have learned how map resultset object user object , how display various info(name etc) object screen.

my query need access many objects(sometimes all: searching, updating) , think may silly make connection db, receive resultset , map object every time need information. instead thought rows database , map objects , put them in arraylist pick out particular information wanted more easily.

is inefficient or bad coding practice? there gaping flaw in logic?

caching rows in application has many strong disadvantages:

  • it doesn't scale: if have 1 million users? if every user has 5 orders, referencing 7 products, etc. etc. you'll end full database in memory, , that's not sustainable.
  • it's harder correctly: you'll have deal several requests reading , modifying users concurrently. database transactions you.
  • it forces app exclusive owner of database. if other app (or script, or batch) accesses database, app won't aware of it, display stale data, , generate errors because, examle, try update users don't exist anymore.

the more have state in application, harder make correct , fast. trust database: it's fast , handles many concurrent accesses correctly. if starts getting slow, think queries, use appropriate indexes, etc.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -