Java 类org.hibernate.engine.jdbc.spi.SqlExceptionHelper 实例源码
项目:lams
文件:SchemaExport.java
/**
* Create a schema exporter for the given Configuration, with the given
* database connection properties.
*
* @param configuration The configuration from which to build a schema export.
* @param properties The properties from which to configure connectivity etc.
* @throws HibernateException Indicates problem preparing for schema export.
*
* @deprecated properties may be specified via the Configuration object
*/
@Deprecated
public SchemaExport(Configuration configuration, Properties properties) throws HibernateException {
final Dialect dialect = Dialect.getDialect( properties );
Properties props = new Properties();
props.putAll( dialect.getDefaultProperties() );
props.putAll( properties );
this.connectionHelper = new ManagedProviderConnectionHelper( props );
this.sqlStatementLogger = new SqlStatementLogger( false, true );
this.formatter = FormatStyle.DDL.getFormatter();
this.sqlExceptionHelper = new SqlExceptionHelper();
this.importFiles = ConfigurationHelper.getString(
AvailableSettings.HBM2DDL_IMPORT_FILES,
properties,
DEFAULT_IMPORT_FILE
);
this.dropSQL = configuration.generateDropSchemaScript( dialect );
this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
项目:lams
文件:SchemaExport.java
/**
* Create a schema exporter for the given Configuration, using the supplied connection for connectivity.
*
* @param configuration The configuration to use.
* @param connection The JDBC connection to use.
* @throws HibernateException Indicates problem preparing for schema export.
*/
public SchemaExport(Configuration configuration, Connection connection) throws HibernateException {
this.connectionHelper = new SuppliedConnectionHelper( connection );
this.sqlStatementLogger = new SqlStatementLogger( false, true );
this.formatter = FormatStyle.DDL.getFormatter();
this.sqlExceptionHelper = new SqlExceptionHelper();
this.importFiles = ConfigurationHelper.getString(
AvailableSettings.HBM2DDL_IMPORT_FILES,
configuration.getProperties(),
DEFAULT_IMPORT_FILE
);
final Dialect dialect = Dialect.getDialect( configuration.getProperties() );
this.dropSQL = configuration.generateDropSchemaScript( dialect );
this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
项目:lams
文件:SchemaExport.java
private void execute(boolean script, boolean export, Writer fileOutput, Statement statement, final String sql)
throws IOException, SQLException {
final SqlExceptionHelper sqlExceptionHelper = new SqlExceptionHelper();
String formatted = formatter.format( sql );
if (delimiter != null) formatted += delimiter;
if (script) System.out.println(formatted);
LOG.debug(formatted);
if ( outputFile != null ) {
fileOutput.write( formatted + "\n" );
}
if ( export ) {
statement.executeUpdate( sql );
try {
SQLWarning warnings = statement.getWarnings();
if ( warnings != null) {
sqlExceptionHelper.logAndClearWarnings( connectionHelper.getConnection() );
}
}
catch( SQLException sqle ) {
LOG.unableToLogSqlWarnings(sqle);
}
}
}
项目:herd
文件:StorageServiceTest.java
@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);
}
});
}
项目:herd
文件:BusinessObjectDataServiceCreateBusinessObjectDataTest.java
@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);
}
});
}
项目:lams
文件:SchemaExport.java
public SchemaExport(
ConnectionHelper connectionHelper,
String[] dropSql,
String[] createSql) {
this.connectionHelper = connectionHelper;
this.dropSQL = dropSql;
this.createSQL = createSql;
this.importFiles = "";
this.sqlStatementLogger = new SqlStatementLogger( false, true );
this.sqlExceptionHelper = new SqlExceptionHelper();
this.formatter = FormatStyle.DDL.getFormatter();
}
项目:lams
文件:ManagedProviderConnectionHelper.java
private void releaseConnection() throws SQLException {
if ( connection != null ) {
try {
new SqlExceptionHelper().logAndClearWarnings( connection );
}
finally {
try {
serviceRegistry.getService( ConnectionProvider.class ).closeConnection( connection );
}
finally {
connection = null;
}
}
}
}
项目:lams
文件:SuppliedConnectionProviderConnectionHelper.java
public void release() throws SQLException {
// we only release the connection
if ( connection != null ) {
new SqlExceptionHelper().logAndClearWarnings( connection );
if ( toggleAutoCommit ) {
connection.setAutoCommit( false );
}
provider.closeConnection( connection );
connection = null;
}
}
项目:lams
文件:SuppliedConnectionHelper.java
public void release() throws SQLException {
new SqlExceptionHelper().logAndClearWarnings( connection );
if ( toggleAutoCommit ) {
connection.setAutoCommit( false );
}
connection = null;
}
项目:lams
文件:SchemaUpdate.java
public SchemaUpdate(Configuration configuration, Properties properties) throws HibernateException {
this.configuration = configuration;
this.dialect = Dialect.getDialect( properties );
Properties props = new Properties();
props.putAll( dialect.getDefaultProperties() );
props.putAll( properties );
this.connectionHelper = new ManagedProviderConnectionHelper( props );
this.sqlExceptionHelper = new SqlExceptionHelper();
this.sqlStatementLogger = new SqlStatementLogger( false, true );
this.formatter = FormatStyle.DDL.getFormatter();
}
项目:lams
文件:SchemaUpdate.java
public SchemaUpdate(ServiceRegistry serviceRegistry, Configuration cfg) throws HibernateException {
this.configuration = cfg;
final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
this.dialect = jdbcServices.getDialect();
this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( jdbcServices.getConnectionProvider() );
this.sqlExceptionHelper = new SqlExceptionHelper();
this.sqlStatementLogger = jdbcServices.getSqlStatementLogger();
this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
}
项目:lams
文件:DatabaseExporter.java
public DatabaseExporter(ConnectionHelper connectionHelper, SqlExceptionHelper sqlExceptionHelper) throws SQLException {
this.connectionHelper = connectionHelper;
this.sqlExceptionHelper = sqlExceptionHelper;
connectionHelper.prepare( true );
connection = connectionHelper.getConnection();
statement = connection.createStatement();
}
项目:herd
文件:BusinessObjectFormatServiceTest.java
@Test
public void testCreateBusinessObjectFormatIncorrectLatestVersion() throws Exception
{
// Create relative database entities.
businessObjectFormatServiceTestHelper.createTestDatabaseEntitiesForBusinessObjectFormatTesting();
// Create a first version of the format with the latest flag set to false.
businessObjectFormatDaoTestHelper
.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, false,
PARTITION_KEY);
try
{
// Try to create a new format version for this format.
final BusinessObjectFormatCreateRequest businessObjectFormatCreateRequest = businessObjectFormatServiceTestHelper
.createBusinessObjectFormatCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_KEY, FORMAT_DESCRIPTION,
businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectFormatServiceTestHelper.getTestAttributeDefinitions(),
businessObjectFormatServiceTestHelper.getTestSchema());
executeWithoutLogging(SqlExceptionHelper.class, new Command()
{
@Override
public void execute()
{
businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest);
fail("Should throw a PersistenceException since the latest flag does not identify the maximum format version.");
}
});
}
catch (PersistenceException e)
{
assertTrue(e.getMessage().contains("ConstraintViolationException: could not execute statement"));
}
}
项目:books
文件:ManagedProvidedConnectionHelper.java
private void releaseConnection() throws SQLException {
if (connection != null) {
try {
new SqlExceptionHelper().logAndClearWarnings(connection);
} finally {
try {
serviceRegistry.getService(ConnectionProvider.class).closeConnection(connection);
} finally {
connection = null;
}
}
}
}
项目:books
文件:SuppliedConnectionProviderConnectionHelper.java
@Override
public void release() throws SQLException {
// we only release the connection
if ( connection != null ) {
new SqlExceptionHelper().logAndClearWarnings( connection );
if ( toggleAutoCommit ) {
connection.setAutoCommit( false );
}
provider.closeConnection( connection );
connection = null;
}
}
项目:lemon
文件:SessionFactoryWrapper.java
public SqlExceptionHelper getSQLExceptionHelper() {
return sessionFactoryImplementor.getSQLExceptionHelper();
}
项目:lams
文件:AbstractCollectionPersister.java
protected SqlExceptionHelper getSQLExceptionHelper() {
return sqlExceptionHelper;
}
项目:lams
文件:DatabaseMetadata.java
public TableMetadata getTableMetadata(String name, String schema, String catalog, boolean isQuoted) throws HibernateException {
Object identifier = identifier(catalog, schema, name);
TableMetadata table = (TableMetadata) tables.get(identifier);
if (table!=null) {
return table;
}
else {
try {
ResultSet rs = null;
try {
if ( (isQuoted && meta.storesMixedCaseQuotedIdentifiers())) {
rs = meta.getTables(catalog, schema, name, types);
} else if ( (isQuoted && meta.storesUpperCaseQuotedIdentifiers())
|| (!isQuoted && meta.storesUpperCaseIdentifiers() )) {
rs = meta.getTables(
StringHelper.toUpperCase(catalog),
StringHelper.toUpperCase(schema),
StringHelper.toUpperCase(name),
types
);
}
else if ( (isQuoted && meta.storesLowerCaseQuotedIdentifiers())
|| (!isQuoted && meta.storesLowerCaseIdentifiers() )) {
rs = meta.getTables(
StringHelper.toLowerCase( catalog ),
StringHelper.toLowerCase(schema),
StringHelper.toLowerCase(name),
types
);
}
else {
rs = meta.getTables(catalog, schema, name, types);
}
while ( rs.next() ) {
String tableName = rs.getString("TABLE_NAME");
if ( name.equalsIgnoreCase(tableName) ) {
table = new TableMetadata(rs, meta, extras);
tables.put(identifier, table);
return table;
}
}
LOG.tableNotFound( name );
return null;
}
finally {
if ( rs != null ) {
rs.close();
}
}
}
catch (SQLException sqlException) {
throw new SqlExceptionHelper( sqlExceptionConverter )
.convert( sqlException, "could not get table metadata: " + name );
}
}
}
项目:lams
文件:JdbcIsolationDelegate.java
protected SqlExceptionHelper sqlExceptionHelper() {
return transactionCoordinator.getJdbcCoordinator().getLogicalConnection().getJdbcServices().getSqlExceptionHelper();
}
项目:lams
文件:JtaIsolationDelegate.java
protected SqlExceptionHelper sqlExceptionHelper() {
return transactionCoordinator.getTransactionContext()
.getTransactionEnvironment()
.getJdbcServices()
.getSqlExceptionHelper();
}
项目:lams
文件:JdbcServicesImpl.java
@Override
public SqlExceptionHelper getSqlExceptionHelper() {
return sqlExceptionHelper;
}
项目:lams
文件:StatementPreparerImpl.java
protected final SqlExceptionHelper sqlExceptionHelper() {
return jdbcCoordinator.getTransactionCoordinator().getTransactionContext().getTransactionEnvironment()
.getJdbcServices()
.getSqlExceptionHelper();
}
项目:lams
文件:SessionFactoryImpl.java
public SqlExceptionHelper getSQLExceptionHelper() {
return getJdbcServices().getSqlExceptionHelper();
}
项目:hibernate-dynamic-dialects
文件:SessionFactoryImpl.java
public SqlExceptionHelper getSQLExceptionHelper() {
return getJdbcServices().getSqlExceptionHelper();
}
项目:lams
文件:JdbcCoordinatorImpl.java
/**
* Access to the SqlExceptionHelper
*
* @return The SqlExceptionHelper
*/
public SqlExceptionHelper sqlExceptionHelper() {
return exceptionHelper;
}
项目:lams
文件:AbstractBatchImpl.java
/**
* Convenience access to the SQLException helper.
*
* @return The underlying SQLException helper.
*/
protected SqlExceptionHelper sqlExceptionHelper() {
return sqlExceptionHelper;
}
项目:lams
文件:SessionFactoryImplementor.java
/**
* Retrieves the SqlExceptionHelper in effect for this SessionFactory.
*
* @return The SqlExceptionHelper for this SessionFactory.
*/
public SqlExceptionHelper getSQLExceptionHelper();