Example usage for org.hibernate Session doWork

List of usage examples for org.hibernate Session doWork

Introduction

In this page you can find the example usage for org.hibernate Session doWork.

Prototype

void doWork(Work work) throws HibernateException;

Source Link

Document

Controller for allowing users to perform JDBC related work using the Connection managed by this Session.

Usage

From source file:com.tremolosecurity.provisioning.service.GenerateReport.java

License:Apache License

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {

    final Gson gson = new Gson();

    try {// w w w.j  a  v a 2s.  co  m

        String name = req.getParameter("name");
        ReportType reportToRunTmp = null;
        boolean foundReport = false;
        for (ReportType report : GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning()
                .getReports().getReport()) {
            if (report.getName().equalsIgnoreCase(name)) {
                reportToRunTmp = report;
                foundReport = true;
                break;
            }
        }

        if (!foundReport) {
            reportToRunTmp = null;
        }

        final ReportType reportToRun = reportToRunTmp;

        if (reportToRun == null) {
            throw new ProvisioningException("Could not find report");
        } else {
            Connection db = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            try {
                Session session = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine()
                        .getHibernateSessionFactory().openSession();
                session.doWork(new Work() {
                    public void execute(Connection connection) throws SQLException {
                        try {
                            generateReportData(req, resp, gson, reportToRun, connection);
                        } catch (IOException e) {
                            throw new SQLException("Could not run reports", e);
                        }
                    }
                });

            } finally {

            }
        }
    } catch (Exception e) {
        logger.error("Could not run report", e);
        resp.setStatus(500);
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Could not run report;" + e.getMessage());
        ProvisioningResult resObj = new ProvisioningResult();
        resObj.setSuccess(false);
        resObj.setError(pe);

        resp.getOutputStream().print(gson.toJson(resObj));
    }
}

From source file:com.tremolosecurity.scalejs.ws.ScaleMain.java

License:Apache License

private void runReport(final HttpFilterRequest request, final HttpFilterResponse response, final Gson gson)
        throws UnsupportedEncodingException, IOException, MalformedURLException, ProvisioningException,
        SQLException {/*from   www .ja v a  2s. co  m*/
    String name = URLDecoder
            .decode(request.getRequestURI().substring(request.getRequestURI().lastIndexOf('/') + 1), "UTF-8");
    ReportType reportToRun = null;

    for (ReportType report : GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning()
            .getReports().getReport()) {
        if (report.getName().equalsIgnoreCase(name)) {
            reportToRun = report;
            break;
        }
    }

    if (reportToRun == null) {
        response.setStatus(404);
        ScaleError error = new ScaleError();
        error.getErrors().add("Report not found");
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().print(gson.toJson(error).trim());
        response.getWriter().flush();
    } else {
        HashSet<String> allowedOrgs = new HashSet<String>();
        final AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL))
                .getAuthInfo();
        OrgType ot = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getOrg();
        AzSys az = new AzSys();
        this.checkOrg(allowedOrgs, ot, az, userData, request.getSession());

        if (allowedOrgs.contains(reportToRun.getOrgID())) {
            Connection db = null;

            final ReportType reportToRunUse = reportToRun;

            try {
                Session session = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine()
                        .getHibernateSessionFactory().openSession();
                session.doWork(new Work() {
                    public void execute(Connection connection) throws SQLException {
                        try {
                            generateReport(request, response, gson, reportToRunUse, userData, connection);
                        } catch (IOException e) {
                            throw new SQLException("Could not run reports", e);
                        }
                    }
                });

            } finally {

            }

        } else {
            response.setStatus(401);
            ScaleError error = new ScaleError();
            error.getErrors().add("Unauthorized");
            ScaleJSUtils.addCacheHeaders(response);
            response.getWriter().print(gson.toJson(error).trim());
            response.getWriter().flush();
        }
    }
}

From source file:com.vladmihalcea.service.impl.StoreServiceImpl.java

License:Apache License

@Override
@Transactional(isolation = Isolation.SERIALIZABLE)
public void purchase(Long productId) {
    Product product = entityManager.find(Product.class, 1L);
    Session session = (Session) entityManager.getDelegate();
    session.doWork(new Work() {
        @Override/*w  w  w.j  a  va  2s  .  c o m*/
        public void execute(Connection connection) throws SQLException {
            LOGGER.debug("Transaction isolation level is {}",
                    Environment.isolationLevelToString(connection.getTransactionIsolation()));
        }
    });
    product.setQuantity(product.getQuantity() - 1);
}

