use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class MailManagerImpl method getMailByParams.
/**
* Retrieve mail definition from db by params.
* Mail contains all texts.
* If mail not exists, or no texts exists null is returned.
*
* @param formId relation to VO form
* @param appType application type
* @param mailType mail type
* @return mail if definition exists or null
*/
private ApplicationMail getMailByParams(Integer formId, AppType appType, MailType mailType) {
ApplicationMail mail;
// We want to use the initial notifications for the embedded applications
if (appType == AppType.EMBEDDED) {
appType = AppType.INITIAL;
}
// get mail def
try {
List<ApplicationMail> mails = jdbc.query(MAILS_SELECT_BY_PARAMS, (resultSet, arg1) -> new ApplicationMail(resultSet.getInt("id"), AppType.valueOf(resultSet.getString("app_type")), resultSet.getInt("form_id"), MailType.valueOf(resultSet.getString("mail_type")), resultSet.getBoolean("send")), formId, appType.toString(), mailType.toString());
// set
if (mails.size() != 1) {
log.error("[MAIL MANAGER] Wrong number of mail definitions returned by unique params, expected 1 but was: {}", mails.size());
return null;
}
mail = mails.get(0);
} catch (EmptyResultDataAccessException ex) {
return null;
}
List<MailText> texts;
try {
texts = jdbc.query(MAIL_TEXTS_SELECT_BY_MAIL_ID, (resultSet, arg1) -> new MailText(new Locale(resultSet.getString("locale")), resultSet.getString("subject"), resultSet.getString("text")), mail.getId());
} catch (EmptyResultDataAccessException ex) {
// if no texts it's error"HmacSHA256"
log.error("[MAIL MANAGER] Mail do not contains any text message.", ex);
return null;
}
texts.forEach(mt -> mail.getMessage().put(mt.getLocale(), mt));
return mail;
}
use of org.springframework.dao.EmptyResultDataAccessException in project SSM by Intel-bigdata.
the class TestBackUpInfoDao method testDelete.
@Test
public void testDelete() {
backUpInfoDao.delete(1L);
BackUpInfo[] backUpInfos = new BackUpInfo[2];
backUpInfos[0] = new BackUpInfo(1, "test", "test", 1);
backUpInfos[1] = new BackUpInfo(2, "test", "test", 1);
backUpInfoDao.insert(backUpInfos);
backUpInfoDao.delete(1L);
Assert.assertTrue(backUpInfoDao.getByRid(2).equals(backUpInfos[1]));
try {
backUpInfoDao.getByRid(1);
} catch (EmptyResultDataAccessException e) {
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project SSM by Intel-bigdata.
the class MetaStore method getHotFiles.
public List<FileAccessInfo> getHotFiles(List<AccessCountTable> tables, int topNum) throws MetaStoreException {
Iterator<AccessCountTable> tableIterator = tables.iterator();
if (tableIterator.hasNext()) {
try {
Map<Long, Integer> accessCounts = accessCountDao.getHotFiles(tables, topNum);
if (accessCounts.size() == 0) {
return new ArrayList<>();
}
Map<Long, String> idToPath = getFilePaths(accessCounts.keySet());
List<FileAccessInfo> result = new ArrayList<>();
for (Map.Entry<Long, Integer> entry : accessCounts.entrySet()) {
Long fid = entry.getKey();
if (idToPath.containsKey(fid) && entry.getValue() > 0) {
result.add(new FileAccessInfo(fid, idToPath.get(fid), entry.getValue()));
}
}
return result;
} catch (EmptyResultDataAccessException e) {
return new ArrayList<>();
} catch (Exception e) {
throw new MetaStoreException(e);
} finally {
for (AccessCountTable accessCountTable : tables) {
if (accessCountTable.isEphemeral()) {
this.dropTable(accessCountTable.getTableName());
}
}
}
} else {
return new ArrayList<>();
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project SSM by Intel-bigdata.
the class MetaStore method getFileState.
/**
* Get FileState of the given path.
*
* @param path
* @return
* @throws MetaStoreException
*/
public FileState getFileState(String path) throws MetaStoreException {
FileState fileState;
try {
fileState = fileStateDao.getByPath(path);
// Fetch info from corresponding table to regenerate a specific file state
switch(fileState.getFileType()) {
case NORMAL:
fileState = new NormalFileState(path);
break;
case COMPACT:
fileState = smallFileDao.getFileStateByPath(path);
break;
case COMPRESSION:
CompressionFileState compressionFileState = getCompressionInfo(path);
if (compressionFileState != null) {
compressionFileState.setFileStage(fileState.getFileStage());
fileState = compressionFileState;
}
break;
case S3:
fileState = new S3FileState(path);
break;
default:
}
} catch (EmptyResultDataAccessException e1) {
fileState = new NormalFileState(path);
} catch (Exception e2) {
throw new MetaStoreException(e2);
}
return fileState;
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class AttributesManagerImpl method getAttributes.
@Override
public List<Attribute> getAttributes(PerunSession sess, Host host, List<String> attrNames) {
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("hId", host.getId());
parameters.addValue("nSC", AttributesManager.NS_HOST_ATTR_CORE);
parameters.addValue("nSO", AttributesManager.NS_HOST_ATTR_OPT);
parameters.addValue("nSD", AttributesManager.NS_HOST_ATTR_DEF);
parameters.addValue("nSV", AttributesManager.NS_HOST_ATTR_VIRT);
parameters.addValue("attrNames", attrNames);
try {
return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("host_attr_values") + " from attr_names " + "left join host_attr_values on id=attr_id and host_id=:hId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new SingleBeanAttributeRowMapper<>(sess, this, host));
} catch (EmptyResultDataAccessException ex) {
return new ArrayList<>();
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
Aggregations