//users@appfuse.dev.java.net

hi,

i´m trying use "org.springframework.jdbc.datasource.DriverManagerDataSource"
to around my problem of connect with distinct users in my datasource.

reource.xml

    <bean id="myDriverManagerDataSourceUrl"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
destroy-method="close">
      <property name="driverClassName" value="${jdbc.driverClassName}"/>
      <property name="url" value="${jdbc.url}"/>
    </bean>

     <bean id="dataSource"
class="org.springframework.jdbc.datasource.UserCredentialsDataSourceAdapter">
       <property name="targetDataSource"
ref="myDriverManagerDataSourceUrl"/>
       <property name="username" value="${jdbc.username}"/>
       <property name="password" value="${jdbc.password}"/>
     </bean>

dao.xml

    <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation"
value="classpath:hibernate.cfg.xml"/>
        <property name="hibernateProperties">
            <value>
                hibernate.dialect=${hibernate.dialect}
                hibernate.query.substitutions=true 'Y', false 'N'
                hibernate.cache.use_second_level_cache=true

hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
            </value>
            <!-- Turn batching off for better error messages under
PostgreSQL -->
            <!-- hibernate.jdbc.batch_size=0 -->
        </property>
    </bean>

now, my principal problem is when i try to pass the test.

    public void testGetTesquemasByTuser() throws Exception {

        UserCredentialsDataSourceAdapter userCredentialsDataSourceAdapter =

(UserCredentialsDataSourceAdapter)applicationContext.getBean("dataSource");


userCredentialsDataSourceAdapter.setCredentialsForCurrentThread("tuser",
"tuser");
          setDataSource(userCredentialsDataSourceAdapter);

          List<Tesquema> ltesquema =
tesquemaUniversalDao.getAll(Tesquema.class);
        log.debug("tusers obtenidos =" + ltesquema.size());

        assertNotNull(ltesquema);
        log.debug("esquema 0 =" + ltesquema.get(0));
        //assertTrue(ltesquema.get(0).getUsername().equals("tuser"));

        assertTrue(ltesquema.size() == 1 );


userCredentialsDataSourceAdapter.removeCredentialsFromCurrentThread();
    }

I try to change the dataSource
"setDataSource(userCredentialsDataSourceAdapter);" but it doesn`t work me.
only works if i invoke toTearDown and SetUp before of getAll

how can i change the actua datasource in my transacction ? or better, how
can i start a new transaction with a new datasource before of a unit test?

thanks!

Reply via email to