List<InternalPropertyDto> res = mapper.selectAsText(ImmutableList.copyOf(keys)); Map<String, Optional<String>> builder = new HashMap<>(keys.size()); res.forEach(internalPropertyDto -> {
/** * No streaming of value */ public Optional<String> selectByKey(DbSession dbSession, String key) { checkKey(key); InternalPropertiesMapper mapper = getMapper(dbSession); InternalPropertyDto res = enforceSingleElement(key, mapper.selectAsText(singletonList(key))); if (res == null) { return Optional.empty(); } if (res.isEmpty()) { return OPTIONAL_OF_EMPTY_STRING; } if (res.getValue() != null) { return Optional.of(res.getValue()); } res = enforceSingleElement(key, mapper.selectAsClob(singletonList(key))); if (res == null) { Loggers.get(InternalPropertiesDao.class) .debug("Internal property {} has been found in db but has neither text value nor is empty. " + "Still it couldn't be retrieved with clob value. Ignoring the property.", key); return Optional.empty(); } return Optional.of(res.getValue()); }
@Test public void selectByKeys_queries_only_clob_properties_with_clob_SQL_query() { underTest.saveAsEmpty(dbSession, A_KEY); underTest.save(dbSession, "key2", VALUE_SMALL); underTest.save(dbSession, "key3", VALUE_SIZE_4001); Set<String> keys = ImmutableSet.of(A_KEY, "key2", "key3", "non_existent_key"); List<InternalPropertyDto> allInternalPropertyDtos = dbSession.getMapper(InternalPropertiesMapper.class).selectAsText(ImmutableList.copyOf(keys)); List<InternalPropertyDto> clobPropertyDtos = dbSession.getMapper(InternalPropertiesMapper.class).selectAsClob(ImmutableList.of("key3")); InternalPropertiesMapper mapperMock = mock(InternalPropertiesMapper.class); DbSession dbSessionMock = mock(DbSession.class); when(dbSessionMock.getMapper(InternalPropertiesMapper.class)).thenReturn(mapperMock); when(mapperMock.selectAsText(ImmutableList.copyOf(keys))) .thenReturn(allInternalPropertyDtos); when(mapperMock.selectAsClob(ImmutableList.of("key3"))) .thenReturn(clobPropertyDtos); underTest.selectByKeys(dbSessionMock, keys); verify(mapperMock).selectAsText(ImmutableList.copyOf(keys)); verify(mapperMock).selectAsClob(ImmutableList.of("key3")); verifyNoMoreInteractions(mapperMock); }
/** * No streaming of value */ public Optional<String> selectByKey(DbSession dbSession, String key) { checkKey(key); InternalPropertiesMapper mapper = getMapper(dbSession); InternalPropertyDto res = mapper.selectAsText(key); if (res == null) { return Optional.empty(); } if (res.isEmpty()) { return OPTIONAL_OF_EMPTY_STRING; } if (res.getValue() != null) { return Optional.of(res.getValue()); } res = mapper.selectAsClob(key); if (res == null) { Loggers.get(InternalPropertiesDao.class) .debug("Internal property {} has been found in db but has neither text value nor is empty. " + "Still we couldn't be retrieved with clob value. Ignoring the property.", key); return Optional.empty(); } return Optional.of(res.getValue()); }