本文整理汇总了Java中org.springframework.jdbc.UncategorizedSQLException类的典型用法代码示例。如果您正苦于以下问题:Java UncategorizedSQLException类的具体用法?Java UncategorizedSQLException怎么用?Java UncategorizedSQLException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UncategorizedSQLException类属于org.springframework.jdbc包,在下文中一共展示了UncategorizedSQLException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateLeaderboardName
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
/**
* Updates the name of a leaderboard.
*
* @param dao
* The LeaderboardDao.
* @param oldName
* The current name of the leaderboard.
* @param name
* The new name of the leaderboard.
* @return An error or success code.
*/
public static String updateLeaderboardName(LeaderboardDao dao, String oldName, String name)
{
Leaderboard leaderboard = dao.getLeaderboard(oldName);
if (null == leaderboard)
{
return LeaderboardMessages.MISSING_LEADERBOARD_CODE;
}
int leaderboardId = leaderboard.getId();
try
{
dao.updateLeaderboardName(leaderboardId, name);
return LeaderboardMessages.NO_ERROR;
}
catch (Exception e)
{
if (e instanceof UncategorizedSQLException)
{
return e.getCause().getMessage();
}
throw e;
}
}
示例2: deleteLeaderboard
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
/**
* Deletes a leaderboard.
*
* @param dao
* The LeaderboardDao.
* @param name
* The name of the leaderboard.
* @return An error or success code.
*/
public static String deleteLeaderboard(LeaderboardDao dao, LeaderboardColumnDao columnDao, String name)
{
Leaderboard leaderboard = dao.getLeaderboard(name);
if (null == leaderboard)
{
return LeaderboardMessages.MISSING_LEADERBOARD_CODE;
}
int leaderboardId = leaderboard.getId();
try
{
columnDao.deleteLeaderboardColumns(leaderboardId);
dao.deleteLeaderboard(leaderboardId);
return LeaderboardMessages.NO_ERROR;
}
catch (Exception e)
{
if (e instanceof UncategorizedSQLException)
{
return e.getCause().getMessage();
}
throw e;
}
}
示例3: translate
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
/**
* Pre-checks the arguments, calls {@link #doTranslate}, and invokes the
* {@link #getFallbackTranslator() fallback translator} if necessary.
*/
@Override
public DataAccessException translate(String task, String sql, SQLException ex) {
Assert.notNull(ex, "Cannot translate a null SQLException");
if (task == null) {
task = "";
}
if (sql == null) {
sql = "";
}
DataAccessException dex = doTranslate(task, sql, ex);
if (dex != null) {
// Specific exception match found.
return dex;
}
// Looking for a fallback...
SQLExceptionTranslator fallback = getFallbackTranslator();
if (fallback != null) {
return fallback.translate(task, sql, ex);
}
// We couldn't identify it more precisely.
return new UncategorizedSQLException(task, sql, ex);
}
示例4: testBogusUpdate
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
@Test
public void testBogusUpdate() throws Exception {
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
final int idParam = 6666;
// It's because Integers aren't canonical
SQLException sqlException = new SQLException("bad update");
given(this.preparedStatement.executeUpdate()).willThrow(sqlException);
Dispatcher d = new Dispatcher(idParam, sql);
this.thrown.expect(UncategorizedSQLException.class);
this.thrown.expect(exceptionCause(equalTo(sqlException)));
try {
this.template.update(d);
}
finally {
verify(this.preparedStatement).setInt(1, idParam);
verify(this.preparedStatement).close();
verify(this.connection, atLeastOnce()).close();
}
}
示例5: testBatchUpdateWithBatchFailure
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
@Test
public void testBatchUpdateWithBatchFailure() throws Exception {
final String[] sql = {"A", "B", "C", "D"};
given(this.statement.executeBatch()).willThrow(
new BatchUpdateException(new int[] { 1, Statement.EXECUTE_FAILED, 1,
Statement.EXECUTE_FAILED }));
mockDatabaseMetaData(true);
given(this.connection.createStatement()).willReturn(this.statement);
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
try {
template.batchUpdate(sql);
}
catch (UncategorizedSQLException ex) {
assertThat(ex.getSql(), equalTo("B; D"));
}
}
示例6: translate
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
/**
* Pre-checks the arguments, calls {@link #doTranslate}, and invokes the
* {@link #getFallbackTranslator() fallback translator} if necessary.
*/
public DataAccessException translate(String task, String sql, SQLException ex) {
Assert.notNull(ex, "Cannot translate a null SQLException");
if (task == null) {
task = "";
}
if (sql == null) {
sql = "";
}
DataAccessException dex = doTranslate(task, sql, ex);
if (dex != null) {
// Specific exception match found.
return dex;
}
// Looking for a fallback...
SQLExceptionTranslator fallback = getFallbackTranslator();
if (fallback != null) {
return fallback.translate(task, sql, ex);
}
// We couldn't identify it more precisely.
return new UncategorizedSQLException(task, sql, ex);
}
示例7: testTransactionAwareDataSourceProxy
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
@Test
public void testTransactionAwareDataSourceProxy() throws Exception {
given(con.getAutoCommit()).willReturn(true);
TransactionTemplate tt = new TransactionTemplate(tm);
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
// something transactional
assertEquals(con, DataSourceUtils.getConnection(ds));
TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy(ds);
try {
assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
// should be ignored
dsProxy.getConnection().close();
}
catch (SQLException ex) {
throw new UncategorizedSQLException("", "", ex);
}
}
});
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
InOrder ordered = inOrder(con);
ordered.verify(con).setAutoCommit(false);
ordered.verify(con).commit();
ordered.verify(con).setAutoCommit(true);
verify(con).close();
}
示例8: invalidSqlStateCode
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
@Test
public void invalidSqlStateCode() {
SQLException sex = new SQLException("Message", "NO SUCH CODE", 1);
try {
throw this.trans.translate("task", sql, sex);
}
catch (UncategorizedSQLException ex) {
// OK
assertTrue("SQL is correct", sql.equals(ex.getSql()));
assertTrue("Exception matches", sex.equals(ex.getSQLException()));
}
}
示例9: testMalformedSqlStateCode
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
private void testMalformedSqlStateCode(SQLException sex) {
try {
throw this.trans.translate("task", sql, sex);
}
catch (UncategorizedSQLException ex) {
// OK
assertTrue("SQL is correct", sql.equals(ex.getSql()));
assertTrue("Exception matches", sex.equals(ex.getSQLException()));
}
}
示例10: testCreateDatabaseExistingNoOverwriteNoCheck
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
@Test
public void testCreateDatabaseExistingNoOverwriteNoCheck() {
try {
assertFalse(rootDAO.existsDatabase(DB_NAME));
rootDAO.createDatabase(DB_NAME);
assertTrue(rootDAO.existsDatabase(DB_NAME));
rootDAO.createDatabase(DB_NAME, false, false);
fail();
} catch (UncategorizedSQLException use) {
} finally {
rootDAO.deleteDatabase(DB_NAME);
}
}
示例11: testCreateDatabaseExistingOverwriteNoCheck
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
@Test
public void testCreateDatabaseExistingOverwriteNoCheck() {
try {
assertFalse(rootDAO.existsDatabase(DB_NAME));
rootDAO.createDatabase(DB_NAME);
assertTrue(rootDAO.existsDatabase(DB_NAME));
rootDAO.createDatabase(DB_NAME, true, false);
fail();
} catch (UncategorizedSQLException use) {
} finally {
rootDAO.deleteDatabase(DB_NAME);
assertFalse(rootDAO.existsDatabase(DB_NAME));
}
}
示例12: testBatchMissingParamAtEnd
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testBatchMissingParamAtEnd() throws Exception {
try {
List<?> data = Arrays.asList(Arrays.asList(9, "stu", "vwx"), Arrays.asList(10, "yza"));
template.sendBody("direct:batch", data);
fail();
} catch (RuntimeCamelException e) {
assertTrue(e.getCause() instanceof UncategorizedSQLException);
}
assertEquals(new Integer(0), jdbcTemplate.queryForObject("select count(*) from projects where id = 9", Integer.class));
assertEquals(new Integer(0), jdbcTemplate.queryForObject("select count(*) from projects where id = 10", Integer.class));
}
示例13: testBatchMissingParamAtBeginning
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testBatchMissingParamAtBeginning() throws Exception {
try {
List<?> data = Arrays.asList(Arrays.asList(9, "stu"), Arrays.asList(10, "vwx", "yza"));
template.sendBody("direct:batch", data);
fail();
} catch (RuntimeCamelException e) {
assertTrue(e.getCause() instanceof UncategorizedSQLException);
}
assertEquals(new Integer(0), jdbcTemplate.queryForObject("select count(*) from projects where id = 9", Integer.class));
assertEquals(new Integer(0), jdbcTemplate.queryForObject("select count(*) from projects where id = 10", Integer.class));
}
示例14: convertGuzzAccessException
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
/**
* Convert the given GuzzException to an appropriate exception
* from the <code>org.springframework.dao</code> hierarchy.
* @param ex GuzzException that occured
* @return the corresponding DataAccessException instance
* @see GuzzAccessor#convertGuzzAccessException
* @see GuzzTransactionManager#convertGuzzAccessException
*/
public static DataAccessException convertGuzzAccessException(GuzzException ex) {
if(ex instanceof JDBCException){
JDBCException e = (JDBCException) ex ;
return new UncategorizedSQLException(e.getMessage(), e.getSQL(), e.getSQLException()) ;
}
return new DataAccessResourceFailureException(ex.getMessage(), ex);
}
示例15: testInvalidSqlStateCode
import org.springframework.jdbc.UncategorizedSQLException; //导入依赖的package包/类
public void testInvalidSqlStateCode() {
String sql = "SELECT FOO FROM BAR";
SQLException sex = new SQLException("Message", "NO SUCH CODE", 1);
try {
throw this.trans.translate("task", sql, sex);
}
catch (UncategorizedSQLException ex) {
// OK
assertTrue("SQL is correct", sql.equals(ex.getSql()));
assertTrue("Exception matches", sex.equals(ex.getSQLException()));
}
}