XSD For SqlMap

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

XSD For SqlMap

hablutzel1
Hi, I want to develop an extension for spring IBatis integration to
allow to use spring beans as Ibatis type handler, and for this I have
thought about using a custom namespace in SqlMap xml's but I have
realized IBatis uses DTD instead of XSD, is this right?
Reply | Threaded
Open this post in threaded view
|

Re: XSD For SqlMap

Eduardo Macarron
Yes, this one http://www.mybatis.org/dtd/mybatis-3-mapper.dtd

On 18 oct, 23:03, hablutzel1 <[hidden email]> wrote:
> Hi, I want to develop an extension for spring IBatis integration to
> allow to use spring beans as Ibatis type handler, and for this I have
> thought about using a custom namespace in SqlMap xml's but I have
> realized IBatis uses DTD instead of XSD, is this right?
Reply | Threaded
Open this post in threaded view
|

Re: XSD For SqlMap

hablutzel1
Thank you, do you know why MyBatis prefer DTD's instead of XSD?? I
have seen many other projects using XSD Schemas, maybe because of the
flexibility it provides.
Anyway, is there an easy way to switch to XSD, or is MyBatis tightly
coupled to DTD's validation... I think that I could maybe branch
current svn and test XSD Schema integration.
What do you think? Or maybe it isn't neccesary for my current goal
that is to insert a namespace in SqlMap to allow spring to load the
SqlMap before MyBatis, look for its namespaced beans and configure
MyBatis to work with these beans as type handlers instead of
instantiating the type handlers by its own.


On 18 oct, 16:23, Eduardo <[hidden email]> wrote:
> Yes, this onehttp://www.mybatis.org/dtd/mybatis-3-mapper.dtd
>
> On 18 oct, 23:03, hablutzel1 <[hidden email]> wrote:
>
> > Hi, I want to develop an extension for spring IBatis integration to
> > allow to use spring beans as Ibatis type handler, and for this I have
> > thought about using a custom namespace in SqlMap xml's but I have
> > realized IBatis uses DTD instead of XSD, is this right?
Reply | Threaded
Open this post in threaded view
|

Re: XSD For SqlMap

hablutzel1
In reply to this post by Eduardo Macarron
Thank you, do you know why MyBatis prefer DTD's instead of XSD?? I
have seen many other projects using XSD Schemas, maybe because of the
flexibility it provides.
Anyway, is there an easy way to switch to XSD, or is MyBatis tightly
coupled to DTD's validation... I think that I could maybe branch
current svn and test XSD Schema integration.
What do you think? Or maybe it isn't neccesary for my current goal
that is to insert a namespace in SqlMap to allow spring to load the
SqlMap before MyBatis, look for its namespaced beans and configure
MyBatis to work with these beans as type handlers instead of
instantiating the type handlers by its own.


On 18 oct, 16:23, Eduardo <[hidden email]> wrote:
> Yes, this onehttp://www.mybatis.org/dtd/mybatis-3-mapper.dtd
>
> On 18 oct, 23:03, hablutzel1 <[hidden email]> wrote:
>
> > Hi, I want to develop an extension for spring IBatis integration to
> > allow to use spring beans as Ibatis type handler, and for this I have
> > thought about using a custom namespace in SqlMap xml's but I have
> > realized IBatis uses DTD instead of XSD, is this right?
Reply | Threaded
Open this post in threaded view
|

Re: XSD For SqlMap

Clinton Begin
Administrator
In reply to this post by hablutzel1
There's no reason that we use DTD over XSD, other than my personal preference.  I don't mind XSD, but it was more of a lack of a reason to change at the time.

There is no hard dependency on it, so no need to branch.  If you want to create an XSD, go for it and submit it as a patch.

Cheers,
Clinton

On Mon, Oct 18, 2010 at 3:46 PM, hablutzel1 <[hidden email]> wrote:
Thank you, do you know why MyBatis prefer DTD's instead of XSD?? I
have seen many other projects using XSD Schemas, maybe because of the
flexibility it provides.
Anyway, is there an easy way to switch to XSD, or is MyBatis tightly
coupled to DTD's validation... I think that I could maybe branch
current svn and test XSD Schema integration.
What do you think? Or maybe it isn't neccesary for my current goal
that is to insert a namespace in SqlMap to allow spring to load the
SqlMap before MyBatis, look for its namespaced beans and configure
MyBatis to work with these beans as type handlers instead of
instantiating the type handlers by its own.


On 18 oct, 16:23, Eduardo <[hidden email]> wrote:
> Yes, this onehttp://www.mybatis.org/dtd/mybatis-3-mapper.dtd
>
> On 18 oct, 23:03, hablutzel1 <[hidden email]> wrote:
>
> > Hi, I want to develop an extension for spring IBatis integration to
> > allow to use spring beans as Ibatis type handler, and for this I have
> > thought about using a custom namespace in SqlMap xml's but I have
> > realized IBatis uses DTD instead of XSD, is this right?

Reply | Threaded
Open this post in threaded view
|

Re: XSD For SqlMap

Eduardo Macarron
In reply to this post by hablutzel1

Hi hablutzel. I don´t see the relationship between MyBatis DTD and
Spring namespaces.

I suppose you want to create a Spring namespace for MyBatis. In that
case you need to provide a XSD for the xml syntax you want to use for
applicationContex.xml. Is fairly impossible that spring applicationXML
syntas is identical to mybatis sqlmap-config.xml syntax.

BTW if you want to set up spring beans as typehandlers I would start
firs from Spring basic xml ("beans namespace") and later.

I would do somethink like this.

<bean id="mytypehandler1" class="TypeHandlerFactoryBean" >
  <property id="javaType" value="java.lang.Spring" />
  <property id="sqlType" value="BOOLEAN" />
</bean>

 ...

<bean id="sqlSessionFactory" class="sqlSessionFactoryBean" >
  <property id="typeHandlers">
     <list>
         <ref="mytypehandler1" />
         <ref="mytypehandler2" />
     </list>
</bean>

And once you have it working, start with namespace.

BTW what do you want this for?



On 18 oct, 23:46, hablutzel1 <[hidden email]> wrote:

> Thank you, do you know why MyBatis prefer DTD's instead of XSD?? I
> have seen many other projects using XSD Schemas, maybe because of the
> flexibility it provides.
> Anyway, is there an easy way to switch to XSD, or is MyBatis tightly
> coupled to DTD's validation... I think that I could maybe branch
> current svn and test XSD Schema integration.
> What do you think? Or maybe it isn't neccesary for my current goal
> that is to insert a namespace in SqlMap to allow spring to load the
> SqlMap before MyBatis, look for its namespaced beans and configure
> MyBatis to work with these beans as type handlers instead of
> instantiating the type handlers by its own.
>
> On 18 oct, 16:23, Eduardo <[hidden email]> wrote:
>
>
>
> > Yes, this onehttp://www.mybatis.org/dtd/mybatis-3-mapper.dtd
>
> > On 18 oct, 23:03, hablutzel1 <[hidden email]> wrote:
>
> > > Hi, I want to develop an extension for spring IBatis integration to
> > > allow to use spring beans as Ibatis type handler, and for this I have
> > > thought about using a custom namespace in SqlMap xml's but I have
> > > realized IBatis uses DTD instead of XSD, is this right?
Reply | Threaded
Open this post in threaded view
|

Re: XSD For SqlMap

Hunter
Currently SqlSessionFactoryBean does not have methods to set the
TypeHandlers so the above XML won't work. Rather than add all possible
methods to SqlSessionFactoryBean, it may be easier to implement a
BeanPostProcessor that either uses an annotation or just looks for all
Spring beans that implement the TypeHandler interface and adds them to
the configured SqlSessionFactory's configuration. It's only 2 or 3
lines of xml to create a bean - I am not sure the benefit of having
full Spring namespace support. See the new MapperScanner class in
MyBatis-Spring (only in SVN for now) for an example post processor.

But, I am not sure why exactly you need this. Unless your TypeHandlers
have some complicated setup (i.e. a non-default constructor), the
easiest thing to do is continue to use the _MyBatis_ config file and
set your TypeHandlers there. SqlSessionFactoryBean has a
configLocation property you can use to point to a MyBatis config file.
SqlSessionFactoryBean will read that config file and load everything
into the Configuration for you at Spring startup.

On Oct 19, 2:38 am, Eduardo <[hidden email]> wrote:

> Hi hablutzel. I don´t see the relationship between MyBatis DTD and
> Spring namespaces.
>
> I suppose you want to create a Spring namespace for MyBatis. In that
> case you need to provide a XSD for the xml syntax you want to use for
> applicationContex.xml. Is fairly impossible that spring applicationXML
> syntas is identical to mybatis sqlmap-config.xml syntax.
>
> BTW if you want to set up spring beans as typehandlers I would start
> firs from Spring basic xml ("beans namespace") and later.
>
> I would do somethink like this.
>
> <bean id="mytypehandler1" class="TypeHandlerFactoryBean" >
>   <property id="javaType" value="java.lang.Spring" />
>   <property id="sqlType" value="BOOLEAN" />
> </bean>
>
>  ...
>
> <bean id="sqlSessionFactory" class="sqlSessionFactoryBean" >
>   <property id="typeHandlers">
>      <list>
>          <ref="mytypehandler1" />
>          <ref="mytypehandler2" />
>      </list>
> </bean>
>
> And once you have it working, start with namespace.
>
> BTW what do you want this for?
>
> On 18 oct, 23:46, hablutzel1 <[hidden email]> wrote:
>
>
>
> > Thank you, do you know why MyBatis prefer DTD's instead of XSD?? I
> > have seen many other projects using XSD Schemas, maybe because of the
> > flexibility it provides.
> > Anyway, is there an easy way to switch to XSD, or is MyBatis tightly
> > coupled to DTD's validation... I think that I could maybe branch
> > current svn and test XSD Schema integration.
> > What do you think? Or maybe it isn't neccesary for my current goal
> > that is to insert a namespace in SqlMap to allow spring to load the
> > SqlMap before MyBatis, look for its namespaced beans and configure
> > MyBatis to work with these beans as type handlers instead of
> > instantiating the type handlers by its own.
>
> > On 18 oct, 16:23, Eduardo <[hidden email]> wrote:
>
> > > Yes, this onehttp://www.mybatis.org/dtd/mybatis-3-mapper.dtd
>
> > > On 18 oct, 23:03, hablutzel1 <[hidden email]> wrote:
>
> > > > Hi, I want to develop an extension for spring IBatis integration to
> > > > allow to use spring beans as Ibatis type handler, and for this I have
> > > > thought about using a custom namespace in SqlMap xml's but I have
> > > > realized IBatis uses DTD instead of XSD, is this right?
Reply | Threaded
Open this post in threaded view
|

Fwd: XSD For SqlMap

hablutzel1
I suppose you want to create a Spring namespace for MyBatis. In that
case you need to provide a XSD for the xml syntax you want to use for
applicationContex.xml. Is fairly impossible that spring applicationXML
syntas is identical to mybatis sqlmap-config.xml syntax.



I don't want to create an spring namespace for ibatis configuration, but a namespace in ibatis configuration files to allow to do something like this



<resultMap id="myIBatisResult" class="myClass">
...
<result property="pojoProperty" column="idColumn"
           di:typeHandler="oneSpringBean"/>
...

</resultMap>


>>>

<bean id="mytypehandler1" class="TypeHandlerFactoryBean" >
 <property id="javaType" value="java.lang.Spring" />
 <property id="sqlType" value="BOOLEAN" />
</bean>

 ...

<bean id="sqlSessionFactory" class="sqlSessionFactoryBean" >
 <property id="typeHandlers">
    <list>
        <ref="mytypehandler1" />
        <ref="mytypehandler2" />
    </list>
</bean>

>>>

If I take an approach like this one, how will resultMap result's be able to pick one of these handlers registered in spring?? That's the idea behind a namespace in ibatis.




 it may be easier to implement a
BeanPostProcessor that either uses an annotation or just looks for all
Spring beans that implement the TypeHandler interface and adds them to
the configured SqlSessionFactory's configuration. It's only 2 or 3
lines of xml to create a bean - I am not sure the benefit of having
full Spring namespace support. See the new MapperScanner class in
MyBatis-Spring (only in SVN for now) for an example post processor


Type Handlers would be normal spring beans, spring would have the responsability to associate some resultMap result's to these beans in the sqlMapFactory (not sure if ibatis have API for this) after Ibatis loads its configuration files.



Unless your TypeHandlers
have some complicated setup (i.e. a non-default constructor), the
easiest thing to do is continue to use the _MyBatis_ config file and
set your TypeHandlers there.

My typehandlers are spring beans, not so complex, but they read xml's for composing information missing in the objects being retrieved from database.
I think it is better to use DI here for these kind of things, it provides all the advantages of spring, as getting a quick outline of every dependency without looking into code.





On Tue, Oct 19, 2010 at 9:29 PM, Hunter <[hidden email]> wrote:
Currently SqlSessionFactoryBean does not have methods to set the
TypeHandlers so the above XML won't work. Rather than add all possible
methods to SqlSessionFactoryBean, it may be easier to implement a
BeanPostProcessor that either uses an annotation or just looks for all
Spring beans that implement the TypeHandler interface and adds them to
the configured SqlSessionFactory's configuration. It's only 2 or 3
lines of xml to create a bean - I am not sure the benefit of having
full Spring namespace support. See the new MapperScanner class in
MyBatis-Spring (only in SVN for now) for an example post processor.

But, I am not sure why exactly you need this. Unless your TypeHandlers
have some complicated setup (i.e. a non-default constructor), the
easiest thing to do is continue to use the _MyBatis_ config file and
set your TypeHandlers there. SqlSessionFactoryBean has a
configLocation property you can use to point to a MyBatis config file.
SqlSessionFactoryBean will read that config file and load everything
into the Configuration for you at Spring startup.

On Oct 19, 2:38 am, Eduardo <[hidden email]> wrote:
> Hi hablutzel. I don´t see the relationship between MyBatis DTD and
> Spring namespaces.
>
> I suppose you want to create a Spring namespace for MyBatis. In that
> case you need to provide a XSD for the xml syntax you want to use for
> applicationContex.xml. Is fairly impossible that spring applicationXML
> syntas is identical to mybatis sqlmap-config.xml syntax.
>
> BTW if you want to set up spring beans as typehandlers I would start
> firs from Spring basic xml ("beans namespace") and later.
>
> I would do somethink like this.
>
> <bean id="mytypehandler1" class="TypeHandlerFactoryBean" >
>   <property id="javaType" value="java.lang.Spring" />
>   <property id="sqlType" value="BOOLEAN" />
> </bean>
>
>  ...
>
> <bean id="sqlSessionFactory" class="sqlSessionFactoryBean" >
>   <property id="typeHandlers">
>      <list>
>          <ref="mytypehandler1" />
>          <ref="mytypehandler2" />
>      </list>
> </bean>
>
> And once you have it working, start with namespace.
>
> BTW what do you want this for?
>
> On 18 oct, 23:46, hablutzel1 <[hidden email]> wrote:
>
>
>
> > Thank you, do you know why MyBatis prefer DTD's instead of XSD?? I
> > have seen many other projects using XSD Schemas, maybe because of the
> > flexibility it provides.
> > Anyway, is there an easy way to switch to XSD, or is MyBatis tightly
> > coupled to DTD's validation... I think that I could maybe branch
> > current svn and test XSD Schema integration.
> > What do you think? Or maybe it isn't neccesary for my current goal
> > that is to insert a namespace in SqlMap to allow spring to load the
> > SqlMap before MyBatis, look for its namespaced beans and configure
> > MyBatis to work with these beans as type handlers instead of
> > instantiating the type handlers by its own.
>
> > On 18 oct, 16:23, Eduardo <[hidden email]> wrote:
>
> > > Yes, this onehttp://www.mybatis.org/dtd/mybatis-3-mapper.dtd
>
> > > On 18 oct, 23:03, hablutzel1 <[hidden email]> wrote:
>
> > > > Hi, I want to develop an extension for spring IBatis integration to
> > > > allow to use spring beans as Ibatis type handler, and for this I have
> > > > thought about using a custom namespace in SqlMap xml's but I have
> > > > realized IBatis uses DTD instead of XSD, is this right?



