droidin.net | 19 Jul 05:06 2010
Picon

Dynamic table names in DELETE


iBatis 3 has wonderful ability in SELECT statements to provide dynamic
substitution before statement is prepared. For example this will work

<select id="foo">SELECT * FROM $db$.MY_TABLE</select>

However I can't make it work when trying to empty table

XML code:

<delete id="del" parameterType="String">DELETE FROM $db$.MY_TABLE</delete>
<!-- and I also tried -->
<delete id="del" parameterType="String">DELETE FROM $0$.MY_TABLE</delete>

Java code:

// method defined as
del(String db);
// and executed as
mapper.del("MY_DB");

I get message complaining that Database '$db$' does not exist

Anyone can suggest the solution? I'm on Teradata db and it is setup in the
way that I need provide db names in query or else I get Object not found

--

-- 
View this message in context: http://old.nabble.com/Dynamic-table-names-in-DELETE-tp29201077p29201077.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
(Continue reading)

Panciz | 10 Jul 08:24 2010
Picon

Ibator 1.2.2

Hi,

I built ibator 1.2.2 from sources downloaded from 
http://svn.apache.org/repos/asf/ibatis/java/ibator/trunk/core/
and create the JAR file.
The problem is that when I run the tool on a configuration file,
which worked with the previous version, I get  

$ java -jar ibator-1.2.2.jar -configfile ../conf/ibatorConfig.xml 
java.net.MalformedURLException
at java.net.URL.<init>(URL.java:601)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager
  .setupCurrentEntity(XMLEntityManager.java:650)
at com.sun.org.apache.xerces.internal.impl
  .XMLEntityManager.startEntity(XMLEntityManager.java:1315)
at com.sun.org.apache.xerces.internal.impl
.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1282)
at com.sun.org.apache.xerces.internal.impl
  .XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:283)
at com.sun.org.apache.xerces.internal.impl
  .XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1193)
at com.sun.org.apache.xerces.internal.impl
  .XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1090)
at com.sun.org.apache.xerces.internal.impl
  .XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1003)
at com.sun.org.apache.xerces.internal.impl
  .XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl
(Continue reading)

Laurent MANNS | 5 Jul 10:58 2010
Picon

Ibatis 3 and null values

Hello,

I'm facing a weird problem when resultType is a Map : 

<select id="test" resultType="java.util.LinkedHashMap">
  select 
    getDate() "Timestamp", 
    null      "Test"
</select>

List<LinkedHashMap<Object, Object>> lignes = session.selectList("test");

for (Iterator it = ((LinkedHashMap<Object, Object>)    
lignes.get(0)).keySet().iterator(); it.hasNext();) 
                  System.out.println(it.next());

                  		
The result is : 

   TIMESTAMP
   Timestamp
   1

Why is first column duplicated when the alias is in lowercase ? And why can't i
get the second column header when it contains null values ? 

Any help would be appreciated. 

Thx.
(Continue reading)

Ashish Kulkarni | 28 Jun 18:03 2010
Picon

ibatis 3 and calling stored procedure

Hi

Is there any place where it has updated information about calling stored procedure from ibatis 3.0, i checked google and could not find any,
I was reading user guide and it says parameterMap is not used, 

I tried the code below and seems it is working, but i would like to do this using some methods from ibatis 3.0

<parameterMap id="swapParameters" type="java.util.HashMap" >
    <parameter property="id" jdbcType="VARCHAR" javaType="java.lang.String" mode="INOUT"/>
    <parameter property="message" jdbcType="VARCHAR" javaType="java.lang.String" mode="INOUT"/>
 </parameterMap>

<select id="getValidPayment" statementType="CALLABLE" resultType="java.lang.String" parameterMap="swapParameters">
call SCHEMA.PROCEDURE (?,?)
</select>

--
Ashish
www.ayurwellness.com
www.mysoftwareneeds.com
karthik085 | 24 Jun 21:05 2010
Picon

Inheritanc


Hi,
I am using iBatis 3.0 beta-9
How can inheritance or has-a relationship be specified for the following
case?

class A
   name: String

class B extends A
   id: Integer

 
Currently, I was trying to use "has-a" relationship - association to do it -
but, it is not working!
    <resultMap id="A" type="org.XXX.A">       
        <result property="name" column="name" />
        <association property="B" column="a_b_id" javaType="org.XXX.B"/>
    </resultMap>

     <association property="B" column="a_b_id" javaType="org.XXX.B">
        <id property="id" column="id" />
    </association>
--

-- 
View this message in context: http://old.nabble.com/Inheritanc-tp28985663p28985663.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
deepak123 | 18 Jun 12:11 2010

Passing Oracle Table Types (Is it possible?)


Hi, 
I have folloiwng types defines in Oracle:

create or replace type position_obj as object
(
POSITION_ID  NUMBER,
PROD_TYPE  VARCHAR2(50),
);

create or replace type position_tab as table of position_obj;
create or replace type error_logs_obj is object
( 
MODULE_NAME   VARCHAR2(30),
DATABASE_UNIT VARCHAR2(30),
TABLE_NAME    VARCHAR2(30),
ERROR_MESS    VARCHAR2(4000),
CREATE_TIME   DATE,
USER_NAME     VARCHAR2(30)
);
create or replace type error_logs_tab is table of error_logs_obj;

And my Oracle SP is:
  PROCEDURE insert_position(p_position_tab  position_tab
                           ,o_error_msg_tab OUT error_logs_tab)

How do i call above SP using iBatis 2.3.4 ? Please let me know if its
possible or not. 

Thanks & Regards,
Deepak
--

-- 
View this message in context: http://old.nabble.com/Passing-Oracle-Table-Types-%28Is-it-possible-%29-tp28922808p28922808.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
moffit | 17 Jun 18:51 2010
Picon

Lazy Loading per ResultMap


Hi all,

  Currently, lazy loading is enabled/disabled globally for all results.  It
would be very useful (for me) to specify the load per association or
collection within the result-map itself.  Is there any way to do this via
the plugin architecture?  Does anyone have any thoughts with regard to this?

Thanks,

Mike
--

-- 
View this message in context: http://old.nabble.com/Lazy-Loading-per-ResultMap-tp28916943p28916943.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
shoenigman | 15 Jun 16:43 2010
Picon

SQLMap Question - Select Statement


I have a quick question about writing a select statement that returns an
object inside of another object...

Say I have a Java bean named Message that has an instance variable named
statusid which is a long. I also have an enum named Status that contains
statusid (long) and statusdesc (String). These two classes map to Oracle
tables named MESSAGE and STATUS respectively...

Right now the select statement correctly returns the statusid value from the
db and sets it in the Message object. However, I want to replace the
statusid instance variable in Message with the enum Status and have a more
complex query that returns the Message along with both values from the
STATUS lookup table in the form of my enum. 

How would this work in the SQLMap? Does anybody have an example of this?
Thanks in advance!
--

-- 
View this message in context: http://old.nabble.com/SQLMap-Question---Select-Statement-tp28892238p28892238.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Absaar | 14 Jun 17:15 2010
Picon

Getting RunTime Exception


Hi,
I am trying to create a POC for iBatis. I have trying to do some
configuration and getting the following error

14-Jun-2010 20:02:20 com.ibatis.common.logging.jdk14.Jdk14LoggingImpl error
SEVERE: SimpleDataSource: Error while loading properties. Cause:
java.lang.RuntimeException: SimpleDataSource: Some properties were not set

Here is the stack trace:

java.lang.RuntimeException: SimpleDataSource: Some properties were not set.
	at
com.ibatis.common.jdbc.SimpleDataSource.initialize(SimpleDataSource.java:131)
	at
com.ibatis.common.jdbc.SimpleDataSource.<init>(SimpleDataSource.java:116)
	at
com.ibatis.sqlmap.engine.datasource.SimpleDataSourceFactory.initialize(SimpleDataSourceFactory.java:31)
	at
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$9.process(SqlMapConfigParser.java:220)
	at
com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)
	at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:105)
	at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)
	at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)
	at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)
	at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)
	at
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:46)
	at
com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)
	at com.ociweb.music.LoadDB.main(LoadDB.java:19)
Exception in thread "main" java.lang.RuntimeException: Error occurred. 
Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause:
java.lang.RuntimeException: Error parsing XPath
'/sqlMapConfig/transactionManager/dataSource/end()'.  Cause:
com.ibatis.sqlmap.client.SqlMapException: Error initializing DataSource. 
Could not instantiate DataSourceFactory.  Cause: java.lang.RuntimeException:
SimpleDataSource: Error while loading properties. Cause:
java.lang.RuntimeException: SimpleDataSource: Some properties were not set.
	at
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:49)
	at
com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)
	at com.ociweb.music.LoadDB.main(LoadDB.java:19)
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. 
Cause: java.lang.RuntimeException: Error parsing XPath
'/sqlMapConfig/transactionManager/dataSource/end()'.  Cause:
com.ibatis.sqlmap.client.SqlMapException: Error initializing DataSource. 
Could not instantiate DataSourceFactory.  Cause: java.lang.RuntimeException:
SimpleDataSource: Error while loading properties. Cause:
java.lang.RuntimeException: SimpleDataSource: Some properties were not set.
	at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
	at
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:46)
	... 2 more
Caused by: java.lang.RuntimeException: Error parsing XPath
'/sqlMapConfig/transactionManager/dataSource/end()'.  Cause:
com.ibatis.sqlmap.client.SqlMapException: Error initializing DataSource. 
Could not instantiate DataSourceFactory.  Cause: java.lang.RuntimeException:
SimpleDataSource: Error while loading properties. Cause:
java.lang.RuntimeException: SimpleDataSource: Some properties were not set.
	at
com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:123)
	at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:105)
	at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)
	at com.ibatis.common.xml.NodeletParser.process(NodeletParser.java:102)
	at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:72)
	at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:51)
	... 3 more
Caused by: com.ibatis.sqlmap.client.SqlMapException: Error initializing
DataSource.  Could not instantiate DataSourceFactory.  Cause:
java.lang.RuntimeException: SimpleDataSource: Error while loading
properties. Cause: java.lang.RuntimeException: SimpleDataSource: Some
properties were not set.
	at
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$9.process(SqlMapConfigParser.java:227)
	at
com.ibatis.common.xml.NodeletParser.processNodelet(NodeletParser.java:121)
	... 8 more
Caused by: java.lang.RuntimeException: SimpleDataSource: Error while loading
properties. Cause: java.lang.RuntimeException: SimpleDataSource: Some
properties were not set.
	at
com.ibatis.common.jdbc.SimpleDataSource.initialize(SimpleDataSource.java:210)
	at
com.ibatis.common.jdbc.SimpleDataSource.<init>(SimpleDataSource.java:116)
	at
com.ibatis.sqlmap.engine.datasource.SimpleDataSourceFactory.initialize(SimpleDataSourceFactory.java:31)
	at
com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser$9.process(SqlMapConfigParser.java:220)
	... 9 more
Caused by: java.lang.RuntimeException: SimpleDataSource: Some properties
were not set.
	at
com.ibatis.common.jdbc.SimpleDataSource.initialize(SimpleDataSource.java:131)

Any help/suggestion form the fellow members would be highly helpful.

Thanks
--

-- 
View this message in context: http://old.nabble.com/Getting-RunTime-Exception-tp28880850p28880850.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Nitin.Dubey | 14 Jun 07:10 2010

SQLExecutor.addBatch() modified

By default for batch inserts ibatis caches the prepared statements in list and always re-uses the last statement for table inserts.  This model works for batch inserts for a single table.  However, we have a requirement where we need to do batch inserts into several tables in a single transaction.  Since ibatis is designed for batch inserts to a single table, using multi table insert gives us pathetic performance, as ibatis creates a new PreparedStatement for every query (occuping database cursor as well).

I looked at the source code and modified SqlExecutor==>addBatch() method.  This method uses a Map instead of a list.  Corresponding changes are done to populate the map and retrieve from map.  Following is the code.

    private Map<String,PreparedStatement> statementMap = new HashMap<String,PreparedStatement>();

    public void addBatch(StatementScope statementScope, Connection conn, String sql, Object[] parameters) throws SQLException {
      PreparedStatement ps = null;
      //if (currentSql != null && currentSql.equals(sql)) {
      if (currentSql != null && statementMap.containsKey(currentSql)) {
        //int last = statementList.size() - 1;
        ps = (PreparedStatement) statementMap.get(currentSql);
      } else {
        ps = prepareStatement(statementScope.getSession(), conn, sql);
        setStatementTimeout(statementScope.getStatement(), ps);
        currentSql = sql;
        statementList.add(ps);
        statementMap.put(currentSql,ps);
        batchResultList.add(new BatchResult(statementScope.getStatement().getId(), sql));
      }
      statementScope.getParameterMap().setParameters(statementScope, ps, parameters);
      ps.addBatch();
      size++;
    }

    public int executeBatch() throws SQLException {
      int totalRowCount = 0;
      Collection<PreparedStatement> psColl = statementMap.values();
      //for (int i = 0, n = statementList.size(); i < n; i++) {
      Iterator<PreparedStatement> it = psColl.iterator();
      //for (int i = 0, n = psColl.size(); i < n; i++) {
      while(it.hasNext()){
        //PreparedStatement ps = (PreparedStatement) statementList.get(i);
       PreparedStatement ps = it.next();
        int[] rowCounts = ps.executeBatch();
        for (int j = 0; j < rowCounts.length; j++) {
          if (rowCounts[j] == Statement.SUCCESS_NO_INFO) {
            // do nothing
          } else if (rowCounts[j] == Statement.EXECUTE_FAILED) {
            throw new SQLException("The batched statement at index " + j + " failed to execute.");
          } else {
            totalRowCount += rowCounts[j];
          }
        }
      }
      return totalRowCount;
    }

Que: After making these changes everything works for us and the performance is very good as it starts using cached PreparedStatements.  Does it look like a proper implementation?  Will it have any other impact that I may not have seen yet?

-- Nitin

mule_user | 9 Jun 23:11 2010
Picon

Select from View (as opposed to table) using iBatis


I am using iBatis (2.5) with DB2 version 8.x and Spring 2.5. Is there any
issue in querying a view (as opposed to table)? It is a very simple select
as:

<resultMap id="codeMap" class="org.impl.CodeBean">
        <result column="TBL_NM"      property="tableName"  
typeHandler="org.our.StringTrimTypeHandler"/>
        <result column="COL_NM"     property="columnName"
typeHandler="org.our.StringTrimTypeHandler"/>
        <result column="CD"            property="code"       
typeHandler="org.our.StringTrimTypeHandler"/>  
        <result column="CD_DESC"   property="shortDesc" 
typeHandler="org.our.StringTrimTypeHandler"/>  
        <result column="CD_LNG_DESC" property="longDesc"  
typeHandler="org.our.StringTrimTypeHandler"/>
</resultMap>

<select id="findAll" resultMap="codeMap">
        select CD from ${jdbc.schema}.V_MY_VIEW
</select>

org.impl.CodeBean is a simple POJO with String attributes only with public
getter and setter. StringTrimTypeHandler are custom code written.

My SQL are working when I am using table, as opposed to View.

When I call the above findAll from JUnit for View, I get exception as:

--    Exception:  org.springframework.jdbc.BadSqlGrammarException: SQL
MAPPING ID: code.findAll; bad SQL grammar []; nested exception is
com.ibatis.common.jdbc.exception.NestedSQLException:   

--- The error occurred in org/.../mapping/code.xml.  

--- The error occurred while applying a parameter map.  

--- Check the code.findAll-InlineParameterMap.  

--- Check the statement (query failed).  

--- Cause: com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -204,
SQLSTATE: 42704, SQLERRMC: MY_SCHEMA.V_MY_VIEW

--    Exception Detail: 
com.ibatis.common.jdbc.exception.NestedSQLException:   

--- The error occurred in org/.../mapping/code.xml.  

I must be missing something. 

Query from View is supported in iBatis, correct?
--

-- 
View this message in context: http://old.nabble.com/Select-from-View-%28as-opposed-to-table%29-using-iBatis-tp28835900p28835900.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

Gmane