[Building Sakai] jdbc spring slowly

Aaron Zeckoski aaronz at vt.edu
Mon Jun 1 07:28:28 PDT 2009


This is just a sample showing that you can swap beans which implment
the same interface. You do not need a bean like that at all. My guess
is that your transactions are not closing and are instead timing out
but that is just a guess without more information.
-AZ


On Mon, Jun 1, 2009 at 3:22 PM, yolima u <yolimita.uribe at gmail.com> wrote:
>
> hi, i have another question,
> in your spring-bean.xml, your declare two beans in the first block of data
> access,
>
> <!-- create a tasklistManagerMemory bean, use the memory implementation -->
>        <bean id="org.sakaiproject.tool.tasklist.api.TaskListManagerMemory"
>                class="org.sakaiproject.tool.tasklist.impl.TaskListManagerMemoryImpl" />
>
>        <!-- create a tasklistManagerJdbc bean which defines a jdbcTemplate
>                using the Sakai datasource and connection pool,
>                This is ONLY used for the JDBC implementation of the manager -->
>        <bean id="org.sakaiproject.tool.tasklist.api.TaskListManagerJdbc"
>                class="org.sakaiproject.tool.tasklist.impl.TaskListManagerJdbcImpl"
>                init-method="init">
>                <property name="jdbcTemplate">
>                        <bean class="org.springframework.jdbc.core.JdbcTemplate">
>                                <constructor-arg type="javax.sql.DataSource">
>                                        <ref bean="javax.sql.DataSource" />
>                                </constructor-arg>
>                        </bean>
>                </property>
>        </bean>
>
> do the two beans work together?
>
> i just have declare the second one, do i need the first one for my tool
> works?
>
> it can been the solution to my problem?
>
> how i just have the second one bean, i call it in my jsp page. If i have to
> declare the first one bean, where do i call it?, because it implements the
> same interface that the second bean. I'm a little confused.
>
> thaks
>
>
> Aaron Zeckoski wrote:
>>
>> Normally spring jdbc will do a commit for each update/insert/delete
>> that you run using the jdbctemplate. If you are doing a lot of these
>> without a transactional wrapper then it can be a little bit expensive
>> (though not typically the amount of time you are talking about).
>>
>> I recommend you try using the spring JdbcDaoSupport class and take a
>> look at the example code here:
>> http://bugs.sakaiproject.org/confluence/display/BOOT/Spring+JDBC+Info
>>
>> It may help to clean up all the empty try/finally blocks in your code
>> for readability when pasting it here. You also might want to send
>> along your spring configuration file along with your code.
>> Hope this helps
>> :-)
>> -AZ
>>
>>
>> On Wed, May 27, 2009 at 1:54 AM, yolima u <yolimita.uribe at gmail.com>
>> wrote:
>>>
>>> hi all,
>>>  i'm developing  a tool in sakai using  jdbc spring for the connection to
>>> the data base
>>> i'm working with a bean where i create all the functions for the data
>>> base:
>>>
>>> public class MetGwBean {
>>>
>>>        private DataSource dataSource;
>>>
>>>        public void setDataSource(DataSource dataSource) {
>>>                this.dataSource = dataSource;
>>>        }
>>>
>>>
>>>
>>>        public void Insertar(String sql,Object[] obj)throws SQLException{
>>>
>>>
>>>           JdbcTemplate sel = new JdbcTemplate(dataSource);
>>>
>>>           try {
>>>                   sel.update(sql, obj);
>>>                   // do things with your connection (select, insert,
>>> delete, etc.)
>>>           } finally {
>>>
>>>           }
>>>        }
>>>
>>>        public List SelectObjetos(String sql,Object[] obj)throws
>>> SQLException{
>>>
>>>                JdbcTemplate sel = new JdbcTemplate(dataSource);
>>>                try{
>>>                        return sel.queryForList(sql, obj, String.class);
>>>                        }finally{
>>>
>>>                        }
>>>        }
>>>
>>>        public List Selectsolo(String sql)throws SQLException{
>>>
>>>                JdbcTemplate sel = new JdbcTemplate(dataSource);
>>>                try{
>>>                        return sel.queryForList(sql,String.class);
>>>                        }finally{
>>>
>>>                        }
>>>        }
>>>
>>>        public void Borrar(String sql,Object[] obj)throws SQLException{
>>>
>>>
>>>                   JdbcTemplate sel = new JdbcTemplate(dataSource);
>>>
>>>                   try {
>>>                           sel.update(sql, obj);
>>>                           // do things with your connection (select,
>>> insert, delete, etc.)
>>>                   } finally {
>>>
>>>                   }
>>>
>>>        }
>>>
>>>        public void Actualizar(String sql,Object[] obj)throws
>>> SQLException{
>>>
>>>
>>>                   JdbcTemplate sel = new JdbcTemplate(dataSource);
>>>
>>>                   try {
>>>                           sel.update(sql, obj);
>>>                           // do things with your connection (select,
>>> insert, delete, etc.)
>>>                   } finally {
>>>
>>>                   }
>>>
>>>        }
>>>
>>>        public String Selectid(String sql,Object[] obj)throws
>>> SQLException{
>>>
>>>                JdbcTemplate sel = new JdbcTemplate(dataSource);
>>>                try{
>>>                        return (String)sel.queryForObject(sql, obj,
>>> String.class);
>>>                        }
>>>                finally{
>>>
>>>                        }
>>>        }
>>>
>>>        public int Selectint(String sql,Object[] obj)throws SQLException{
>>>
>>>                JdbcTemplate sel = new JdbcTemplate(dataSource);
>>>                try{
>>>                        return sel.queryForInt(sql, obj);
>>>                        }
>>>                finally{
>>>
>>>                        }
>>>        }
>>> }
>>>
>>>
>>>
>>> later i call this functions in a jsp page, for example:
>>>
>>>
>>>
>>> if (request.getParameter("guardar")!=null)
>>>        {
>>>                if (request.getParameter("textarea")!=null)
>>>                {
>>>                        objgen.setProyecto(bean2.getCurrentSiteId());//id
>>> del proyecto
>>>                        String
>>> idobgen=bean.Selectid(objgen.SqlObjId(),objgen.ObjetoBuscar(objgen));//buscar
>>> el id del obj general
>>>
>>>  objesp.setObjgeneral(Integer.parseInt(idobgen));//id de obj general en
>>> obj esp
>>>
>>>  objesp.setdescObjetivo(request.getParameter("textarea"));
>>>                        objesp.setAutor(bean2.getCurrentUserId());
>>>                        objesp.setestado("en definicion");
>>>                        objesp.setprioridad(0);
>>>
>>>  bean.Insertar(objesp.SqlInsertar(),objesp.ObjetoInsertar(objesp));
>>>                        response.sendRedirect("objetivos_esp.jsp");
>>>                        return;
>>>                }
>>>        }
>>>
>>> the problem is that the tool is fast for to do the select, but the tool
>>> takes so much time for to do the inserts, like 3 to 4 minutes.
>>>
>>> and in some jsp pages i need show data of the data base that i just
>>> insert
>>> to the DB, but how the tool does this so slowly, the jsp page can't show
>>> this data.
>>>
>>> why does the tool do the insert to slowly?
>>> what can i do for do this more fast?
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/jdbc-spring-slowly-tp23734131p23734131.html
>>> Sent from the Sakai - Development mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> sakai-dev mailing list
>>> sakai-dev at collab.sakaiproject.org
>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>
>>> TO UNSUBSCRIBE: send email to
>>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>>> "unsubscribe"
>>>
>>
>>
>>
>> --
>> Aaron Zeckoski (aaronz at vt.edu)
>> Senior Research Engineer - CARET - Cambridge University
>> [http://bugs.sakaiproject.org/confluence/display/~aaronz/]
>> Sakai Fellow - [http://aaronz-sakai.blogspot.com/]
>> _______________________________________________
>> sakai-dev mailing list
>> sakai-dev at collab.sakaiproject.org
>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>
>> TO UNSUBSCRIBE: send email to
>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>> "unsubscribe"
>>
>
> --
> View this message in context: http://www.nabble.com/jdbc-spring-slowly-tp23734131p23815695.html
> Sent from the Sakai - Development mailing list archive at Nabble.com.
>
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>
> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"



-- 
Aaron Zeckoski (aaronz at vt.edu)
Senior Research Engineer - CARET - Cambridge University
https://twitter.com/azeckoski - http://www.linkedin.com/in/azeckoski
http://aaronz-sakai.blogspot.com/ -
http://confluence.sakaiproject.org/confluence/display/~aaronz/


More information about the sakai-dev mailing list