-->
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: One DAO with multiple CFG files
PostPosted: Wed Apr 08, 2009 2:50 pm 
Newbie

Joined: Fri Apr 18, 2008 5:53 pm
Posts: 4
DB2 - Websphere 6.1 - java 1.5

I'm trying to implement something that I'm afraid is going to slow my application down, but wanted to see if there was a good way to do this.

The database is already built and being used by more people then just me, so changing the database structure or tables is a last resort.

I have an application that needs to read and modify tables in two different schemas. The tables in the two schemas are identical. One represents work in progress while the other represents production data.

So I would like to have the same DAO flip flop between schemas.

My concern is that because I access my DAO statically I'm going to have to synchronize the methods inside so that users don't connect to the wrong schema.

So in the Manager Class I haev
Code:
DateSensitiveDAO dao = DateSensitiveDAO.getInstance(false);

Then in the DAO
Code:
public final class DateSensitiveDAO extends BaseDAO{

    private static final Logger logger = Logger.getLogger(DateSensitiveDAO.class);
    private static String cfgFile = "grp_hibernate.cfg.xml";
    private static final String cfgFileNonWip = "grp_hibernate.cfg.xml";
    private static final String cfgFileWip = "grp_wip_hibernate.cfg.xml";
    private static boolean initialized = false;
    private static final DateSensitiveDAO _instance = new DateSensitiveDAO();

    public static final DateSensitiveDAO getInstance(boolean isWip){       
        _instance.setWip(isWip);
        return _instance;
    }
    public void setWip(boolean isWip) {
        if(isWip) {
            cfgFile = cfgFileWip;
        }else {
            cfgFile = cfgFileNonWip;
        }       
        initialized = false;
    }
.....
}


This works with just one user, but I'm worried that it's going to cause problems.

Has anyone had to do something like this?

I could just double the number of classes that I'm using and create separate objects for each table in each schema, but I'd really like to avoid having to do that.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 08, 2009 3:11 pm 
Regular
Regular

Joined: Tue Dec 30, 2008 8:14 pm
Posts: 50
How about having two instances of the DAO:

public final class DateSensitiveDAO extends BaseDAO {
//more code
private static final DateSensitiveDAO _instance = new DateSensitiveDAO(cfgFileNonWip);
private static final DateSensitiveDAO _wipInstance = new DateSensitiveDAO(cfgFileWip);

private DateSensitiveDAO(String cfgfile) {
//initilaize
}

public static final DateSensitiveDAO getWipInstance(){
return _wipInstance;
}

public static final DateSensitiveDAO getInstance(){
return _instance;
}

//more code
}


---
please rate


Top
 Profile  
 
 Post subject: I like it
PostPosted: Wed Apr 08, 2009 3:26 pm 
Newbie

Joined: Fri Apr 18, 2008 5:53 pm
Posts: 4
LinHib wrote:
How about having two instances of the DAO:
private static final DateSensitiveDAO _instance = new DateSensitiveDAO(cfgFileNonWip);
private static final DateSensitiveDAO _wipInstance = new DateSensitiveDAO(cfgFileWip);


I like it. Wish I would have thought of it myself.


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.