-->
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.  [ 1 post ] 
Author Message
 Post subject: Progress monitor
PostPosted: Sat Dec 04, 2010 7:04 am 
Newbie

Joined: Sat Dec 04, 2010 5:58 am
Posts: 1
I am migrating a Swing desktop application with JDBC MySQL database access to JPA/Hibernate.

I wonder, if there is any built-in support for progress monitors or any recommended strategy for using progress monitors in JPA/Hibernate?

In JDBC I used this code fragment:

Code:
    ResultSet rs;
    PreparedStatement stmt = con.prepareStatement("SELECT ...",
    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    rs = stmt.executeQuery();
    int rowCount = rs.getRow();
    getProgressMonitor().setMaximum(rowCount);
    rs.beforeFirst();
    while (rs.next()) {
        getProgressMonitor().setProgress(rs.getRow());
        [... process row ...]
    }


I searched for a similar functionality in JPA 2, but without success.

In Hibernate it is possible to use a scrollable query interface like in this fragment:

Code:
    Query q = em.createNamedQuery("item.findAll");
    QueryImpl qx=(QueryImpl) q;
    // Scroll only works with normal queries, not with join fetch
    qx.getHibernateQuery().scroll(ScrollMode.FORWARD_ONLY);
    Iterator it=qx.getHibernateQuery().iterate();
    getProgressMonitor().setMaximum(/* ??? */);
    int counter;
    Item item;
    for(counter=0, item=null; it.hasNext(); counter++, item=it.next()) {
        getProgressMonitor().setProgress(counter);
        [... process item ...]
    }


My questions: Is there a better interface for progress monitors? Is there an interface for inserts and updates?

A simple counter, which sets the progress for any processed object, which is saved or updated, may not be adequate, because the SQL execution may be delayed until flushing or commit.

Björn


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

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.