Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Pattern »

Re: Using Factory

Bayarsaikhan VOLODYA (YAZ-ArGe)

2005-10-04

Replies:

have you ever tried Hibernate (www.hibernate.org). if you use it, you only
need only one main Factory class which creates 3 datasources.
you dont have to deal with with so many factories and data accesses and
thousands lines of code.

-----Original Message-----
From: An interest list for Sun Java Center J2EE Pattern Catalog
[mailto:J2EEPATTERNS-INTEREST@(protected)
EJB-INTEREST anonymous
Sent: Tuesday, October 04, 2005 2:59 PM
To: J2EEPATTERNS-INTEREST@(protected)
Subject: Using Factory


Hi,
I use three databases and so, I am using Factory pattern for Data Access
Objects.Is there anyway to optimize the below code while getting datasource.

class Factory{
public static MySqlFactory mySqlFactory = new MySqlFactory();
//other data access factories

public Factory getFactory(int factoryType){
if(factoryType == 1)
 return mySqlFactory;
//other factories
}

}

public class MySqlFactory{

public getCustomerDataAccess(){
return new CustomerDataAccess();
}

public class CustomerDataAccess(){
private DataSource datasource = null;

public Vector getCustomerData(int i){

if(datasource == null)
//create a new datasource and put in cache
else //use the one in cache...

//other code goes here

}

}

}

====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive:
http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to
listserv@(protected)

====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.