88import pExceptions .MusicNotFoundException ;
99
1010public class MusicaControl {
11- private ArrayList <Musica > lstMusica ;
1211 private final MusicaDAO dao ;
1312 private static MusicaControl musicaControl ;
1413
1514 private MusicaControl () throws SQLException {
1615 this .dao = MusicaDAO .getInstance ();
17- this .lstMusica = new ArrayList <Musica >();
18- fetch ();
1916 }
2017
2118 public static MusicaControl getInstance () throws SQLException {
@@ -27,52 +24,54 @@ public static MusicaControl getInstance() throws SQLException {
2724
2825 public void add (Musica e ) throws SQLException {
2926 dao .add (e );
30- lstMusica .add (e );
3127 }
3228
3329 public Musica find (String nome , String autor ) throws MusicNotFoundException , SQLException {
3430 return findAll (nome , autor ).get (0 );
3531 }
3632
3733 public ArrayList <Musica > findAll (String nome , String autor ) throws MusicNotFoundException , SQLException {
38- fetch ();
39- ArrayList <Musica > lMusicas = new ArrayList <Musica >();
34+ ArrayList <Musica > lMusicas = dao .selectByAuthorANDName (nome , autor );
4035
36+ /*
4137 for (Musica musica : lstMusica) {
4238 if (musica.getAutor().toLowerCase().startsWith(autor.toLowerCase())
43- && musica .getNome ().toLowerCase ().startsWith (nome .toLowerCase ()))
44- lMusicas .add (musica );
39+ && musica.getNome().toLowerCase().startsWith(nome.toLowerCase()))
40+ lMusicas.add(musica);
4541 }
46-
42+ */
43+
4744 if (lMusicas .size () < 1 )
4845 throw new MusicNotFoundException (MusicNotFoundException .NotFound );
4946
5047 return lMusicas ;
5148 }
5249
5350 public ArrayList <Musica > findByName (String nome ) throws MusicNotFoundException , SQLException {
54- fetch ();
55- ArrayList <Musica > lMusicas = new ArrayList <Musica >();
51+ ArrayList <Musica > lMusicas = dao .selectByName (nome );
5652
53+ /*
5754 for (Musica musica : lstMusica) {
5855 if (musica.getNome().toLowerCase().startsWith(nome.toLowerCase()))
5956 lMusicas.add(musica);
6057 }
61-
58+ */
59+
6260 if (lMusicas .size () > 0 )
6361 return lMusicas ;
6462 else
6563 throw new MusicNotFoundException (MusicNotFoundException .NotFoundByName );
66- }
67-
64+ }
65+
6866 public ArrayList <Musica > findByAuthor (String autor ) throws MusicNotFoundException , SQLException {
69- fetch ( );
70- ArrayList < Musica > lMusicas = new ArrayList < Musica >();
71-
67+ ArrayList < Musica > lMusicas = dao . selectByAuthor ( autor );
68+
69+ /*
7270 for (Musica musica : lstMusica) {
7371 if (musica.getAutor().toLowerCase().startsWith(autor.toLowerCase()))
7472 lMusicas.add(musica);
7573 }
74+ */
7675
7776 if (lMusicas .size () > 0 )
7877 return lMusicas ;
@@ -83,7 +82,7 @@ public ArrayList<Musica> findByAuthor(String autor) throws MusicNotFoundExceptio
8382 /*
8483 public Musica findPerf(String nome, String autor) throws MusicNotFoundException, SQLException {
8584 fetch();
86-
85+
8786 for (Musica musica : lstMusica) {
8887 if (musica.getAutor().equalsIgnoreCase(autor)
8988 && musica.getNome().equalsIgnoreCase(nome))
@@ -97,21 +96,12 @@ public Musica findPerf(String nome, String autor) throws MusicNotFoundException,
9796 public void remove (String nome , String autor ) throws MusicNotFoundException , SQLException {
9897 remove (find (nome , autor ));
9998 }
100-
99+
101100 public void remove (Musica e ) throws MusicNotFoundException , SQLException {
102- lstMusica .remove (e );
103101 dao .remove (e );
104102 }
105103
106- private void fetch () throws SQLException {
107- try {
108- this .lstMusica = dao .get ();
109- } catch (SQLException e ) {
110- throw new SQLException ("Erro: Impossível receber valores do banco de dados." );
111- }
112- }
113-
114- public ArrayList <Musica > getList () {
115- return lstMusica ;
104+ public ArrayList <Musica > getList () throws SQLException {
105+ return dao .select ();
116106 }
117107}
0 commit comments