/** * Create a PreparedStatement for SELECT requests with scrolling of results */ public PreparedStatement newScrollingSelectStatement(DbSession session, String sql) { int fetchSize = database.getDialect().getScrollDefaultFetchSize(); return newScrollingSelectStatement(session, sql, fetchSize); }
@CheckForNull public PropertyDto selectProjectProperty(long componentId, String propertyKey) { try (DbSession session = mybatis.openSession(false)) { return selectProjectProperty(session, componentId, propertyKey); } }
@Test public void shouldOpenBatchSession() { underTest.start(); try (DbSession session = underTest.openSession(false)) { assertThat(session.getConnection(), notNullValue()); assertThat(session.getMapper(RuleMapper.class), notNullValue()); } } }
@Test public void shouldConfigureMyBatis() { underTest.start(); Configuration conf = underTest.getSessionFactory().getConfiguration(); assertThat(conf.isUseGeneratedKeys(), Is.is(true)); assertThat(conf.hasMapper(RuleMapper.class), Is.is(true)); assertThat(conf.isLazyLoadingEnabled(), Is.is(false)); }
public Collection<QualityGateConditionDto> selectForQualityGate(long qGateId) { SqlSession session = myBatis.openSession(false); try { return selectForQualityGate(qGateId, session); } finally { MyBatis.closeQuietly(session); } }
public void closeSession(@Nullable DbSession session) { MyBatis.closeQuietly(session); }
public static PreparedStatement preparedStatementToSelectFileSources(DbClient dbClient, DbSession session, String dataType, @Nullable String projectUuid) throws SQLException { String sql = createSQL(dataType, projectUuid); // rows are big, so they are scrolled once at a time (one row in memory at a time) PreparedStatement stmt = dbClient.getMyBatis().newScrollingSingleRowSelectStatement(session, sql); if (projectUuid != null) { stmt.setString(1, projectUuid); } return stmt; }
public QualityGateConditionDto selectById(long id) { SqlSession session = myBatis.openSession(false); try { return selectById(id, session); } finally { MyBatis.closeQuietly(session); } }
public List<ComponentDto> selectProjects(String profileName, String language) { DbSession session = mybatis.openSession(false); try { return selectProjects(profileName, language, session); } finally { MyBatis.closeQuietly(session); } }
public List<PropertyDto> selectGlobalProperties() { try (DbSession session = mybatis.openSession(false)) { return selectGlobalProperties(session); } }
/** * Create a PreparedStatement for SELECT requests with scrolling of results row by row (only one row * in memory at a time) */ public PreparedStatement newScrollingSingleRowSelectStatement(DbSession session, String sql) { int fetchSize = database.getDialect().getScrollSingleRowFetchSize(); return newScrollingSelectStatement(session, sql, fetchSize); }
public Collection<QualityGateDto> selectAll() { SqlSession session = myBatis.openSession(false); try { return selectAll(session); } finally { MyBatis.closeQuietly(session); } }
public List<PropertyDto> selectProjectProperties(String resourceKey) { try (DbSession session = mybatis.openSession(false)) { return selectProjectProperties(session, resourceKey); } }
IssueIteratorForSingleChunk(DbClient dbClient, @Nullable String projectUuid, @Nullable Collection<String> issueKeys) { checkArgument(issueKeys == null || issueKeys.size() <= DatabaseUtils.PARTITION_SIZE_FOR_ORACLE, "Cannot search for more than " + DatabaseUtils.PARTITION_SIZE_FOR_ORACLE + " issue keys at once. Please provide the keys in smaller chunks."); this.projectUuid = projectUuid; this.issueKeys = issueKeys; this.session = dbClient.openSession(false); try { String sql = createSql(); stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql); iterator = createIterator(); } catch (Exception e) { session.close(); throw new IllegalStateException("Fail to prepare SQL request to select all issues", e); } }
public int countByTypeAndKey(String type, String key) { SqlSession session = mybatis.openSession(false); try { return countByTypeAndKey(type, key, session); } finally { MyBatis.closeQuietly(session); } }
@CheckForNull public PropertyDto selectGlobalProperty(String propertyKey) { try (DbSession session = mybatis.openSession(false)) { return selectGlobalProperty(session, propertyKey); } }
private static PreparedStatement createStatement(DbClient dbClient, DbSession session, List<String> projectUuids) throws SQLException { String sql; if (projectUuids.isEmpty()) { sql = StringUtils.replace(SQL_TEMPLATE, "{projectsCondition}", ""); } else { sql = StringUtils.replace(SQL_TEMPLATE, "{projectsCondition}", " AND projects.uuid in (" + repeat("?", ", ", projectUuids.size()) + ")"); } PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql); int index = 1; // query for RowKind.USER index = populateProjectUuidPlaceholders(stmt, projectUuids, index); // query for RowKind.GROUP index = populateProjectUuidPlaceholders(stmt, projectUuids, index); // query for RowKind.ANYONE index = setPrivateProjectPlaceHolder(stmt, index, false); index = populateProjectUuidPlaceholders(stmt, projectUuids, index); // query for RowKind.NONE index = setPrivateProjectPlaceHolder(stmt, index, true); populateProjectUuidPlaceholders(stmt, projectUuids, index); return stmt; }
@CheckForNull public QualityGateDto selectByName(String name) { SqlSession session = myBatis.openSession(false); try { return selectByName(session, name); } finally { MyBatis.closeQuietly(session); } }
@Override public DbSession openSession(boolean batch) { return myBatis.openSession(false); }