|  |  |  | @@ -3,6 +3,7 @@ package envoy.server.database; | 
		
	
		
			
				|  |  |  |  | import java.util.List; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | import javax.persistence.EntityManager; | 
		
	
		
			
				|  |  |  |  | import javax.persistence.EntityTransaction; | 
		
	
		
			
				|  |  |  |  | import javax.persistence.Persistence; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | import envoy.server.data.ConfigItem; | 
		
	
	
		
			
				
					
					|  |  |  | @@ -19,6 +20,9 @@ import envoy.server.data.User; | 
		
	
		
			
				|  |  |  |  |  */ | 
		
	
		
			
				|  |  |  |  | public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	private final EntityManager		entityManager	= Persistence.createEntityManagerFactory("envoy").createEntityManager(); | 
		
	
		
			
				|  |  |  |  | 	private final EntityTransaction	transaction		= entityManager.getTransaction(); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	private static final PersistenceManager persistenceManager = new PersistenceManager(); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
	
		
			
				
					
					|  |  |  | @@ -26,7 +30,10 @@ public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  | 	 * | 
		
	
		
			
				|  |  |  |  | 	 * @since Envoy Server Standalone v0.1-alpha | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	private PersistenceManager() {} | 
		
	
		
			
				|  |  |  |  | 	private PersistenceManager() { | 
		
	
		
			
				|  |  |  |  | 		transaction.begin(); | 
		
	
		
			
				|  |  |  |  | 		Runtime.getRuntime().addShutdownHook(new Thread(() -> transaction.commit())); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
		
			
				|  |  |  |  | 	 * @return the {@link PersistenceManager} singleton | 
		
	
	
		
			
				
					
					|  |  |  | @@ -34,8 +41,6 @@ public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public static PersistenceManager getPersistenceManager() { return persistenceManager; } | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	private EntityManager entityManager = Persistence.createEntityManagerFactory("envoy").createEntityManager(); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
		
			
				|  |  |  |  | 	 * Adds a {@link User} to the database. | 
		
	
		
			
				|  |  |  |  | 	 * | 
		
	
	
		
			
				
					
					|  |  |  | @@ -43,9 +48,8 @@ public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  | 	 * @since Envoy Server Standalone v0.1-alpha | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public void addUser(User User) { | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().begin(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.persist(User); | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().commit(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.flush(); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
	
		
			
				
					
					|  |  |  | @@ -55,9 +59,8 @@ public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  | 	 * @since Envoy Server Standalone v0.1-alpha | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public void addMessage(Message message) { | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().begin(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.persist(message); | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().commit(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.flush(); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
	
		
			
				
					
					|  |  |  | @@ -67,9 +70,8 @@ public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  | 	 * @since Envoy Server Standalone v0.1-alpha | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public void addConfigItem(ConfigItem configItem) { | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().begin(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.persist(configItem); | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().commit(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.flush(); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
	
		
			
				
					
					|  |  |  | @@ -79,9 +81,8 @@ public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  | 	 * @since Envoy Server Standalone v0.1-alpha | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public void updateUser(User user) { | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().begin(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.merge(user); | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().commit(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.flush(); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
	
		
			
				
					
					|  |  |  | @@ -91,9 +92,8 @@ public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  | 	 * @since Envoy Server Standalone v0.1-alpha | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public void updateMessage(Message message) { | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().begin(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.merge(message); | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().commit(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.flush(); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
	
		
			
				
					
					|  |  |  | @@ -103,9 +103,8 @@ public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  | 	 * @since Envoy Server Standalone v0.1-alpha | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public void updateConfigItem(ConfigItem configItem) { | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().begin(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.merge(configItem); | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().commit(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.flush(); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
	
		
			
				
					
					|  |  |  | @@ -115,9 +114,8 @@ public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  | 	 * @since Envoy Server Standalone v0.1-alpha | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public void deleteUser(User user) { | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().begin(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.remove(user); | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().commit(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.flush(); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
	
		
			
				
					
					|  |  |  | @@ -127,9 +125,8 @@ public class PersistenceManager { | 
		
	
		
			
				|  |  |  |  | 	 * @since Envoy Server Standalone v0.1-alpha | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public void deleteMessage(Message message) { | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().begin(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.remove(message); | 
		
	
		
			
				|  |  |  |  | 		entityManager.getTransaction().commit(); | 
		
	
		
			
				|  |  |  |  | 		entityManager.flush(); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
	
		
			
				
					
					|  |  |  |   |