openmeetings-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebawag...@apache.org
Subject svn commit: r1441702 - in /openmeetings/trunk/singlewebapp/src/org/apache/openmeetings: data/conference/dao/ClientDao.java persistence/beans/rooms/Client.java test/session/TestDbSession.java
Date Sat, 02 Feb 2013 05:57:37 GMT
Author: sebawagner
Date: Sat Feb  2 05:57:37 2013
New Revision: 1441702

URL: http://svn.apache.org/viewvc?rev=1441702&view=rev
Log:
OPENMEETINGS-460 Fixing rest of ordinary ClientDao functionalities

Modified:
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/dao/ClientDao.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/rooms/Client.java
    openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestDbSession.java

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/dao/ClientDao.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/dao/ClientDao.java?rev=1441702&r1=1441701&r2=1441702&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/dao/ClientDao.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/conference/dao/ClientDao.java
Sat Feb  2 05:57:37 2013
@@ -22,6 +22,7 @@ import java.util.List;
 
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
 import javax.persistence.TypedQuery;
 
 import org.apache.openmeetings.persistence.beans.basic.Server;
@@ -61,7 +62,26 @@ public class ClientDao {
 	}
 	
 	public void delete(Client entity) {
-		em.remove(entity);
+		Query q = em.createNamedQuery("deletedById");
+		q.setParameter("id", entity.getId());
+		q.executeUpdate();
+	}
+	
+	public void removeClientByServerAndStreamId(Server server, String streamId) {
+		Query q = em.createNamedQuery("deletedByServerAndStreamId");
+		q.setParameter("server", server);
+		q.setParameter("streamid", streamId);
+		q.executeUpdate();
+	}
+	
+	public int countClients() {
+		return em.createNamedQuery("countClients", Long.class).getSingleResult().intValue();
+	}
+	
+	public int countClientsByServer(Server server) {
+		TypedQuery<Long> q = em.createNamedQuery("countClientsByServer", Long.class);
+		q.setParameter("server", server);
+		return q.getSingleResult().intValue();
 	}
 
 	public long countClientsByServerAndStreamId(Server server, String streamId) {
@@ -114,5 +134,23 @@ public class ClientDao {
 	public List<Client> getClients() {
 		return em.createNamedQuery("getClients", Client.class).getResultList();
 	}
-	
+
+	public List<Client> getClientsByUserId(Server server, Long userId) {
+		TypedQuery<Client> q = em.createNamedQuery("getClientsByUserId", Client.class);
+		q.setParameter("server", server);
+		q.setParameter("user_id", userId);	
+		return q.getResultList();
+	}
+
+	public List<Client> getClientsByRoomId(Long roomId) {
+		TypedQuery<Client> q = em.createNamedQuery("getClientsByRoomId", Client.class);
+		q.setParameter("room_id", roomId);	
+		return q.getResultList();
+	}
+
+	public List<Long> getRoomsIdsByServer(Server server) {
+		//TODO needed for cluster implementation	
+		return null;
+	}
+
 }

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/rooms/Client.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/rooms/Client.java?rev=1441702&r1=1441701&r2=1441702&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/rooms/Client.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/persistence/beans/rooms/Client.java
Sat Feb  2 05:57:37 2013
@@ -44,13 +44,19 @@ import org.apache.openmeetings.utils.mat
 @Entity
 @NamedQueries({
 	@NamedQuery(name = "deleteAll", query = "DELETE FROM Client"),
+	@NamedQuery(name = "deletedById", query = "DELETE FROM Client c WHERE c.id = :id"),
 	@NamedQuery(name = "deleteClientsByServer", query = "DELETE FROM Client c WHERE c.server
= :server"),
+	@NamedQuery(name = "deletedByServerAndStreamId", query = "DELETE FROM Client c WHERE c.server
= :server AND c.streamid LIKE :streamid"),
+	@NamedQuery(name = "countClients", query = "SELECT count(c.id) FROM Client c"),
+	@NamedQuery(name = "countClientsByServer", query = "SELECT count(c.id) FROM Client c WHERE
c.server = :server"),
 	@NamedQuery(name = "countClientsByServerAndStreamId", query = "SELECT count(c.id) FROM Client
c WHERE c.streamid LIKE :streamid AND c.server = :server"),
 	@NamedQuery(name = "getClientByServerAndStreamId", query = "SELECT c FROM Client c WHERE
c.streamid LIKE :streamid AND c.server = :server"),
 	@NamedQuery(name = "getClientsByPublicSIDAndServer", query = "SELECT c FROM Client c WHERE
c.publicSID LIKE :publicSID AND c.server = :server"),
 	@NamedQuery(name = "getClientsByPublicSID", query = "SELECT c FROM Client c WHERE c.publicSID
LIKE :publicSID"),
 	@NamedQuery(name = "getClientsByServer", query = "SELECT c FROM Client c WHERE c.server
= :server"),
-	@NamedQuery(name = "getClients", query = "SELECT c FROM Client c")
+	@NamedQuery(name = "getClients", query = "SELECT c FROM Client c"),
+	@NamedQuery(name = "getClientsByUserId", query = "SELECT c FROM Client c WHERE c.server
= :server AND c.user_id = :user_id"),
+	@NamedQuery(name = "getClientsByRoomId", query = "SELECT c FROM Client c WHERE c.room_id
= :room_id")
 })
 @Table(name = "client")
 public class Client implements Serializable {

Modified: openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestDbSession.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestDbSession.java?rev=1441702&r1=1441701&r2=1441702&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestDbSession.java
(original)
+++ openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/session/TestDbSession.java
Sat Feb  2 05:57:37 2013
@@ -64,6 +64,7 @@ public class TestDbSession extends Abstr
 		Client cl1 = new Client();
 		cl1.setStreamid("1");
 		cl1.setServer(null);
+		cl1.setUser_id(1L);
 		cl1.setRoom_id(1L);
 		cl1.setPublicSID("public1");
 		clientDao.add(cl1);
@@ -71,7 +72,8 @@ public class TestDbSession extends Abstr
 		Client cl2 = new Client();
 		cl2.setStreamid("2");
 		cl2.setServer(null);
-		cl2.setRoom_id(2L);
+		cl2.setRoom_id(1L);
+		cl2.setUser_id(2L);
 		cl2.setPublicSID("public2");
 		clientDao.add(cl2);
 
@@ -79,6 +81,7 @@ public class TestDbSession extends Abstr
 		cl3.setStreamid("3");
 		cl3.setServer(server);
 		cl3.setRoom_id(3L);
+		cl3.setUser_id(3L);
 		cl3.setPublicSID("public3");
 		clientDao.add(cl3);
 		
@@ -137,8 +140,59 @@ public class TestDbSession extends Abstr
 		List<Client> clientsAll = clientDao.getClients();
 		assertEquals(3, clientsAll.size());
 		
+		//by userid
+		List<Client> clTest_User_1_list = clientDao.getClientsByUserId(null, 1L);
+		assertEquals(cl1.getId(), clTest_User_1_list.get(0).getId());
+		
+		List<Client> clTest_User_3_list = clientDao.getClientsByUserId(server, 3L);
+		assertEquals(cl3.getId(), clTest_User_3_list.get(0).getId());
+		
+		List<Client> clTest_UserFail_list = clientDao.getClientsByUserId(null, 3L);
+		assertEquals(0, clTest_UserFail_list.size());
+		
+		//by roomid
+		List<Client> clTest_Room_1_list = clientDao.getClientsByRoomId(1L);
+		assertEquals(2, clTest_Room_1_list.size());
+		
+		List<Client> clTest_Room_3_list = clientDao.getClientsByRoomId(3L);
+		assertEquals(cl3.getId(), clTest_Room_3_list.get(0).getId());
+		
+		List<Client> clTest_RoomFail_list = clientDao.getClientsByRoomId(2L);
+		assertEquals(0, clTest_RoomFail_list.size());
+		
+		//count all
+		int countAll = clientDao.countClients();
+		assertEquals(3, countAll);
+		
+		//count by server
+		int clTest_Count_1_list = clientDao.countClientsByServer(null);
+		assertEquals(2, clTest_Count_1_list);
+		
+		int clTest_Count_3_list = clientDao.countClientsByServer(server);
+		assertEquals(1, clTest_Count_3_list);
+		
+		//remove by id
+		clientDao.delete(cl1);
+		
+		int clTest_Count_Delete_list = clientDao.countClientsByServer(null);
+		assertEquals(1, clTest_Count_Delete_list);
+		
+		//remove by server and streamid
+		clientDao.removeClientByServerAndStreamId(null, "2");
+		
+		clTest_Count_Delete_list = clientDao.countClientsByServer(null);
+		assertEquals(0, clTest_Count_Delete_list);
+		
+		clientDao.removeClientByServerAndStreamId(server, "3");
+		
+		clTest_Count_Delete_list = clientDao.countClientsByServer(server);
+		assertEquals(0, clTest_Count_Delete_list);
+		
+		//delete all
 		clientDao.cleanAllClients();
 
+		countAll = clientDao.countClients();
+		assertEquals(0, countAll);
 	}
 
 }



Mime
View raw message