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


Java DataAccessResourceFailureException类代码示例

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


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

示例1: setClobAsAsciiStream

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
@Override
public void setClobAsAsciiStream(
		PreparedStatement ps, int paramIndex, InputStream asciiStream, int contentLength)
		throws SQLException {

	Clob clob = ps.getConnection().createClob();
	try {
		FileCopyUtils.copy(asciiStream, clob.setAsciiStream(1));
	}
	catch (IOException ex) {
		throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex);
	}

	this.temporaryClobs.add(clob);
	ps.setClob(paramIndex, clob);

	if (logger.isDebugEnabled()) {
		logger.debug(asciiStream != null ?
				"Copied ASCII stream into temporary CLOB with length " + contentLength :
				"Set CLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:TemporaryLobCreator.java

示例2: setClobAsCharacterStream

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
@Override
public void setClobAsCharacterStream(
		PreparedStatement ps, int paramIndex, Reader characterStream, int contentLength)
		throws SQLException {

	Clob clob = ps.getConnection().createClob();
	try {
		FileCopyUtils.copy(characterStream, clob.setCharacterStream(1));
	}
	catch (IOException ex) {
		throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex);
	}

	this.temporaryClobs.add(clob);
	ps.setClob(paramIndex, clob);

	if (logger.isDebugEnabled()) {
		logger.debug(characterStream != null ?
				"Copied character stream into temporary CLOB with length " + contentLength :
				"Set CLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:TemporaryLobCreator.java

示例3: SpringSessionSynchronization

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
public SpringSessionSynchronization(
		SessionHolder sessionHolder, SessionFactory sessionFactory,
		SQLExceptionTranslator jdbcExceptionTranslator, boolean newSession) {

	this.sessionHolder = sessionHolder;
	this.sessionFactory = sessionFactory;
	this.jdbcExceptionTranslator = jdbcExceptionTranslator;
	this.newSession = newSession;

	// Check whether the SessionFactory has a JTA TransactionManager.
	TransactionManager jtaTm =
			SessionFactoryUtils.getJtaTransactionManager(sessionFactory, sessionHolder.getAnySession());
	if (jtaTm != null) {
		this.hibernateTransactionCompletion = true;
		// Fetch current JTA Transaction object
		// (just necessary for JTA transaction suspension, with an individual
		// Hibernate Session per currently active/suspended transaction).
		try {
			this.jtaTransaction = jtaTm.getTransaction();
		}
		catch (SystemException ex) {
			throw new DataAccessResourceFailureException("Could not access JTA transaction", ex);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:SpringSessionSynchronization.java

示例4: setBlobAsBinaryStream

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
@Override
public void setBlobAsBinaryStream(
		PreparedStatement ps, int paramIndex, InputStream binaryStream, int contentLength)
		throws SQLException {

	Blob blob = ps.getConnection().createBlob();
	try {
		FileCopyUtils.copy(binaryStream, blob.setBinaryStream(1));
	}
	catch (IOException ex) {
		throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex);
	}

	this.temporaryBlobs.add(blob);
	ps.setBlob(paramIndex, blob);

	if (logger.isDebugEnabled()) {
		logger.debug(binaryStream != null ?
				"Copied binary stream into temporary BLOB with length " + contentLength :
				"Set BLOB to null");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:TemporaryLobCreator.java

示例5: getNextKey

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
/**
 * Executes the SQL as specified by {@link #getSequenceQuery()}.
 */
@Override
protected long getNextKey() throws DataAccessException {
	Connection con = DataSourceUtils.getConnection(getDataSource());
	Statement stmt = null;
	ResultSet rs = null;
	try {
		stmt = con.createStatement();
		DataSourceUtils.applyTransactionTimeout(stmt, getDataSource());
		rs = stmt.executeQuery(getSequenceQuery());
		if (rs.next()) {
			return rs.getLong(1);
		}
		else {
			throw new DataAccessResourceFailureException("Sequence query did not return a result");
		}
	}
	catch (SQLException ex) {
		throw new DataAccessResourceFailureException("Could not obtain sequence value", ex);
	}
	finally {
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeStatement(stmt);
		DataSourceUtils.releaseConnection(con, getDataSource());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:AbstractSequenceMaxValueIncrementer.java

示例6: doTranslate

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
@Override
protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
	String sqlState = getSqlState(ex);
	if (sqlState != null && sqlState.length() >= 2) {
		String classCode = sqlState.substring(0, 2);
		if (logger.isDebugEnabled()) {
			logger.debug("Extracted SQL state class '" + classCode + "' from value '" + sqlState + "'");
		}
		if (BAD_SQL_GRAMMAR_CODES.contains(classCode)) {
			return new BadSqlGrammarException(task, sql, ex);
		}
		else if (DATA_INTEGRITY_VIOLATION_CODES.contains(classCode)) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (DATA_ACCESS_RESOURCE_FAILURE_CODES.contains(classCode)) {
			return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (TRANSIENT_DATA_ACCESS_RESOURCE_CODES.contains(classCode)) {
			return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
		}
		else if (CONCURRENCY_FAILURE_CODES.contains(classCode)) {
			return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
		}
	}
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:SQLStateSQLExceptionTranslator.java

示例7: getSession

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
/**
 * Return a Session for use by this template.
 * <p>Returns a new Session in case of "alwaysUseNewSession" (using the same
 * JDBC Connection as a transactional Session, if applicable), a pre-bound
 * Session in case of "allowCreate" turned off, and a pre-bound or new Session
 * otherwise (new only if no transactional or otherwise pre-bound Session exists).
 * @return the Session to use (never {@code null})
 * @see SessionFactoryUtils#getSession
 * @see SessionFactoryUtils#getNewSession
 * @see #setAlwaysUseNewSession
 * @see #setAllowCreate
 */
protected Session getSession() {
	if (isAlwaysUseNewSession()) {
		return SessionFactoryUtils.getNewSession(getSessionFactory(), getEntityInterceptor());
	}
	else if (isAllowCreate()) {
		return SessionFactoryUtils.getSession(
				getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
	}
	else if (SessionFactoryUtils.hasTransactionalSession(getSessionFactory())) {
		return SessionFactoryUtils.getSession(getSessionFactory(), false);
	}
	else {
		try {
			return getSessionFactory().getCurrentSession();
		}
		catch (HibernateException ex) {
			throw new DataAccessResourceFailureException("Could not obtain current Hibernate Session", ex);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:HibernateTemplate.java

示例8: testExecuteWithNotAllowCreate

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
@Test
public void testExecuteWithNotAllowCreate() {
	reset(sessionFactory);
	given(sessionFactory.getCurrentSession()).willThrow(new HibernateException(""));
	HibernateTemplate ht = new HibernateTemplate();
	ht.setSessionFactory(sessionFactory);
	ht.setAllowCreate(false);
	try {
		ht.execute(new HibernateCallback<Object>() {
			@Override
			public Object doInHibernate(org.hibernate.Session session) throws HibernateException {
				return null;
			}
		});
		fail("Should have thrown DataAccessException");
	}
	catch (DataAccessResourceFailureException ex) {
		// expected
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:HibernateTemplateTests.java

示例9: forceEvict

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
/**
 * This really does not work for most cases so be very careful with it
 * @param object
 */
protected void forceEvict(Serializable object) {
    boolean active = false;
    try {
        Session session = currentSession();
        if (session.isOpen() && session.isConnected()) {
            if (session.contains(object)) {
                active = true;
                session.evict(object);
            }
        } else {
            LOG.warn("Session is not open OR not connected, cannot evict objects");
        }
        if (!active) {
            LOG.info("Unable to evict object ("+object.getClass().getName()+") from session, it is not persistent: "+object);
        }
    } catch (DataAccessResourceFailureException | IllegalStateException | HibernateException e) {
        LOG.warn("Failure while attempting to evict object ("+object.getClass().getName()+") from session", e);
    }
}
 
开发者ID:sakaicontrib,项目名称:evaluation,代码行数:24,代码来源:EvaluationDaoImpl.java

示例10: endDocument

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
/**
 * Writes the EndDocument tag manually.
 *
 * @param writer
 *            XML event writer
 * @throws XMLStreamException if there is a problem ending the document
 */
protected final void endDocument(final XMLEventWriter writer)
		throws XMLStreamException {

	// writer.writeEndDocument(); <- this doesn't work after restart
	// we need to write end tag of the root element manually

	String nsPrefix = null;
	if (!StringUtils.hasText(getRootTagNamespacePrefix())) {
		nsPrefix = "";
	} else {
		nsPrefix = getRootTagNamespacePrefix() + ":";
	}
	try {
		bufferedWriter.write("</" + nsPrefix + getRootTagName() + ">");
	} catch (IOException ioe) {
		throw new DataAccessResourceFailureException(
				"Unable to close file resource: [" + resource + "]", ioe);
	}
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:27,代码来源:StaxEventItemWriter.java

示例11: getPosition

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
/**
 * Get the actual position in file channel. This method flushes any buffered
 * data before position is read.
 *
 * @return byte offset in file channel
 */
private long getPosition() {

	long position;

	try {
		eventWriter.flush();
		position = channel.position();
		if (bufferedWriter instanceof TransactionAwareBufferedWriter) {
			position += ((TransactionAwareBufferedWriter) bufferedWriter)
					.getBufferSize();
		}
	} catch (Exception e) {
		throw new DataAccessResourceFailureException(
				"Unable to write to file resource: [" + resource + "]", e);
	}

	return position;
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:25,代码来源:StaxEventItemWriter.java

示例12: getPosition

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
private long getPosition() {

		long position;

		try {
			eventWriter.flush();
			position = channel.position();
			if (bufferedWriter instanceof TransactionAwareBufferedWriter) {
				position += ((TransactionAwareBufferedWriter) bufferedWriter)
						.getBufferSize();
			}
		} catch (Exception e) {
			throw new DataAccessResourceFailureException(
					"Unable to write to file resource: [" + resource + "]", e);
		}

		return position;
	}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:19,代码来源:StaxEventItemWriter.java

示例13: getVistaAccounts

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
protected synchronized List<VistaAccount> getVistaAccounts() {
    InputStream is = null;
    try {
        Resource vistaAccountConfig = getVistaAccountConfig();
        is = vistaAccountConfig.getInputStream();
        JsonNode json = jsonMapper.readTree(is);
        JsonNode items = json.path("data").path("items");
        List<VistaAccount> accounts = jsonMapper.convertValue(items, jsonMapper.getTypeFactory().constructCollectionType(List.class, VistaAccount.class));
        // quick and dirty way to set VistaAccount.id to its index in the list. Might be a fancier way to do it with Jackson...
        for (int i = 0; i < accounts.size(); i++) {
            accounts.get(i).setId(i);
            accounts.get(i).decrypt(hmpEncryption);
        }
        return accounts;
    } catch (Exception e) {
        throw new DataAccessResourceFailureException("unable to load vista-account config", e);
    } finally {
        IOUtils.closeSilently(is);
    }
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:21,代码来源:JsonVistaAccountDao.java

示例14: getPrimaryVistaSystemId

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
public String getPrimaryVistaSystemId() {
    InputStream is = null;
    try {
        Resource vistaAccountConfig = getVistaAccountConfig();
        is = vistaAccountConfig.getInputStream();
        JsonNode json = jsonMapper.readTree(is);
        JsonNode items = json.path("data").path("items");
        List<VistaAccount> accounts = jsonMapper.convertValue(items, jsonMapper.getTypeFactory().constructCollectionType(List.class, VistaAccount.class));
        // quick and dirty way to set VistaAccount.id to its index in the list. Might be a fancier way to do it with Jackson...
        if(accounts.size()>0) {
            return accounts.get(0).getVistaId();
        }
    } catch (Exception e) {
        throw new DataAccessResourceFailureException("unable to load vista-account config", e);
    } finally {
        IOUtils.closeSilently(is);
    }
    return "";
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:20,代码来源:JsonVistaAccountDao.java

示例15: findByDivisionHostAndPort

import org.springframework.dao.DataAccessResourceFailureException; //导入依赖的package包/类
@Override
public VistaAccount findByDivisionHostAndPort(String division, String host, int port) {
	List<VistaAccount> allAccounts = getVistaAccounts();
	try {
		for (VistaAccount account : allAccounts) {
			if (division!=null && division.equalsIgnoreCase(account.getDivision()) &&
					host!=null && host.equalsIgnoreCase(account.getHost()) &&
					port == account.getPort()) {
				return account;
			}
		}
    } catch (Exception e) {
        throw new DataAccessResourceFailureException("unable to load vista-account config", e);
    }

    return null;
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:18,代码来源:JsonVistaAccountDao.java


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