1
votes

Grettings!. I am having too much troubling with the following question... i will try to be as clear as possibly. Currently i have a Jackrabbit JCR implementation running in our web application. All things works fine, buts just a little (big) problem appears when trying to do some specific search.

For a brief synopsis of what kind of data is stored, we have 3 a node class called "Entry", that extends another node class named "BaseEntry" and that extends another called "BaseNode". The Entry class represents a Node in our JCR system, and has a set of properties (mapped as attributes in the corresponding class), an also inherits the properties mapped in their superclasses as well.

I copy and paste, the important part of the class definition and the properties of interest...

@Node(jcrType = "entry",  extend = BaseEntry.class)
public class Entry extends BaseEntry {

  ... // nothing really important here
}

@Node(jcrType = "baseEntry", extend = BaseNode.class, isAbstract = true)
public abstract class BaseEntry extends BaseNode {

  @Collection (jcrType = "attachment",
      collectionConverter = NTCollectionConverterImpl.class)
  protected List<Attachment> attachments = new ArrayList<Attachment>();

  ...

}

@Node(jcrType = "baseNode", isAbstract = true)
public abstract class BaseNode {

  @Field(jcrName = "name", id = true)
  protected String name;

  @Field(jcrName = "creationDate")
  protected Date creationDate;

  ...
}

1) How i can make a predicate for select only those nodes (entries) that have a specific year in the property creationDate ignoring the rest. The attribute is of type Date (in the class) and i guess the property is stored in a xs:DateTime format i guess... i really do not know very well... how it really match a Date in the JCR underlying system.

So far i get to this...
there must something like this //element(*, entry)[getYear(@creationDate) == <year>]

must be an integer, string, ... i really don't kwow.

2) How i can make a predicate for select only those nodes (entries) that contains attachments that have name a certain name.

Again the class Attachment, the important part...

@Node(jcrType = "attachment", discriminator = true)
public class Attachment extends BaseNode implements Comparable<Attachment> {
  ...
}

So far i get to this.. that is working.. but there must be a better way:

//element(*, entry) [jcr:contains(./*,'<nameOfInterest>')]

That all friends, i really apologies for the absent of information that i reader may require to understand better the background of the matter, i guess this is what i can do. I am pretty new to Jackrabbit and JCR, and i have to get the hands (dirty) on it, without knowing very well what i am doing.. and obliviously it began to be very complicated...

Well hope any charity soul can answer this, and help, at least a little :D. Thanks for advance. Greetings. VĂ­ctor.

1

1 Answers

1
votes

I'm not an expert, but I try to answer anyway:

Question 1

//element(*, entry)[getYear(@creationDate) == <year>]

I think you could use:

//element(*, entry)[
    @creationDate >= '2001-01-01T00:00:00.0' 
and @creationDate < '2002-01-01T00:00:00.0']

Question 2

Select only those nodes (entries) that contains attachments that have name a certain name.

I only know the SQL-2 query, using equality on the node name. I'm not sure if this is what you are looking for:

select * from [nt:base] where name() = '<nameOfInterest>'