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:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java

public void removeAnonAndAuthRoles(String[] siteRefs) {
    try {//from w ww .j  a v  a 2 s .c  om
        if (siteRefs == null || siteRefs.length == 0) {
            return;
        }
        int subArrayIndex = 0;
        do {
            int subArraySize = ORACLE_IN_CLAUSE_SIZE_LIMIT;
            if (subArrayIndex + subArraySize > siteRefs.length) {
                subArraySize = (siteRefs.length - subArrayIndex);
            }
            String[] subSiteRefs = Arrays.copyOfRange(siteRefs, subArrayIndex, subArrayIndex + subArraySize);

            String query1 = getStatement("delete.anon.auth.roles");
            String query2 = getStatement("delete.anon.auth.permissions");

            String inParams = "(";
            for (int i = 0; i < subSiteRefs.length; i++) {
                inParams += "?";
                if (i < subSiteRefs.length - 1) {
                    inParams += ",";
                }
            }
            inParams += ")";
            query1 = query1.replace("(?)", inParams);
            query2 = query2.replace("(?)", inParams);
            getJdbcTemplate().update(query1, subSiteRefs);
            getJdbcTemplate().update(query2, subSiteRefs);
            subArrayIndex = subArrayIndex + subArraySize;
        } while (subArrayIndex < siteRefs.length);
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
    }
}

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

public void updateSiteProperty(String[] siteIds, String propertyName, String propertyValue) {
    try {//from w w  w  . j a v a2 s  .  co  m
        if (siteIds == null || siteIds.length == 0) {
            return;
        }
        String query = getStatement("update.siteProperty");

        if (oracle) {
            //Create Replace query:
            String values = "";
            for (String siteId : siteIds) {
                if (!"".equals(values)) {
                    values += " union ";
                }
                values += "select '" + siteId + "' SITE_ID, '" + propertyName + "' NAME, '" + propertyValue
                        + "' VALUE from dual";
            }
            query = query.replace("?", values);
        } else {
            //Create Replace query:
            String values = "";
            for (String siteId : siteIds) {
                if (!"".equals(values)) {
                    values += ",";
                }
                values += "('" + siteId + "', '" + propertyName + "','" + propertyValue + "')";
            }
            query = query + values;
        }

        getJdbcTemplate().update(query);
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
    }
}

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

public void copyRole(String fromRealm, String fromRole, String[] toRealm, String toRole) {
    if (toRealm == null || toRealm.length == 0) {
        return;/*  w  w  w.  j av a 2 s . c o  m*/
    }
    try {
        int subArrayIndex = 0;
        do {
            int subArraySize = ORACLE_IN_CLAUSE_SIZE_LIMIT;
            if (subArrayIndex + subArraySize > toRealm.length) {
                subArraySize = (toRealm.length - subArrayIndex);
            }
            String[] subSiteRefs = Arrays.copyOfRange(toRealm, subArrayIndex, subArrayIndex + subArraySize);

            String query1 = getStatement("insert.copyrole");
            String query2 = getStatement("insert.copyroledesc");

            String inParams = "(";
            for (int i = 0; i < subSiteRefs.length; i++) {
                inParams += "?";
                if (i < subSiteRefs.length - 1) {
                    inParams += ",";
                }
            }
            inParams += ")";
            query1 = query1.replace("(?)", inParams);
            query2 = query2.replace("(?)", inParams);
            List<String> parameters1 = new ArrayList<String>();
            parameters1.addAll(Arrays.asList(subSiteRefs));
            parameters1.add(fromRealm);
            parameters1.add(fromRole);
            parameters1.add(toRole);
            List<String> parameters2 = new ArrayList<String>();
            parameters2.addAll(Arrays.asList(subSiteRefs));
            parameters2.add(toRole);
            getJdbcTemplate().update(query1, parameters1.toArray());
            getJdbcTemplate().update(query2, parameters2.toArray());
            subArrayIndex = subArrayIndex + subArraySize;
        } while (subArrayIndex < toRealm.length);
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
    }
}

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

