/** * 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 ); }
/** * 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 ); }
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); } } }
@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 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(); }
private void releaseConnection() throws SQLException { if ( connection != null ) { try { new SqlExceptionHelper().logAndClearWarnings( connection ); } finally { try { serviceRegistry.getService( ConnectionProvider.class ).closeConnection( connection ); } finally { connection = null; } } } }
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; } }
public void release() throws SQLException { new SqlExceptionHelper().logAndClearWarnings( connection ); if ( toggleAutoCommit ) { connection.setAutoCommit( false ); } connection = null; }
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(); }
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(); }
public DatabaseExporter(ConnectionHelper connectionHelper, SqlExceptionHelper sqlExceptionHelper) throws SQLException { this.connectionHelper = connectionHelper; this.sqlExceptionHelper = sqlExceptionHelper; connectionHelper.prepare( true ); connection = connectionHelper.getConnection(); statement = connection.createStatement(); }
@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")); } }
private void releaseConnection() throws SQLException { if (connection != null) { try { new SqlExceptionHelper().logAndClearWarnings(connection); } finally { try { serviceRegistry.getService(ConnectionProvider.class).closeConnection(connection); } finally { connection = null; } } } }
@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; } }
public SqlExceptionHelper getSQLExceptionHelper() { return sessionFactoryImplementor.getSQLExceptionHelper(); }
protected SqlExceptionHelper getSQLExceptionHelper() { return sqlExceptionHelper; }
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 ); } } }
protected SqlExceptionHelper sqlExceptionHelper() { return transactionCoordinator.getJdbcCoordinator().getLogicalConnection().getJdbcServices().getSqlExceptionHelper(); }
protected SqlExceptionHelper sqlExceptionHelper() { return transactionCoordinator.getTransactionContext() .getTransactionEnvironment() .getJdbcServices() .getSqlExceptionHelper(); }
@Override public SqlExceptionHelper getSqlExceptionHelper() { return sqlExceptionHelper; }
protected final SqlExceptionHelper sqlExceptionHelper() { return jdbcCoordinator.getTransactionCoordinator().getTransactionContext().getTransactionEnvironment() .getJdbcServices() .getSqlExceptionHelper(); }
public SqlExceptionHelper getSQLExceptionHelper() { return getJdbcServices().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. */ public SqlExceptionHelper getSQLExceptionHelper();