You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Wolf-Dieter Mische <Mi...@gmx.at> on 2008/06/22 21:21:01 UTC

Changing the Database at runtime

Hello,

in my current project I have to change the database at runtime. Does anybody do this before? I found some information on spring and ibatis, but in my case I have a simple java application. 

I tried it with changing a properties file and creating a new SqlMapClient, but he always uses the old database.

heres my code:

        String propfile = "com/mydom/ibatis.properties";
        Properties props = Resources.getResourceAsProperties(propfile);

        String sqlmap = "./src/com/mydom/SqlMapConfig.xml";
        Reader reader = new FileReader(sqlmap);
        SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);

        //doing some inserts, etc.

        props.setProperty("url", "jdbc:mysql://localhost:3306/otherdatabase");
        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);

        //doing some inserts, etc

Any ideas?

greetz
wolle
-- 
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx

Re: Changing the Database at runtime

Posted by Clinton Begin <cl...@gmail.com>.
If you think it's a bug, zip up a failing unit test and attach it to a
JIRA request.

Cheers,
Clinton

On Sun, Jun 22, 2008 at 2:57 PM, Wolf-Dieter Mische <Mi...@gmx.at> wrote:
> hm... currently I separated the creation in a parameterless function and getting the same result. before I calling the function I do this:
> ((SimpleDataSource)sqlMap.getDataSource()).forceCloseAll();
> sqlMap = null;
> System.gc();
> createNewInstance();
>
> The logging says: SimpleDataSource forcefully closed/removed all connections.
>
> So it looks like that the connections are closed. There must be some remaining object in ibatis.
>
>
> greetz
> wolle
>
> -------- Original-Nachricht --------
>> Datum: Sun, 22 Jun 2008 14:15:57 -0600
>> Von: "Clinton Begin" <cl...@gmail.com>
>> An: user-java@ibatis.apache.org
>> Betreff: Re: Changing the Database at runtime
>
>> It does pool connections, but it's per SqlMapClient instance, so:
>>
>>        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);
>>
>> Would result in a new instance that had its own connection pool.
>> Nothing magical here... so double check that you're using the right
>> instance everywhere.
>>
>> One other thing though, this isn't an intended use for iBATIS -- to be
>> creating SqlMapClient instances like this.  You might want to force
>> close all of the connections from the pool.  If you're using
>> SimpleDataSource, you can do so like this:
>>
>> ((SimpleDataSource)sqlMap.getDataSource()).forceCloseAll();
>>
>> Clinton
>>
>> On Sun, Jun 22, 2008 at 2:04 PM, Wolf-Dieter Mische <Mi...@gmx.at> wrote:
>> > It doesn't work. I also tried it with a second properties file. It seems
>> to me that ibatis caches the connection or something.
>> >
>> > Any other suggestions?
>> >
>> > greetz
>> > wolle
>> >
>> >
>> > -------- Original-Nachricht --------
>> >> Datum: Sun, 22 Jun 2008 13:53:16 -0600
>> >> Von: "Clinton Begin" <cl...@gmail.com>
>> >> An: user-java@ibatis.apache.org
>> >> Betreff: Re: Changing the Database at runtime
>> >
>> >>  Properties props = Resources.getResourceAsProperties(propfile);
>> >>
>> >> That line uses the classloader to load the props file.   It's likely
>> >> caching the first time you load it.
>> >>
>> >> Try using a FileReader instead.
>> >>
>> >> Clinton
>> >>
>> >> On Sun, Jun 22, 2008 at 1:21 PM, Wolf-Dieter Mische <Mi...@gmx.at>
>> wrote:
>> >> > Hello,
>> >> >
>> >> > in my current project I have to change the database at runtime. Does
>> >> anybody do this before? I found some information on spring and ibatis,
>> but in
>> >> my case I have a simple java application.
>> >> >
>> >> > I tried it with changing a properties file and creating a new
>> >> SqlMapClient, but he always uses the old database.
>> >> >
>> >> > heres my code:
>> >> >
>> >> >        String propfile = "com/mydom/ibatis.properties";
>> >> >        Properties props =
>> Resources.getResourceAsProperties(propfile);
>> >> >
>> >> >        String sqlmap = "./src/com/mydom/SqlMapConfig.xml";
>> >> >        Reader reader = new FileReader(sqlmap);
>> >> >        SqlMapClient sqlMap =
>> >> SqlMapClientBuilder.buildSqlMapClient(reader, props);
>> >> >
>> >> >        //doing some inserts, etc.
>> >> >
>> >> >        props.setProperty("url",
>> >> "jdbc:mysql://localhost:3306/otherdatabase");
>> >> >        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);
>> >> >
>> >> >        //doing some inserts, etc
>> >> >
>> >> > Any ideas?
>> >> >
>> >> > greetz
>> >> > wolle
>> >> > --
>> >> > GMX startet ShortView.de. Hier findest Du Leute mit Deinen
>> Interessen!
>> >> > Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx
>> >> >
>> >
>> > --
>> > Psssst! Schon vom neuen GMX MultiMessenger gehört?
>> > Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
>> >
>
> --
> Psssst! Schon vom neuen GMX MultiMessenger gehört?
> Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
>