public List<String> getSitesWithDelegatedAccessTool(String[] siteIds) {
    try {//from   w w  w  .  ja  v  a  2s  .  c om
        List<String> returnList = new ArrayList<String>();
        if (siteIds == null || siteIds.length == 0) {
            return returnList;
        }

        int subArrayIndex = 0;
        do {
            int subArraySize = ORACLE_IN_CLAUSE_SIZE_LIMIT;
            if (subArrayIndex + subArraySize > siteIds.length) {
                subArraySize = (siteIds.length - subArrayIndex);
            }
            String[] subSiteRefs = Arrays.copyOfRange(siteIds, subArrayIndex, subArrayIndex + subArraySize);

            String query = getStatement("select.delegatedaccess.user.hasworkspacetool");
            String inParams = "(";
            for (int i = 0; i < subSiteRefs.length; i++) {
                inParams += "?";
                if (i < subSiteRefs.length - 1) {
                    inParams += ",";
                }
            }
            inParams += ")";
            query = query.replace("(?)", inParams);
            List<String> results = (List<String>) getJdbcTemplate().query(query, subSiteRefs, new RowMapper() {
                public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                    return resultSet.getString("SITE_ID");
                }
            });
            if (results != null) {
                returnList.addAll(results);
            }
            subArrayIndex = subArrayIndex + subArraySize;
        } while (subArrayIndex < siteIds.length);

        return returnList;
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return null;
    }

}

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

/**
 * DAC-40 Highlight Inactive Courses in site search
 * requires the job "InactiveCoursesJob" attached in the jira
 *//*from   w ww  .  j  av  a2  s.c o  m*/

public List<String> findActiveSites(String[] siteIds) {
    List<String> returnList = new ArrayList<String>();

    if (siteIds == null || siteIds.length == 0) {
        return returnList;
    }
    try {
        int subArrayIndex = 0;
        do {
            int subArraySize = ORACLE_IN_CLAUSE_SIZE_LIMIT;
            if (subArrayIndex + subArraySize > siteIds.length) {
                subArraySize = (siteIds.length - subArrayIndex);
            }
            String[] subSiteRefs = Arrays.copyOfRange(siteIds, subArrayIndex, subArrayIndex + subArraySize);

            String query = getStatement("select.activeSites");
            String inParams = "(";
            for (int i = 0; i < subSiteRefs.length; i++) {
                inParams += "?";
                if (i < subSiteRefs.length - 1) {
                    inParams += ",";
                }
            }
            inParams += ")";
            query = query.replace("(?)", inParams);
            List<String> results = (List<String>) getJdbcTemplate().query(query, subSiteRefs, new RowMapper() {
                public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                    return resultSet.getString("SITE_ID");
                }
            });
            if (results != null) {
                returnList.addAll(results);
            }
            subArrayIndex = subArrayIndex + subArraySize;
        } while (subArrayIndex < siteIds.length);

        return returnList;
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return null;
    }

}

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

public Map<String, List<String>> getNodesBySiteRef(String[] siteRefs, String hierarchyId) {
    try {//from  ww  w . j a  v a 2s. co m
        Map<String, List<String>> returnMap = new HashMap<String, List<String>>();
        if (siteRefs == null || siteRefs.length == 0) {
            return returnMap;
        }
        int subArrayIndex = 0;
        do {
            int subArraySize = ORACLE_IN_CLAUSE_SIZE_LIMIT;
            if (subArrayIndex + subArraySize > siteRefs.length) {
                subArraySize = (siteRefs.length - subArrayIndex);
            }
            String[] subSiteRefs = Arrays.copyOfRange(siteRefs, subArrayIndex, subArrayIndex + subArraySize);

            String query = getStatement("select.hierarchyNode");
            String inParams = "(";
            for (int i = 0; i < subSiteRefs.length; i++) {
                inParams += "?";
                if (i < subSiteRefs.length - 1) {
                    inParams += ",";
                }
            }
            inParams += ")";
            query = query.replace("(?)", inParams);
            List<String> parameters = new ArrayList<String>();
            parameters.add(hierarchyId);
            parameters.addAll(Arrays.asList(subSiteRefs));
            List<String[]> results = (List<String[]>) getJdbcTemplate().query(query, parameters.toArray(),
                    new RowMapper() {

                        public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                            return new String[] { resultSet.getString("title"), resultSet.getString("ID") };
                        }
                    });
            if (results != null) {
                for (String[] result : results) {
                    if (result != null && result.length == 2) {
                        if (!returnMap.containsKey(result[0])) {
                            returnMap.put(result[0], new ArrayList<String>());
                        }
                        returnMap.get(result[0]).add(result[1]);
                    }
                }
            }
            subArrayIndex = subArrayIndex + subArraySize;
        } while (subArrayIndex < siteRefs.length);

        return returnMap;
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return null;
    }
}

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

