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 Kai Grabfelder <no...@kaigrabfelder.de> on 2009/02/01 15:18:44 UTC

Re: Using iBatis outside servlet container

Theres a Mock JNDI implementation within the spring library. We are using it for several productive batch
application.

http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/mock/jndi/package-summary.html

Regards

Kai

--- Original Nachricht ---
Absender: Ian Zabel
Datum: 30.01.2009 18:10
> This is how I create a mock JNDI datasource for our unit tests to match the
> one we normally get from Tomcat:
> // Create initial context
>             System.setProperty( Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.naming.java.javaURLContextFactory" );
>             System.setProperty( Context.URL_PKG_PREFIXES,
> "org.apache.naming" );
> 
>             Hashtable env = new Hashtable();
>             env.put( Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.naming.java.javaURLContextFactory" );
>             env.put( Context.URL_PKG_PREFIXES, "org.apache.naming" );
> 
>             try
>             {
>                 InitialContext ic = new InitialContext( env );
> 
>                 ic.createSubcontext( "java:" );
>                 ic.createSubcontext( "java:/comp" );
>                 ic.createSubcontext( "java:/comp/env" );
>                 ic.createSubcontext( "java:/comp/env/jdbc" );
> 
>                 // Construct DataSource
>                 ds = new OracleConnectionPoolDataSource();
>                 ds.setURL( JDBC_CONNECT_STRING );
>                 ds.setUser( USER );
>                 ds.setPassword( PASSWORD );
> 
>                 ic.bind( new TestBaseClass().getLookupName(), ds );
>             }
>             catch ( Exception e )
>             {
>                 //e.printStackTrace();
>                 // Name java: is already bound in this Context
>             }
> 
> Maybe something like that will help.
> 
> Ian.
> 
> On Fri, Jan 30, 2009 at 9:35 AM, Kai Kousa <ka...@jadecon.fi> wrote:
> 
>> Mock JNDI sounds useful as it would prevent separate configs for web-app
>> and the console-app.
>>
>> Can you give any pointers for doing this? I'm not very familiar with JNDI
>>
>> Kai
>>
>>
>> Larry Meadors wrote:
>>
>>> You could also do a very simple mock JNDI implementation - it's less
>>> than 100 lines of code.
>>>
>>> That way you could use the same sqlmapconfig.xml in both places.
>>>
>>> Larry
>>>
>>>
>>> On Fri, Jan 30, 2009 at 7:24 AM, Nathan Maves <na...@gmail.com>
>>> wrote:
>>>
>>>
>>>> There is nothing in the IB library that is tied to a servlet container.
>>>> You can use any of the various datasources from IB.  c3p0 is just another
>>>> DB
>>>> connection pool so use it just as you would dbcp or the built in SIMPLE
>>>> db
>>>> connection pool.
>>>> Nathan
>>>>
>>>> On Fri, Jan 30, 2009 at 5:14 AM, charlie bird <ze...@yahoo.co.uk>
>>>> wrote:
>>>>
>>>>
>>>>> I've got similar question
>>>>>
>>>>> Has anyone done this sort of thing with c3p0?
>>>>> Can I use the same datasource xml that would be used for servlet
>>>>> container
>>>>> config?
>>>>>
>>>>> Thanks
>>>>>
>>>>> Charlie
>>>>>
>>>>> --- On Fri, 30/1/09, Jan Kriesten <kr...@mail.footprint.de> wrote:
>>>>>
>>>>>
>>>>>
>>>>>> From: Jan Kriesten <kr...@mail.footprint.de>
>>>>>> Subject: Re: Using iBatis outside servlet container
>>>>>> To: user-java@ibatis.apache.org
>>>>>> Date: Friday, 30 January, 2009, 9:43 AM
>>>>>> Hi,
>>>>>>
>>>>>>
>>>>>>
>>>>>>> What do I have to do in order to provide a data source
>>>>>>>
>>>>>>>
>>>>>> to iBatis?
>>>>>>
>>>>>> use
>>>>>>
>>>>>> <transactionManager type="JDBC">
>>>>>>  <dataSource type="SIMPLE">
>>>>>>    <property name="JDBC.Driver"
>>>>>> value="..."/>
>>>>>>    ...
>>>>>>  </dataSource>
>>>>>> </transactionManager>
>>>>>>
>>>>>> in your sqlMapConfig. You're not bound to JNDI with
>>>>>> iBATIS.
>>>>>>
>>>>>> Best regards, --- Jan.
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>