deleted applyAction method as per @CyB3RC0nN0R s request

additionally inserted necessary TODO for a method that may cause
problems in the future.
This commit is contained in:
delvh 2020-02-05 21:53:36 +01:00
parent f04c81bbf0
commit 1940acb4ae
2 changed files with 6 additions and 38 deletions

View File

@ -132,37 +132,6 @@ public class PersistenceManager {
entityManager.getTransaction().commit(); entityManager.getTransaction().commit();
} }
/**
* @param action the action that should be applied for this entity. Case does
* <b>not</b> matter.<br>
* Currently supported values are:<br>
* -"add"/"persist" to add an object to the database<br>
* -"update"/"merge" to update this object in the database<br>
* -"delete"/"remove" to delete this object in the database
* @param entity the object to apply the action to
* @since Envoy Server Standalone v0.1-alpha
*/
public void applyAction(String action, Object entity) {
entityManager.getTransaction().begin();
switch (action.trim().toLowerCase()) {
case "add":
case "persist":
entityManager.persist(entity);
break;
case "update":
case "merge":
entityManager.merge(entity);
break;
case "delete":
case "remove":
entityManager.remove(entity);
break;
default:
throw new IllegalStateException("Unknown action: " + action + " was selected to be executed in the database");
}
entityManager.getTransaction().commit();
}
/** /**
* Searches for a {@link User} with a specific id. * Searches for a {@link User} with a specific id.
* *

View File

@ -22,8 +22,8 @@ import envoy.server.net.ObjectWriteProxy;
*/ */
public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChangeEvent> { public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChangeEvent> {
private static ObjectWriteProxy writeProxy; private static ObjectWriteProxy writeProxy;
private static PersistenceManager persistenceManager = PersistenceManager.getPersistenceManager(); private static PersistenceManager persistenceManager = PersistenceManager.getPersistenceManager();
@Override @Override
public Class<UserStatusChangeEvent> getInputClass() { return UserStatusChangeEvent.class; } public Class<UserStatusChangeEvent> getInputClass() { return UserStatusChangeEvent.class; }
@ -59,9 +59,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
* @param evt the {@link UserStatusChangeEvent} * @param evt the {@link UserStatusChangeEvent}
* @since Envoy Server Standalone v0.1-alpha * @since Envoy Server Standalone v0.1-alpha
*/ */
public static void updateUserStatus(UserStatusChangeEvent evt) { public static void updateUserStatus(UserStatusChangeEvent evt) { updateUserStatus(persistenceManager.getUserById(evt.getId())); }
updateUserStatus(persistenceManager.getUserById(evt.getId()));
}
/** /**
* notifies active contacts of this {@link User} that his {@link UserStatus} has * notifies active contacts of this {@link User} that his {@link UserStatus} has
@ -94,5 +92,6 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
* @since Envoy Server Standalone v0.1-alpha * @since Envoy Server Standalone v0.1-alpha
*/ */
public static void setWriteProxy(ObjectWriteProxy writeProxy) { UserStatusChangeProcessor.writeProxy = writeProxy; } public static void setWriteProxy(ObjectWriteProxy writeProxy) { UserStatusChangeProcessor.writeProxy = writeProxy; }
// TODO may cause an problem if two clients log in at the same time.
// Change Needed.
} }