Results 1 to 7 of 7

Thread: getIsolationLevel method in "declarative way"

  1. #1
    Join Date
    Nov 2006
    Posts
    218

    Default getIsolationLevel method in "declarative way"

    Hi,

    I would like know if it's possible use getIsolationLevel() (Interface TransactionDefinition) to know if in a method where I suppose it could be in a transaction, isolation level setted is used.
    That's my configuration springapp-servlet.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
    	<!-- Data Source -->
    
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
          <property name="driverClassName">
          	<value>org.postgresql.Driver</value>
          </property>
          <property name="url">
            <value>jdbc:postgresql://localhost:5432/transactionstest</value>
          </property>
          <property name="username">
          	<value>postgres</value>
          </property>
          <property name="password">
          	<value>postgres</value>
          </property>
        </bean>
        
        <!-- Persistence -->
    
    	<bean id="jdbcTemplate"
    		class="org.springframework.jdbc.core.JdbcTemplate">
    		<property name="dataSource">
    			<ref local="dataSource" />
    		</property>
    	</bean>
    
    	<bean id="postgresTablesCreator" class="org.test.persistence.PostgresTablesCreator">
    	   <property name="jdbcTemplate">
            	<ref bean="jdbcTemplate"/>
            </property>
    	</bean>
    
        <bean id="personManagerDao" class="org.test.persistence.PersonManagerDaoJdbc">
            <property name="jdbcTemplate">
            	<ref bean="jdbcTemplate"/>
            </property>
        </bean>
    
        <bean id="personManager" class="org.test.persistence.PersonManager">
            <property name="personManagerDao">
                <ref bean="personManagerDao"/>
            </property>
        </bean>
        
        <!-- Transactions - Units of Work -->
        
        <bean id="dummyTransactionBean"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="proxyInterfaces">
    			<list>
    				<value>
    					org.test.transaction.DummyTransaction
    				</value>
    			</list>
    		</property>
    		<property name="target">
    			<ref bean="dummyTransaction" />
    		</property>
    		<property name="transactionManager">
    			<ref bean="txManager" />
    		</property>
    		<property name="transactionAttributeSource">
    			<ref bean="attributeSource" />
    		</property>
    	</bean>
    
        <bean id="txManager"
        	class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        	<property name="dataSource" ref="dataSource" />
        </bean>
    
        <bean id="attributeSource"
    		class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
    		<property name="properties">
    			<props>
    				<prop key="queryPersonThread">PROPAGATION_REQUIRES_NEW,ISOLATION_SERIALIZABLE</prop>
    			</props>
    		</property>
    	</bean>
    	
    	<bean id="dummyTransaction" class="org.test.transaction.DummyTransactionImpl">
            <property name="personManager">
                <ref bean="personManager"/>
            </property>
            <property name="transactionManager">
                <ref bean="txManager"/>
            </property>
        </bean>
    
    </beans>
    and this is my simple method in transaction (simple query to db not really useful in transaction but it's just a test):

    Code:
    public synchronized void queryPersonThread() {
                    log.info("TRANSACTION ON THIS METHOD INFOS");
    		this.name = personManager.getPersonNameById(this.id);
    	}
    can I "print" via log infos about isolation level directly in this method? Using getIsolationLevel() method above?

    Thanks,
    Julio

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Have you had a look at TransactionSynchronizationManager?
    http://www.springframework.org/docs/...olationLevel()

  3. #3
    Join Date
    Nov 2006
    Posts
    218

    Default

    in same class there is useful "isActualTransactionActive" too

    in programmatic way my transaction works, in declarative way not, but I have found my mistake. Questions are "moved" here:

    http://forum.springframework.org/showthread.php?t=35007

    Thanks,
    Julio

  4. #4
    Join Date
    Nov 2006
    Posts
    218

    Default

    Hi,

    finally (read above thread) my declarative-autoproxied transactions works (I'm rolling on floor break-dance style )

    In methods I have added this:

    Code:
    if (TransactionSynchronizationManager.isActualTransactionActive())
    			logger.info ("THREAD1: TRANSACTION ACTIVED");
    		else
    			logger.info ("THREAD1: TRANSACTION NOT ACTIVED");
    		
    		logger.info ("TRANSACTION NAME " + TransactionSynchronizationManager.getCurrentTransactionName());
    		
    		logger.info("TRANSACTION ISOLATION LEVEL " + TransactionSynchronizationManager.getCurrentTransactionIsolationLevel().toString());
    * strange thing *

    in documentation there is static method getCurrentTransactionIsolationLevel:

    http://www.springframework.org/docs/...solationLevel()

    that returns "Integer". But Eclipse underlines method-name with red line (method not found) and compiling I get error (method not present).

    I'm using spring 2.0 - maybe documentation is not updated? method was moved? where?

    Thanks,
    Julio

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Glad it's finally working! The method is there on the 2.0 code, I would guess you don't have the right jar on the classpath maybe? If you click the error in eclipse it does tell you what the problem is. BTW, I'd like to see the breakdancing....... have to post it on youtube .
    Code:
    	/**
    	 * Return the isolation level for the current transaction, if any.
    	 * To be called by resource management code when preparing a newly
    	 * created resource (for example, a JDBC Connection).
    	 * @see TransactionSynchronization#beforeCommit(boolean)
    	 * @see org.hibernate.Session#flush
    	 * @see org.hibernate.Session#setFlushMode
    	 * @see org.hibernate.FlushMode#NEVER
    	 */
    	public static Integer getCurrentTransactionIsolationLevel() {
    		return (Integer) currentTransactionIsolationLevel.get();
    	}
    Last edited by karldmoore; Feb 19th, 2007 at 09:40 AM.

  6. #6
    Join Date
    Nov 2006
    Posts
    218

    Default

    yes, it was problem version:

    in maven "spring-dependencies" were at version 2.0.0, upgrading to 2.0.2 method is present

    Thanks,
    Julio

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Great, glad it's working. I've not yet had the pleasures of maven, I'm errr looking forward to it .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •