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());
}
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();
}
}
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"));
}
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);
}
}
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();
}
}
Aggregations