当前位置: 首页>>代码示例>>Java>>正文


Java DataAccessException类代码示例

本文整理汇总了Java中org.springframework.dao.DataAccessException的典型用法代码示例。如果您正苦于以下问题:Java DataAccessException类的具体用法?Java DataAccessException怎么用?Java DataAccessException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataAccessException类属于org.springframework.dao包,在下文中一共展示了DataAccessException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: afterCompletion

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count != null) {
		// Do not modify the PersistenceManager: just clear the marker.
		if (count > 1) {
			request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
		}
		else {
			request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		}
	}
	else {
		PersistenceManagerHolder pmHolder = (PersistenceManagerHolder)
				TransactionSynchronizationManager.unbindResource(getPersistenceManagerFactory());
		logger.debug("Closing JDO PersistenceManager in OpenPersistenceManagerInViewInterceptor");
		PersistenceManagerFactoryUtils.releasePersistenceManager(
				pmHolder.getPersistenceManager(), getPersistenceManagerFactory());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:OpenPersistenceManagerInViewInterceptor.java

示例2: update

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
@Override
public int update(String sql) throws DataAccessException {
    LogOperate logOperate = parseOperate(sql);
    Assert.notNull(logOperate,"不匹配的操作类型,日志记录失败!");
    switch (logOperate){
        case DELETE:
            deleteRecordLog(logOperate,sql);
            break;
        case UPDATE:
            updateRecordLog(logOperate,sql);
            break;
        case INSERT:
            insertRecordLog(logOperate,sql);
            break;
        default:
            break;
    }
    return super.update(sql);
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:20,代码来源:LogJdbcTemplate.java

示例3: load

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
@Override
public Object load(final String entityName, final Serializable id, final LockMode lockMode)
		throws DataAccessException {

	return executeWithNativeSession(new HibernateCallback<Object>() {
		@Override
		public Object doInHibernate(Session session) throws HibernateException {
			if (lockMode != null) {
				return session.load(entityName, id, lockMode);
			}
			else {
				return session.load(entityName, id);
			}
		}
	});
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:HibernateTemplate.java

示例4: delete

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
/**
 * 删除供应商
 * @return
 */
public String delete()
{
    Log.infoFileSync("====================开始调用删除供应商信息方法delete()================");
    try 
    {
           supplierService.delete(model.getSupplierID());
           tipMsg = "成功";
           tipType = 0;
       } 
    catch (DataAccessException e) 
    {
        Log.errorFileSync(">>>>>>>>>>>删除ID为 " + model.getSupplierID() + "  的供应商异常", e);
        tipMsg = "失败";
           tipType = 1;
       }
    model.getShowModel().setMsgTip(tipMsg);
    logService.create(new Logdetails(getUser(), "删除供应商", model.getClientIp(),
            new Timestamp(System.currentTimeMillis())
    , tipType, "删除供应商ID为  "+ model.getSupplierID() + ",名称为  " + model.getSupplier() + tipMsg + "!", "删除供应商" + tipMsg));
    Log.infoFileSync("====================结束调用删除供应商信息方法delete()================");
    return SUCCESS;
}
 
开发者ID:cendi2005,项目名称:jshERP,代码行数:27,代码来源:SupplierAction.java

示例5: executeSingleResultQuery

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
private Object executeSingleResultQuery(String query, Map<?, ?> params)
{
	return jdbcTemplate.query(query, params, new ResultSetExtractor()
	{
		@Override
		public Object extractData(ResultSet rs) throws SQLException, DataAccessException
		{
			Object data = null;
			if( rs.next() )
			{
				data = rs.getObject(1);

				// Sanity check - ensure only a single result
				if( rs.next() )
				{
					throw new IncorrectResultSizeDataAccessException(1);
				}
			}
			return data;
		}
	});
}
 
开发者ID:equella,项目名称:Equella,代码行数:23,代码来源:SqlTaxonomyDataSource.java

示例6: delete

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
/**
 * 删除资产名称
 * @return
 */
public String delete()
{
    Log.infoFileSync("====================开始调用删除资产名称信息方法delete()================");
    try 
    {
        assetnameService.delete(model.getAssetNameID());
        tipMsg = "成功";
        tipType = 0;
    } 
    catch (DataAccessException e) 
    {
        Log.errorFileSync(">>>>>>>>>>>删除ID为 " + model.getAssetNameID() + "  的资产名称异常", e);
        tipMsg = "失败";
        tipType = 1;
    }
    model.getShowModel().setMsgTip(tipMsg);
    logService.create(new Logdetails(getUser(), "删除资产名称", model.getClientIp(),
            new Timestamp(System.currentTimeMillis())
    , tipType, "删除资产名称ID为  "+ model.getAssetNameID() + " " + tipMsg + "!", "删除资产名称" + tipMsg));
    Log.infoFileSync("====================结束调用删除资产名称信息方法delete()================");
    return SUCCESS;
}
 
开发者ID:cendi2005,项目名称:jshERP,代码行数:27,代码来源:AssetNameAction.java

示例7: batchDelete

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
/**
 * 批量删除指定ID资产类型
 * @return
 */
public String batchDelete()
{
    try
    {
        categoryService.batchDelete(model.getCategoryIDs());
           model.getShowModel().setMsgTip("成功");
           //记录操作日志使用
           tipMsg = "成功";
           tipType = 0;
       } 
    catch (DataAccessException e) 
    {
        Log.errorFileSync(">>>>>>>>>>>批量删除资产类型ID为:" + model.getCategoryIDs() + "信息异常", e);
        tipMsg = "失败";
           tipType = 1;
       }
    
    logService.create(new Logdetails(getUser(), "批量删除资产类型", model.getClientIp(),
               new Timestamp(System.currentTimeMillis())
       , tipType, "批量删除资产类型ID为  "+ model.getCategoryIDs() + " " + tipMsg + "!", "批量删除资产类型" + tipMsg));
    return SUCCESS;
}
 
开发者ID:cendi2005,项目名称:jshERP,代码行数:27,代码来源:CategoryAction.java

示例8: testCallback3

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
@Test
public void testCallback3() {
    final Properties[] result = {null};

    redisTemplate.execute(new RedisCallback<Object>() {
        @Override
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            Properties properties = connection.info();
            System.out.println(properties);

            Enumeration<String> nameList = (Enumeration<String>) properties.propertyNames();
            while (nameList.hasMoreElements()) {
                System.out.println(nameList.nextElement());
            }

            result[0] = properties;
            return null;
        }
    });
}
 
开发者ID:luoxn28,项目名称:redis-info,代码行数:21,代码来源:TestRedis.java

示例9: update

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
protected int update(final PreparedStatementCreator psc, final PreparedStatementSetter pss)
		throws DataAccessException {

	logger.debug("Executing prepared SQL update");
	return execute(psc, new PreparedStatementCallback<Integer>() {
		@Override
		public Integer doInPreparedStatement(PreparedStatement ps) throws SQLException {
			try {
				if (pss != null) {
					pss.setValues(ps);
				}
				int rows = ps.executeUpdate();
				if (logger.isDebugEnabled()) {
					logger.debug("SQL update affected " + rows + " rows");
				}
				return rows;
			}
			finally {
				if (pss instanceof ParameterDisposer) {
					((ParameterDisposer) pss).cleanupParameters();
				}
			}
		}
	});
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:JdbcTemplate.java

示例10: getAppCategoryRank

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
@Override
public List<App> getAppCategoryRank(final int parentId, final int subCatalog, final int top) {
    PreparedStatementCallback<List<App>> cb = new PreparedStatementCallback<List<App>>() {
        @Override
        public List<App> doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
            ps.setInt(1, parentId);
            ps.setInt(2, subCatalog);
            ps.setInt(3, top);
            ResultSet rs = null;
            try {
                rs = ps.executeQuery();
                if (rs.last()) {
                    int count = rs.getRow();
                    List<App> list = new ArrayList<App>(count);
                    rs.beforeFirst();
                    App app = null;
                    while (rs.next()) {
                        app = appRowMapper.mapRow(rs, rs.getRow());
                        changeOutputImpl.setUrls(app);
                        list.add(app);
                    }
                    return list;
                }

            } catch (Exception e) {
                logger.error("SQL data error:", e);
                return null;
            } finally {
                if (null != rs)
                    rs.close();
            }
            return null;
        }
    };
    return jdbcTemplate.execute(QUERY_APP_CATEGORY_TOP_SQL, cb);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:37,代码来源:AppRankDaoImpl.java

示例11: loadUserByUsername

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
@Override
public UserDetails loadUserByUsername(String incomingUserName) throws UsernameNotFoundException, DataAccessException
{
    CacheEntry userEntry = getUserEntryOrNull(incomingUserName);
    if (userEntry == null)
    {
        throw new UsernameNotFoundException("Could not find user by userName: " + incomingUserName);
    }
    UserDetails userDetails = userEntry.userDetails;
    if (userEntry.credentialExpiryDate == null || userEntry.credentialExpiryDate.getTime() >= System.currentTimeMillis())
    {
        return userDetails;
    }

    if (userDetails instanceof RepositoryAuthenticatedUser)
    {
        RepositoryAuthenticatedUser repoUser = (RepositoryAuthenticatedUser) userDetails;
        return new RepositoryAuthenticatedUser(userDetails.getUsername(), userDetails.getPassword(), userDetails.isEnabled(),
                userDetails.isAccountNonExpired(), false,
                userDetails.isAccountNonLocked(), userDetails.getAuthorities(), repoUser.getHashIndicator(), repoUser.getSalt());
    }

    throw new AlfrescoRuntimeException("Unable to retrieve a compatible UserDetails object (requires RepositoryAuthenticatedUser)");
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:25,代码来源:RepositoryAuthenticationDao.java

示例12: updateSortListProp

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
public static void updateSortListProp(JsonNode props) throws IOException, SQLException, DataAccessException {
    String name = props.get("scheme").asText();
    JsonNode propNode = props.findPath("properties");
    String propString = recProp("prop.sortlist." + name) + ",";
    if (propNode.isArray()) {
        for (JsonNode p : propNode) {
            propString = propString + p.textValue() + ",";
        }
        propString = propString.substring(0, propString.length() - 1);
    } else if (propNode.isTextual()) {
        propString = propString + propNode.textValue();
    } else {
        Logger.error("passed property neither a list or array");
        throw new IllegalArgumentException();
    }
    chngProp("prop.sortlist." + name, propString);
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:18,代码来源:PropertyDao.java

示例13: authenticateUsernamePasswordInternal

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
@Override
protected final HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential)
        throws GeneralSecurityException, PreventedException {

    if (StringUtils.isBlank(this.sql) || getJdbcTemplate() == null) {
        throw new GeneralSecurityException("Authentication handler is not configured correctly");
    }

    final String username = credential.getUsername();
    final String encyptedPassword = getPasswordEncoder().encode(credential.getPassword());
    final int count;
    try {
        count = getJdbcTemplate().queryForObject(this.sql, Integer.class, username, encyptedPassword);
    } catch (final DataAccessException e) {
        throw new PreventedException("SQL exception while executing query for " + username, e);
    }
    if (count == 0) {
        throw new FailedLoginException(username + " not found with SQL query.");
    }
    return createHandlerResult(credential, this.principalFactory.createPrincipal(username), null);
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:22,代码来源:SearchModeSearchDatabaseAuthenticationHandler.java

示例14: onLoginSuccess

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
@Override
protected void onLoginSuccess(HttpServletRequest request, HttpServletResponse response, Authentication
    successfulAuthentication) {

    String login = successfulAuthentication.getName();

    log.debug("Creating new persistent login for user {}", login);
    PersistentToken token = userRepository.findOneByLogin(login).map(u -> {
        PersistentToken t = new PersistentToken();
        t.setSeries(generateSeriesData());
        t.setUser(u);
        t.setTokenValue(generateTokenData());
        t.setTokenDate(LocalDate.now());
        t.setIpAddress(request.getRemoteAddr());
        t.setUserAgent(request.getHeader("User-Agent"));
        return t;
    }).orElseThrow(() -> new UsernameNotFoundException("User " + login + " was not found in the database"));
    try {
        persistentTokenRepository.save(token);
        addCookie(token, request, response);
    } catch (DataAccessException e) {
        log.error("Failed to save persistent token ", e);
    }
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:25,代码来源:CustomPersistentRememberMeServices.java

示例15: zoekPersonen

import org.springframework.dao.DataAccessException; //导入依赖的package包/类
@Override
public List<Long> zoekPersonen(final SqlStamementZoekPersoon sql, final boolean postgres) throws QueryCancelledException {
    final JdbcTemplate jdbcTemplate = new JdbcTemplate(masterDataSource);
    if (postgres) {
        //statement timeout zorgt ook voor het cancellen van query op server
        jdbcTemplate.execute(String.format("set local statement_timeout = %d", TimeUnit.SECONDS.toMillis(maxStatementDuurSec)));
    }
    try {
        return jdbcTemplate.queryForList(sql.getSql(), Long.class, (Object[]) sql.getParameters().toArray());
    } catch (DataAccessException e) {
        if (e.getCause() != null && e.getCause() instanceof SQLException && SQL_TIMEOUT_CODE.equals(((SQLException) e.getCause()).getSQLState())) {
            throw new QueryCancelledException(e);
        }
        throw e;
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:17,代码来源:ZoekPersoonRepositoryImpl.java


注:本文中的org.springframework.dao.DataAccessException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。