Implemented AddContact mechanism on the server

(currently unfinished an not working see stack trace for current
problem)
This commit is contained in:
DieGurke 2020-02-09 22:16:33 +01:00
parent 1c8b639014
commit ec90a3c2f5
3 changed files with 16 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import envoy.server.data.ConfigItem;
import envoy.server.database.PersistenceManager;
import envoy.server.net.ObjectMessageProcessor;
import envoy.server.net.ObjectMessageReader;
import envoy.server.processors.ContactOperationProcessor;
import envoy.server.processors.ContactsRequestProcesor;
import envoy.server.processors.IdGeneratorRequestProcessor;
import envoy.server.processors.LoginCredentialProcessor;
@ -44,6 +45,7 @@ public class Startup {
processors.add(new UserStatusChangeProcessor());
processors.add(new IdGeneratorRequestProcessor());
processors.add(new ContactsRequestProcesor());
processors.add(new ContactOperationProcessor());
Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors));
initializeCurrentMessageId();

View File

@ -3,7 +3,17 @@ package envoy.server.data;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* This class serves as a way to let Hibernate communicate with the server

View File

@ -194,7 +194,9 @@ public class PersistenceManager {
* @return the contacts of this User - currently everyone using Envoy
* @since Envoy Server Standalone v0.1-alpha
*/
public List<User> getContacts(User user) { return entityManager.createQuery("FROM User").getResultList(); }
public List<User> getContacts(User user) {
return entityManager.createNamedQuery("getContactsOfUser").setParameter("user", user).getResultList();
}
// TODO current solution gets all users, not just contacts. Should be changed to
// entityManager.createNamedQuery("getContactsOfUser").setParameter("user",
// user).getResultList();