Java Stammtisch Carol McDonald

Wednesday Jul 01, 2009

jax

June: 2 JavaOne Hands On Labs , Sun Technology Exchange, Java Technology Day Israel, and Java Day Turkey  

I had a very busy June, I gave two Hands on Labs at JavaOne, two sessions at the Sun Technology Exchange, three sessions at Java Technology Day in Tel Aviv Israel, and one session at Java Day in Istanbul Turkey.

JavaOne Hands On Labs:

iguana.jpg iguana.jpg

I co-developed and delivered 2 Hands On Labs for JavaOne this year:

You can download these 2 HOLs documentation and code below:


Sun Technology Exchange:

iguana.jpg iguana.jpg
In Fort Lauderdale as part of the Sun Technology Exchange I gave two educational sessions to learn how:
  • JavaFX can help you build rich internet applications (RIAs) and includes the tools and platform SDK for developers, web developers, and designers to create dynamic applications.
  • GlassFish, an enterprise-quality Java EE 5 application server, offers advanced clustering, centralized administration, and best-in-class performance.
  • download the slides


Java Technology Day Israel

iguana.jpg iguana.jpgiguana.jpg
At the Java Technology Day in Israel I gave the following sessions:
  • WSIT Reliability Security and Transactions in Web Services
    • Metro is a high-performance, extensible, easy-to-use web service stack. You can use it for every type of web service, from simple to reliable, secured, and transacted web services that interoperate with .NET services. Metro bundles stable versions of the JAX-WS (Java API for XML Web Services) reference implementation and WSIT (Web Services Interoperability Technology). JAX-WS is a fundamental technology for developing SOAP-based and RESTful Java technology-based web services. WSIT enables secure, reliable interoperability between Java technology-based web services and Microsoft's Windows Communication Foundation.
    • you can download and try out WSIT in this JavaOne HOL: Metro: Try Out Simple and Interoperable Web Services and with these lab instructions.
    • You can read more about some of the example code for this session at
      GlassFish and MySQL, Part 3: Creating a Pet Catalog Web Service
  • MySQL for Developers
    • If you are a developer using MySQL, you should learn enough to take advantage of its strengths, because having an understanding of the database can help you develop better-performing applications. This session talks about MySQL database design and SQL tuning for developers.
    • download or view a screencast of this presentation
  • OpenESB and Connecting Enterprises
    • This session  explains and demonstrates several concrete technologies that make SOA architecture possible - BPEL (Business Process Execution Language), JBI (Java Business Integration) and OpenESB. The part of of BPEL starts with an explanation of the requirements of standardized business process language. The BPEL language is then described using an example. The relationship between BPEL and WSDL is also explained. Finally, BPEL designer and runtime that comes with NetBeans IDE is demonstrated using Travel reservation sample BPEL project. It also explains the motivation of the JBI and OpenESB as a standardized application integration framework in the same way J2EE architecture standardized how enterprise applications are built and deployed. Finally Sun's solution in SOA and application integration space is discussed. Whenever possible, concrete steps of building, deploying and testing SOA applications will be demonstrated step by step.
  • download the slides for all 3

Java Day Turkey

iguana.jpg iguana.jpg iguana.jpg
At the Java Day in Istanbul Turkey I gave the MySQL for Developers session again, see above for more information.




Friday May 01, 2009


I'm Speaking At JavaOne

I'm working on 2 Hands On Labs for JavaOne this year:
  • Building RIA Dojo and JavaFX™ Pet Catalog Clients for MySQL™ backed RESTful Web Services
  • Developing Real-Time Revolutionary Web Applications, Using Comet and Ajax
You can read the HOL details and download some preview documentation and code below:
  • Session ID:       LAB-6771
  • Session Title:     Building RIA Dojo and JavaFX™ Pet Catalog Clients for MySQL™ backed RESTful Web Services
  • Session Abstract:
    • The goal of the Java™ API for RESTful Web Services (JAX-RS) is to provide a high-level declarative programming model for such services that is easy to use and encourages development according to REST tenets. Services built with this API are deployable with a variety of Web container technologies and benefit from built-in support for best-practice HTTP usage patterns and conventions.
      This Hands-on Lab provides an overview of the JAX-RS API and walks developers through the design process for a sample RESTful service.
      Dojo is an open-source DHTML toolkit written in the JavaScript™ programming language. The new JavaFX™ platform brings rich Internet applications to all the screens of your life.
      In the lab, participants will use the NetBeans™ IDE to rapidly develop JAX-RS, Dojo, and JavaFX applications and then deploy them on the GlassFish™ application server, with Java DB or the MySQL™ database.
  • Speakers:       Carol McDonald, Sun Microsystems, Inc.; Sridhar Reddy, Consultant

You can read more about some of the example code for this HOL at
GlassFish and MySQL, Part 4: Creating a RESTful Web Service and JavaFX Client

You can download a preview (some of the slides, docs, code) for this HOL at
Preview subset of slides, doc, code, for Building RIA Dojo and JavaFX™ Pet Catalog Clients for MySQL™ backed RESTful Web Services

  • Session ID:       LAB-5558
  • Session Title:     Developing Real-Time Revolutionary Web Applications, Using Comet and Ajax
  • Session Abstract:  
    • Join the asynchronous Web revolution! Emerging Ajax techniques -- variously called Ajax Push, Comet, and HTTP streaming -- are bringing revolutionary changes to Web application interactivity, moving the Web into the Participation Age. Because Ajax-based applications are almost becoming the de facto technology for designing Web-based applications, it is more and more important that such applications react on the fly, or in real time, to both client and server events. Aajx can be used to enable the browser to request information from the Web server but does not allow a server to push updates to a browser. Comet solves this problem. It is a technology that enables Web clients and Web servers to communicate asynchronously, enabling real-time operations and functions previously unheard of with traditional Web applications to approach the capabilities of desktop applications.
  • Speakers:       Justin Bolter, Sun Microsystems, Inc.; Doris Chen, Sun Microsystems, Inc.; Carol McDonald, Sun Microsystems, Inc.


You can read more about some of the example code for this HOL at
RESTful Web Services and Comet
You can download a preview (some of the slides, docs, code) for this HOL at
Preview subset of slides, doc, code, for Developing Real-Time Revolutionary Web Applications, Using Comet and Ajax

Duke



Thursday Apr 16, 2009

Developing RESTful Web Services with JAX-RS, Netbeans, Glassfish and MySQL

Yesterday I gave a talk at a the Jacksonville Java Users Group (JAXJUG) on Developing RESTful Web Services with JAX-RS, Netbeans, Glassfish, and MySQL.
Jacksonville-Beach-Ocean-View.jpg


You can dowload the StarOffice presentation here

Developing RESTful Web Services with Netbeans and JAX-RS


