Search in sources :

Example 11 with SqlConnection

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();
}
Also used : HealthMeasureBuilder(io.vertigo.commons.analytics.health.HealthMeasureBuilder) SqlDataBaseManager(io.vertigo.database.sql.SqlDataBaseManager) SqlConnection(io.vertigo.database.sql.connection.SqlConnection) HealthChecked(io.vertigo.commons.analytics.health.HealthChecked)

Example 12 with SqlConnection

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());
    }
}
Also used : SqlStatement(io.vertigo.database.sql.statement.SqlStatement) SqlStatementBuilder(io.vertigo.database.sql.statement.SqlStatementBuilder) SQLException(java.sql.SQLException) SqlConnection(io.vertigo.database.sql.connection.SqlConnection) OptionalInt(java.util.OptionalInt) BatchUpdateException(java.sql.BatchUpdateException)

Example 13 with SqlConnection

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();
}
Also used : Item(io.vertigo.dynamo.search.data.domain.Item) ItemDataBase(io.vertigo.dynamo.search.data.domain.ItemDataBase) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) SqlConnection(io.vertigo.database.sql.connection.SqlConnection)

Example 14 with SqlConnection

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();
    }
}
Also used : VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) SqlConnection(io.vertigo.database.sql.connection.SqlConnection)

Example 15 with SqlConnection

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();
    }
}
Also used : SqlConnection(io.vertigo.database.sql.connection.SqlConnection)

Aggregations

SqlConnection (io.vertigo.database.sql.connection.SqlConnection)18 Test (org.junit.Test)7 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)5 Movie (io.vertigo.database.sql.data.Movie)5 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)2 SqlDataBaseManager (io.vertigo.database.sql.SqlDataBaseManager)2 SqlConnectionProvider (io.vertigo.database.sql.connection.SqlConnectionProvider)2 SqlStatementBuilder (io.vertigo.database.sql.statement.SqlStatementBuilder)2 SearchIndexDefinition (io.vertigo.dynamo.search.metamodel.SearchIndexDefinition)2 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 OptionalInt (java.util.OptionalInt)2 HealthChecked (io.vertigo.commons.analytics.health.HealthChecked)1 HealthMeasureBuilder (io.vertigo.commons.analytics.health.HealthMeasureBuilder)1 VTransaction (io.vertigo.commons.transaction.VTransaction)1 ResourceManager (io.vertigo.core.resource.ResourceManager)1 SqlParameter (io.vertigo.database.sql.statement.SqlParameter)1 SqlStatement (io.vertigo.database.sql.statement.SqlStatement)1