Newer
Older
labs / tiddlers / content / labs / lab06 / _Labs_06_Milestone 1 Tips.md

You now have everything that you need to complete milestone 1.

The following are some tips that will help you to solve/avoid some specific problems. We will continue to add to this section as new problems are encountered, so check here regularly.

  • You will need to create a new database in H2 for milestone 1 --- don't use the same database that we were using for the lab. Follow the instructions in section <> of this week's lab to create a new database. Use an appropriate name when creating the database (single-word, all lowercase).

  • The ProductCollectionsDAO class that you were given doesn't include any dummy data. You should add a few products to the DAO for testing the products web page. Add the following constructor to the ProductCollectionsDAO class to add a few dummy products:

      @SuppressWarnings("OverridableMethodCallInConstructor")
      public ProductCollectionsDAO() {
          saveProduct(new Product("WD1234", "Slimy Widget", "A widget that is covered in some kind of nasty shmoo.", "Widgets", new BigDecimal("7.32"), new BigDecimal(35)));
          saveProduct(new Product("WD1234", "Green Widget", "A widget that has gone mouldy.", "Widgets", new BigDecimal("21.43"), new BigDecimal(3)));
          saveProduct(new Product("DH8832", "Dodgy Doohicky", "A doohicky that might work, or it might not...", "Doohickies", new BigDecimal("12.32"), new BigDecimal(5)));
          saveProduct(new Product("DH8832", "Polkadot Doohicky", "A doohicky that is covered in spots.", "Doohickies", new BigDecimal("43.23"), new BigDecimal(6)));
      }

    Once you have the product JDBI DAO working you should comment out this code so that it doesn't interfere with your DAO tests.

  • Once you have completed the product JDBI DAO, you can modify the ProductCatalogue class to use the new DAO and then use the Swing UI to add products to the database.

  • The SQL for the "check username and password" customer DAO method is not obvious. Refer to the <> reference section.

  • The customer ID column should use an auto-incrementing sequence. Refer to the <> section of the reference.

  • Since the customer ID is being auto-generated, you should not include it in the insert statement.

  • Don't use a merge statement for inserting the customer data --- use insert. You should only use merge if you are trying to dual-pupose a single operation for both inserting and updating (which we did with the save method in the student system). We don't need to update the customer, so we don't need merge. Additionally, the generated customer ID means we can't use customer ID as the merge key, and using username creates a situation where users can hijack each other's accounts by creating a new account with an existing username --- the new user's details will replace the existing user.

  • Since the customer ID can be null, you should not use it for determining equality in the hashCode/equals methods --- use username instead.

  • The Customer domain class that you were given has two problems with the second constructor --- it expects a customer ID, and it does not initialise the password field. Delete th

  • You can wrap an if-else statement around the links in the navigation menu to toggle which ones are shown based on if the user is signed in or not.

  • The sign in servlet should check the customer's username and password using the appropriate customer DAO method. If the credentials are correct then the servlet should get the customer from the DAO and add it to the session. If not, a message should be added to the session and the user should be redirected back to the sign in page where the message is displayed.

  • Don't forget about the <> section --- there is a lot of useful examples and reference material in there that you will find useful.