public List<PropertyDto> selectGlobalProperties() { try (DbSession session = mybatis.openSession(false)) { return selectGlobalProperties(session); } }
public List<PropertyDto> selectProjectProperties(String resourceKey) { try (DbSession session = mybatis.openSession(false)) { return selectProjectProperties(session, resourceKey); } }
@CheckForNull public PropertyDto selectProjectProperty(long componentId, String propertyKey) { try (DbSession session = mybatis.openSession(false)) { return selectProjectProperty(session, componentId, propertyKey); } }
@CheckForNull public PropertyDto selectGlobalProperty(String propertyKey) { try (DbSession session = mybatis.openSession(false)) { return selectGlobalProperty(session, propertyKey); } }
@Override public DbSession openSession(boolean batch) { return myBatis.openSession(false); }
public boolean hasProjectNotificationSubscribersForDispatchers(String projectUuid, Collection<String> dispatcherKeys) { try (DbSession session = mybatis.openSession(false); Connection connection = session.getConnection(); PreparedStatement pstmt = createStatement(projectUuid, dispatcherKeys, connection); ResultSet rs = pstmt.executeQuery()) { return rs.next() && rs.getInt(1) > 0; } catch (SQLException e) { throw new IllegalStateException("Fail to execute SQL for hasProjectNotificationSubscribersForDispatchers", e); } }
public void renamePropertyKey(String oldKey, String newKey) { checkArgument(!Strings.isNullOrEmpty(oldKey), "Old property key must not be empty"); checkArgument(!Strings.isNullOrEmpty(newKey), "New property key must not be empty"); if (!newKey.equals(oldKey)) { try (DbSession session = mybatis.openSession(false)) { getMapper(session).renamePropertyKey(oldKey, newKey); session.commit(); } } }
public void saveGlobalProperties(Map<String, String> properties) { try (DbSession session = mybatis.openSession(false)) { PropertiesMapper mapper = getMapper(session); properties.entrySet().forEach(entry -> { mapper.deleteGlobalProperty(entry.getKey()); save(mapper, entry.getKey(), null, null, entry.getValue()); }); session.commit(); } }
public void deleteProjectProperty(String key, Long projectId) { try (DbSession session = mybatis.openSession(false)) { deleteProjectProperty(key, projectId, session); session.commit(); } }
private DelegatingDbSessionSupplier buildRegularDbSessionSupplier() { return new DelegatingDbSessionSupplier(() -> { DbSession res = myBatis.openSession(false); ensureAutoCommitFalse(res); return res; }); }
private DelegatingDbSessionSupplier buildBatchDbSessionSupplier() { return new DelegatingDbSessionSupplier(() -> { DbSession res = myBatis.openSession(true); ensureAutoCommitFalse(res); return res; }); }
public long count() { try (DbSession session = mybatis.openSession(false)) { return session.getMapper(NotificationQueueMapper.class).count(); } } }
@Override public DbSession openSession(boolean batch) { if (!CACHING_ENABLED.get()) { return myBatis.openSession(batch); } if (batch) { return new NonClosingDbSession(batchDbSession.get().get()); } return new NonClosingDbSession(regularDbSession.get().get()); }
public void insert(List<NotificationQueueDto> dtos) { try (DbSession session = mybatis.openSession(true)) { NotificationQueueMapper mapper = session.getMapper(NotificationQueueMapper.class); for (NotificationQueueDto dto : dtos) { mapper.insert(dto); } session.commit(); } }
public DbSession getSession() { if (session == null) { session = db.getMyBatis().openSession(false); } return session; }
@Test public void openSession_without_caching_always_returns_a_new_batch_session_when_parameter_is_true() { DbSession[] expected = {mock(DbSession.class), mock(DbSession.class), mock(DbSession.class), mock(DbSession.class)}; when(myBatis.openSession(true)) .thenReturn(expected[0]) .thenReturn(expected[1]) .thenReturn(expected[2]) .thenReturn(expected[3]) .thenThrow(oneCallTooMuch()); assertThat(Arrays.stream(expected).map(ignored -> underTest.openSession(true)).collect(MoreCollectors.toList())) .containsExactly(expected); }
@Test public void openSession_without_caching_always_returns_a_new_regular_session_when_parameter_is_false() { DbSession[] expected = {mock(DbSession.class), mock(DbSession.class), mock(DbSession.class), mock(DbSession.class)}; when(myBatis.openSession(false)) .thenReturn(expected[0]) .thenReturn(expected[1]) .thenReturn(expected[2]) .thenReturn(expected[3]) .thenThrow(oneCallTooMuch()); assertThat(Arrays.stream(expected).map(ignored -> underTest.openSession(false)).collect(MoreCollectors.toList())) .containsExactly(expected); }
private void verifyDelegation(boolean batchOrRegular, boolean firstCall, BiConsumer<DbSession, DbSession> r) { when(myBatis.openSession(batchOrRegular)) .thenReturn(myBatisDbSession) .thenThrow(oneCallTooMuch()); r.accept(myBatisDbSession, underTest.openSession(batchOrRegular)); verify(myBatisDbSession, times(firstCall ? 1 : 0)).getSqlSession(); verifyNoMoreInteractions(myBatisDbSession); reset(myBatis, myBatisDbSession); }
@Test public void disableCaching_does_not_open_DB_connection_if_openSession_was_never_called() { when(myBatis.openSession(anyBoolean())) .thenThrow(oneCallTooMuch()); underTest.enableCaching(); underTest.disableCaching(); verifyNoMoreInteractions(myBatis); }
@Test public void shouldOpenBatchSession() { underTest.start(); try (DbSession session = underTest.openSession(false)) { assertThat(session.getConnection(), notNullValue()); assertThat(session.getMapper(RuleMapper.class), notNullValue()); } } }