How To Strategy Java, Databases, and SQL [Video]
We need to save our thumbnail information to a database in order that we are able to render our footage to a pleasant HTML gallery web page and end the proof of idea for our Google Photos clone!
Which database ought to we use and why? Which Java database API? What database instruments will make our lives simpler alongside the best way? Discover out on this episode of Marco Codes!
What’s within the Video
00:00 Intro
We’ll cowl what the plan is for this episode: so as to add database capabilities to our Google Pictures clone, which presently solely works with information, however would not retailer their metadata in a database desk.
00:52 The place We Left Off
Earlier than leaping straight into implementing database and ORM options, we are going to do a fast code recap of the earlier episodes, to remind ourselves how the picture scanning and conversion course of presently works.
01:46 Setup
Every time we need to do one thing with databases and Java, we want a few (on this case) Maven dependencies. Extra particularly we need to make sure that so as to add the H2 database to our mission, which we are going to use for manufacturing, not only for testing! We’ll additionally add the HikariCP connection pool to it – one thing I do by default in each mission and which is often completed mechanically by frameworks like Spring Boot.
04:38 Writing a Database Schema
Right here, I current my present method when doing Java database work: ensuring the database schema is hand-written, considering by desk names, column names, sorts, and many others. Therefore, we’ll begin writing a schema.sql file for our new “media” desk throughout this part.
10:08 Making a DataSource
Having created the schema, we’ll have to create a DataSource
subsequent. As we’re utilizing HikariCP, we’ll comply with its documentation pages to arrange the DataSource
. We’ll additionally make sure that the schema.sql file written earlier will get mechanically executed every time we run our utility.
12:46 Saving Thumbnail Knowledge
It is lastly time to not simply render thumbnail information on disk, but in addition save details about the generated thumbnails and authentic photographs in our brand-new database desk! We’ll use plain JDBC to try this and speak about its benefits and drawbacks.
14:00 Refactoring Maneuver
Generally you simply have to _see_ sure issues which might be very exhausting to elucidate in phrases. To scrub up our program, we should change a few technique signatures and transfer parameters up and down all through the file.
16:21 Extracting Picture Creation Dates
In the mean time, we do not correctly detect the picture creation date from its metadata. We’ll speak about the right way to implement this sooner or later and why we’ll persist with the file creation date for now.
17:10 Avoiding Duplication
We’ll additionally have to deal with duplicates. If we re-run our program a number of occasions, we do not need to retailer the picture metadata a number of occasions in our tables. Let’s repair this right here.
19:04 Inspecting H2 File DBs
In case you do not know the right way to entry H2 file databases, we are going to spend a while displaying you ways to try this from inside IntelliJ IDEA and its database instrument window.
21:23 Rendering HTML Output
Final however not least, we’ll have to render all the data from our database to a pleasant, little HTML web page, so we are able to truly browse our thumbnails! As a bonus level, this would be the easiest and possibly dirtiest implementation of such an HTML web page you have seen for some time – but it surely works!
30:30 What’s Subsequent?
Did you want what you noticed? Which characteristic ought to we implement subsequent? Let me know!
Video