Search in sources :

Example 1 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 2 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();
    carIndexDefinition = definitionSpace.resolve(IDX_CAR, 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 car(ID BIGINT, MAKE 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) );");
        execCallableStatement(connection, "create sequence SEQ_CAR start with 10001 increment by 1");
    }
    // On supprime tout
    remove("*:*");
    final CarDataBase carDataBase = new CarDataBase();
    carDataBase.loadDatas();
    initialDbCarSize = carDataBase.size();
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        for (final Car car : carDataBase.getAllCars()) {
            car.setId(null);
            storeManager.getDataStore().create(car);
        }
        transaction.commit();
    }
    waitIndexation();
}
Also used : CarDataBase(io.vertigo.dynamo.search_2_4.data.domain.CarDataBase) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) 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 3 with SqlConnection

use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.

the class AbstractTaskEngineSQL method obtainConnection.

/**
 * Retourne la connexion SQL de cette transaction en la demandant au pool de connexion si nécessaire.
 * @return Connexion SQL
 */
private SqlConnection obtainConnection() {
    final VTransaction transaction = transactionManager.getCurrentTransaction();
    SqlConnection connection = transaction.getResource(getVTransactionResourceId());
    if (connection == null) {
        // On récupère une connexion du pool
        // Utilise le provider de connexion déclaré sur le Container.
        connection = getConnectionProvider().obtainConnection();
        transaction.addResource(getVTransactionResourceId(), connection);
    }
    return connection;
}
Also used : VTransaction(io.vertigo.commons.transaction.VTransaction) SqlConnection(io.vertigo.database.sql.connection.SqlConnection)

Example 4 with SqlConnection

use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.

the class AbstractSqlDataBaseManagerTest method doSetUp.

@Override
protected final void doSetUp() throws Exception {
    final SqlConnection connection = obtainMainConnection();
    try {
        execpreparedStatement(connection, createTableMovie());
        execpreparedStatement(connection, createSequenceMovie());
        if (commitRequiredOnSchemaModification()) {
            connection.commit();
        }
    } finally {
        connection.release();
    }
}
Also used : SqlConnection(io.vertigo.database.sql.connection.SqlConnection)

Example 5 with SqlConnection

use of io.vertigo.database.sql.connection.SqlConnection in project vertigo by KleeGroup.

the class AbstractSqlDataBaseManagerTest method testSelectListInput.

@Test
public void testSelectListInput() throws Exception {
    // On crée les données
    createDatas();
    // ----
    final SqlConnection connection = obtainMainConnection();
    final List<Movie> movies;
    final List<Movie> moviesParams = new ArrayList<>();
    moviesParams.add(Movies.createMovie(1, Movies.TITLE_MOVIE_1, null, null, null, null, null, null, null));
    moviesParams.add(Movies.createMovie(2, Movies.TITLE_MOVIE_2, null, null, null, null, null, null, null));
    try {
        movies = dataBaseManager.executeQuery(SqlStatement.builder("select * from movie where movie.title in (#movies.0.title#, #movies.1.title#) ").bind("movies", List.class, moviesParams).build(), Movie.class, 2, connection);
    } finally {
        connection.release();
    }
    Assert.assertEquals(2, movies.size());
}
Also used : Movie(io.vertigo.database.sql.data.Movie) ArrayList(java.util.ArrayList) SqlConnection(io.vertigo.database.sql.connection.SqlConnection) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

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