Monday, July 22, 2013

DB Isolation Levels, Locks, Dirty Reads, Non-Repeatable Reads, and Phantom Reads

A good wikipedia article on Isolation (of the I in ACID): https://en.wikipedia.org/wiki/Isolation_(database_systems).  Introduces well the concepts of the various levels of isolation, the required locking for each level, and the observed results per level.

Thursday, July 18, 2013

Maven built GWT Project in Eclipse Running on Standalone Tomcat 7


Vogella has an excellent tutorial on GWT in Eclipse here: GWT Tutorial.  Playing around with the 'userService' in Eclipse (just name changes of some resources), I decided to convert the GWT example to a maven gwt-archetype project.  


What's Needed


- Eclipse with m2e plugin and maven-gwt-plugin
Tomcat 7 installation (OSX: download the tar and untar the dir wherever you want; I put it in /Applications/apache-tomcat-7.0.42)


Installing Plugins and Tomcat

Install the m2e plugin (through the 'Help->Install New Software...' link in Eclipse), as well as the maven-gwt-plugin (through modifying a dummy maven project's POM to include the plugin as a dependency).  I think this step is a bit awkward because you can't install the plugin through a site like you can the m2e plugin, but I am thankful to the developers who have created the plugin.  You can try to install it like how it's shown here, though I wasn't successful with this on two separate machines (gwt archetype wouldn't show in the filter list).  This didn't work either.

Install the Tomcat server by adding it in the Eclipse Preferences -> Server -> Runtime Environment -> Add.  Point it to your installation directory.  You should see it in Server view (Window -> Show View -> Other -> type: server).  Here's my setup: 
Right clicking the instance and going to properties shows the location.  Ensure it is not the workspace location.


Creating the Project


- Create a new 'Maven Project' in Eclipse (File->New->Other... type: 'maven')
- Uncheck 'Create simple project...' and click Next
- Type 'gwt' in the 'Filter' textbox and select 'gwt-maven-plugin'
- type your Group Id, Artifact Id, Package, and give the module the same name as that described in your *.gwt.xml file; ensure you are careful with all of these properties (uniform across other descriptors, property files, and code), and click Finish

Ensure your web.xml references your servlet name, servlet path, and the webapp (the HTML file in this tutorial) correctly!  The web.xml file will highlight a syntax error if the welcome-file-list is present before the servlet-mapping config.  Here is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  
  <!-- Servlets -->
  <servlet>
    <servlet-name>userServlet</servlet-name>
    <servlet-class>test.server.MyUserServiceImpl</servlet-class>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>userServlet</servlet-name>
    <url-pattern>/test/userService</url-pattern>
  </servlet-mapping>

  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>HelloUniverse.html</welcome-file>
  </welcome-file-list>


</web-app>

Ensure that your welcome HTML file correctly references the generated *.nocache.js file and other resources like CSS files:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link type="text/css" rel="stylesheet" href="HelloUniverse.css">
    <title>Web Application Starter Project</title>
    
    <script type="text/javascript" language="javascript" src="hellouniverse/hellouniverse.nocache.js"></script>
  </head>

  <body>
</body>

</html> 

You also need to modify the project's Deployment Assembly property (right click the project -> Properties -> type: deployment, and it should pop up).  Add the /target/<project-name><version>-SNAPSHOT/<modulename> to be deployed on a directory <modulename> (hellounivere in my case):

Building and Running the Project

Now you can build the project by right clicking it-> Run As -> Maven Install.  Then add the project to the server by right clicking the server -> Add and Remove, then move to the right the project you want to deploy.

Go to your URL (localhost:8080/HelloUniverse) and the Click Me button should popup in a second.  If you don't, use the appropriate browser Developer Tools to debug.  A 404 on the *.nocache.js file is likely due to some issues in your web.xml or HTML file.  You should see this upon success:

Project Zip File

You can import my project and server setup from here.