|
From: Colin S. <col...@ex...> - 2004-05-28 13:24:07
|
Hmm... I would probably go for adapter...
j=FCrgen h=F6ller [werk3AT] wrote:
>Hmm... you've got a point there. So votes please: "UserCredentialsDataSo=
urceProxy" or "UserCredentialsDataSourceAdapter"? Or maybe a different, e=
ven better name?
>=20
>Juergen
>=20
>P.S.: Let's move this to the developer list.
>=20
>
>________________________________
>
>Von: spr...@li... im Auftrag von Tho=
mas Risberg
>Gesendet: Fr 28.05.2004 13:39
>An: spr...@li...
>Betreff: Re: [Springframework-user] JNDI dataSource with separate user/p=
as sword/schema strings
>
>
>
>Don't want to nit pick about the naming, but I think it looks like an
>Adapter as well as a Proxy.
>
>JdbcTemplate
>|
>|
>getConnection()
>|
>|
>v
>UserCredentialsDataSource
>|
>|
>getConnection(username, password)
>|
>|
>v
>DataSource
>
>Thomas
>
>
>j=FCrgen h=F6ller [werk3AT] wrote:
>
> =20
>
>>Regarding the naming: IMO, such a DataSource is a "proxy" rather than a=
n "adapter", as it exposes the same interface as the target.
>>
>>Juergen
>>
>>
>>________________________________
>>
>>Von: spr...@li... im Auftrag von j=FC=
rgen h=F6ller [werk3AT]
>>Gesendet: Fr 28.05.2004 10:20
>>An: spr...@li...
>>Betreff: Re: [Springframework-user] JNDI dataSource with separate user/=
pas sword/schema strings
>>
>>
>>
>>I consider that a good idea! We've actually discussed it before, exactl=
y for that purpose.
>>
>>So I've just added a "UserCredentialsDataSourceProxy" to our jdbc.datas=
ource package, taking "targetDataSource", "username" and "password" as be=
an properties. On "getConnection()" calls, it simply delegates to the "ge=
tConnection(username, password)" method of the target DataSource with the=
given user credentials.
>>
>>Additionally, there's also the option of setting thread-bound credentia=
ls, via the "setCredentialsForCurrentThread(username, password)" method".=
The application needs to make sure that such thread-bound credentials ar=
e removed at the end of the operation, via the "removeCredentialsFromCurr=
entThread()" method.
>>
>>If noone objects, this will be part of 1.0.2, as it arguably is a simpl=
e and straightforward addition that does not affect any other code.
>>
>>Juergen
>>
>>
>>________________________________
>>
>>Von: spr...@li... im Auftrag von Th=
omas Risberg
>>Gesendet: Fr 28.05.2004 05:04
>>An: spr...@li...
>>Betreff: Re: [Springframework-user] JNDI dataSource with separate user/=
pas sword/schema strings
>>
>>
>>
>>This has come up before and we should figure out the best recommended
>>solution. We could use a custom datasource adapter that has a referenc=
e
>>to the real datasource and adds username/password to the get connection
>>call. This username/password could be set via DI or stored in a thread
>>local in the case of each invocation having their own username/password
>>combo.
>>
>>Thomas
>>
>>
>>Colin Sampaleanu wrote:
>>
>>
>>
>> =20
>>
>>>Robert,
>>>
>>>Your variant below will work actually, since Spring is not going to
>>>get the DataSource and connection from it, but rather Hibernate itself
>>>will get the DataSource from JNDI and do a getConnection(name, pass)
>>>(via its own DatasourceConnectionProvider class).
>>>
>>>As per my previous email, Spring has no ability to call
>>>getConnection(name, pass) on a dataSource, so you need to make sure
>>>that all your operations can be done via Hibernate code... To be safe,
>>>you probably should not use Spring's HibernateTransactionManager and
>>>DataSourceTransactionManager classes, since they make the DataSource
>>>(either set directly or in the case of the former also pulled out from
>>>the SessionFactory) bound to the current thread/transaction, and
>>>expose the ability to get a connection from it with DataSourceUtils,
>>>which has no ability to do anything more than a simple getConnection()
>>>call to get a connection. So you would probably want to run with
>>>JTATransactionManager.
>>>
>>>Juergen, I don't know if you've been following this thread, but we
>>>should think about enhaning Spring to allow specifying a name/pass and
>>>make it user getConnection(name, pass) in that case...
>>>
>>>Colin
>>>
>>>
>>>Loren, Robert wrote:
>>>
>>> =20
>>>
>>> =20
>>>
>>>>Greetings-
>>>>
>>>>Ok, now I've got this working.
>>>>So it seems that I now need something like
>>>>PropertyPlaceholderConfigurer,
>>>>only using JNDI.
>>>>
>>>>----------------------------------------
>>>>IN appcontext.xml:
>>>>
>>>> <!-- Hibernate SessionFactory -->
>>>> <bean id=3D"sessionFactory"
>>>>class=3D"org.springframework.orm.hibernate.LocalSessionFactoryBean">
>>>> <!--<property name=3D"dataSource"><ref
>>>>local=3D"dataSource"/></property>-->
>>>> <property name=3D"mappingResources">
>>>> <value>/WEB-INF/OurApp.hbm.xml</value>
>>>> </property>
>>>> <property name=3D"hibernateProperties">
>>>> <props>
>>>> <prop
>>>>key=3D"hibernate.dialect">${hibernate.dialect}</prop>
>>>> <prop
>>>>key=3D"hibernate.show_sql">${hibernate.showsql}</prop>
>>>> <prop
>>>>key=3D"hibernate.connection.username">${hibernate.connection.username=
}</prop
>>>>
>>>>
>>>>
>>>> <prop
>>>>key=3D"hibernate.connection.password">${hibernate.connection.password=
}</prop
>>>>
>>>>
>>>>
>>>> <prop
>>>>key=3D"hibernate.connection.datasource">${hibernate.connection.dataso=
urce}</
>>>>
>>>>prop>
>>>> </props>
>>>> </property>
>>>> </bean>
>>>>--------------------------------------
>>>>IN jdbc.properties:
>>>>
>>>>hibernate.dialect=3Dnet.sf.hibernate.dialect.DB2Dialect
>>>>hibernate.showsql=3Dtrue
>>>>hibernate.connection.username=3Dme
>>>>hibernate.connection.password=3Dmypassword
>>>>hibernate.connection.datasource=3Djdbc/mydatasource
>>>>
>>>>Let's see what I can find,
>>>>Rob
>>>>
>>>>-----Original Message-----
>>>>From: Loren, Robert [mailto:Rob...@ca...]
>>>>Sent: Thursday, May 27, 2004 7:16 PM
>>>>To: 'spr...@li...'
>>>>Subject: RE: [Springframework-user] JNDI dataSource with separate
>>>>user/pas sword/schema strings
>>>>
>>>>
>>>>Thanks for your reply, Colin.
>>>>
>>>>Yes, we do want the datasource to be setup by the admin in the
>>>>container,
>>>>then accessed by the app. In DB2, you can pass the username and passw=
ord
>>>>to the getConnection() method of the datasource, and that is what
>>>>most of
>>>>our in-house code is doing. We then use the schema name in our querie=
s
>>>>when connecting up. I guess it's the runtime use of these parameters,
>>>>through the session/template, that we're trying to emulate. If the
>>>>datasource could be injected with the user and password somehow, that
>>>>would be fine, but I don't see that as possible.
>>>>
>>>>Hibernate has properties such as "hibernate.connection.username" that
>>>>seem
>>>>available for the SessionFactory. I'm trying to get those to work wit=
h
>>>>strings at the moment. But if successful there, I'd like to somehow s=
wap
>>>>them out with JNDI-located strings.
>>>>
>>>>Hope this gives you more,
>>>>Rob
>>>>
>>>>-----Original Message-----
>>>>From: Colin Sampaleanu [mailto:col...@ex...]
>>>>Sent: Thursday, May 27, 2004 6:47 PM
>>>>To: spr...@li...
>>>>Subject: Re: [Springframework-user] JNDI dataSource with separate
>>>>user/password/schema strings
>>>>
>>>>
>>>>Loren, Robert wrote:
>>>>
>>>>
>>>>
>>>> =20
>>>>
>>>> =20
>>>>
>>>>>Hi,
>>>>>
>>>>>We're looking to deploy into a WAS 5/DB2 environment with a
>>>>>Spring/Hibernate-based application.
>>>>>
>>>>>We're excited, but worried at this point, trying to figure out how
>>>>>to get
>>>>>a pooled data source wired up from WAS's JNDI store.
>>>>>
>>>>>It was very easy to wire the data source itself, using the
>>>>>JndiObjectFactoryBean from looking at the examples. However, our
>>>>>Architecture group wants us to store the name, password, and schema =
we
>>>>>
>>>>> =20
>>>>>
>>>>> =20
>>>>>
>>>>use
>>>>
>>>>
>>>> =20
>>>>
>>>> =20
>>>>
>>>>>externally to the data source itself.
>>>>>
>>>>>I'm looking for something similar to how the strings are stored in t=
he
>>>>>jdbc.properties file for DriverManagerDataSource, only maybe using t=
he
>>>>>JndiObjectFactoryBeans wired into the SessionFactory properties.
>>>>>
>>>>>Does anyone have sample code on how this might be configured? Should=
I
>>>>>maybe be posting this to the developer group?
>>>>>
>>>>>Thanks very much for any help in advance, and thanks for Spring,
>>>>>
>>>>>Rob
>>>>>
>>>>>
>>>>>
>>>>> =20
>>>>>
>>>>> =20
>>>>>
>>>>Rob,
>>>>
>>>>I'm a little confused about what you're trying to do, and about the
>>>>DataSource lifecycle you want to achieve. I presume that as opposed
>>>>to the normal scenario where a sysadmin or deployer sets up the one
>>>>datasource (which gets bound to JNDI) in the appserver, you would
>>>>like Spring to create the datasource, based on config params which
>>>>are provided by/to Spring?
>>>>
>>>>There is nothing stopping you from creating something like an Apache
>>>>DBCP Datasource, and using that. However, you are then going to give
>>>>up the much more robust WAS DataSource impl. which is integrated into
>>>>the container and the container's transaction manager.
>>>>
>>>>Can you provide more details?
>>>>
>>>>Regards,
>>>>Colin
>>>>
>>>>
>>>> =20
>>>>
|