franta-hg@16
|
1 |
package cz.frantovo.sql.vyuka.dao;
|
franta-hg@16
|
2 |
|
franta-hg@16
|
3 |
import cz.frantovo.superDAO.SuperDAO;
|
franta-hg@16
|
4 |
import java.sql.Connection;
|
franta-hg@16
|
5 |
import java.sql.SQLException;
|
franta-hg@16
|
6 |
import java.util.logging.Level;
|
franta-hg@16
|
7 |
import javax.naming.InitialContext;
|
franta-hg@16
|
8 |
import javax.naming.NamingException;
|
franta-hg@16
|
9 |
import javax.sql.DataSource;
|
franta-hg@16
|
10 |
|
franta-hg@16
|
11 |
/**
|
franta-hg@16
|
12 |
*
|
franta-hg@16
|
13 |
* @author fiki
|
franta-hg@16
|
14 |
*/
|
franta-hg@16
|
15 |
public class VyukaSuperDAO extends SuperDAO {
|
franta-hg@16
|
16 |
|
franta-hg@16
|
17 |
protected InitialContext kontext = null;
|
franta-hg@16
|
18 |
|
franta-hg@16
|
19 |
protected enum DATABAZE {
|
franta-hg@16
|
20 |
|
franta-hg@16
|
21 |
/** Databáze aplikace – historie, nastavení. */
|
franta-hg@16
|
22 |
APLIKACE,
|
franta-hg@16
|
23 |
/** Databáze, na které se spouštějí příkazy uživatelů. */
|
franta-hg@16
|
24 |
PISKOVISTE
|
franta-hg@16
|
25 |
}
|
franta-hg@16
|
26 |
|
franta-hg@16
|
27 |
public VyukaSuperDAO() {
|
franta-hg@16
|
28 |
try {
|
franta-hg@16
|
29 |
kontext = new InitialContext();
|
franta-hg@16
|
30 |
} catch (NamingException ex) {
|
franta-hg@16
|
31 |
log.log(Level.SEVERE, "Chyba při inicializaci kontextu", ex);
|
franta-hg@16
|
32 |
}
|
franta-hg@16
|
33 |
}
|
franta-hg@16
|
34 |
|
franta-hg@16
|
35 |
/**
|
franta-hg@16
|
36 |
* @param databaze Která databáze (aplikace = historie a nastavení | pískoviště = příkazy uživatele)
|
franta-hg@16
|
37 |
* @return Databázové spojení
|
franta-hg@16
|
38 |
*/
|
franta-hg@16
|
39 |
protected Connection getSpojeni(DATABAZE databaze) {
|
franta-hg@16
|
40 |
if (databaze == null) {
|
franta-hg@16
|
41 |
databaze = DATABAZE.PISKOVISTE;
|
franta-hg@16
|
42 |
}
|
franta-hg@16
|
43 |
log.log(Level.SEVERE, "DATABAZE:" + String.valueOf(databaze));
|
franta-hg@16
|
44 |
String jndi = orizniJNDI(getVlastnost(databaze, VyukaSuperDAO.class));
|
franta-hg@16
|
45 |
DataSource zdroj = null;
|
franta-hg@16
|
46 |
try {
|
franta-hg@16
|
47 |
zdroj = (DataSource) kontext.lookup(jndi);
|
franta-hg@16
|
48 |
return zdroj.getConnection();
|
franta-hg@16
|
49 |
} catch (NamingException ex) {
|
franta-hg@16
|
50 |
log.log(Level.SEVERE, "getSpojeni: lookup", ex);
|
franta-hg@16
|
51 |
return null;
|
franta-hg@16
|
52 |
} catch (SQLException ex) {
|
franta-hg@16
|
53 |
log.log(Level.SEVERE, "getSpojeni: sql", ex);
|
franta-hg@16
|
54 |
return null;
|
franta-hg@16
|
55 |
}
|
franta-hg@16
|
56 |
}
|
franta-hg@16
|
57 |
} |