• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JdbcExceptionHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: convert

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
/**
 * Convert the given SQLException into Hibernate's JDBCException hierarchy.
 *
 * @param sqlException The SQLException to be converted.
 * @param message	  An optional error message.
 * @param sql		  Optionally, the sql being performed when the exception occurred.
 * @return The resulting JDBCException; returns null if it could not be converted.
 */
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
	String sqlStateClassCode = JdbcExceptionHelper.extractSqlStateClassCode( sqlException );
	if ( sqlStateClassCode != null ) {
		Integer errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
		if ( INTEGRITY_VIOLATION_CATEGORIES.contains( errorCode ) ) {
			String constraintName =
					getConversionContext()
							.getViolatedConstraintNameExtracter()
							.extractConstraintName( sqlException );
			return new ConstraintViolationException( message, sqlException, sql, constraintName );
		}
		else if ( DATA_CATEGORIES.contains( sqlStateClassCode ) ) {
			return new DataException( message, sqlException, sql );
		}
	}
	return null; // allow other delegates the chance to look
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:CacheSQLExceptionConversionDelegate.java


示例2: buildSQLExceptionConversionDelegate

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
	return new SQLExceptionConversionDelegate() {
		@Override
		public JDBCException convert(SQLException sqlException, String message, String sql) {
			final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
			final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
			if("JZ0TO".equals( sqlState ) || "JZ006".equals( sqlState )){
				throw new LockTimeoutException( message, sqlException, sql );
			}
			if ( 515 == errorCode && "ZZZZZ".equals( sqlState ) ) {
				// Attempt to insert NULL value into column; column does not allow nulls.
				final String constraintName = getViolatedConstraintNameExtracter().extractConstraintName( sqlException );
				return new ConstraintViolationException( message, sqlException, sql, constraintName );
			}
			return null;
		}
	};
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:SybaseASE157Dialect.java


示例3: buildSQLExceptionConversionDelegate

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
	return new SQLExceptionConversionDelegate() {
		@Override
		public JDBCException convert(SQLException sqlException, String message, String sql) {
			final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
			final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
			if ( "HY008".equals( sqlState ) ) {
				throw new QueryTimeoutException( message, sqlException, sql );
			}
			if (1222 == errorCode ) {
				throw new LockTimeoutException( message, sqlException, sql );
			}
			return null;
		}
	};
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:SQLServer2005Dialect.java


示例4: extractConstraintName

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
public String extractConstraintName(SQLException sqle) {
	try {
		final int sqlState = Integer.valueOf( JdbcExceptionHelper.extractSqlState( sqle ) );
		switch (sqlState) {
			// CHECK VIOLATION
			case 23514: return extractUsingTemplate( "violates check constraint \"","\"", sqle.getMessage() );
			// UNIQUE VIOLATION
			case 23505: return extractUsingTemplate( "violates unique constraint \"","\"", sqle.getMessage() );
			// FOREIGN KEY VIOLATION
			case 23503: return extractUsingTemplate( "violates foreign key constraint \"","\"", sqle.getMessage() );
			// NOT NULL VIOLATION
			case 23502: return extractUsingTemplate( "null value in column \"","\" violates not-null constraint", sqle.getMessage() );
			// TODO: RESTRICT VIOLATION
			case 23001: return null;
			// ALL OTHER
			default: return null;
		}
	}
	catch (NumberFormatException nfe) {
		return null;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:PostgreSQL81Dialect.java


示例5: buildSQLExceptionConversionDelegate

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
	return new SQLExceptionConversionDelegate() {
		@Override
		public JDBCException convert(SQLException sqlException, String message, String sql) {
			final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );

			if ( "40P01".equals( sqlState ) ) {
				// DEADLOCK DETECTED
				return new LockAcquisitionException( message, sqlException, sql );
			}

			if ( "55P03".equals( sqlState ) ) {
				// LOCK NOT AVAILABLE
				return new PessimisticLockException( message, sqlException, sql );
			}

			// returning null allows other delegates to operate
			return null;
		}
	};
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:PostgreSQL81Dialect.java


示例6: buildSQLExceptionConversionDelegate

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
	return new SQLExceptionConversionDelegate() {
		@Override
		public JDBCException convert(SQLException sqlException, String message, String sql) {
			final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
			if (errorCode == SQLITE_TOOBIG || errorCode == SQLITE_MISMATCH) {
				return new DataException(message, sqlException, sql);
			} else if (errorCode == SQLITE_BUSY || errorCode == SQLITE_LOCKED) {
				return new LockAcquisitionException(message, sqlException, sql);
			} else if ((errorCode >= SQLITE_IOERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOTADB) {
				return new JDBCConnectionException(message, sqlException, sql);
			}

			// returning null allows other delegates to operate
			return null;
		}
	};
}
 
开发者ID:shilongdai,项目名称:vsDiaryWriter,代码行数:20,代码来源:SQLiteDialect.java


示例7: buildSQLExceptionConverter

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
        return new SQLExceptionConverter() {
                @Override
                public JDBCException convert(SQLException sqlException,
                                String message, String sql) {
                        final String sqlState = JdbcExceptionHelper
                                        .extractSqlState(sqlException);
                        if (sqlState != null) {
                                if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
                                        return new SQLGrammarException(message, sqlException,
                                                        sql);
                                } else if (DATA_CATEGORIES.contains(sqlState)) {
                                        return new DataException(message, sqlException, sql);
                                } else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
                                        return new LockAcquisitionException(message,
                                                        sqlException, sql);
                                }
                        }
                        return null;
                }
        };
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:24,代码来源:GemFireXDDialect.java


