Friday October 02, 2009
TOTD #109: How to convert a JSF managed bean to JSR 299 bean (Web Beans) ?
Content available at http://blog.arungupta.me/2009/10/totd-109-how-to-convert-a-jsf-managed-bean-to-jsr-299-bean-web-beans/>.
Posted by Arun Gupta in General | Comments[3]
|
|
|
|
|
Wednesday September 02, 2009
Track your running miles using Apache Wicket, GlassFish, NetBeans, MySQL, and YUI Charts
Content available at: http://blog.arungupta.me/2009/09/track-your-running-miles-using-apache-wicket-glassfish-netbeans-mysql-and-yui-charts/.
Posted by Arun Gupta in General | Comments[0]
|
|
|
|
|
Monday August 31, 2009
TOTD #97 showed how to install GlassFish Tools Bundle for Eclipse 1.1. Basically there are two options - either install Eclipse 3.4.2 with WTP and pre-bundled/configured with GlassFish v2/v3, MySQL JDBC driver and other features. Or if you are using Eclipse 3.5, then you can install the plug-in separately and get most of the functionality.
TOTD #98 showed how to create a simple Metro/JAX-WS compliant Web service using that bundle and deploy on GlassFish.
This Tip Of The Day (TOTD) shows how to create a simple Java EE 6 application that reads data from a MySQL database using JPA 2.0 and Servlet 3.0 and display the results. A more formal support of Java EE 6/Servlet 3.0 is coming but in the meanwhile the approach mentioned below will work.
Lets get started!














@WebServlet(urlPatterns="/ServletClient")
public class ServletClient extends HttpServlet {
@PersistenceUnit
EntityManagerFactory factory;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ServletOutputStream out = resp.getOutputStream();
List list = factory.createEntityManager().createQuery("select f from Film f where f.title like 'GL%';").getResultList();
out.println("<html><table>");
for (Object film : list) {
out.print("<tr><td>" + ((Film)film).getTitle() + "</tr></td>");
}
out.println("</table></html>");
}
}
import java.io.IOException; import java.util.List; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceUnit; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import model.Film;Basically, this is a Servlet 3.0 specification compliant Servlet that uses @WebServlet annotation. It uses @PersistenceUnit to inject the generated JPA Persistence Unit which is then used to query the database. The database query return all the movies whose title start with "GL" and the response is displayed in an HTML formatted table.


Simple, easy and clean!
How are you using Eclipse and GlassFish - the consolidated bundle or standalone Eclipse + GlassFish plugin ?
Download GlassFish Tools Bundle for Eclipse now.
Please send your questions and comments to users@glassfishplugins.dev.java.net.
Please leave suggestions on other TOTD that you’d like to see. A complete archive of all the tips is available here.
Technorati: glassfish eclipse mysql jpa database
Posted by Arun Gupta in General | Comments[0]
|
|
|
|
|
Monday August 17, 2009
TOTD
#93
showed how to get started with Java EE 6
using NetBeans
6.8 M1 and
GlassFish v3 by
building a simple Servlet 3.0 + JPA 2.0 web
application. TOTD
#94 built upon it by using Java Server Faces 2 instead of
Servlet 3.0 for displaying the results. However we are still using a
POJO
for all the database interactions. This works fine if we are only
reading values from the database but that's not how a typical web
application behaves. The web application would typically perform all
CRUD operations. More typically they like to perform one or more CRUD
operations within the context of a transaction. And how do you do
transactions in the context of a web application ? Java EE 6 comes to
your rescue.
The EJB 3.1
specification (another new specification in Java EE 6) allow
POJO classes to be annotated with @EJB and bundled within
WEB-INF/classes of a WAR file. And so you get all transactional
capabilities in your web application very easily.
This Tip
Of The Day (TOTD) shows how
to enhance the application created in TOTD #94 and use EJB 3.1 instead
of the JSF managed bean
for
performing the business logic. There are two ways to achieve this
pattern as described below.
Lets call this TOTD #95.1
| @javax.ejb.Stateless @ManagedBean public class StateList { @PersistenceUnit EntityManagerFactory emf; public List<States> getStates() { return emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); } } |