public Map<String, Set<String>> getNodesAndPermsForUser(String userId, String[] nodeIds) {
    try {//w  w w .ja  v  a  2 s  .c  om
        Map<String, Set<String>> returnMap = new HashMap<String, Set<String>>();
        if (nodeIds == null || nodeIds.length == 0) {
            return returnMap;
        }
        int subArrayIndex = 0;
        do {
            int subArraySize = ORACLE_IN_CLAUSE_SIZE_LIMIT;
            if (subArrayIndex + subArraySize > nodeIds.length) {
                subArraySize = (nodeIds.length - subArrayIndex);
            }
            String[] subSiteRefs = Arrays.copyOfRange(nodeIds, subArrayIndex, subArrayIndex + subArraySize);

            String query = getStatement("select.nodes.and.perms.for.user");
            String inParams = "(";
            for (int i = 0; i < subSiteRefs.length; i++) {
                inParams += "?";
                if (i < subSiteRefs.length - 1) {
                    inParams += ",";
                }
            }
            inParams += ")";
            query = query.replace("(?)", inParams);
            List<String> parameters = new ArrayList<String>();
            parameters.add(userId);
            parameters.addAll(Arrays.asList(subSiteRefs));
            List<String[]> results = (List<String[]>) getJdbcTemplate().query(query, parameters.toArray(),
                    new RowMapper() {

                        public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                            return new String[] { resultSet.getString("NODEID"),
                                    resultSet.getString("PERMISSION") };
                        }
                    });
            if (results != null) {
                for (String[] result : results) {
                    if (result != null && result.length == 2) {
                        if (!returnMap.containsKey(result[0])) {
                            returnMap.put(result[0], new HashSet<String>());
                        }
                        returnMap.get(result[0]).add(result[1]);
                    }
                }
            }
            subArrayIndex = subArrayIndex + subArraySize;
        } while (subArrayIndex < nodeIds.length);

        return returnMap;
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return null;
    }
}

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

public Map<String, Map<String, String>> searchSitesForProp(String[] props, String[] siteIds) {
    try {/*from w w  w .  jav a 2s.com*/
        Map<String, Map<String, String>> returnMap = new HashMap<String, Map<String, String>>();
        if (props == null || props.length == 0 || siteIds == null || siteIds.length == 0) {
            return returnMap;
        }
        int subArrayIndex = 0;
        do {
            int subArraySize = ORACLE_IN_CLAUSE_SIZE_LIMIT;
            if (subArrayIndex + subArraySize > siteIds.length) {
                subArraySize = (siteIds.length - subArrayIndex);
            }
            String[] subSiteRefs = Arrays.copyOfRange(siteIds, subArrayIndex, subArrayIndex + subArraySize);

            String query = getStatement("select.sitesProp");
            String propInParams = "(";
            for (int i = 0; i < props.length; i++) {
                propInParams += "'" + props[i].replace("'", "''") + "'";
                if (i < props.length - 1) {
                    propInParams += ",";
                }
            }
            propInParams += ")";
            query = query.replace("(:props)", propInParams);

            propInParams += ")";
            String inParams = "(";
            for (int i = 0; i < subSiteRefs.length; i++) {
                inParams += "'" + subSiteRefs[i].replace("'", "''") + "'";
                if (i < subSiteRefs.length - 1) {
                    inParams += ",";
                }
            }
            inParams += ")";
            query = query.replace("(:siteIds)", inParams);
            List<String[]> results = (List<String[]>) getJdbcTemplate().query(query, new RowMapper() {

                public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                    return new String[] { resultSet.getString("SITE_ID"), resultSet.getString("NAME"),
                            resultSet.getString("VALUE") };
                }
            });
            if (results != null) {
                for (String[] result : results) {
                    Map<String, String> propMap = new HashMap<String, String>();
                    if (returnMap.containsKey(result[0])) {
                        propMap = returnMap.get(result[0]);
                    }
                    propMap.put(result[1], result[2]);
                    returnMap.put(result[0], propMap);
                }
            }
            subArrayIndex = subArrayIndex + subArraySize;
        } while (subArrayIndex < siteIds.length);

        return returnMap;
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return null;
    }
}

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

/**
 * Save.// w ww.j a v a  2s . co m
 *
 * @param payment the payment
 * @param receipt the receipt
 * @param checkUser the check user
 * @param privileges the privileges
 * @param action the action
 *
 * @return the int
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
private int save(final PaymentBean payment, final ReceiptBean receipt, final UserBean checkUser,
        final PrivilegesBean privileges, final String action) throws WhichDoctorDaoException {

    /* Check required information within PaymentBean is present */
    if (payment.getReferenceGUID() == 0) {
        throw new WhichDoctorDaoException("Payment requires a valid " + "Reference GUID number");
    }
    if (receipt.getId() == 0) {
        throw new WhichDoctorDaoException("Payment requires a valid receipt");
    }
    if (!privileges.getPrivilege(checkUser, "payments", action)) {
        throw new WhichDoctorDaoException("Insufficient user credentials " + "to create new payment entry");
    }

    /* Get the Receipt TypeId */
    int typeId = 0;
    try {
        FinancialTypeBean financialObject = this.financialTypeDAO.load("Receipt", receipt.getTypeName(),
                receipt.getClassName());
        typeId = financialObject.getFinancialTypeId();
    } catch (Exception e) {
        dataLogger.error("Error loading financial type for receipt: " + e.getMessage());
        throw new WhichDoctorDaoException("Error loading financial type " + "for receipt: " + e.getMessage());
    }

    if (payment.getIncomeStreamId() > 0 && payment.getNetValue() > 0) {
        // Debit should not exist if payment is negative This is because you
        // cannot attribute negative payment to a debit
        payment.setDebit(new DebitBean());

        // As it is a negative debit the net value should be negative
        payment.setNetValue(0 - payment.getNetValue());
        // Reset the value in order to recalculate GST (if applicable)
        payment.setValue(0);
    }

    int personGUID = 0;
    int organisationGUID = 0;
    if (payment.getPerson() != null) {
        personGUID = payment.getPerson().getGUID();
    }
    if (payment.getOrganisation() != null) {
        organisationGUID = payment.getOrganisation().getGUID();
    }

    int newDebitGUID = 0;
    if (payment.getDebit() != null) {
        // Load the debit to get the GST rate
        try {
            final DebitBean debit = this.debitDAO.loadGUID(payment.getDebit().getGUID());
            if (debit != null) {
                payment.setGSTRate(debit.getGSTRate());
                newDebitGUID = debit.getGUID();

                if (personGUID == 0 && debit.getPerson() != null) {
                    personGUID = debit.getPerson().getGUID();
                }
                if (organisationGUID == 0 && debit.getOrganisation() != null) {
                    organisationGUID = debit.getOrganisation().getGUID();
                }
            }
        } catch (WhichDoctorDaoException wde) {
            dataLogger.error("Error loading debit: " + wde.getMessage());
        }
    }

    int existingDebitGUID = 0;
    // Load the existing payment (if GUID > 0) to check if the
    // associated debit has changed.
    if (payment.getGUID() > 0) {
        try {
            final PaymentBean existingPayment = this.loadGUID(payment.getGUID());
            if (existingPayment.getDebit() != null) {
                existingDebitGUID = existingPayment.getDebit().getGUID();
            }
        } catch (WhichDoctorDaoException wde) {
            dataLogger.error("Error loading existing payment: " + wde.getMessage());
        }
    }

    int paymentId = 0;

    Timestamp sqlTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis());

    ArrayList<Object> parameters = new ArrayList<Object>();
    parameters.add(payment.getReferenceGUID());
    parameters.add(personGUID);
    parameters.add(organisationGUID);
    parameters.add(newDebitGUID);
    parameters.add(payment.getValue());
    parameters.add(payment.getNetValue());
    parameters.add(payment.getIncomeStreamId());
    parameters.add(payment.getGSTRate());
    parameters.add(payment.getActive());
    parameters.add(sqlTimeStamp);
    parameters.add(checkUser.getDN());
    parameters.add(payment.getLogMessage(action));

    try {
        Integer[] result = this.performUpdate("payment", payment.getGUID(), parameters, "Payment", checkUser,
                action);
        /* Set the returned guid and id values */
        payment.setGUID(result[0]);
        paymentId = result[1];
    } catch (Exception e) {
        dataLogger.error("Error processing payment record: " + e.getMessage());
        throw new WhichDoctorDaoException("Error processing payment: " + e.getMessage());
    }

    if (paymentId > 0) {

        dataLogger.info(checkUser.getDN() + " created paymentId: " + paymentId);
        /* Get Issued Date */
        Date issued = new Date(Calendar.getInstance().getTimeInMillis());
        if (receipt.getIssued() != null) {
            issued = new Date(receipt.getIssued().getTime());
        }

        if (action.compareTo("delete") == 0) {
            /* Delete the financial summary */
            this.getJdbcTemplateWriter().update(this.getSQL().getValue("payment/deleteSummary"),
                    new Object[] { receipt.getGUID(), payment.getGUID() });

        } else {
            /* Create or modify financial summary entry */
            try {
                this.getJdbcTemplateWriter().update(this.getSQL().getValue("payment/editSummary"),
                        new Object[] { receipt.getGUID(), typeId, receipt.getNumber(), receipt.getDescription(),
                                payment.getValue(), payment.getNetValue(), receipt.getCancelled(), issued,
                                personGUID, organisationGUID, payment.getGUID(),

                                typeId, receipt.getDescription(), payment.getValue(), payment.getNetValue(),
                                receipt.getCancelled(), issued, personGUID, organisationGUID });
            } catch (DataAccessException dae) {
                dataLogger.error("Failed to modify the financial summary: " + dae.getMessage());
                throw new WhichDoctorDaoException(
                        "Failed to modify the financial summary: " + dae.getMessage());
            }
        }

        /* Update the related debit's calculated values */
        if (existingDebitGUID > 0) {
            this.debitDAO.refreshDebitValues(existingDebitGUID);
        }
        if (newDebitGUID > 0 && newDebitGUID != existingDebitGUID) {
            this.debitDAO.refreshDebitValues(newDebitGUID);
        }

        /* Update the search index */
        if (organisationGUID > 0) {
            this.searchIndexDAO.updateCurrentBalanceIndex(organisationGUID, "organisation");
        } else {
            this.searchIndexDAO.updateCurrentBalanceIndex(personGUID, "person");
        }
    }
    return paymentId;
}

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