Performance question

Posted by Brian Parkinson <pa...@avaning.com>.
Hello:

I'm using iBATIS with MySQL and Java, and all is well. Started to do
some performance testing, and discovered that things are pretty slow,
and so wondering if someone might have some insight. I apologize, as
this is not really iBATIS per se, but I can't get great help on the
MySQL forums...

I have a simple table, with a BLOB entry, and I'm seeing long (~300ms)
times for updates. The table is InnoDB. The datasource:

	<bean id="mapConfig"
class="org.springframework.core.io.ClassPathResource">
		<constructor-arg>
	
<value>com/ecobee/foundation/dao/ibatis/SqlMapConfig.xml</value>
		</constructor-arg>
	</bean>
	 
	<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName"
value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql:///ecobee" />
		<property name="username" value="XXX" />
		<property name="password" value="XXX" />	
		<property name="initialSize" value="10" />
		<property name="maxActive" value="100" />	
		<property name="maxIdle" value="10" />
	</bean>

	<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" ref="mapConfig" />
	</bean>

I was using the Spring transaction manager stuff, but pulled it out for
the time being in the hopes of improving performance.

So, the DAO simple maps a number of data members to columns, and then
compresses and BLOBs the final column. There is no contention for row,
and my understanding is that InnoDB will do row level locking.

Anyone out there have any ideas that I might try to get performance
better? It seems to take a very long time to update the rows. The
overall size of the BLOB is about 2K or so (not that big).

Any hints or suggestions appreciated - I'm not a DB guy.

Regards,

Brian Parkinson
Avaning Inc.


Re: Changing the Database at runtime

Posted by Wolf-Dieter Mische <Mi...@gmx.at>.
hm... currently I separated the creation in a parameterless function and getting the same result. before I calling the function I do this:
((SimpleDataSource)sqlMap.getDataSource()).forceCloseAll();
sqlMap = null;
System.gc();
createNewInstance();

The logging says: SimpleDataSource forcefully closed/removed all connections.

So it looks like that the connections are closed. There must be some remaining object in ibatis.


greetz
wolle

-------- Original-Nachricht --------
> Datum: Sun, 22 Jun 2008 14:15:57 -0600
> Von: "Clinton Begin" <cl...@gmail.com>
> An: user-java@ibatis.apache.org
> Betreff: Re: Changing the Database at runtime