| @Stateless public class StateBeanBean { @PersistenceUnit EntityManagerFactory emf; public List<States> getStates() { return emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); } } |
| @ManagedBean public class StateList { @EJB StateBeanBean bean; public List<States> getStates() { return bean.getStates(); } } |
| @Stateless public class StateBeanBean { @PersistenceContext EntityManager em; public List<States> getStates() { return em.createNamedQuery("States.findAll").getResultList(); } } |

Posted by Arun Gupta in General | Comments[1]
|
|
|
|
|
Friday August 14, 2009
TOTD
#93
showed how to get started with Java EE 6
using NetBeans
6.8 M1 and
GlassFish v3 by
building a simple Servlet 3.0 + JPA 2.0 web
application. JPA 2.0 + Eclipselink was used for the database
connectivity
and Servlet 3.0 was used for displaying the results to the user. The
sample demonstrated how the two technologies can be mixed to create a
simple web application. But Servlets are meant for server-side
processing rather than displaying the results to end user. JavaServer
Faces 2 (another new specification in Java EE 6) is designed
to fulfill
that purpose.
This Tip
Of The Day (TOTD) shows how
to enhance the application created in TOTD #93 and use JSF 2 for
displaying the results.


| package server; import java.util.List; import javax.faces.bean.ManagedBean; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceUnit; import states.States; /** * @author arungupta */ @ManagedBean public class StateList { @PersistenceUnit EntityManagerFactory emf; public List<States> getStates() { return emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); } } |
| Show States |
|
<h:dataTable var="state" value="#{stateList.states}"
border="1"> <h:column><h:outputText value="#{state.abbrev}"/></h:column> <h:column><h:outputText value="#{state.name}"/></h:column> </h:dataTable> |


Posted by Arun Gupta in General | Comments[3]
|
|
|
|
|
Thursday August 13, 2009
NetBeans
6.8 M1 introduces support for creating Java EE 6 applications
... cool!
This Tip Of The Day (TOTD) shows how
to create a simple web application using JPA 2.0 and Servlet 3.0 and
deploy on GlassFish v3 latest
promoted build (58
as of this writing). If you can work with the one week older build then
NetBeans 6.8 M1 comes pre-bundled with 57. The example below should
work fine on that as well.
| ~/tools/glassfish/v3/58/glassfishv3/bin >sudo mysql --user root Password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1592 Server version: 5.1.30 MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create database states; Query OK, 1 row affected (0.02 sec) mysql> CREATE USER duke IDENTIFIED by 'glassfish'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL on states.* TO duke; Query OK, 0 rows affected (0.24 sec) mysql> use states; Database changed mysql> CREATE TABLE STATES ( -> id INT, -> abbrev VARCHAR(2), -> name VARCHAR(50), -> PRIMARY KEY (id) -> ); Query OK, 0 rows affected (0.16 sec) mysql> INSERT INTO STATES VALUES (1, "AL", "Alabama"); INSERT INTO STATES VALUES (2, "AK", "Alaska"); . . . mysql> INSERT INTO STATES VALUES (49, "WI", "Wisconsin"); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO STATES VALUES (50, "WY", "Wyoming"); Query OK, 1 row affected (0.00 sec) |
| ~/tools/glassfish/v3/58/glassfishv3/bin >asadmin start-domain |
| ~/tools/glassfish/v3/58/glassfishv3/bin >./asadmin
create-jdbc-connection-pool --datasourceclassname
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype
javax.sql.DataSource --property
"User=duke:Password=glassfish:URL=jdbc\:mysql\://localhost/states"
jdbc/states Command create-jdbc-connection-pool executed successfully. ~/tools/glassfish/v3/58/glassfishv3/bin >./asadmin ping-connection-pool jdbc/states Command ping-connection-pool executed successfully. ~/tools/glassfish/v3/58/glassfishv3/bin >./asadmin create-jdbc-resource --connectionpoolid jdbc/states jdbc/jndi_states Command create-jdbc-resource executed successfully. |





| @PersistenceUnit EntityManagerFactory emf; |
|
List<States> list =
emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); out.println("<table border=\"1\">"); for (States state : list) { out.println("<tr><td>" + state.getAbbrev() + "</td><td>" + state.getName() + "</td></tr>"); } out.println("</table>"); |



Posted by Arun Gupta in General | Comments[5]
|
|
|
|
|
Tuesday July 28, 2009
Track your running miles using JRuby, Ruby-on-Rails, GlassFish, NetBeans, MySQL, and YUI Charts
This blog introduces a new application that will provide basic tracking
of your running distance and generate charts to monitor progress. There
are numerous similar applications that are already available/hosted and
this is a very basic application. What's different about this ?
The first version of this application is built using JRuby,
Ruby-on-Rails, GlassFish Gem, MySQL, and NetBeans IDE. This combination
of technologies is a high quality Rails stack that is used in production
deploymnet at various places. Still nothing different ?
A similar version of this application
will be built using a variety of Web frameworks such as Java EE, Grails, Wicket, Spring and Struts2 (in
no particular order). The goal is to provide a similar application,
slightly bigger than "Hello World," built using different frameworks
and deploy on GlassFish.
Each framework will then be evaluated based upon the criteria ranging
from the basic principles of framework, ease-of-use in
design/development/testing/debugging/production of this web app,
database interaction, tools support, ability to add 3rd party
libraries, browser compatibility and other points.
An important point to note is that this is not an exhaustive
evaluation of different Web frameworks and the scope is limited only to
this application.
A complete list of frameworks planned is available here.
The criteria used to evaluate each framework is described here.
Your feedback in terms of Web frameworks and evaluation criteria is
highly appreciated. Please share your feedback on the users list.
Now the first version of application. The complete instructions to
check out and run the Rails version of
this application are available here.
Here are some charts generated using the application:

and

YUI is
used for all the charting capabilities.
And here is a short video that explains how the application work:
If you are a runner, check out the application and use it for tracking
your miles. A sample runlog is available in "test/fixtures/runlogs.yml"
and races in "test/fixtures/races.yml".
If you know Rails, please provide feedback if the application is DRY
and using the right set of helpers.
If you'd like the existing list of web frameworks to be pruned or
include another one to the list, let us know.
Share you feedback at users@runner.kenai.com.
Technorati: jruby
rubyonrails
glassfish
netbeans
mysql
yahoo
yui chart running miles framework
Posted by Arun Gupta in Running | Comments[2]
|
|
|
|
|
Wednesday July 08, 2009
Received a "certificate of attendance as speaker" for recently
concluded FISL 10.

This is sweet, thanks FISL organizers! It certainly adds a personal
touch to the whole experience.
I don't remember receiving a personal certificate like this :)
Technorati: conf
fisl brazil glassfish
netbeans
mysql
eclipse
Posted by Arun Gupta in General | Comments[3]
|
|
|
|
|
Tuesday June 30, 2009
FISL 2009 wrapped up over the weekend. Even though the
conference officially ended on Saturday but the connections made there
will certainly allow us to continue all the great momentum. The
conference celebrates open source and it was certainly great to see
Federal Government and Banks with their booths in the exhibitor halls.
The visit by Brazilian President Lula certainly highlights the
importance of this conference to the local community. There were booths
from Debian, Firefox, Ubuntu and other major open source softwares.
Some commercial vendors had a booth as well and of course Sun
Microsystems had a big presence with GlassFish,
Open Solaris, NetBeans, MySQL and other offerings.
I delivered 3 talks and participated in 1 talk show:

Friday June 26, 2009
Digital TV-based Banking using GlassFish, NetBeans and MySQL - Ginga community in Brazil
Learn how GlassFish
and NetBeans
helped Ginga community
to build a TV Banking application in Brazil. See a live demo of the
product, it's really exciting!
Why GlassFish ? - They love how NetBeans tooling completely hides the
complexity of what's happening underneath and the ease-of-use with
GlassFish.
Thanks Hugo Lavalle for the interview and good luck with your product!
Technorati: conf
fisl brazil glassfish
story
netbeans
mysql
ginga
digitaltv
banking
Posted by Arun Gupta in General | Comments[4]
|
|
|
|
|
Wednesday June 24, 2009

I presented on "Creating
powerful web applications using GlassFish, MySQL and NetBeans/Eclipse"
as the first talk of FISL 10 yesterday. The room was only partial full
being the first talk of FISL but got packed towards the middle so that
was exciting. The slides are available here.
The key message is that NetBeans
and Eclipse
provide a seamless development/deployment environment for GlassFish.
The several demos shown in the talk are explained at:
Posted by Arun Gupta in General | Comments[7]
|
|
|
|
|
Wednesday June 17, 2009
GlassFish swimming to FISL, Brazil
![]() |
FISL stands for "Forum Internacional Software Livre" in
the Portuguese language and means "International Free Software Forum"
in the English language. The punch line is "A technologia que liberta"
and means "The technology that liberates". This is the biggest event about free software in America and was attended by 7417 participants in 2008. |

