use of org.hibernate.tool.schema.spi.CommandAcceptanceException in project hibernate-orm by hibernate.
the class AbstractScriptTargetOutput method accept.
@Override
public void accept(String command) {
try {
writer().write(command);
writer().write(System.lineSeparator());
writer().flush();
} catch (IOException e) {
throw new CommandAcceptanceException("Could not write to target script file", e);
}
}
use of org.hibernate.tool.schema.spi.CommandAcceptanceException in project hibernate-orm by hibernate.
the class SchemaToolTransactionHandlingTest method testDropCreateDropInExistingJtaTransaction.
// for each case we want to run these tool delegates in a matrix of:
// 1) JTA versus JDBC transaction handling
// 2) existing transaction versus not
//
// cases:
// 1) create-drop
// 2) update
// 3) validate
//
// so:
// 1) create-drop
// 1.1) JTA transaction handling
// 1.1.1) inside an existing transaction
// 1.1.2) outside any transaction
// 1.1) JDBC transaction handling
// - there really cannot be an "existing transaction" case...
@Test
public void testDropCreateDropInExistingJtaTransaction() {
// start a JTA transaction...
try {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
} catch (Exception e) {
throw new RuntimeException("Unable to being JTA transaction prior to starting test", e);
}
// hold reference to Transaction object
final Transaction jtaTransaction;
try {
jtaTransaction = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().getTransaction();
} catch (SystemException e) {
throw new RuntimeException("Unable to access JTA Transaction prior to starting test", e);
}
final StandardServiceRegistry registry = buildJtaStandardServiceRegistry();
// perform the test...
try {
final SchemaManagementTool smt = registry.getService(SchemaManagementTool.class);
final SchemaDropper schemaDropper = smt.getSchemaDropper(Collections.emptyMap());
final SchemaCreator schemaCreator = smt.getSchemaCreator(Collections.emptyMap());
final Metadata mappings = buildMappings(registry);
try {
try {
schemaDropper.doDrop(mappings, ExecutionOptionsTestImpl.INSTANCE, SourceDescriptorImpl.INSTANCE, TargetDescriptorImpl.INSTANCE);
} catch (CommandAcceptanceException e) {
//ignore may happen if sql drop does not support if exist
}
schemaCreator.doCreation(mappings, ExecutionOptionsTestImpl.INSTANCE, SourceDescriptorImpl.INSTANCE, TargetDescriptorImpl.INSTANCE);
} finally {
try {
schemaDropper.doDrop(mappings, ExecutionOptionsTestImpl.INSTANCE, SourceDescriptorImpl.INSTANCE, TargetDescriptorImpl.INSTANCE);
} catch (Exception ignore) {
// ignore
}
}
} finally {
try {
jtaTransaction.commit();
((StandardServiceRegistryImpl) registry).destroy();
} catch (Exception e) {
// not much we can do...
}
}
}
use of org.hibernate.tool.schema.spi.CommandAcceptanceException in project hibernate-orm by hibernate.
the class GenerationTargetToDatabase method accept.
@Override
public void accept(String command) {
ddlTransactionIsolator.getJdbcContext().getSqlStatementLogger().logStatement(command, DDLFormatterImpl.INSTANCE);
try {
final Statement jdbcStatement = jdbcStatement();
jdbcStatement.execute(command);
try {
SQLWarning warnings = jdbcStatement.getWarnings();
if (warnings != null) {
ddlTransactionIsolator.getJdbcContext().getSqlExceptionHelper().logAndClearWarnings(jdbcStatement);
}
} catch (SQLException e) {
log.unableToLogSqlWarnings(e);
}
} catch (SQLException e) {
throw new CommandAcceptanceException("Error executing DDL via JDBC Statement", e);
}
}
Aggregations