Simple Bug Tracker – Persistence

1. Right click on the project and select New->Create Entity class from Database
2. From the database connection drop-down, select the BugTracker database, and then select the bugstatus table.

3. Click add. Click next.
4. On the next page, change the package to gb.beans
5. Click the ‘Create Persistence Unit…’ button. Keep the defaults and just click Create.
6. Click next. Then click Finish.
7. Under the package gb.beans you’ll find a new class, namely Bugstatus.java.
8. Right new->other and then go to Persistence and select ‘JPA Controller Classes from Entity Classes’. Place this class in the gb.beans package.

9. Create a new class called Controller.java and place it into a package called gb.controller.
10. In the controller class create a member variable called status, which is a List of bugstatus. Give this list a getter method.
11. Create a new method called initialise() and add the following code:

   public void initialise() {
      BugstatusJpaController jpaController = new BugstatusJpaController();
      status = jpaController.findBugstatusEntities();
   }

12. Next goto the MainFrame.java class and add a member variable of type Controller.

13. Alter the MainFrame constructor to be as follows:

   public MainFrame() {
      initComponents();
      theController = new Controller();
      theController.initialise();
      populateComboBox();
   }

14. And for the populateComboBox() method:

   private void populateComboBox() {
      jComboBox1.removeAllItems();

      for (Bugstatus status : theController.getStatus())
         jComboBox1.addItem(status.getStatus());
   }

15. Start the application. NOTE: Remember we don’t have any bug status’ in the database at the moment, so an empty combo box is correct!

16. Essentially repeat these steps for the owners and areas tables, without any further alterations to the MainFrame.java class.

Advertisements

3 thoughts on “Simple Bug Tracker – Persistence

  1. This is interesting stuff. As a seasoned MySql user – albeit in a web context – it’s great to read an alternate interface method and gain insight into using NetBeans.

    Was NetBeans a conscious choice for development on this project or is this your usual Java IDE?

    Do you think this could be easily ported to non-desktop or remote usage?

    • NetBeans is the IDE of choice at my current place of employment – and whist its not *that* new to me, I’m certainly not as proficient in it as say Visual Studio, so attemtping to learn it better, and hence developing using this. I’m sure Eclipse would offer exactly the same (or possibly better!) functionality.

      If I was implementing this for real, it’d be a website. But I don’t want to worry about security access issues etc.. hence the desktop database and client approach. I’m certainly aiming to keep the view seperate from the controller-model parts of the code, so it *should* migrate easily to a web application.

      Glad to see you’re still reading – surely you can’t be finding it that difficult to sleep! 🙂

  2. NetBeans is the IDE of choice at my current place of employment – and whist its not *that* new to me, I’m certainly not as proficient in it as say Visual Studio, so attemtping to learn it better, and hence developing using this. I’m sure Eclipse would offer exactly the same (or possibly better!) functionality.
    +1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s