Search in sources :

Example 36 with EmptyResultDataAccessException

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

the class AttributesManagerImpl method getAttributes.

public List<Attribute> getAttributes(PerunSession sess, UserExtSource ues, List<String> attrNames) throws InternalErrorException {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("uesId", ues.getId());
    parameters.addValue("nSC", AttributesManager.NS_UES_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_UES_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_UES_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_UES_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("ues") + " from attr_names " + "left join user_ext_source_attr_values ues on id=ues.attr_id and ues_id=:uesId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, ues));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<Attribute>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 37 with EmptyResultDataAccessException

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

the class AttributesManagerImpl method getAttributes.

public List<Attribute> getAttributes(PerunSession sess, Vo vo, List<String> attrNames) throws InternalErrorException {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("vId", vo.getId());
    parameters.addValue("nSC", AttributesManager.NS_VO_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_VO_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_VO_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_VO_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("vot") + " from attr_names " + "left join vo_attr_values vot on id=vot.attr_id and vo_id=:vId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, vo));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<Attribute>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 38 with EmptyResultDataAccessException

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

the class DatabaseManagerImpl method updateDatabaseVersion.

public void updateDatabaseVersion(List<DBVersion> dbVersions) throws InternalErrorException {
    Collections.reverse(dbVersions);
    for (DBVersion v : dbVersions) {
        log.debug("Executing update commands of version " + v.getVersion());
        List<String> successfulCommands = new ArrayList<>();
        for (String c : v.getCommands()) {
            try {
                jdbc.execute(c);
                log.debug("Command executed: " + c);
                successfulCommands.add(c);
            } catch (EmptyResultDataAccessException ex) {
                log.error("Update unsuccessful. All versions before " + v.getVersion() + " were successfully executed. " + "Error executing command in version " + v.getVersion() + ": " + c, ex);
                log.error("Successful commands from " + v.getVersion() + ": " + successfulCommands);
                throw new ConsistencyErrorException("Update unsuccessful. Error executing command in version " + v.getVersion() + ": " + c, ex);
            } catch (RuntimeException ex) {
                log.error("Update unsuccessful. All versions before " + v.getVersion() + " were successfully executed. " + "Error executing command in version " + v.getVersion() + ": " + c, ex);
                log.error("Successful commands from " + v.getVersion() + ": " + successfulCommands);
                throw new InternalErrorException("Update unsuccessful. Error executing command in version " + v.getVersion() + ": " + c, ex);
            }
        }
    }
}
Also used : DBVersion(cz.metacentrum.perun.core.api.DBVersion) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) ArrayList(java.util.ArrayList) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 39 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class UserRepository method findUserByNickname.

public User findUserByNickname(String nickname) {
    String query = "SELECT * FROM User WHERE nickname = ?";
    List<User> resultUser;
    try {
        resultUser = jdbcTemplate.query(query, (rs, rowNum) -> {
            User user = new User();
            user.setId(rs.getLong("id"));
            user.setEmail(rs.getString("email"));
            user.setPassword(rs.getString("password"));
            user.setNickname(rs.getString("nickname"));
            return user;
        }, nickname);
    } catch (EmptyResultDataAccessException e) {
        log.error(e.getMessage());
        return null;
    }
    return resultUser.size() > 0 ? resultUser.get(0) : null;
}
Also used : List(java.util.List) User(com.mapia.domain.User) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Repository(org.springframework.stereotype.Repository) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) User(com.mapia.domain.User) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 40 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)

Aggregations

EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)40 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)20 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)17 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 Group (cz.metacentrum.perun.core.api.Group)5 HashSet (java.util.HashSet)5 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 RowMapper (org.springframework.jdbc.core.RowMapper)4 Member (cz.metacentrum.perun.core.api.Member)3 User (com.mapia.domain.User)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 PerunNotifRegex (cz.metacentrum.perun.notif.entities.PerunNotifRegex)2