本文整理汇总了Java中org.hibernate.exception.GenericJDBCException类的典型用法代码示例。如果您正苦于以下问题:Java GenericJDBCException类的具体用法?Java GenericJDBCException怎么用?Java GenericJDBCException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericJDBCException类属于org.hibernate.exception包,在下文中一共展示了GenericJDBCException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFallbackExceptionTranslation
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
@Test
public void testFallbackExceptionTranslation() throws HibernateException {
SQLException sqlEx = new SQLException("argh", "27");
final GenericJDBCException gjex = new GenericJDBCException("mymsg", sqlEx);
try {
hibernateTemplate.execute(new HibernateCallback<Object>() {
@Override
public Object doInHibernate(org.hibernate.Session session) throws HibernateException {
throw gjex;
}
});
fail("Should have thrown DataIntegrityViolationException");
}
catch (DataIntegrityViolationException ex) {
// expected
assertEquals(sqlEx, ex.getCause());
assertTrue(ex.getMessage().indexOf("mymsg") != -1);
}
}
示例2: runQuery
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
/**
* Run query.
*
* @param <T>
* the generic type
* @param query
* the query
* @param type
* the type
* @return the vector
*/
@SuppressWarnings("unchecked")
<T> Vector<T> runQuery(final Query query, final Class<T> type) {
HibernateHelper.logger.debug("runSQL: " + query);
// TODO create prepared statements
Vector<?> returnVal = null;
try {
returnVal = new Vector<T>(query.list());
}
catch (final GenericJDBCException dbe) {
throw dbe;
}
catch (final HibernateException e) {
HibernateHelper.logger.error("Error fetching " + NewsGroup.class.getName(), e);
}
if (null == returnVal) {
returnVal = new Vector<>();
}
return (Vector<T>) returnVal;
}
示例3: catchNewConnectionJson
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
/**
* Generate an exception related to create a new DB connection.
*
* @param e
* exception
* @param txId
* @param resource
* @return
*/
public static Response catchNewConnectionJson(UriInfo ui, GenericJDBCException e,
String resource, String txId) {
// ALARM DETECTED
FactoryResponse.logger.error(Constants.LOG_ALARM + " Cannot open connection with the database");
// Write response
String[] args = {"Cannot open connection with the database"};
RSSException newException = new RSSException(UNICAExceptionType.GENERIC_SERVER_FAULT, args, e, txId, null);
FactoryResponse.logger.error("Return GRETAException: [" + newException.getExceptionType().getExceptionId()
+ "] "
+ newException.getMessage(), e);
ExceptionTypeBean exceptObj = FactoryResponse.exceptionJson( ui,
newException, resource);
return FactoryResponse.createResponseError(newException, exceptObj);
}
示例4: catchNewConnectionJson
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
/**
* Generate an exception related to create a new DB connection.
*
* @param e
* exception
* @param txId
* @param resource
* @return
*/
public static Response catchNewConnectionJson(UriInfo ui, GenericJDBCException e,
String resource, String txId) {
// ALARM DETECTED
FactoryResponse.logger.error(Constants.LOG_ALARM + " Cannot open connection with the database");
// Write response
String[] args = {"Cannot open connection with the database"};
RSSException newException = new RSSException(UNICAExceptionType.GENERIC_SERVER_FAULT, args, e, txId, null);
FactoryResponse.logger.error("Return GRETAException: [" + newException.getExceptionType().getExceptionId()
+ "] "
+ newException.getMessage(), e);
ExceptionTypeBean exceptObj = FactoryResponse.exceptionJson(ui,
newException, resource);
return FactoryResponse.createResponseError(newException, exceptObj);
}
示例5: buildSQLExceptionConverter
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
return new SQLExceptionConverter() {
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
final int errorCode = sqlException.getErrorCode();
if (errorCode == SQLITE_CONSTRAINT) {
final String constraintName = EXTRACTER.extractConstraintName(sqlException);
return new ConstraintViolationException(message, sqlException, sql, constraintName);
} else 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 new GenericJDBCException(message, sqlException, sql);
}
};
}
示例6: convert
import org.hibernate.exception.GenericJDBCException; //导入依赖的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);
}
示例7: returnsGenericJDBCExceptionForEverythingElse
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
@Test
public void returnsGenericJDBCExceptionForEverythingElse() {
when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(41);
JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
assertTrue(exception instanceof GenericJDBCException);
assertEquals("message", exception.getMessage());
assertEquals("sql", exception.getSQL());
}
示例8: determineRowCount
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
@Override
protected int determineRowCount(int reportedRowCount, PreparedStatement statement) {
try {
return toCallableStatement( statement ).getInt( parameterPosition );
}
catch( SQLException sqle ) {
sqlExceptionHelper.logExceptions( sqle, "could not extract row counts from CallableStatement" );
throw new GenericJDBCException( "could not extract row counts from CallableStatement", sqle );
}
}
示例9: buildMinimalSQLExceptionConverter
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
/**
* Builds a minimal converter. The instance returned here just always converts to
* {@link org.hibernate.exception.GenericJDBCException}.
*
* @return The minimal converter.
*/
public static SQLExceptionConverter buildMinimalSQLExceptionConverter() {
return new SQLExceptionConverter() {
public JDBCException convert(SQLException sqlException, String message, String sql) {
return new GenericJDBCException( message, sqlException, sql );
}
};
}
示例10: convert
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
for ( SQLExceptionConversionDelegate delegate : delegates ) {
final JDBCException jdbcException = delegate.convert( sqlException, message, sql );
if ( jdbcException != null ) {
return jdbcException;
}
}
return new GenericJDBCException( message, sqlException, sql );
}
示例11: convertHibernateAccessException
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
protected DataAccessException convertHibernateAccessException(HibernateException ex) {
if (ex instanceof JDBCException) {
return convertJdbcAccessException((JDBCException) ex, jdbcExceptionTranslator);
}
if (GenericJDBCException.class.equals(ex.getClass())) {
return convertJdbcAccessException((GenericJDBCException) ex, jdbcExceptionTranslator);
}
return SessionFactoryUtils.convertHibernateAccessException(ex);
}
示例12: testHibernateDataGenericJDBCException
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
@Test
public void testHibernateDataGenericJDBCException() throws UNISoNException {
String articleID = "124A";
int articleNumber = 4567;
Date date = new Date();
String from = "[email protected]";
String subject = "Interesting chat";
String references = "";
String content = "This is interesting";
String newsgroups = "alt.interesting";
String postingHost = "testserver";
GenericJDBCException genericJDBCException = new GenericJDBCException("test", new BatchUpdateException(new int[]{1,2},new SQLException()), "select");
Mockito.when(this.session.beginTransaction()).thenThrow(genericJDBCException);
NewsArticle article = new NewsArticle(articleID, articleNumber, date, from, subject, references, content, newsgroups, postingHost);
this.helper.hibernateData(article, session); }
示例13: determineRowCount
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
protected int determineRowCount(int reportedRowCount, PreparedStatement statement) {
try {
return toCallableStatement( statement ).getInt( parameterPosition );
}
catch( SQLException sqle ) {
JDBCExceptionReporter.logExceptions( sqle, "could not extract row counts from CallableStatement" );
throw new GenericJDBCException( "could not extract row counts from CallableStatement", sqle );
}
}
示例14: rethrowAsDatastoreLogAll
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
public static void rethrowAsDatastoreLogAll( final HibernateException he, final Log log, final String message )
throws DatastoreException
{
final String internalMess = concMess( message, he );
if (he instanceof JDBCConnectionException || he instanceof GenericJDBCException
|| he instanceof SQLGrammarException)
{
log.error( internalMess, he );
throw new DatastoreException( internalMess, he );
}
else if (he instanceof ConstraintViolationException)
{
log.error( internalMess, he );
throw new DatastoreException( internalMess, he );
}
else if (he instanceof LockAcquisitionException)
{
log.error( internalMess, he );
throw new DatastoreException( internalMess, he );
}
else if (he instanceof QuerySyntaxException)
{
log.error( internalMess, he );
throw new DatastoreException( internalMess, he );
}
else if (he instanceof QueryException)
{
log.error( internalMess, he );
throw new DatastoreException( internalMess, he );
}
else
{
log.error( internalMess, he );
throw new DatastoreException( internalMess, he );
}
}
示例15: rethrowJdbcAsDatastore
import org.hibernate.exception.GenericJDBCException; //导入依赖的package包/类
public static void rethrowJdbcAsDatastore( final HibernateException he, final Log log, final String message, final int logErrorMask ) // NOPMD by dan on 01/02/15 07:21
throws DatastoreException
{
final String internalMess = concMess( message, he );
if (he instanceof JDBCConnectionException || he instanceof GenericJDBCException
|| he instanceof SQLGrammarException)
{
if ((logErrorMask & JDBC_IS_ERROR) != 0)
{
log.error( internalMess, he );
}
throw new DatastoreException( internalMess, he );
}
else if (he instanceof ConstraintViolationException)
{
log.error( internalMess, he );
throw new DatastoreException( internalMess, he );
}
else if (he instanceof LockAcquisitionException)
{
log.error( internalMess, he );
throw new DatastoreException( internalMess, he );
}
else if (he instanceof QuerySyntaxException)
{
log.error( internalMess, he );
throw new DatastoreException( internalMess, he );
}
else
{
log.error( internalMess, he );
throw new DatastoreException( internalMess, he );
}
}