From source file:com.xgestion2.vistas.informes.FormFechasFiltro.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    if (!textFecha.getText().isEmpty() && !textFecha1.getText().isEmpty()) {
        // TODO add your handling code here:
        String filePath = new File("src/Horas por Legajos.jasper").getAbsolutePath();

        Session session = FormPrincipal.sessionFactory.openSession();
        session.doWork(new Work() {
            public void execute(Connection connection) throws SQLException {

                //PARAMETROS
                Map<String, Object> parameters;
                parameters = new HashMap<String, Object>();
                parameters.put("fecha1", convertToDate(textFecha.getText()));
                parameters.put("fecha2", convertToDate(textFecha1.getText()));

                AbastractJasperReports.createReport(connection, filePath, parameters);
                AbastractJasperReports.showViewer();
            }/*  w  ww.j a v a2s .c o  m*/
        });
    }
}

From source file:com.xpn.xwiki.internal.store.hibernate.HibernateStore.java

License:Open Source License

/**
 * Execute an SQL statement using Hibernate.
 *
 * @param sql the SQL statement to execute
 * @param session the Hibernate Session in which to execute the statement
 *//* www  .  j a v a  2s  .  co  m*/
private void executeSQL(final String sql, Session session) {
    session.doWork(new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {
            Statement stmt = null;
            try {
                stmt = connection.createStatement();
                stmt.execute(sql);
            } finally {
                try {
                    if (stmt != null) {
                        stmt.close();
                    }
                } catch (Exception e) {
                }
            }
        }
    });
}

From source file:com.xpn.xwiki.store.migration.hibernate.R35100XWIKI7564DataMigration.java

License:Open Source License

@Override
public void hibernateMigrate() throws DataMigrationException, XWikiException {
    getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() {
        @Override// www.  ja  va 2 s  .c o  m
        public Object doInHibernate(Session session) throws HibernateException, XWikiException {
            session.doWork(new R35100Work());
            return Boolean.TRUE;
        }
    });
}

From source file:com.xpn.xwiki.store.migration.hibernate.R35101XWIKI7645DataMigration.java

License:Open Source License

@Override
public void hibernateMigrate() throws DataMigrationException, XWikiException {
    getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() {
        @Override/* w w  w.j  a va2  s .  c  om*/
        public Object doInHibernate(Session session) throws HibernateException, XWikiException {
            session.doWork(new R35101Work());
            return Boolean.TRUE;
        }
    });
}

From source file:com.xpn.xwiki.store.migration.hibernate.R35102XWIKI7771DataMigration.java

License:Open Source License

@Override
public void hibernateMigrate() throws DataMigrationException, XWikiException {
    getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() {
        @Override//from  www.ja  va 2  s. c o  m
        public Object doInHibernate(Session session) throws HibernateException, XWikiException {
            session.doWork(
                    new R35102Work("xwikircs", "xwr_patch", "xwr_docid", "History for document with ID"));
            session.doWork(new R35102Work("xwikirecyclebin", "xdd_xml", "xdd_id", "Deleted document with ID"));
            session.doWork(
                    new R35102Work("xwikiattrecyclebin", "xda_xml", "xda_id", "Deleted attachment with ID"));
            return Boolean.TRUE;
        }
    });
}

From source file:com.xpn.xwiki.store.migration.hibernate.R42000XWIKI7726DataMigration.java

License:Open Source License

@Override
public void hibernateMigrate() throws DataMigrationException, XWikiException {
    getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() {
        @Override/* w w  w.jav a2 s  .  c  o m*/
        public Object doInHibernate(Session session) throws HibernateException, XWikiException {
            session.doWork(new R42000Work());
            return Boolean.TRUE;
        }
    });
}

From source file:com.xpn.xwiki.store.migration.hibernate.R50000XWIKI8948DataMigration.java

License:Open Source License

@Override
public void hibernateMigrate() throws DataMigrationException, XWikiException {
    getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>() {
        @Override/*from ww w .  ja v  a 2s.c  om*/
        public Object doInHibernate(Session session) throws HibernateException {
            session.doWork(new R50000Work());
            return Boolean.TRUE;
        }
    });
}