Changeset 57

Show
Ignore:
Timestamp:
05/22/09 09:04:04 (4 years ago)
Author:
frasten
Message:

CLOSED - # 33: Eliminare i vari TODO ed utilizzare Main.errorBox()
 http://my-trac.assembla.com/oberheditor/ticket/33

Location:
trunk/src/oberheditor
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/oberheditor/Canzone.java

    r48 r57  
    3434         * Creo una canzone caricandola dal database. 
    3535         * @param id L'id della canzone. 
     36         * @throws SQLException  
    3637         */ 
    37         public Canzone(int id) { 
     38        public Canzone(int id) throws SQLException { 
    3839                this(); 
    3940                if (id <= 0) throw new IllegalArgumentException("L'id deve essere > 0."); 
     
    5960                        } 
    6061                } catch (SQLException e) { 
    61                         // TODO Auto-generated catch block 
    62                         e.printStackTrace(); 
     62                        throw e; 
    6363                } 
    6464        } 
     
    118118         * canzone, la inserisce, altrimenti la aggiorna. 
    119119         * @return <em>true</em> in caso di successo, altrimenti <em>false</em>. 
     120         * @throws SQLException  
    120121         */ 
    121         public boolean salvaDB() { 
     122        public boolean salvaDB() throws SQLException { 
    122123                Database.creaTable(Database.TBL_CANZONE); 
    123124                 
  • trunk/src/oberheditor/Database.java

    r39 r57  
    2020                        System.exit(1); 
    2121                } catch (SQLException e) { 
    22                         // TODO Auto-generated catch block 
     22                        System.out.println("Errore di connessione al database."); 
    2323                        e.printStackTrace(); 
    2424                        System.exit(1); 
     
    3030                        conn.close(); 
    3131                } catch (SQLException e) { 
    32                         // TODO Auto-generated catch block 
    3332                        e.printStackTrace(); 
    3433                } 
    3534        } 
    3635         
    37         public static ResultSet query(String query, String ... args) { 
     36        public static ResultSet query(String query, String ... args) throws SQLException { 
    3837                try { 
    3938                         
     
    4645                        return res; 
    4746                } catch (SQLException e) { 
    48                         // TODO Auto-generated catch block 
    49                         e.printStackTrace(); 
     47                        throw e; 
    5048                } 
    51                 return null; 
    5249        } 
    5350         
    54         public static int queryUp(String query, String ... args) { 
     51        public static int queryUp(String query, String ... args) throws SQLException { 
    5552                try { 
    5653                        PreparedStatement prep = conn.prepareStatement(query); 
     
    6966            return result; 
    7067                } catch (SQLException e) { 
    71                         // TODO Auto-generated catch block 
    72                         e.printStackTrace(); 
     68                        throw e; 
    7369                } 
    74                 return -1; 
    7570        } 
    7671         
    77         public static void creaTable(int tabella) { 
     72        public static void creaTable(int tabella) throws SQLException { 
    7873                 
    7974                if ((tabella & TBL_CANZONE) != 0) { 
     
    9287        /** 
    9388         * Creo il database e lo popolo 
     89         * @throws SQLException  
    9490         */ 
    95         public static void crea() { 
     91        public static void crea() throws SQLException { 
    9692                Database.creaTable(Database.TBL_CANZONE | Database.TBL_SCALETTA | Database.TBL_SCALETTA_CANZONE); 
    9793                queryUp("DELETE FROM scaletta"); 
  • trunk/src/oberheditor/Scaletta.java

    r40 r57  
    2424         * Creo una scaletta caricandola dal database. 
    2525         * @param id L'id della scaletta 
     26         * @throws SQLException  
    2627         */ 
    27         public Scaletta(int id) { 
     28        public Scaletta(int id) throws SQLException { 
    2829                this(); 
    2930                if (id <= 0) throw new IllegalArgumentException("L'id deve essere > 0."); 
     
    6869                         
    6970                } catch (SQLException e) { 
    70                         // TODO Auto-generated catch block 
    71                         e.printStackTrace(); 
     71                        throw e; 
    7272                } 
    7373           
     
    142142         
    143143         
    144         public boolean salvaDB() { 
     144        public boolean salvaDB() throws SQLException { 
    145145                Database.creaTable(Database.TBL_CANZONE | Database.TBL_SCALETTA | Database.TBL_SCALETTA_CANZONE); 
    146146                 
  • trunk/src/oberheditor/gui/WinCanzone.java

    r52 r57  
    11package oberheditor.gui; 
     2 
     3import java.sql.SQLException; 
    24 
    35import oberheditor.Canzone; 
     
    258260        private void salvaCanzoneEdEsci() { 
    259261                canzone.setPatches(listPatches.getItems()); 
    260                 if (canzone.salvaDB()) { 
    261                         this.hoFattoModifiche = true; 
    262                         win.close(); 
     262                try { 
     263                        if (canzone.salvaDB()) { 
     264                                this.hoFattoModifiche = true; 
     265                                win.close(); 
     266                        } 
     267                } catch (SQLException e) { 
     268                        Main.errorBox(win, "Errore nel salvataggio.\n" + e.getMessage()); 
     269                        e.printStackTrace(); 
    263270                } 
    264271        } 
    265272         
    266273        private void caricaCanzoneDatabase(int id) {     
    267                 canzone = new Canzone(id); 
     274                try { 
     275                        canzone = new Canzone(id); 
     276                } catch (SQLException e) { 
     277                        Main.errorBox(win, "Errore nel caricamento.\n" + e.getMessage()); 
     278                        e.printStackTrace(); 
     279                } 
    268280                txtNome.setText(canzone.getNome()); 
    269281                 
  • trunk/src/oberheditor/gui/WinMain.java

    r55 r57  
    196196                                        // TODO: magari unificare con una query unica, invece che mille query nel for 
    197197                                        int id = scalette.get(selezione[i]).getId(); 
    198                                         Database.queryUp("DELETE FROM scaletta WHERE id = ?", id+""); 
    199                                         Database.queryUp("DELETE FROM scaletta_canzone WHERE id_scaletta = ?", id+""); 
    200                                          
    201                                         // dal vettore delle scalette 
    202                                         scalette.remove(selezione[i]); 
    203                                         refreshTastiScaletta(); 
     198                                        try { 
     199                                                Database.queryUp("DELETE FROM scaletta WHERE id = ?", id+""); 
     200                                                Database.queryUp("DELETE FROM scaletta_canzone WHERE id_scaletta = ?", id+""); 
     201                                                // dal vettore delle scalette 
     202                                                scalette.remove(selezione[i]); 
     203                                                refreshTastiScaletta(); 
     204                                        } catch (SQLException e1) { 
     205                                                Main.errorBox(win, "Errore nell'eliminazione.\n" + e1.getMessage()); 
     206                                                e1.printStackTrace(); 
     207                                        } 
    204208                                } 
    205209                        } 
     
    301305                                        // TODO: magari unificare con una query unica, invece che mille query nel for 
    302306                                        int id = canzoni.get(selezione[i]).getId(); 
    303                                         Database.queryUp("DELETE FROM canzone WHERE id = ?", id+""); 
    304                                         Database.queryUp("DELETE FROM scaletta_canzone WHERE id_canzone = ?", id+""); 
    305                                          
    306                                         // dal vettore delle scalette 
    307                                         canzoni.remove(selezione[i]); 
    308                                         refreshTastiCanzone(); 
     307                                        try { 
     308                                                Database.queryUp("DELETE FROM canzone WHERE id = ?", id+""); 
     309                                                Database.queryUp("DELETE FROM scaletta_canzone WHERE id_canzone = ?", id+""); 
     310                                                // dal vettore delle scalette 
     311                                                canzoni.remove(selezione[i]); 
     312                                                refreshTastiCanzone(); 
     313                                        } catch (SQLException e1) { 
     314                                                Main.errorBox(win, "Errore nell'eliminazione.\n" + e1.getMessage()); 
     315                                                e1.printStackTrace(); 
     316                                        } 
    309317                                } 
    310318                        } 
     
    354362 
    355363        private void caricaScalette() { 
    356                 Database.creaTable(Database.TBL_SCALETTA); 
    357                 ResultSet res = Database.query("SELECT id FROM scaletta ORDER BY data DESC, id DESC;"); 
     364                ResultSet res; 
     365                try { 
     366                        Database.creaTable(Database.TBL_SCALETTA); 
     367                        res = Database.query("SELECT id FROM scaletta ORDER BY data DESC, id DESC;"); 
     368                } catch (SQLException e1) { 
     369                        Main.errorBox(win, "Errore nel caricamento.\n" + e1.getMessage()); 
     370                        e1.printStackTrace(); 
     371                        return; 
     372                } 
    358373                 
    359374                // Se avevo gia' selezione, la ripristino dopo aver ricaricato. 
     
    388403                        } 
    389404                } catch (SQLException e) { 
    390                         // TODO Auto-generated catch block 
     405                        Main.errorBox(win, "Errore di connessione al database."); 
    391406                        e.printStackTrace(); 
    392407                } 
     
    395410         
    396411        private void caricaCanzoni() { 
    397                 Database.creaTable(Database.TBL_CANZONE); 
    398                 ResultSet res = Database.query("SELECT id FROM canzone ORDER BY nome ASC;"); 
     412                ResultSet res; 
     413                try { 
     414                        Database.creaTable(Database.TBL_CANZONE); 
     415                        res = Database.query("SELECT id FROM canzone ORDER BY nome ASC;"); 
     416                } catch (SQLException e1) { 
     417                        Main.errorBox(win, "Errore nel caricamento.\n" + e1.getMessage()); 
     418                        e1.printStackTrace(); 
     419                        return; 
     420                } 
     421                 
    399422                 
    400423                // Se avevo gia' selezione, la ripristino dopo aver ricaricato. 
     
    426449                        } 
    427450                } catch (SQLException e) { 
    428                         // TODO Auto-generated catch block 
     451                        Main.errorBox(win, "Errore di connessione al database."); 
    429452                        e.printStackTrace(); 
    430453                } 
  • trunk/src/oberheditor/gui/WinScaletta.java

    r56 r57  
    433433                } 
    434434                 
    435                 if (scaletta.salvaDB()) { 
    436                         this.hoFattoModifiche = true; 
    437                         win.close(); 
     435                try { 
     436                        if (scaletta.salvaDB()) { 
     437                                this.hoFattoModifiche = true; 
     438                                win.close(); 
     439                        } 
     440                } catch (SQLException e) { 
     441                        Main.errorBox(win, "Errore nel salvataggio.\n" + e.getMessage()); 
     442                        e.printStackTrace(); 
    438443                } 
    439444        } 
     
    478483         
    479484        private void caricaCanzoniDisponibili() { 
    480                 Database.creaTable(Database.TBL_CANZONE); 
    481                 ResultSet res = Database.query("SELECT id FROM canzone ORDER BY nome ASC;"); 
     485                ResultSet res; 
     486                try { 
     487                        Database.creaTable(Database.TBL_CANZONE); 
     488                        res = Database.query("SELECT id FROM canzone ORDER BY nome ASC;"); 
     489                } catch (SQLException e1) { 
     490                        Main.errorBox(win, "Errore nel caricamento.\n" + e1.getMessage()); 
     491                        e1.printStackTrace(); 
     492                        return; 
     493                } 
     494                 
    482495                canzoniDisponibili = new Vector<Canzone>(); 
    483496                canzoniDisponibiliOriginale = new Vector<Canzone>(); 
     
    498511                        listCanzoniDisponibili.select(0); 
    499512                } catch (SQLException e) { 
    500                         // TODO Auto-generated catch block 
     513                        Main.errorBox(win, "Errore di connessione al database."); 
    501514                        e.printStackTrace(); 
    502515                } 
     
    504517         
    505518        private void caricaScalettaDatabase(int id) { 
    506                  
    507                 scaletta = new Scaletta(id); 
     519                try { 
     520                        scaletta = new Scaletta(id); 
     521                } catch (SQLException e) { 
     522                        Main.errorBox(win, "Errore nel caricamento.\n" + e.getMessage()); 
     523                        e.printStackTrace(); 
     524                        return; 
     525                } 
    508526                txtNome.setText(scaletta.getNome()); 
    509527