Content:
Lightweight RESTful approaches have emerged as a popular alternative to SOAP-based technologies for deployment of services on the Internet.

The goal of the Java API for RESTful Web Services (JAX-RS) is to provide a high-level declarative programming model for such services that is easy to use and encourages development according to REST tenets. Services built with this API are deployable with a variety of Web container technologies and benefit from built-in support for best-practice HTTP usage patterns and conventions.

This talk will provides an overview of the design process for a sample RESTful Pet Catalog service using JAX-RS. It shows how to build 2 sample clients for the Pet Catalog service one using the dojo AJAX framework and one using JavaFX.


You can get more information here:

Here is a link to the PDF slides and recorded Webinar
Developing MySQL-Backed RESTful Web Services with Netbeans and JAX-RS

Here is a link to the Article
GlassFish and MySQL, Part 4: Creating a RESTful Web Service and JavaFX Client

Here is a link to the JavaFX code
RESTful Web Service and JavaFX client code

Here is a link to dojo client explanation and code
RESTful Web Service and dojo client explanation and code





Tuesday Apr 14, 2009

the world economy developed huge potential instabilities—vast trade imbalances-From 2000 to 2008, the U.S. trade deficit with China ballooned from $84 billion to $266 billion

A Global Free-For-All?
URL: http://www.newsweek.com/id/192477

Wednesday Mar 25, 2009

Yesterday I gave a talk at a the Ruby Jax User Group on Groovy and Grails with Netbeans , Glassfish and MySQL. The Jacksonville JUG  was invited too, it was held at the hashrocket office , which has the best view I've ever seen from an office building:
beach.jpg

You can dowload the presentation here
Groovy and Grails with Netbeans , Glassfish and MySQL

Content:
     Grails Basics and Netbeans 6.5
     Domain-driven development with Grails
     Orchestrating requests with controllers
     Groovy Views with GSP
     configuring for MySQL
     running on Glassfish  

You can read more about the code examples here:

Building a Grails Pet Catalog using Netbeans 6.5 and MySQL

Combining Groovy, Grails, MySQL, and the Java Persistence API

Writing Your First Ruby-on-Rails Web Application

Sample Catalog Application using using JRuby and Rails
Yesterday I gave a webinar which talked about how to leverage the latest version of the Netbeans IDE to develop RESTful Web Services and clients deployed on Glassfish with MySQL. The talk gave an overview of the design process for a sample RESTful Pet Catalog service using JAX-R, and discussed how to build 3 sample clients for the Pet Catalog service,  one using the Dojo AJAX framework , one using Comet and one using JavaFX.

You can download the presentation  here:
Developing MySQL-Backed Applications with Netbeans and Java RESTful Web Services

you can watch  a 7 minute screencast on how to build a RESTful Pet Catalog using JAX-RS and dojo here

RESTful Pet Catalog screencast

You can read more about the example RESTful web service and the JavaFX client for the RESTful web service here:

Glassfish and MySQL part 4

You can read more about the Comet client for the RESTful web service here:
RESTful Web Services and Comet

You can read more about the dojo client for the RESTful web service here:
a RESTful Pet Catalog

JAX-RS provides a standardized API for building RESTful web services in Java. Central to the RESTful architecture is the concept of resources identified by universal resource identifiers (URIs). The API  provides a set of annotations which you can add to Plain Old Java Objects (POJOs)  to expose web resources identified by URIs

Dojo – An open-source DHTML toolkit written in JavaScript. The Dojo Toolkit includes many utilities that go beyond Ajax. For example, the dojox.comet module simplifies programming Comet applications.

Comet – Techniques that enable a server to push data to client browsers through an HTTP open line of communication.

Thursday Mar 19, 2009


Here is a screencast about MySQL  for Developers

If you are a developer using MySQL, you should learn enough to take advantage of its strengths, because having an understanding of the database can help you develop better-performing applications. This session will talk about MySQL database design and SQL tuning for developers. Some topics include:
  • MySQL Storage Engine Architecture
  • Schema, the basic foundation of performance
  • Think about performance when choosing Data Types
  • Indexes and SQL tuning
  • Understanding SQL Statements using EXPLAIN
  • Scans and seeks
  • Solving performance problems in your queries
  • A Few Things to consider for JPA/Hibernate devlopers, Lazy loading and Optimistic locking


You can download the slides here
https://techdayscode.dev.java.net/servlets/ProjectDocumentList?folderID=9890

You can read more about this at
MySQL for Developers
GlassFish and MySQL, Part 4: Creating a RESTful Web Service and JavaFX Client
High Performance MySQL book
MySQL Pluggable Storage Engine Architecture
MySQL Storage Engine Architecture, Part 2: An In-Depth Look
Optimizing Queries with EXPLAIN
Java Persistence with Hibernate book
Jay Pipes blog
Colin Charles blog
mysql performance blog
Ronald Bradford blog
Taking JPA for a Test Drive
Pro EJB 3: Java Persistence API
Pro MySQL, Chapter 6: Benchmarking and Profiling





Tuesday Mar 10, 2009

This is the fourth article in a series of articles on GlassFish and MySQL.
In Part 4, you'll learn how to create a RESTful web service for the web
application. You'll also examine a JavaFX client for the RESTful web service. As
was the case for Part 3, the web service discussed in Part 4 uses GlassFish,
MySQL, and the Java Persistence API.

Glassfish and MySQL part 4

Wednesday Feb 11, 2009

grailsexample


Building a Grails Pet Catalog using Netbeans 6.5 and MySQL


This Catalog Sample app demonstrates the usage of Groovy and Grails to implement pagination of data sets for a Store Catalog.
download Catalog sample code

Overview of the Technologies and Frameworks in the Sample Application

Grails aims to bring the "coding by convention" paradigm to Groovy. It's an open-source web application framework that leverages the Groovy language and complements Java Web development.

Groovy is an agile and dynamic language for the Java Virtual Machine, it compiles to Java bytecode, and it combines popular features from languages such as Smalltalk, Python, and Ruby.

MySQL is the world's most popular open-source database. It offers consistently fast performance, high reliability and ease of use.

The NetBeans IDE 6.5 , in addition to full support of all Java platforms (Java SE, Java EE, Java ME, and JavaFX), has support for software development with PHP, Ajax and JavaScript, Groovy and Grails, Ruby and Ruby on Rails, and C/C++.  Netbeans 6.5 feature highlights for Groovy and Grails:

  • Develop pure Groovy apps or use Groovy in Java SE projects
  • Groovy editor with code completion, highlighting, and more
  • Grails web application framework
  • Open existing Grails applications without adding metadata

Grails is a Model-View-Controller based framework that simplifies the development of  web applications by reducing the need for configuration files and by generating a lot of the things needed in a database-backed Web application.

mvc.gif



The Sample Application

