# HG changeset patch # User František Kučera # Date 1243802218 -7200 # Node ID 4b6ab4ba1a95d129788a818fea49bc2b818dde2c # Parent 6facd99aa1895b9465227d6a2acf5de700b484b9 Tipy (rady, citáty…) pro uživatele načítáme z databáze (v náhodném pořadí). + Databázové schéma. diff -r 6facd99aa189 -r 4b6ab4ba1a95 java/sql-vyuka/src/java/cz/frantovo/sql/vyuka/dao/TipyDAO.java --- a/java/sql-vyuka/src/java/cz/frantovo/sql/vyuka/dao/TipyDAO.java Sun May 31 18:49:00 2009 +0200 +++ b/java/sql-vyuka/src/java/cz/frantovo/sql/vyuka/dao/TipyDAO.java Sun May 31 22:36:58 2009 +0200 @@ -1,13 +1,43 @@ package cz.frantovo.sql.vyuka.dao; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.logging.Level; + /** - * + * Rady, tipy, odkazy, citáty… pro zobrazování uživatelům. * @author fiki */ public class TipyDAO extends VyukaSuperDAO { + private enum SQL { + + NAHODNY_TIP + } + + /** + * @return Náhodný tip načtený z databáze + */ public String getTip() { - /** TODO: Tipy brát z databáze. */ - return "Stejně vám něco doporučíme."; + Connection db = getSpojeni(DATABAZE.APLIKACE); + if (db == null) { + log.log(Level.SEVERE, "Databáze je null."); + return null; + } else { + PreparedStatement ps = null; + ResultSet rs = null; + try { + ps = db.prepareStatement(getSQL(SQL.NAHODNY_TIP)); + rs = ps.executeQuery(); + rs.next(); + return rs.getString("text"); + } catch (Exception e) { + log.log(Level.SEVERE, "Chyba při hledání náhodného tipu.", e); + return null; + } finally { + zavri(db, ps, rs); + } + } } } diff -r 6facd99aa189 -r 4b6ab4ba1a95 java/sql-vyuka/src/java/cz/frantovo/sql/vyuka/dao/TipyDAO.sql.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/sql-vyuka/src/java/cz/frantovo/sql/vyuka/dao/TipyDAO.sql.xml Sun May 31 22:36:58 2009 +0200 @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff -r 6facd99aa189 -r 4b6ab4ba1a95 java/sql-vyuka/web/ajax.jspx --- a/java/sql-vyuka/web/ajax.jspx Sun May 31 18:49:00 2009 +0200 +++ b/java/sql-vyuka/web/ajax.jspx Sun May 31 22:36:58 2009 +0200 @@ -14,8 +14,9 @@ - + + @@ -25,8 +26,9 @@ + - + @@ -62,6 +64,7 @@ + @@ -87,18 +90,23 @@ + - +

+
+ - + +

TODO: nápověda.

+
diff -r 6facd99aa189 -r 4b6ab4ba1a95 sql/schéma.sql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sql/schéma.sql Sun May 31 22:36:58 2009 +0200 @@ -0,0 +1,133 @@ +-- +-- PostgreSQL database dump +-- + +-- Started on 2009-05-31 22:35:00 CEST + +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = off; +SET check_function_bodies = false; +SET client_min_messages = warning; +SET escape_string_warning = off; + +-- +-- TOC entry 10 (class 2615 OID 16788) +-- Name: sqlvyukaaplikace; Type: SCHEMA; Schema: -; Owner: - +-- + +CREATE SCHEMA sqlvyukaaplikace; + + +SET search_path = sqlvyukaaplikace, pg_catalog; + +-- +-- TOC entry 1579 (class 1259 OID 16797) +-- Dependencies: 10 +-- Name: historie_seq; Type: SEQUENCE; Schema: sqlvyukaaplikace; Owner: - +-- + +CREATE SEQUENCE historie_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- TOC entry 1578 (class 1259 OID 16789) +-- Dependencies: 1848 1849 10 +-- Name: historie; Type: TABLE; Schema: sqlvyukaaplikace; Owner: -; Tablespace: +-- + +CREATE TABLE historie ( + id numeric DEFAULT nextval('historie_seq'::regclass) NOT NULL, + datum timestamp with time zone DEFAULT now(), + sql text, + id_sezeni character varying(255), + ip_adresa character varying(255) +); + + +-- +-- TOC entry 1580 (class 1259 OID 16813) +-- Dependencies: 10 +-- Name: tip_seq; Type: SEQUENCE; Schema: sqlvyukaaplikace; Owner: - +-- + +CREATE SEQUENCE tip_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +-- +-- TOC entry 1581 (class 1259 OID 16815) +-- Dependencies: 1850 10 +-- Name: tip; Type: TABLE; Schema: sqlvyukaaplikace; Owner: -; Tablespace: +-- + +CREATE TABLE tip ( + id numeric DEFAULT nextval('tip_seq'::regclass) NOT NULL, + text character varying(512) NOT NULL +); + + +-- +-- TOC entry 1859 (class 0 OID 0) +-- Dependencies: 1581 +-- Name: TABLE tip; Type: COMMENT; Schema: sqlvyukaaplikace; Owner: - +-- + +COMMENT ON TABLE tip IS 'Rady, tipy, odkazy a citáty… které budeme zobrazovat uživateli v náhodném pořadí.'; + + +-- +-- TOC entry 1860 (class 0 OID 0) +-- Dependencies: 1581 +-- Name: COLUMN tip.text; Type: COMMENT; Schema: sqlvyukaaplikace; Owner: - +-- + +COMMENT ON COLUMN tip.text IS 'HTML text. Bude vložen do

odstavce

. → Pozor na validitu.'; + + +-- +-- TOC entry 1852 (class 2606 OID 16796) +-- Dependencies: 1578 1578 +-- Name: historie_pk; Type: CONSTRAINT; Schema: sqlvyukaaplikace; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY historie + ADD CONSTRAINT historie_pk PRIMARY KEY (id); + + +-- +-- TOC entry 1854 (class 2606 OID 16823) +-- Dependencies: 1581 1581 +-- Name: tip_pk; Type: CONSTRAINT; Schema: sqlvyukaaplikace; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY tip + ADD CONSTRAINT tip_pk PRIMARY KEY (id); + + +-- +-- TOC entry 1856 (class 2606 OID 16825) +-- Dependencies: 1581 1581 +-- Name: tip_uq; Type: CONSTRAINT; Schema: sqlvyukaaplikace; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY tip + ADD CONSTRAINT tip_uq UNIQUE (text); + + +-- Completed on 2009-05-31 22:35:01 CEST + +-- +-- PostgreSQL database dump complete +-- +