-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Blocking all tables in Hibernate transaction?
PostPosted: Wed Nov 23, 2005 2:35 am 
Newbie

Joined: Wed Oct 05, 2005 1:20 pm
Posts: 15
Location: Russia Izhevsk
Hello

I am using Spring 1.2.6, Hibernate 3.1rc3, Struts.
I have a task to drop and create all database tables and load data into database from file in other words restore data from backup archive at runtime.

Code:
<!-- Backup Manager Implementation -->
    <bean id="backupManager" parent="txProxyTemplate" lazy-init="false">
        <property name="target">
            <bean class="com.blandware.atleap.service.core.impl.BackupManagerImpl">
                <property name="backupDAO">
                    <ref bean="backupDAO"/>
                </property>
            </bean>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="backup*">PROPAGATION_REQUIRED</prop>
                <prop key="list*">PROPAGATION_REQUIRED</prop>
                <prop key="restore*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
    </bean>


I use HibernateDaoSupport.

Code:
<!-- BackupDAO: Hibernate implementation -->
    <bean id="backupDAO" class="com.blandware.atleap.persistence.hibernate.core.BackupDAOHibernate">
        <property name="sessionFactory">
            <ref local="sessionFactory"/>
        </property>
    </bean>


My restore method do following

Code:
public void restore(final Date date, final Boolean force) {

        HibernateTemplate hibernateTemplate = new HibernateTemplate(getSessionFactory());
        hibernateTemplate.setFlushMode(HibernateTemplate.FLUSH_NEVER);
        hibernateTemplate.execute(
                new HibernateCallback() {
                    public Object doInHibernate(Session session) throws HibernateException, SQLException {
                        Connection con = session.connection();

                        boolean oldAutoCommit = con.getAutoCommit();
                        if (!oldAutoCommit) {
                            con.setAutoCommit(true);
                        }
                        InputStream is = null;
                        try {

                            //read data from archive
                            ...

                            //drop all tables
                            ...

                            //create all required tables
                            ...

                            //load initial data
                            ...

                        } catch (Exception ex) {
                            String message = "Cannot restore database with date " + date;
                            if (log.isWarnEnabled()) {
                                log.warn(message, ex);
                            }
                            throw new HibernateException(message, ex);
                        } finally {
                            try {
                                is.close();
                            } catch(Exception e) {}

                            if (!oldAutoCommit) {
                                con.setAutoCommit(false);
                            }
                        }

                        return null;
                    }
                }
        );

    }


It works perfectly, but if during execution of this method some other client tries perform some operation I got different exceptions.

How to prevent using any tables during execution of this task?

Thanks beforehand.

_________________
--
Andrey Grebnev
http://www.jroller.com/page/agrebnev


Top
 Profile  
 
 Post subject: Re: Blocking all tables in Hibernate transaction?
PostPosted: Fri Dec 02, 2005 9:40 pm 
Newbie

Joined: Tue Nov 22, 2005 11:57 am
Posts: 5
agrebnev wrote:

It works perfectly, but if during execution of this method some other client tries perform some operation I got different exceptions.

Hi,
which thread gets which exception?

agrebnev wrote:
How to prevent using any tables during execution of this task?


Actually you probably don't need to prevent others from using your tables. Thats what transaction isolation (e.g. READ_COMMITTED) is for.

See http://en.wikipedia.org/wiki/Transaction_isolation_level

cheers,
spunky


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 2:00 am 
Newbie

Joined: Wed Oct 05, 2005 1:20 pm
Posts: 15
Location: Russia Izhevsk
I did not find solution in case droping and recreating DB tables.

But in case deleting all data and loading new again I can specify SERIALIZABLE isolation.

_________________
--
Andrey Grebnev
http://www.jroller.com/page/agrebnev


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.