本文整理汇总了Java中javax.jcr.query.Query.bindValue方法的典型用法代码示例。如果您正苦于以下问题:Java Query.bindValue方法的具体用法?Java Query.bindValue怎么用?Java Query.bindValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jcr.query.Query
的用法示例。
在下文中一共展示了Query.bindValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryForVanityUrlNode
import javax.jcr.query.Query; //导入方法依赖的package包/类
/**
* Query for a vanity url node.
*
* @param vanityUrl vanity url from request
* @param siteName site name from aggegation state
* @return first vanity url node of result or null, if nothing found
*/
public Node queryForVanityUrlNode(final String vanityUrl, final String siteName) {
Node node = null;
try {
Session jcrSession = MgnlContext.getJCRSession(VanityUrlModule.WORKSPACE);
QueryManager queryManager = jcrSession.getWorkspace().getQueryManager();
Query query = queryManager.createQuery(QUERY, JCR_SQL2);
query.bindValue(PN_VANITY_URL, new StringValue(vanityUrl));
query.bindValue(PN_SITE, new StringValue(siteName));
QueryResult queryResult = query.execute();
NodeIterator nodes = queryResult.getNodes();
if (nodes.hasNext()) {
node = nodes.nextNode();
}
} catch (RepositoryException e) {
LOGGER.error("Error message.", e);
}
return node;
}
示例2: getWebResourceGroupQueryResults
import javax.jcr.query.Query; //导入方法依赖的package包/类
/**
*
* Runs Query for Web Resource Nodes in a given group
*
* @param session
* @param webResourceGroupName
* @return
* @throws RepositoryException
*/
protected QueryResult getWebResourceGroupQueryResults(Session session,
String webResourceGroupName) throws RepositoryException {
Query query = session
.getWorkspace()
.getQueryManager()
.createQuery(
"SELECT * FROM [nt:file] INNER JOIN [webresource:WebResourceGroup] as webResourceGroupSet ON ISDESCENDANTNODE([nt:file], webResourceGroupSet) WHERE webResourceGroupSet.[webresource:name] = $webResourceName",
Query.JCR_SQL2);
query.bindValue("webResourceName", session.getValueFactory()
.createValue(webResourceGroupName));
QueryResult queryResult = query.execute();
return queryResult;
}
示例3: getArtifactsByChecksum
import javax.jcr.query.Query; //导入方法依赖的package包/类
@Override
public List<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, String checksum )
throws MetadataRepositoryException
{
List<ArtifactMetadata> artifacts;
String q = getArtifactQuery( repositoryId ) + " AND ([sha1] = $checksum OR [md5] = $checksum)";
try
{
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery( q, Query.JCR_SQL2 );
ValueFactory valueFactory = getJcrSession().getValueFactory();
query.bindValue( "checksum", valueFactory.createValue( checksum ) );
QueryResult result = query.execute();
artifacts = new ArrayList<>();
for ( Node n : JcrUtils.getNodes( result ) )
{
artifacts.add( getArtifactFromNode( repositoryId, n ) );
}
}
catch ( RepositoryException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
return artifacts;
}
示例4: runJcrQuery
import javax.jcr.query.Query; //导入方法依赖的package包/类
private List<ArtifactMetadata> runJcrQuery( String repositoryId, String q, Map<String, String> bindings )
throws MetadataRepositoryException
{
List<ArtifactMetadata> artifacts;
if ( repositoryId != null )
{
q += " AND ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath( repositoryId ) + "')";
}
log.info( "Running JCR Query: {}", q );
try
{
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery( q, Query.JCR_SQL2 );
ValueFactory valueFactory = getJcrSession().getValueFactory();
for ( Entry<String, String> entry : bindings.entrySet() )
{
query.bindValue( entry.getKey(), valueFactory.createValue( entry.getValue() ) );
}
long start = Calendar.getInstance().getTimeInMillis();
QueryResult result = query.execute();
long end = Calendar.getInstance().getTimeInMillis();
log.info( "JCR Query ran in {} milliseconds: {}", end - start , q );
artifacts = new ArrayList<>();
RowIterator rows = result.getRows();
while ( rows.hasNext() )
{
Row row = rows.nextRow();
Node node = row.getNode( "artifact" );
artifacts.add( getArtifactFromNode( repositoryId, node ) );
}
}
catch ( RepositoryException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
return artifacts;
}
示例5: getWebResourceCachedInventoryPaths
import javax.jcr.query.Query; //导入方法依赖的package包/类
public Map<String, List<String>> getWebResourceCachedInventoryPaths(
Session session, String webResourceGroupName)
throws RepositoryException {
Map<String, List<String>> result = new HashMap<String, List<String>>();
Query query = session
.getWorkspace()
.getQueryManager()
.createQuery(
"SELECT * FROM [webresource:WebResourceGroup] as webResourceGroupSet WHERE webResourceGroupSet.[webresource:name] = $webResourceName",
Query.JCR_SQL2);
query.bindValue("webResourceName", session.getValueFactory()
.createValue(webResourceGroupName));
QueryResult queryResult = query.execute();
NodeIterator queryIt = queryResult.getNodes();
if (queryIt.hasNext()) {
WebResourceGroup webResourceGroup = new WebResourceGroup(
queryIt.nextNode());
result.putAll(webResourceGroup.getInventory());
}
return result;
}
示例6: getArtifactsByDateRange
import javax.jcr.query.Query; //导入方法依赖的package包/类
@Override
public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
throws MetadataRepositoryException
{
List<ArtifactMetadata> artifacts;
String q = getArtifactQuery( repoId );
if ( startTime != null )
{
q += " AND [whenGathered] >= $start";
}
if ( endTime != null )
{
q += " AND [whenGathered] <= $end";
}
try
{
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery( q, Query.JCR_SQL2 );
ValueFactory valueFactory = getJcrSession().getValueFactory();
if ( startTime != null )
{
query.bindValue( "start", valueFactory.createValue( createCalendar( startTime ) ) );
}
if ( endTime != null )
{
query.bindValue( "end", valueFactory.createValue( createCalendar( endTime ) ) );
}
QueryResult result = query.execute();
artifacts = new ArrayList<>();
for ( Node n : JcrUtils.getNodes( result ) )
{
artifacts.add( getArtifactFromNode( repoId, n ) );
}
}
catch ( RepositoryException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
return artifacts;
}
示例7: runJcrQuery
import javax.jcr.query.Query; //导入方法依赖的package包/类
private List<ArtifactMetadata> runJcrQuery( String repositoryId, String q, Map<String, String> bindings )
throws MetadataRepositoryException
{
List<ArtifactMetadata> artifacts;
if ( repositoryId != null )
{
q += " AND ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath( repositoryId ) + "')";
}
log.info( "Running JCR Query: {}", q );
try
{
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery( q, Query.JCR_SQL2 );
ValueFactory valueFactory = getJcrSession().getValueFactory();
for ( Entry<String, String> entry : bindings.entrySet() )
{
query.bindValue( entry.getKey(), valueFactory.createValue( entry.getValue() ) );
}
long start = Calendar.getInstance().getTimeInMillis();
QueryResult result = query.execute();
long end = Calendar.getInstance().getTimeInMillis();
log.info( "JCR Query ran in {} milliseconds: {}", end - start, q );
artifacts = new ArrayList<>();
RowIterator rows = result.getRows();
while ( rows.hasNext() )
{
Row row = rows.nextRow();
Node node = row.getNode( "artifact" );
artifacts.add( getArtifactFromNode( repositoryId, node ) );
}
}
catch ( RepositoryException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
}
log.info( "Artifacts found {}", artifacts.size() );
for ( ArtifactMetadata meta : artifacts )
{
log.info( "Artifact: " + meta.getVersion() + " " + meta.getFacetList() );
}
return artifacts;
}