Gerry's software development journey of trial, errors and re-trials

Menu

Monthly Archives: June 2013

I’ve been always annoyed with inability of selecting dialog box on Mac using keyboard like you can in Windows:

Thanks to this rather-old-post there’s actually a way to enable dialog box option selection / cycling using keyboard. Go to System Preferences -> Keyboard and select All Controls under Full Keyboard Access at the bottom:

Now there’s one less thing for which you shouldn’t take your fingers off keyboard from.

ProxyPassReverseCookieDomain directive will cause the cookie domain be re-written into the intended domain. Without this end-user would see localhost as their cookie domain (which is again wrong).

ProxyPreserveHost directive will cause the domain header be forwarded into Tomcat. Without this Tomcat will see the incoming request coming from localhost. This is handy when you’re planning to serve multiple host name under Tomcat.

You can try this on be adding the above configuration into your httpd.conf file (typically located on /etc/httpd/conf/httpd.conf). Once you’ve edited the config, restart apache using sudo apachectl -k restart command.

This is a tutorial to build a very simple pizzashop Spring MVC, Hibernate and MySQL application. The main page shows all pizza rows stored on a database table:

Technology in Java world moves very fast. Using straight Hibernate might no longer be preferable since Java EE 5 introduces JPA (Java Persistence API) but it’s still good to learn anyway. Spring MVC and Hibernate is one of the most popular Java libraries used out there.

Tools / Environment Required
If you’re just starting fresh and don’t have most of the tools below just install JDK, STS (Springsource Tools Suite) and MySQL server, everything else is bundled within them.

Now all the boilerplate code done, we can start coding the business functionality. For this simple app we will have a pizza database table with just id, name and price column. Create the Pizza entity class representing the table

Create a DAO class to obtain Pizza entity persisted on database. Note that we won’t create service layer classes for the sake of simplicity (on real-life complex business application adding service layer is a good practice).

Create a Spring MVC controller to handle request from the main page. Note that PizzaDAO reference is injected, and after collection of Pizza entity objects are obtained it’s passed to the view using Model object.

It is assumed you have MySQL server running on your local machine (localhost) on the default port 3306. The name of the schema is pizzashop and table pizza. Have a look at Spring beans configuration section above to reconfigure this.

Running The Code

The easiest way to run your code is using in-memory Maven Tomcat plugin. It will launch on-the-fly Tomcat server with your code deployed. Make sure your project is selected on the project exploded and setup a maven run configuration on STS. Go to Run -> Run Configurations.. and create a new maven build entry like this:

Well done on making it this far. Hopefully that was a quick and nice introduction to Spring MVC + Hibernate + MySQL and you can see how the tedious database to java class mapping is now simplified. You might have lots of questions in your mind by now — feel free to ask in the comment section below. Following are few official references and community article links you can browse around:

This is yet another quirks of C++ programming I found (and could be very hard to debug).

When you use Windows API (eg: you have #include <afxwin.h>), it will pull min() and max() macro.

Apparently this will cause confusion for the compiler if you’re including another 3rd party library which expects standard library min() and max(). The error message you get is something like this (how obscure is this?):

This article applies to following environments (but conceptually it can be applied to any environment):

Github

Windows 7

If you’ve been relying on the github GUI, you may get (very) annoyed when the conflict screen appear (Failed to sync this branch due to unmerged files)

This is few (often not so) simple steps to resolve the conflicts:

Click OPEN SHELL, a windows powershell will come up

Start by running git status, this command will help you as you progress resolving the conflict. It also contain pretty clear instruction on how to mark a file resolved, and how to finish conflict resolution

In this examply (luckily) I only have 1 file in conflict hello.txt. Open it using a text editor, and edit the conflict. Conflicts are presented in a unified diff format:

hello world
<<<<<<< HEAD
mary
=======
bobby
>>>>>>> bobby
the many
testing
file

Above example is saying you changed the 2nd line to “mary”, but your colleague changed it to “bobby”. You now have to decide either (or merge both).

For every conflict you resolved, you can tell git so by git add command, eg: git add hello.txt

Once all conflicts are resolved do git rebase –continue command (if you’re in rebase mode — sometime github will use other conflict resolution and will tell you what command to run when completed)