The sample application displays an online catalog of pets sold in a pet store. The image below shows the Catalog Listing page, which allows a user to page through a list of items in a store.




Setting Things Up:

  1. If MySQL is already not already installed, then download MySQL  and install it.

  2. Download and install Netbeans 6.5 bundled with Glassfish v3 Prelude.

  3. Download and install Grails.

  4. Start NetBeans IDE.  

  5. In the Netbeans IDE,  select Tools Options Groovy and set the location of the Grails package, which you installed using the Glassfish v3 updatetool.



Creating the Catalog Database Item table:
  1. Download the sample code and extract its contents. You should now see the newly extracted directory as <sample_install_dir>/catalog, where <sample_install_dir> is the directory where you unzipped the sample package. For example, if you extracted the contents to C:\ on a Windows machine, then your newly created directory should be at C:\Catalog.

  2. In the Netbeans IDE,  Click Open Project in the File menu and select the catalog directory you just unzipped.
    The file  "/catalog/grails-app/conf/DataSource.groovy" is configured for  MySQL.

  3. Start the MySQL database as follows:
    • Click the Services tab in the NetBeans IDE.
    • Expand the databases node. You should see the MySQL server database in the list of databases.
      databaselist.jpg
    • Right-mouse click on the MySQL server database and select Start.

  4. Create the catalog database as follows:
    • Right-mouse click on the MySQL server database and select Create Database.
    • Enter the database name petcatalog and userid root and password admin. This will open a New Database Connection window. Click O.K. to accept the displayed settings.

  5. Create the tables in the MySQL catalog database as follows:
    • Expand the Drivers node. You should see a driver for the petcatalog database in the list of drivers.
      driverlist.jpg
    • Right-mouse click on the petcatalog driver and select Connect.
    • Right-mouse click on the petcatalog driver and select Execute Command. This will open up a SQL command window.
    • Copy the contents of the catalog.sql file in the <sample_install_dir>/Catalog directory and paste the contents into the SQL command window.
    • Click the Run SQL icon runsql.jpg (Ctrl+Shift+E) above the SQL command window.

  6. Ensure that the username and password settings in the catalog\grails-app\conf\DataSource.groovy file are the same as the corresponding property settings in NetBeans IDE 6.5 for your MySQL server database.
Running the Sample Code:
  1. Run the project as follows:

    • Right click the catalog node in the Projects window.
    • Select Run Project.
