You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Tim Christopher <ti...@gmail.com> on 2005/03/04 00:54:57 UTC
Referencing between SqlMaps
Hi,
Can any tell me how I can reference a statement that is stored within
a different SqlMap?
I'm sure I can remember reading in one of the docs that this is
possible but I've tried what I thought I can remember it saying and it
doesn't work.
Here's a line from within my resultMap:
<result property="anObj" column="OBJ_ID" select="AnObj.getById"/>
If I create a statement within the same SqlMap and change the select
statement to "getById" (instead of "AnObj.getById") it works fine...
But by leaving it how it is and moving the "getById" statement to the
AnObj.xml SqlMap it throws the following Exception:
SqlMapException: There is no statement named AnObj.getById in this SqlMap.
Is what I'm trying to do actually possible? And if so any advice
would be greatly appreciated.
Tim Christopher
Re: Storing the Dao or the DaoManager in the application context
Posted by Brandon Goodin <br...@gmail.com>.
Do something like the following. Then you simply call the static
getDaoManager() method.
package com.foo.myapp.dao.sqlmap;
import com.ibatis.common.resources.Resources;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.DaoManagerBuilder;
import java.io.Reader;
public class DaoConfig {
private static final DaoManager daoManager;
static {
try {
String resource = "com/foo/myapp/config/dao.xml";
Reader reader = Resources.getResourceAsReader(resource);
daoManager = DaoManagerBuilder.buildDaoManager(reader);
} catch (Exception e) {
throw new RuntimeException("Could not initialize DaoConfig.
Cause: " + e);
}
}
public static DaoManager getDaomanager() {
return daoManager;
}
}
Brandon
On Mon, 07 Mar 2005 07:09:03 -0800, Richard Yee <ry...@cruzio.com> wrote:
> Hi,
> I'm developing an application using the iBATIS DaoManager and currently
> store the dao's that I get by calling DaoManager.getDao( ) in the
> application context at the application startup.. I was wondering if this is
> correct. Should I instead be storing the DaoManager in the application
> context at startup and then calling the getDao() method from it for each
> request?
>
> Thanks,
>
> Richard
>
>
Storing the Dao or the DaoManager in the application context
Posted by Richard Yee <ry...@cruzio.com>.
Hi,
I'm developing an application using the iBATIS DaoManager and currently
store the dao's that I get by calling DaoManager.getDao( ) in the
application context at the application startup.. I was wondering if this is
correct. Should I instead be storing the DaoManager in the application
context at startup and then calling the getDao() method from it for each
request?
Thanks,
Richard
Re: Referencing between SqlMaps
Posted by Tim Christopher <ti...@gmail.com>.
Hi,
Sorry for replying to my own post like this but does anyone actually
know if it is possible to reference between SqlMaps... It's driving
me crazy having to search through all my SqlMaps to make sure I have
changed all the neccessary resultmaps everytime I update an object.
I'd love to be able to refer to a resultmap from another file to save
having to declare the same thing in mutliple files... If this is not
currently possible, are there any plans to add it in the future?
Tim Christopher
On Thu, 3 Mar 2005 23:54:57 +0000, Tim Christopher
<ti...@gmail.com> wrote:
> Hi,
>
> Can any tell me how I can reference a statement that is stored within
> a different SqlMap?
>
> I'm sure I can remember reading in one of the docs that this is
> possible but I've tried what I thought I can remember it saying and it
> doesn't work.
>
> Here's a line from within my resultMap:
> <result property="anObj" column="OBJ_ID" select="AnObj.getById"/>
>
> If I create a statement within the same SqlMap and change the select
> statement to "getById" (instead of "AnObj.getById") it works fine...
> But by leaving it how it is and moving the "getById" statement to the
> AnObj.xml SqlMap it throws the following Exception:
>
> SqlMapException: There is no statement named AnObj.getById in this SqlMap.
>
> Is what I'm trying to do actually possible? And if so any advice
> would be greatly appreciated.
>
> Tim Christopher
>