Friday, June 25, 2010

Great day for Indians

Today, like many indians i feel proud because today Queen's Baton reaching India. Wow what a great day for me and all indians.It is exactly a 100 day countdown for the first ever Commonwealth Games being hosted by India.

India, which will be hosting the prestigious international sporting event in the national capital, received the baton from Pakistan. Queen's Baton Relay, which has traveled across the world after it was launched by Queen Elizabeth-II at Buckingham Palace in Oct 2009, arrived in Amritsar through the Wagah Border.

I also hope like others that this kind of events would heal the strained relationship between India and Pakistan as well as bolster the ties between all countreis.

Thursday, June 24, 2010

Short Introduction GWT (Google Web ToolKit)

GWT:

In last couple of months, i am working on GWT (Google Web ToolKit). I am not great fan of this techonology because i got too many problems.

It uses well-known Remote Procedure Call (RPC) principles implemented by a generic servlet (RemoteServiceServlet), which you can specialize for your own needs. You also can use JavaScript Object Notation (JSON) as the data interchange format for your HTTP messages sent with the GWT HTTPRequest class.
Way of creating the application.
1)One way just install GWTSDK and create application by using following command
webappcreator -out projectname packagename.projectname
It creates structure similar to web applciation.
src:
--packagename.projectname.gwt.xml(This file contains information about entry point and inherited modules)
--packagename.client
--projectname.java (By default this is entry class and it runs while we run this applciation.)
--GreetingServiceAsync.java ( An interface with methods)
--GreetingService.java ( An interface which extends RemoteService)
--packagename.server
--GreetingServiceImpl (extends RemoteServiceServlet implements GreetingService )
This class overrides the methods of GreetingService
war:
--WEB-INF (with classes, lib folders and web.xml (similar to normal j2ee web application))
--projectname.html and .css
--build.xml (for detais of build.xml read ANT in detail)

In next post,I would like to discuss these files in detail
Now import this project to eclipse workspace ,build required jar (all required jar --inside bin of GWT folder or parallel to webappcreator) and run as JAVA Application (Hosted Mode)

2) Second way install plugin for GWT on eclipse. You will get 3 icons. One blue button ('g' is written on it) and other with red ('G' is written)and etc
Now just click on blue button and you got screen where you write project name and package name. (Uncheck Google App Engine for Now)
You project hasbeen created. If you want to use extra jar ,then build them.Some extra folders are created like test and test classes ,shared etc. Rest similar to above.



Problem: Less control over the client-side code of your application because it’s eventually generated by the GWT compiler.GWT provides a compiler that translates the Java code on the client side into JavaScript and DHTML.So you can use only few JAVA API's (lan and util).

Personally i got these error:
1)When i create war file, i am not able to create it properly while in normal web application i can create easily. (according to me This error is not because of GWT, but little bit tough for me..:( ) I am still with this error.
2)On changing platforms (Windows to linux and vice-versa), some functions doesn't support. So it requires extra time.

Maybe i am new of this tecgonology that's why i am getting these problem or it has.
But it creates good application where i want to use AJAX. Much dynamic site and better look can be created using this techonology.

Jar Needed for it:
gwt-dev-windows.jar or gwt-dev-linux.jar: Programming tools including the compiler. The embedded Web browser provided by GWT is platform-dependent.
gwt-user.jar: The GWT runtime.
gwt-servlet.jar: The jar to deploy on your application server with the code generated by the GWT compiler. It contains the RemoteServiceServlet.

Any suggestion or solution of problem. Plz tell me.

Thanks!!

Saturday, June 19, 2010

A basic application for iBatis use

Last month i got chance to learn some new techonologies like GWT (Google Web ToolKit) and iBatis. Firstly i would like to demonstrate application on iBatis. In upcoming posts, i would cover GWT.

I found iBatis very useful because With Ibatis I find myself getting the Job done faster, I create any POJO any set of tables, and I link them, much flixability in that field, but little extra work, building Queries and managing Maps (Little time required here). I never worked or got chance to learn hibernate.So bit difficult for me to tell that which is much better.But anyway here i developed a small application which only tells you that how you can use iBatis in your projects.

Download iBatis.jar
http://ibatis.apache.org/javadownloads.html

iBatis:

Step1: create SQLMapConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
<settings useStatementNamespaces="true"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL"
value="jdbc:mysql://localhost:3306/mhrddemo"/>
<property name="JDBC.Username" value="root"/>
<property name="JDBC.Password" value="mysql"/>
</dataSource>
</transactionManager>
<sqlMap resource="DataBean.xml"/>
</sqlMapConfig>

you can create property file and then use that values in this config file.

2)create another xml where you write query:
DataBean.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="Contact">
<!--- Showing all data of table -->



<!--- Showing all data of table -->
<select id="getAll" resultClass="ibdeep.DataBean">
select university_id,entity_type,entity_description from entity_type
</select>

<resultMap id="result" class="ibdeep.DataBean">
<result property="university_id" column="university_id"/>
<result property="entity_type" column="entity_type"/>
<result property="entity_description" column="entity_description"/>

</resultMap>
<select id="getById" resultMap="result">
select * from entity_type where entity_type=#entity_type#
</select>


</sqlMap>

3) create a java file which has getter and setter of table fields or properties.

package ibdeep;

class DataBean
{

private String university_id;

private String entity_type;

private String entity_description;

public DataBean(){

}

public DataBean(String university_id,String entity_type,String entity_description){

this.university_id=university_id;
this.entity_type=entity_type;
this.entity_description=entity_description;

}

public String getUniversity_id(){

return university_id;

}

public void setUniversity_id(String university_id){

this.university_id=university_id;

}

public String getEntity_type(){

return entity_type;

}

public void setEntity_type(String entity_type){

this.entity_type=entity_type;

}

public String getEntity_description(){

return entity_description;

}

public void setEntity_description(String entity_description){

this.entity_description=entity_description;

}

}

Step 4): Create another java file
package ibdeep;

import com.ibatis.common.resources.Resources;

import com.ibatis.db.sqlmap.SqlMap;

import com.ibatis.sqlmap.client.*;

import java.io.Reader;

public class SqlMapManager {
private static SqlMap sqlMap = null;
static SqlMapManager smm;

public static SqlMapClient getSqlMapClient() {
try {
Reader reader = Resources
.getResourceAsReader("ibdeep/SqlMapConfig.xml");
SqlMapClient sqlMapper = SqlMapClientBuilder
.buildSqlMapClient(reader);
reader.close();

return sqlMapper;
} catch (Exception e) {
System.out.println("Map Exception");
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}


public void setSqlMap(SqlMap sqlMap) {
SqlMapManager.sqlMap = sqlMap;
}


public static SqlMap getSqlMap() {
return sqlMap;
}
}

Step 5) create properties file.you can use it.You can pass these values directly

url=jdbc:mysql://localhost:3306/mhrddemo
login=root
password=mysql

Step 6) Finally create java file which uses

package ibdeep;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import java.io.*;
import java.sql.SQLException;
import java.util.*;

class IBatisExample
{
public static void main(String[] args)
throws IOException,SQLException{
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlMapClient sqlMap =
SqlMapClientBuilder.buildSqlMapClient(reader);

//Output all contacts

System.out.println("All Contacts");
List<DataBean> contacts = (List<DataBean>)
sqlMap.queryForList("Contact.getAll",null);
DataBean contact = null;
for (DataBean c : contacts) {
System.out.print(" " + c.getUniversity_id());
System.out.print(" " + c.getEntity_type());
System.out.print(" " + c.getEntity_description());
contact = c;
System.out.println("");
}
}
}

I hope it is useful.