Example usage for javax.persistence Query executeUpdate

List of usage examples for javax.persistence Query executeUpdate

Introduction

In this page you can find the example usage for javax.persistence Query executeUpdate.

Prototype

int executeUpdate();

Source Link

Document

Execute an update or delete statement.

Usage

From source file:io.apiman.manager.api.jpa.JpaStorage.java

private void deleteAllMemberships(OrganizationBean organizationBean) throws StorageException {
    String jpql = "DELETE RoleMembershipBean b " + " WHERE b.organizationId = :orgId ";

    Query query = getActiveEntityManager().createQuery(jpql);
    query.setParameter("orgId", organizationBean.getId());
    query.executeUpdate();
}

From source file:io.apiman.manager.api.jpa.JpaStorage.java

public void deleteAllPlans(OrganizationBean organizationBean) throws StorageException {
    deleteAllPlanVersions(organizationBean);

    String jpql = "DELETE PlanBean p " + "     WHERE p.organization.id = :orgId ";

    Query query = getActiveEntityManager().createQuery(jpql);
    query.setParameter("orgId", organizationBean.getId());
    query.executeUpdate();
}

From source file:io.apiman.manager.api.jpa.JpaStorage.java

private void deleteAllPlanVersions(OrganizationBean organizationBean) throws StorageException {
    String jpql = "DELETE PlanVersionBean deleteBean " + " WHERE deleteBean IN (" + "SELECT v"
            + "  FROM PlanVersionBean v " + "  JOIN v.plan p " + "  JOIN p.organization o "
            + " WHERE o.id = :orgId " + ")";

    Query query = getActiveEntityManager().createQuery(jpql);
    query.setParameter("orgId", organizationBean.getId());
    query.executeUpdate();
}

From source file:io.apiman.manager.api.jpa.JpaStorage.java

private void deleteAllAuditEntries(OrganizationBean organizationBean, AuditEntityType entityType,
        String entityId) throws StorageException {
    String jpql = "DELETE AuditEntryBean b " + " WHERE b.organizationId = :orgId ";

    if (entityId != null && entityType != null) {
        jpql += String.format("AND b.entityId = '%s' AND b.entityType = '%s' ", entityId, entityType.name());
    }/*ww w  . j a  va2 s. c om*/

    Query query = getActiveEntityManager().createQuery(jpql);
    query.setParameter("orgId", organizationBean.getId());
    query.executeUpdate();
}

From source file:io.apiman.manager.api.jpa.JpaStorage.java

/**
 * @see io.apiman.manager.api.core.IStorage#deleteRole(io.apiman.manager.api.beans.idm.RoleBean)
 *///  ww  w.j  av a  2s.  co  m
@Override
public void deleteRole(RoleBean role) throws StorageException {
    try {
        EntityManager entityManager = getActiveEntityManager();

        RoleBean prole = get(role.getId(), RoleBean.class);

        // First delete all memberships in this role
        Query query = entityManager.createQuery("DELETE from RoleMembershipBean m WHERE m.roleId = :roleId");
        query.setParameter("roleId", role.getId());
        query.executeUpdate();

        // Then delete the role itself.
        super.delete(prole);
    } catch (Throwable t) {
        throw new StorageException(t);
    }
}

From source file:op.care.nursingprocess.PnlNursingProcess.java

private JPanel getMenu(final NursingProcess np) {

    final JPanel pnlMenu = new JPanel(new VerticalLayout());
    long numDFNs = DFNTools.getNumDFNs(np);

    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) {
        /***/*from   w w w.j  a  v a 2  s .  com*/
         *       ____ _
         *      / ___| |__   __ _ _ __   __ _  ___
         *     | |   | '_ \ / _` | '_ \ / _` |/ _ \
         *     | |___| | | | (_| | | | | (_| |  __/
         *      \____|_| |_|\__,_|_| |_|\__, |\___|
         *                              |___/
         */
        JButton btnChange = GUITools.createHyperlinkButton("nursingrecords.nursingprocess.btnchange.tooltip",
                SYSConst.icon22playerPlay, null);
        btnChange.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnChange.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                NursingProcess template = np.clone();
                template.setTo(SYSConst.DATE_UNTIL_FURTHER_NOTICE);
                template.setUserOFF(null);
                template.setUserON(OPDE.getLogin().getUser());
                template.setNextEval(new DateTime().plusWeeks(4).toDate());
                new DlgNursingProcess(template, new Closure() {
                    @Override
                    public void execute(Object o) {
                        if (o != null) {
                            EntityManager em = OPDE.createEM();
                            try {
                                em.getTransaction().begin();
                                em.lock(em.merge(resident), LockModeType.OPTIMISTIC);

                                // Fetch the new Plan from the PAIR
                                NursingProcess myNewNP = em.merge(
                                        ((Pair<NursingProcess, ArrayList<InterventionSchedule>>) o).getFirst());
                                NursingProcess myOldNP = em.merge(np);
                                em.lock(myOldNP, LockModeType.OPTIMISTIC);

                                // Close old NP
                                myOldNP.setUserOFF(em.merge(OPDE.getLogin().getUser()));
                                myOldNP.setTo(new DateTime().minusSeconds(1).toDate());
                                NPControl lastValidation = em
                                        .merge(new NPControl(myNewNP.getSituation(), myOldNP));
                                lastValidation.setLastValidation(true);
                                myOldNP.getEvaluations().add(lastValidation);

                                // Starts 1 second after the old one stopped
                                myNewNP.setFrom(new DateTime(myOldNP.getTo()).plusSeconds(1).toDate());

                                // Create new DFNs according to plan
                                DFNTools.generate(em, myNewNP.getInterventionSchedule(), new LocalDate(), true);
                                em.getTransaction().commit();

                                // Refresh Display
                                valuecache.get(np.getCategory()).remove(np);
                                contenPanelMap.remove(np);
                                valuecache.get(myOldNP.getCategory()).add(myOldNP);
                                valuecache.get(myNewNP.getCategory()).add(myNewNP);
                                Collections.sort(valuecache.get(myNewNP.getCategory()));
                                createCP4(myNewNP.getCategory());

                                boolean reloadSearch = false;
                                for (Commontags ctag : myNewNP.getCommontags()) {
                                    if (!listUsedCommontags.contains(ctag)) {
                                        listUsedCommontags.add(ctag);
                                        reloadSearch = true;
                                    }
                                }
                                if (reloadSearch) {
                                    prepareSearchArea();
                                }

                                buildPanel();
                                GUITools.flashBackground(contenPanelMap.get(myNewNP), Color.YELLOW, 2);
                            } catch (OptimisticLockException ole) {
                                OPDE.warn(ole);
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                    OPDE.getMainframe().emptyFrame();
                                    OPDE.getMainframe().afterLogin();
                                }
                                OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                            } catch (Exception e) {
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                OPDE.fatal(e);
                            } finally {
                                em.close();
                            }
                            //                                reloadTable();
                        }
                    }
                });

            }
        });
        btnChange.setEnabled(!np.isClosed() && numDFNs != 0);
        pnlMenu.add(btnChange);

        /***
         *      ____        _   _                ____  _
         *     | __ ) _   _| |_| |_ ___  _ __   / ___|| |_ ___  _ __
         *     |  _ \| | | | __| __/ _ \| '_ \  \___ \| __/ _ \| '_ \
         *     | |_) | |_| | |_| || (_) | | | |  ___) | || (_) | |_) |
         *     |____/ \__,_|\__|\__\___/|_| |_| |____/ \__\___/| .__/
         *                                                     |_|
         */

        final JButton btnStop = GUITools.createHyperlinkButton("nursingrecords.nursingprocess.btnstop.tooltip",
                SYSConst.icon22stop, null);
        btnStop.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnStop.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                final JidePopup popup = new JidePopup();

                JPanel dlg = new PnlEval(np, new Closure() {
                    @Override
                    public void execute(Object o) {
                        if (o != null) {
                            popup.hidePopup();

                            Pair<NursingProcess, String> result = (Pair<NursingProcess, String>) o;

                            EntityManager em = OPDE.createEM();
                            try {
                                em.getTransaction().begin();
                                em.lock(em.merge(resident), LockModeType.OPTIMISTIC);

                                NursingProcess myOldNP = em.merge(np);
                                em.lock(myOldNP, LockModeType.OPTIMISTIC);

                                myOldNP.setUserOFF(em.merge(OPDE.getLogin().getUser()));
                                myOldNP.setTo(new Date());
                                NPControl lastValidation = em.merge(new NPControl(result.getSecond(), myOldNP));
                                lastValidation.setLastValidation(true);
                                myOldNP.getEvaluations().add(lastValidation);

                                em.getTransaction().commit();

                                // Refresh Display
                                valuecache.get(np.getCategory()).remove(np);
                                contenPanelMap.remove(np);
                                valuecache.get(myOldNP.getCategory()).add(myOldNP);
                                Collections.sort(valuecache.get(myOldNP.getCategory()));

                                createCP4(myOldNP.getCategory());
                                buildPanel();
                                //                                    GUITools.flashBackground(contenPanelMap.get(myOldNP), Color.YELLOW, 2);

                            } catch (OptimisticLockException ole) {
                                OPDE.warn(ole);
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                    OPDE.getMainframe().emptyFrame();
                                    OPDE.getMainframe().afterLogin();
                                }
                                OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                            } catch (Exception e) {
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                OPDE.fatal(e);
                            } finally {
                                em.close();
                            }

                            OPDE.getDisplayManager()
                                    .addSubMessage(DisplayManager.getSuccessMessage(np.getTopic(), "closed"));
                            reloadDisplay();
                        }
                    }
                }, true);

                popup.setMovable(false);
                popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS));
                popup.getContentPane().add(dlg);
                popup.setOwner(btnStop);
                popup.removeExcludedComponent(btnStop);
                popup.setDefaultFocusComponent(dlg);

                GUITools.showPopup(popup, SwingConstants.WEST);
            }
        });
        btnStop.setEnabled(!np.isClosed() && numDFNs != 0);
        pnlMenu.add(btnStop);

        /***
         *      ____        _   _                _____    _ _ _
         *     | __ ) _   _| |_| |_ ___  _ __   | ____|__| (_) |_
         *     |  _ \| | | | __| __/ _ \| '_ \  |  _| / _` | | __|
         *     | |_) | |_| | |_| || (_) | | | | | |__| (_| | | |_
         *     |____/ \__,_|\__|\__\___/|_| |_| |_____\__,_|_|\__|
         *
         */

        JButton btnEdit = GUITools.createHyperlinkButton("nursingrecords.nursingprocess.btnedit.tooltip",
                SYSConst.icon22edit, null);
        btnEdit.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnEdit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                new DlgNursingProcess(np, new Closure() {
                    @Override
                    public void execute(Object o) {
                        if (o != null) {
                            EntityManager em = OPDE.createEM();
                            try {
                                em.getTransaction().begin();
                                em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                                NursingProcess mynp = em.merge(
                                        ((Pair<NursingProcess, ArrayList<InterventionSchedule>>) o).getFirst());
                                em.lock(mynp, LockModeType.OPTIMISTIC);
                                // Schedules to delete
                                for (InterventionSchedule is : ((Pair<NursingProcess, ArrayList<InterventionSchedule>>) o)
                                        .getSecond()) {
                                    em.remove(em.merge(is));
                                }
                                // No unused DFNs to delete
                                Query delQuery = em.createQuery(
                                        "DELETE FROM DFN dfn WHERE dfn.nursingProcess = :nursingprocess ");
                                delQuery.setParameter("nursingprocess", mynp);
                                delQuery.executeUpdate();
                                // Create new DFNs according to plan
                                DFNTools.generate(em, mynp.getInterventionSchedule(), new LocalDate(), true);
                                em.getTransaction().commit();

                                boolean reloadSearch = false;
                                for (Commontags ctag : mynp.getCommontags()) {
                                    if (!listUsedCommontags.contains(ctag)) {
                                        listUsedCommontags.add(ctag);
                                        reloadSearch = true;
                                    }
                                }
                                if (reloadSearch) {
                                    prepareSearchArea();
                                }

                                // Refresh Display
                                valuecache.get(np.getCategory()).remove(np);
                                contenPanelMap.remove(np);
                                valuecache.get(mynp.getCategory()).add(mynp);
                                Collections.sort(valuecache.get(mynp.getCategory()));

                                createCP4(mynp.getCategory());
                                buildPanel();
                                GUITools.flashBackground(contenPanelMap.get(mynp), Color.YELLOW, 2);

                            } catch (OptimisticLockException ole) {
                                OPDE.warn(ole);
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                    OPDE.getMainframe().emptyFrame();
                                    OPDE.getMainframe().afterLogin();
                                }
                                OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                            } catch (Exception e) {
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                OPDE.fatal(e);
                            } finally {
                                em.close();
                            }
                            //                                reloadTable();
                        }
                    }
                });
            }
        });
        btnEdit.setEnabled(!np.isClosed() && numDFNs == 0);
        pnlMenu.add(btnEdit);
    }

    /***
     *      ____        _   _                ____       _      _
     *     | __ ) _   _| |_| |_ ___  _ __   |  _ \  ___| | ___| |_ ___
     *     |  _ \| | | | __| __/ _ \| '_ \  | | | |/ _ \ |/ _ \ __/ _ \
     *     | |_) | |_| | |_| || (_) | | | | | |_| |  __/ |  __/ ||  __/
     *     |____/ \__,_|\__|\__\___/|_| |_| |____/ \___|_|\___|\__\___|
     *
     */
    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) { // => ACL_MATRIX
        JButton btnDelete = GUITools.createHyperlinkButton("nursingrecords.nursingprocess.btndelete.tooltip",
                SYSConst.icon22delete, null);
        btnDelete.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnDelete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                new DlgYesNo(SYSTools.xx("misc.questions.delete1") + "<br/><b>" + np.getTopic() + "</b><br/>"
                        + SYSTools.xx("misc.questions.delete2"), SYSConst.icon48delete, new Closure() {
                            @Override
                            public void execute(Object o) {
                                if (o.equals(JOptionPane.YES_OPTION)) {
                                    EntityManager em = OPDE.createEM();
                                    try {
                                        em.getTransaction().begin();
                                        em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                                        NursingProcess myOldNP = em.merge(np);
                                        em.lock(myOldNP, LockModeType.OPTIMISTIC);

                                        // DFNs to delete
                                        Query delQuery = em.createQuery(
                                                "DELETE FROM DFN dfn WHERE dfn.nursingProcess = :nursingprocess ");
                                        delQuery.setParameter("nursingprocess", myOldNP);
                                        //                                    delQuery.setParameter("status", DFNTools.STATE_OPEN);
                                        delQuery.executeUpdate();

                                        em.remove(myOldNP);
                                        em.getTransaction().commit();

                                        // Refresh Display
                                        valuecache.get(np.getCategory()).remove(np);
                                        contenPanelMap.remove(np);

                                        createCP4(myOldNP.getCategory());
                                        buildPanel();

                                        OPDE.getDisplayManager().addSubMessage(
                                                DisplayManager.getSuccessMessage(np.getTopic(), "deleted"));

                                    } catch (OptimisticLockException ole) {
                                        OPDE.warn(ole);
                                        if (em.getTransaction().isActive()) {
                                            em.getTransaction().rollback();
                                        }
                                        if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                            OPDE.getMainframe().emptyFrame();
                                            OPDE.getMainframe().afterLogin();
                                        }
                                        OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                                    } catch (Exception e) {
                                        if (em.getTransaction().isActive()) {
                                            em.getTransaction().rollback();
                                        }
                                        OPDE.fatal(e);
                                    } finally {
                                        em.close();
                                    }
                                }
                            }
                        });
            }
        });
        btnDelete.setEnabled(!np.isClosed() && numDFNs == 0);
        pnlMenu.add(btnDelete);
    }

    /***
     *      ____  _         _____            _
     *     | __ )| |_ _ __ | ____|_   ____ _| |
     *     |  _ \| __| '_ \|  _| \ \ / / _` | |
     *     | |_) | |_| | | | |___ \ V / (_| | |
     *     |____/ \__|_| |_|_____| \_/ \__,_|_|
     *
     */
    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) {
        final JButton btnEval = GUITools.createHyperlinkButton("nursingrecords.nursingprocess.btneval.tooltip",
                SYSConst.icon22redo, null);
        btnEval.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnEval.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                final JidePopup popup = new JidePopup();

                JPanel dlg = new PnlEval(np, new Closure() {
                    @Override
                    public void execute(Object o) {
                        if (o != null) {
                            popup.hidePopup();

                            Pair<NursingProcess, String> result = (Pair<NursingProcess, String>) o;

                            EntityManager em = OPDE.createEM();
                            try {
                                em.getTransaction().begin();
                                em.lock(em.merge(resident), LockModeType.OPTIMISTIC);

                                NursingProcess evaluatedNP = em.merge(result.getFirst());
                                em.lock(evaluatedNP, LockModeType.OPTIMISTIC);

                                NPControl newEvaluation = em
                                        .merge(new NPControl(result.getSecond(), evaluatedNP));
                                evaluatedNP.getEvaluations().add(newEvaluation);

                                em.getTransaction().commit();

                                // Refresh Display
                                valuecache.get(np.getCategory()).remove(np);
                                contenPanelMap.remove(np);
                                valuecache.get(evaluatedNP.getCategory()).add(evaluatedNP);
                                Collections.sort(valuecache.get(evaluatedNP.getCategory()));

                                createCP4(evaluatedNP.getCategory());
                                buildPanel();
                                GUITools.flashBackground(contenPanelMap.get(evaluatedNP), Color.YELLOW, 2);

                            } catch (OptimisticLockException ole) {
                                OPDE.warn(ole);
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                    OPDE.getMainframe().emptyFrame();
                                    OPDE.getMainframe().afterLogin();
                                }
                                OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                            } catch (Exception e) {
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                OPDE.fatal(e);
                            } finally {
                                em.close();
                            }

                            OPDE.getDisplayManager().addSubMessage(new DisplayMessage(
                                    SYSTools.xx("nursingrecords.nursingprocess.success.neweval")));
                            reloadDisplay();
                        }
                    }
                }, false);

                popup.setMovable(false);
                popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS));
                popup.getContentPane().add(dlg);
                popup.setOwner(btnEval);
                popup.removeExcludedComponent(btnEval);
                popup.setDefaultFocusComponent(dlg);

                GUITools.showPopup(popup, SwingConstants.NORTH_WEST);
            }
        });

        btnEval.setEnabled(!np.isClosed());
        pnlMenu.add(btnEval);

        /***
         *      _     _       _____  _    ____
         *     | |__ | |_ _ _|_   _|/ \  / ___|___
         *     | '_ \| __| '_ \| | / _ \| |  _/ __|
         *     | |_) | |_| | | | |/ ___ \ |_| \__ \
         *     |_.__/ \__|_| |_|_/_/   \_\____|___/
         *
         */
        final JButton btnTAGs = GUITools.createHyperlinkButton("misc.msg.editTags", SYSConst.icon22tagPurple,
                null);
        btnTAGs.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnTAGs.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                final JidePopup popup = new JidePopup();

                final JPanel pnl = new JPanel(new BorderLayout(5, 5));
                final PnlCommonTags pnlCommonTags = new PnlCommonTags(np.getCommontags(), true, 3);
                pnl.add(new JScrollPane(pnlCommonTags), BorderLayout.CENTER);
                JButton btnApply = new JButton(SYSConst.icon22apply);
                pnl.add(btnApply, BorderLayout.SOUTH);
                btnApply.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        EntityManager em = OPDE.createEM();
                        try {

                            em.getTransaction().begin();
                            em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                            NursingProcess myNP = em.merge(np);
                            em.lock(myNP, LockModeType.OPTIMISTIC_FORCE_INCREMENT);

                            myNP.getCommontags().clear();
                            for (Commontags commontag : pnlCommonTags.getListSelectedTags()) {
                                myNP.getCommontags().add(em.merge(commontag));
                            }

                            em.getTransaction().commit();

                            // Refresh Display
                            valuecache.get(np.getCategory()).remove(np);
                            contenPanelMap.remove(np);
                            valuecache.get(myNP.getCategory()).add(myNP);
                            Collections.sort(valuecache.get(myNP.getCategory()));

                            boolean reloadSearch = false;
                            for (Commontags ctag : myNP.getCommontags()) {
                                if (!listUsedCommontags.contains(ctag)) {
                                    listUsedCommontags.add(ctag);
                                    reloadSearch = true;
                                }
                            }
                            if (reloadSearch) {
                                prepareSearchArea();
                            }

                            createCP4(myNP.getCategory());
                            buildPanel();
                            GUITools.flashBackground(contenPanelMap.get(myNP), Color.YELLOW, 2);

                        } catch (OptimisticLockException ole) {
                            OPDE.warn(ole);
                            OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                            if (em.getTransaction().isActive()) {
                                em.getTransaction().rollback();
                            }
                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                OPDE.getMainframe().emptyFrame();
                                OPDE.getMainframe().afterLogin();
                            } else {
                                reloadDisplay();
                            }
                        } catch (Exception e) {
                            if (em.getTransaction().isActive()) {
                                em.getTransaction().rollback();
                            }
                            OPDE.fatal(e);
                        } finally {
                            em.close();
                        }
                    }
                });

                popup.setMovable(false);
                popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS));
                popup.setOwner(btnTAGs);
                popup.removeExcludedComponent(btnTAGs);
                pnl.setPreferredSize(new Dimension(350, 150));
                popup.getContentPane().add(pnl);
                popup.setDefaultFocusComponent(pnl);

                GUITools.showPopup(popup, SwingConstants.WEST);

            }
        });
        btnTAGs.setEnabled(!np.isClosed());
        pnlMenu.add(btnTAGs);

        pnlMenu.add(new JSeparator());

        /***
         *      _     _         _____ _ _
         *     | |__ | |_ _ __ |  ___(_) | ___  ___
         *     | '_ \| __| '_ \| |_  | | |/ _ \/ __|
         *     | |_) | |_| | | |  _| | | |  __/\__ \
         *     |_.__/ \__|_| |_|_|   |_|_|\___||___/
         *
         */
        final JButton btnFiles = GUITools.createHyperlinkButton("misc.btnfiles.tooltip", SYSConst.icon22attach,
                null);
        btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnFiles.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                Closure fileHandleClosure = np.isClosed() ? null : new Closure() {
                    @Override
                    public void execute(Object o) {
                        EntityManager em = OPDE.createEM();
                        final NursingProcess myNP = em.find(NursingProcess.class, np.getID());
                        em.close();
                        // Refresh Display
                        valuecache.get(np.getCategory()).remove(np);
                        contenPanelMap.remove(np);
                        valuecache.get(myNP.getCategory()).add(myNP);
                        Collections.sort(valuecache.get(myNP.getCategory()));

                        createCP4(myNP.getCategory());
                        buildPanel();
                    }
                };
                new DlgFiles(np, fileHandleClosure);
            }
        });
        btnFiles.setEnabled(OPDE.isFTPworking());
        pnlMenu.add(btnFiles);

        /***
         *      _     _         ____
         *     | |__ | |_ _ __ |  _ \ _ __ ___   ___ ___  ___ ___
         *     | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __|
         *     | |_) | |_| | | |  __/| | | (_) | (_|  __/\__ \__ \
         *     |_.__/ \__|_| |_|_|   |_|  \___/ \___\___||___/___/
         *
         */
        final JButton btnProcess = GUITools.createHyperlinkButton("misc.btnprocess.tooltip",
                SYSConst.icon22link, null);
        btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnProcess.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                new DlgProcessAssign(np, new Closure() {
                    @Override
                    public void execute(Object o) {
                        if (o == null) {
                            return;
                        }
                        Pair<ArrayList<QProcess>, ArrayList<QProcess>> result = (Pair<ArrayList<QProcess>, ArrayList<QProcess>>) o;

                        ArrayList<QProcess> assigned = result.getFirst();
                        ArrayList<QProcess> unassigned = result.getSecond();

                        EntityManager em = OPDE.createEM();

                        try {
                            em.getTransaction().begin();

                            em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                            final NursingProcess myNP = em.merge(np);
                            em.lock(myNP, LockModeType.OPTIMISTIC_FORCE_INCREMENT);

                            ArrayList<SYSNP2PROCESS> attached = new ArrayList<SYSNP2PROCESS>(
                                    myNP.getAttachedQProcessConnections());
                            for (SYSNP2PROCESS linkObject : attached) {
                                if (unassigned.contains(linkObject.getQProcess())) {
                                    linkObject.getQProcess().getAttachedNReportConnections().remove(linkObject);
                                    linkObject.getNursingProcess().getAttachedQProcessConnections()
                                            .remove(linkObject);
                                    em.merge(new PReport(
                                            SYSTools.xx(PReportTools.PREPORT_TEXT_REMOVE_ELEMENT) + ": "
                                                    + myNP.getTitle() + " ID: " + myNP.getID(),
                                            PReportTools.PREPORT_TYPE_REMOVE_ELEMENT,
                                            linkObject.getQProcess()));
                                    em.remove(linkObject);
                                }
                            }
                            attached.clear();

                            for (QProcess qProcess : assigned) {
                                java.util.List<QProcessElement> listElements = qProcess.getElements();
                                if (!listElements.contains(myNP)) {
                                    QProcess myQProcess = em.merge(qProcess);
                                    SYSNP2PROCESS myLinkObject = em.merge(new SYSNP2PROCESS(myQProcess, myNP));
                                    em.merge(new PReport(
                                            SYSTools.xx(PReportTools.PREPORT_TEXT_ASSIGN_ELEMENT) + ": "
                                                    + myNP.getTitle() + " ID: " + myNP.getID(),
                                            PReportTools.PREPORT_TYPE_ASSIGN_ELEMENT, myQProcess));
                                    qProcess.getAttachedNursingProcessesConnections().add(myLinkObject);
                                    myNP.getAttachedQProcessConnections().add(myLinkObject);
                                }
                            }

                            em.getTransaction().commit();

                            // Refresh Display
                            valuecache.get(np.getCategory()).remove(np);
                            contenPanelMap.remove(np);
                            valuecache.get(myNP.getCategory()).add(myNP);
                            Collections.sort(valuecache.get(myNP.getCategory()));

                            createCP4(myNP.getCategory());
                            buildPanel();

                        } catch (OptimisticLockException ole) {
                            OPDE.warn(ole);
                            if (em.getTransaction().isActive()) {
                                em.getTransaction().rollback();
                            }
                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                OPDE.getMainframe().emptyFrame();
                                OPDE.getMainframe().afterLogin();
                            } else {
                                reloadDisplay();
                            }
                        } catch (RollbackException ole) {
                            if (em.getTransaction().isActive()) {
                                em.getTransaction().rollback();
                            }
                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                OPDE.getMainframe().emptyFrame();
                                OPDE.getMainframe().afterLogin();
                            }
                            OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                        } catch (Exception e) {
                            if (em.getTransaction().isActive()) {
                                em.getTransaction().rollback();
                            }
                            OPDE.fatal(e);
                        } finally {
                            em.close();
                        }

                    }
                });
            }
        });
        btnProcess.setEnabled(!np.isClosed());
        pnlMenu.add(btnProcess);

    }
    return pnlMenu;
}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String newCarrito(String productid, String sesion, String productname, String cantidad, String precio,
        String preciomay) {//from w  w w. java 2  s  . c o  m
    Message m = new Message();
    listCarrito = null;
    Query q = null;
    Carrito p = new Carrito();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();

    q = entity.createNamedQuery("Carrito.findBySesion").setParameter("idcarrito", sesion)
            .setParameter("productid", Integer.parseInt(productid));
    //Query q = entity.createNativeQuery("SELECT c FROM Carrito c WHERE idcarrito =" + Integer.parseInt(sesion) + " and c.productid=" + Integer.parseInt(productid));
    listCarrito = q.getResultList();
    if (listCarrito.size() == 0) {
        p.setIdcarrito(sesion);
        p.setProdname(productname);
        p.setCantidad(Integer.parseInt(cantidad));
        p.setProductid(Integer.parseInt(productid));
        p.setSalepricemay(Double.parseDouble(preciomay));
        p.setSalepricemin(Double.parseDouble(precio));

        entity.persist(p);
        entity.flush();

        m.setCode(200);
        m.setMsg("Todo bien compa");
        m.setDetail("OK, El id es:" + p.getProductid().toString());

    } else {
        int can = listCarrito.get(0).getCantidad();
        can++;
        q = entity.createNamedQuery("Carrito.EditarCarritoCantidad").setParameter("cantidad", can)
                .setParameter("idcarrito", sesion).setParameter("productid", Integer.parseInt(productid));
        q.executeUpdate();
        entity.clear();

        m.setCode(200);
        m.setMsg("Todo bien compa");
        m.setDetail("Se actualizo correctamente");

    }
    return gson.toJson(m);
}

From source file:io.apiman.manager.api.jpa.JpaStorage.java

/**
 * @see io.apiman.manager.api.core.IStorage#deleteMemberships(java.lang.String, java.lang.String)
 *///from  w  w w .  j  a  va  2  s  .  c  o  m
@Override
public void deleteMemberships(String userId, String organizationId) throws StorageException {
    try {
        EntityManager entityManager = getActiveEntityManager();
        Query query = entityManager.createQuery(
                "DELETE FROM RoleMembershipBean m WHERE m.userId = :userId AND m.organizationId = :orgId");
        query.setParameter("userId", userId);
        query.setParameter("orgId", organizationId);
        query.executeUpdate();
    } catch (Throwable t) {
        throw new StorageException(t);
    }
}

From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java

@Override
@Transactional/*w  w  w. ja v  a 2 s.co m*/
public boolean updateProfile(ProfileEntity profile) {
    Query query = entityManager.createNativeQuery(
            "update profile set last_modified=now(), credit_name=:credit_name, family_name=:family_name, given_names=:given_names, biography=:biography, iso2_country=:iso2_country, biography_visibility=:biography_visibility, keywords_visibility=:keywords_visibility, researcher_urls_visibility=:researcher_urls_visibility, other_names_visibility=:other_names_visibility, names_visibility=:credit_name_visibility, profile_address_visibility=:profile_address_visibility, indexing_status='PENDING' where orcid=:orcid");
    query.setParameter("credit_name", profile.getCreditName());
    query.setParameter("family_name", profile.getFamilyName());
    query.setParameter("given_names", profile.getGivenNames());
    query.setParameter("biography", profile.getBiography());
    Iso3166Country iso2Country = profile.getIso2Country();
    query.setParameter("iso2_country", iso2Country != null ? iso2Country.value() : null);
    query.setParameter("biography_visibility", StringUtils.upperCase(profile.getBiographyVisibility().value()));
    query.setParameter("keywords_visibility", StringUtils.upperCase(profile.getKeywordsVisibility().value()));
    query.setParameter("researcher_urls_visibility",
            StringUtils.upperCase(profile.getResearcherUrlsVisibility().value()));
    query.setParameter("other_names_visibility",
            StringUtils.upperCase(profile.getOtherNamesVisibility().value()));
    query.setParameter("credit_name_visibility",
            StringUtils.upperCase(profile.getCreditNameVisibility().value()));
    query.setParameter("profile_address_visibility",
            StringUtils.upperCase(profile.getProfileAddressVisibility().value()));
    query.setParameter("orcid", profile.getId());

    boolean result = query.executeUpdate() > 0 ? true : false;

    return result;
}

From source file:org.opencms.db.jpa.CmsUserDriver.java

/**
 * Deletes an additional user info.<p>
 * @param dbc the current dbc/*  ww w  .j a  v  a2  s.  com*/
 * @param userId the user to delete additional info from
 * @param key the additional info to delete 
 * @throws CmsDataAccessException if something goes wrong
 */
protected void internalDeleteUserInfo(CmsDbContext dbc, CmsUUID userId, String key)
        throws CmsDataAccessException {

    try {
        Query q = m_sqlManager.createQuery(dbc, C_USERDATA_DELETE_2);
        // write data to database
        q.setParameter(1, userId.toString());
        q.setParameter(2, key);
        q.executeUpdate();
    } catch (PersistenceException e) {
        throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE, e), e);
    }
}