Search in sources :

Example 41 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.

the class PerunNotifObjectDaoImpl method isObjectRelation.

@Override
public boolean isObjectRelation(int templateId, Integer objectId) {
    logger.debug("IsObjectRelation for templateId: {}, objectId: {}", Arrays.asList(templateId, objectId));
    try {
        SqlRowSet rowSet = this.getJdbcTemplate().queryForRowSet("select * from pn_regex_object where regex_id = ? AND object_id = ?", templateId, objectId);
        logger.debug("Relation between templateId: {} and objectId: {}, found.", Arrays.asList(templateId, objectId));
        return rowSet.next();
    } catch (EmptyResultDataAccessException ex) {
        //This exception signals empty row
        logger.debug("Relation between templateId: {}, and objectId: {}, not found", Arrays.asList(templateId, objectId));
        return false;
    }
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 42 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.

the class PerunNotifRegexDaoImpl method getPerunNotifRegexById.

@Override
public PerunNotifRegex getPerunNotifRegexById(int id) throws InternalErrorException {
    logger.debug("Loading regex from db by id: {}", id);
    PerunNotifRegex regex = null;
    try {
        regex = this.getJdbcTemplate().queryForObject("SELECT * from pn_regex where id = ?", new Object[] { id }, PerunNotifRegex.PERUN_NOTIF_REGEX);
    } catch (EmptyResultDataAccessException ex) {
        logger.debug("Regex with id: {}, not found.", id);
        return null;
    }
    logger.debug("Regex with id: {}, loaded from db. Loading objects.", id);
    List<PerunNotifObject> objects = this.getJdbcTemplate().query("SELECT * from pn_object object JOIN pn_regex_object bind ON object.id = bind.object_id WHERE bind.regex_id = ?", new Object[] { regex.getId() }, PerunNotifObject.PERUN_NOTIF_OBJECT);
    regex.addObjects(objects);
    logger.debug("Objects loaded result: {}", regex);
    return regex;
}
Also used : PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 43 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.

the class PerunNotifTemplateDaoImpl method getPerunNotifTemplateById.

@Override
public PerunNotifTemplate getPerunNotifTemplateById(int id) throws InternalErrorException {
    PerunNotifTemplate template = null;
    try {
        template = this.getJdbcTemplate().queryForObject("SELECT * from pn_template where id = ?", new Object[] { id }, PerunNotifTemplate.PERUN_NOTIF_TEMPLATE);
    } catch (EmptyResultDataAccessException ex) {
        //This exception is thrown when object is not found
        return null;
    }
    Set<PerunNotifRegex> regexes = perunNotifRegexDao.getPerunNotifRegexForTemplateId(template.getId());
    template.setMatchingRegexs(regexes);
    List<PerunNotifReceiver> perunNotifReceiver = this.getJdbcTemplate().query("SELECT * from pn_receiver where template_id = ?", new Object[] { template.getId() }, PerunNotifReceiver.PERUN_NOTIF_RECEIVER);
    template.setReceivers(perunNotifReceiver);
    List<PerunNotifTemplateMessage> perunNotifTemplateMessages = this.getJdbcTemplate().query("SELECT * from pn_template_message where template_id = ?", new Object[] { template.getId() }, PerunNotifTemplateMessage.PERUN_NOTIF_TEMPLATE_MESSAGE_ROW_MAPPER);
    template.setPerunNotifTemplateMessages(perunNotifTemplateMessages);
    return template;
}
Also used : PerunNotifTemplate(cz.metacentrum.perun.notif.entities.PerunNotifTemplate) PerunNotifTemplateMessage(cz.metacentrum.perun.notif.entities.PerunNotifTemplateMessage) PerunNotifReceiver(cz.metacentrum.perun.notif.entities.PerunNotifReceiver) PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 44 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project bamboobsc by billchen198318.

the class SysMessageUtil method get.

public static String get(String code) {
    if (code == null || "".equals(code)) {
        return "";
    }
    if (sysMsgMap.get(code) != null) {
        return sysMsgMap.get(code);
    }
    init();
    if (jdbcTemplate == null) {
        return "";
    }
    String message = null;
    TbSysCode sysCode = new TbSysCode();
    sysCode.setCode(code);
    Map<String, Object> queryMap = getQuery(sysCode);
    if (queryMap == null) {
        return "";
    }
    try {
        message = jdbcTemplate.queryForObject(((String) queryMap.get(SqlGenerateUtil.RETURN_SQL)), (Object[]) queryMap.get(SqlGenerateUtil.RETURN_PARAMS), String.class);
        if (message != null) {
            sysMsgMap.put(code, message);
        }
    } catch (EmptyResultDataAccessException eda) {
        System.out.println(eda.getMessage().toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return message == null ? code : message;
}
Also used : TbSysCode(com.netsteadfast.greenstep.po.hbm.TbSysCode) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 45 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project spring-data-jdbc by spring-projects.

the class JdbcRepositoryQuery method execute.

@Override
public Object execute(Object[] objects) {
    String query = determineQuery();
    MapSqlParameterSource parameters = bindParameters(objects);
    if (queryMethod.isModifyingQuery()) {
        int updatedCount = context.getTemplate().update(query, parameters);
        Class<?> returnedObjectType = queryMethod.getReturnedObjectType();
        return (returnedObjectType == boolean.class || returnedObjectType == Boolean.class) ? updatedCount != 0 : updatedCount;
    }
    if (queryMethod.isCollectionQuery() || queryMethod.isStreamQuery()) {
        return context.getTemplate().query(query, parameters, rowMapper);
    }
    try {
        return context.getTemplate().queryForObject(query, parameters, rowMapper);
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Aggregations

EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)47 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)20 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)19 Attribute (cz.metacentrum.perun.core.api.Attribute)10 ConsistencyErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException)10 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)10 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)9 ArrayList (java.util.ArrayList)9 User (cz.metacentrum.perun.core.api.User)6 SQLException (java.sql.SQLException)6 Group (cz.metacentrum.perun.core.api.Group)5 HashSet (java.util.HashSet)5 ResultSet (java.sql.ResultSet)4 RowMapper (org.springframework.jdbc.core.RowMapper)4 Member (cz.metacentrum.perun.core.api.Member)3 User (com.mapia.domain.User)2 UserMetadataServiceException (com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException)2 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)2 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)2 PerunNotifObject (cz.metacentrum.perun.notif.entities.PerunNotifObject)2