List of usage examples for org.springframework.dao DataAccessException getMessage
@Override
@Nullable
public String getMessage()
From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java
public List<DBInfoType> getParam(Object utype, boolean showStatus) throws I2B2Exception, I2B2DAOException { // log.info(sql + domainId + projectId + ownerId); List<DBInfoType> queryResult = null; try {//from w w w . j a v a 2 s.com if (utype instanceof ProjectType) { if (((ProjectType) utype).getUserName() != null && !((ProjectType) utype).getUserName().equals("")) { String sql = "select * from pm_project_user_params where id=? " + (showStatus == false ? "" : " and status_cd<>'D'"); if (((ProjectType) utype).getParam().get(0).getId() != null) queryResult = jt.query(sql, getParam(), ((ProjectType) utype).getParam().get(0).getId()); } else { String sql = "select * from pm_project_params where id=? " + (showStatus == false ? "" : " and status_cd<>'D'"); if (((ProjectType) utype).getParam().get(0).getId() != null) queryResult = jt.query(sql, getParam(), ((ProjectType) utype).getParam().get(0).getId()); } } else if (utype instanceof GlobalDataType) { String sql = "select * from pm_global_params where id=? " + (showStatus == false ? "" : " and status_cd<>'D'"); if (((GlobalDataType) utype).getParam().get(0).getId() != null) queryResult = jt.query(sql, getGlobal(), ((GlobalDataType) utype).getParam().get(0).getId()); } else if (utype instanceof ApprovalType) { String sql = "select * from pm_approval_params where id=? " + (showStatus == false ? "" : " and status_cd<>'D'"); if (((ApprovalType) utype).getParam().get(0).getId() != null) queryResult = jt.query(sql, getParam(), ((UserType) utype).getParam().get(0).getId()); } else if (utype instanceof UserType) { String sql = "select * from pm_user_params where id=? " + (showStatus == false ? "" : " and status_cd<>'D'"); if (((UserType) utype).getParam().get(0).getId() != null) queryResult = jt.query(sql, getParam(), ((UserType) utype).getParam().get(0).getId()); } else if (utype instanceof CellDataType) { String sql = "select * from pm_cell_params where id=? " + (showStatus == false ? "" : " and status_cd<>'D'"); if (((CellDataType) utype).getParam().get(0).getId() != null) queryResult = jt.query(sql, getParam(), ((CellDataType) utype).getParam().get(0).getId()); } else if (utype instanceof RoleType) { String sql = "select * from pm_project_user_roles where project_id=? and user_id=? " + (showStatus == false ? "" : " and status_cd<>'D'"); queryResult = jt.query(sql, getRole(), ((RoleType) utype).getProjectId(), ((RoleType) utype).getUserName()); } else if (utype instanceof ConfigureType) { if (((ConfigureType) utype).getParam().isEmpty() == false) // || (((ConfigureType) utype).getDomainId()).size() == 0)) { String sql = "select * from pm_hive_params where id=? " + (showStatus == false ? "" : " and status_cd<>'D'"); if (((ConfigureType) utype).getParam().get(0).getId() != null) queryResult = jt.query(sql, getParam(), ((ConfigureType) utype).getParam().get(0).getId()); } else { String sql = "select * from pm_hive_data where active = '1' and domain_id=? " + (showStatus == false ? "" : " and status_cd<>'D'"); if (((ConfigureType) utype).getParam().get(0).getId() != null) queryResult = jt.query(sql, getEnvironment(), ((ConfigureType) utype).getDomainId()); } } } catch (DataAccessException e) { log.error(e.getMessage()); e.printStackTrace(); throw new I2B2DAOException("Database error"); } return queryResult; }
From source file:edu.harvard.i2b2.workplace.dao.FolderDao.java
public void check_addRootNode(String metadataSchema, String userId, ProjectType projectInfo, DBInfoType dbInfo) throws I2B2DAOException, I2B2Exception { String entriesSql = "select c_name from " + metadataSchema + "workplace_access where LOWER(c_user_id) = ? and LOWER(c_group_id) = ?"; ParameterizedRowMapper<String> map = new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { String name = rs.getString("c_name"); return name; }//from w w w . j a v a2s . c o m }; List queryResult = null; try { queryResult = jt.query(entriesSql, map, userId.toLowerCase(), projectInfo.getId().toLowerCase()); } catch (DataAccessException e1) { // TODO Auto-generated catch block log.error(e1.getMessage()); throw new I2B2DAOException("Database Error"); } // log.info("check for root node size = " + queryResult.size()); if (queryResult.size() > 0) return; // else queryResult is empty // need to create a new entry for user //1. get ProtectedAccess status for user if (projectInfo.getRole().size() == 0) { log.error("no role found for this user in project: " + projectInfo.getName()); I2B2Exception e = new I2B2Exception("No role found for user"); throw e; } String protectedAccess = "N"; Iterator it = projectInfo.getRole().iterator(); while (it.hasNext()) { String role = (String) it.next(); if (role.toLowerCase().equals("protected_access")) { protectedAccess = "Y"; break; } } // 2. Get tableCd tableName info String tableSql = "select distinct(c_table_cd), c_table_name from " + metadataSchema + "workplace_access"; ParameterizedRowMapper<String> map2 = new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { String name = "\\\\" + rs.getString("c_table_cd") + "\\" + rs.getString("c_table_name"); return name; } }; queryResult = jt.query(tableSql, map2); String tableInfo = (String) queryResult.get(0); //extract table code and table name String tableCd = StringUtil.getTableCd(tableInfo); String tableName = StringUtil.getIndex(tableInfo); String addSql = "insert into " + metadataSchema + "workplace_access " + "(c_table_cd, c_table_name, c_hlevel, c_protected_access, c_name, c_user_id, c_index, c_visualattributes, c_share_id, c_group_id, c_entry_date) values (?,?,?,?,?,?,?,?,?,?,?)"; int numRootsAdded = -1; String index = StringUtil.generateMessageId(); try { numRootsAdded = jt.update(addSql, tableCd, tableName, 0, protectedAccess, userId, userId, index, "CA", "N", projectInfo.getId(), Calendar.getInstance().getTime()); } catch (DataAccessException e) { log.error("Dao addChild failed"); log.error(e.getMessage()); throw new I2B2DAOException("Data access error ", e); } // log.info(addSql + " " + numRowsAdded); log.debug("Number of roots added: " + numRootsAdded); return; }
From source file:edu.harvard.i2b2.workplace.dao.FolderDao.java
/** * This method finds the search word in the given category. * /*from w ww . j a v a2s . co m*/ * @param returnType * @param projectInfo * @param type - parameters to be used in the select statement. Can have two values core or all * @param parameters * @param category * @param hiddenStr - string to be used in where clause * @param maxString - string to be used in select or where clause * @param searchWord * @param dbInfo * @param protectedAccess * @return * @throws I2B2DAOException * * @author Neha Patel */ private List findInCategory(final FindByChildType returnType, final ProjectType projectInfo, String type, String parameters, String category, String hiddenStr, String maxString, String searchWord, final DBInfoType dbInfo, boolean protectedAccess) throws I2B2DAOException { String metadataSchema = dbInfo.getDb_fullSchema(); setDataSource(dbInfo.getDb_dataSource()); ParameterizedRowMapper<String> map = new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { String name = "\\\\" + rs.getString("c_table_cd") + "\\" + rs.getString("c_table_name"); return name; } }; // Getting tablename where the content is saved from table 'WORKPLACE' List queryResult = null; String resultStr = null; StringBuilder sqlToRetreiveTableNm = new StringBuilder("select distinct c_table_cd, c_table_name from " + metadataSchema + "workplace_access where LOWER(c_user_id) = ? and LOWER(c_group_id) = ?"); if (!protectedAccess) { sqlToRetreiveTableNm.append(" and c_protected_access = ? "); try { queryResult = jt.query(sqlToRetreiveTableNm.toString(), map, category.toLowerCase(), projectInfo.getId().toLowerCase(), "N"); resultStr = (String) queryResult.get(0); } catch (DataAccessException e) { log.error(e.getMessage()); throw new I2B2DAOException( "findWorkplaceByKeyword(): Database Error while accessing workplace_access table with protected access"); } } else { try { queryResult = jt.query(sqlToRetreiveTableNm.toString(), map, category.toLowerCase(), projectInfo.getId().toLowerCase()); resultStr = (String) queryResult.get(0); } catch (DataAccessException e) { log.error(e.getMessage()); throw new I2B2DAOException( "findWorkplaceByKeyword(): Database Error while accessing workplace_access table"); } } String tableCd = StringUtil.getTableCd(resultStr); String tableName = StringUtil.getIndex(resultStr); StringBuilder sql = new StringBuilder("select " + parameters + " from " + metadataSchema + tableName + " where LOWER(c_user_id) = ? and LOWER(c_group_id) = ? and LOWER(c_name) like ? and (c_status_cd != 'D' or c_status_cd is null) "); sql.append(hiddenStr + maxString); ParameterizedRowMapper<FolderType> mapper = getMapper(type, returnType.isBlob(), tableCd, dbInfo.getDb_serverType()); /* * commenting out protectedAcess code from workplace table for now * if (!protectedAccess){ sql.append(" and (c_protected_access != 'Y' or c_protected_access is null) "); } */ sql.append(" order by c_name "); // Executing the query to find the workplace content with the given name queryResult = null; try { queryResult = jt.query(sql.toString(), mapper, category.toLowerCase(), projectInfo.getId().toLowerCase(), searchWord); } catch (DataAccessException e) { log.error(e.getMessage()); log.error("findWorkplaceByKeyword(): Database Error while accessing workplace table"); throw new I2B2DAOException("findWorkplaceByKeyword(): Database Error while accessing workplace table"); } log.debug("result size = " + queryResult.size()); return queryResult; }
From source file:edu.harvard.i2b2.workplace.dao.FolderDao.java
/** * This method searches for the word in the whole project. If the user has a manager role then it searches in the whole project * if the user doesn't have manager role then it searches with the condition of userid or share = Y * /*from ww w . jav a 2 s .c o m*/ * @param returnType * @param projectInfo * @param type * @param parameters * @param hiddenStr * @param maxString * @param searchWord * @param protectedAccess * @param dbInfo * @param userId * @return * @throws DataAccessException * @throws I2B2Exception * * @author Neha Patel */ private List findInAll(final FindByChildType returnType, final ProjectType projectInfo, String type, String parameters, String hiddenStr, String maxString, String searchWord, boolean protectedAccess, final DBInfoType dbInfo, final String userId) throws DataAccessException, I2B2Exception { // Check if user is a manager boolean managerRole = false; for (String param : projectInfo.getRole()) { if (param.equalsIgnoreCase("manager")) { managerRole = true; break; } } String metadataSchema = dbInfo.getDb_fullSchema(); setDataSource(dbInfo.getDb_dataSource()); ParameterizedRowMapper<String> map = new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { String name = "\\\\" + rs.getString("c_table_cd") + "\\" + rs.getString("c_table_name"); return name; } }; // Getting tablename where the content is saved from table 'WORKPLACE' List queryResult = null; String resultStr = null; StringBuilder sqlToRetreiveTableNm = new StringBuilder( "select distinct c_table_cd, c_table_name from " + metadataSchema + "workplace_access where "); // if user is a manager then search in the whole project if (managerRole) { sqlToRetreiveTableNm.append("LOWER(c_group_id) = ? "); } else { // if user is not a manager then user should be able to search only in his folder or shared folder of the project sqlToRetreiveTableNm.append( "(LOWER(c_user_id) = ? and LOWER(c_group_id) = ?) or (LOWER(c_group_id) = ? and c_share_id = 'Y') "); } if (!protectedAccess) { sqlToRetreiveTableNm.append(" and (c_protected_access = 'N' or c_protected_access is null) "); } try { if (managerRole) { queryResult = jt.query(sqlToRetreiveTableNm.toString(), map, projectInfo.getId().toLowerCase()); } else { queryResult = jt.query(sqlToRetreiveTableNm.toString(), map, userId.toLowerCase(), projectInfo.getId().toLowerCase(), projectInfo.getId().toLowerCase()); } resultStr = (String) queryResult.get(0); } catch (DataAccessException e) { log.error(e.getMessage()); throw new I2B2DAOException( "findWorkplaceByKeyword(): Database Error while accessing workplace_access table with protected access"); } String tableCd = ""; String tableName = ""; List returnResult = null; // Run the query for each tablename. There could be more than one table where workplace content is stored if (queryResult != null && !queryResult.isEmpty()) { Iterator itr = queryResult.iterator(); while (itr.hasNext()) { resultStr = (String) itr.next(); tableCd = StringUtil.getTableCd(resultStr); tableName = StringUtil.getIndex(resultStr); StringBuilder sql = new StringBuilder("select " + parameters + " from " + metadataSchema + tableName + " where LOWER(c_name) like ? and (c_status_cd != 'D' or c_status_cd is null) "); if (managerRole) { sql.append("and LOWER(c_group_id) = ? "); } else { sql.append( "and ((LOWER(c_user_id) = ? and LOWER(c_group_id) = ?) or (LOWER(c_group_id) = ? and c_share_id = 'Y')) "); } sql.append(hiddenStr + maxString); ParameterizedRowMapper<FolderType> mapper = getMapper(type, returnType.isBlob(), tableCd, dbInfo.getDb_serverType()); /* * commenting out protectedAcess code from workplace table for now * if (!protectedAccess){ sql.append(" and (c_protected_access != 'Y' or c_protected_access is null) "); } */ sql.append(" order by c_name "); // Executing the query to find the workplace content with the given name List workplaceResult = null; try { if (managerRole) { workplaceResult = jt.query(sql.toString(), mapper, searchWord, projectInfo.getId().toLowerCase()); } else { workplaceResult = jt.query(sql.toString(), mapper, searchWord, userId.toLowerCase(), projectInfo.getId().toLowerCase(), projectInfo.getId().toLowerCase()); } } catch (DataAccessException e) { log.error(e.getMessage()); log.error("findWorkplaceByKeyword(): Database Error while accessing workplace table"); throw new I2B2DAOException( "findWorkplaceByKeyword(): Database Error while accessing workplace table"); } if (returnResult == null) { returnResult = workplaceResult; } else { returnResult.addAll(workplaceResult); } } // end while (itr.hasNext()) } log.debug("result size = " + returnResult.size()); return returnResult; }
From source file:edu.harvard.i2b2.workplace.dao.FolderDao.java
/** * This method determines if the given category(workplace root folder name) is shared or not by * checking c_share_id parameter in workplace_access table * //from www . j a va 2s. c o m * @param category - the root folder name which is in question if its shared or not * @param projectInfo * @param dbInfo * @return * @throws DataAccessException * @throws I2B2Exception * * @author Neha Patel */ public boolean isShared(String category, final ProjectType projectInfo, final DBInfoType dbInfo) throws DataAccessException, I2B2Exception { boolean isSharedBool = false; String metadataSchema = dbInfo.getDb_fullSchema(); setDataSource(dbInfo.getDb_dataSource()); ParameterizedRowMapper<String> map = new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { String name = rs.getString("c_share_id"); return name; } }; // Getting column 'c_share_id' to check if the given category/folder is shared List queryResult = null; String resultStr = ""; String sqlForCheckingShared = "select c_share_id from " + metadataSchema + "workplace_access where LOWER(c_user_id) = ? and LOWER(c_group_id) = ? and (c_status_cd != 'D' or c_status_cd is null)"; try { queryResult = jt.query(sqlForCheckingShared.toString(), map, category.toLowerCase(), projectInfo.getId().toLowerCase()); if (queryResult != null && !queryResult.isEmpty()) { resultStr = (String) queryResult.get(0); } } catch (DataAccessException e) { log.error(e.getMessage()); throw new I2B2DAOException("isShared(): Database Error while accessing workplace_access table"); } if (resultStr != null && resultStr.toUpperCase().trim().equals("Y")) { isSharedBool = true; } else isSharedBool = false; return isSharedBool; }
From source file:edu.harvard.i2b2.workplace.dao.FolderDao.java
/** * @param numRowsSet/*from w w w .j av a 2s .c o m*/ * @param metadataSchema * @param tableName * @param indexStr * @param protectedAccVal * @return * @throws I2B2DAOException * * @author Neha Patel */ private int updateProtectedAccess(String metadataSchema, String tableName, String columnName, String indexStr, String protectedAccVal) throws I2B2DAOException { String updateSql = "update " + metadataSchema + tableName + " set c_protected_access = ? where " + columnName + " in ( " + indexStr + " )"; int numRowsSet = -1; try { numRowsSet = jt.update(updateSql, protectedAccVal); } catch (DataAccessException e) { log.error("Dao updateProtectedAccess failed"); log.error(e.getMessage()); throw new I2B2DAOException("Data access error ", e); } return numRowsSet; }
From source file:edu.harvard.i2b2.workplace.dao.FolderDao.java
private void checkForChildrenDeletion(String nodeIndex, String tableName, String metadataSchema) throws DataAccessException { // mark children for deletion String updateSql = " update " + metadataSchema + tableName + " set c_change_date = ?, c_status_cd = 'D' where c_parent_index = ? "; int numChildrenDeleted = -1; try {//from w ww .j a va 2 s . c om // log.info(sql + " " + w_index); numChildrenDeleted = jt.update(updateSql, Calendar.getInstance().getTime(), nodeIndex); } catch (DataAccessException e) { log.error("Dao deleteChild failed"); log.error(e.getMessage()); throw e; } log.debug("Number of children deleted: " + numChildrenDeleted); // look for children that are folders String folderSql = "select c_index from " + metadataSchema + tableName + " where c_parent_index = ? and c_visualattributes like 'F%' "; ParameterizedRowMapper<String> map = new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { String index = (rs.getString("c_index")); return index; } }; List folders = null; try { folders = jt.query(folderSql, map, nodeIndex); } catch (DataAccessException e) { log.error(e.getMessage()); throw e; } // recursively check folders for children to delete if (folders != null) { Iterator it = folders.iterator(); while (it.hasNext()) { String folderIndex = (String) it.next(); checkForChildrenDeletion(folderIndex, tableName, metadataSchema); } } }
From source file:edu.harvard.i2b2.workplace.dao.WorkplaceDbDao.java
public List<DBInfoType> getDbLookupByHiveOwner(String domainId, String ownerId) throws I2B2Exception, I2B2DAOException { String metadataSchema = getMetadataSchema(); String sql = "select * from " + metadataSchema + "work_db_lookup where LOWER(c_domain_id) = ? and c_project_path = ? and (LOWER(c_owner_id) = ? or c_owner_id ='@') order by c_project_path"; String projectId = "@"; // log.info(sql + domainId + projectId + ownerId); List queryResult = null;/*from w w w. j a v a2 s. c o m*/ try { queryResult = jt.query(sql, getMapper(), domainId.toLowerCase(), projectId, ownerId.toLowerCase()); } catch (DataAccessException e) { log.error(e.getMessage()); throw new I2B2DAOException("Database error"); } return queryResult; // List<DBInfoType> dataSourceLookupList = // this.query(sql, new Object[]{domainId,projectId,ownerId}, new mapper()); // return dataSourceLookupList; }
From source file:edu.harvard.i2b2.workplace.dao.WorkplaceDbDao.java
@SuppressWarnings("unchecked") public List<DBInfoType> getDbLookupByHiveProjectOwner(String domainId, String projectId, String ownerId) throws I2B2Exception, I2B2DAOException { String metadataSchema = getMetadataSchema(); String sql = "select * from " + metadataSchema + "work_db_lookup where LOWER(c_domain_id) = ? and LOWER(c_project_path) like ? and (LOWER(c_owner_id) =? or c_owner_id = '@') order by c_project_path"; // desc c_owner_id desc"; // List<DBInfoType> dataSourceLookupList = this.query(sql, new Object[]{domainId,projectId+"%",ownerId},new int[]{Types.VARCHAR,Types.VARCHAR,Types.VARCHAR},new mapper() ); // return dataSourceLookupList; // log.info(sql + domainId + projectId + ownerId); List queryResult = null;//from w w w . j ava2 s. c o m try { queryResult = jt.query(sql, getMapper(), domainId.toLowerCase(), projectId.toLowerCase(), ownerId.toLowerCase()); } catch (DataAccessException e) { log.error(e.getMessage()); throw new I2B2DAOException("Database error"); } return queryResult; }
From source file:edu.jhuapl.openessence.datasource.jdbc.entry.JdbcOeDataEntrySource.java
/** * Executes UPDATE SQL Statment using Spring's JdbcTemplate. * * @param tablename table to insert values into * @param replRecord use values of replacement record within the UPDATE statement * @param pkIds_ValuesMap maps dimensionID to the value. In this case, the dimensions will correspond to PK columns *///ww w. j a v a 2s . c o m private void editableUpdateStatement(String tablename, TableAwareQueryRecord replRecord, Map<String, Object> pkIds_ValuesMap) throws OeDataSourceAccessException { try { jdbcTemplate .update(new MultiTableUpdatePreparedStatementCreator(tablename, replRecord, pkIds_ValuesMap)); } catch (DataAccessException e) { if (e.getCause() instanceof UpdateException) { log.info(e.getMessage()); } else { throw new OeDataSourceAccessException(e); } } }