> It does pool connections, but it's per SqlMapClient instance, so:
> 
>        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);
> 
> Would result in a new instance that had its own connection pool.
> Nothing magical here... so double check that you're using the right
> instance everywhere.
> 
> One other thing though, this isn't an intended use for iBATIS -- to be
> creating SqlMapClient instances like this.  You might want to force
> close all of the connections from the pool.  If you're using
> SimpleDataSource, you can do so like this:
> 
> ((SimpleDataSource)sqlMap.getDataSource()).forceCloseAll();
> 
> Clinton
> 
> On Sun, Jun 22, 2008 at 2:04 PM, Wolf-Dieter Mische <Mi...@gmx.at> wrote:
> > It doesn't work. I also tried it with a second properties file. It seems
> to me that ibatis caches the connection or something.
> >
> > Any other suggestions?
> >
> > greetz
> > wolle
> >
> >
> > -------- Original-Nachricht --------
> >> Datum: Sun, 22 Jun 2008 13:53:16 -0600
> >> Von: "Clinton Begin" <cl...@gmail.com>
> >> An: user-java@ibatis.apache.org
> >> Betreff: Re: Changing the Database at runtime
> >
> >>  Properties props = Resources.getResourceAsProperties(propfile);
> >>
> >> That line uses the classloader to load the props file.   It's likely
> >> caching the first time you load it.
> >>
> >> Try using a FileReader instead.
> >>
> >> Clinton
> >>
> >> On Sun, Jun 22, 2008 at 1:21 PM, Wolf-Dieter Mische <Mi...@gmx.at>
> wrote:
> >> > Hello,
> >> >
> >> > in my current project I have to change the database at runtime. Does
> >> anybody do this before? I found some information on spring and ibatis,
> but in
> >> my case I have a simple java application.
> >> >
> >> > I tried it with changing a properties file and creating a new
> >> SqlMapClient, but he always uses the old database.
> >> >
> >> > heres my code:
> >> >
> >> >        String propfile = "com/mydom/ibatis.properties";
> >> >        Properties props =
> Resources.getResourceAsProperties(propfile);
> >> >
> >> >        String sqlmap = "./src/com/mydom/SqlMapConfig.xml";
> >> >        Reader reader = new FileReader(sqlmap);
> >> >        SqlMapClient sqlMap =
> >> SqlMapClientBuilder.buildSqlMapClient(reader, props);
> >> >
> >> >        //doing some inserts, etc.
> >> >
> >> >        props.setProperty("url",
> >> "jdbc:mysql://localhost:3306/otherdatabase");
> >> >        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);
> >> >
> >> >        //doing some inserts, etc
> >> >
> >> > Any ideas?
> >> >
> >> > greetz
> >> > wolle
> >> > --
> >> > GMX startet ShortView.de. Hier findest Du Leute mit Deinen
> Interessen!
> >> > Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx
> >> >
> >
> > --
> > Psssst! Schon vom neuen GMX MultiMessenger gehört?
> > Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
> >

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

Re: Changing the Database at runtime

Posted by Clinton Begin <cl...@gmail.com>.
It does pool connections, but it's per SqlMapClient instance, so:

       sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);

Would result in a new instance that had its own connection pool.
Nothing magical here... so double check that you're using the right
instance everywhere.

One other thing though, this isn't an intended use for iBATIS -- to be
creating SqlMapClient instances like this.  You might want to force
close all of the connections from the pool.  If you're using
SimpleDataSource, you can do so like this:

((SimpleDataSource)sqlMap.getDataSource()).forceCloseAll();

Clinton

On Sun, Jun 22, 2008 at 2:04 PM, Wolf-Dieter Mische <Mi...@gmx.at> wrote:
> It doesn't work. I also tried it with a second properties file. It seems to me that ibatis caches the connection or something.
>
> Any other suggestions?
>
> greetz
> wolle
>
>
> -------- Original-Nachricht --------
>> Datum: Sun, 22 Jun 2008 13:53:16 -0600
>> Von: "Clinton Begin" <cl...@gmail.com>
>> An: user-java@ibatis.apache.org
>> Betreff: Re: Changing the Database at runtime
>
>>  Properties props = Resources.getResourceAsProperties(propfile);
>>
>> That line uses the classloader to load the props file.   It's likely
>> caching the first time you load it.
>>
>> Try using a FileReader instead.
>>
>> Clinton
>>
>> On Sun, Jun 22, 2008 at 1:21 PM, Wolf-Dieter Mische <Mi...@gmx.at> wrote:
>> > Hello,
>> >
>> > in my current project I have to change the database at runtime. Does
>> anybody do this before? I found some information on spring and ibatis, but in
>> my case I have a simple java application.
>> >
>> > I tried it with changing a properties file and creating a new
>> SqlMapClient, but he always uses the old database.
>> >
>> > heres my code:
>> >
>> >        String propfile = "com/mydom/ibatis.properties";
>> >        Properties props = Resources.getResourceAsProperties(propfile);
>> >
>> >        String sqlmap = "./src/com/mydom/SqlMapConfig.xml";
>> >        Reader reader = new FileReader(sqlmap);
>> >        SqlMapClient sqlMap =
>> SqlMapClientBuilder.buildSqlMapClient(reader, props);
>> >
>> >        //doing some inserts, etc.
>> >
>> >        props.setProperty("url",
>> "jdbc:mysql://localhost:3306/otherdatabase");
>> >        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);
>> >
>> >        //doing some inserts, etc
>> >
>> > Any ideas?
>> >
>> > greetz
>> > wolle
>> > --
>> > GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
>> > Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx
>> >
>
> --
> Psssst! Schon vom neuen GMX MultiMessenger gehört?
> Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
>

