List of usage examples for org.springframework.dao DataAccessException printStackTrace
public void printStackTrace()
From source file:com.thinkbiganalytics.hive.service.HiveService.java
public QueryResult query(String query) throws DataAccessException { final DefaultQueryResult queryResult = new DefaultQueryResult(query); final List<QueryResultColumn> columns = new ArrayList<>(); final Map<String, Integer> displayNameMap = new HashMap<>(); if (query != null && !query.toLowerCase().startsWith("show")) { query = safeQuery(query);/*from w ww .j a v a 2 s .co m*/ } try { // Setting in order to query complex formats like parquet jdbcTemplate.execute("set hive.optimize.index.filter=false"); jdbcTemplate.query(query, new RowMapper<Map<String, Object>>() { @Override public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { if (columns.isEmpty()) { ResultSetMetaData rsMetaData = rs.getMetaData(); for (int i = 1; i <= rsMetaData.getColumnCount(); i++) { String colName = rsMetaData.getColumnName(i); DefaultQueryResultColumn column = new DefaultQueryResultColumn(); column.setField(rsMetaData.getColumnName(i)); String displayName = rsMetaData.getColumnLabel(i); column.setHiveColumnLabel(displayName); //remove the table name if it exists displayName = StringUtils.substringAfterLast(displayName, "."); Integer count = 0; if (displayNameMap.containsKey(displayName)) { count = displayNameMap.get(displayName); count++; } displayNameMap.put(displayName, count); column.setDisplayName(displayName + "" + (count > 0 ? count : "")); column.setTableName(StringUtils.substringAfterLast(rsMetaData.getColumnName(i), ".")); column.setDataType(ParserHelper.sqlTypeToHiveType(rsMetaData.getColumnType(i))); columns.add(column); } queryResult.setColumns(columns); } Map<String, Object> row = new LinkedHashMap<>(); for (QueryResultColumn column : columns) { row.put(column.getDisplayName(), rs.getObject(column.getHiveColumnLabel())); } queryResult.addRow(row); return row; } }); } catch (DataAccessException dae) { dae.printStackTrace(); throw dae; } return queryResult; }
From source file:edu.duke.cabig.c3pr.dao.StudyDao.java
private void updateDatabaseWithRemoteStudies(List<Study> remoteStudies) { try {//from w ww .j a va 2 s .c om for (Study remoteStudy : remoteStudies) { if (remoteStudy != null) { RemoteStudy remoteStudyTemp = (RemoteStudy) remoteStudy; Study studyFromDatabase = getByExternalIdentifier(remoteStudyTemp.getExternalId()); //If studyFromDatabase is null then save else it already exists as a remoteStudy. if (studyFromDatabase == null) { //save the associated HealthcareSites first. List<HealthcareSite> healthcareSiteList = new ArrayList<HealthcareSite>(); for (StudyOrganization studyOrganization : remoteStudyTemp.getStudyOrganizations()) { if (studyOrganization.getHealthcareSite() instanceof RemoteHealthcareSite) { healthcareSiteList.add(studyOrganization.getHealthcareSite()); } } healthcareSiteDao.updateDatabaseWithRemoteHealthcareSites(healthcareSiteList); HealthcareSite healthcareSite = null; //Update the studyInv and the hcsi to point to the saved hcs. for (int i = 0; i < remoteStudyTemp.getStudyOrganizations().size(); i++) { healthcareSite = remoteStudyTemp.getStudyOrganizations().get(i).getHealthcareSite(); if (healthcareSite instanceof RemoteHealthcareSite) { remoteStudyTemp.getStudyOrganizations().get(i) .setHealthcareSite(healthcareSiteList.get(i)); for (StudyInvestigator studyInvestigator : remoteStudyTemp.getStudyOrganizations() .get(i).getStudyInvestigators()) { studyInvestigator.getHealthcareSiteInvestigator() .setHealthcareSite(healthcareSiteList.get(i)); } } } //save the associated Investigators next. Investigator investigator = null; Investigator savedInvestigator = null; for (StudyOrganization studyOrganization : remoteStudyTemp.getStudyOrganizations()) { for (StudyInvestigator studyInvestigator : studyOrganization.getStudyInvestigators()) { investigator = studyInvestigator.getHealthcareSiteInvestigator().getInvestigator(); if (investigator instanceof RemoteInvestigator) { //this does not save the associated hcsi. It returns the saved Inv with the unsaved hcsi attached to it savedInvestigator = investigatorDao .updateDatabaseWithRemoteContent((RemoteInvestigator) investigator); //Set the saved Investigator in the hcsi. So now the hcsi has the saved hcs and inv in it. studyInvestigator.getHealthcareSiteInvestigator() .setInvestigator(savedInvestigator); HealthcareSiteInvestigator savedHealthcareSiteInvestigator = null; if (studyInvestigator.getHealthcareSiteInvestigator().getId() == null) { savedHealthcareSiteInvestigator = healthcareSiteInvestigatorDao .updateDatabaseWithRemoteContent( studyInvestigator.getHealthcareSiteInvestigator()); if (savedHealthcareSiteInvestigator != null) { studyInvestigator .setHealthcareSiteInvestigator(savedHealthcareSiteInvestigator); } } } } } for (OrganizationAssignedIdentifier organizationAssignedIdentifier : remoteStudyTemp .getOrganizationAssignedIdentifiers()) { if (organizationAssignedIdentifier.getHealthcareSite() == null || organizationAssignedIdentifier.getHealthcareSite().getId() == null) { if (organizationAssignedIdentifier.getType() .equals(OrganizationIdentifierTypeEnum.NCI)) { organizationAssignedIdentifier .setHealthcareSite(healthcareSiteDao.getNCIOrganization()); } else if (organizationAssignedIdentifier.getType() .equals(OrganizationIdentifierTypeEnum.CTEP)) { organizationAssignedIdentifier .setHealthcareSite(healthcareSiteDao.getCTEPOrganization()); } else if (organizationAssignedIdentifier .getHealthcareSite() instanceof RemoteHealthcareSite) { HealthcareSite remoteHealthcareSite = healthcareSiteDao .getByPrimaryIdentifierFromLocal( ((RemoteHealthcareSite) organizationAssignedIdentifier .getHealthcareSite()).getPrimaryIdentifier()); if (remoteHealthcareSite != null) { organizationAssignedIdentifier.setHealthcareSite(remoteHealthcareSite); } } } } for (int i = 0; i < remoteStudyTemp.getOrganizationAssignedIdentifiers().size(); i++) { if (remoteStudyTemp.getOrganizationAssignedIdentifiers().get(i) .getHealthcareSite() == null) { remoteStudyTemp.getOrganizationAssignedIdentifiers().remove(i); } } //TODO: Check to see if it exists as localStudy by using the searchByOrganizationAssignedIdentifier() save(remoteStudyTemp); } else { log.debug("Not saving the study as a study with the external Id :" + remoteStudyTemp.getExternalId() + " already exists in the system."); } getHibernateTemplate().flush(); } else { log.error("Null Remote Study in the list in updateDatabaseWithRemote Content"); } } } catch (DataAccessException e) { e.printStackTrace(); } catch (C3PRBaseRuntimeException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.harvard.i2b2.crc.dao.DblookupDao.java
public List<DblookupType> getDblookup(final SetDblookupType dblookupType) throws DataAccessException, I2B2Exception { String sql = "SELECT * FROM " + dbluTable + " WHERE c_project_path=? AND " + keyOrder; List<DblookupType> queryResult = null; try {// w w w.ja v a2s . c o m queryResult = jt.query(sql, getMapper(), slashSandwich(dblookupType.getProjectPath()), dblookupType.getDomainId(), dblookupType.getOwnerId()); } catch (DataAccessException e) { log.error(e.getMessage()); e.printStackTrace(); throw new I2B2DAOException("Database error"); } return queryResult; }
From source file:edu.harvard.i2b2.crc.dao.DblookupDao.java
public List<DblookupType> getDblookup(String column, String value) throws DataAccessException, I2B2Exception { String sql = "SELECT * FROM " + dbluTable + " WHERE "; String v = value, s = column.toLowerCase(); List<DblookupType> queryResult = null; try {//from ww w .j av a 2s . c o m if (s.equalsIgnoreCase("domain_id")) { sql += keyOrder; queryResult = jt.query(sql, getMapper(), value, userId); } else if (s.equalsIgnoreCase("owner_id")) { sql += keyOrder; queryResult = jt.query(sql, getMapper(), domainId, value); } else { sql += "c_" + column + "=? AND " + keyOrder; if (s.equalsIgnoreCase("project_path")) { v = slashSandwich(value); } else { } queryResult = jt.query(sql, getMapper(), v, domainId, userId); } log.info(sql + "(c_" + column + "=" + v + ", domainId=" + domainId + ", userId=" + userId + ") -- # of entries found: " + queryResult.size()); } catch (DataAccessException e) { log.error(e.getMessage()); e.printStackTrace(); throw new I2B2DAOException("Database error"); } return queryResult; }
From source file:edu.harvard.i2b2.crc.dao.DblookupDao.java
public int deleteDblookup(final DeleteDblookupType dblookupType) throws DataAccessException, I2B2Exception { int numRowsDeleted = 0; String sql = "DELETE FROM " + dbluTable + " WHERE c_project_path=? AND " + key; try {//w w w .j a v a 2s . c o m numRowsDeleted = jt.update(sql, slashSandwich(dblookupType.getProjectPath()), dblookupType.getDomainId(), dblookupType.getOwnerId()); } catch (DataAccessException e) { log.error(e.getMessage()); e.printStackTrace(); throw new I2B2DAOException("Database error"); } return numRowsDeleted; }
From source file:edu.harvard.i2b2.im.dao.DblookupDao.java
public List<DblookupType> getDblookup(final SetDblookupType dblookupType) throws DataAccessException, I2B2Exception { String sql = "SELECT * FROM " + dbluTable + " WHERE c_project_path=? AND " + keyOrder; List<DblookupType> queryResult = null; try {//from w w w. j ava 2s .co m queryResult = jt.query(sql, getMapper(), slashEnd(dblookupType.getProjectPath()), dblookupType.getDomainId(), dblookupType.getOwnerId()); } catch (DataAccessException e) { log.error(e.getMessage()); e.printStackTrace(); throw new I2B2DAOException("Database error"); } return queryResult; }
From source file:edu.harvard.i2b2.im.dao.DblookupDao.java
public List<DblookupType> getDblookup(String column, String value) throws DataAccessException, I2B2Exception { String sql = "SELECT * FROM " + dbluTable + " WHERE "; String v = value, s = column.toLowerCase(); List<DblookupType> queryResult = null; try {/*from ww w. j a v a2s . co m*/ if (s.equalsIgnoreCase("domain_id")) { sql += keyOrder; queryResult = jt.query(sql, getMapper(), value, userId); } else if (s.equalsIgnoreCase("owner_id")) { sql += keyOrder; queryResult = jt.query(sql, getMapper(), domainId, value); } else { sql += "c_" + column + "=? AND " + keyOrder; if (s.equalsIgnoreCase("project_path")) { v = slashEnd(value); } else { } queryResult = jt.query(sql, getMapper(), v, domainId, userId); } log.info(sql + "(c_" + column + "=" + v + ", domainId=" + domainId + ", userId=" + userId + ") -- # of entries found: " + queryResult.size()); } catch (DataAccessException e) { log.error(e.getMessage()); e.printStackTrace(); throw new I2B2DAOException("Database error"); } return queryResult; }
From source file:edu.harvard.i2b2.im.dao.DblookupDao.java
public int deleteDblookup(final DeleteDblookupType dblookupType) throws DataAccessException, I2B2Exception { int numRowsDeleted = 0; String sql = "DELETE FROM " + dbluTable + " WHERE c_project_path=? AND " + key; try {//from w w w . j a v a 2 s. c o m numRowsDeleted = jt.update(sql, slashEnd(dblookupType.getProjectPath()), dblookupType.getDomainId(), dblookupType.getOwnerId()); } catch (DataAccessException e) { log.error(e.getMessage()); e.printStackTrace(); throw new I2B2DAOException("Database error"); } return numRowsDeleted; }
From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java
@SuppressWarnings("unchecked") public List<DBInfoType> getEnvironment(String domainId) throws I2B2Exception, I2B2DAOException { String sql = "select * from pm_hive_data where active='1' and status_cd <> 'D'"; if (domainId != null) sql += " and domain_id = ?"; // log.info(sql + domainId + projectId + ownerId); List<DBInfoType> queryResult = null; try {// w w w . ja v a 2 s . c o m log.debug("Start query"); if (domainId == null) queryResult = jt.query(sql, getEnvironment()); else queryResult = jt.query(sql, getEnvironment(), domainId); log.debug("Query Size: " + queryResult.size()); log.debug("End query"); } catch (DataAccessException e) { log.error(e.getMessage()); e.printStackTrace(); throw new I2B2DAOException("Database error"); } return queryResult; }