Doubt User table and Friend table

1

Hey guys, I need help, I'm a beginner in java, and I'm doing a college job where it's going to be a mini social network, in the beginning let's do user registration, inside the beans class, user receives a Friend List I'm com a doubt.

My question, how am I going to relate this to DAO and if I need to add some data in the USER_AMIGO table with status etc ???

Someone can give me an example.

Tables in the USER and the other FRIEND_USER.

             Tabela USUARIO

+-----------+------------------+----------+----------------+
| CD_LOGIN  | NOME_DE_USUARIO  |  SENHA   | EMAIL_USUARIO  |
+-----------+------------------+----------+----------------+
|       1   |      test        |   test   |       test     |
|       2   |      test        |   test   |       test     |
+---------+----------+----------+--------------------------+

              Tabela AMIGO_USUARIO

+-----------+---------------+-----------------+
| CD_AMIGO  | EMAIL_USUARIO | EMAIL_USUARIO2  |
+-----------+---------------+-----------------+
|       1   |      test     |      test       |    
|       2   |      test     |      test       |           
+---------+----------+----------+-------------+
    
asked by anonymous 15.10.2015 / 15:21

1 answer

0

You should have in the associative table the status. And another important point, use user code and not email. If you ever want to change the email, you will have problems.

Tabela AMIGO_USUARIO

+-----------+---------------+-----------------+-------------+
| CD_AMIGO  | CD_USUARIO1   | CD_USUARIO2     |   status    |
+-----------+---------------+-----------------+-------------+
|       1   |      test     |      test       |    1        |
|       2   |      test     |      test       |    0        |
+-----------+---------------+-----------------+-------------+

In DAO you do not relate the data, you only access it. You will have the relationship in the Model, it will represent the bank entity in your application. Ex:

public class Amizade {
        public Amigo amigo1;
        public Amigo amigo2;
        int status;
    }
    // Essa abaixo é a DAO
    public class AmizadeRepository{
       public ArrayList<Amizade> fetchAll(){
        // fazer a consulta e retornar a lista
       }
    }
    
15.10.2015 / 15:34