Search in sources :

Example 1 with UsecaseBuilder

use of org.qi4j.api.usecase.UsecaseBuilder in project qi4j-sdk by Qi4j.

the class SQLEntityStoreMixin method queryAllEntities.

private void queryAllEntities(Module module, EntityStatesVisitor entityStatesVisitor) {
    Connection connection = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    UsecaseBuilder builder = UsecaseBuilder.buildUsecase("qi4j.entitystore.sql.visit");
    Usecase usecase = builder.withMetaInfo(CacheOptions.NEVER).newUsecase();
    final DefaultEntityStoreUnitOfWork uow = new DefaultEntityStoreUnitOfWork(entityStoreSPI, newUnitOfWorkId(), module, usecase, System.currentTimeMillis());
    try {
        connection = database.getConnection();
        ps = database.prepareGetAllEntitiesStatement(connection);
        database.populateGetAllEntitiesStatement(ps);
        rs = ps.executeQuery();
        while (rs.next()) {
            DefaultEntityState entityState = readEntityState(uow, database.getEntityValue(rs).getReader());
            if (!entityStatesVisitor.visit(entityState)) {
                return;
            }
        }
    } catch (SQLException ex) {
        throw new EntityStoreException(ex);
    } finally {
        SQLUtil.closeQuietly(rs);
        SQLUtil.closeQuietly(ps);
        SQLUtil.closeQuietly(connection);
    }
}
Also used : DefaultEntityState(org.qi4j.spi.entitystore.helpers.DefaultEntityState) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) UsecaseBuilder(org.qi4j.api.usecase.UsecaseBuilder) DefaultEntityStoreUnitOfWork(org.qi4j.spi.entitystore.DefaultEntityStoreUnitOfWork) PreparedStatement(java.sql.PreparedStatement) Usecase(org.qi4j.api.usecase.Usecase) EntityStoreException(org.qi4j.spi.entitystore.EntityStoreException)

Aggregations

Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Usecase (org.qi4j.api.usecase.Usecase)1 UsecaseBuilder (org.qi4j.api.usecase.UsecaseBuilder)1 DefaultEntityStoreUnitOfWork (org.qi4j.spi.entitystore.DefaultEntityStoreUnitOfWork)1 EntityStoreException (org.qi4j.spi.entitystore.EntityStoreException)1 DefaultEntityState (org.qi4j.spi.entitystore.helpers.DefaultEntityState)1