java - Insert unique entities to the sqlite DB -


there 100k entities in sqlite db following structure:

  • id (numeric, pk)
  • key (varchar, unique/pk)
  • other fields, varchars

i have list of 100-1k entities. want add db entities, key not present in db , show list of added ones.

example

as relevant example may consider this: library books entities. each book has global unique isbn number (key) , unique id (id) in library catalog.
some person brings library set of books. library checks books isbn in catalog, takes 'new' books , shows person list of taken books.

some thoughts how can achieved:

1) select keys db, put them [hash]set, in loop verify key new entities not exist in set.
2) #1 instead of selecting keys, select keys present both in db , list
3) in loop check existence of entity additional select query
4) enable constraints in db, check existence catching exceptions

all of them have own disadvantages, believe. can suggest better?

for i'm asking 'best practices', believe of approach work case without huge performance issues (no actual tests now, i'm in analysis phase), how should done better?

code in java, plan use simple daos jdbc, if suggests hibernate alternative approach, reconsider thoughts.

your suggested solutions valid , possible situations, altough number #1 , number #4 ideas. number #2 , #3 solutions used. choose 2 need answer following questions:

  • what typical use case application? (sometimes 1 new book, hundreds of books @ once, mixed)
  • based on metrics code "judged", trying optimize for? (readability/maintainability, performance, etc)

based on answers these questions above can either pick #2 or #3.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -