Hola tu clase, la que me has pasado, que no he podido ponerla ya que
implemente una interfaz que no la tengo, me la he convertido a esto que te
pongo abajo.

Luego lo que pretendo es probarlo desde una clase main para lo cual hago:

public class PruebaIbatis extends MyAppSqlconfig{
        public static void main (String args[]){
                MyAppSqlconfig f;
                try{
                        Object cat = 
(Object)f.getObject("getCategoriasById",new Integer(3));
                }catch(Exception e){
                        e.printStackTrace();
                }
        }
}
pero me da un error diciendome que la f no esta inicializada que es un
objeto del tipo de la clase que te pongo abajo, la qu ehe modificado con
la tuya.
me peudes dar un empujoncillo ma a ver si lo consigo?
Muchas gracias por tu ayuda.
De veras.


import java.io.Reader;
import java.sql.SQLException;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class MyAppSqlconfig {
        private static final SqlMapClient sqlMap;
        static {
                try {
                        String resource = "SqlMapConfig.xml";
                        Reader reader = Resources.getResourceAsReader(resource);
                        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new RuntimeException(
                                "Error initializing MyAppSqlConfig class.Cause 
: " + e);
                }
        }

        public static SqlMapClient getSqlMapInstance() {
                return sqlMap;
        }

        public final Object getObject(String statementName, Object 
parameterObject)
                throws Exception {
                Object result = null;

                try {
                        sqlMap.startTransaction();
                        result = sqlMap.queryForObject(statementName, 
parameterObject);
                        sqlMap.commitTransaction();
                } catch (Exception e) {
                        try {
                                sqlMap.endTransaction();
                        } catch (SQLException ex) {
                                ex.printStackTrace();
                        }
                        e.printStackTrace();
                }
                return result;
        }
}//clase


> Muy buenas!!!
> Necesitas una  clase que carge tu configuración. Te
> mando el código de la mía con la que realizo las
> transacciones. Lo único que tienes que hacer es
> extender a la que te mando y utilizar los métodos de
> la superclase, o  sea, los de mi clase abstracta,
> desde la subclase.
> public class AbstractUnafeDAO implements IUnafeDAO {
>       public static int INSERT_BATCH = 0;
>       public static int DELETE_BATCH = 1;
>       public static int UPDATE_BATCH = 2;
>
>       private static Log log =
> LogFactory.getLog(AbstractUnafeDAO.class);
>       private static SqlMapClient sqlMap = null;
>
>       static {
>               // CARGA ESTATICA DE LOS PARAMETROS
>               try {
>                       String resource =
> "com/unafe/dao/conf/sql-map-config.xml";
>                       Reader reader =
> Resources.getResourceAsReader(resource);
>                       sqlMap =
> SqlMapClientBuilder.buildSqlMapClient(reader);
>                       reader.close();
>               } catch (Exception ex) {
>                       log.error("AbstractUnafeDAO static block: " + ex);
>                       throw new RuntimeException("Error Initializing
> AbstractUnafeDAO :" + ex);
>               }
>       }
>
>       public final List getList(String statementName,
> Object parameterObject) throws SQLException {
>               List list = null;
>
>               try {
>                       sqlMap.startTransaction();
>                       list = sqlMap.queryForList(statementName,
> parameterObject);
>                       sqlMap.commitTransaction();
>               } catch (SQLException e) {
>                       try {
>                               sqlMap.endTransaction();
>                       } catch (SQLException ex) {
>                               log.error("AbstractUnafeDAO
> getList.endTransaction: " + ex);
>                               throw ex;
>                       }
>                       log.error("AbstractUnafeDAO
> getList.commitTransaction: " + e);
>                       throw e;
>               }
>
>               return list;
>       }
>
>       public final Object getObject(String statementName,
> Object parameterObject) throws SQLException {
>               Object result = null;
>
>               try {
>                       sqlMap.startTransaction();
>                       result = sqlMap.queryForObject(statementName,
> parameterObject);
>                       sqlMap.commitTransaction();
>               } catch (SQLException e) {
>                       try {
>                               sqlMap.endTransaction();
>                       } catch (SQLException ex) {
>                               log.error("AbstractUnafeDAO
> getObject.endTransaction: " + ex);
>                               throw ex;
>                       }
>                       log.error("AbstractUnafeDAO
> getObject.commitTransaction: " + e);
>                       throw e;
>               }
>
>               return result;
>       }
>
>
>       public final int update(String statementName, Object
> parameterObject) throws SQLException {
>               int result = 0;
>
>               try {
>                       sqlMap.startTransaction();
>                       result = sqlMap.update(statementName,
> parameterObject);
>                       sqlMap.commitTransaction();
>               } catch (SQLException e) {
>                       try {
>                               sqlMap.endTransaction();
>                       } catch (SQLException ex) {
>                               log.error("AbstractUnafeDAO 
> update.endTransaction:
> " + ex);
>                               throw ex;
>                       }
>                       log.error("AbstractUnafeDAO
> update.commitTransaction: " + e);
>                       throw e;
>               }
>
>               return result;
>       }
>
>       public final void insert(String statementName, Object
> parameterObject) throws SQLException {
>               try {
>                       sqlMap.startTransaction();
>                       sqlMap.insert(statementName, parameterObject);
>                       sqlMap.commitTransaction();
>               } catch (SQLException e) {
>                       try {
>                               sqlMap.endTransaction();
>                       } catch (SQLException ex) {
>                               log.error("AbstractUnafeDAO 
> insert.endTransaction:
> " + ex);
>                               throw ex;
>                       }
>                       log.error("AbstractUnafeDAO
> insert.commitTransaction: " + e);
>                       throw e;
>               }
>       }
>
>       public final void delete(String statementName, Object
> parameterObject) throws SQLException {
>               try {
>                       sqlMap.startTransaction();
>                       sqlMap.delete(statementName, parameterObject);
>                       sqlMap.commitTransaction();
>               } catch (SQLException e) {
>                       try {
>                               sqlMap.endTransaction();
>                       } catch (SQLException ex) {
>                               log.error("AbstractUnafeDAO 
> delete.endTransaction:
> " + ex);
>                               throw ex;
>                       }
>                       log.error("AbstractUnafeDAO
> delete.commitTransaction: " + e);
>                       throw e;
>               }
> /*            finally{
>                       try {
>                               sqlMap.endTransaction();
>                       } catch (SQLException ex) {
>                               throw ex;
>                       }
>               }
>               */
>       }
>
>       public final void executeBatch(int accion, String
> statementName, List objs) throws SQLException{
>               try {
>                       sqlMap.startTransaction();
>                       sqlMap.startBatch();
>                       for(int i=0;i<objs.size();i++){
>                               if(accion==INSERT_BATCH)
>                                       sqlMap.insert(statementName, 
> objs.get(i));
>                               else if(accion==UPDATE_BATCH)
>                                       sqlMap.update(statementName, 
> objs.get(i));
>                               else if(accion==DELETE_BATCH)
>                                       sqlMap.delete(statementName, 
> objs.get(i));
>                       }
>                       sqlMap.executeBatch();
>                       sqlMap.commitTransaction();
>               } catch (SQLException e) {
>                       try {
>                               sqlMap.endTransaction();
>                       } catch (SQLException ex) {
>                               log.error("AbstractUnafeDAO
> executeBatch.endTransaction: " + ex);
>                               throw ex;
>                       }
>                       log.error("AbstractUnafeDAO
> executeBatch.commitTransaction: " + e);
>                       throw e;
>               }
>       }
> }
>
> Saludos
>
>
>
> ______________________________________________
> Renovamos el Correo Yahoo!
> Nuevos servicios, más seguridad
> http://correo.yahoo.es
>


Reply via email to