When you run the project, your browser should display the opening page of the Sample Application (at http://localhost:8080/catalog/).



How to Create the Catalog Sample Application with Netbeans 6.5 and MySQL

Creating the Application
  1. Run the "grails create-app" command from the IDE, by using  the IDE "Grails Application" project template to create a new Grails application as follows:

    • Choose File > New Project (Ctrl-Shift-N) and then select "Grails Application" from the "Groovy" category. Click Next.
    • In Project Name, type "catalog"; in Project Location, select the folder where the application will be created. Click Finish.


      The IDE runs the "grails create-app" command, showing the output in the Output window. The Projects window should show you this:


      Expand the folders and have a look at the source structure created by the IDE via the Grails scripts. Also look at the generated files and notice that many of them have default values filled in.

Configure Your Grails app data source for MySQL database

Configuring the data source is a simple matter of changing the values for the desired database and driver and placing the driver jar file in the <..>/lib directory.
  1. Download MySQL Connector/J 5.1.6 from here.
  2. Extract the bundle and copy the  "mysql-connector-java-5.1.6-bin.jar" to the "lib" directory of your Grails application: catalog\lib.
  3. Double click on the file "catalog\grails-app\conf\DataSource.groovy" to edit in order to change the values for MySQL configuration. The updated file looks like this (changes highlighted in red):


    Code Sample from: catalog\grails-app\conf\DataSource.groovy

    dataSource {
        pooled = true
        driverClassName = "com.mysql.jdbc.Driver"
        username = "root"
        password = ""   // your mysql password here
        dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
    }
    hibernate {
        cache.use_second_level_cache=true
        cache.use_query_cache=true
        cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
    }
    // environment specific settings
    environments {
        development {
            dataSource {
                dbCreate = "update"  // one of 'create', 'create-drop','update'
                url = "jdbc:mysql://localhost/petcatalog"
            }
        }
        test {
            dataSource {
                dbCreate = "update"
                url = "jdbc:mysql://localhost/petcatalog"
            }
        }
        production {
            dataSource {
                dbCreate = "update"
                url = "jdbc:mysql://localhost/petcatalog"
            }
        }
    }



    Being in production, it's recommended to use InnoDB tables instead of MyISAM tables. This can be easily specified by using the dialect as explained here. More details about the contents of "DataSource.groovy" can be found here.


Creating the Domain Class
  1. use the IDE to run the "grails create-domain-class" script as follows:
    • Right-click on the Domain Classes node and choose New > Grails Domain Class.


    • Name the domain class "Item" and click Finish. The "Item.groovy" domain class is created in the Domain Classes node.


  2. Double click on the catalog\grails-app\domain\Item.groovy class to open it in the editor and add the attributes shown in red below to the item class.
    Code Sample from: catalog\grails-app\domain\Item.groovy

    class Item {
      Long id
      String name
      String description
      String imageurl
      String imagethumburl
      BigDecimal price

    }


The Model - Grails Domain Classes

The Model is your application's persistent business domain objects. A Grails domain object instance represents a row in a database table.  The command grails create-domain-class Item generates the Item.groovy class shown below corresponding to the item database table.

After model code generation you have to add the domain object's attributes and relationships.


Code Sample from: domain\Item.groovy

class Item {
  Long id
  String name
  String description
  String imageurl
  String imagethumburl
  BigDecimal price

}





SQL  Sample for items table

CREATE TABLE item (
  id INT NOT NULL,
  product_id BIGINT NOT NULL,
  name VARCHAR(30) NOT NULL,
  description VARCHAR(500) NOT NULL,
  imageurl VARCHAR(55),
  imagethumburl VARCHAR(55),
  price DECIMAL(14,2) NOT NULL,
  primary key (id),

);


Groovy with Grails dynamically generates getters and setters and the dynamic methods Item.save(), Item.delete(),  Item.list(), Item.get() to retrieve/update data from/to the db table.

Grails Object Relational Mapping (GORM) is currently built on top of Hibernate but you don't have to know Hibernate to use it.

Creating the Controller and Views
  1. use the "grails generate-all" script to create a controller and views for the domain class as follows:
    • Right-click the Controllers node and choose New > Grails Controller.


    • The Item controller and Item views are generated.


The Controller

Controllers handle incoming http requests, interact with the model to get data and to process requests,  invoke the correct view, and direct domain data to the view for display.  In Grails, http requests are handled by Controller classes which are made up of one or more action methods that are executed on request and then either render a Groovy Server Page or redirect to another action. Grails routes requests to the controller action which corresponds to the URL mapping for the request. In Grails the default mapping from URL to action method follows this convention: http://host/app/controller/action/id .  For example the URL http://host/catalog/item/list calls the list action method in the item controller class shown below.     Grails Scaffolding provides a series of standardized Controller action methods for listing, showing, creating, updating, and deleting objects of a class.  These standardized actions come with both controller logic and default view Groovy Server Pages. The command generate-all Item generates the Item controller and the List, Show, Create, Edit Groovy Server Pages for the Item domain object. The ItemController list action renders a view with a paginated list of item objects.

Code Sample from: catalog\grails-app\controllers\ItemController.groovy

class ItemController {

def index = { redirect(action:list,params:params) }

  def list = {
    if(!params.max) params.max = 10
    [ itemInstanceList: Item.list( params ) ]
  }
. . .


When a URL has a controller but no action (e.g. http://localhost:8080/catalog/item/  ), Grails defaults to the index action. In the ItemController code the  index action method redirects to the list action.  The ItemController list action method calls the Item.list() method which returns an ArrayList of item objects retrieved from the item database table . If there are more than params.max objects in the table, Grails creates next and previous pagination links automatically. The itemInstanceList variable  is automatically made available to the view by the framework.

After executing code, actions usually render a GSP in the views directory corresponding to the name of the controller and action, for example the list action will render the catalog\grails-app\views\item\list.gsp .



Running the Application

The catalog Grails application is ready to run:.
  1. Right-click the application and choose "Run".

  2. When you run the project, your browser should display the opening page of the Sample Application (at http://localhost:8080/catalog/) . If the browser does not open automatically, paste the URL into a browser and then you'll see your application.



  3. Click the "ItemController" link and you'll see this:


Modifying The View

The view layer generates a web page, using data from domain objects provided by the controller. In Grails, the view is rendered using Groovy Server Pages

Modifying the List View GSP

  1. Copy the sub directory images from the sample application directory catalog\web-app\ to your application's catalog\web-app\  directory.
  2. Double click on the file "catalog\grails-app\views\item\ list.gsp" to edit in order to modify the item list table. Make the changes highlighted in red):
    Code Sample from: grails-app\views\item\list.gsp

    <table>
       <thead>
         <tr>
    <g:sortableColumn property="name" title="Name" />
            <g:sortableColumn property="imagethumburl" title="Photo" />
            <g:sortableColumn property="price" title="Price" />
         </tr>
       </thead>
       <tbody>
    <g:each in="${itemInstanceList}" status="i" var="itemInstance">
            <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
    <td>
                  <g:link action="show" id="${itemInstance.id}">
                    ${fieldValue(bean:itemInstance, field:'name')}</g:link>
               </td>
               <td>
                  <img src="${itemInstance.imagethumburl}" alt="Pet" />
               </td>
               <td>
                  ${fieldValue(bean:itemInstance, field:'price')}
               </td>
            </tr>
         </g:each>
      </tbody>
     </table>

    <div class="paginateButtons">
    <g:paginate total="${Item.count()}" />
    </div>


    The view uses instance variables set by the controller to access the data it needs to render the GSP.

    GSP has a GroovyTagLib similar to the  JSP tag library. <g: are GroovyTags.

    <g:sortableColumn
           The sortableColumn tag renders a sortable column to support sorting in tables.

    <g:each in="${itemInstanceList}" status="i" var="itemInstance">
    loops through each object in the itemInstanceList variable, which is an ordered ArrayList of Item model objects,  and assigns each Item model object to the iteInstance variable.

    <g:link action="show" id="${itemInstance.id}"> ${fieldValue(bean:itemInstance, field:'name')} </g:link>
    the <g:link> GroovyTag creates an html anchor tag href based on the action, id, controller parameters specified. In this example it generates a link to the item/show/id action which when clicked will display the corresponding item details. For example this line will generate the following HTML for the variable item:
    <a href="/catalog/item/show/2">Friendly Cat</a>
    <img src="${itemInstance.imagethumburl}" alt="Pet" />
    sets the HTML img tag to the item's imagethumburl attribute. 

    ${fieldValue(bean:itemInstance, field:'price')}
    displays the value of the  item 's price attribute .

    <g:paginate total="${Item.count()}" />
    The paginate tag creates next/previous buttons and a breadcrumb trail to allow pagination of results using the Item.count() domain method.

  3. Save your modifcations in the editor. Click reload current page on your browser. The Item List page should now look like the image below:


The Show Action Method

In Grails the mapping for the URL http://host/item/show/1  ( http://host/controller/action/id )  will route to the show action in the ItemController passing 1 to the method as the id of the params parameter hash. The show action of the ItemController class is shown below. The ItemController show action renders a view showing the details of the item object corresponding to the id parameter.

Code Sample from: grails-app\controllers\ItemController.groovy

 def show = {
   def itemInstance = Item.get( params.id )

   if(!itemInstance) {
      flash.message = "Item not found with id ${params.id}"
      redirect(action:list)
   }
   else { return [ itemInstance : itemInstance ] }
 }



The show action method  calls the Item.get() method which queries the items table returning the itemInstance instance variable corresponding to the item with the attribute id (primary key) equal to the  id parameter. This is the equivalent of the following sql : select * from items where id='1' . The itemInstance variable is automatically made available to the Show view by the framework.

Modifying the Show View GSP

After executing code in the action, the show action renders the catalog\grails-app\views\item\show.gsp.
  1. Double click on the file "catalog\grails-app\views\item\show.gsp" to edit in order to modify the item show view. Make the changes highlighted in red below:

    Code Sample from: catalog\grails-app\views\item\show.gsp

     <table>
         <tbody>
    <tr class="prop">
                 <td valign="top" class="name">Name:</td>
                 <td valign="top" class="value">${itemInstance.name}</td>
             </tr>
             <tr class="prop">
                 <td valign="top" class="name">Description:</td>
                 <td valign="top" class="value">${itemInstance.description}</td>
             </tr>
             <tr class="prop">
                 <td valign="top" class="name">Photo:</td>
                 <td><img src="${itemInstance.imageurl}" alt="Pet" /></td>
             </tr>
             <tr class="prop">
                 <td valign="top" class="name">Price:</td>
                 <td valign="top" class="value">${itemInstance.price}</td>
             </tr>
         </tbody>
     </table>



    ${itemInstance.description}
    displays the value of the  item 's description attribute.
    <img src="${itemInstance.imageurl}" />
    sets the HTML image tag for the item's imageurl attribute.
    ${itemInstance.price}
    displays the value of the  item's price attribute.

  2. Save your modifcations in the editor. Click reload current page on your browser.
    The image below shows the resulting page for the url http://host/catalog/item/show/1, which displays the item 1's details:



Layouts

Grails layouts  let you put common html on multiple views (for example page headers,  footers, sidebars).  Default layout templates are in the views layouts directory with a file name corresponding to the controller, or you can associate a view with a layout using the "layout" meta tag to your page:
<meta name="layout" content="main">
To replace the Grails logo with a title and parrot image at the top of the Pet Catalog pages,  put this table in the catalog\grails-app\views\layouts\main.gsp  layout page:

Code Sample from: app/views/layouts/main.gsp

<table>
  <tr>
   <td>Pet Catalog</td>
   <td>
     <img src="${createLinkTo(dir:'images',file:'pet_logo.jpg')}"/>
   </td>
 </tr>
</table>


The image below shows the result on the show page after modifying main.gsp layout page :





Running you Grails app on Glassfish v2:

Netbeans does not yet support deploying grails app directly to Glassfish, but you can create a WAR file and deploy it on Glassfish as follows:
  1. If Jetty is running stop it: click on the IDE Services Tab, Under the Jetty server right-click on the catalog app and select Stop

  2. Right-click on the catalog project node and choose Create War File.

  3. Rename the catalog-0.1.war file to catalog.war. Copy the  catalog.war file from your catalog directory to your Glassfish installation glassfish-v2ur2\domains\domain1\autodeploy  directory. Start Glassfish.

    Enter the URL  http://localhost:8080/catalog/  in your browser, you should see the home page of the Sample Application.

Running you Grails app on Glassfish v3:

GlassFish v3 Prelude is a lightweight Web 2.0 development and deployment platform built on a modular OSGi-based architecture. Developers can benefit from a dynamically extensible and embeddable platform with support for existing Java Web technologies, JRuby, and Groovy. GlassFish Support For Grails Framework adds the Grails framework to the GlassFish application server and allows development and easy deployment of Grails applications. Applications can be deployed in shared or standalone mode. Shared mode allows library reuse and results in much smaller war files.
  1. Install the Grails package to Glassfish v3 using the updatetool.   Start the GlassFish Update Center by issuing the following command: GF_install\updatecenter\bin\updatetool. Check the GlassFish Support for Grails Framework checkbox in the GlassFish Update Center and click Install.
  2. Read the Glassfish Getting started with Grails.

Conclusion

This concludes the sample application which demonstrates how to work with Groovy and Grails  to page through a list of  Item Model objects which are retrieved using Item Controller action methods, and displayed using Item View GSPs.

References


Saturday Feb 07, 2009


Pet Catalog Photos : JavaFX Example Application

Pet Catalog Photos is a simple JavaFX application that displays pet photos retrieved from a RESTful Pet Catalog app (implemented using JAX-RS) described in an earlier blog entry and in this screencast.  This JavaFX example is a modification of the Interesting Photos : JavaFX Example Application.

catalogclient.jpg


Understanding the Code


Code Sample from: main.fx

// Application User Interface
def stage = Stage {
    title: "Pet Catalog"
    resizable: false
    x: bind stageX with inverse
    y: bind stageY with inverse
    width: stageWidth
    height: stageHeight
    visible: true
    style: StageStyle.TRANSPARENT
    scene: Scene {
        content: Group {
            content: bind stageContent
            clip: Rectangle {
                width: stageWidth
                height: stageHeight
                arcWidth: 20
                arcHeight: 20
            }
        }
        fill: Color.TRANSPARENT
    }
}


Stage is the  top level container window required to display any visible JavaFX objects. The variables title, width and height define the the text that appears on the window's top border and its height and width.
The scene variable defines an instance of the Scene object literal, which sets the area in which you can place the JavaFX objects.
Scene is a drawing surface for graphical content and a container that holds the scene graph nodes. It can be added to Stage, and JavaFX renders everything on a scene.
The scene instance variable has a content variable that is used to hold JavaFX graphical elements and defines the graphical content of the application. Here the content consists of a Group Node . The Group Node has a  content variable which is a sequence of child Nodes that will be rendered in order whenever this Group is rendered. The Group Node has a clip variable which specifies a Rectangle which defines the the clipping shape for this Group Node.

stage5_1_1_1.JPG

The Group Node content variable has a data binding  with stageContent.  Data binding allows creating a direct and immediate relationship between two variables or between a variable and the outcome of a function or an expression.   stageContent  is a sequence of Nodes as shown in the code below.  Node - is an element in a scene graph. The following visual objects are examples of javafx.scene.Node implementations: javafx.scene.image.ImageView, javafx.scene.media.Mediaview, javafx.ext.swing.*, javafx.scene.shape.*, and javafx.scene.text.Text. These are leaf nodes, which cannot have a child element.

Code Sample from: main.fx

// Application User Interface
var stageContent: Node[];

stageContent = [
        bgImage, titleBar, nextButton, backButton, closeButton,
        titleText, statusText, thumbImageViewGroup, fullImageView
];

stage4.gif
A grid of ImageView is added to Scene of Stage.

The thumbImageViewGroup variable has a data binding  with thumbImageViews which is a sequence of ThumbImageView which extends ImageView. ImageView is a Node used for painting images loaded with Image class.  The code below shows how the  thumbImageViews sequence is initialized to a  grid of  3 columns and 3 rows of  ThumbImageView .

Code Sample from:  main.fx

var thumbImageViews: ThumbImageView[]; // Thumbnail images
for(col in [0..2]) {
    for(row in [0..2]) {
        def thumbImageView = ThumbImageView {
            x: thumbBaseX + (col * (thumbSize + thumbSpace))
            y: thumbBaseY + (row * (thumbSize + thumbSpace))
            fitWidth: thumbSize
            fitHeight: thumbSize
        }
        insert thumbImageView into thumbImageViews;
    }
}
var thumbImageViewGroup = Group {
    content: bind thumbImageViews
}


calling the RESTful  Pet Catalog Web Service 


Information and URLs for pet photos is obtained by performing an HTTP GET request on a RESTful Catalog service by using the JavaFX asynchronous HTTP API (javafx.io.http.HttpRequest).  HttpRequest allows one to specify a location and method and start a HTTP operation with the function enqueue().  The content of the HTTP response can be accessed in the onInput callback function. onInput calls the PhotoPullParser.parse function to parse the XML.The onDone Callback is invoked when the request has finished execution, onDone calls the updateImages() function, explained later, which updates the images displayed in the Photo-Grid. 


Code Sample from: main.fx

function loadImageMetadata() {
    var start=page * 9;  
    var request: HttpRequest = HttpRequest {

        location: "http://localhost:8080/catalog/resources/items/?start={start}&max=9"
        method: HttpRequest.GET

        onInput: function(input: java.io.InputStream) {                            
             var parser = PhotoPullParser{};
             photos = parser.parse(input);    
        }

        onDone: function() {
             updateImages();
        }
    }
    request.enqueue();
}


The response XML document contains a list of information about available photos. The document contains the following information about each photo:

  • id
  • imagethumburl
  • imageurl
  • server
  • name
  • price
  • productid
  • description
Here is example XML returned from the RESTFul Catalog Service:

 <items uri="http://localhost:8080/catalog/resources/items/">
       <item uri="http://localhost:8080/catalog/resources/items/1/">
           <description>This black and white colored cat is super friendly./description>
           <id>1</id>
           <imagethumburl>http://localhost:8080/catalog/images/anthony-s.jpg</imagethumburl>
           <imageurl>http://localhost:8080/catalog/images/anthony.jpg</imageurl>
           <name>Friendly Cat</name>
           <price>307.10</price>
           <productid>feline01</productid>
       </item>
   ...
   </items>


The response document is parsed by using the JavaFX XML pull parser (javafx.data.pull.PullParser) to extract information about the photos.
The parser supplies a sequence of Events as it process the document under application control. XML and JSON are the two data formats currently supported.  The PullParser can be used with the onEvent callback, which reports the current parse event.  The onEvent callback shown below parses the xml item elements into an instance of the Photo class. When the item END_ELEMENT , </item>, is reached,  the photo
variable is inserted into the photos sequence.

Code Sample from: PhotoPullParser.fx
import javafx.data.pull.PullParser;

public class PhotoPullParser {

  public function parse(input: InputStream): Photo[] {

    // Information about all catalog photos
    var photos: Photo[];
    var photo: Photo;

    // Parse the input data (Photo Metadata) and construct Photo instance
    def parser = PullParser {

        input: input

        onEvent: function(event: Event) {
            if (event.type == PullParser.START_ELEMENT) {
                if(event.qname.name == "item" and event.level == 1) {
                    photo = Photo { };
                }
            } else
            if (event.type == PullParser.END_ELEMENT) {
                if(event.qname.name == "item" and event.level == 1) {
                   insert photo into photos;
                } else
                if(event.qname.name == "id" and event.level == 2) {
                    photo.id = event.text;
                } else
                if(event.qname.name == "name" and event.level == 2) {
                    photo.name = event.text;
                } else
                if(event.qname.name == "imagethumburl" and event.level == 2) {
                    photo.imagethumburl = event.text;
                } else
                if(event.qname.name == "imageurl" and event.level == 2) {
                    photo.imageurl = event.text;
                } else
                if(event.qname.name == "description" and event.level == 2) {
                    photo.description = event.text;
                } else
                if(event.qname.name == "productid" and event.level == 2) {
                    photo.productid = event.text;
                }
            }
        }
    }
    parser.parse();
    return photos;
  }
}

A sequence of photo objects is constructed by parsing the response XML.

Code Sample from: Photo.fx

public class Photo {
    public var id: String;
    public var imagethumburl: String;
    public var imageurl: String;
    public var name: String;
    public var price: String;
    public var description: String;
    public var productid: String;
}



The onDone Callback is invoked when the HttpRequest has finished execution, onDone calls the updateImages() function, shown below.


Code Sample from:  main.fx

// Load image and data specified in given Photo object
function loadImage(photo: Photo, thumbImageView: ThumbImageView): Void {
    thumbImageView.image = Image {
        url: "{photo.imagethumburl}";
        width: thumbSize
        height: thumbSize
        backgroundLoading: true
        placeholder: thumbImageView.image
    };
    thumbImageView.photo = photo;

// Update images displayed in Photo-Grid
function updateImages() {
    for(i in [0..8]) {
        var photoIndex = i;
        loadImage(photos[photoIndex], thumbImageViews[i]);
    }
}

updateImages updates the images displayed in the thumbImageViewGroup by  updating the thumbImageView Image URLs to the photo URLs parsed from the HTTP response. The photos are then fetched and displayed in Stage as a grid. The imagethumburl , imageurl are used to retrieve and then display photos. The ImageView class knows how to retrieve the image using the URL and display it. Once the photo is retrieved, it is displayed in Scene of Stage through the use of data binding.


If the user clicks a thumb photo, the normal photo is loaded and shown.

catalogclientlarge.jpg


When the user clicks a thumb photo, the ThumbImageView onMouseClicked function sets the fullImageView url to the clicked photo's larger image url and sets the fullImageView show variable to true.


Code Sample from:  main.fx

// Initialize fullscreen ImageView
var fullImageView = FullImageView {
    translateX: thumbBaseX
    translateY: thumbBaseY
    visible: false
}

// To display thumb image
class ThumbImageView extends ImageView {

    public override var onMouseClicked = function(e:MouseEvent) {   
      // Load larger image
      fullImageView.image = Image {
         url: "{photo.imageurl}"
         placeholder: image
         backgroundLoading: true
       };
    }  
    fullImageView.show = true;
}

When the fullImageView show variable is set to true, The FullImageView Node's  visible variable is set to true which specifies that this Node and any subnodes should be rendered as part of the scene graph. The  fader() function causes the fullImageView to fade in or out. The FullImageView Node's  opacity variable specifies how opaque (that is, solid) the Node appears. Animation occurs along a timeline, represented by a javafx.animation.Timeline object. Each timeline contains one or more key frames, represented by javafx.animation.KeyFrame objects. The value of the time instance variable, 3s, defines the elapsed time at which the values within the key frame will be set in a single cycle of the Timeline object. The play() method plays the timeline as defined.


Code Sample from:  FullImageView.fx

public class FullImageView extends ImageView {

    public var show = false on replace {
        if(useEffects) {
            fader();
        } else {
visible = show;
        }
    }
    var timeline:Timeline = Timeline {
        rate: bind timelineRate with inverse
        keyFrames: [
            KeyFrame {
                time: 3s
                values: [ opacity => 1.0 tween Interpolator.LINEAR ]
            }
        ]
    };
    function fader() {    
        if(show) {
            timeline.time = 0s;
            timelineRate = 1.0;
opacity = 0.0;
visible = true;
        } else {
            timeline.time = 3s;
            timelineRate = -3.0;
opacity = 1.0;
        }   
        timeline.play();
    }


stage4.gif

Clicking the normal photo again restores the thumb photo grid. The user can navigate to the next or previous set of photos by clicking << and >> arrow buttons.  Clicking the nextButton calls the onNext() function which increments the page number and calls loadImageMetadata();

Code Sample from:  main.fx

// Display next set of photos
var nextButton = ImageButton {
    selectImage: Image {
        url: "{__DIR__}images/next_h.png"
    };        
    onMouseClicked: function(e) {
onNext();
    }
}

// Load image and data specified in given Photo object
function onNext() {
    fullImageView.show = false;
    page++;
    //updateImages();
    loadImageMetadata();
}


Running the code

Netbeans 6.5 has plugins for JavaFX.  If  you don't have Netbeans 6.5  download and install it, then  go to Tools..Plugins and select the JavaFX plugins.  You can also download the JavaFX SDK without Netbeans, but I'm going to focus on using JavaFX with Netbeans.
To start learning JavaFX  you can start off with the doc Creating Your First JavaFX Application and/or with the tutorial  Learning the JavaFX Script Programming Language.

Running the RESTful Catalog service

  1. Download the sample code and extract its contents. You should now see the newly extracted directory as <sample_install_dir>/catalog, where <sample_install_dir> is the directory where you unzipped the sample package. For example, if you extracted the contents to C:\ on a Windows machine, then your newly created directory should be at C:\catalog.
  2. Start NetBeans IDE. Click Open Project in the File menu and select the catalog directory you just unzipped.
  3. Start the MySQL or JavaDB database as follows:
    • Click the Services tab in the NetBeans IDE.
    • Expand the databases node. You should see the MySQL server or JavaDB database in the list of databases.
      databaselist.jpg
    • Right-mouse click on the MySQL or JavaDB server database and select Start.
  4. Create the catalog database as follows:
    • Right-mouse click on the MySQL or JavaDB server database and select Create Database.
    • Enter the database name petcatalog and userid root and password admin. This will open a New Database Connection window. Click O.K. to accept the displayed settings.
  5. Create the tables in the MySQL catalog database as follows:
    • Expand the Drivers node. You should see a driver for the petcatalog database in the list of drivers.
      driverlist.jpg
    • Right-mouse click on the petcatalog driver and select Connect.
    • Right-mouse click on the petcatalog driver and select Execute Command. This will open up a SQL command window.
    • Copy the contents of the catalog.sql file in the catalog directory and paste the contents into the SQL command window.
    • Click the Run SQL icon runsql.jpg (Ctrl+Shift+E) above the SQL command window.
    • Open the  catalog/setup/sun-resources.xml file and verify that the property values it specifies match those of the database you created (jndi datasource, username, password...). For example
      <resources>
        <jdbc-resource  jndi-name="catalog" />
          <property name="User" value="root"/>
          <property name="Password" value="admin"/>
          <property name="serverName" value="localhost"/>
          <property name="portNumber" value="3306"/>
          <property name="databaseName" value="petcatalog"/>
          <property name="URL" value="jdbc:mysql://localhost:3306/petcatalog"/>
      </resources> 
      Edit the property values as necessary to match the database you created .
  6. Build the project as follows:

    • Right click the catalog node in the Projects window.
    • Select Clean and Build Project.

  7. Run the project as follows:

    • Right click the catalog node in the Projects window.
    • Select Run Project.
When you run the project, your browser should display and empty html page at http://localhost:8080/catalog/  (this is the service not the client).

Running the JavaFX Pet Catalog Client

  1. Download the sample code and extract its contents. You should now see the newly extracted directory as <sample_install_dir>/catalog, where <sample_install_dir> is the directory where you unzipped the sample package. For example, if you extracted the contents to C:\ on a Windows machine, then your newly created directory should be at C:\catalogclient.
  2. In NetBeans IDE, click Open Project in the File menu and select the catalogclient directory you just unzipped.
  3. Run the project as follows:
    • Right click the catalogclient  node in the Projects window.
    • Select Run Project.
When you run the project, your browser should display the Pet Catalog Client.

References



Friday Feb 06, 2009

for those interested in REST ,  a 7 minute screencast on how to build a
RESTful Pet Catalog using JAX-RS and dojo

http://www.netbeans.org/kb/docs/websvc/pet-catalog-screencast.html 

http://www.bestechvideos.com/2008/11/11/netbeans-tv-restful-web-services-pet-catalog



Saturday Dec 06, 2008

Pet Catalog Photos : JavaFX Example Application

Pet Catalog Photos is a simple JavaFX application that displays pet photos retrieved from a RESTful Pet Catalog app (implemented using JAX-RS) described in an earlier blog entry and in this screencast.  This JavaFX example is a modification of the Interesting Photos : JavaFX Example Application.

catalogclient.jpg


Understanding the Code

Information and URLs for pet photos is obtained by performing an HTTP GET request  on a RESTful Catalog service by using the JavaFX asynchronous HTTP API (javafx.io.http.HttpRequest). The response document is parsed by using the JavaFX XML pull parser (javafx.data.pull.PullParser) to extract information about the photos. The photos are then fetched and displayed in Stage as a grid. The user can click the thumb image to load the normal image. Clicking the normal image again returns the UI to thumb image view. 

The response XML document contains a list of information about available photos. The document contains the following information about each photo:

  • id
  • imagethumburl
  • imageurl
  • server
  • name
  • price
  • productid
  • description
Here is example XML returned from the RESTFul Catalog Service:
  
 <items uri="http://localhost:8080/catalog/resources/items/">
       <item uri="http://localhost:8080/catalog/resources/items/1/">
           <description>This black and white colored cat is super friendly./description>
           <id>1</id>
           <imagethumburl>http://localhost:8080/catalog/images/anthony-s.jpg</imagethumburl>
           <imageurl>http://localhost:8080/catalog/images/anthony.jpg</imageurl>
           <name>Friendly Cat</name>
           <price>307.10</price>
           <productid>feline01</productid>
       </item>
   ...
   </items>

The imagethumburl , imageurl are used to retrieve and then display photos. The ImageView class knows how to retrieve the image using the URL and display it. Once the photo is retrieved, it is displayed in Scene of Stage through the use of data binding.

A sequence of photo objects is constructed by parsing the response XML. A grid of ImageView is added to Scene of Stage. If the user clicks this thumb photo, the normal photo is loaded and shown. Clicking the normal photo restores the thumb photo grid. The user can navigate to the next or previous set of photos by clicking << and >> arrow buttons.


Running the code

Netbeans 6.5 has plugins for JavaFX.  If  you don't have Netbeans 6.5  download and install it, then  go to Tools..Plugins and select the JavaFX plugins.  You can also download the JavaFX SDK without Netbeans, but I'm going to focus on using JavaFX with Netbeans.
To start learning JavaFX  you can start off with the doc Creating Your First JavaFX Application and/or with the tutorial  Learning the JavaFX Script Programming Language. 

Running the RESTful Catalog service

  1. Download the sample code and extract its contents. You should now see the newly extracted directory as <sample_install_dir>/catalog, where <sample_install_dir> is the directory where you unzipped the sample package. For example, if you extracted the contents to C:\ on a Windows machine, then your newly created directory should be at C:\catalog.
  2. Start NetBeans IDE. Click Open Project in the File menu and select the catalog directory you just unzipped.
  3. Start the MySQL database as follows:
    • Click the Services tab in the NetBeans IDE.
    • Expand the databases node. You should see the MySQL server database in the list of databases.  
      Database list
    • Right-mouse click on the MySQL server database and select Start.
  4. Create the catalog database as follows:
    • Right-mouse click on the MySQL server database and select Create Database.
    • Enter the database name catalog. This will open a New Database Connection window. Click O.K. to accept the displayed settings.
  5. Create the tables in the MySQL catalog database as follows:
    • Expand the Drivers node. You should a driver for the catalog database in the list of drivers.
      Driver list
    • Right-mouse click on the catalog driver and select Connect.
    • Right-mouse click on the catalog driver and select Execute Command. This will open up a SQL command window.
    • Copy the contents of the catalog.sql file in the catalog directory and paste the contents into the SQL command window.
    • Click the Run SQL icon Run SQL icon (Ctrl+Shift+E) above the SQL command window.
    • Open the  catalog/setup/sun-resources.xml file and verify that the property values it specifies match those of the database you created (jndi datasource, username, password...). Edit the property values as necessary.
  6. Build the project as follows:

    • Right click the catalog node in the Projects window.
    • Select Clean and Build Project.

  7. Run the project as follows:

    • Right click the catalog node in the Projects window.
    • Select Run Project.
When you run the project, your browser should display and empty html page at http://localhost:8080/catalog/  (this is the service not the client).

Running the JavaFX Pet Catalog Client

  1. Download the sample code and extract its contents. You should now see the newly extracted directory as <sample_install_dir>/catalog, where <sample_install_dir> is the directory where you unzipped the sample package. For example, if you extracted the contents to C:\ on a Windows machine, then your newly created directory should be at C:\catalogclient.
  2. In NetBeans IDE, click Open Project in the File menu and select the catalogclient directory you just unzipped.
  3. Run the project as follows:
    • Right click the catalogclient  node in the Projects window.
    • Select Run Project.
When you run the project, your browser should display the Pet Catalog Client.

References


Friday Oct 24, 2008

yesterday Greenspan admitted that he was surprised and "partially" wrong about the free market. When will economists admit that they are wrong about globalization?  A problem with globalization is it encourages over specialization in what a country does best. Over specialization is bad because when the environment changes you die,  you see this in the fossil record, generalizers survive changes (I have a BS in Geology).  A Haitian neighbor agreed this is a problem, when Haiti specialized in Bananas for example and then Honduras grew them cheaper, where did that leave Haiti? 

A country should not over import , a country should have its own farmers, manufacturers , scientists, and engineers.

Monday Oct 20, 2008

Travelling in Brazil and Buenos Aires recently I was wondering why has North America been (generally) more successful than South America? Brazil and Argentina had economic booms... and busts. I think it is because historically N. America has had a more stable and relatively less corrupt government, a strong middle class, strong work and values ethics, creating an infrastructure of trust and opportunity. It is important that the government provide a education , opportunity, a safety net , but at the same time the people should not depend on the government to provide for them.

I have repeatedly heard politicians say that free trade has led to greater prosperity here and abroad. China has become the global factory, Brazil the world's farmer, and India its back office, this is not viable longterm.
Right now we don't have "free" trade, its not "free" when pollution is so bad the Olympic athletes were concerned about breathing, and green stuff had to be removed for the kayak competition. Its not "free" when we import almost everything and some of our best exports--- movies and software-- are not purchased but copied illegally. What we need is fair and balanced trade.
Limits should be set so that we only buy as much from a country as they buy from us (I mean real products not debt). We should make sure to keep some manufacturing here, we can't just be a country of services. We should make sure that we keep enough hi-tech jobs here to encourage future generations to study science and tech in college.
It is risky to depend on other countries for food, manufacturing, or hi-tech. The Philippines used to export rice, now they import it. Every country should be able to feed itself, at least I want to live in a country that grows enough food to feed itself.
It is wrong when the country's largest employer is Walmart, what kind of future does that offer? A country of have's and have nots.

The strength of our country is a strong middle class, a mostly stable incorrupt government, an infrastructure of trust and values, a work ethic, and a future of more than flipping burgers.

Tuesday Sep 30, 2008


Since September 24th I've been speaking in Brazil at JUGs, Universitys, and at Sun Tech Days as part of the September Month of Java in Brazil .

MapBRAZIL-Cities2.jpg


I spoke on September 24  in Maringa to ~500 JUG members/students/professors, September 25 in Toledo to ~ 500,  September 26 in  Xanxere to ~ 200, September 27 in Porto Alegre to ~70, and in Sao Paulo there were ~1000 attendees.   We spoke in a different location each evening which meant going to sleep late and waking up early the next morning to travel to the next location.  The guys organizing this obviously do not value sleep and time to run (I'm a avid runner)  as much as I do !   They also don't have the same conception of safety, our driver was going 90mph on a 2 lane road with oncoming traffic which didn't phase Bruno and Eduardo, whereas I was seriously praying to God for my life !! :)  The attendees in each city were very friendly and enthusiastic which compensated for the difficult schedule  (but next time I will insist on more time to travel between destinations!) .   Also we drove close to the beautiful  Iguaçu_Falls  and we flew through the beautiful Florianópolis  (note to self,  next time make sure to schedule a little time to rest and see noteworthy sites ;) .

During this trip I spoke on:

I learned a little about Brazil in conversations over dinner:
It was good that USA kicked out the Brits before we discovered gold, because the Portuguese took away a lot of Brazil's gold. USA has probably had more economic stability (until recently) because we always had a strong middle class, whereas in Brazil historically there was a big gap between the rich and poor with the wealth concentrated in a small percent of the population, however this has been improving recently
Brazil had really bad inflation during the 1970s, ~ 25% per month !  Brazillians told me they used to take their salary check and buy food for the whole month the same day.  But now the Brazillian inflation is under control, they paid off their debt,  and the economy is doing well. Last year they received more foreign investment than any other country.  
Last year Brazil made a huge oil discovery  which could raise Brazil's petroleum reserves by ~40 percent and boost Brazil into the ranks of the world's major exporters (drill baby drill) .  Brazillian cars are required to run on a gas ethanol  mixture and they have a very cost-effective process to produce ethanol from sugar cane. Brazil's sugar cane-based industry is far more efficient than the U.S. corn-based industry. Sugar cane ethanol has an energy balance 7 times greater than ethanol produced from corn , and Brazil's sugar cane based ethanol industry has not caused food prices to increase.
Bruno told me that he grew up near the amazon forest and used to swim in rivers with piranhas,  he said they don't bite unless you have a cut and are bleeding, can you imagine swimming with these things ?
piran.jpg

Here are some photos from my trip :

IMG_0868_1_1.JPG IMG_0871_1_1.JPGIMG_0878_1_1.JPG IMG_0885_1_1.JPGIMG_0886_1_1.JPG IMG_0888_1_1.JPG