Example usage for org.springframework.dao DataAccessException getMessage

List of usage examples for org.springframework.dao DataAccessException getMessage

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:pe.gob.mef.gescon.hibernate.impl.ConsultaDaoImpl.java

@Override
public List<HashMap<String, Object>> listarReporte(HashMap filters) {
    final String fCategoria = (String) filters.get("fCategoria");
    final Date fFromDate = (Date) filters.get("fFromDate");
    final Date fToDate = (Date) filters.get("fToDate");
    final String fType = (String) filters.get("fType");
    final String fCodesBL = (String) filters.get("fCodesBL");
    final String fCodesPR = (String) filters.get("fCodesPR");
    final String fCodesC = (String) filters.get("fCodesC");
    final String order = (String) filters.get("order");
    SimpleDateFormat sdf = new SimpleDateFormat(Constante.FORMAT_DATE_SHORT);
    final StringBuilder sql = new StringBuilder();
    Object object = null;/*from  w w  w .j ava 2s.  co m*/
    try {
        sql.append("SELECT x.ID, x.NOMBRE, x.SUMILLA, x.IDCATEGORIA, x.CATEGORIA, x.FECHA, ");
        sql.append(
                "       x.IDTIPOCONOCIMIENTO, x.TIPOCONOCIMIENTO, x.IDESTADO, x.ESTADO, x.SUMA, x.CONTADOR, ");
        sql.append("       DECODE(x.CONTADOR,0,0,x.SUMA/x.CONTADOR) AS PROMEDIO, x.USUARIOCREA, x.FECHACREA ");
        sql.append("FROM (SELECT ");
        sql.append("            a.nbaselegalid AS ID, a.vnumero AS NOMBRE, a.vnombre AS SUMILLA, ");
        sql.append(
                "            a.ncategoriaid AS IDCATEGORIA, b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, ");
        sql.append(
                "            1 AS IDTIPOCONOCIMIENTO, 'Base Legal' AS TIPOCONOCIMIENTO, a.nestadoid AS IDESTADO, c.vnombre AS ESTADO, ");
        sql.append(
                "            a.vusuariocreacion AS USUARIOCREA, TO_CHAR(a.dfechacreacion,'dd/MM/yyyy') AS FECHACREA, ");
        sql.append(
                "            NVL(SUM(e.ncalificacion),0) AS SUMA, NVL(COUNT(e.ncalificacion),0) AS CONTADOR ");
        sql.append("        FROM TBASELEGAL a ");
        sql.append("        INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid ");
        sql.append("        INNER JOIN MTESTADO_BASELEGAL c ON a.nestadoid = c.nestadoid ");
        sql.append("        LEFT OUTER JOIN TCALIFICACION_BASELEGAL e ON a.nbaselegalid = e.nbaselegalid ");
        sql.append("        WHERE a.nactivo = :ACTIVO ");
        sql.append("        AND c.nestadoid IN (3,4,5,6) AND b.NESTADO = 1 ");
        if (StringUtils.isNotBlank(fCategoria)) {
            sql.append("    AND a.ncategoriaid IN (").append(fCategoria).append(") ");
        }
        if (fFromDate != null) {
            sql.append("    AND TRUNC(a.dfechapublicacion) >= TO_DATE('").append(sdf.format(fFromDate))
                    .append("','dd/mm/yyyy') ");
        }
        if (fToDate != null) {
            sql.append("    AND TRUNC(a.dfechapublicacion) <= TO_DATE('").append(sdf.format(fToDate))
                    .append("','dd/mm/yyyy') ");
        }
        if (StringUtils.isNotBlank(fCodesBL)) {
            sql.append("    AND a.nbaselegalid IN (").append(fCodesBL).append(") ");
        }
        sql.append("        GROUP BY a.nbaselegalid, a.vnumero, a.vnombre, a.ncategoriaid, b.vnombre, ");
        sql.append(
                "        a.dfechapublicacion, 1, 'Base Legal', a.nestadoid, c.vnombre, a.vusuariocreacion, a.dfechacreacion ");
        sql.append("        ) x ");
        sql.append("WHERE 1 IN (").append(fType).append(") "); //BASE LEGAL
        sql.append("UNION ");
        sql.append("SELECT y.ID, y.NOMBRE, y.SUMILLA, y.IDCATEGORIA, y.CATEGORIA, y.FECHA, ");
        sql.append(
                "       y.IDTIPOCONOCIMIENTO, y.TIPOCONOCIMIENTO, y.IDESTADO, y.ESTADO, y.SUMA, y.CONTADOR, ");
        sql.append("       DECODE(y.CONTADOR,0,0,y.SUMA/y.CONTADOR) AS PROMEDIO, y.USUARIOCREA, y.FECHACREA ");
        sql.append("FROM (SELECT ");
        sql.append(
                "            a.npreguntaid AS ID, a.vasunto AS NOMBRE, a.vdetalle AS SUMILLA, a.ncategoriaid AS IDCATEGORIA, ");
        sql.append(
                "            b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, 2 AS IDTIPOCONOCIMIENTO, ");
        sql.append(
                "            'Preguntas y Respuestas' AS TIPOCONOCIMIENTO, a.nsituacionid AS IDESTADO, c.vnombre AS ESTADO, ");
        sql.append(
                "            a.vusuariocreacion AS USUARIOCREA, TO_CHAR(a.dfechacreacion,'dd/MM/yyyy') AS FECHACREA, ");
        sql.append(
                "            NVL(SUM(e.ncalificacion),0) AS SUMA, NVL(COUNT(e.ncalificacion),0) AS CONTADOR ");
        sql.append("        FROM TPREGUNTA a ");
        sql.append("        INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid ");
        sql.append("        INNER JOIN MTSITUACION c ON a.nsituacionid = c.nsituacionid ");
        sql.append("        LEFT OUTER JOIN TCALIFICACION_PREGUNTA e ON a.npreguntaid = e.npreguntaid ");
        sql.append("        WHERE a.nactivo = :ACTIVO ");
        sql.append("        AND c.nsituacionid = 6 AND b.NESTADO = 1 ");
        if (StringUtils.isNotBlank(fCategoria)) {
            sql.append("    AND a.ncategoriaid IN (").append(fCategoria).append(") ");
        }
        if (fFromDate != null) {
            sql.append("    AND TRUNC(a.dfechacreacion) >= TO_DATE('").append(sdf.format(fFromDate))
                    .append("','dd/mm/yyyy') ");
        }
        if (fToDate != null) {
            sql.append("    AND TRUNC(a.dfechacreacion) <= TO_DATE('").append(sdf.format(fToDate))
                    .append("','dd/mm/yyyy') ");
        }
        if (StringUtils.isNotBlank(fCodesPR)) {
            sql.append("    AND a.npreguntaid IN (").append(fCodesPR).append(") ");
        }
        sql.append("        GROUP BY a.npreguntaid, a.vasunto, a.vdetalle, a.ncategoriaid, b.vnombre, ");
        sql.append(
                "        a.dfechapublicacion, 2, 'Preguntas y Respuestas', a.nsituacionid, c.vnombre, a.vusuariocreacion, a.dfechacreacion ");
        sql.append("        ) y ");
        sql.append("WHERE 2 IN (").append(fType).append(") "); //PREGUNTAS Y RESPUESTAS
        sql.append("UNION ");
        sql.append("SELECT z.ID, z.NOMBRE, z.SUMILLA, z.IDCATEGORIA, z.CATEGORIA, z.FECHA, ");
        sql.append(
                "       z.IDTIPOCONOCIMIENTO, z.TIPOCONOCIMIENTO, z.IDESTADO, z.ESTADO, z.SUMA, z.CONTADOR, ");
        sql.append("       DECODE(z.CONTADOR,0,0,z.SUMA/z.CONTADOR) AS PROMEDIO, z.USUARIOCREA, z.FECHACREA ");
        sql.append("FROM (SELECT ");
        sql.append("            a.nconocimientoid AS ID, a.vtitulo AS NOMBRE, a.vdescripcion AS SUMILLA, ");
        sql.append(
                "            a.ncategoriaid AS IDCATEGORIA, b.vnombre AS CATEGORIA, a.dfechapublicacion AS FECHA, ");
        sql.append("            a.ntpoconocimientoid AS IDTIPOCONOCIMIENTO, d.vnombre AS TIPOCONOCIMIENTO, ");
        sql.append(
                "            a.nsituacionid AS IDESTADO, c.vnombre AS ESTADO, a.vusuariocreacion AS USUARIOCREA, ");
        sql.append("            TO_CHAR(a.dfechacreacion,'dd/MM/yyyy') AS FECHACREA, ");
        sql.append(
                "            NVL(SUM(e.ncalificacion),0) AS SUMA, NVL(COUNT(e.ncalificacion),0) AS CONTADOR ");
        sql.append("        FROM TCONOCIMIENTO a ");
        sql.append("        INNER JOIN MTCATEGORIA b ON a.ncategoriaid = b.ncategoriaid ");
        sql.append("        INNER JOIN MTSITUACION c ON a.nsituacionid = c.nsituacionid ");
        sql.append("        INNER JOIN MTTIPO_CONOCIMIENTO d ON a.ntpoconocimientoid = d.ntpoconocimientoid ");
        sql.append("        AND a.ntpoconocimientoid IN (").append(fType).append(") ");
        sql.append("        LEFT OUTER JOIN TCALIFICACION e ON a.nconocimientoid = e.nconocimientoid ");
        sql.append("        WHERE a.nactivo = :ACTIVO ");
        sql.append("        AND c.nsituacionid = 6 AND b.nestado = 1 ");
        if (StringUtils.isNotBlank(fCategoria)) {
            sql.append("    AND a.ncategoriaid IN (").append(fCategoria).append(") ");
        }
        if (fFromDate != null) {
            sql.append("    AND TRUNC(a.dfechacreacion) >= TO_DATE('").append(sdf.format(fFromDate))
                    .append("','dd/mm/yyyy') ");
        }
        if (fToDate != null) {
            sql.append("    AND TRUNC(a.dfechacreacion) <= TO_DATE('").append(sdf.format(fToDate))
                    .append("','dd/mm/yyyy') ");
        }
        if (StringUtils.isNotBlank(fCodesC)) {
            sql.append("    AND a.nconocimientoid IN (").append(fCodesC).append(") ");
        }
        sql.append(
                "        GROUP BY a.nconocimientoid, a.vtitulo, a.vdescripcion, a.ncategoriaid, b.vnombre, ");
        sql.append(
                "        a.dfechapublicacion, a.ntpoconocimientoid, d.vnombre, a.nsituacionid, c.vnombre, a.vusuariocreacion, a.dfechacreacion ");
        sql.append("        ) z ");
        sql.append("WHERE (3 IN (").append(fType).append(") OR 4 IN (").append(fType).append(") OR 5 IN (")
                .append(fType).append(") OR 6 IN (").append(fType).append(")) "); //WIKI            
        if (StringUtils.isNotBlank(order)) {
            sql.append("ORDER BY ").append(order);
        } else {
            sql.append("ORDER BY 6 DESC ");
        }

        object = getHibernateTemplate().execute(new HibernateCallback() {
            @Override
            public Object doInHibernate(Session session) throws HibernateException {
                Query query = session.createSQLQuery(sql.toString());
                query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
                if (StringUtils.isNotBlank(sql.toString())) {
                    query.setParameter("ACTIVO", BigDecimal.ONE);
                }
                return query.list();
            }
        });
    } catch (DataAccessException e) {
        e.getMessage();
        e.printStackTrace();
    }
    return (List<HashMap<String, Object>>) object;
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/changePassword", method = RequestMethod.POST)
@Timed// w w  w .jav  a 2  s.  co m
@ExceptionMetered
public ModelMap changePassword(@RequestParam(value = "pin", required = false) String pin,
        @RequestParam(value = "old_password", required = false) String oldPassword,
        @RequestParam(value = "new_password") String newPassword, HttpSession session,
        HttpServletResponse resp) {
    try {
        User user = getUser(service, session, pin);
        if (user == null) {
            invalidCredentials(resp);
            return null;
        }
        if (user.isGvPassword()) {
            sendError(400, "user is using google voice password. Cannot change password via api.", resp);
            return null;
        }
        if (!user.getPassword().equals(oldPassword)) {
            invalidCredentials(resp);
            return null;
        }
        if (StringUtils.isBlank(newPassword)) {
            invalidCredentials(resp);
            return null;
        }
        service.changePassword(user.getEmail(), newPassword, false);
        return new ModelMap("result", "ok");
    } catch (DataAccessException e) {
        internalError(e, resp);
        return null;
    } catch (IOException e) {
        sendError(400, e.getMessage(), resp);
        return null;
    }
}

From source file:org.jooq.example.TransactionTest.java

@Test
public void testjOOQTransactionsNested() {
    AtomicBoolean rollback1 = new AtomicBoolean(false);
    AtomicBoolean rollback2 = new AtomicBoolean(false);

    try {/*  w w  w .  j  a  v  a  2  s .  c  om*/

        // If using Spring transactions, we don't need the c1 reference
        dsl.transaction(c1 -> {

            // The first insertion will work
            dsl.insertInto(BOOK).set(BOOK.ID, 5).set(BOOK.AUTHOR_ID, 1).set(BOOK.TITLE, "Book 5").execute();

            assertEquals(5, dsl.fetchCount(BOOK));

            try {

                // Nest transactions using Spring. This should create a savepoint, right here
                // If using Spring transactions, we don't need the c2 reference
                dsl.transaction(c2 -> {

                    // The second insertion shouldn't work
                    for (int i = 0; i < 2; i++)
                        dsl.insertInto(BOOK).set(BOOK.ID, 6).set(BOOK.AUTHOR_ID, 1).set(BOOK.TITLE, "Book 6")
                                .execute();

                    Assert.fail();
                });
            }

            catch (DataAccessException e) {
                rollback1.set(true);
            }

            // We should've rolled back to the savepoint
            assertEquals(5, dsl.fetchCount(BOOK));

            throw new org.jooq.exception.DataAccessException("Rollback");
        });
    }

    // Upon the constraint violation, the transaction must already have been rolled back
    catch (org.jooq.exception.DataAccessException e) {
        assertEquals("Rollback", e.getMessage());
        rollback2.set(true);
    }

    assertEquals(4, dsl.fetchCount(BOOK));
    assertTrue(rollback2.get());
    assertTrue(rollback2.get());
}

From source file:com.sfs.whichdoctor.dao.OnlineApplicationDAOImpl.java

/**
 * Delete the OnlineApplicationBean.//from   w ww  .j  av a2  s  . c o  m
 *
 * @param onlineApplication the online application
 * @param checkUser the check user
 * @param privileges the privileges
 *
 * @return true, if successful
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final boolean delete(final OnlineApplicationBean onlineApplication, final UserBean checkUser,
        final PrivilegesBean privileges) throws WhichDoctorDaoException {

    if (!privileges.getPrivilege(checkUser, "systemAdmin", "delete")) {
        throw new WhichDoctorDaoException("Insufficient user credentials " + "to delete online application");
    }

    boolean success = false;

    final String deleteSQL = this.getSQL().getValue("onlineapplication/delete");

    try {
        final int deleteCount = this.getJdbcTemplateWriter().update(deleteSQL,
                new Object[] { onlineApplication.getId() });

        dataLogger.info("Online application records deleted: " + deleteCount);

        if (deleteCount > 0) {
            success = true;
        }

    } catch (DataAccessException de) {
        dataLogger.error("Error deleting online application: " + de.getMessage());
    }

    return success;
}

From source file:com.sfs.whichdoctor.dao.CreditDAOImpl.java

/**
 * Update the financial summary./*  w w w  . j  a  v a  2s . co  m*/
 *
 * @param action the action
 * @param credit the credit
 * @param typeId the type id
 * @param issued the issued
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
private void updateFinancialSummary(final String action, final CreditBean credit, final int typeId,
        final Date issued) throws WhichDoctorDaoException {

    try {
        if (StringUtils.equals(action, "delete")) {
            this.getJdbcTemplateWriter().update(this.getSQL().getValue("credit/deleteSummary"),
                    new Object[] { credit.getGUID() });
        } else {
            /* Create or modify the financial summarty */
            this.getJdbcTemplateWriter().update(this.getSQL().getValue("credit/editSummary"),
                    new Object[] { credit.getGUID(), typeId, credit.getNumber(), credit.getDescription(),
                            credit.getValue(), credit.getNetValue(), credit.getCancelled(), issued,
                            credit.getPersonId(), credit.getOrganisationId(),

                            typeId, credit.getNumber(), credit.getDescription(), credit.getValue(),
                            credit.getNetValue(), credit.getCancelled(), issued, credit.getPersonId(),
                            credit.getOrganisationId() });
        }
    } catch (DataAccessException dae) {
        dataLogger.error("Failed to modify the financial summary: " + dae.getMessage());
        throw new WhichDoctorDaoException("Failed to modify the financial summary: " + dae.getMessage());
    }
}

From source file:com.sfs.whichdoctor.dao.ReceiptDAOImpl.java

/**
 * Update the financial summary./*  w  w  w. ja v  a  2  s . c o  m*/
 *
 * @param action the action
 * @param receipt the receipt
 * @param typeId the type id
 * @param issued the issued
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
private void updateFinancialSummary(final String action, final ReceiptBean receipt, final int typeId,
        final Date issued) throws WhichDoctorDaoException {

    if (!StringUtils.equals(action, "delete")) {
        /* Modify the financial summary for this entry */
        try {
            this.getJdbcTemplateWriter().update(this.getSQL().getValue("receipt/editSummary"), new Object[] {
                    typeId, receipt.getDescription(), receipt.getCancelled(), issued, receipt.getGUID() });
        } catch (DataAccessException dae) {
            dataLogger.error("Failed to modify the financial summary: " + dae.getMessage());
            throw new WhichDoctorDaoException("Failed to modify the financial summary: " + dae.getMessage());
        }
    }
}

From source file:com.sfs.whichdoctor.dao.WhichDoctorDAOImpl.java

/**
 * Renames the identified DN within the datastore to the new DN.
 *
 * @param originalDN the original dn//from www .j  a va  2s.c o m
 * @param newDN the new dn
 * @param checkUser the check user
 * @param privileges the privileges
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final void renameDN(final String originalDN, final String newDN, final UserBean checkUser,
        final PrivilegesBean privileges) throws WhichDoctorDaoException {
    if (originalDN == null) {
        throw new WhichDoctorDaoException("The original User DN cannot be null");
    }
    if (originalDN.compareTo("") == 0) {
        throw new WhichDoctorDaoException("The original User DN cannot be an empty string");
    }
    if (newDN == null) {
        throw new WhichDoctorDaoException("The User DN cannot be null");
    }
    if (newDN.compareTo("") == 0) {
        throw new WhichDoctorDaoException("The User DN cannot be an empty string");
    }
    if (!privileges.getPrivilege(checkUser, "systemAdmin", "modify")) {
        throw new WhichDoctorDaoException("Insufficient user credentials to rename user DN");
    }

    /** Loop through the SQLBean values and execute relevant updates **/

    String[] types = { "update", "replace", "delete" };
    final int maxCount = 100;

    for (String type : types) {
        for (int i = 0; i < maxCount; i++) {
            String sql = null;
            try {
                final String sqlIndex = "whichdoctor/renameDn/" + type + i;
                dataLogger.debug("SQL Index: " + sqlIndex);
                sql = this.getSQL().getValue(sqlIndex);
                dataLogger.debug(StringUtils.capitalize(type) + " SQL: " + sql);
            } catch (Exception e) {
                sql = null;
            }

            ArrayList<String> variables = new ArrayList<String>();

            if (StringUtils.equals(type, "update")) {
                variables.add(newDN);
                variables.add(originalDN);
            }
            if (StringUtils.equals(type, "replace")) {
                variables.add(originalDN);
                variables.add(newDN);
            }
            if (StringUtils.equals(type, "delete")) {
                variables.add(originalDN);
            }

            if (StringUtils.isNotBlank(sql)) {
                try {
                    this.getJdbcTemplateWriter().update(sql, variables.toArray());
                } catch (DataAccessException dae) {
                    dataLogger.error("Error renaming User DN: " + dae.getMessage());
                }
            }
        }
    }
}

