Ibatis prints all the SQL statements executed at the underlying layer.

Source: Internet
Author: User

When using ibatis as the persistent layer, it is very helpful for debugging programs to know exactly the SQL statements executed.

Add the printed code to the file com. ibatis. sqlmap. Engine. Scope. requestscope. java.

The source code is as follows:

/*
* Copyright 2004 Clinton begin
*
* Licensed under the Apache license, version 2.0 (the "License ");
* You may not use this file before t in compliance with the license.
* You may obtain a copy of the license
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* Distributed under the license is distributed on an "as is" basis,
* Without warranties or conditions of any kind, either express or implied.
* See the license for the specific language governing permissions and
* Limitations under the license.
*/
Package com. ibatis. sqlmap. Engine. scope;

Import com. ibatis. sqlmap. Engine. Mapping. Parameter. parametermap;
Import com. ibatis. sqlmap. Engine. Mapping. Result. resultmap;
Import com. ibatis. sqlmap. Engine. Mapping. SQL. SQL;
Import com. ibatis. sqlmap. Engine. Mapping. Statement. mappedstatement;

Import java. SQL. resultset;
Import java. util. Map;
Import java. util. hashmap;

Import org. Apache. commons. Logging. log;
Import org. Apache. commons. Logging. logfactory;

/**
* Request based implementation of scope Interface
*/
Public class requestscope extends baseline {

Private Static final log = logfactory. getlog (requestscope. Class );
// Used by any
Private sessionscope session;
Private errorcontext;
Private mappedstatement statement;
Private parametermap;
Private resultmap;
Private SQL;

// Used by dynamicsql
Private parametermap dynamicparametermap;
Private string dynamicsql;

// Used by N + 1 select Solution
Private resultset;
Private map uniquekeys;
Private Boolean rowdatafound;
Private string currentnestedkey;

/**
* @ Return returns the currentnestedkey.
*/
Public String getcurrentnestedkey (){
Return currentnestedkey;
}

/**
* @ Param currentnestedkey the currentnestedkey to set.
*/
Public void setcurrentnestedkey (string currentnestedkey ){
This. currentnestedkey = currentnestedkey;
}

/**
* Default constructor
*/
Public requestscope (){
Errorcontext = new errorcontext ();
Reset ();
}

/**
* Get the request's error Context
*
* @ Return-the request's error Context
*/
Public errorcontext geterrorcontext (){
Return errorcontext;
}

/**
* Get the Session of the request
*
* @ Return-the session
*/
Public sessionscope getsession (){
Return session;
}

/**
* Set the session for the request
*
* @ Param session-the new session
*/
Public void setsession (sessionscope session ){
This. Session = session;
}

/**
* Get the statement for the request
*
* @ Return-the statement
*/
Public mappedstatement getstatement (){
Return Statement;
}

/**
* Set the statement for the request
*
* @ Param statement-the statement
*/
Public void setstatement (mappedstatement statement ){
This. Statement = statement;
}

/**
* Get the parameter map for the request
*
* @ Return-the parameter Map
*/
Public parametermap getparametermap (){
Return parametermap;
}

/**
* Set the parameter map for the request
* @ Param parametermap-the New Parameter Map
*/
Public void setparametermap (parametermap ){
This. parametermap = parametermap;
}

/**
* Get the result map for the request
*
* @ Return-the result map
*/
Public resultmap getresultmap (){
Return resultmap;
}

/**
* Set the result map for the request
*
* @ Param resultmap-the result map
*/
Public void setresultmap (resultmap ){
This. resultmap = resultmap;
}

/**
* Get the SQL for the request
*
* @ Return-the SQL
*/
Public SQL getsql (){
Log.info ("getsql () return SQL:" + SQL );
Return SQL;
}

/**
* Set the SQL for the request
*
* @ Param SQL-the SQL
*/
Public void setsql (SQL ){
This. SQL = SQL;
}

/**
* Get the dynamic parameter for the request
*
* @ Return-the dynamic parameter
*/
Public parametermap getdynamicparametermap (){
Return dynamicparametermap;
}

/**
* Set the dynamic parameter for the request
*
* @ Param dynamicparametermap-the dynamic parameter
*/
Public void setdynamicparametermap (parametermap dynamicparametermap ){
This. dynamicparametermap = dynamicparametermap;
}

/**
* Get the dynamic SQL for the request
*
* @ Return-the dynamic SQL
*/
Public String getdynamicsql (){
Log.info ("getdynamicsql () return dynamicsql:" + dynamicsql );
Return dynamicsql;
}

/**
* Set the dynamic SQL for the request
* @ Param dynamicsql-the dynamic SQL
*/
Public void setdynamicsql (string dynamicsql ){
This. dynamicsql = dynamicsql;
}

Public resultset getresultset (){
Return resultset;
}

Public void setresultset (resultset ){
This. resultset = resultset;
}

Public map getuniquekeys (resultmap map ){
If (uniquekeys = NULL ){
Return NULL;
}
Return (MAP) uniquekeys. Get (MAP );
}

Public void setuniquekeys (resultmap map, map keys ){
If (uniquekeys = NULL ){
Uniquekeys = new hashmap ();
}
This. uniquekeys. Put (MAP, keys );
}

Public Boolean isrowdatafound (){
Return rowdatafound;
}

Public void setrowdatafound (Boolean rowdatafound ){
This. rowdatafound = rowdatafound;
}

Public void reset (){
Super. Reset ();
Errorcontext. Reset ();
Session = NULL;
Statement = NULL;
Parametermap = NULL;
Resultmap = NULL;
SQL = NULL;
Dynamicparametermap = NULL;
Dynamicsql = NULL;
Resultset = NULL;
Uniquekeys = NULL;
Rowdatafound = true;
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.