franta-hg@1: package cz.frantovo.springDemo1.web; franta-hg@1: franta-hg@2: import cz.frantovo.springDemo1.KnihaDAORemote; franta-hg@5: import cz.frantovo.springDemo1.KnihaDAOjdbcRemote; franta-hg@1: import cz.frantovo.springDemo1.dto.Kniha; franta-hg@1: import java.util.Collection; franta-hg@2: import java.util.logging.Level; franta-hg@2: import java.util.logging.Logger; franta-hg@2: import javax.naming.Context; franta-hg@2: import javax.naming.InitialContext; franta-hg@2: import javax.naming.NamingException; franta-hg@1: franta-hg@1: /** franta-hg@1: * franta-hg@1: * @author fiki franta-hg@1: */ franta-hg@1: public class SpringDemo1Bean { franta-hg@1: franta-hg@2: private static final Logger log = Logger.getLogger(SpringDemo1Bean.class.getSimpleName()); franta-hg@2: private KnihaDAORemote knihaDAO; franta-hg@5: private KnihaDAOjdbcRemote knihaDAOjdbc; franta-hg@2: franta-hg@5: /** Spring JdbcTemplate */ franta-hg@1: public Collection getKnihy() { franta-hg@5: return lookupKnihaDAO().getKnihy(); franta-hg@2: } franta-hg@2: franta-hg@5: /** JDBC */ franta-hg@5: public Collection getKnihyJdbc() { franta-hg@5: return lookupKnihaDAOjdbc().getKnihy(); franta-hg@5: } franta-hg@5: franta-hg@5: /** Spring JdbcTemplate */ franta-hg@5: private KnihaDAORemote lookupKnihaDAO() { franta-hg@2: if (knihaDAO == null) { franta-hg@2: try { franta-hg@2: Context c = new InitialContext(); franta-hg@2: knihaDAO = (KnihaDAORemote) c.lookup("cz.frantovo.springDemo1.KnihaDAORemote"); franta-hg@2: } catch (NamingException e) { franta-hg@5: log.log(Level.SEVERE, "Chyba při hledání KnihaDAO", e); franta-hg@2: throw new RuntimeException(e); franta-hg@2: } franta-hg@2: } franta-hg@2: return knihaDAO; franta-hg@1: } franta-hg@1: franta-hg@5: /** JDBC */ franta-hg@5: private KnihaDAOjdbcRemote lookupKnihaDAOjdbc() { franta-hg@5: if (knihaDAOjdbc == null) { franta-hg@5: try { franta-hg@5: Context c = new InitialContext(); franta-hg@5: knihaDAOjdbc = (KnihaDAOjdbcRemote) c.lookup("cz.frantovo.springDemo1.KnihaDAOjdbcRemote"); franta-hg@5: } catch (NamingException e) { franta-hg@5: log.log(Level.SEVERE, "Chyba při hledání KnihaDAOjdbc", e); franta-hg@5: throw new RuntimeException(e); franta-hg@5: } franta-hg@5: } franta-hg@5: return knihaDAOjdbc; franta-hg@5: } franta-hg@5: franta-hg@1: }