public List<Object[]> searchSites(String titleSearch, Map<String, String> propsMap, String[] instructorIds,
        String insturctorType, boolean publishedOnly) {
    try {//from   w w w  . ja  va  2  s  . c o m
        if (titleSearch == null) {
            titleSearch = "";
        }
        titleSearch = "%" + titleSearch + "%";
        Object[] params = new Object[] { titleSearch };
        String query = "";
        final boolean noInstructors = instructorIds == null || instructorIds.length == 0;
        //either grab the simple site search based on title or the one that limits by instructor ids
        if (noInstructors) {
            query = getStatement("select.siteSearch");
        } else {
            if (DelegatedAccessConstants.ADVANCED_SEARCH_INSTRUCTOR_TYPE_MEMBER.equals(insturctorType)) {
                query = getStatement("select.siteSearchMembers");
            } else {
                //default is instructor search
                query = getStatement("select.siteSearchInstructors");
            }
            String inParams = "(";
            //to be on the safe side, I added oracle limit restriction, but hopefully no one is searching for
            //more than 1000 instructors
            for (int i = 0; i < instructorIds.length && i < ORACLE_IN_CLAUSE_SIZE_LIMIT; i++) {
                inParams += "'" + instructorIds[i].replace("'", "''") + "'";
                if (i < instructorIds.length - 1) {
                    inParams += ",";
                }
            }
            inParams += ")";
            query = query.replace("(:userIds)", inParams);
        }
        //add the site properties restrictions in the where clause
        if (propsMap != null && propsMap.size() > 0) {
            params = new Object[1 + (propsMap.size() * 2)];
            params[0] = titleSearch;
            int i = 1;
            for (Entry<String, String> entry : propsMap.entrySet()) {
                query += " " + getStatement("select.siteSearchPropWhere");
                params[i] = entry.getKey();
                i++;
                params[i] = entry.getValue();
                i++;
            }
        }
        if (publishedOnly) {
            query += " " + getStatement("select.siteSearchPublishedOnly");
        }

        return (List<Object[]>) getJdbcTemplate().query(query, params, new RowMapper() {

            public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                if (noInstructors) {
                    return new Object[] { resultSet.getString("SITE_ID"), resultSet.getString("TITLE"),
                            resultSet.getBoolean("PUBLISHED") };
                } else {
                    return new Object[] { resultSet.getString("SITE_ID"), resultSet.getString("TITLE"),
                            resultSet.getBoolean("PUBLISHED"), resultSet.getString("USER_ID") };
                }
            }
        });
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return new ArrayList<Object[]>();
    }
}