From source file:com.sfs.whichdoctor.dao.AddressVerificationDAOImpl.java

/**
 * Update the process status.// w w w .ja  va 2s.  c o m
 *
 * @param addressVerificationId the address verification id
 * @param status the status
 * @param message the message
 */
private void updateProcessStatus(final int addressVerificationId, final String status, final String message) {

    // Load the process status
    int processStatusId = 0;
    try {
        ObjectTypeBean objectType = this.getObjectTypeDAO().load("Address Verification Process Status", "",
                status);
        if (objectType != null) {
            processStatusId = objectType.getObjectTypeId();
        }
    } catch (SFSDaoException sfe) {
        dataLogger.error("Error loading process status: " + sfe.getMessage());
    }

    try {
        this.getJdbcTemplateWriter().update(this.getSQL().getValue("addressVerification/processStatus"),
                new Object[] { processStatusId, message, addressVerificationId });

    } catch (DataAccessException de) {
        dataLogger.error("Error updating the address verification status: " + de.getMessage());
    }
}

From source file:com.sfs.whichdoctor.dao.AddressVerificationDAOImpl.java

/**
 * Deletes the address verification bean.
 *
 * @param addressVerification the address verification
 * @return the boolean/*w w w . j  a  v a 2s .co m*/
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final boolean delete(final AddressVerificationBean addressVerification) throws WhichDoctorDaoException {

    if (addressVerification == null) {
        throw new WhichDoctorDaoException("The address verification cannot be null");
    }
    if (addressVerification.getAddressVerificationId() < 1) {
        throw new WhichDoctorDaoException("A valid ID is required");
    }

    boolean success = false;
    int deleteCount = 0;

    try {
        deleteCount = this.getJdbcTemplateWriter().update(this.getSQL().getValue("addressVerification/delete"),
                new Object[] { addressVerification.getAddressVerificationId() });

    } catch (DataAccessException de) {
        dataLogger.error("Error deleting address verification record: " + de.getMessage());
        throw new WhichDoctorDaoException(
                "Error deleting address verification " + "record: " + de.getMessage());
    }

    if (deleteCount > 0) {
        success = true;

        // Check the verification status of the address compared to
        // what is waiting to be verified
        try {
            AddressBean address = this.addressDAO.loadGUID(addressVerification.getAddressGUID());

            Collection<AddressVerificationBean> pending = loadPendingForGUID(
                    addressVerification.getAddressGUID());

            if (StringUtils.startsWithIgnoreCase(address.getVerificationStatus(), PENDING)) {
                if (pending.size() == 0) {
                    // There are no pending records, set status to unverified
                    this.addressDAO.updateVerificationStatus("Unverified address",
                            addressVerification.getAddressGUID());
                }
            }
        } catch (WhichDoctorDaoException wde) {
            dataLogger.error("Error checking current verification of the address: " + wde.getMessage());
        }
    }
    return success;
}

From source file:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java

public void cleanupOrphanedPermissions() {
    try {/*from  w ww  . ja v  a2s  .  c  o  m*/
        getJdbcTemplate().update(getStatement("delete.orphaned.permissions"));
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
    }
}