Monday, July 4, 2011

CRUD Operation in iBatis

1. To return a single value in iBatis Use "queryForObject"

Eg: select userName from user where user_id=2;

2. To return a set of Values in iBatis use "queryForList"

Eg: select * from user

3.Update Query goes here

4. Delete query goes here

5. Insert query goes here

Inser Query



SELECT SEQ_ID.NEXTVAL AS ID FROM DUAL

INSERT INTO User(
userName
)VALUES(
#userName:VARCHAR#
)


From SQL MAP DAO
testVO.setUserName(testVO.getUserName);
insert("createUser", testVO);

Simple Select Query with no Filters

1. Create a Valued Object Which contains the Column of Table (Simple Getter & Setter)

Eg:

TestVO.java

private String userName;

public final String getUserName() {
return userName;
}

public final void setUserName(String userName) {
this.userName= userName;
}

2. Refer this VO in the defined XML File which has the DB related Queries



3.



4.
Note : Here the Parameter calss test contains null .
public List getuserList() {
return queryForList("getUsersList", null);
}

Thursday, June 30, 2011

Implementation Class

Programming Languages Core Java, J2EE- EJB 3.0,Servlets, JSP, JDBC,JSTL
Frameworks Struts Framework, Apache Beehive Framework
Databases Oracle, MySQL 5.0, MS SQL Server 2005
Scripting Languages HTML, XML,XSL, JavaScript, XSD, JaXB
ORM Hibernate, Java Persistence API
Tools and IDEs Net beans 6.8, Eclipse IDE, WebLogic Workshop, SQL Developer, TOAD
Application Servers / Web Servers WebLogic Application Server, Jboss Application Server, Glassfish Application Server and Tomcat web server
Web Services REST Services, JaX WS, EJB WS
Portal Aqua logic User Interaction, Aqualogic pages and publisher, Liferay


package com.pepsico.pcna.ims.dao;

import org.apache.log4j.*;
import com.ibatis.dao.client.*;
import com.pepsico.pcna.ims.AppGlobals;
import com.pepsico.pcna.ims.dao.iface.*;
import com.pepsico.pcna.ims.util.*;
import com.pepsico.pcna.ims.valueobject.*;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;

public class GamePlanSqlMapDao extends BaseSqlMapDao implements GamePlanDao {
private Logger logger = null;

/**
*
* @param daoManager
* DaoManager
*/
public GamePlanSqlMapDao(DaoManager daoManager) {
super(daoManager);
logger = Logger.getLogger(getClass());
}



/**
* Get the game details for the view page.
*/
public GamePlanVO getGamePlan(GamePlanVO gamePlanVO) {
logger.debug("view game plan starting");
gamePlanVO = (GamePlanVO) queryForObject("getGamePlan", gamePlanVO);
patchGameVOFields(gamePlanVO);
logger.debug("view game plan ending");
return gamePlanVO;
}

/**
* Update the game plan.
*/
public void finalizeGamePlan(GamePlanVO GamePlanVO) {
update("finalizeGamePlan", GamePlanVO);
}




/**
* insert the file attachments for gameplan.
*/
public void insertGamePlanAttach(GamePlanVO gamePlanVO) {
insert("insertGamePlanAttach", gamePlanVO);
}

/**
* Delete the game plan attachments.
*/
public void deleteGamePlanAttach(String fileID) {
try {
delete("deleteGamePlanAttach", fileID);
} catch (SQLException e) {
logger.error("Exception occured while deleting attachment" + e);
}
}

/**
* Archive game plans.
*/
public void archiveGamePlans() {
// Update GamePlans status from Active 'A' or Draft to Archived 'H'
// after 1 year from Start date.
update("archiveGamePlans", null);
}

DAO.xml



PUBLIC "-//iBATIS.com//DTD DAO Configuration 2.0//EN"
"http://www.ibatis.com/dtd/dao-2.dtd">






value="sql-map-config.xml" />


implementation="com.test.dao.TestSqlMapDao"/>




SQL MAP CONFIG








cacheModelsEnabled="true"
enhancementEnabled="true"
maxSessions="64"
maxTransactions="8"
maxRequests="128"/>










database.properties

####################################
# Database Connectivity Properties
####################################

driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@metasun1:1521:metasun1
username=pc_dealcs
password=xnsnds
jndiname=jdbc/ims