use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.
the class SqlConnectionProviderPlugin method checkTestSelect.
@HealthChecked(name = "testQuery", feature = "sqlDatabase")
default HealthMeasure checkTestSelect() {
final HealthMeasureBuilder healthMeasureBuilder = HealthMeasure.builder();
final String testQuery = getDataBase().getSqlDialect().getTestQuery();
try {
final SqlDataBaseManager sqlDataBaseManager = Home.getApp().getComponentSpace().resolve(SqlDataBaseManager.class);
final SqlConnection connection = obtainConnection();
try {
sqlDataBaseManager.executeQuery(SqlStatement.builder(testQuery).build(), Integer.class, 1, connection);
} finally {
connection.release();
}
healthMeasureBuilder.withGreenStatus();
} catch (final Exception e) {
healthMeasureBuilder.withRedStatus(e.getMessage(), e);
}
return healthMeasureBuilder.build();
}
use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.
the class AbstractTaskEngineSQL method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
final SqlConnection connection = obtainConnection();
final SqlStatementBuilder statementBuilder = SqlStatement.builder(getSqlQuery().trim());
setNamedParameters(statementBuilder);
final SqlStatement sqlStatement = statementBuilder.build();
try {
// Execute le Statement JDBC.
final OptionalInt sqlRowcountOpt = doExecute(sqlStatement, connection);
// On positionne le nombre de lignes affectées.
sqlRowcountOpt.ifPresent(this::setRowCount);
} catch (final BatchUpdateException sqle) {
// Gère les erreurs d'exécution Batch JDBC.
throw handleSQLException(connection, sqle.getNextException(), sqlStatement.getSqlQuery());
} catch (final SQLException sqle) {
// Gère les erreurs d'exécution JDBC.
throw handleSQLException(connection, sqle, sqlStatement.getSqlQuery());
}
}
use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.
the class SearchManagerStoreTest method doSetUp.
@Override
protected void doSetUp() throws Exception {
final DefinitionSpace definitionSpace = getApp().getDefinitionSpace();
itemIndexDefinition = definitionSpace.resolve(IDX_ITEM, SearchIndexDefinition.class);
// A chaque test on recrée la table famille
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final SqlConnection connection = dataBaseManager.getConnectionProvider(SqlDataBaseManager.MAIN_CONNECTION_PROVIDER_NAME).obtainConnection();
execCallableStatement(connection, "create table item(ID BIGINT, MANUFACTURER varchar(50), MODEL varchar(255), DESCRIPTION varchar(512), YEAR INT, KILO INT, PRICE INT, CONSOMMATION NUMERIC(8,2), MOTOR_TYPE varchar(50), OPTIONAL_NUMBER BIGINT, OPTIONAL_STRING varchar(50), LAST_MODIFIED timestamp );");
execCallableStatement(connection, "create sequence SEQ_ITEM start with 10001 increment by 1");
}
// On supprime tout
remove("*:*");
final ItemDataBase itemDataBase = new ItemDataBase();
initialDbItemSize = itemDataBase.size();
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
for (final Item item : itemDataBase.getAllItems()) {
item.setId(null);
storeManager.getDataStore().create(item);
}
transaction.commit();
}
waitIndexation();
}
use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.
the class SearchManagerStoreTest method doTearDown.
/**
* {@inheritDoc}
*/
@Override
protected void doTearDown() throws Exception {
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
// A chaque fin de test on arréte la base.
final SqlConnection connection = dataBaseManager.getConnectionProvider(SqlDataBaseManager.MAIN_CONNECTION_PROVIDER_NAME).obtainConnection();
execCallableStatement(connection, "shutdown;");
transaction.commit();
}
}
use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.
the class AbstractSqlDataBaseManagerTest method doTearDown.
@Override
protected final void doTearDown() throws Exception {
final SqlConnection connection = obtainMainConnection();
try {
// we use a shared database so we need to drop the table
execpreparedStatement(connection, DROP_SEQUENCE_MOVIE);
execpreparedStatement(connection, DROP_TABLE_MOVIE);
if (commitRequiredOnSchemaModification()) {
connection.commit();
}
} finally {
connection.release();
}
}
Aggregations