Skip to content

Instantly share code, notes, and snippets.

@mweststrate
Created July 13, 2012 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mweststrate/3103734 to your computer and use it in GitHub Desktop.
Save mweststrate/3103734 to your computer and use it in GitHub Desktop.
xpath example 4
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