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


Java GenericJDBCException类代码示例

本文整理汇总了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);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:HibernateTemplateTests.java

示例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;
}
 
开发者ID:leonarduk,项目名称:unison,代码行数:31,代码来源:HibernateHelper.java

示例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);
}
 
开发者ID:conwetlab,项目名称:fiware-rss,代码行数:25,代码来源:FactoryResponse.java

示例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);
}
 
开发者ID:conwetlab,项目名称:fiware-rss,代码行数:25,代码来源:FactoryResponse.java

示例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);
        }
    };
}
 
开发者ID:sensepost,项目名称:yeti,代码行数:21,代码来源:SQLiteDialect.java

示例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);
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:16,代码来源:SQLiteSQLExceptionConversionDelegate.java

示例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());
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:10,代码来源:SQLiteSQLExceptionConversionDelegateTest.java

示例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 );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:Expectations.java

示例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 );
		}
	};
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:SQLExceptionConverterFactory.java

示例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 );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:StandardSQLExceptionConverter.java

示例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);
}
 
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:10,代码来源:GrailsHibernateTemplate.java

示例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);	}
 
开发者ID:leonarduk,项目名称:unison,代码行数:16,代码来源:HibernateHelperTest.java

示例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 );
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:10,代码来源:Expectations.java

示例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 );
	}
}
 
开发者ID:danielhams,项目名称:mad-java,代码行数:37,代码来源:HibernateExceptionHandler.java

示例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 );
	}
}
 
开发者ID:danielhams,项目名称:mad-java,代码行数:35,代码来源:HibernateExceptionHandler.java


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