use of org.qi4j.library.sql.common.SQLConfiguration in project qi4j-sdk by Qi4j.
the class DerbySQLEntityStoreTest method tearDown.
// END SNIPPET: assembly
@Override
public void tearDown() throws Exception {
UnitOfWork uow = this.module.newUnitOfWork(UsecaseBuilder.newUsecase("Delete " + getClass().getSimpleName() + " test data"));
try {
SQLConfiguration config = uow.get(SQLConfiguration.class, DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
Connection connection = module.findService(DataSource.class).get().getConnection();
connection.setAutoCommit(false);
String schemaName = config.schemaName().get();
if (schemaName == null) {
schemaName = SQLs.DEFAULT_SCHEMA_NAME;
}
try (Statement stmt = connection.createStatement()) {
stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
connection.commit();
}
FileUtil.removeDirectory("target/qi4j-data");
} finally {
uow.discard();
super.tearDown();
}
}
use of org.qi4j.library.sql.common.SQLConfiguration in project qi4j-sdk by Qi4j.
the class MySQLEntityStoreTest method tearDown.
// END SNIPPET: assembly
@Override
public void tearDown() throws Exception {
if (true) {
return;
}
UnitOfWork uow = this.module.newUnitOfWork(UsecaseBuilder.newUsecase("Delete " + getClass().getSimpleName() + " test data"));
try {
SQLConfiguration config = uow.get(SQLConfiguration.class, MySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
Connection connection = module.findService(DataSource.class).get().getConnection();
connection.setAutoCommit(false);
String schemaName = config.schemaName().get();
if (schemaName == null) {
schemaName = SQLs.DEFAULT_SCHEMA_NAME;
}
try (Statement stmt = connection.createStatement()) {
stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
connection.commit();
}
} finally {
uow.discard();
super.tearDown();
}
}
use of org.qi4j.library.sql.common.SQLConfiguration in project qi4j-sdk by Qi4j.
the class PostgreSQLDBIntegrityTest method createAndRemoveEntityAndVerifyNoExtraDataLeftInDB.
@Test
public void createAndRemoveEntityAndVerifyNoExtraDataLeftInDB() throws Exception {
UnitOfWork uow = this.module.newUnitOfWork();
TestEntity entity = uow.newEntity(TestEntity.class);
uow.complete();
uow = this.module.newUnitOfWork();
entity = uow.get(entity);
SQLConfiguration config = uow.get(SQLConfiguration.class, PostgreSQLIndexQueryAssembler.DEFAULT_IDENTITY);
String schemaName = config.schemaName().get();
if (schemaName == null) {
schemaName = PostgreSQLAppStartup.DEFAULT_SCHEMA_NAME;
}
uow.remove(entity);
uow.complete();
Connection connection = this.module.findService(DataSource.class).get().getConnection();
try {
GenericDatabaseExplorer.visitDatabaseTables(connection, null, schemaName, null, new DatabaseProcessorAdapter() {
@Override
public void beginProcessRowInfo(String schemaNamee, String tableName, Object[] rowContents) {
if ((tableName.startsWith(DBNames.QNAME_TABLE_NAME_PREFIX) && (tableName.equals(DBNames.QNAME_TABLE_NAME_PREFIX + 0) || tableName.equals(DBNames.QNAME_TABLE_NAME_PREFIX + 1))) || tableName.equals(DBNames.ALL_QNAMES_TABLE_NAME) || tableName.equals(DBNames.ENTITY_TABLE_NAME)) {
throw new RuntimeException("Table: " + schemaNamee + "." + tableName);
}
}
}, SQLVendorProvider.createVendor(PostgreSQLVendor.class));
} finally {
SQLUtil.closeQuietly(connection);
}
}
use of org.qi4j.library.sql.common.SQLConfiguration in project qi4j-sdk by Qi4j.
the class PostgreSQLEntityStoreTest method tearDown.
// END SNIPPET: assembly
@Override
public void tearDown() throws Exception {
UnitOfWork uow = module.newUnitOfWork(UsecaseBuilder.newUsecase("Delete " + getClass().getSimpleName() + " test data"));
try {
SQLConfiguration config = uow.get(SQLConfiguration.class, PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
Connection connection = module.findService(DataSource.class).get().getConnection();
connection.setAutoCommit(false);
String schemaName = config.schemaName().get();
if (schemaName == null) {
schemaName = SQLs.DEFAULT_SCHEMA_NAME;
}
try (Statement stmt = connection.createStatement()) {
stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
connection.commit();
}
} finally {
uow.discard();
super.tearDown();
}
}
use of org.qi4j.library.sql.common.SQLConfiguration in project qi4j-sdk by Qi4j.
the class DerbySQLEntityStorePerformanceTest method cleanUp.
@Override
protected void cleanUp() throws Exception {
if (module == null) {
return;
}
UnitOfWork uow = this.module.newUnitOfWork(UsecaseBuilder.newUsecase("Delete " + getClass().getSimpleName() + " test data"));
try {
SQLConfiguration config = uow.get(SQLConfiguration.class, DerbySQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
Connection connection = module.findService(DataSource.class).get().getConnection();
String schemaName = config.schemaName().get();
if (schemaName == null) {
schemaName = SQLs.DEFAULT_SCHEMA_NAME;
}
Statement stmt = null;
try {
stmt = connection.createStatement();
stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
connection.commit();
} finally {
SQLUtil.closeQuietly(stmt);
}
} finally {
uow.discard();
super.cleanUp();
}
}
Aggregations