franta-hg@16: package cz.frantovo.sql.vyuka.dao; franta-hg@16: franta-hg@16: import cz.frantovo.superDAO.SuperDAO; franta-hg@16: import java.sql.Connection; franta-hg@16: import java.sql.SQLException; franta-hg@16: import java.util.logging.Level; franta-hg@16: import javax.naming.InitialContext; franta-hg@16: import javax.naming.NamingException; franta-hg@16: import javax.sql.DataSource; franta-hg@16: franta-hg@16: /** franta-hg@16: * franta-hg@16: * @author fiki franta-hg@16: */ franta-hg@16: public class VyukaSuperDAO extends SuperDAO { franta-hg@16: franta-hg@16: protected InitialContext kontext = null; franta-hg@16: franta-hg@16: protected enum DATABAZE { franta-hg@16: franta-hg@16: /** Databáze aplikace – historie, nastavení. */ franta-hg@16: APLIKACE, franta-hg@16: /** Databáze, na které se spouštějí příkazy uživatelů. */ franta-hg@16: PISKOVISTE franta-hg@16: } franta-hg@16: franta-hg@16: public VyukaSuperDAO() { franta-hg@16: try { franta-hg@16: kontext = new InitialContext(); franta-hg@16: } catch (NamingException ex) { franta-hg@16: log.log(Level.SEVERE, "Chyba při inicializaci kontextu", ex); franta-hg@16: } franta-hg@16: } franta-hg@16: franta-hg@16: /** franta-hg@16: * @param databaze Která databáze (aplikace = historie a nastavení | pískoviště = příkazy uživatele) franta-hg@16: * @return Databázové spojení franta-hg@16: */ franta-hg@16: protected Connection getSpojeni(DATABAZE databaze) { franta-hg@16: if (databaze == null) { franta-hg@16: databaze = DATABAZE.PISKOVISTE; franta-hg@16: } franta-hg@16: log.log(Level.SEVERE, "DATABAZE:" + String.valueOf(databaze)); franta-hg@16: String jndi = orizniJNDI(getVlastnost(databaze, VyukaSuperDAO.class)); franta-hg@16: DataSource zdroj = null; franta-hg@16: try { franta-hg@16: zdroj = (DataSource) kontext.lookup(jndi); franta-hg@16: return zdroj.getConnection(); franta-hg@16: } catch (NamingException ex) { franta-hg@16: log.log(Level.SEVERE, "getSpojeni: lookup", ex); franta-hg@16: return null; franta-hg@16: } catch (SQLException ex) { franta-hg@16: log.log(Level.SEVERE, "getSpojeni: sql", ex); franta-hg@16: return null; franta-hg@16: } franta-hg@16: } franta-hg@16: }