示例8: buildSQLExceptionConversionDelegate

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
        return new SQLExceptionConversionDelegate() {
                @Override
                public JDBCException convert(SQLException sqlException,
                                String message, String sql) {
                        final String sqlState = JdbcExceptionHelper
                                        .extractSqlState(sqlException);
                        if (sqlState != null) {
                                if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
                                        return new SQLGrammarException(message, sqlException,
                                                        sql);
                                } else if (DATA_CATEGORIES.contains(sqlState)) {
                                        return new DataException(message, sqlException, sql);
                                } else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
                                        return new LockAcquisitionException(message,
                                                        sqlException, sql);
                                }
                        }
                        return null;
                }
        };
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:23,代码来源:GemFireXDDialect.java


示例9: buildSQLExceptionConversionDelegate

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
	return new SQLExceptionConversionDelegate() {
		@Override
		public JDBCException convert(SQLException sqlException, String message, String sql) {
			final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
			if (errorCode == SQLITE_TOOBIG || errorCode == SQLITE_MISMATCH) {
				return new DataException(message, sqlException, sql);
			} else if (errorCode == SQLITE_BUSY || errorCode == SQLITE_LOCKED) {
				return new LockAcquisitionException(message, sqlException, sql);
			} else if ((errorCode >= SQLITE_IOERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOTADB) {
				return new JDBCConnectionException(message, sqlException, sql);
			}
			return null;
		}
	};
}
 
开发者ID:kb2623,项目名称:spletne-seje,代码行数:18,代码来源:SQLiteDialect.java


示例10: extractConstraintName

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
public String extractConstraintName(SQLException sqle) {
    try {
        final int sqlState = Integer.valueOf( JdbcExceptionHelper.extractSqlState( sqle ) );
        switch (sqlState) {
            // CHECK VIOLATION - TODO: When added
            //case 23514: return extractUsingTemplate( "violates check constraint \"","\"", sqle.getMessage() );
            // UNIQUE VIOLATION
           case 23501: return extractUsingTemplate( "violates unique constraint ","\"", sqle.getMessage() );
            // FOREIGN KEY VIOLATION
            case 23503: return extractUsingTemplate( "due to foreign key constraint "," on ", sqle.getMessage() );
            // NOT NULL VIOLATION
            case 23502: return extractUsingTemplate( "NULL value not permitted for ","\"", sqle.getMessage() );
            // TODO: RESTRICT VIOLATION
            //case 23001: return null;
            // ALL OTHER
            default: return null;
        }
    }
    catch (NumberFormatException nfe) {
        return null;
    }
}
 
