ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <lmead...@apache.org>
Subject Re: SQL fragment does not respect namespaces in 2.2.0 beta
Date Fri, 25 Aug 2006 23:56:17 GMT
OK, I looked at this more, and could not reproduce it, maybe you can
clarify it - the following definitions produced what I would expect:

=== SqlMapConfig_namespace.xml ===
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
    PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
  <properties resource="com/ibatis/sqlmap/maps/SqlMapConfig.properties"/>
  <settings useStatementNamespaces="true" />
  <transactionManager type="JDBC" commitRequired="false">
    <dataSource type="${dataSourceType}">
      <property name="JDBC.Driver" value="${driver}"/>
      <property name="JDBC.ConnectionURL" value="${url}"/>
      <property name="JDBC.Username" value="${username}"/>
      <property name="JDBC.Password" value="${password}"/>
    </dataSource>
  </transactionManager>
  <sqlMap resource="${SqlMapPath}/Include1.xml"/>
  <sqlMap resource="${SqlMapPath}/Include2.xml"/>
</sqlMapConfig>
===

=== Include1.xml ===
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Include1">
  <sql id="testSql">select * from include1_test</sql>
  <select id="testSelect">
    <include refid="testSql" />
  </select>
</sqlMap>
===

=== Include2.xml ===
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Include2">
  <sql id="testSql">select * from include2_test</sql>
  <select id="testSelect">
    <include refid="testSql" />
  </select>
</sqlMap>
===

Here is the unit test I used:

===
  public void testSqlFragments() {
    String smc = "com/ibatis/sqlmap/maps/SqlMapConfig_namespace.xml";
    SqlMapClient client = null;
    try {
      client = SqlMapClientBuilder.buildSqlMapClient(
          Resources.getResourceAsReader(smc));
      assertNotNull(client);
      SqlMapClientImpl clientImpl = (SqlMapClientImpl) client;
      SqlMapExecutorDelegate delegate = clientImpl.delegate;
      assertNotNull(delegate);
      assertEquals("select * from include1_test",
          delegate.getMappedStatement("Include1.testSelect")
              .getSql().getSql(null, null).trim());
      assertEquals("select * from include2_test",
          delegate.getMappedStatement("Include2.testSelect")
              .getSql().getSql(null, null).trim());
    } catch (Exception e) {
      log.error(e.getLocalizedMessage(), e);
      fail(e.getLocalizedMessage());
    }
  }
===

FWIW, this is one way you could get the SQL for a mapped statement if
you wanted to prepare and execute it yourself. ;-)

Larry


On 8/25/06, Larry Meadors <lmeadors@apache.org> wrote:
> Hmm, that is not what I would expect...if you can provide a simple set
> of sqlmaps and a test case, we can get it fixed for the next release
> (unless you want to provide a patch, too - that would be heroic).
>
> Larry
>
>
> On 8/25/06, Scott Warner <swarner@adcc.com> wrote:
> > I have multiple sql maps that use the same id for an sql fragment and I
> > use namespaces to keep them from colliding.  This works fine in 2.1.7,
> > but in 2.2.0 I get sql errors because it is using the same value for the
> > fragment in all sqlmaps instead of redefining it in each one.  Is 2.2.0
> > supposed to work this way?
> >
> > Scott Warner
> >
>

Mime
View raw message