use of javax.inject.Provider in project torodb by torodb.
the class AbstractReadInterface method getCollectionDidsWithFieldsInBatch.
@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Integer>. It's iterated and closed in caller code")
private Cursor<Integer> getCollectionDidsWithFieldsInBatch(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCol, MetaDocPart metaDocPart, Multimap<MetaField, KvValue<?>> valuesMultimap) throws SQLException {
@SuppressWarnings("checkstyle:LineLength") Provider<Stream<Map.Entry<MetaField, Collection<KvValue<?>>>>> valuesMultimapSortedStreamProvider = () -> valuesMultimap.asMap().entrySet().stream().sorted((e1, e2) -> e1.getKey().getIdentifier().compareTo(e2.getKey().getIdentifier()));
String statement = getReadCollectionDidsWithFieldInStatement(metaDatabase.getIdentifier(), metaDocPart.getIdentifier(), valuesMultimapSortedStreamProvider.get().map(e -> new Tuple2<String, Integer>(e.getKey().getIdentifier(), e.getValue().size())));
Connection connection = dsl.configuration().connectionProvider().acquire();
try {
PreparedStatement preparedStatement = connection.prepareStatement(statement);
int parameterIndex = 1;
Iterator<Map.Entry<MetaField, Collection<KvValue<?>>>> valuesMultimapSortedIterator = valuesMultimapSortedStreamProvider.get().iterator();
while (valuesMultimapSortedIterator.hasNext()) {
Map.Entry<MetaField, Collection<KvValue<?>>> valuesMultimapEntry = valuesMultimapSortedIterator.next();
for (KvValue<?> value : valuesMultimapEntry.getValue()) {
sqlHelper.setPreparedStatementValue(preparedStatement, parameterIndex, valuesMultimapEntry.getKey().getType(), value);
parameterIndex++;
}
}
return new DefaultDidCursor(errorHandler, preparedStatement.executeQuery());
} finally {
dsl.configuration().connectionProvider().release(connection);
}
}
use of javax.inject.Provider in project OpenAM by OpenRock.
the class RestSTSServiceHttpRouteProvider method get.
@Override
public Set<HttpRoute> get() {
return Collections.singleton(HttpRoute.newHttpRoute(STARTS_WITH, "rest-sts", new Provider<Handler>() {
@Override
public Handler get() {
Router restSTSRouter = RestSTSInjectorHolder.getInstance(Key.get(Router.class));
rootRouter.route("").auditAs(STS).authenticateWith(Routers.ssoToken().exceptActions(RestSTSService.TRANSLATE, RestSTSService.VALIDATE, RestSTSService.CANCEL).exceptPatch().exceptRead().exceptUpdate()).toRequestHandler(STARTS_WITH, restSTSRouter);
return newHttpHandler(rootRouter.getRouter());
}
}));
}
use of javax.inject.Provider in project xwiki-platform by xwiki.
the class UsersAndGroupsMimeMessageFactoryTest method createMessageWhenNotExistingMimeMessageFactory.
@Test
public void createMessageWhenNotExistingMimeMessageFactory() throws Exception {
Session session = Session.getInstance(new Properties());
Map<String, Object> parameters = new HashMap<>();
parameters.put("hint", "factoryHint");
parameters.put("source", "factoryHint");
Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(this.mocker);
try {
this.mocker.getComponentUnderTest().createMessage(Collections.<String, Object>emptyMap(), parameters);
fail("Should have thrown an exception");
} catch (MessagingException expected) {
assertEquals("Failed to find a [MimeMessageFactory<MimeMessage>] for hint [factoryHint]", expected.getMessage());
}
}
use of javax.inject.Provider in project xwiki-platform by xwiki.
the class UsersAndGroupsMimeMessageFactoryTest method createMessage.
@Test
public void createMessage() throws Exception {
DocumentReference userReference = new DocumentReference("userwiki", "userspace", "userpage");
Map<String, Object> source = Collections.<String, Object>singletonMap("users", Collections.singletonList(userReference));
Map<String, Object> parameters = new HashMap<>();
parameters.put("hint", "template");
parameters.put("source", new DocumentReference("templatewiki", "templatespace", "templatepage"));
Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(this.mocker);
this.mocker.registerMockComponent(new DefaultParameterizedType(null, MimeMessageFactory.class, MimeMessage.class), "template");
// Setup XWikiContext since this is required internally by the iterator constructor
Execution execution = this.mocker.registerMockComponent(Execution.class);
XWikiContext xwikiContext = mock(XWikiContext.class);
ExecutionContext executionContext = new ExecutionContext();
executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xwikiContext);
when(execution.getContext()).thenReturn(executionContext);
Iterator<MimeMessage> iterator = this.mocker.getComponentUnderTest().createMessage(source, parameters);
assertNotNull(iterator);
}
use of javax.inject.Provider in project xwiki-platform by xwiki.
the class DefaultExtendedRenderingConfigurationTest method configure.
@Before
public void configure() throws Exception {
Provider<ComponentManager> contextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(contextComponentManagerProvider.get()).thenReturn(this.mocker);
}
Aggregations