Proper Java Database Approach

I created a small JavaFX with two scenes. The user can enter 3 fields (text) and upload some documents for the object.

So, I thought when the user clicks on to save the json object, it is created and added to the list of Json objects. These Json objects are then written to the file.

This is what I was thinking:

{ "objects": { "object1": { "field1": "foo" "field2": "foo" "field3": "foo" "folderwithfileslocation": "C:/ProgramFiles/myapp/foobar/" }, "object2": { "field1": "foobar" "field2": "foobar" "field3": "foobar" "folderwithfileslocation": "C:/ProgramFiles/myapp/barbar/" }, ....... .... .. } 

They will be read into objects at startup, so the user has access to them, so he can edit them, add, delete, etc. etc. typical CRUD.

Is this the right approach? There would be a maximum of 500-600 entries. Should I add a unique identifier (idk like randomUUID() )?

thanks

+5
source share
1 answer

Most database schemas have added a UUID as their primary key, but it's important to understand why - the primary key allows you to search for a specific document. If a user updates or deletes a specific document, you will need a way to find that record in the database so that you can apply this action.

If one of the other columns (perhaps a folder?) Is unique (and not NULL), then PK would be fine in itself without adding a UUID. Similarly, if objects are always considered a list, you can use the index in that list as PK, but this makes some assumptions regarding the ordering of the list. If they don’t do this work for you, adding PK is probably a good idea, and UUIDs are a very good way to do this.

Personally, I expect to add the UUID for debugging alone. The overhead is tiny, and it goes a long way to tracking.

+3
source

All Articles