aspose file tools*
The moose likes Object Relational Mapping and the fly likes How to retrieve metadata in ibatis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to retrieve metadata in ibatis" Watch "How to retrieve metadata in ibatis" New topic
Author

How to retrieve metadata in ibatis

Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
Hello all,
I am retrieving a hashmap out of ibatis.
However the map does not give me metadata information.

Is there a way to retrieve the metadata(eg.column names) through ibatis.

Thanks,
Viidhya
Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
Well.
I found the solution.
have to use the TypeHandlerCallback.

Thanks.
Rajesh Kumar S
Greenhorn

Joined: Apr 28, 2011
Posts: 3
Hi Vidhya,

Please post me the way and code for retrieving metadata using iBatis. I'm battling regarding same for so many days.Thanks in Adv...:-)

I am using a Query "Select * from MyTable" . Do you know how to retrieve metadata from the same using iBatis . Result may contain multiple results (rows)
Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
Rajesh,

The class you need is : TypeHandlerCallBack.

I created a ResultSetHandlerCallBack class which extends the above class.


I then have a ResultSetMap class which uses the above call back class.


This is how I use it in the dao.


The ResultSetHandlerCallBack class puts the results in the form of multiple maps with colName and value as pairs. Then the row map is added to a rows list.
The ResultSetMap is needed as this class helps to get the handle for the metadata info we populated using the Handler class.

I am sure this will be enough for you.
Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
The ibatis map :
Rajesh Kumar S
Greenhorn

Joined: Apr 28, 2011
Posts: 3
HI Vidhya,

Thanks a lot :-) You saved me from hell..

Also may i know the value of CommonTokens.RESULT_ROWS_TOKEN.

I'm not able to get Resultset as it is retrieving null eventhough results are there . please help me regarding this.

I'm just getting ResultSet from the ResultGetter
public class ResultSetHandlerCallback implements TypeHandlerCallback {

public ResultSet getResult(ResultGetter getter) throws SQLException {
ResultSet resultSet = getter.getResultSet();
System.out.println("resultSet "+resultSet ); // Here its returing null.
return resultSet;
}

@Override
public void setParameter(ParameterSetter arg0, Object arg1)
throws SQLException {
// TODO Auto-generated method stub

}

@Override
public Object valueOf(String arg0) {
// TODO Auto-generated method stub
return null;
}
}

public class ResultSetMap {


private ResultSet resultSet;
public ResultSet getResultSet() {

return resultSet;
}

public void setResultSet(ResultSet resultSet) {
this.resultSet = resultSet;
}
}


SQLMAP file :-
<typeAlias type="com.logo.customermemory.eclipse.dao.impl.ResultSetMap" alias="resultSetMap" />

<resultMap id = "resultSetMapResult" class = "resultSetMap">
<result property = "resultSet" typeHandler = "com.logo.customermemory.eclipse.dao.impl.ResultSetHandlerCallback" />
</resultMap>

<select id="defaultGroupOrderingQuery" parameterClass="groupSearchVO" resultMap="resultSetMapResult">
SELECT * FROM (
SELECT ROWNUM rnum ,CMG.* FROM (
SELECT * FROM (
<include refid="outerQuery"/>
(
<include refid="getRowNumInnerQuery"/>
AND EVENT_STATUS <![CDATA[ <= ]]> 3 ))
UNION ALL
SELECT * FROM (
<include refid="outerQuery"/>
(
<include refid="getRowNumInnerQuery"/>
AND EVENT_STATUS > 3 )
) )CMG )
</select>


Same query if i run in SQL Command ,result is 2 rows...So,please help me regarding this.

Thank you very much for your support.
Viidhya Kishore
Ranch Hand

Joined: Jan 03, 2007
Posts: 99
CommonTokens.RESULT_ROWS_TOKEN is just a token.
You could have it as
in ResultSetHandlerCallback
Line 44 - result.put("rows",rows);

In my dao code :
line 4 - resultSetMap.getResult().get("rows");

The reason your resultSet is coming null is because of your ResultSetMap class.
You cant have this:

This class HAS TO return a Map.

Please update this class to EXACTLY as I had written.

It should work then.
Rajesh Kumar S
Greenhorn

Joined: Apr 28, 2011
Posts: 3
Hi Vidhya,

Thank you very much for the help. But i stuck with the same. I am getting column names as cell values instead of results . Please help me regarding this. Below is my code.









For above query , result is 2 rows


vicente raul fernandez castneda
Greenhorn

Joined: Sep 11, 2011
Posts: 1
Hi Viidhya.

I implemented all that you said and it works well,
But, i need to know how to get the metadata when there is no any row.

I execute the follow sentence:

select * from mytable where 1=0; //it doesnt return any row.

So, i just need to know the metadata.
With your code works well with data, but nothing happen when the sentece doesnt return anything.
Because i should know the metadata even theres no data retreiving.

Thank you so much.

Regards.

 
wood burning stoves
 
subject: How to retrieve metadata in ibatis