當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。