开发者ID:computerstaat,项目名称:sql-layer-adapter-hibernate,代码行数:23,代码来源:FoundationDBSQLDialect.java


示例11: buildSQLExceptionConversionDelegate

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
  return new SQLExceptionConversionDelegate() {
    @Override
    public JDBCException convert(SQLException sqlException, String message, String sql) {
      final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
      if (errorCode == SQLITE_TOOBIG || errorCode == SQLITE_MISMATCH) {
        return new DataException(message, sqlException, sql);
      } else if (errorCode == SQLITE_BUSY || errorCode == SQLITE_LOCKED) {
        return new LockAcquisitionException(message, sqlException, sql);
      } else if ((errorCode >= SQLITE_IOERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOTADB) {
        return new JDBCConnectionException(message, sqlException, sql);
      }

      // returning null allows other delegates to operate
      return null;
    }
  };
}
 
开发者ID:ntenhoeve,项目名称:Introspect-Framework,代码行数:20,代码来源:SQLiteDialect.java


示例12: convert

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
    final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
    if (errorCode == SQLITE_CONSTRAINT) {
        final String constraintName = EXTRACTER.extractConstraintName(sqlException);
        return new ConstraintViolationException(message, sqlException, sql, constraintName);
    } else if (errorCode == SQLITE_TOO_BIG || errorCode == SQLITE_MISMATCH) {
        return new DataException(message, sqlException, sql);
    } else if (errorCode == SQLITE_BUSY || errorCode == SQLITE_LOCKED) {
        return new LockAcquisitionException(message, sqlException, sql);
    } else if ((errorCode >= SQLITE_IO_ERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOT_ADB) {
        return new JDBCConnectionException(message, sqlException, sql);
    }
    return new GenericJDBCException(message, sqlException, sql);
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:16,代码来源:SQLiteSQLExceptionConversionDelegate.java


示例13: setup

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Before
public void setup() {
    conversionDelegate = new SQLiteSQLExceptionConversionDelegate();
    sqlException = mock(SQLException.class);
    when(sqlException.getMessage()).thenReturn("message");

    PowerMockito.mockStatic(JdbcExceptionHelper.class);
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:9,代码来源:SQLiteSQLExceptionConversionDelegateTest.java


示例14: returnsConstraintViolationException

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Test
public void returnsConstraintViolationException() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(19);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof ConstraintViolationException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:10,代码来源:SQLiteSQLExceptionConversionDelegateTest.java


示例15: returnsDataExceptionForSqliteTooBigError

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Test
public void returnsDataExceptionForSqliteTooBigError() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(18);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof DataException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:10,代码来源:SQLiteSQLExceptionConversionDelegateTest.java


示例16: returnsDataExceptionForSqliteMismatch

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Test
public void returnsDataExceptionForSqliteMismatch() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(20);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof DataException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:10,代码来源:SQLiteSQLExceptionConversionDelegateTest.java


示例17: returnsLockAcquisitionExceptionForSqliteBusy

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Test
public void returnsLockAcquisitionExceptionForSqliteBusy() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(5);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof LockAcquisitionException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:10,代码来源:SQLiteSQLExceptionConversionDelegateTest.java


示例18: returnsLockAcquisitionExceptionForSqliteLocked

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Test
public void returnsLockAcquisitionExceptionForSqliteLocked() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(6);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof LockAcquisitionException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:10,代码来源:SQLiteSQLExceptionConversionDelegateTest.java


示例19: returnsJDBCConnectionExceptionForSqliteCorrupt

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Test
public void returnsJDBCConnectionExceptionForSqliteCorrupt() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(11);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof JDBCConnectionException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:10,代码来源:SQLiteSQLExceptionConversionDelegateTest.java


示例20: returnsJDBCConnectionExceptionForSqliteNotAbd

import org.hibernate.internal.util.JdbcExceptionHelper; //导入依赖的package包/类
@Test
public void returnsJDBCConnectionExceptionForSqliteNotAbd() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(26);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof JDBCConnectionException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:10,代码来源:SQLiteSQLExceptionConversionDelegateTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Main类代码示例发布时间:2022-05-23
下一篇:
Java ContentDisposition类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap