Migration of existing samples database "HSQLDB" to "MySQL"
Sample tutorial: ZKPetshop2
This sample is from the Book: "ZK™: Ajax without JavaScript™ Framework" chapter8.
But this is tutorial is old versioned because fisheye component in index.zul is old.
So I downloaded from ZK Community
Here we select ZK Forge on SF.net
From this SourceForge.net Repository,we download zkPetShop2.tar.gz
Completed NetBeans Project is here.
Here are change point from original.
・ web.xml
from
<resource-ref>
<res-ref-name>jdbc/hsql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
to
<resource-ref>
<description>Visual Web generated DataSource Reference</description>
<res-ref-name>jdbc/Petshop_MySQL</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
- META-INF/content.xml
from
<Resource name="jdbc/hsql" username="sa" password=""
url="jdbc:hsqldb:file:/hsqldb/petshop"
auth="Container" defaultAutoCommit="false"
driverClassName="org.hsqldb.jdbcDriver" maxActive="20"
timeBetweenEvictionRunsMillis="60000"
type="javax.sql.DataSource"/>
to
<Resource name="jdbc/Petshop_MySQL" username="root" password="master"
url="jdbc:mysql://localhost:3306/Petshop"
auth="Container" defaultAutoCommit="false"
driverClassName="com.mysql.jdbc.Driver" maxActive="20"
timeBetweenEvictionRunsMillis="60000"
type="javax.sql.DataSource"/>
- SellerWindow.java
from
((Image) getFellow("picture")).setContent(null);
to
((Image) getFellow("picture")).setContent((org.zkoss.image.Image)null);
- src/hibernate.cfg.xml
from
<!-- connnect via JNDI -->
<property name="hibernate.connection.datasource">java:comp/env/jdbc/hsql</property>
<!-- Database connection settings
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost/petstore</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
-->
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
to
<!-- connnect via JNDI -->
<property name="hibernate.connection.datasource">java:comp/env/jdbc/Petshop_MySQL</property>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/Petshop</property>
<property name="connection.username">root</property>
<property name="connection.password">master</property>
<!-- -->
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
- In NetBeans Project,addition directory "setup" is needed in project root
to create "JNDI - Connection Pool Settings" automatically.
This setups jdbc connection pool and JNDI information in Application Server.
sun-resources.xml is exists in this directory:
[WEB-ROOT]/setup/sun-resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="jdbc/Petshop_MySQL" object-type="user" pool-name="mysql_Petshop_rootPool"/>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="mysql_Petshop_rootPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="User" value="root"/>
<property name="Password" value="master"/>
<property name="serverName" value="localhost"/>
<property name="portNumber" value="3306"/>
<property name="databaseName" value="Petshop"/>
<property name="URL" value="jdbc:mysql://localhost:3306/Petshop"/>
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
</jdbc-connection-pool>
</resources>