Posted by Arun Gupta in General | Comments[10]
|
|
|
|
|
Wednesday April 22, 2009
Offshore monitoring of windfarms using GlassFish - MySQL Users Conference 2009 Day 3
John Powell from eMapSite
stopped by at the Whisper
Suite in MySQL
Users Conference earlier today to talk about his GlassFish
issue. The possible workaround was suggested and then the discussion
became interesting on how GlassFish is used for offshore monitoring of
windfarms and process weather forecasting data. Hear all about it and
watch a flashy demo of their product in this video:
NetBeans,
GlassFish, and MySQL
is their development stack with a "very positive experience"!
Stay tuned for the stories
entry.
And the complete picture album is available at:
Technorati: conf
mysqlconf
mysql
santaclara
glassfish
netbeans
Posted by Arun Gupta in General | Comments[1]
|
|
|
|
| MySQL Users Conference 2009 Day 3 - Cloud Shootout
I arrived at the MySQL
Users Conference just in time for the The
Great Open Cloud Shootout.
| Thorsten | Fully automatbale computing infrastructure, changes the way production scale deployments operate, saves time/cost, increases reliability |
| Chander | Elasiticity is an important aspect, Can "shoot for the moon without shooting foot", accessing a pool of resources which is infinite from an individual/organization perspective |
| Monty | Much like electricity/network bandwidth, applying that same model to computing resources |
| Jeremy | Virtualization is an important piece |
| Lew | Not new technology, rather a new way of delivery. As a developer, provision the application through the code. |
| Monty | It's for you |
| Thorsten | Amazon launched, mostly for geeks. 2007 -> Amazon skeptical and RightScale gets VC funding, 2008 -> some common usage, 2009 -> Top-down from CIOs. Basically everybody, cross-organiation, vertical |
| Mike | Horizontal technology opportunity, starting to see mainstream applications including ISVs/primary line of business, interest/adoption is growing |
| Chander | Definitely growing for ISVs, makes backup sexy, "Even though running a backup company, expected to be entertaining" |
| Jeremy | Power outlets are shaped differently, technology has not matured enough. Next few years standardization will happen. |
| Monty | People will never notice it exists, but able to access the information |
| Prashant | Putting/Sharing the data on cloud |
| Monty | All of a sudden facebook traffic, leverage a collective of people who are already investing in an effort |
| Lew | Cloud computing based on virtualization |
| Mike | More & more enterprises moving in the cloud, gain durability & resilience which was not an option because of a single data center |
| Jeremy | Legacy apps are easiest to move into cloud, they are better understood and can scale easily |
| Prashant | Cloud is the right approach/dream, not there yet. Traditional apps can be moved into cloud. |
| Thorsten | Flexibility in development and tests, DBA clone another slave server with exactly the same setup to test out schema changes |
| Monty | Spin up EC2 instances, run the tests and shut them down ... everything in approx $1. Give it back to the cloud and make it more efficient for the world in general. |
| Lew | We are making it so affordable, cost can be 10% of what it was before. |
| Chander | Performance, a customer requested a refund where they were trying to shove a 1TB in an hour. US is 6Mbps, needs to significantly increase before it can be utilized. |
| Thorsten | Compute needs to move where the data is. |
| Chander | Most businesses will find bandwidth/redundancy limited. Customer always need to customer where not to use cloud and set expectations accordingly |
| Lew | Financially sensitive applications, owning your own data center |
| Chander | Trust and privacy, it's more about education though. Encryption is going tobe a key. |
| Jeremy | Competitiion, unless other companies battle it out and making it easy to to migrate from one service to other, it'll be difficult. Avoid vendor lockin. |
| Mike | Based on open industry standards, no deep rooted concern in the user community |
| Thorsten | Way to operate across different clouds, API is not the most important level. What is a server ? Can I hibernate it, mount it, how much storage volume is allowed, cross-data center boundary are a better abstraction. |
| Lew | Very early to lock the standards, everybody is currently in a stage of experiementation |
| Monty | Potential downside to premature standardization, too early to jump to standards |
| Chander | Open standards are a definite key to success. S3 fostered innovation. |
| Thorsten | S3 is a good standard but not an open API. It will be doubly nice if it's "free" or "open" or whatever the word is. |
| Mike | Standards dont really matter if the performance cannot be met. When innovating at a rapid rate, it' difficult to make everybody agree upon standards. |
| Lew | At least publish the API where everybody can use them. |
| Chander | Showing backup to Sun cloud, Sun has S3 compatible APIs, also compatible to WebDAV. |
| Monty | You can |
| Mike | Very unique and compelling business opportunity. Amazon Dev Pay: Buy infrastructure on demand, setup your software on AMI, set your own price and then customers can use it, "Software as a Innuity" |
| Chander | Traditional backup vendors will be worried. |
| Prashant | Database on the cloud |
| Lew | Seeing an explosion in the amount of data/compute required, accordingly analytics. Tremendous amount of opportunity when Cassandra & Drizzle are cloud-enabled. |
| Mike | More ISVs in the cloud. |
| Jeremy | How to do performance tuning and optimizations in cloud, do that for major cloud infrastructure. |
| Monty | Freedom to work from anywhere, don't need to be physically at the datacenter, enables multinational consulting |
| Chander | When more clouds become available, it'll be explosion which will happen later this year. |
| Jeremy | CPU time in terms of use, storage centric clouds pay for integrity |
| Lew | Creating Data centers with loading docks. |
| Monty | Paying for CPU cycle, like mainframe model. |
| Thorsten | Cloud is like mainframe but very elastic. |
| Chander | Billing is not a challenge, storage clouds are better because of pricing, compute is challenging |
| Thorsten | Flexibility of moving to the next volume, master, slave makes is very refreshing |
| Monty | Start out thinking M x N problems, never think about one database instance in cloud, there will be X > 1 |
Posted by Arun Gupta in General | Comments[6]
|
|
|
|
|
Tuesday April 21, 2009
MySQL Users Conference 2009 Day 2
I presented on Creating
Quick and Powerful Web Applications with MySQL, GlassFish, and NetBeans.
The key messages conveyed during the preso are:
Posted by Arun Gupta in General | Comments[4]
|
|
|
|
|
Today's Page Hits: 2084
Total # blog entries: 994
| « November 2009 | ||||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
1 | 2 | 4 | 6 | 7 | ||
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | |||||
| Today | ||||||