Updated PersistenceManager as per @CyB3RC0nN0R 's request

This commit is contained in:
delvh 2020-01-04 15:39:43 +01:00
parent 0ecc9cf0e9
commit 8d0e334d60

View File

@ -23,25 +23,12 @@ public class PersistenceManager {
private EntityManager entityManager = Persistence.createEntityManagerFactory("envoy").createEntityManager();
/**
*
* @since Envoy Server Standalone v0.1-alpha
*/
public PersistenceManager() {
/*
* // TODO TESTING
* User user = new User(3, "t");
* User user2 = new User(2, "w");
* Message msg = new MessageBuilder(user.getId(), user2.getId()).build();
* entityManager.getTransaction().begin();
* entityManager.persist(user);
* entityManager.persist(user2);
* entityManager.persist(msg);
* entityManager.getTransaction().commit();
*/ // TODO delete until here
}
public PersistenceManager() {}
/**
* Adds a user to the database.
* Adds a {@link User} to the database.
*
* @param User the {@link User} to add to the database
* @since Envoy Server Standalone v0.1-alpha
@ -49,29 +36,28 @@ public class PersistenceManager {
public void addUser(User User) { entityManager.persist(User); }
/**
* Adds a message to the database.
* Adds a {@link Message} to the database.
*
* @param message the {@link Message} to add to the database
* @since Envoy Server Standalone v0.1-alpha
*/
public void addMessage(Message message) { entityManager.persist(message); }// TODO these functions or the one below?
public void addMessage(Message message) { entityManager.persist(message); }
/**
* This is a delegate function for {@link EntityManager#persist} in order to add
* an {@link User} / a {@link Message} into the database
* Updates a {@link User} in the database
*
* @param obj the object to add to the database
* @param user the {@link User} to add to the database
* @since Envoy Server Standalone v0.1-alpha
*/
public void addObject(Object obj) { entityManager.persist(obj); }
public void updateUser(User user) { entityManager.unwrap(Session.class).merge(user); }
/**
* Updates a row of database objects, either a Message or a User with new data.
* Updates a {@link Message} in the database.
*
* @param obj the object to update (existing User/Message)
* @param message the message to update
* @since Envoy Server Standalone v0.1-alpha
*/
public void updateObject(Object obj) { entityManager.unwrap(Session.class).merge(obj); }
public void updateMessage(Message message) { entityManager.unwrap(Session.class).merge(message); }
/**
* Searches for a user with a specific id.