本文整理匯總了Java中org.springframework.dao.EmptyResultDataAccessException類的典型用法代碼示例。如果您正苦於以下問題:Java EmptyResultDataAccessException類的具體用法?Java EmptyResultDataAccessException怎麽用?Java EmptyResultDataAccessException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EmptyResultDataAccessException類屬於org.springframework.dao包,在下文中一共展示了EmptyResultDataAccessException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDependencies
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
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);
}
}
示例2: getReferences
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
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);
}
}
示例3: getDatasetSchemaTextByVersion
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
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;
}
示例4: getMetricByID
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
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;
}
示例5: getFlowSnapshot
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
@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;
}
}
示例6: getCurrentGithubId
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
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;
}
示例7: githubStatRecordKeyReturned
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
@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);
}
示例8: updateConfigurationValue
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
@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);
}
示例9: updateConfigurationValue
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
@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);
}
示例10: testSpringLocalTx
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
@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
}
}
示例11: findByClientIdAndSubject
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
@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;
}
}
示例12: findById
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
@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;
}
示例13: registerGlobalAuthentication
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
@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);
}
});
}
示例14: loadUser
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
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")
);
}
}
);
}
示例15: findUserByEmail
import org.springframework.dao.EmptyResultDataAccessException; //導入依賴的package包/類
@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;
}
}