--
Jaime Hablutzel - 9-9956-3299
 
(tildes omitidas intencionalmente)



--
Jaime Hablutzel - 9-9956-3299
 
(tildes omitidas intencionalmente)
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: XSD For SqlMap

Hunter
I agree the DI is more transparent than using Spring post processors
or MyBatis interceptors /plugins.

MyBatis uses its own custom XML parser so I don't think you really
need a DTD or schema. I am not too familiar with this code, but I
think you can add a new element to your mapper file and write the code
that parses it. In this case, you want to overwrite
org.apache.ibatis.builder.xml.XMLMapperBuilder.buildResultMappingFromContext().
Ultimately you want to get your TypeHandlers put into
Configuration.typeHandlerRegistry.

Unfortunately, MyBatis does not have an easy way to plug customer
parsers back into the rest of the parsing framework. You are also
going to have to overwrite XMLConfigBuilder.mapperElement() and
SqlSessionFactoryBean (or SqlSessionFactoryBuilder) to parse your XML
with the custom config builder class.

If you have any specific questions about the XML parser, please feel
free to ask more questions on the mailing list.

On Oct 21, 3:37 pm, Jaime Hablutzel Egoavil <[hidden email]>
wrote:

> I suppose you want to create a Spring namespace for MyBatis. In that
> case you need to provide a XSD for the xml syntax you want to use for
> applicationContex.xml. Is fairly impossible that spring applicationXML
> syntas is identical to mybatis sqlmap-config.xml syntax.
>
> I don't want to create an spring namespace for ibatis configuration, but a
> namespace in ibatis configuration files to allow to do something like this
>
> <resultMap id="myIBatisResult" class="myClass">
> ...
> <result property="pojoProperty" column="idColumn"
>            di:typeHandler="oneSpringBean"/>
> ...
>
> </resultMap>
>
>
>
> <bean id="mytypehandler1" class="TypeHandlerFactoryBean" >
>  <property id="javaType" value="java.lang.Spring" />
>  <property id="sqlType" value="BOOLEAN" />
> </bean>
>
>  ...
>
> <bean id="sqlSessionFactory" class="sqlSessionFactoryBean" >
>  <property id="typeHandlers">
>     <list>
>         <ref="mytypehandler1" />
>         <ref="mytypehandler2" />
>     </list>
> </bean>
>
>
>
> If I take an approach like this one, how will resultMap result's be able to
> pick one of these handlers registered in spring?? That's the idea behind a
> namespace in ibatis.
>
>  it may be easier to implement a
> BeanPostProcessor that either uses an annotation or just looks for all
> Spring beans that implement the TypeHandler interface and adds them to
> the configured SqlSessionFactory's configuration. It's only 2 or 3
> lines of xml to create a bean - I am not sure the benefit of having
> full Spring namespace support. See the new MapperScanner class in
> MyBatis-Spring (only in SVN for now) for an example post processor
>
> Type Handlers would be normal spring beans, spring would have the
> responsability to associate some resultMap result's to these beans in the
> sqlMapFactory (not sure if ibatis have API for this) after Ibatis loads its
> configuration files.
>
> Unless your TypeHandlers
> have some complicated setup (i.e. a non-default constructor), the
> easiest thing to do is continue to use the _MyBatis_ config file and
> set your TypeHandlers there.
>
> My typehandlers are spring beans, not so complex, but they read xml's for
> composing information missing in the objects being retrieved from database.
> I think it is better to use DI here for these kind of things, it provides
> all the advantages of spring, as getting a quick outline of every dependency
> without looking into code.
>
>
>
>
>
> On Tue, Oct 19, 2010 at 9:29 PM, Hunter <[hidden email]> wrote:
> > Currently SqlSessionFactoryBean does not have methods to set the
> > TypeHandlers so the above XML won't work. Rather than add all possible
> > methods to SqlSessionFactoryBean, it may be easier to implement a
> > BeanPostProcessor that either uses an annotation or just looks for all
> > Spring beans that implement the TypeHandler interface and adds them to
> > the configured SqlSessionFactory's configuration. It's only 2 or 3
> > lines of xml to create a bean - I am not sure the benefit of having
> > full Spring namespace support. See the new MapperScanner class in
> > MyBatis-Spring (only in SVN for now) for an example post processor.
>
> > But, I am not sure why exactly you need this. Unless your TypeHandlers
> > have some complicated setup (i.e. a non-default constructor), the
> > easiest thing to do is continue to use the _MyBatis_ config file and
> > set your TypeHandlers there. SqlSessionFactoryBean has a
> > configLocation property you can use to point to a MyBatis config file.
> > SqlSessionFactoryBean will read that config file and load everything
> > into the Configuration for you at Spring startup.
>
> > On Oct 19, 2:38 am, Eduardo <[hidden email]> wrote:
> > > Hi hablutzel. I don´t see the relationship between MyBatis DTD and
> > > Spring namespaces.
>
> > > I suppose you want to create a Spring namespace for MyBatis. In that
> > > case you need to provide a XSD for the xml syntax you want to use for
> > > applicationContex.xml. Is fairly impossible that spring applicationXML
> > > syntas is identical to mybatis sqlmap-config.xml syntax.
>
> > > BTW if you want to set up spring beans as typehandlers I would start
> > > firs from Spring basic xml ("beans namespace") and later.
>
> > > I would do somethink like this.
>
> > > <bean id="mytypehandler1" class="TypeHandlerFactoryBean" >
> > >   <property id="javaType" value="java.lang.Spring" />
> > >   <property id="sqlType" value="BOOLEAN" />
> > > </bean>
>
> > >  ...
>
> > > <bean id="sqlSessionFactory" class="sqlSessionFactoryBean" >
> > >   <property id="typeHandlers">
> > >      <list>
> > >          <ref="mytypehandler1" />
> > >          <ref="mytypehandler2" />
> > >      </list>
> > > </bean>
>
> > > And once you have it working, start with namespace.
>
> > > BTW what do you want this for?
>
> > > On 18 oct, 23:46, hablutzel1 <[hidden email]> wrote:
>
> > > > Thank you, do you know why MyBatis prefer DTD's instead of XSD?? I
> > > > have seen many other projects using XSD Schemas, maybe because of the
> > > > flexibility it provides.
> > > > Anyway, is there an easy way to switch to XSD, or is MyBatis tightly
> > > > coupled to DTD's validation... I think that I could maybe branch
> > > > current svn and test XSD Schema integration.
> > > > What do you think? Or maybe it isn't neccesary for my current goal
> > > > that is to insert a namespace in SqlMap to allow spring to load the
> > > > SqlMap before MyBatis, look for its namespaced beans and configure
> > > > MyBatis to work with these beans as type handlers instead of
> > > > instantiating the type handlers by its own.
>
> > > > On 18 oct, 16:23, Eduardo <[hidden email]> wrote:
>
> > > > > Yes, this onehttp://www.mybatis.org/dtd/mybatis-3-mapper.dtd
>
> > > > > On 18 oct, 23:03, hablutzel1 <[hidden email]> wrote:
>
> > > > > > Hi, I want to develop an extension for spring IBatis integration to
> > > > > > allow to use spring beans as Ibatis type handler, and for this I
> > have
> > > > > > thought about using a custom namespace in SqlMap xml's but I have
> > > > > > realized IBatis uses DTD instead of XSD, is this right?
>
> --
> Jaime Hablutzel - 9-9956-3299
>
> (tildes omitidas intencionalmente)
>
> --
> Jaime Hablutzel - 9-9956-3299
>
> (tildes omitidas intencionalmente)
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: XSD For SqlMap

Eduardo Macarron
In reply to this post by hablutzel1
> If I take an approach like this one, how will resultMap result's be able to
> pick one of these handlers registered in spring?? That's the idea behind a
> namespace in ibatis.

I don´t see the problem.

The process seems simple:
- You have some typehandlers in your Spring context
- Then you register them in MyBatis so they are used when needed.

MyBatis will be able to find them and use them to process your
resultmaps.

The point is that, as Hunter said, nothing of this is implemented
right now. But you could make your own bean that gets
SqlSessionFactory + type handlers injected and registers it.