@Override public XQResultSequence executeQuery(String query) throws XQException { checkState(ex_expression_closed); if (query == null) { throw new XQException("Provided query is null"); } closeResults(); ResultCursor<XQItemAccessor> result = connection.executeQuery(query, context); XQResultSequence sequence; if (context.getScrollability() == XQConstants.SCROLLTYPE_SCROLLABLE) { sequence = new ScrollableXQResultSequence(this, ((ResultCursorBase<XQItemAccessor>) result).getList()); } else { sequence = new IterableXQResultSequence(this, result); } results.add(sequence); return sequence; }
@Test public void shouldGetContentsFromEditorIfContentsFromEditorEnabled() throws Exception { given(config.isContextItemEnabled()).willReturn(true); given(config.isContextItemFromEditorEnabled()).willReturn(true); given(config.getContextItemText()).willReturn(CONTEXT_ITEM_TEXT); given(config.getContextItemType()).willReturn(CONTEXT_ITEM_TYPE); binder.bindContextItem(connection, expression); assertThat(fileRead, is(false)); verify(config).isContextItemEnabled(); verify(config).isContextItemFromEditorEnabled(); verify(config).getContextItemText(); verify(binderFactory).getBinder(CONTEXT_ITEM_TYPE); verify(typeBinder).bind(expression, connection, XQConstants.CONTEXT_ITEM, CONTEXT_ITEM_TEXT, CONTEXT_ITEM_TYPE); }
private <T> ResultCursorBase<T> getResultCursor(Properties props) { ResultCursorBase<T> cursor; int fetchSize = Integer.parseInt(props.getProperty(pn_client_fetchSize, "0")); int scrollType = Integer.parseInt(props.getProperty(pn_xqj_scrollability, xqScrollForwardStr)); if (scrollType == XQConstants.SCROLLTYPE_SCROLLABLE) { cursor = new FixedCursorImpl<>(fetchSize); } else { if (Boolean.parseBoolean(props.getProperty(pn_client_fetchAsynch, "false"))) { String clientId = props.getProperty(pn_client_id); String queueName = "client:" + clientId; if (fetchSize > 0) { cursor = new BoundedCursorImpl<>(repo.getHzInstance(), queueName, fetchSize); } else { cursor = new QueuedCursorImpl<>(repo.getHzInstance(), queueName); } } else { if (Boolean.parseBoolean(props.getProperty(pn_document_compress, "false"))) { cursor = new CompressingCursorImpl<>(repo, fetchSize); } else { cursor = new FixedCursorImpl<>(fetchSize); } } } logger.trace("getResultCursor.exit; returning {} for props {}", cursor, props); return cursor; }
@Override public XQResultSequence executeQuery() throws XQException { checkState(ex_expression_closed); closeResults(); ResultCursor<XQItemAccessor> result = connection.executeQuery(xquery, context); XQResultSequence sequence; if (context.getScrollability() == XQConstants.SCROLLTYPE_SCROLLABLE) { sequence = new ScrollableXQResultSequence(this, ((ResultCursorBase<XQItemAccessor>) result).getList()); } else { sequence = new IterableXQResultSequence(this, result); } results.add(sequence); return sequence; }
public void bindContextItem(XQConnection connection, XQPreparedExpression preparedExpression) throws Exception { if (config.isContextItemEnabled()) { String contextItemValue = config.isContextItemFromEditorEnabled() ? config.getContextItemText() : readFile(config.getContextItemFile()); binderFactory.getBinder(config.getContextItemType()).bind(preparedExpression, connection, XQConstants.CONTEXT_ITEM, contextItemValue, config.getContextItemType()); } }
@Test public void shouldGetContentsFromFileIfContentsFromEditorDisabled() throws Exception { given(config.isContextItemEnabled()).willReturn(true); given(config.isContextItemFromEditorEnabled()).willReturn(false); given(config.getContextItemType()).willReturn(CONTEXT_ITEM_TYPE); binder.bindContextItem(connection, expression); assertThat(fileRead, is(true)); verify(config).isContextItemEnabled(); verify(config).isContextItemFromEditorEnabled(); verify(config, times(0)).getContextItemText(); verify(binderFactory).getBinder(CONTEXT_ITEM_TYPE); verify(typeBinder).bind(expression, connection, XQConstants.CONTEXT_ITEM, FILE_CONTENTS, CONTEXT_ITEM_TYPE); }
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException { if (input==null) { throw new PipeRunException(this, getLogPrefix(session) + "got null input"); } if (!(input instanceof String)) { throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName()); } try { String stringResult = (String)input; // We already specifically use Saxon in this pipe, hence set xslt2 // to true to make XmlUtils use the Saxon // DocumentBuilderFactoryImpl. ParameterResolutionContext prc = new ParameterResolutionContext(stringResult, session, isNamespaceAware(), true); Map parametervalues = null; if (getParameterList() != null) { parametervalues = prc.getValueMap(getParameterList()); } preparedExpression.bindDocument(XQConstants.CONTEXT_ITEM, stringResult, null, null); Iterator iterator = getParameterList().iterator(); while (iterator.hasNext()) { Parameter parameter = (Parameter)iterator.next(); preparedExpression.bindObject(new QName(parameter.getName()), parametervalues.get(parameter.getName()), null); } XQResultSequence resultSequence = preparedExpression.executeQuery(); stringResult = resultSequence.getSequenceAsString(null); return new PipeRunResult(getForward(), stringResult); } catch (Exception e) { throw new PipeRunException(this, getLogPrefix(session)+" Exception on running xquery", e); } }