Java 类org.springframework.dao.EmptyResultDataAccessException 实例源码

项目:premier-wherehows    文件:DatasetsDAO.java   
public static void getDependencies(
        Long datasetId,
        List<DatasetDependency> depends)
{
    String nativeName = null;
    try
    {
        nativeName = getJdbcTemplate().queryForObject(
                GET_DATASET_NATIVE_NAME,
                String.class,
                datasetId);
    }
    catch (EmptyResultDataAccessException e)
    {
        nativeName = null;
    }

    if (StringUtils.isNotBlank(nativeName))
    {
        getDatasetDependencies("/" + nativeName.replace(".", "/"), 1, 0, depends);
    }

}
项目:premier-wherehows    文件:DatasetsDAO.java   
public static void getReferences(
        Long datasetId,
        List<DatasetDependency> references)
{
    String nativeName = null;
    try
    {
        nativeName = getJdbcTemplate().queryForObject(
                GET_DATASET_NATIVE_NAME,
                String.class,
                datasetId);
    }
    catch (EmptyResultDataAccessException e)
    {
        nativeName = null;
    }

    if (StringUtils.isNotBlank(nativeName))
    {
        getDatasetReferences("/" + nativeName.replace(".", "/"), 1, 0, references);
    }

}
项目:premier-wherehows    文件:DatasetsDAO.java   
public static String getDatasetSchemaTextByVersion(
        Long datasetId, String version)
{
    String schemaText = null;
    try
    {
        schemaText = getJdbcTemplate().queryForObject(
                GET_DATASET_SCHEMA_TEXT_BY_VERSION,
                String.class,
                datasetId, version);
    }
    catch (EmptyResultDataAccessException e)
    {
        schemaText = null;
    }
    return schemaText;
}
项目:wherehowsX    文件:DatasetsDAO.java   
public static void getDependencies(
        Long datasetId,
        List<DatasetDependency> depends)
{
    String nativeName = null;
    try
    {
        nativeName = getJdbcTemplate().queryForObject(
                GET_DATASET_NATIVE_NAME,
                String.class,
                datasetId);
    }
    catch (EmptyResultDataAccessException e)
    {
        nativeName = null;
    }

    if (StringUtils.isNotBlank(nativeName))
    {
        getDatasetDependencies("/" + nativeName.replace(".", "/"), 1, 0, depends);
    }

}
项目:wherehowsX    文件:DatasetsDAO.java   
public static void getReferences(
        Long datasetId,
        List<DatasetDependency> references)
{
    String nativeName = null;
    try
    {
        nativeName = getJdbcTemplate().queryForObject(
                GET_DATASET_NATIVE_NAME,
                String.class,
                datasetId);
    }
    catch (EmptyResultDataAccessException e)
    {
        nativeName = null;
    }

    if (StringUtils.isNotBlank(nativeName))
    {
        getDatasetReferences("/" + nativeName.replace(".", "/"), 1, 0, references);
    }

}
项目:wherehowsX    文件:MetricsDAO.java   
public static Metric getMetricByID(int id, String user)
{
    Integer userId = UserDAO.getUserIDByUserName(user);
    Metric metric = null;
    try
    {
        metric = (Metric)getJdbcTemplate().queryForObject(
                GET_METRIC_BY_ID,
                new MetricRowMapper(),
                    userId,
                id);
    }
    catch(EmptyResultDataAccessException e)
    {
        Logger.error("Metric getMetricByID failed, id = " + id);
        Logger.error("Exception = " + e.getMessage());
    }

    return metric;
}
项目:nifi-registry    文件:DatabaseMetadataService.java   
@Override
public FlowSnapshotEntity getFlowSnapshot(final String flowIdentifier, final Integer version) {
    final String sql =
            "SELECT " +
                    "fs.flow_id, " +
                    "fs.version, " +
                    "fs.created, " +
                    "fs.created_by, " +
                    "fs.comments " +
            "FROM " +
                    "flow_snapshot fs, " +
                    "flow f, " +
                    "bucket_item item " +
            "WHERE " +
                    "item.id = f.id AND " +
                    "f.id = ? AND " +
                    "f.id = fs.flow_id AND " +
                    "fs.version = ?";

    try {
        return jdbcTemplate.queryForObject(sql, new FlowSnapshotEntityRowMapper(),
                flowIdentifier, version);
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
项目:nixmash-blog    文件:GithubJobUI.java   
public long getCurrentGithubId() {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    String sql = "SELECT stat_id FROM github_stats WHERE stat_date = current_date()";
    long statId = -1;
    try {
        statId = jdbcTemplate.queryForObject(sql, Long.class);
    } catch (EmptyResultDataAccessException e) {

        jdbcTemplate.update(
                new PreparedStatementCreator() {
                    String INSERT_SQL = "INSERT INTO github_stats (stat_date) VALUES (current_date())";
                    public PreparedStatement createPreparedStatement(Connection cn) throws SQLException {
                        PreparedStatement ps = cn.prepareStatement(INSERT_SQL, new String[] {"stat_id"});
                        return ps;
                    }
                },
                keyHolder);
        statId = keyHolder.getKey().longValue();

    }
    logger.info("Current GitHub Stats ID: " + statId);
    return statId;
}
项目:nixmash-blog    文件:GitHubTests.java   
@Test
public void githubStatRecordKeyReturned() throws Exception {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    long statId = -1L;
    try {
        statId = jdbcTemplate.queryForObject("SELECT stat_id FROM github_stats WHERE stat_date = '2010-10-10'", Long.class);
    } catch (EmptyResultDataAccessException e) {

        jdbcTemplate.update(
                new PreparedStatementCreator() {
                    String INSERT_SQL = "INSERT INTO github_stats (stat_date) VALUES ('2010-10-10')";

                    public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                        PreparedStatement ps = connection.prepareStatement(INSERT_SQL, new String[]{"stat_id"});
                        return ps;
                    }
                },
                keyHolder);
        statId = keyHolder.getKey().longValue();
    }

    assertThat(statId).isGreaterThan(0);
}
项目:spring-configuration-support    文件:ConfigurationDaoImpl.java   
@Override
public void updateConfigurationValue(Environment env,
                                     String defaultEnvKey,
                                     String key,
                                     String value) throws DataAccessException {
    Map<String, Object> paramMap = new HashMap<>();
    paramMap.put("config_key", key);
    paramMap.put("config_value", value);
    try {
        // check, whether there is a concrete config value
        paramMap.put("config_env", env.getValue());
        namedParameterJdbcTemplate.queryForObject(this.getQuery, paramMap, new ConfigurationValueRowMapper());
    } catch (EmptyResultDataAccessException e) {
        // no... set the default to update
        LOG.trace("no concrete config value, set the default to update", e);
        paramMap.put("config_env", defaultEnvKey);
    }

    namedParameterJdbcTemplate.update(this.updateQuery, paramMap);
}
项目:spring-configuration-support    文件:ConfigurationDaoJdbcImpl.java   
@Override
@Transactional(readOnly = false)
public void updateConfigurationValue(Environment env,
                                     String defaultEnvKey,
                                     String key,
                                     String value) throws DataAccessException {
    Map<String, Object> paramMap = new HashMap<>();
    paramMap.put("config_key", key);
    paramMap.put("config_value", value);
    try {
        // check, whether there is a concrete config value
        paramMap.put("config_env", env.getValue());
        namedParameterJdbcTemplate.queryForObject(this.getQuery, paramMap, new ConfigurationValueRowMapper());
    } catch (EmptyResultDataAccessException e) {
        // no... set the default to update
        LOG.trace("no concrete config value, set the default to update", e);
        paramMap.put("config_env", defaultEnvKey);
    }

    namedParameterJdbcTemplate.update(this.updateQuery, paramMap);
}
项目:org.ops4j.pax.transx    文件:HsqlTest.java   
@Test
public void testSpringLocalTx() throws Exception {
    DataSource ds = wrap(createHsqlDataSource());
    JdbcTemplate jdbc = new JdbcTemplate(ds);
    TransactionTemplate tx = new TransactionTemplate(new DataSourceTransactionManager(ds));

    jdbc.execute(DROP_USER);
    jdbc.execute(CREATE_TABLE_USER);

    tx.execute(ts -> jdbc.update(INSERT_INTO_USER, 1, "user1"));
    User user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
    assertEquals(new User(1, "user1"), user);
    tx.execute(ts -> jdbc.update(DELETE_FROM_USER_BY_ID, 1));

    tx.execute(ts -> {
        int nb = jdbc.update(INSERT_INTO_USER, 1, "user1");
        ts.setRollbackOnly();
        return nb;
    });
    try {
        user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
        fail("Expected a EmptyResultDataAccessException");
    } catch (EmptyResultDataAccessException e) {
        // expected
    }
}
项目:simple-openid-provider    文件:JdbcRefreshTokenStore.java   
@Override
@Transactional
public RefreshTokenContext findByClientIdAndSubject(ClientID clientId, Subject subject) {
    Objects.requireNonNull(clientId, "clientId must not be null");
    Objects.requireNonNull(subject, "subject must not be null");
    try {
        RefreshTokenContext context = this.jdbcOperations.queryForObject(this.statementSelectByClientIdAndSubject,
                refreshTokenContextMapper, clientId.getValue(), subject.getValue());
        if (context.isExpired()) {
            this.jdbcOperations.update(this.statementDeleteByToken,
                    ps -> ps.setString(1, context.getRefreshToken().getValue()));
            return null;
        }
        return context;
    }
    catch (EmptyResultDataAccessException e) {
        return null;
    }
}
项目:siga    文件:UserDaoImpl.java   
@Override
public User findById(Integer id) {

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("id", id);

    String sql = "SELECT * FROM users WHERE id=:id";

    User result = null;
    try {
        result = namedParameterJdbcTemplate.queryForObject(sql, params, new UserMapper());
    } catch (EmptyResultDataAccessException e) {
        // do nothing, return null
    }

    /*
     * User result = namedParameterJdbcTemplate.queryForObject( sql, params,
     * new BeanPropertyRowMapper<User>());
     */

    return result;

}
项目:JavaRestCalculator    文件:SecurityServiceConfiguration.java   
@Autowired
public void registerGlobalAuthentication(AuthenticationManagerBuilder auth) throws Exception {
    LOG.info("Registering global user details service");
    auth.userDetailsService(username -> {
        try {
            BillingUser user = billingDao.loadUser(username);
            return new User(
                    user.getUsername(),
                    user.getPassword(),
                    Collections.singletonList(() -> "AUTH")
            );
        } catch (EmptyResultDataAccessException e) {
            LOG.warn("No such user: " + username);
            throw new UsernameNotFoundException(username);
        }
    });
}
项目:JavaRestCalculator    文件:BillingDao.java   
public BillingUser loadUser(String username) throws EmptyResultDataAccessException {
    LOG.trace("Querying for user " + username);
    return jdbcTemplate.queryForObject(
            "SELECT username, password, enabled FROM billing.users WHERE username = ?",
            new Object[]{username},
            new RowMapper<BillingUser>() {
                @Override
                public BillingUser mapRow(ResultSet rs, int rowNum) throws SQLException {
                    return new BillingUser(
                            rs.getString("username"),
                            rs.getString("password"),
                            rs.getBoolean("enabled")
                    );
                }
            }
    );
}
项目:Spring-Security-Third-Edition    文件:JpaCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(final String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return userRepository.findByEmail(email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:Spring-Security-Third-Edition    文件:JpaCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(final String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return userRepository.findByEmail(email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:Spring-Security-Third-Edition    文件:JpaCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(final String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return userRepository.findByEmail(email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:Spring-Security-Third-Edition    文件:JdbcCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return jdbcOperations.queryForObject(CALENDAR_USER_QUERY + "email = ?", CALENDAR_USER_MAPPER, email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:nakadi-producer-spring-boot-starter    文件:EventLogRepositoryImpl.java   
@Override
public EventLog findOne(Integer id) {
    Map<String, Object> namedParameterMap = new HashMap<>();
    namedParameterMap.put("id", id);
    try {
        return jdbcTemplate.queryForObject(
            "SELECT * FROM nakadi_events.event_log where id = :id",
            namedParameterMap,
            new BeanPropertyRowMapper<>(EventLog.class)
        );
    } catch (EmptyResultDataAccessException ignored) {
        return null;
    }
}
项目:Spring-Security-Third-Edition    文件:JdbcCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return jdbcOperations.queryForObject(CALENDAR_USER_QUERY + "email = ?", CALENDAR_USER_MAPPER, email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:Spring-Security-Third-Edition    文件:JpaCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(final String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return userRepository.findByEmail(email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:Spring-Security-Third-Edition    文件:JpaCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(final String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return userRepository.findByEmail(email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:nifi-registry    文件:DatabaseMetadataService.java   
@Override
public FlowEntity getFlowById(final String flowIdentifier) {
    final String sql = "SELECT * FROM flow f, bucket_item item WHERE f.id = ? AND item.id = f.id";
    try {
        return jdbcTemplate.queryForObject(sql, new FlowEntityRowMapper(), flowIdentifier);
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
项目:Learning-Spring-5.0    文件:BookDAO_JdbcTemplate.java   
@Override
    public Book serachBook(long ISBN) {
        // TODO Auto-generated method stub
        String SEARCH_BOOK = "select * from book where ISBN=?";
        Book book_serached = null;
        try {
            book_serached = jdbcTemplate.queryForObject(SEARCH_BOOK, new Object[] { ISBN }, new RowMapper<Book>() {

                @Override
                public Book mapRow(ResultSet set, int rowNum) throws SQLException {
                    // TODO Auto-generated method stub

                    Book book = new Book();
                    book.setBookName(set.getString("bookName"));
                    book.setAuthor(set.getString("author"));
                    book.setDescription(set.getString("description"));
                    book.setISBN(set.getLong("ISBN"));
                    book.setPrice(set.getInt("price"));
                    book.setPublication(set.getString("publication"));
                    return book;
                }
            });
            return book_serached;
        } catch (EmptyResultDataAccessException ex) {
//          ex.printStackTrace();
            return new Book();
        }
    }
项目:Spring-Security-Third-Edition    文件:JpaCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(final String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return userRepository.findByEmail(email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:project-template    文件:ProductServiceImpl.java   
@Override
public ProductDto get(long id) {
    log.info("get service");
    Product product = repository.findOne(id)
            .orElseThrow(() -> new EmptyResultDataAccessException("No product found with id: " + id, 1));
    return mapper.map(product, ProductDto.class);
}
项目:Spring-Security-Third-Edition    文件:JpaCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(final String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return userRepository.findByEmail(email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:Spring-Security-Third-Edition    文件:JdbcCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return jdbcOperations.queryForObject(CALENDAR_USER_QUERY + "email = ?", CALENDAR_USER_MAPPER, email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:Spring-Security-Third-Edition    文件:JpaCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(final String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return userRepository.findByEmail(email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:wherehowsX    文件:DatasetInfoDao.java   
public static void updateDatasetCaseSensitivity(JsonNode root)
    throws Exception {
  final JsonNode properties = root.path("datasetProperties");
  if (properties.isMissingNode() || properties.isNull()) {
    throw new IllegalArgumentException(
        "Dataset properties update fail, missing necessary fields: " + root.toString());
  }
  final JsonNode caseSensitivity = properties.path("caseSensitivity");
  if (caseSensitivity.isMissingNode() || caseSensitivity.isNull()) {
    throw new IllegalArgumentException(
        "Dataset properties update fail, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  ObjectMapper om = new ObjectMapper();

  DatasetCaseSensitiveRecord record = om.convertValue(caseSensitivity, DatasetCaseSensitiveRecord.class);
  record.setDatasetId(datasetId);
  record.setDatasetUrn(urn);
  record.setModifiedTime(System.currentTimeMillis() / 1000);
  try {
    DatasetCaseSensitiveRecord result = getDatasetCaseSensitivityByDatasetId(datasetId);
    String[] columns = record.getDbColumnNames();
    Object[] columnValues = record.getAllValuesToString();
    String[] conditions = {"dataset_id"};
    Object[] conditionValues = new Object[]{datasetId};
    CASE_SENSITIVE_WRITER.update(columns, columnValues, conditions, conditionValues);
  } catch (EmptyResultDataAccessException ex) {
    CASE_SENSITIVE_WRITER.append(record);
    CASE_SENSITIVE_WRITER.insert();
  }
}
项目:wherehowsX    文件:DatasetInfoDao.java   
public static void updateDatasetCompliance(JsonNode root)
    throws Exception {
  final JsonNode security = root.path("privacyCompliancePolicy");
  if (security.isMissingNode() || security.isNull()) {
    throw new IllegalArgumentException(
        "Dataset security info update fail, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  ObjectMapper om = new ObjectMapper();

  DatasetComplianceRecord record = om.convertValue(security, DatasetComplianceRecord.class);
  record.setDatasetId(datasetId);
  record.setDatasetUrn(urn);
  record.setModifiedTime(System.currentTimeMillis() / 1000);
  try {
    DatasetComplianceRecord result = getDatasetComplianceByDatasetId(datasetId);
    String[] columns = record.getDbColumnNames();
    Object[] columnValues = record.getAllValuesToString();
    String[] conditions = {"dataset_id"};
    Object[] conditionValues = new Object[]{datasetId};
    COMPLIANCE_WRITER.update(columns, columnValues, conditions, conditionValues);
  } catch (EmptyResultDataAccessException ex) {
    COMPLIANCE_WRITER.append(record);
    COMPLIANCE_WRITER.insert();
  }
}
项目:wherehowsX    文件:DatasetInfoDao.java   
public static void updateDatasetSecurity(JsonNode root)
    throws Exception {
  final JsonNode security = root.path("securitySpecification");
  if (security.isMissingNode() || security.isNull()) {
    throw new IllegalArgumentException(
        "Dataset security info update fail, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  ObjectMapper om = new ObjectMapper();

  DatasetSecurityRecord record = om.convertValue(security, DatasetSecurityRecord.class);
  record.setDatasetId(datasetId);
  record.setDatasetUrn(urn);
  record.setModifiedTime(System.currentTimeMillis() / 1000);
  try {
    DatasetSecurityRecord result = getDatasetSecurityByDatasetId(datasetId);
    String[] columns = record.getDbColumnNames();
    Object[] columnValues = record.getAllValuesToString();
    String[] conditions = {"dataset_id"};
    Object[] conditionValues = new Object[]{datasetId};
    SECURITY_WRITER.update(columns, columnValues, conditions, conditionValues);
  } catch (EmptyResultDataAccessException ex) {
    SECURITY_WRITER.append(record);
    SECURITY_WRITER.insert();
  }
}
项目:Spring-Security-Third-Edition    文件:JdbcCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return jdbcOperations.queryForObject(CALENDAR_USER_QUERY + "email = ?", CALENDAR_USER_MAPPER, email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:Spring-Security-Third-Edition    文件:JdbcCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return jdbcOperations.queryForObject(CALENDAR_USER_QUERY + "email = ?", CALENDAR_USER_MAPPER, email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:demo-cas-server-web    文件:UserDaoJdbc.java   
/**
 * 根据用户名获取用户信息
 * @create 2015-7-20 上午10:40:54
 * @author 玄玉<http://blog.csdn.net/jadyer>
 */
public User getByUsername(String username){
    try{
        return (User)this.jdbcTemplate.queryForObject(SQL_USER_GET, new Object[]{username}, new UserRowMapper());
    }catch(EmptyResultDataAccessException e){
        return new User();
    }
}
项目:amv-access-api-poc    文件:IssuerServiceImpl.java   
@Override
public Optional<IssuerEntity> findIssuerById(long id) {
    try {
        return Optional.ofNullable(issuerRepository.findOne(id));
    } catch (EmptyResultDataAccessException e) {
        return Optional.empty();
    }
}
项目:Spring-Security-Third-Edition    文件:JdbcCalendarUserDao.java   
@Override
@Transactional(readOnly = true)
public CalendarUser findUserByEmail(String email) {
    if (email == null) {
        throw new IllegalArgumentException("email cannot be null");
    }
    try {
        return jdbcOperations.queryForObject(CALENDAR_USER_QUERY + "email = ?", CALENDAR_USER_MAPPER, email);
    } catch (EmptyResultDataAccessException notFound) {
        return null;
    }
}
项目:SpaceInvasion-09-2017    文件:UserServicePostgres.java   
@Override
public User getUser(Integer userId) {
    String sql;
    User user;
    if (userId == null) {
        throw new Exceptions.NotFoundUser();
    }
    sql = "SELECT * FROM users WHERE id = ?";
    try {
        user = jdbcTemplateObject.queryForObject(sql, USER_ROW_MAPPER, userId);
    } catch (EmptyResultDataAccessException e) {
        throw new Exceptions.NotFoundUser();
    }
    return user;
}