Re: Changing the Database at runtime

Posted by Wolf-Dieter Mische <Mi...@gmx.at>.
It doesn't work. I also tried it with a second properties file. It seems to me that ibatis caches the connection or something.

Any other suggestions?

greetz 
wolle


-------- Original-Nachricht --------
> Datum: Sun, 22 Jun 2008 13:53:16 -0600
> Von: "Clinton Begin" <cl...@gmail.com>
> An: user-java@ibatis.apache.org
> Betreff: Re: Changing the Database at runtime

>  Properties props = Resources.getResourceAsProperties(propfile);
> 
> That line uses the classloader to load the props file.   It's likely
> caching the first time you load it.
> 
> Try using a FileReader instead.
> 
> Clinton
> 
> On Sun, Jun 22, 2008 at 1:21 PM, Wolf-Dieter Mische <Mi...@gmx.at> wrote:
> > Hello,
> >
> > in my current project I have to change the database at runtime. Does
> anybody do this before? I found some information on spring and ibatis, but in
> my case I have a simple java application.
> >
> > I tried it with changing a properties file and creating a new
> SqlMapClient, but he always uses the old database.
> >
> > heres my code:
> >
> >        String propfile = "com/mydom/ibatis.properties";
> >        Properties props = Resources.getResourceAsProperties(propfile);
> >
> >        String sqlmap = "./src/com/mydom/SqlMapConfig.xml";
> >        Reader reader = new FileReader(sqlmap);
> >        SqlMapClient sqlMap =
> SqlMapClientBuilder.buildSqlMapClient(reader, props);
> >
> >        //doing some inserts, etc.
> >
> >        props.setProperty("url",
> "jdbc:mysql://localhost:3306/otherdatabase");
> >        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);
> >
> >        //doing some inserts, etc
> >
> > Any ideas?
> >
> > greetz
> > wolle
> > --
> > GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
> > Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx
> >

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

Re: Changing the Database at runtime

Posted by Clinton Begin <cl...@gmail.com>.
 Properties props = Resources.getResourceAsProperties(propfile);

That line uses the classloader to load the props file.   It's likely
caching the first time you load it.

Try using a FileReader instead.

Clinton

On Sun, Jun 22, 2008 at 1:21 PM, Wolf-Dieter Mische <Mi...@gmx.at> wrote:
> Hello,
>
> in my current project I have to change the database at runtime. Does anybody do this before? I found some information on spring and ibatis, but in my case I have a simple java application.
>
> I tried it with changing a properties file and creating a new SqlMapClient, but he always uses the old database.
>
> heres my code:
>
>        String propfile = "com/mydom/ibatis.properties";
>        Properties props = Resources.getResourceAsProperties(propfile);
>
>        String sqlmap = "./src/com/mydom/SqlMapConfig.xml";
>        Reader reader = new FileReader(sqlmap);
>        SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);
>
>        //doing some inserts, etc.
>
>        props.setProperty("url", "jdbc:mysql://localhost:3306/otherdatabase");
>        sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, props);
>
>        //doing some inserts, etc
>
> Any ideas?
>
> greetz
> wolle
> --
> GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
> Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx
>