Search in sources :

Example 1 with RowBounds

use of org.apache.ibatis.session.RowBounds in project sonarqube by SonarSource.

the class ComponentDaoTest method select_provisioned.

@Test
public void select_provisioned() {
    OrganizationDto organization = db.organizations().insert();
    ComponentDto provisionedProject = db.components().insertComponent(newProjectDto(organization).setKey("provisioned.project").setName("Provisioned Project"));
    ComponentDto provisionedView = db.components().insertView(organization);
    String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization)).getComponentUuid();
    String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization).setEnabled(false)).getComponentUuid();
    String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid();
    Set<String> projectQualifiers = newHashSet(Qualifiers.PROJECT);
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, projectQualifiers, new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsOnly(provisionedProject.uuid());
    // pagination
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, projectQualifiers, new RowBounds(2, 10))).isEmpty();
    // filter on qualifiers
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet("XXX"), new RowBounds(0, 10))).isEmpty();
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.PROJECT, "XXX"), new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsOnly(provisionedProject.uuid());
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.PROJECT, Qualifiers.VIEW), new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsOnly(provisionedProject.uuid(), provisionedView.uuid());
    // match key
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), provisionedProject.getKey(), projectQualifiers, new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsExactly(provisionedProject.uuid());
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "pROvisiONed.proJEcT", projectQualifiers, new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsExactly(provisionedProject.uuid());
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "missing", projectQualifiers, new RowBounds(0, 10))).isEmpty();
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "to be escaped '\"\\%", projectQualifiers, new RowBounds(0, 10))).isEmpty();
    // match name
    assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "ned proj", projectQualifiers, new RowBounds(0, 10))).extracting(ComponentDto::uuid).containsExactly(provisionedProject.uuid());
}
Also used : RowBounds(org.apache.ibatis.session.RowBounds) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 2 with RowBounds

use of org.apache.ibatis.session.RowBounds in project sonarqube by SonarSource.

the class ProvisionedAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    SearchOptions options = new SearchOptions().setPage(request.mandatoryParamAsInt(Param.PAGE), request.mandatoryParamAsInt(Param.PAGE_SIZE));
    Set<String> desiredFields = desiredFields(request);
    String query = request.param(Param.TEXT_QUERY);
    try (DbSession dbSession = dbClient.openSession(false)) {
        OrganizationDto organization = support.getOrganization(dbSession, request.getParam(PARAM_ORGANIZATION).or(defaultOrganizationProvider.get()::getKey));
        userSession.checkPermission(PROVISION_PROJECTS, organization);
        RowBounds rowBounds = new RowBounds(options.getOffset(), options.getLimit());
        List<ComponentDto> projects = dbClient.componentDao().selectProvisioned(dbSession, organization.getUuid(), query, QUALIFIERS_FILTER, rowBounds);
        int nbOfProjects = dbClient.componentDao().countProvisioned(dbSession, organization.getUuid(), query, QUALIFIERS_FILTER);
        JsonWriter json = response.newJsonWriter().beginObject();
        writeProjects(projects, json, desiredFields);
        options.writeJson(json, nbOfProjects);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) RowBounds(org.apache.ibatis.session.RowBounds) SearchOptions(org.sonar.server.es.SearchOptions) JsonWriter(org.sonar.api.utils.text.JsonWriter) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 3 with RowBounds

use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.

the class DefaultResultSetHandlerTest method shouldRetainColumnNameCase.

/**
   * Contrary to the spec, some drivers require case-sensitive column names when getting result.
   * 
   * @see <a href="http://code.google.com/p/mybatis/issues/detail?id=557">Issue 557</a>
   */
