Be prepared to be shot when making a coding error!

Introducing Scooter 1.1 Release

Relax. No one get shot for compliation errors. But you will hear gun shots. Well, just for fun.

Java development should be fun as well as productive. In Scooter 1.1 release, we continue to develop Scooter along this direction. The following are main features introduced into this release. For a full list of features, click here.

Compilation error audio and visual notification

Scooter now alerts you when you make a compilation error. Here are simple steps to see it.

1. Just type the following in a command window to start Scooter's Hello World sample app:

>java -jar tools/server.jar examples/greeting

2. Open a Java source file, e.g. greeting/WEB-INF/src/greeting/controllers/HelloController.java

3. Intentionally make a coding error by removing a semicolon ';' from one of the code line.

4. Save the file. Now you should hear a gun-shot sound.

5. Browse http://localhost:8080/greeting. You should see the following:

Compilation alert

6. Click on the link to the file. You can edit and compile it online. (username: admin, password: welcome)

Guess what sound you will hear when you successfully compile the code? Try it yourself.

Query interface for Active Record

Scooter now supports Query Interface as Rails3.0.

The following is an example usage of the new query interface. Click here for more details.

//Retrieve a pet named Leo
ActiveRecord Leo = Pet.where("name='Leo'").getRecord();

//Retrieve a list of pets whose ids are 6 and 10, and
//sort results by birth_date in descending order
List pets = Pet.where("owner_id IN (6, 10)").orderBy("birth_date DESC").getRecords();

//Retrieve a list of pets with a limit of 3 records per page and
//skips the first 5 records and order the result by pet name:
List pets = Pet.limit(3).offset(5).orderBy("name").getRecords();

//Retrieve a list of owners whose last name starts with 'E' and their pets
List owners = Owner.where("last_name='E%'").includes("pets").getRecords();

The last example above uses includes() method and uses two models, pet and owner. Only one SQL query will be executed. This is how Scooter does eager loading.

Active Record with non-default database

By overriding getConnectionName() method, you can link a model with a specific database connection.

//The post record comes from blog_development which is the default database.
public class Post extends ActiveRecord {
}

//The post record comes from blog_mysql database which is not the default.
public class Post extends ActiveRecord {
    public String getConnectionName() {
        return "blog_mysql";
    }
}

ActiveRecord post = Post.newRecord();
post.setData("content", "Java programming is fun.");
post.create();//create a new record in the posts table in blog_mysql.

ActiveRecord post10 = Post.findById(10);//retrieve post record with id #10.

You can even join models from different databases. Click here for more details.

Better HTTP request support

Now you have more APIs to deal with a HTTP request in your controller classes.

//Get all employees from a selection list in HTTP Form.
String[] selectedEmployees = pArray("employees");

//Get gender choice from a choicebox in HTTP Form.
Boolean gender = pBoolean("sex");

//Get birthday from an input in HTTP Form.
Date birthday = pDate("birthday");

You can also specify a date format or use pFile() and pFiles() to handle uploaded files. Click here for details.

Also take a look at the http://localhost:8080/greeting/examples example. Example 3 demonstrates how to handle various elements of a HTTP form.

HTTP Form Example

MS SQL Server database support

Scooter now supports Microsoft's SQL Server database. You can create an AJAX-powered application for SQL Server with the following steps.

1. Create the app named "adventureworks".

>java -jar tools/create.jar adventureworks sqlserver
Adventure Works

2. Modify the adventureworks_development entry in adventureworks/WEB-INF/config/database.properties file by adding your own username and password.

database.connection.aw=\
	driver=com.microsoft.sqlserver.jdbc.SQLServerDriver,\
	url=jdbc:sqlserver://localhost:1433;databaseName=adventureworks,\
	username=sa,\
	password=welcome,\
	max_pool_size=10,\
	min_pool_size=1

3. Start the server

>java -jar tools/server.jar adventureworks

4. Browse Adventure Works Sample Database from Microsoft.

http://localhost:8080/adventureworks/admin/databases/adventureworks_development/tables
Browse Adventure Works tables

5. Create an AJAX-powered application to manage locations in product schema.

5.1 Set use.plural.table.name=false in adventureworks/WEB-INF/config/database.properties.
The default value is true. But apparently Adventure Works sample database does not use plural words for table names.

5.2 Generate the app

>java -jar tools/generate.jar adventureworks scaffold-ajax production.location

6. Browse product locations in an AJAX way: you can show/edit/delete/add a record without leaving the page.

http://localhost:8080/adventureworks/productionlocations
Ajax Product Locations

For more details on Scooter's AJAX support, click AJAX.

FreeMarker support

Besides JSP, StringTemplate, Scooter now supports Free Marker template. You can mix view files with all of these types.

You can play with different templates by using different return statements in greeting/WEB-INF/src/greeting/controllers/WelcomeController.java. The views are located under greeting/WEB-INF/views/welcome. There is no need to restart web server after each update of the file.

public class WelcomeController {
    public String sayit() {
        flash("notice", "Successfully found the message");
        setViewData("content", "Java programming is fun!");

        //render default view (.jsp)
        return renderView("sayit");

        //render FreeMarker view
        //return renderView("sayit.ftl");

        //render StringTemplate view
        //return renderView("sayit.st");
    }
}

Browse the following URL whenever you make a change in the WelcomeController.java class.

http://localhost:8080/greeting/welcome/sayit

For more details on Scooter's view rendering, click here.

Generating scaffold code from any database connection

You can generate scaffold code for any database connection, not just the default connection.

The example below generates an application to do CRUD on posts table in an Oracle database.

>java -jar tools/generate.jar blog scaffold post@blog_oracle

You can then browse the posts with this url:

http://localhost:8080/blog/posts

Type the below command for more examples on using code generation.

>java -jar tools/generate.jar -help

For more details on Scooter's tools, click here.