Amol’s Weblog

Things, the way I see them…

Archive for August 31st, 2007

Configure Abator on eclipse

Posted by Amol Chaudhari on August 31, 2007

So we are thinking of using iBatis on our project… And our team is very excited about it…

We decided to play around with iBatis to get some hands-on experience.. and after some Googling, i found out that Abator is the tool that will help us get started quickly on the iBatis road…

But when i googled for steps to configure Abator on eclipse, i did not find clear steps. Though the documentation and Adam Smith’s blog Introduction to iBatis helped me a lot to configure Abator. I just want to reconcile all the information at the single place.

So here we go….

1. Download the abator.jar from here. The version i used is “abator-1.0.0-238″.

2. Download the iBatis jars from here. The version i used is “2.2.0.638″

3. Make sure that you have the database driver jars. I am using DB2 (Version 8.1.7.445) to test and the jar files are: db2jcc.jar and db2jcc_license_cu.jar

4. Create a simple java project in eclipse.

5. Add the following directories to the project.

src – will contain Abator generated source

lib – will contain the necessary jars

config – will contain some configuration files needed for Abator.

6. Add the abator.jar, iBatis jars and database related jars to the lib directory.

7. Add all these jars on the project build path by right clicking the Project > select properties > select Java Build Path > Libraries on RHS > Add Jars and select all the jars.

8. Now in the “config” folder add two files: abatorConfig.xml and configuration.properties.

abatorConfig.xml:



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE abatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN"

  "http://ibatis.apache.org/dtd/abator-config_1_0.dtd"><abatorConfiguration>

  <abatorContext>

    <jdbcConnection driverClass="${database.driver}"

        connectionURL="${database.url}"

        userId="${database.username}"

        password="${database.password}">

      <classPathEntry location="${database.driver.jar.path}" />

   <classPathEntry location="${database.driver.license.jar.path}" />

    </jdbcConnection>

<javaModelGenerator targetPackage="${ibatis.generated.source.model.pkg}"

    	targetProject="src">

    	<property name="trimStrings" value="true" />

    </javaModelGenerator>

<sqlMapGenerator targetPackage="${ibatis.generated.source.sqlmap.pkg}"

    	targetProject="src">

    	<property name="trimStrings" value="true" />

    </sqlMapGenerator>

<daoGenerator targetPackage="${ibatis.generated.source.dao.pkg}"

    	targetProject="src" type="IBATIS">

    </daoGenerator>

<table schema="ABC" tableName="TBLSTUDENT" />

</abatorContext>

</abatorConfiguration>

And this is my configuration.properties file:


database.driver=com.ibm.db2.jcc.DB2Driver
database.url=jdbc:db2:AMOL
database.username=db2inst
database.password=db2inst
database.driver.jar.path=lib/db2jcc.jar
database.driver.license.jar.path=lib/db2jcc_license_cu.jar
ibatis.generated.source.model.pkg=com.ibatis.model
ibatis.generated.source.sqlmap.pkg=com.ibatis.dao.sqlmap
ibatis.generated.source.dao.pkg=com.ibatis.dao

9. Add a build.xml file to your project:

build.xml:



<project name="AbatorTest" default="generate-ibatis" basedir=".">

	<property name="abator.config.dir" 		value="config"/>
	<property name="lib.dir" 		value="lib" />

	<property file="${abator.config.dir}/configuration.properties"/>

	<path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>

	<target name="generate-ibatis" description="Generate iBatis Code">
		<taskdef name="abator"
		      classname="org.apache.ibatis.abator.ant.AbatorAntTask"
						classpathref="classpath"/>
		<abator overwrite="true" configfile="${abator.config.dir}/abatorConfig.xml" verbose="true" >
			<propertyset>
				<propertyref name="ibatis.generated.source.model.pkg"/>
				<propertyref name="ibatis.generated.source.sqlmap.pkg"/>
				<propertyref name="ibatis.generated.source.dao.pkg"/>
				<propertyref name="database.driver" />
				<propertyref name="database.url" />
				<propertyref name="database.username" />
				<propertyref name="database.password" />
				<propertyref name="database.driver.jar.path" />
				<propertyref name="database.driver.license.jar.path" />
			</propertyset>
		</abator>
	</target>
</project>

10. Thats it… you are done with the setup.
11. Now to generate the iBatis code for any table you simply need to put the table name in the abatorConfig.xml.. something like tableName=”TBLSTUDENT” – i have already put.

12. Now tweak around the generated code as per your requirements…

Posted in Java | 2 Comments »

Planning to start all over again…

Posted by Amol Chaudhari on August 31, 2007

Ok.. Its been almost an year since i last posted on my blog… And i don’t have any excuses for this…

Anyway, i have once again decided to start blogging afresh.. and this time i am planning to be a bit consistent… :-)

And who provided the much needed PUSH? well its my boss.. You know sometimes good things do happen to you because of bosses.. :-)

Posted in First Ones | Comments Off