Created
July 13, 2012 08:49
-
-
Save mweststrate/3103734 to your computer and use it in GitHub Desktop.
xpath example 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String implementation4(String name, Category category, Long offset) throws CoreException | |
{ | |
StringBuilder b = new StringBuilder(); | |
//create the xpath | |
XPath<Product> xpath = XPath.create(getContext(), Product.class) | |
.subconstraint( Product.MemberNames.Product_ProductState , ProductState.entityName ) | |
.eq( ProductState.MemberNames.Published , true ) | |
.or() | |
.eq( ProductState.MemberNames.PublishAnyway , true ) | |
.close() | |
.and() | |
.eq( Product.MemberNames.Product_Category , category ) | |
.and() | |
.eq( Product.MemberNames.Name , name) | |
.offset(offset.intValue()) | |
.addSortingAsc(Product.MemberNames.Nr); | |
//count | |
long count = xpath.count(); | |
b.append(count).append("\n"); | |
//retrieve all | |
List<Product> products = xpath.all(); | |
Product first = xpath.first(); | |
//add number of the first | |
if (first != null) | |
b.append(first.getNr()).append("\n"); | |
//add descriptions of the others | |
for(Product p : products) | |
b.append(p.getDescription()).append("\n"); | |
return b.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment