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:com.sfs.whichdoctor.dao.PersonDAOImpl.java

/**
 * Load a PersonBean for a specified, anonymous, candidate number using the
 * load options provided./*from w w w  .  j  a  va  2  s .  c o  m*/
 *
 * @param candidateNumber the candidate number
 * @param loadDetails the load details
 *
 * @return the person bean
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final PersonBean loadCandidateNumber(final int candidateNumber, final BuilderBean loadDetails)
        throws WhichDoctorDaoException {
    dataLogger.info("Candidate Number: " + candidateNumber + " requested");

    int personGUID = 0;

    final String loadSQL = getSQL().getValue("person/loadCandidate");

    try {
        personGUID = this.getJdbcTemplateReader().queryForInt(loadSQL, new Object[] { candidateNumber });
    } catch (DataAccessException de) {
        dataLogger.error("Error getting guid for supplied candidate: " + de.getMessage());
    }
    if (personGUID > 0) {
        return loadGUID(personGUID, loadDetails);
    } else {
        throw new WhichDoctorDaoException("Sorry no person matching those " + "details could be identified");
    }
}

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

/**
 * Recalculate all of the rotation years.
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 *///from w ww.ja v a2s .com
public final void recalculateAllRotationYears() throws WhichDoctorDaoException {

    // Load all of the rotations
    Collection<RotationBean> rotations = new ArrayList<RotationBean>();
    try {
        rotations = this.loadActiveRotations();
    } catch (WhichDoctorDaoException wde) {
        dataLogger.error("Error loading all rotations: " + wde.getMessage());
    }

    if (rotations != null) {
        for (RotationBean rotation : rotations) {
            try {
                this.getJdbcTemplateWriter().update(this.getSQL().getValue("rotation/updateYear"),
                        new Object[] { getRotationYear(rotation.getStartDate(), rotation.getEndDate()),
                                rotation.getGUID() });

            } catch (DataAccessException de) {
                dataLogger.error("Error updating the year for the rotation guid: " + rotation.getGUID() + ", "
                        + de.getMessage());
            }
        }
    }
}

From source file:org.sakaiproject.genericdao.springjdbc.JdbcGenericDao.java

private void executeDDLforType(InputStream sqlDDL, Class<?> type) {
    // Now run the DDL commands if possible
    try {//from  ww w.  j  a v a 2  s . c om
        if (isAutoCommitDDL()) {
            commitTransaction(); // start the transaction
        }
        BufferedReader r = new BufferedReader(new InputStreamReader(sqlDDL));
        try {
            // read the first line, skipping any '--' comment lines
            boolean firstLine = true;
            StringBuffer buf = new StringBuffer();
            for (String line = r.readLine(); line != null; line = r.readLine()) {
                line = line.trim();
                if (line.startsWith("--"))
                    continue;
                if (line.length() == 0)
                    continue;

                // add the line to the buffer
                buf.append(' ');
                buf.append(line);

                // process if the line ends with a ';'
                boolean process = line.endsWith(";");

                if (!process)
                    continue;

                // remove trailing ';'
                buf.setLength(buf.length() - 1);

                String ddl = buf.toString().trim();
                // FIXME do replacements even if we do not know the type
                if (type != null) {
                    // handle ddl replacements
                    ddl = handleTypeReplacements(type, ddl);
                }

                // run the first line as the test - if it fails, we are done
                if (firstLine) {
                    firstLine = false;
                    try {
                        if (showSQL) {
                            logInfo("DDL=" + ddl);
                        }
                        getSpringJdbcTemplate().execute(ddl);
                    } catch (DataAccessException e) {
                        //log.info("Could not to execute first DDL ("+ddl+"), skipping the rest");
                        logInfo("Could not execute first DDL line, skipping the rest: " + e.getMessage() + ":"
                                + e.getCause());
                        //e.printStackTrace();
                        return;
                    }
                } else {
                    // run other lines, until done - any one can fail (we will report it)
                    try {
                        if (showSQL) {
                            logInfo("DDL=" + ddl);
                        }
                        getSpringJdbcTemplate().execute(ddl);
                    } catch (DataAccessException e) {
                        throw new IllegalArgumentException("Failed while executing ddl: " + e.getMessage(), e);
                    }
                }
                if (isAutoCommitDDL()) {
                    commitTransaction();
                }

                // clear the buffer for next
                buf.setLength(0);
            }
        } catch (IOException any) {
            throw new RuntimeException("Failure while processing DDL", any);
        } finally {
            try {
                r.close();
            } catch (IOException any) {
                //log.warn("Failure while closing DDL inputstream reader", any);
            }
            // close the connection used for this DDL
            if (isAutoCommitDDL()) {
                closeConnection();
            }
        }
    } finally {
        try {
            sqlDDL.close();
        } catch (IOException any) {
            //log.warn("Failure while closing inputstream", any);
        }
    }
}

From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java

@SuppressWarnings("unchecked")
public List<DBInfoType> getEnvironmentData(String domainId) throws I2B2Exception, I2B2DAOException {
    String sql = "select * from pm_hive_params where domain_id = ? and status_cd<>'D'";
    //      log.info(sql + domainId + projectId + ownerId);
    List<DBInfoType> queryResult = null;
    try {//from w  w  w .java 2 s  .com
        queryResult = jt.query(sql, getEnvironmentParams(), domainId);
    } catch (DataAccessException e) {
        log.error(e.getMessage());
        throw new I2B2DAOException("Database error");
    }
    return queryResult;
}

From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java

@SuppressWarnings("unchecked")
public List<DBInfoType> getProjectParams(String projectId) throws I2B2Exception, I2B2DAOException {
    String sql = "select * from pm_project_params where project_id=? and status_cd<>'D'";
    //log.debug(sql  + projectId );
    List<DBInfoType> queryResult = null;
    try {/*from  w w  w.  j  a  v a  2  s.c o  m*/
        queryResult = jt.query(sql, getProjectParams(), projectId);
    } catch (DataAccessException e) {
        log.error(e.getMessage());
        e.printStackTrace();
        throw new I2B2DAOException("Database error");
    }
    return queryResult;
}

From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java

@SuppressWarnings("unchecked")
public List<DBInfoType> getCellParam(String cellId, String project) throws I2B2Exception, I2B2DAOException {
    String sql = "select * from  pm_cell_params where cell_id = ? and  project_path = ? and status_cd<>'D'";
    //      log.info(sql + domainId + projectId + ownerId);
    List<DBInfoType> queryResult = null;
    try {/* w ww.  j  a  v a2  s . c om*/
        queryResult = jt.query(sql, getParam(), cellId, project);
    } catch (DataAccessException e) {
        log.error(e.getMessage());
        e.printStackTrace();
        throw new I2B2DAOException("Database error");
    }
    return queryResult;
}

From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java

@SuppressWarnings("unchecked")
public List<DBInfoType> getProjectUserParams(String projectId, String userId)
        throws I2B2Exception, I2B2DAOException {
    String sql = "select * from pm_project_user_params where project_id=? and user_id=? and status_cd<>'D'";
    //      log.info(sql + domainId + projectId + ownerId);
    List<DBInfoType> queryResult = null;
    try {// ww w.j  a  va 2s .  co m
        queryResult = jt.query(sql, getProjectUserParams(), projectId, userId);
    } catch (DataAccessException e) {
        log.error(e.getMessage());
        e.printStackTrace();
        throw new I2B2DAOException("Database error");
    }
    return queryResult;
}

From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java

@SuppressWarnings("unchecked")
public List<DBInfoType> getRole(String userId, String project) throws I2B2Exception, I2B2DAOException {
    String sql = "select  distinct" + "    case  upper(rr.COLUMN_CD)"
            + "         when '@'   then pur.PROJECT_ID" + "         when 'PROJECT_ID' then pur.PROJECT_ID"
            + "         else null" + "    end as PROJECT_ID," + "    case  upper(rr.COLUMN_CD)"
            + "         when '@'   then pur.USER_ID" + "         when 'USER_ID' then pur.USER_ID"
            + "         else null" + "    end as USER_ID," + "    case  upper(rr.COLUMN_CD)"
            + "         when '@'   then pur.USER_ROLE_CD" + "         when 'USER_ROLE_CD' then pur.USER_ROLE_CD"
            + "         else null" + "    end as USER_ROLE_CD" + " from "
            + "    pm_project_user_roles pur, pm_role_requirement rr" + " where " + "    pur.status_cd<>'D' and"
            + "    rr.status_cd<>'D' and" + "    pur.user_id = ? and"
            + (project != null ? "    pur.project_id = ? and" : "")
            + "    (rr.read_hivemgmt_CD = '@') OR (upper(rr.read_hivemgmt_CD) =  upper(pur.USER_ROLE_CD)) and"
            + "    upper(rr.table_cd) =  'PM_PROJECT_USER_ROLES'";
    //      String sql =  "select * from pm_project_user_roles where user_id=? and project_id=? and status_cd<>'D'";
    //      log.info(sql + domainId + projectId + ownerId);
    List<DBInfoType> queryResult = null;
    try {/*from   ww  w . j  a v  a2 s  .  c  o  m*/
        if (project == null)
            queryResult = jt.query(sql, getRole(), userId);
        else
            queryResult = jt.query(sql, getRole(), userId, project);
    } catch (DataAccessException e) {
        log.error(e.getMessage());
        e.printStackTrace();
        throw new I2B2DAOException("Database error");
    }
    return queryResult;
}

