Package org.traccar.web.shared.model

Examples of org.traccar.web.shared.model.User


    }

    @Override
    public List<Device> getDevices() {
        List<Device> devices = new LinkedList<Device>();
        User user = getSessionUser();
        devices.addAll(user.getDevices());
        return devices;
    }
View Full Code Here


        synchronized (entityManager) {        
            TypedQuery<Device> query = entityManager.createQuery("SELECT x FROM Device x WHERE x.uniqueId = :id", Device.class);
            query.setParameter("id", device.getUniqueId());
            List<Device> results = query.getResultList();
           
            User user = getSessionUser();

            if (results.isEmpty()) {
                entityManager.getTransaction().begin();
                try {
                    entityManager.persist(device);
                    user.getDevices().add(device);
                    entityManager.getTransaction().commit();
                    return device;               
                } catch (RuntimeException e) {
                    entityManager.getTransaction().rollback();
                    throw e;
View Full Code Here

    @Override
    public Device removeDevice(Device device) {
        EntityManager entityManager = getSessionEntityManager();
        synchronized (entityManager) {
            User user = getSessionUser();
            entityManager.getTransaction().begin();
            try {
                device = entityManager.merge(device);
                user.getDevices().remove(device);
                device.setLatestPosition(null);
                entityManager.flush();
                Query query = entityManager.createQuery("DELETE FROM Position x WHERE x.device = :device");
                query.setParameter("device", device);
                query.executeUpdate();
View Full Code Here

    @Override
    public List<Position> getLatestPositions() {
        EntityManager entityManager = getSessionEntityManager();
        synchronized (entityManager) {
            List<Position> positions = new LinkedList<Position>();
            User user = getSessionUser();
            if (user.getDevices() != null && !user.getDevices().isEmpty()) {
                TypedQuery<Position> query = entityManager.createQuery(
                        "SELECT x FROM Position x WHERE x.id IN (" +
                                "SELECT y.latestPosition FROM Device y WHERE y IN (:devices))", Position.class);
                query.setParameter("devices", user.getDevices());
                positions.addAll(query.getResultList());
            }
            return positions;
        }
    }
View Full Code Here

TOP

Related Classes of org.traccar.web.shared.model.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.