下面列出了org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess#org.hibernate.engine.jdbc.spi.SqlExceptionHelper 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Ignore
@Test(expected = PersistenceException.class)
public void testDeleteStorageConstraintViolation() throws Exception
{
// Create a storage unit entity that refers to a newly created storage.
final StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper
.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE,
SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
executeWithoutLogging(SqlExceptionHelper.class, new Command()
{
@Override
public void execute()
{
// Delete the storage which is invalid because there still exists a storage unit entity that references it.
StorageKey alternateKey = new StorageKey(storageUnitEntity.getStorage().getName());
storageService.deleteStorage(alternateKey);
}
});
}
@Test(expected = PersistenceException.class)
public void testCreateBusinessObjectDataAttributeValueTooLarge() throws Exception
{
final BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest();
// Create and add a duplicate attribute which is not allowed.
Attribute newAttribute = new Attribute();
newAttribute.setName("Valid Name");
newAttribute.setValue(new String(new char[4001]).replace('\0', 'A')); // Test value greater than 4000 byte limit.
businessObjectDataCreateRequest.getAttributes().add(newAttribute);
executeWithoutLogging(SqlExceptionHelper.class, new Command()
{
@Override
public void execute()
{
// Create the business object data which is invalid.
businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest);
}
});
}
public JtaIsolationDelegate(
JdbcConnectionAccess connectionAccess,
SqlExceptionHelper sqlExceptionHelper,
TransactionManager transactionManager) {
this.connectionAccess = connectionAccess;
this.sqlExceptionHelper = sqlExceptionHelper;
this.transactionManager = transactionManager;
}
public DatabaseExporter(ConnectionHelper connectionHelper, SqlExceptionHelper sqlExceptionHelper) throws SQLException {
this.connectionHelper = connectionHelper;
this.sqlExceptionHelper = sqlExceptionHelper;
connectionHelper.prepare( true );
connection = connectionHelper.getConnection();
statement = connection.createStatement();
}
private JdbcContextImpl(
JdbcConnectionAccess jdbcConnectionAccess,
Dialect dialect,
SqlStatementLogger sqlStatementLogger,
SqlExceptionHelper sqlExceptionHelper,
ServiceRegistry serviceRegistry) {
this.jdbcConnectionAccess = jdbcConnectionAccess;
this.dialect = dialect;
this.sqlStatementLogger = sqlStatementLogger;
this.sqlExceptionHelper = sqlExceptionHelper;
this.serviceRegistry = serviceRegistry;
}
@SuppressWarnings("deprecation")
private SqlExceptionHelper buildSqlExceptionHelper(Dialect dialect, boolean logWarnings) {
final StandardSQLExceptionConverter sqlExceptionConverter = new StandardSQLExceptionConverter();
sqlExceptionConverter.addDelegate( dialect.buildSQLExceptionConversionDelegate() );
sqlExceptionConverter.addDelegate( new SQLExceptionTypeDelegate( dialect ) );
// todo : vary this based on extractedMetaDataSupport.getSqlStateType()
sqlExceptionConverter.addDelegate( new SQLStateConversionDelegate( dialect ) );
return new SqlExceptionHelper( sqlExceptionConverter, logWarnings );
}
@Override
public SqlExceptionHelper getSqlExceptionHelper() {
if ( jdbcEnvironment != null ) {
return jdbcEnvironment.getSqlExceptionHelper();
}
return null;
}
@Override @SuppressWarnings("unchecked")
public <R extends Service> R getService(Class<R> serviceRole) {
if ( serviceRole == VertxInstance.class ) {
return (R) vertxService;
}
else if ( serviceRole == JdbcEnvironment.class ) {
return (R) new JdbcEnvironment() {
@Override
public Dialect getDialect() {
return new MySQL8Dialect();
}
@Override
public ExtractedDatabaseMetaData getExtractedDatabaseMetaData() {
return null;
}
@Override
public Identifier getCurrentCatalog() {
return null;
}
@Override
public Identifier getCurrentSchema() {
return null;
}
@Override
public QualifiedObjectNameFormatter getQualifiedObjectNameFormatter() {
return null;
}
@Override
public IdentifierHelper getIdentifierHelper() {
return null;
}
@Override
public NameQualifierSupport getNameQualifierSupport() {
return null;
}
@Override
public SqlExceptionHelper getSqlExceptionHelper() {
return null;
}
@Override
public LobCreatorBuilder getLobCreatorBuilder() {
return null;
}
@Override
public TypeInfo getTypeInfoForJdbcCode(int jdbcTypeCode) {
return null;
}
};
}
else {
throw new IllegalArgumentException( "This is a mock service - need to explicitly handle any service we might need during testing" );
}
}
public JdbcIsolationDelegate(JdbcConnectionAccess connectionAccess, SqlExceptionHelper sqlExceptionHelper) {
this.connectionAccess = connectionAccess;
this.sqlExceptionHelper = sqlExceptionHelper;
}
protected SqlExceptionHelper sqlExceptionHelper() {
return this.sqlExceptionHelper;
}
protected SqlExceptionHelper sqlExceptionHelper() {
return this.sqlExceptionHelper;
}
protected SqlExceptionHelper getSQLExceptionHelper() {
return sqlExceptionHelper;
}
public SuppliedConnectionProviderConnectionHelper(ConnectionProvider provider, SqlExceptionHelper sqlExceptionHelper) {
this.provider = provider;
this.sqlExceptionHelper = sqlExceptionHelper;
}
public SuppliedConnectionHelper(Connection connection, SqlExceptionHelper sqlExceptionHelper) {
this.connection = connection;
this.sqlExceptionHelper = sqlExceptionHelper;
}
@Override
public SqlExceptionHelper getSqlExceptionHelper() {
return sqlExceptionHelper;
}
@Override
public SqlExceptionHelper getSqlExceptionHelper() {
return jdbcServices.getSqlExceptionHelper();
}
@Override
public SqlExceptionHelper getSqlExceptionHelper() {
return sqlExceptionHelper;
}
protected final SqlExceptionHelper sqlExceptionHelper() {
return getJdbcService().getSqlExceptionHelper();
}
@Override
public SqlExceptionHelper getSQLExceptionHelper() {
return delegate.getSQLExceptionHelper();
}
public SqlExceptionHelper getSQLExceptionHelper() {
return sessionFactoryImplementor.getSQLExceptionHelper();
}
/**
* Obtain the helper for dealing with JDBC {@link java.sql.SQLException} faults.
*
* @return This environment's helper.
*/
SqlExceptionHelper getSqlExceptionHelper();
/**
* Access to the SqlExceptionHelper
*
* @return The SqlExceptionHelper
*/
public SqlExceptionHelper sqlExceptionHelper() {
return exceptionHelper;
}
/**
* Convenience access to the SQLException helper.
*
* @return The underlying SQLException helper.
*/
protected SqlExceptionHelper sqlExceptionHelper() {
return sqlExceptionHelper;
}
/**
* Retrieves the SqlExceptionHelper in effect for this SessionFactory.
*
* @return The SqlExceptionHelper for this SessionFactory.
*
* @deprecated since 5.0; use {@link JdbcServices#getSqlExceptionHelper()} instead as
* obtained from {@link #getServiceRegistry()}
*/
@Deprecated
default SqlExceptionHelper getSQLExceptionHelper() {
return getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper();
}
SqlExceptionHelper getSqlExceptionHelper();