Porting Pleso framework Demo to Netbeans and MySQL

draindecorumΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 8 χρόνια και 11 μήνες)

592 εμφανίσεις

Porting Pleso framework Demo to Netbeans and MySQL
Author:
E. Ozkan
Company:
OzTech IT Consultants
Email:

eozkan@oztech.eu
Date:
30-Jan-2009
1.
Scope
We are planning to use GWT to develop GUIs for a database application. Logically, we have focussed

on CRUD applications. We identified a few candidates for our purpose and Pleso framework was one

of them. Since we are using Netbeans and MySQL, we decided to port the demo application to our

environment. This document summarizes our experience.
2.
Environment

NetBeans IDE 6.5,

Java 1.6.0 Update 11,

MySQL Server 5.1,

GWT 1.5.3

Pleso Framework 0.2 beta

Ibatis 2.3.3.720
It is also assumed that the
gwt4nb
plugin has been installed into the
Netbeans IDE
.
3.
Migration Steps
Select
File->New Project …

from the Netbeans main menu.
Provide a project name “
gwt_pleso_mysql_demo
” and click on the
Next
button.
Use defaults for server and settings and click on the
Next
button:
Select “
Google Web Toolkit
” frameworks
option and click on the
Finish
button:
Create a new
Java Package
under
Source Packages
:
Provide name of the java package:
net.pleso.auth
:
Copy source files from the original demo package (drag-drop from windows explorer). There is a one-
to-one mapping between folders containing source code and netbeans packages. For example, contents

of the
src\net\pleso\auth
folder should be copied into the
net.pleso.auth
package. Repeat same

procedure for the remaining packages
net.pleso.demo
(without folders)
,
net.pleso.demo.server

and

net.pleso.demo.client
.
The files
demo.html
and
style.css
in the folder

src\net\pleso\demo\public
must be copied into the
Web Pages
:
Edit the
web.xml
file in the
Configuration Files
and copy servlet definitions and mappings from the file

web.xml
in the folder
src\net\pleso\demo:
<servlet>
<servlet-name>AuthService</servlet-name>
<servlet -class>net.pleso.demo.server.auth.AuthServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AuthService</servlet-name>
<url-pattern>/auth</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>BankService</servlet-name>
<servlet-class>net.pleso.demo.server.bank.BankServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BankService</servlet-name>
<url-pattern>/bank</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>OperationService</servlet-name>
<servlet-class>net.pleso.demo.server.operation.OperationServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>OperationService</servlet-name>
<url-pattern>/operation</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ClientService</servlet-name>
<servlet-class>net.pleso.demo.server.client.ClientServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ClientService</servlet-name>
<url-pattern>/client</url-pattern>
</servlet-mapping>
Add Required Libraries
Add libraries iBatis, Pleso framework UI & Core

and
MySQL Java Connector by using
Add

JAR/Folder …
4.
Clean the Project
Problem
Delete two files which are not required any more:
welcomeGWT.html
and

demoEntryPoint.java
.
Source
Migrated Project
Packages
Web Pages
net.pleso.demo.client
Files
welcomeGWT.html

demoEntryPoint.java
.
Solution
Locate files; right click and, then, select
Delete
.
See the following figure.
5.
Changes
5.1.
Demo Package Issues
These correspond to the issues that have been identified while migrating the Pleso demo:
Problem
GWT compiler does compile if there are single quotes in messages.
Source
gwt-pf-ui.jar
Package
net.pleso.framework.client.localization
File
messages.properties
Solution
Change all "can't" with "can not" (by using 7-zip).
(Re)archive the library gwt-pf-ui.jar
Problem
There is no column named
“is_confirmed”
in the table
“operation”
.
Source
Demo Package (gwt-pf-demo1.tar.gz)
Package
Not Applicable
File
demo_sql.sql
Solution
MySQL database creation script contains this column.
However, add a database column “is_confirmed” .
5.2.
Netbeans Related Changes

Problem
There is no class named “
AuthServiceImpl”
which is referenced in the web.xml:
<servlet-class>net.pleso.demo.server.auth.AuthServiceImpl
</servlet-class>
Source
Netbeans migration
Package
Configuration Files
File
web.xml
Solution
Change
AuthServiceImpl
to
DemoAuthServiceImpl:
<servlet-class>net.pleso.demo.server.auth.DemoAuthServiceImpl
</servlet-class>
Problem
URL pattern /auth, /bank, /operation and /client should be preceded by the GWT

output directory (gwt.output.dir=/net.pleso.demo.demo).
Source
Netbeans migration
Package
Configuration Files
File
web.xml
Solution
Perhaps changing the GWT output directory is also a valid solution. However, I

preferred to change four url patterns such as:
<url-pattern>/auth</url-pattern>
to

<url-pattern>/net.pleso.demo.demo/auth</url-pattern>

Problem
Start web page should be
demo.html
(instead of
welcomeGWT.html
).
Source
Netbeans migration
Package
Configuration Files
File
web.xml
Solution
Change the welcome file to
demo.html
:
<welcome-file-list>
<welcome-file>demo.html</welcome-file>
</welcome-file-list>
Problem
Refer to the java script created by GWT compiler in the start WEB page.
Source
Netbeans migration
Package
Web Pages
File
demo.html
Solution
Within the body tag of the
demo.html; c
hange
<script language="javascript" src="gwt.js">
</script>
to

<script language="javascript"
src="net.pleso.demo.demo/net.pleso.demo.demo.nocache.js">
</script>
Problem
GWT compiler gives an error message for Constants class:

[ERROR] class net.pleso.demo.client.localization.Constants_ and

Constants are both potential default classes for interface

com.google.gwt.i18n.client.Constants.
Source
Netbeans migration
Package
net.pleso.demo.client.localization
File
Constants.java
Solution
Change
Constants.java
to
AppConstants.java
by using Refactor->Rename.
Rename
Constants.properties
to
AppConstants.properties
.
Problem
Add GWT and Pleso inheritance.
Source
Netbeans migration
Package
net.pleso.demo
File
demo.gwt.xml
Solution
Replace
<entry-point class="net.pleso.demo.client.demoEntryPoint"/>
With
<!-- Pleso auth library. -->
<inherits name='net.pleso.auth.plesoauth'/>
<!-- Pleso gwt framework library. -->
<inherits name='net.pleso.framework.plesoframework'/>
<!-- i18n. -->
<inherits name="com.google.gwt.i18n.I18N" />
<!-- Specify the app entry point class. -->
<entry-point class='net.pleso.demo.client.demo'/>
Problem
The database column
is_confirmed
can be null.
Source
Netbeans migration
Package
net.pleso.demo.server.operation
File
OperationServiceImpl.java
Solution
Comment out the following two lines in the
method public void update(Operation

operation) throws BaseException
:
//if (operation.getIs_confirmed().booleanValue())
//
throw new BaseException("test");
5.3.
MySQL Related Changes

Problem
MySQL stored functions can not return a set or table. MySQL stored procedures can

execute a query but they can not be called in the
FROM
clause of
SELECT
statement.
Source
Migrated Project - Ibatis Configuration
Package
net.pleso.demo.server.client
File
client.xml
Solution
Only feasible solution that I found is using dynamic queries within the sql mapping

file (Please note that same solution applies to
selectCountClient
):
<select id="selectClient" resultMap="ClientResult" parameterClass="SelectParams" >
Select * From CLIENT_VIEW
<dynamic prepend="WHERE">
<isNotNull prepend="AND" property="searchRow.cl_id">
CL_ID = $searchRow.cl_id$
</isNotNull>
<isNotNull prepend="AND" property="searchRow.cl_bank_id">
CL_BANK_ID = $searchRow.cl_bank_id$
</isNotNull>
<isNotNull prepend="AND" property="searchRow.cl_name">
CL_NAME LIKE '%$searchRow.cl_name$%'
</isNotNull>
<isNotNull prepend="AND" property="searchRow.bank_name">
BANK_NAME LIKE '%$searchRow.bank_name$%'
</isNotNull>
<isNotNull prepend="AND" property="searchRow.cl_sex">
CL_SEX LIKE '%$searchRow.cl_sex$%'
</isNotNull>
<isNotNull prepend="AND" property="searchRow.cl_money_start">
CL_MONEY BETWEEN $searchRow.cl_money_start$ AND $searchRow.cl_money_end$
</isNotNull>
<isNotNull prepend="AND" property="searchRow.cl_birthday_start">
( CL_BIRTHDAY
BETWEEN STR_TO_DATE('$searchRow.cl_birthday_start$', '%d-%m-%Y %H:%i')
AND STR_TO_DATE('$searchRow.cl_birthday_end$', '%d-%m-%Y %H:%i') )
</isNotNull>
</dynamic>
<isNotEmpty property="orderByColumnName">
order by $orderByColumnName$ $orderByDirectionString$
</isNotEmpty>
limit #limit# offset #offset#
</select>
Problem
Database connection parameters should be adapted to MySQL server
Source
Migrated Project – database connection
Package
net.pleso.demo.server
File
connection.properties
Solution
Use the following parameters (typical parameters):
host = localhost
port = 3306
database = pfdemo
Problem
IBatis should use MySQL java connector.
Source
Migrated Project - Ibatis Configuration
Package
net.pleso.demo.server
File
SqlMapConfig.xml
Solution
Use the following for MySQL connection:
<transactionManager type="JDBC" commitRequired="true">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL" value="jdbc:mysql://$
{host}:${port}/${database}"/>
<property name="JDBC.Username" value="${login}"/>
<property name="JDBC.Password" value="${password}"/>
</dataSource>
</transactionManager>
6.
Compilation Issues

Problem
GWT compiler gives out of memory while compiling the application.
Source
Migrated project
Package
Not Applicable
File
Not Applicable
Solution
If you get out of memory error from the GWT compiler, add
maxmemory
:
<java classpath="${javac.classpath}:${src.dir}" failonerror="true"
classname="com.google.gwt.dev.GWTCompiler" fork="true"

maxmemory="256M"
>
7.
Create Demo Database

Select
Services
tab; select your MySQL Server; use right mouse click and select
Create Database...
:
Provide database name (e.g.,
pfdemo
) and click on the
OK
button:
Select connection created for new database; use right mouse click and select
Connect...
:
Provide database user name and password and click on the
OK
button:
Use right mouse click and select
Execute Command …
:
Copy the content of the file
demo_mysql.sql
into the SQL command sheet and click on the “
Run SQL


icon:
After successful execution you should see four tables and one view: