The issue you may find is that there will not be one instance per VM when
using a normal singleton pattern, but one per ClassLoader. Since an EJB
server can use many ClassLoader instances you may have just as man instances
of your DAO
Dave Wolf
Internet Applications Division
Sybase
----- Original Message -----
From: "Jerson Chua" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, January 14, 2001 9:02 PM
Subject: Repost: EJB and a single instance of DAO
> I'm reposting it cause I wan't able to get any reply. Can anyone from a
> server vendor answer this question? Will there be a transactional problem
if
> all beans shared one DAO instance?
>
> Jerson
>
> Hi everyone...
> Will there be a problem (like transactional) if all EJB share one DAO
> instance? The DAO doesn't maintain any state which will be concurrently
> accessed.
>
> Thanks...
> Jerson
> -- code --
> public class DAOFactory {
> private static OracleDAO oracleDAO;
> private static SybaseDAO sybaseDAO;
>
> public static DAO getDAO() throws OrderDAOException {
>
> try {
> InitialContext ic = new InitialContext();
> DataSource ds = (DataSource)ic.lookup("ds");
> Connection conn = ds.getConnection();
> String DBProductName =
>
conn.getMetaData().getDatabaseProductName().trim();
> conn.close();
>
> if (DBProductName.startsWith("Oracle")) {
> return getOracleDAO();
> } else if (DBProductName.startsWith("SQL Server")) {
> return getSybaseDAO();
> } else {
> throw new OrderDAOException("db not
> supported");
> }
> } catch (NamingException ne) {
> throw new OrderDAOException("OrderDAOFactory.getDAO:
> NamingException while getting DB connection : \n" + ne.getMessage());
> } catch (SQLException se) {
> throw new OrderDAOException("OrderDAOFactory.getDAO:
> SQLException while getting DB connection : \n" + se.getMessage());
> }
> }
>
> public OracleDAO getOracleDAO() {
> if (oracleDAO == null) {
> oracleDAO = new OracleDAO;
> }
> return oracleDAO;
> }
>
> public SybaseDAO getSybaseDAO() {
> if (sybaseDAO == null) {
> sybaseDAO = new sybaseDAO;
> }
> return sybaseDAO;
> }
> }
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".