MyBatis and Sharding

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

MyBatis and Sharding

Jatin
Hello,

Just like Hibernate provides Sharding capabilities (sharding logic,
shard sessionFactoy, shard selection etc), does MyBatis support
Sharding?
I have not come across anything in MyBatis documentation that talks
about it even though I came across two Google projects Shard-Batis and
ibatis-sharding, both of which look pretty old, inactive, for iBatis
and mostly in Chinese.

Any guidance is appreciated.
Reply | Threaded
Open this post in threaded view
|

Re: MyBatis and Sharding

Clinton Begin
Administrator
There's no official support.  But because Sharding is data driven, MyBatis won't be able to do it exactly as any ORM does.  Do you have any suggestions as to how this could work, without generating or augmenting the SQL?

Clinton

On Wed, Apr 27, 2011 at 5:55 PM, Jatin <[hidden email]> wrote:
Hello,

Just like Hibernate provides Sharding capabilities (sharding logic,
shard sessionFactoy, shard selection etc), does MyBatis support
Sharding?
I have not come across anything in MyBatis documentation that talks
about it even though I came across two Google projects Shard-Batis and
ibatis-sharding, both of which look pretty old, inactive, for iBatis
and mostly in Chinese.

Any guidance is appreciated.

Reply | Threaded
Open this post in threaded view
|

Re: MyBatis and Sharding

Jatin
Thanks Clinton. I did look into these 3 projects available on
googlecode (and am still looking into them and trying to understand):

1. ibatis-sharding --> With most activity, but inactive for last 2
years. No documentation. Few comments and those too in Chinese. Built
on old ibatis and not mybatis.
2. spring-ibatis-cluster --> Incomplete. Built on old ibatis and not
mybatis.
3. shard-batis --> No activity, inactive. Built on old ibatis and not
mybatis.

To start off, they have more than one dataSource based on the number
of shards of the same database:

 <bean id="dataSource0"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="xxx"/>
    <property name="url" value="xxx:partition0"/>
    <property name="username" value="xxx"/>
    <property name="password" value="xxx"/>
  </bean>

  <bean id="dataSource1"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="xxx:partition1"/>
    <property name="username" value="xxx"/>
    <property name="password" value="xxx"/>
  </bean>

Based on the above 2 they have equal number of sqlSessionFactory
beans:

<bean id="sqlSessionFactory0"
class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource0" />
        <property name="mapperLocations" value="classpath:Mapper.xml" />
</bean>

<bean id="sqlSessionFactory1"
class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource1" />
        <property name="mapperLocations" value="classpath:Mapper.xml" />
</bean>

Then one has to inject these into the DAOs. I am trying to understand
the rest of the classes where the actual sharding strategy is
implemented.

On Apr 28, 5:52 am, Clinton Begin <[hidden email]> wrote:

> There's no official support.  But because Sharding is data driven, MyBatis
> won't be able to do it exactly as any ORM does.  Do you have any suggestions
> as to how this could work, without generating or augmenting the SQL?
>
> Clinton
>
>
>
>
>
>
>
> On Wed, Apr 27, 2011 at 5:55 PM, Jatin <[hidden email]> wrote:
> > Hello,
>
> > Just like Hibernate provides Sharding capabilities (sharding logic,
> > shard sessionFactoy, shard selection etc), does MyBatis support
> > Sharding?
> > I have not come across anything in MyBatis documentation that talks
> > about it even though I came across two Google projects Shard-Batis and
> > ibatis-sharding, both of which look pretty old, inactive, for iBatis
> > and mostly in Chinese.
>
> > Any guidance is appreciated.