tags:

views:

24

answers:

1

I have an AbstractDao implemented by every Dao of my database.

public abstract class AbstractDaoImpl extends HibernateDaoSupport {

(...) public void delete(T pEntity) throws FerdeDaoException {

    try {
        this.getHibernateTemplate().delete(pEntity);
    } (...)
}

....

Bascially the flushMode seems to be at AUTO.

What do i want ?

I want to be sure that when this class is use in unit test, I want to have a flush after every basic operation (delete, update, save) with this class above.

What is a solution ?

i think i would have to add after the line : this.getHibernateTemplate().delete(pEntity) in the method above

this one : this.getHibernateTemplate().flush() only for my unit test.

But i cant add it directly in the AsbtractDao because it is used in other project where the flush will be done automatically.

Or do i have nothin to add because the AUTO flushmode flush after every DELETE/SAVE/UPDATE operation ?? ( i dont have read that ine the javadoc).

Thanks in advance for your anwser.

A: 

Nice one :)

Why you don't specify a system variable, that specifies the mode of operation of your application. for example:

-DrunningMode=test -DrunningMode=development -DrunningMode=production

and based on your runningMode system variable you can decide what to do in your AbstractDAO, or you can set the property of AUTO flush for testing to true, and for non testing environments to false, and use different configurations when running in different modes.

If you are using this class in different projects, may be it is better that you back it with a configuration file that will instruct this class how to work. (XML or .properties)

Omar Al Kababji