Changeset 57
- Timestamp:
- 05/22/09 09:04:04 (4 years ago)
- Location:
- trunk/src/oberheditor
- Files:
-
- 6 modified
-
Canzone.java (modified) (3 diffs)
-
Database.java (modified) (5 diffs)
-
Scaletta.java (modified) (3 diffs)
-
gui/WinCanzone.java (modified) (2 diffs)
-
gui/WinMain.java (modified) (6 diffs)
-
gui/WinScaletta.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/oberheditor/Canzone.java
r48 r57 34 34 * Creo una canzone caricandola dal database. 35 35 * @param id L'id della canzone. 36 * @throws SQLException 36 37 */ 37 public Canzone(int id) {38 public Canzone(int id) throws SQLException { 38 39 this(); 39 40 if (id <= 0) throw new IllegalArgumentException("L'id deve essere > 0."); … … 59 60 } 60 61 } catch (SQLException e) { 61 // TODO Auto-generated catch block 62 e.printStackTrace(); 62 throw e; 63 63 } 64 64 } … … 118 118 * canzone, la inserisce, altrimenti la aggiorna. 119 119 * @return <em>true</em> in caso di successo, altrimenti <em>false</em>. 120 * @throws SQLException 120 121 */ 121 public boolean salvaDB() {122 public boolean salvaDB() throws SQLException { 122 123 Database.creaTable(Database.TBL_CANZONE); 123 124 -
trunk/src/oberheditor/Database.java
r39 r57 20 20 System.exit(1); 21 21 } catch (SQLException e) { 22 // TODO Auto-generated catch block22 System.out.println("Errore di connessione al database."); 23 23 e.printStackTrace(); 24 24 System.exit(1); … … 30 30 conn.close(); 31 31 } catch (SQLException e) { 32 // TODO Auto-generated catch block33 32 e.printStackTrace(); 34 33 } 35 34 } 36 35 37 public static ResultSet query(String query, String ... args) {36 public static ResultSet query(String query, String ... args) throws SQLException { 38 37 try { 39 38 … … 46 45 return res; 47 46 } catch (SQLException e) { 48 // TODO Auto-generated catch block 49 e.printStackTrace(); 47 throw e; 50 48 } 51 return null;52 49 } 53 50 54 public static int queryUp(String query, String ... args) {51 public static int queryUp(String query, String ... args) throws SQLException { 55 52 try { 56 53 PreparedStatement prep = conn.prepareStatement(query); … … 69 66 return result; 70 67 } catch (SQLException e) { 71 // TODO Auto-generated catch block 72 e.printStackTrace(); 68 throw e; 73 69 } 74 return -1;75 70 } 76 71 77 public static void creaTable(int tabella) {72 public static void creaTable(int tabella) throws SQLException { 78 73 79 74 if ((tabella & TBL_CANZONE) != 0) { … … 92 87 /** 93 88 * Creo il database e lo popolo 89 * @throws SQLException 94 90 */ 95 public static void crea() {91 public static void crea() throws SQLException { 96 92 Database.creaTable(Database.TBL_CANZONE | Database.TBL_SCALETTA | Database.TBL_SCALETTA_CANZONE); 97 93 queryUp("DELETE FROM scaletta"); -
trunk/src/oberheditor/Scaletta.java
r40 r57 24 24 * Creo una scaletta caricandola dal database. 25 25 * @param id L'id della scaletta 26 * @throws SQLException 26 27 */ 27 public Scaletta(int id) {28 public Scaletta(int id) throws SQLException { 28 29 this(); 29 30 if (id <= 0) throw new IllegalArgumentException("L'id deve essere > 0."); … … 68 69 69 70 } catch (SQLException e) { 70 // TODO Auto-generated catch block 71 e.printStackTrace(); 71 throw e; 72 72 } 73 73 … … 142 142 143 143 144 public boolean salvaDB() {144 public boolean salvaDB() throws SQLException { 145 145 Database.creaTable(Database.TBL_CANZONE | Database.TBL_SCALETTA | Database.TBL_SCALETTA_CANZONE); 146 146 -
trunk/src/oberheditor/gui/WinCanzone.java
r52 r57 1 1 package oberheditor.gui; 2 3 import java.sql.SQLException; 2 4 3 5 import oberheditor.Canzone; … … 258 260 private void salvaCanzoneEdEsci() { 259 261 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(); 263 270 } 264 271 } 265 272 266 273 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 } 268 280 txtNome.setText(canzone.getNome()); 269 281 -
trunk/src/oberheditor/gui/WinMain.java
r55 r57 196 196 // TODO: magari unificare con una query unica, invece che mille query nel for 197 197 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 } 204 208 } 205 209 } … … 301 305 // TODO: magari unificare con una query unica, invece che mille query nel for 302 306 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 } 309 317 } 310 318 } … … 354 362 355 363 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 } 358 373 359 374 // Se avevo gia' selezione, la ripristino dopo aver ricaricato. … … 388 403 } 389 404 } catch (SQLException e) { 390 // TODO Auto-generated catch block405 Main.errorBox(win, "Errore di connessione al database."); 391 406 e.printStackTrace(); 392 407 } … … 395 410 396 411 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 399 422 400 423 // Se avevo gia' selezione, la ripristino dopo aver ricaricato. … … 426 449 } 427 450 } catch (SQLException e) { 428 // TODO Auto-generated catch block451 Main.errorBox(win, "Errore di connessione al database."); 429 452 e.printStackTrace(); 430 453 } -
trunk/src/oberheditor/gui/WinScaletta.java
r56 r57 433 433 } 434 434 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(); 438 443 } 439 444 } … … 478 483 479 484 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 482 495 canzoniDisponibili = new Vector<Canzone>(); 483 496 canzoniDisponibiliOriginale = new Vector<Canzone>(); … … 498 511 listCanzoniDisponibili.select(0); 499 512 } catch (SQLException e) { 500 // TODO Auto-generated catch block513 Main.errorBox(win, "Errore di connessione al database."); 501 514 e.printStackTrace(); 502 515 } … … 504 517 505 518 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 } 508 526 txtNome.setText(scaletta.getNome()); 509 527