Created
July 6, 2012 13:55
-
-
Save mweststrate/3060283 to your computer and use it in GitHub Desktop.
xpath example java 1
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 implementation1(String name, Category category, Long offset) throws CoreException | |
{ | |
StringBuilder b = new StringBuilder(); | |
//create the xpath | |
String xpath = | |
"//Products.Product[Products.Product_ProductState/Products.ProductState[Published = true() or PublishAnyway = true()]]" + | |
"[Products.Product_Category = '" + category.getGUID() + "']" + | |
"[Name = '" + name + "']"; | |
//count | |
long count = Core.retrieveXPathQueryAggregate(getContext(), "count(" + xpath + ")"); | |
b.append(count).append("\n"); | |
//retrieve all | |
List<IMendixObject> products = Core.retrieveXPathQuery(getContext(), xpath, 0, offset.intValue(), | |
ImmutableMap.of("Nr","Asc") | |
); | |
//add number of the first | |
if (products.size() > 0) { | |
Product proxy = Product.initialize(getContext(), products.get(0)); | |
b.append(proxy.getNr()).append("\n"); | |
} | |
//add descriptions of the others | |
for(IMendixObject p : products) { | |
Product proxy = Product.initialize(getContext(), p); | |
b.append(proxy.getDescription()).append("\n"); | |
} | |
return b.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment