From: Florian L. <fle...@us...> - 2005-11-08 13:15:02
|
Update of /cvsroot/magicmap/magicmapserver/src/net/sf/magicmap/server/facade In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4716/src/net/sf/magicmap/server/facade Modified Files: PositionFacade2.java Log Message: anpassen der webservices an PositionCache Index: PositionFacade2.java =================================================================== RCS file: /cvsroot/magicmap/magicmapserver/src/net/sf/magicmap/server/facade/PositionFacade2.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PositionFacade2.java 8 Nov 2005 10:29:13 -0000 1.7 --- PositionFacade2.java 8 Nov 2005 13:14:50 -0000 1.8 *************** *** 95,126 **** pos.setPosX(positionX); pos.setPosY(positionY); - pos.setLastModified(System.currentTimeMillis()); - //pos.setId(); //brauchen wir wahrscheinlich nicht PositionCache.getPositionCache().createOrUpdatePosition(map,pos); } - /** - * @param character - * @param pm - * @param client - * @param pos - * @throws MapException - */ - private void setNewSignalCharacter(SignalCharacterDTO character, PersistenceManager pm, Client client, Position pos) - throws MapException{ - // alle Scanresults dieser Position löschen - pm.deletePersistentAll(pos.getScanResults()); - SimpleScanResultDTO[] dtos = character.getSimpleScanResults(); - if (dtos != null){ - for (int i = 0; i < dtos.length; i++){ - AccessPoint ap = findOrCreateAccessPoint(dtos[i].getMacAP(), pm); - //@TODO think about? ap.setSsid(dtos[i].getSsid()); - ScanResult sr = new ScanResult(client, ap, dtos[i].getSignalLevel(), dtos[i].getNoise(), new Timestamp(System - .currentTimeMillis())); //@TODO use lastSeen - pm.makePersistent(sr); - sr.setPosition(pos); - } - } - } /** --- 95,101 ---- *************** *** 154,177 **** } - /** - * @param positionName - * @param map - * @param pm - * @return - */ - private Position checkPosition(String positionName, Map map, PersistenceManager pm){ - Position result = null; - Collection results; - Extent e = pm.getExtent(Position.class, true); - Query query = pm.newQuery(e, "name == myName && map == myMap"); - query.declareParameters("java.lang.String myName, net.sf.magicmap.db.Map myMap"); - query.declareImports("import java.lang.String; import net.sf.magicmap.db.Map;"); - results = (Collection) query.execute(positionName, map); - if (results != null && !results.isEmpty()){ - result = (Position) results.iterator().next(); - } - return result; - - } /** --- 129,132 ---- *************** *** 243,306 **** * @throws SessionException */ - private Position checkPosition(long positionId, PersistenceManager pm) throws MapException{ - Position result = null; - Collection results; - Extent e = pm.getExtent(Position.class, true); - Query query = pm.newQuery(e, "id == myId"); - query.declareParameters("java.lang.Long myId"); - results = (Collection) query.execute(new Long(positionId)); - if (results != null && !results.isEmpty()){ - result = (Position) results.iterator().next(); - } else{ - pm.currentTransaction().rollback(); - throw new MapException("Position mit der id:" + positionId + " existiert nicht"); - } - return result; - - } - - /** - * @param client - * @param map - * @return - */ - private Position getPositionForClientAndMap(Client client, Map map, PersistenceManager pm){ - Position result = null; - Collection results; - Extent e = pm.getExtent(Position.class, true); - Query query = pm.newQuery(e, "client == myClient && map == myMap"); - query.declareParameters("net.sf.magicmap.db.Client myClient, net.sf.magicmap.db.Map myMap"); - query.declareImports("import net.sf.magicmap.db.Client; import net.sf.magicmap.db.Map;"); - results = (Collection) query.execute(client, map); - if (results != null && !results.isEmpty()){ - result = (Position) results.iterator().next(); - } - return result; - } - - /** - * @param client - * @param map - * @return - */ - private Position getPositionForApAndMap(AccessPoint ap, Map map, PersistenceManager pm){ - Position result = null; - Collection results; - Extent e = pm.getExtent(Position.class, true); - Query query = pm.newQuery(e, "accessPoint == myAp && map == myMap"); - query.declareParameters("net.sf.magicmap.db.AccessPoint myAp, net.sf.magicmap.db.Map myMap"); - query.declareImports("import net.sf.magicmap.db.AccessPoint; import net.sf.magicmap.db.Map;"); - results = (Collection) query.execute(ap, map); - if (results != null && !results.isEmpty()){ - result = (Position) results.iterator().next(); - } - return result; - } - - /** - * @param sessionId - * @param tx - * @throws SessionException - */ private Client checkClient(String mac, PersistenceManager pm) throws MapException{ if (mac == null || "".equals(mac)){ --- 198,201 ---- *************** *** 331,363 **** this.logger.info("createOrUpdateClientPosition()"); PersistenceManager pm = null; - Transaction tx = null; try{ ! pm = JDOUtil.pmfactory.getPersistenceManager(); ! tx = pm.currentTransaction(); ! tx.begin(); ! int count = 0; ! while (count < 3){ ! try{ ! createOrUpdateClientPositionInternal(sessionId, mapName, positionX, positionY, character, clientMac, fixed, ! pm); ! break; ! } catch (javax.jdo.JDODataStoreException jdoEx){ ! if (tx.isActive()){ ! tx.rollback(); ! } ! count++; ! tx.begin(); ! } ! } ! if (count == 3){ ! if (tx.isActive()){ ! tx.rollback(); ! } ! System.out.println("createOrUpdateClientPosition - GAVE UP - repeated 3 times"); ! } ! if (tx.isActive()){ ! tx.commit(); ! } ! } catch (Exception e){ e.printStackTrace(); --- 226,232 ---- this.logger.info("createOrUpdateClientPosition()"); PersistenceManager pm = null; try{ ! pm = JDOUtil.pmfactory.getPersistenceManager(); ! createOrUpdateClientPositionInternal(sessionId, mapName, positionX, positionY, character, clientMac, fixed, pm); } catch (Exception e){ e.printStackTrace(); *************** *** 369,375 **** } } finally{ - if (tx.isActive()){ - tx.rollback(); - } JDOUtil.closePM(pm); } --- 238,241 ---- *************** *** 395,411 **** Map map = checkMap(mapName, positionX, positionY, pm); Client client = checkClient(clientMac, pm); ! ! Position pos = getPositionForClientAndMap(client, map, pm); ! if (pos == null){ ! pos = new Position(map, positionX, positionY, client.getMac()); ! pm.makePersistent(pos); } ! pos.setClient(client); ! pos.setDeleted(false); ! pos.setName(client.getMac()); pos.setPosX(positionX); pos.setPosY(positionY); ! pos.setFixed(fixed); ! setNewSignalCharacter(character, pm, client, pos); } --- 261,278 ---- Map map = checkMap(mapName, positionX, positionY, pm); Client client = checkClient(clientMac, pm); ! PositionDTO pos = new PositionDTO(); ! if (client != null){ ! ClientDTO clientDTO = new ClientDTO(); ! clientDTO.setMac(client.getMac()); ! clientDTO.setId(new Long(client.getId())); ! clientDTO.setName(client.getName()); ! pos.setClient(clientDTO); } ! pos.setCharacter(character); ! pos.setFixed(fixed); ! pos.setName(clientMac); pos.setPosX(positionX); pos.setPosY(positionY); ! PositionCache.getPositionCache().createOrUpdatePosition(map,pos); } *************** *** 417,442 **** this.logger.info("createOrUpdateAccessPosition()"); PersistenceManager pm = null; - Transaction tx = null; try{ pm = JDOUtil.pmfactory.getPersistenceManager(); - tx = pm.currentTransaction(); - tx.begin(); checkSession(sessionId, pm); Map map = checkMap(mapName, positionX, positionY, pm); AccessPoint ap = findOrCreateAccessPoint(accessPointMac, pm); - Position pos = getPositionForApAndMap(ap, map, pm); - if (pos == null){ - pos = new Position(map, positionX, positionY, ap.getMac()); - pm.makePersistent(pos); - } - pos.setAccessPoint(ap); - pos.setDeleted(false); - pos.setName(ap.getMac()); - pos.setPosX(positionX); - pos.setPosY(positionY); - pos.setFixed(fixed); ! tx.commit(); } catch (Exception e){ e.printStackTrace(); --- 284,307 ---- this.logger.info("createOrUpdateAccessPosition()"); PersistenceManager pm = null; try{ pm = JDOUtil.pmfactory.getPersistenceManager(); checkSession(sessionId, pm); Map map = checkMap(mapName, positionX, positionY, pm); AccessPoint ap = findOrCreateAccessPoint(accessPointMac, pm); ! PositionDTO pos = new PositionDTO(); ! if (ap != null){ ! AccessPointDTO apDTO = new AccessPointDTO(); ! apDTO.setMac(ap.getMac()); ! apDTO.setSsid(ap.getSsid()); // zur zeit noch nicht verwendet TODO ssid setzen ! pos.setAccessPoint(apDTO); ! } ! pos.setFixed(fixed); ! pos.setName(accessPointMac); ! pos.setPosX(positionX); ! pos.setPosY(positionY); ! PositionCache.getPositionCache().createOrUpdatePosition(map,pos); ! } catch (Exception e){ e.printStackTrace(); *************** *** 448,454 **** } } finally{ - if (tx.isActive()){ - tx.rollback(); - } JDOUtil.closePM(pm); } --- 313,316 ---- *************** *** 464,485 **** this.logger.info("movePosition()"); PersistenceManager pm = null; - Transaction tx = null; try{ pm = JDOUtil.pmfactory.getPersistenceManager(); - tx = pm.currentTransaction(); - tx.begin(); checkSession(sessionId, pm); ! Position pos = checkPosition(positionId, pm); ! Map map = pos.getMap(); ! if (newPositionX < 0 || newPositionY < 0 || newPositionX > (map.getImageWidth().intValue() - 1) ! || newPositionY > (map.getImageHeight().intValue() - 1)){ ! pm.currentTransaction().rollback(); ! throw new MapException("Position ist nicht auf der Karte"); ! } ! pos.setPosX(newPositionX); ! pos.setPosY(newPositionY); ! pos.setFixed(fixed); ! tx.commit(); ! } catch (Exception e){ e.printStackTrace(); if (e instanceof MapException){ --- 326,336 ---- this.logger.info("movePosition()"); PersistenceManager pm = null; try{ pm = JDOUtil.pmfactory.getPersistenceManager(); checkSession(sessionId, pm); ! Map map = checkMap(mapname, newPositionX, newPositionY, pm); ! PositionCache.getPositionCache().movePosition(map, positionId, newPositionX, newPositionY, fixed); ! } ! catch (Exception e){ e.printStackTrace(); if (e instanceof MapException){ *************** *** 490,496 **** } } finally{ - if (tx.isActive()){ - tx.rollback(); - } JDOUtil.closePM(pm); } --- 341,344 ---- *************** *** 505,517 **** this.logger.info("deletePosition()"); PersistenceManager pm = null; - Transaction tx = null; try{ pm = JDOUtil.pmfactory.getPersistenceManager(); - tx = pm.currentTransaction(); - tx.begin(); checkSession(sessionId, pm); ! Position pos = checkPosition(positionId, pm); ! pos.setDeleted(true); ! tx.commit(); } catch (Exception e){ e.printStackTrace(); --- 353,361 ---- this.logger.info("deletePosition()"); PersistenceManager pm = null; try{ pm = JDOUtil.pmfactory.getPersistenceManager(); checkSession(sessionId, pm); ! Map map = checkMap(mapname, pm); ! PositionCache.getPositionCache().deletePosition(map,positionId); } catch (Exception e){ e.printStackTrace(); *************** *** 523,529 **** } } finally{ - if (tx.isActive()){ - tx.rollback(); - } JDOUtil.closePM(pm); } --- 367,370 ---- *************** *** 539,626 **** SessionException{ this.logger.info("getPositionsForMapSince() " + timeStamp); PersistenceManager pm = null; - Transaction tx = null; - ArrayList result = new ArrayList(); try{ pm = JDOUtil.pmfactory.getPersistenceManager(); - tx = pm.currentTransaction(); - tx.begin(); checkSession(sessionId, pm); Map map = checkMap(mapName, pm); ! Extent e = pm.getExtent(Position.class, true); ! String filter = "map == myMap && lastModified > myLastModified"; ! if (timeStamp == -1){ ! filter += " && deleted == 0"; ! } ! Query query = pm.newQuery(e, filter); ! query.declareParameters("net.sf.magicmap.db.Map myMap, java.lang.Long myLastModified"); ! query.declareImports("import net.sf.magicmap.db.Map; import java.lang.Long;"); ! Collection results = null; ! results = (Collection) query.execute(map, new Long(timeStamp)); ! if (results != null){ ! Iterator it = results.iterator(); ! while (it.hasNext()){ ! Position pos = (Position) it.next(); ! // bei Timestamp -1 nur nicht gelöschte Positionen zurückliefern ! PositionDTO dto = new PositionDTO(); ! AccessPoint ap = pos.getAccessPoint(); ! if (ap != null){ ! AccessPointDTO apDTO = new AccessPointDTO(); ! apDTO.setMac(ap.getMac()); ! apDTO.setId(new Long(ap.getId())); ! apDTO.setSsid(ap.getSsid()); ! dto.setAccessPoint(apDTO); ! } ! Client client = pos.getClient(); ! if (client != null){ ! ClientDTO clientDTO = new ClientDTO(); ! clientDTO.setMac(client.getMac()); ! clientDTO.setId(new Long(client.getId())); ! clientDTO.setName(client.getName()); ! dto.setClient(clientDTO); ! } ! dto.setId(new Long(pos.getId())); ! dto.setDeleted(pos.isDeleted()); ! dto.setLastModified(new Long(pos.getLastModified())); ! dto.setPosX(new Integer(pos.getPosX())); ! dto.setPosY(new Integer(pos.getPosY())); ! dto.setFixed(pos.isFixed()); ! dto.setName(pos.getName()); ! dto.setCharacter(new SignalCharacterDTO()); ! // Scanresults holen ! Collection scanResults = pos.getScanResults(); ! if (scanResults != null){ ! Iterator scanIt = scanResults.iterator(); ! while (scanIt.hasNext()){ ! ScanResult sr = (ScanResult) scanIt.next(); ! ! Date lastSeen = null; ! if (sr.getScantime() != null){ ! lastSeen = new Date(sr.getScantime().getTime()); ! } ! ! SimpleScanResultDTO ssr = new SimpleScanResultDTO(); ! ! //ssr.setLastSeen(lastSeen); //TODO: last seen benutzen ! ssr.setMacAP(sr.getAccessPoint().getMac()); ! ssr.setNoise(sr.getNoiseLevel()); ! ssr.setSignalLevel(sr.getSignalLevel()); ! ssr.setSsid(sr.getAccessPoint().getSsid()); ! ! ArrayList list; ! if (dto.getCharacter().getSimpleScanResults() == null){ ! list = new ArrayList(); ! } else{ ! list = new ArrayList(Arrays.asList(dto.getCharacter().getSimpleScanResults())); ! } ! ! list.add(ssr); ! dto.getCharacter().setSimpleScanResults((SimpleScanResultDTO[]) list.toArray(new SimpleScanResultDTO[0])); ! } ! } ! result.add(dto); ! } ! } ! tx.commit(); } catch (Exception e){ e.printStackTrace(); --- 380,390 ---- SessionException{ this.logger.info("getPositionsForMapSince() " + timeStamp); + PositionDTO [] result = null; PersistenceManager pm = null; try{ pm = JDOUtil.pmfactory.getPersistenceManager(); checkSession(sessionId, pm); Map map = checkMap(mapName, pm); ! result = PositionCache.getPositionCache().getPositionsForMapSince(map,timeStamp); } catch (Exception e){ e.printStackTrace(); *************** *** 632,642 **** } } finally{ - if (tx.isActive()){ - tx.rollback(); - } JDOUtil.closePM(pm); } this.logger.info("getPositionsForMapSince() - done "); ! return (PositionDTO[]) result.toArray(new PositionDTO[0]); } --- 396,403 ---- } } finally{ JDOUtil.closePM(pm); } this.logger.info("getPositionsForMapSince() - done "); ! return result; } *************** *** 650,676 **** PersistenceManager pm = null; String positionResult = null; - Transaction tx = null; try{ pm = JDOUtil.pmfactory.getPersistenceManager(); - tx = pm.currentTransaction(); - tx.begin(); checkSession(sessionId, pm); Map map = checkMap(mapName, pm); checkClient(clientMac, pm); ! Extent e = pm.getExtent(Position.class, true); ! String filter = "map == myMap && name == myName"; ! Query query = pm.newQuery(e, filter); ! query.declareParameters("net.sf.magicmap.db.Map myMap, java.lang.String myName"); ! query.declareImports("import net.sf.magicmap.db.Map; import java.lang.String;"); ! Collection results = null; ! results = (Collection) query.execute(map, clientMac); ! if (results != null){ ! Iterator it = results.iterator(); ! if(it.hasNext()){ ! Position pos = (Position) it.next(); ! positionResult = String.valueOf(pos.getPosX())+ "#" + String.valueOf(pos.getPosY()) + "#" + String.valueOf(pos.isFixed()); ! } ! } ! tx.commit(); } catch (Exception e){ e.printStackTrace(); --- 411,421 ---- PersistenceManager pm = null; String positionResult = null; try{ pm = JDOUtil.pmfactory.getPersistenceManager(); checkSession(sessionId, pm); Map map = checkMap(mapName, pm); checkClient(clientMac, pm); ! PositionDTO pos = PositionCache.getPositionCache().getPositionForClientOnMap(map,clientMac); ! positionResult = String.valueOf(pos.getPosX())+ "#" + String.valueOf(pos.getPosY()) + "#" + String.valueOf(pos.isFixed()); } catch (Exception e){ e.printStackTrace(); *************** *** 682,688 **** } } finally{ - if (tx.isActive()){ - tx.rollback(); - } JDOUtil.closePM(pm); } --- 427,430 ---- |