@Test
public void shouldRetainColumnNameCase() throws Exception {
    final MappedStatement ms = getMappedStatement();
    final Executor executor = null;
    final ParameterHandler parameterHandler = null;
    final ResultHandler resultHandler = null;
    final BoundSql boundSql = null;
    final RowBounds rowBounds = new RowBounds(0, 100);
    final DefaultResultSetHandler fastResultSetHandler = new DefaultResultSetHandler(executor, ms, parameterHandler, resultHandler, boundSql, rowBounds);
    when(stmt.getResultSet()).thenReturn(rs);
    when(rs.getMetaData()).thenReturn(rsmd);
    when(rs.getType()).thenReturn(ResultSet.TYPE_FORWARD_ONLY);
    when(rs.next()).thenReturn(true).thenReturn(false);
    when(rs.getInt("CoLuMn1")).thenReturn(100);
    when(rs.wasNull()).thenReturn(false);
    when(rsmd.getColumnCount()).thenReturn(1);
    when(rsmd.getColumnLabel(1)).thenReturn("CoLuMn1");
    when(rsmd.getColumnType(1)).thenReturn(Types.INTEGER);
    when(rsmd.getColumnClassName(1)).thenReturn(Integer.class.getCanonicalName());
    when(stmt.getConnection()).thenReturn(conn);
    when(conn.getMetaData()).thenReturn(dbmd);
    // for simplicity.
    when(dbmd.supportsMultipleResultSets()).thenReturn(false);
    final List<Object> results = fastResultSetHandler.handleResultSets(stmt);
    assertEquals(1, results.size());
    assertEquals(Integer.valueOf(100), ((HashMap) results.get(0)).get("cOlUmN1"));
}
Also used : ParameterHandler(org.apache.ibatis.executor.parameter.ParameterHandler) Executor(org.apache.ibatis.executor.Executor) BoundSql(org.apache.ibatis.mapping.BoundSql) RowBounds(org.apache.ibatis.session.RowBounds) MappedStatement(org.apache.ibatis.mapping.MappedStatement) ResultHandler(org.apache.ibatis.session.ResultHandler) Test(org.junit.Test)

Example 4 with RowBounds

use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.

the class BaseExecutorTest method shouldSelect2DiscriminatedPosts.

@Test
public void shouldSelect2DiscriminatedPosts() throws Exception {
    Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
    try {
        MappedStatement selectStatement = ExecutorTestHelper.prepareSelectDiscriminatedPost(config);
        List<Map<String, String>> products = executor.query(selectStatement, null, new RowBounds(2, 2), Executor.NO_RESULT_HANDLER);
        assertEquals(2, products.size());
        for (Map<String, String> m : products) {
            if ("IMAGES".equals(m.get("SECTION"))) {
                assertNull(m.get("subject"));
            } else {
                assertNotNull(m.get("subject"));
            }
        }
    } finally {
        executor.rollback(true);
        executor.close(false);
    }
}
Also used : JdbcTransaction(org.apache.ibatis.transaction.jdbc.JdbcTransaction) RowBounds(org.apache.ibatis.session.RowBounds) MappedStatement(org.apache.ibatis.mapping.MappedStatement) HashMap(java.util.HashMap) Map(java.util.Map) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 5 with RowBounds

use of org.apache.ibatis.session.RowBounds in project generator by mybatis.

the class FlatJava5Test method testPKFieldsSelectByExampleBetweenWithRowbounds.

@Test
public void testPKFieldsSelectByExampleBetweenWithRowbounds() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
        Pkfields record = new Pkfields();
        record.setFirstname("Fred");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(1);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Wilma");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(2);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Pebbles");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(3);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Barney");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(1);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Betty");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(2);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Bamm Bamm");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(3);
        mapper.insert(record);
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andId2Between(1, 3);
        example.setOrderByClause("ID1, ID2");
        RowBounds rb = new RowBounds(2, 3);
        List<Pkfields> answer = mapper.selectByExampleWithRowbounds(example, rb);
        assertEquals(3, answer.size());
        assertEquals("Pebbles", answer.get(0).getFirstname());
        assertEquals("Barney", answer.get(1).getFirstname());
        assertEquals("Betty", answer.get(2).getFirstname());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.annotated.flat.mapper.PkfieldsMapper) RowBounds(org.apache.ibatis.session.RowBounds) Pkfields(mbg.test.mb3.generated.annotated.flat.model.Pkfields) PkfieldsExample(mbg.test.mb3.generated.annotated.flat.model.PkfieldsExample) Test(org.junit.Test)

Aggregations

RowBounds (org.apache.ibatis.session.RowBounds)45 Test (org.junit.Test)35 SqlSession (org.apache.ibatis.session.SqlSession)31 Country (com.github.pagehelper.model.Country)14 CountryMapper (com.github.pagehelper.mapper.CountryMapper)7 BaseDataTest (org.apache.ibatis.BaseDataTest)7 MappedStatement (org.apache.ibatis.mapping.MappedStatement)7 HashMap (java.util.HashMap)6 PageInfo (com.github.pagehelper.PageInfo)4 Executor (org.apache.ibatis.executor.Executor)4 BoundSql (org.apache.ibatis.mapping.BoundSql)4 MetaObject (org.apache.ibatis.reflection.MetaObject)4 ResultHandler (org.apache.ibatis.session.ResultHandler)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 CacheKey (org.apache.ibatis.cache.CacheKey)3 Blog (org.apache.ibatis.domain.blog.Blog)3 DraftPost (org.apache.ibatis.domain.blog.DraftPost)3 Post (org.apache.ibatis.domain.blog.Post)3