From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java

@SuppressWarnings("unchecked")
public List<DBInfoType> getCell(String cell, String project, boolean ignoreDeleted)
        throws I2B2Exception, I2B2DAOException {
    //      log.info(sql + domainId + projectId + ownerId);
    List<DBInfoType> queryResult = null;
    log.debug("Searching for cell: " + cell + " within project " + project);
    try {//from w w  w .  jav a  2s . c  om
        if (cell.equals("@")) {
            String sql = "select * from pm_cell_data where project_path = ?";
            if (ignoreDeleted)
                sql += " and status_cd<>'D'";
            queryResult = jt.query(sql, getCell(), project);
        } else if ((cell.equals("@") && !project.equals("/"))) {
            String sql = "select * from pm_cell_data where project_path = ?";
            if (ignoreDeleted)
                sql += " and status_cd<>'D'";
            queryResult = jt.query(sql, getCell(), project);

        } else {
            String sql = "select * from pm_cell_data where cell_id = ? and project_path = ?";
            if (ignoreDeleted)
                sql += " and status_cd<>'D'";

            queryResult = jt.query(sql, getCell(), cell, project);
        }
    } catch (DataAccessException e) {
        log.error(e.getMessage());
        e.printStackTrace();
        throw new I2B2DAOException("Database error");
    }
    return queryResult;
}

From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java

public List<DBInfoType> getUserProject(String user) throws I2B2Exception, I2B2DAOException {

    String sql = "select  distinct" + "    case  upper(rr.COLUMN_CD)" + "         when '@'   then pd.PROJECT_ID"
            + "         when 'PROJECT_ID' then pd.PROJECT_ID" + "         else null" + "    end as PROJECT_ID,"
            + "    case  upper(rr.COLUMN_CD)" + "         when '@'   then pd.PROJECT_NAME"
            + "         when 'PROJECT_NAME' then pd.PROJECT_NAME" + "         else null"
            + "    end as PROJECT_NAME," + "    case  upper(rr.COLUMN_CD)"
            + "         when '@'   then pd.PROJECT_WIKI" + "         when 'PROJECT_WIKI' then pd.PROJECT_WIKI"
            + "         else null" + "    end as PROJECT_WIKI," + "    case  upper(rr.COLUMN_CD)"
            + "         when '@'   then pd.PROJECT_PATH" + "         when 'PROJECT_PATH' then pd.PROJECT_PATH"
            + "         else null" + "    end as PROJECT_PATH," + "    case  upper(rr.COLUMN_CD)"
            + "         when '@'   then pd.PROJECT_KEY" + "         when 'PROJECT_KEY' then pd.PROJECT_KEY"
            + "         else null" + "    end as PROJECT_KEY," + "    case  upper(rr.COLUMN_CD)"
            + "         when '@'   then pd.PROJECT_DESCRIPTION"
            + "         when 'PROJECT_DESCRIPTION' then pd.PROJECT_DESCRIPTION" + "         else null"
            + "    end as PROJECT_DESCRIPTION" + " from "
            + "    pm_project_data pd, pm_project_user_roles pur, pm_role_requirement rr" + " where "
            + "    pd.status_cd<>'D'  and" + "    pur.status_cd<>'D' and" + "    rr.status_cd<>'D' and"
            + "     pur.user_ID = ? and" + "    pd.PROJECT_ID = pur.PROJECT_ID and"
            + "    (rr.read_hivemgmt_CD = '@') OR (upper(rr.read_hivemgmt_CD) =  upper(pur.USER_ROLE_CD)) and"
            + "    pd.PROJECT_ID = pur.project_id and" + "    upper(rr.table_cd) =  'PM_PROJECT_DATA'";

    //      String sql =  "select distinct pd.* from pm_project_data pd, pm_project_user_roles pur where pd.project_id=pur.project_id and pur.user_id = ?  and pur.status_cd<>'D' and pd.status_cd<>'D'";
    //      log.info(sql + domainId + projectId + ownerId);
    List<DBInfoType> queryResult = null;
    try {// w  w w.java2  s.c  om
        queryResult = jt.query(sql, getProject(), user);
    } catch (DataAccessException e) {
        log.error(e.getMessage());
        e.printStackTrace();
        throw new I2B2DAOException("Database error");
    }
    return queryResult;
}