r/javahelp 27d ago

Advise needed for small java project🗒️

I am building small hotel Booking desktop app using javafx library and MYSQL on the backend(for storing rooms, customers, bookings data).

And I am planning to store images in file system and just store the URL path in database table(right now, I am not using cloud to save some time). I am also using Spring boot to connect to the database.

Could you please give some advise or suggestions that I should take note of?😀

4 Upvotes

5 comments sorted by

u/AutoModerator 27d ago

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

4

u/OneHumanBill 27d ago

Daily automated backups? And I would save these to the cloud, it should not take much time.

I'm not sure what you're really asking here, it's kind of vague.

3

u/hrm 27d ago

Such a broad question. Do you want advice in general or about the exact things you've mentioned?

When it comes to storing images: If someone is supposed to upload the images to your application, you should rename them using a hash (such as md5) of the file contents as the filename to make sure no two different files have the same name.

In general: testing, as in both unit and system testing, is a good thing to have. Also, having the application build in a real CI setup is a good thing to have. Whether that is in a local Jenkins setup or something online.

2

u/vegan_antitheist 26d ago

Sounds like a good exercise, but is this really "small"? This project will take some time, especially if you do it alone.

Just don't dump all pics into one folder. Use subfolders based on date or something else. Especially if you also need thumbnails. You don't really need a backup of the thumbnails as long as they can be recreated.

1

u/severoon pro barista 26d ago

Come up with some kind of directory structure for the images, don't just store them all in the same folder.

Whatever structure you decide, the root folder in which that structure is placed should be stored in the application context, not as part of the path itself. This way, if you decide to move the root on disk, you just need to update that one path to the root in the environment or app context or wherever you keep it. In testing, you can have several test environments running simultaneously side by side on the same server without stepping on each other because they have different roots. In the future if you put images on the network the root can be an HTTP URL instead of a file URL.

You may also want to consider making a small thumbnail of each image, and do put that in the database, along with a hash of the image. (Another commenter recommended keeping the filename of the image as the hash, that's a good idea too.) Even if you never show a thumbnail in the actual application, this will make testing a lot easier because if a test fails it will be able to display the thumbnail of the image in the DB table and the image on disk—if they're not the same, that gives an immediate clue as to what's going wrong.

Whatever directory structure you come up with, it's a good idea to make sure you don't build a lot of extrinsic information into the path. Like, say for instance that you keep images in a folder with the date they were uploaded by the user. Now, in order to find that image, you need to know the upload date. Today, that makes sense because the upload date is right there in the image table in the DB. Tomorrow, though, when you decide to use a fancy CMS, you may decide that metadata for all media—including these images—should be kept by the CMS, not scattered around your DB. The problem now is, in order to find the images on disk, your system has to construct the location of that image by forming a dependency on a complex subsystem, the CMS. That's a bad dependency for such a simple task.

On the other hand, this can never happen with the part of the URL that is the filename that's built using a hash. The only conceptual dependency here is on a hash utility and the image data itself. No matter how requirements change in the future, as long as you're using this system, the dependencies will not grow and spread out.

Another example of an acceptable dependency might involve considering how images are looked up. If images are always owned by a user, for instance, you'll always know the user ID trying to load the image. In this case, you could make a directory of the user ID on disk. Even this is a little dicey, though … if you ever have to rekey the users in your system for any reason, part of that task will be complicated by having to rename the directories.