You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by Tak Yoshida <ta...@optonline.net> on 2005/03/05 15:41:13 UTC
Enhancement proposal: plug in external bean
Hello SQLMap development team,
I would like to post this idea again,
which is submitted to sourceforge forum last year.
I believe this is not only for my case in real world,
and makes SQLMap more flexible.
I have already done on 2.0.9b, and it works pretty well on my project.
If you would reflect my proposal in the future SQLMap, that would be great.
thanks,
Tak Yoshida
-------- Here is the post on Oct 30th for 2.0.7 --------
I found one thing I should ask,
that is external service bean plug in feature for the complex object query.
In my project, I need to use Oracle Object Cache Service for disributed
application environment.
and this cache will be managed outside of SQLMap framework,
which mean I cannot use SQLMap cache plugin mechanism where SQLMap manages cache object itself.
So I would like to have SQLMap call external service for complex object's sub query.
Here is my proposal:
Summary:
Inject ServiceLocator to make SQLMap be able to call the service managed
outside of SQLMap.
1: To make use of external object, SqlMapClient has UserServiceBeanLocator object property.
public interface SqlMapClient extends SqlMapExecutor,
SqlMapTransactionManager {
public void setUserServiceBeanLocator(UserServiceBeanLocator serviceBeanLocator);
public UserServiceBeanLocator getUserServiceBeanLocator();
....
}
And SqlMapClientImpl has this imlementation.
public interface UserServiceBeanLocator {
// locator method
public Object getUserServiceBean(String name) throws SqlMapException;
}
2: Extends resultMap's "result" tag attribute to specify the external bean and the method name.
<result property="shipMode" column="SMODE" javaType="string" bean="shipModeDao" method="getShipModeById"/>
instead of
<result property="shipMode" column="SMODE" select="shipModeSqlMap.getShipModeById"/>
3: To support 2, DTD must be enhanced for new two attributes, and
XmlSqlMapClientBuilder must support it. --> SQLMapParser on 2.0.9b
4: And to hold these external bean info in mapping object created by XmlSqlMapClientBuilder,
I introduce UserServiceBeanInfo.
public class UserServiceBeanInfo {
private String beanName;
private String methodName;
private Method method;
...
}
5: Utilizing aboves, BasicResultMap.getResults() method can do nested quesry for the complex property by calling external service.
Here is a snippet of the codes
} else if (mapping.getUserServiceBeanInfo() != null) {
// get key for complex property
Object rawValue = getPrimitiveResultMappingValue(rs, mapping);
// get complex property via external service
UserServiceBeanLocator serviceBeanLocator =
request.getSession().getSqlMapClient().getUserServiceBeanLocator();
UserServiceBeanInfo serviceBeanInfo = mapping.getUserServiceBeanInfo();
try {
Object service = serviceBeanLocator.getUserServiceBean(serviceBeanInfo.getBeanName());
Method method = serviceBeanInfo.getMethod(); // check cacheed one.
if (method == null) {
method = service.getClass().getMethod(serviceBeanInfo.getMethodName(), new Class[] {mapping.getJavaType()});
serviceBeanInfo.setMethod(method); // cache it.
}
columnValues[i] = method.invoke(service, new Object[] {rawValue});
... exception handling...
} else {
6: Application is fully responsible to set this up at startup time.
I am injecting spring ApplicationContext object to SqlMapClient via ApplicationListener,
-------------------------------
--
Tak Yoshida mailto:tak-yoshida@users.sourceforge.net
Re: Enhancement proposal: plug in external bean
Posted by Brandon Goodin <br...@gmail.com>.
Hey Tak,
Thanks for the input. Please put this into JIRA as an enhancement.
http://issues.apache.org/jira/browse/IBATIS
Thanks,
Brandon
On Sat, 05 Mar 2005 09:41:13 -0500, Tak Yoshida
<ta...@optonline.net> wrote:
> Hello SQLMap development team,
>
> I would like to post this idea again,
> which is submitted to sourceforge forum last year.
>
> I believe this is not only for my case in real world,
> and makes SQLMap more flexible.
>
> I have already done on 2.0.9b, and it works pretty well on my project.
> If you would reflect my proposal in the future SQLMap, that would be great.
>
> thanks,
> Tak Yoshida
>
> -------- Here is the post on Oct 30th for 2.0.7 --------
> I found one thing I should ask,
> that is external service bean plug in feature for the complex object query.
>
> In my project, I need to use Oracle Object Cache Service for disributed
> application environment.
> and this cache will be managed outside of SQLMap framework,
> which mean I cannot use SQLMap cache plugin mechanism where SQLMap manages cache object itself.
>
> So I would like to have SQLMap call external service for complex object's sub query.
>
> Here is my proposal:
> Summary:
> Inject ServiceLocator to make SQLMap be able to call the service managed
> outside of SQLMap.
>
> 1: To make use of external object, SqlMapClient has UserServiceBeanLocator object property.
>
> public interface SqlMapClient extends SqlMapExecutor,
> SqlMapTransactionManager {
> public void setUserServiceBeanLocator(UserServiceBeanLocator serviceBeanLocator);
> public UserServiceBeanLocator getUserServiceBeanLocator();
> ....
> }
> And SqlMapClientImpl has this imlementation.
>
> public interface UserServiceBeanLocator {
> // locator method
> public Object getUserServiceBean(String name) throws SqlMapException;
> }
>
> 2: Extends resultMap's "result" tag attribute to specify the external bean and the method name.
>
> <result property="shipMode" column="SMODE" javaType="string" bean="shipModeDao" method="getShipModeById"/>
> instead of
> <result property="shipMode" column="SMODE" select="shipModeSqlMap.getShipModeById"/>
>
> 3: To support 2, DTD must be enhanced for new two attributes, and
> XmlSqlMapClientBuilder must support it. --> SQLMapParser on 2.0.9b
>
> 4: And to hold these external bean info in mapping object created by XmlSqlMapClientBuilder,
> I introduce UserServiceBeanInfo.
> public class UserServiceBeanInfo {
> private String beanName;
> private String methodName;
> private Method method;
> ...
> }
>
> 5: Utilizing aboves, BasicResultMap.getResults() method can do nested quesry for the complex property by calling external service.
>
> Here is a snippet of the codes
> } else if (mapping.getUserServiceBeanInfo() != null) {
> // get key for complex property
> Object rawValue = getPrimitiveResultMappingValue(rs, mapping);
> // get complex property via external service
> UserServiceBeanLocator serviceBeanLocator =
> request.getSession().getSqlMapClient().getUserServiceBeanLocator();
> UserServiceBeanInfo serviceBeanInfo = mapping.getUserServiceBeanInfo();
> try {
> Object service = serviceBeanLocator.getUserServiceBean(serviceBeanInfo.getBeanName());
> Method method = serviceBeanInfo.getMethod(); // check cacheed one.
> if (method == null) {
> method = service.getClass().getMethod(serviceBeanInfo.getMethodName(), new Class[] {mapping.getJavaType()});
> serviceBeanInfo.setMethod(method); // cache it.
> }
> columnValues[i] = method.invoke(service, new Object[] {rawValue});
> ... exception handling...
> } else {
>
> 6: Application is fully responsible to set this up at startup time.
> I am injecting spring ApplicationContext object to SqlMapClient via ApplicationListener,
> -------------------------------
>
> --
> Tak Yoshida mailto:tak-yoshida@users.sourceforge.net
>
Re: Enhancement proposal: plug in external bean
Posted by Tak Yoshida <ta...@optonline.net>.
Larry,
I'm sorry I'm not sure what's the service layer in this context.
You might be talking about the layer above DAO, correct?
What I did is injecting service bean to SQLMap for sub-query.
because, as long as SQLMap manages sub-query invocation, such as
<result property=”category” column=”PRD_CAT_ID” select=”getCategory/>,
we don't have any control to inject another service into this invocation.
If you have better idea for this, please share it for us.
Anyway, I will follow the discussion with Clinton in Jira.
Tak
Larry Meadors wrote in <a1...@mail.gmail.com>
>This (to me at least) feels like something that should be done in the
>service layer, not in the DAO layer.
>
>Larry
--
Tak Yoshida mailto:tak-yoshida@users.sourceforge.net
Re: Enhancement proposal: plug in external bean
Posted by Larry Meadors <la...@gmail.com>.
This (to me at least) feels like something that should be done in the
service layer, not in the DAO layer.
Larry
On Sat, 05 Mar 2005 09:41:13 -0500, Tak Yoshida
<ta...@optonline.net> wrote:
> Hello SQLMap development team,
>
> I would like to post this idea again,
> which is submitted to sourceforge forum last year.
>
> I believe this is not only for my case in real world,
> and makes SQLMap more flexible.
>
> I have already done on 2.0.9b, and it works pretty well on my project.
> If you would reflect my proposal in the future SQLMap, that would be great.
>
> thanks,
> Tak Yoshida
>
> -------- Here is the post on Oct 30th for 2.0.7 --------
> I found one thing I should ask,
> that is external service bean plug in feature for the complex object query.
>
> In my project, I need to use Oracle Object Cache Service for disributed
> application environment.
> and this cache will be managed outside of SQLMap framework,
> which mean I cannot use SQLMap cache plugin mechanism where SQLMap manages cache object itself.
>
> So I would like to have SQLMap call external service for complex object's sub query.
>
> Here is my proposal:
> Summary:
> Inject ServiceLocator to make SQLMap be able to call the service managed
> outside of SQLMap.
>
> 1: To make use of external object, SqlMapClient has UserServiceBeanLocator object property.
>
> public interface SqlMapClient extends SqlMapExecutor,
> SqlMapTransactionManager {
> public void setUserServiceBeanLocator(UserServiceBeanLocator serviceBeanLocator);
> public UserServiceBeanLocator getUserServiceBeanLocator();
> ....
> }
> And SqlMapClientImpl has this imlementation.
>
> public interface UserServiceBeanLocator {
> // locator method
> public Object getUserServiceBean(String name) throws SqlMapException;
> }
>
> 2: Extends resultMap's "result" tag attribute to specify the external bean and the method name.
>
> <result property="shipMode" column="SMODE" javaType="string" bean="shipModeDao" method="getShipModeById"/>
> instead of
> <result property="shipMode" column="SMODE" select="shipModeSqlMap.getShipModeById"/>
>
> 3: To support 2, DTD must be enhanced for new two attributes, and
> XmlSqlMapClientBuilder must support it. --> SQLMapParser on 2.0.9b
>
> 4: And to hold these external bean info in mapping object created by XmlSqlMapClientBuilder,
> I introduce UserServiceBeanInfo.
> public class UserServiceBeanInfo {
> private String beanName;
> private String methodName;
> private Method method;
> ...
> }
>
> 5: Utilizing aboves, BasicResultMap.getResults() method can do nested quesry for the complex property by calling external service.
>
> Here is a snippet of the codes
> } else if (mapping.getUserServiceBeanInfo() != null) {
> // get key for complex property
> Object rawValue = getPrimitiveResultMappingValue(rs, mapping);
> // get complex property via external service
> UserServiceBeanLocator serviceBeanLocator =
> request.getSession().getSqlMapClient().getUserServiceBeanLocator();
> UserServiceBeanInfo serviceBeanInfo = mapping.getUserServiceBeanInfo();
> try {
> Object service = serviceBeanLocator.getUserServiceBean(serviceBeanInfo.getBeanName());
> Method method = serviceBeanInfo.getMethod(); // check cacheed one.
> if (method == null) {
> method = service.getClass().getMethod(serviceBeanInfo.getMethodName(), new Class[] {mapping.getJavaType()});
> serviceBeanInfo.setMethod(method); // cache it.
> }
> columnValues[i] = method.invoke(service, new Object[] {rawValue});
> ... exception handling...
> } else {
>
> 6: Application is fully responsible to set this up at startup time.
> I am injecting spring ApplicationContext object to SqlMapClient via ApplicationListener,
> -------------------------------
>
> --
> Tak Yoshida mailto:tak-yoshida@users.sourceforge.net
>