Coders Campus Podcast

Coders Campus Podcast

By Trevor PageEducationHow ToCourses
Download on the App Store

Coders Campus Podcast episodes

  • Hibernate - Creating Data Access Objects (DAOs)
    Data Access Objects – What are they?

    Data Access Objects (or DAOs for short) are used as a direct line of connection and communication with our database. DAOs are used when the actual CRUD (CRUD = Create, Read, Update, Delete) operations are needed and invoked in our Java code. These data access objects also represent the “data layer” of our application.

    These objects are still just plain old Java objects that incorporate the use of some Hibernate annotations to give them the functionality we need from them. Again, that functionality being the communication with the database.

    Also, believe it or not, the concept of creating a file specifically for accessing the database is a design pattern. It’s called the Data Access Object Pattern and you can read more about it from this nice short Wiki article.

    What Hibernate Annotations Should We Use?

    Okay, so now that you’re somewhat familiar with DAOs, it’s time to learn how to integrate these plain old Java objects with our Hibernate framework (so they actually do the work we need them to do).

    There are two main annotations that you need to be familiar with:

    • @Repository
    • @Transactional
    • To learn more, visit our show notes page via http://howtoprogramwithjava.com/session52

      1 hr
    • Hibernate's most important annotation - @Entity
      What You’ll Learn

      The focus of this podcast / blog post is to teach you how to create the connection between your Java objects and the SQL Database tables. Remember, the whole point of the Hibernate framework is for you to be able to write Java code that allows you to communicate with your database.

      When I say that the goal is to communicate with your database, what I mean is:

      1. Create the tables (if they’re not already there) that will represent your Java objects
      2. Give Java the ability to send queries and execute scripts on your database
      3. Establish a transactional means by which to perform CRUD operations
      4. What we’re going to be tackling in this post will the step #1, how to get Hibernate to create our tables for us.

        1 hr
      5. Hibernate Persistence for Beginners

        What is a Persistence Framework?

        As the name implies, it has something to do with persisting things... this means that we're still talking about databases.  But what is it that we are persisting with this framework?

        Objects (of course)

        A persistence framework is something we use in Java to bridge the gap between Java and SQL.

        Hopefully we've gone through all of my previous tutorials and have learned a thing or two about Java and SQL.  But one thing I haven't taught you yet, is how to put your knowledge of SQL into Java.

        That's what I'll be teaching you throughout these Hibernate (persistence framework) tutorials.

        And if you haven't guessed it already, Hibernate is a persistence framework that you can use in Java.  It's what allows you to write Java code (staying true to Object Oriented programming practices) and yet still be able to communicate with your database.  Cool eh?

        For more information on this, check out the show notes page via: howtoprogramwithjava.com/session50

        1 hr 2 min
      6. The SQL Subquery
        The SQL Subquery



        Now that you’ve learned about SQL Joins, aggregate functionsand the group by keyword, it’s time we moved on to our final topic in our SQL tutorial series. Today you’ll be learning all about SQL Subqueries, how to use them and when you should use a SQL subquery.

        So, what is a subquery?

        First and foremost, let’s get the jargon out of the way. A subquery can also be referred to as a nested query. It’s just like having a nested if statement in your Java code. Essentially what you’re doing with a subquery is you are constructing a regular old query (select statement) which could be run all by itself if you wanted to, but instead of running it all by itself, you’re jamming it into another query (select statement) to give you more specific (filtered) results.

        What’s very important to note here is that the SQL subquery can almost always be re-written as a join with a whereclause attached to it.

        More info on this via http://howtoprogramwithjava.com/session49

        49 min
      7. SQL Group By

        After having talked about all the SQL Aggregate functions, there’s one more topic that goes hand in hand with what we’ve already learned… The group by keyword.

        This particular keyword allows us to take a bunch of data and mash it all together into matching groups and then perform aggregate functions on those groups (like sum and avg).

        You might ask yourself why you’d want to “mash together” a bunch of data. The answer to this is best explained with an example, but let me try to put it in regular words before we jump into our example. Grouping data together allows us to look at aggregate data in relation to unique piece of data (or rows), a typical use case would be to group all the matching data together so you can get a count of the number of occurrences of specific data. An example related to grouping and counting could be a presidential election, you’ll have all the votes in a database and you’ll want to group that data together to get the total votes for each unique candidate...

        For more info, check out the show notes via http://howtoprogramwithjava.com/session48

         

        47 min
      8. SQL Aggregate Functions

        In today’s podcast episode you’ll be learning all about the aggregate functions that exist in SQL.

        What the heck is an aggregate function? Well that’s what I’m going to try and teach you today, and I promise, it’s not a difficult concept to grasp. Just think of an aggregate function as a method that you’re calling that will process data in your database and return a value. Obviously the returned value will depend on which of the aggregate functions you choose to use.

        So that begs an obvious question, what are the aggregate functions that we can use in SQL? I’m glad you asked, here’s the ones that I use all the time in MySQL:

        • MAX
        • MIN
        • SUM
        • AVG
        • COUNT
        • Okay, great! So now we know what the names of these functions are, now let’s see some examples of them in use!

          33 min
        • Database Joins

          There are three categories of joins that you can make use of in SQL:

          •   Inner Join
          •   Outer Join
          •   Cross Join
          •  

            But before we dive into the categories of joins, we first need to have an understanding of what a join really is.

            Joins are used in SQL to bring together all the relevant data from multiple database tables.  Remember that we've broken data down into multiple tables and established relationships between the tables.

             

            ... More via show notes: http://howtoprogramwithjava.com/session46

            58 min
          • Enforcing Database Relationships Part II

            In this SQL tutorial episode/post we’re going to learn how to enforce our SQL relationships that we’ve already learned about. We’re going to be tackling the one-to-one and many-to-many relationships and we’re going to learn how to write the code to enforce these relationships in our database.

            As outlined in the podcast, we are going to be focusing on the many-to-many relationship with the author and bookexample. Remember that one author can publish many books, and one book can be written by many authors. This indicates a many-to-many relationship and I’m going to show you how to enforce that relationship in your database...

             

            Show notes available via http://howtoprogramwithjava.com/session45

            56 min
          • Database Relationships: Many-to-Many and One-to-One

            Show Notes available via: http://howtoprogramwithjava.com/session43

             

            In this post we will be expanding on the topic of database relationships and touch on two that are less common but just as useful.

            Many-to-Many Relationship

            The many-to-many database relationship is used when you are in the situation where the rows in the first table can map to multiple rows in the second table… and those rows in the second table can also map to multiple (different) rows in the first table.

             

            One-to-One Relationship

            A One-to-One relationship means that you have two tables that have a relationship, but that relationship only exists in such a way that any given row from Table A can have at most one matching row in Table B.

            45 min
          • Creating Database Tables in MySQL

            You’ve learned all about how to create sql queries to read, write, update and delete data… but you haven’t yet learned how to create the tables where you’ll be doing the reading, writing, updating and deleting.

            So that’s what today’s podcast is all about, be sure to click the play button above this to listen to the show and then follow along with the notes via http://howtoprogramwithjava.com/session44

            1 hr 3 min

          About Coders Campus Podcast

          From the publisher's feed

          Learn how to program using the Java programming language. This podcast will teach you step by step how to use the Java programming language to create your own applications or web applications! These…