本文整理了Java中javax.jcr.query.Query.getStatement
方法的一些代码示例,展示了Query.getStatement
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getStatement
方法的具体详情如下:
包路径:javax.jcr.query.Query
类名称:Query
方法名:getStatement
[英]Returns the statement defined for this query.
If the language of this query is JCR-SQL2 or another string-based language, this method will return the statement that was used to create this query.
If the language of this query is JCR-JQOM, this method will return the JCR-SQL2 equivalent of the JCR-JQOM object tree. This is the standard serialization of JCR-JQOM and is also the string stored in the jcr:statement
property if the query is persisted. See #storeAsNode(String).
[中]返回为此查询定义的语句。
如果此查询的语言是JCR-SQL2或其他基于字符串的语言,则此方法将返回用于创建此查询的语句。
如果这个查询的语言是JCR-JQOM,那么这个方法将返回JCR-SQL2等价于JCR-JQOM对象树。这是JCR-JQOM的标准序列化,如果查询被持久化,它也是jcr:statement
属性中存储的字符串。请参见#storeAsNode(字符串)。
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public String getStatement() {
return this.query.getStatement();
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-connector
/**
* @inheritDoc
*/
public String getStatement() {
return query.getStatement();
}
代码示例来源:origin: net.adamcin.oakpal/oakpal-core
@Override
public String getStatement() {
return delegate.getStatement();
}
代码示例来源:origin: apache/jackrabbit
/** {@inheritDoc} */
public String getStatement() throws RemoteException {
return query.getStatement();
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine
/**
* @inheritDoc
*/
public String getStatement() {
String queryString = query.getStatement();
String[] argumentNames = getArguments();
for (int i = 0; i < argumentNames.length; i++) {
queryString = queryString.replaceAll(MAGIC_NAMED_START + argumentNames[i] + MAGIC_NAMED_END, "\\$" + argumentNames[i]);
}
return queryString;
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine
public void bindValue(String varName, Value value) throws IllegalArgumentException, RepositoryException {
if (query.getStatement().contains(MAGIC_NAMED_START)) {
if(arguments == null)
arguments = new HashMap<String, Value>();
arguments.put(varName, value);
} else {
query.bindValue(varName, value);
}
}
代码示例来源:origin: brix-cms/brix-cms
public String getStatement() {
return getDelegate().getStatement();
}
代码示例来源:origin: brix-cms/brix-cms
public String execute() throws Exception {
return getDelegate().getStatement();
}
});
代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine
/**
* @inheritDoc
*/
public String[] getArguments() {
String queryString = query.getStatement();
Set<String> arguments = new HashSet<String>();
for (int position = queryString.indexOf(MAGIC_NAMED_START); position >= 0; position = queryString.indexOf(MAGIC_NAMED_START, position)) {
position += MAGIC_NAMED_START.length();
int endPosition = position;
if (Character.isJavaIdentifierStart(queryString.charAt(endPosition))) {
do {
++endPosition;
} while (endPosition < queryString.length() && Character.isJavaIdentifierPart(queryString.charAt(endPosition)) &&
!queryString.substring(endPosition).startsWith(MAGIC_NAMED_END));
}
if (queryString.substring(endPosition).startsWith(MAGIC_NAMED_END)) {
arguments.add(queryString.substring(position, endPosition));
position = endPosition + MAGIC_NAMED_END.length();
}
}
return arguments.toArray(new String[arguments.size()]);
}
代码示例来源:origin: apache/jackrabbit
/**
* Tests it the statement returned by {@link Query#getStatement()} is equal
* to the one passed in createQuery().
*/
public void testGetStatement() throws RepositoryException {
String statement = "/" + jcrRoot + "/foo";
Query q = session.getWorkspace().getQueryManager().createQuery(statement, qsXPATH);
assertEquals("Statement returned by Query.getStatement() is not equal to the initial statement.",
statement,
q.getStatement());
}
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine
/**
* @inheritDoc
*/
public QueryResult execute(Map<String, String> arguments) throws RepositoryException {
String queryString = query.getStatement();
if (arguments != null) {
for (Map.Entry<String,String> entry : arguments.entrySet()) {
bindValue(entry.getKey(), session.getValueFactory().createValue(entry.getValue()));
}
}
if (this.arguments != null) {
for (Map.Entry<String, Value> entry : this.arguments.entrySet()) {
queryString = queryString.replace(MAGIC_NAMED_START + entry.getKey() + MAGIC_NAMED_END, entry.getValue().getString());
}
}
Query q = session.getWorkspace().getQueryManager().createQuery(queryString, getLanguage());
return factory.getQueryResultDecorator(session, execute(q));
}
代码示例来源:origin: apache/jackrabbit
/**
* Stores a {@link javax.jcr.query.Query#XPATH} query at:
* <code>testRoot + "/" + nodeName1</code>.
* @throws NotExecutableException if nt:query is not supported.
*/
public void testSave() throws RepositoryException, NotExecutableException {
checkNtQuery();
Query query = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
query.storeAsNode(testRoot + "/" + nodeName1);
assertTrue("Node has not been stored", testRootNode.hasNode(nodeName1));
Node queryNode = testRootNode.getNode(nodeName1);
assertTrue("Query node is not of type nt:query", queryNode.isNodeType(ntQuery));
Query query2 = superuser.getWorkspace().getQueryManager().getQuery(queryNode);
assertEquals("Persisted query does not match initial query.", query.getStatement(), query2.getStatement());
}
代码示例来源:origin: nl.vpro/jcr-criteria
@Override
public String getSpellCheckerSuggestion() {
if (spellCheckerSuggestion == null && spellCheckerQuery != null) {
RowIterator rows;
try {
rows = spellCheckerQuery.execute().getRows();
// the above query will always return the root node no matter what string we check
Row r = rows.nextRow();
// get the result of the spell checking
Value v = r.getValue("rep:spellcheck()");
if (v == null) {
// no suggestion returned, the spelling is correct or the spell checker
// does not know how to correct it.
} else {
spellCheckerSuggestion = v.getString();
}
} catch (RepositoryException e) {
log.warn("Error getting excerpt using " + spellCheckerQuery.getStatement(), e);
return null;
}
}
return spellCheckerSuggestion;
}
代码示例来源:origin: apache/jackrabbit-oak
private boolean performQuery(@NotNull final TestContext ec) throws RepositoryException {
QueryManager qm = ec.session.getWorkspace().getQueryManager();
ValueFactory vf = ec.session.getValueFactory();
Query q = qm.createQuery("SELECT * FROM [nt:base] WHERE [title] = $title", Query.JCR_SQL2);
q.bindValue("title", vf.createValue(ec.title));
LOG.trace("statement: {} - title: {}", q.getStatement(), ec.title);
RowIterator rows = q.execute().getRows();
if (rows.hasNext()) {
rows.nextRow().getPath();
return true;
} else {
return false;
}
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldCreateQuery() throws Exception {
String statement = "SELECT * FROM [nt:unstructured]";
QueryManager queryManager = workspace.getQueryManager();
Query query = queryManager.createQuery(statement, Query.JCR_SQL2);
assertThat(query, is(notNullValue()));
assertThat(query.getLanguage(), is(Query.JCR_SQL2));
assertThat(query.getStatement(), is(statement));
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldLoadStoredQuery() throws Exception {
String statement = "SELECT * FROM [nt:unstructured]";
QueryManager queryManager = workspace.getQueryManager();
Query query = queryManager.createQuery(statement, Query.JCR_SQL2);
Node node = query.storeAsNode("/storedQuery");
Query loaded = queryManager.getQuery(node);
assertThat(loaded, is(notNullValue()));
assertThat(loaded.getLanguage(), is(Query.JCR_SQL2));
assertThat(loaded.getStatement(), is(statement));
assertThat(loaded.getStoredQueryPath(), is(node.getPath()));
}
代码示例来源:origin: apache/jackrabbit
protected void setUp() throws Exception {
super.setUp();
qomQuery = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.childNode("s", testRoot),
qf.comparison(
qf.propertyValue("s", propertyName1),
QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
qf.bindVariable("v")
)
), null, null);
sqlQuery = qm.createQuery(qomQuery.getStatement(), Query.JCR_SQL2);
}
代码示例来源:origin: ModeShape/modeshape
protected QueryResult assertJcrSql2Query( String sql,
long expectedRowCount ) throws RepositoryException {
Query query = session().getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
QueryResult results = query.execute();
printMessage(query.getStatement());
ValidateQuery.validateQuery().printDetail(print).rowCount(expectedRowCount).validate(query, results);
return results;
}
代码示例来源:origin: ModeShape/modeshape
@Test
@FixFor( "MODE-2329" )
public void shouldAllowUsingExpandedSelectorNameInQOM() throws Exception {
QueryObjectModelFactory qomFactory = session.getWorkspace().getQueryManager().getQOMFactory();
Selector selector = qomFactory.selector(NodeType.NT_BASE, "category");
// Build and execute the query ...
Query query = qomFactory.createQuery(selector, qomFactory.childNode("category", "/Cars"), null, new Column[0]);
assertThat(query.getStatement(), is("SELECT * FROM [{http://www.jcp.org/jcr/nt/1.0}base] AS category WHERE ISCHILDNODE(category,'/Cars')"));
QueryResult result = query.execute();
validateQuery().rowCount(4).hasColumns(allColumnNames("category")).validate(query, result);
}
代码示例来源:origin: ModeShape/modeshape
@FixFor( "MODE-1611" )
@Test
public void shouldAllowQomUseOfIsChildNodeInWhereClause() throws RepositoryException {
QueryObjectModelFactory qomFactory = session.getWorkspace().getQueryManager().getQOMFactory();
Selector selector = qomFactory.selector("nt:base", "category");
ChildNode childNodeConstraint = qomFactory.childNode("category", "/Cars");
Constraint constraint = childNodeConstraint;
Column[] columns = new Column[0];
Ordering[] orderings = null;
// Build and execute the query ...
Query query = qomFactory.createQuery(selector, constraint, orderings, columns);
assertThat(query.getStatement(), is("SELECT * FROM [nt:base] AS category WHERE ISCHILDNODE(category,'/Cars')"));
QueryResult result = query.execute();
validateQuery().rowCount(4).hasColumns(allColumnNames("category")).validate(query, result);
}
内容来源于网络,如有侵权,请联系作者删除!