ContentBean and IdentifiableContentBean

To support Solr search introduction, the HST has introduced 2 new base bean API classes. The orginal base HippoBean interface now extends IdentifiableContentBean. The IdentifiableContentBean in turn extends from the marker interface ContentBean.

public interface HippoBean extends IdentifiableContentBean,
                                   NodeAware,
                                   ObjectConverterAware,
                                   Comparable<HippoBean> {
   // body
}
Note that for all implementations of IdentifiableContentBean it is mandatory to have a public no-args constructor

For any bean that extends from HippoItem, this is already the case because the HippoItem contains a public no-args constructor

IdentifiableContentBean:

/**
 * The base interface for all identifiable beans: This includes
 * beans that can be completely independent of jcr, for example
 *  a bean that represents some external src. The
 * {@link #getIdentifier()} must return the unique
 * identifier for this {@link IdentifiableContentBean}:
 * This is typically the identifier used in indexes
 */
public interface IdentifiableContentBean extends ContentBean {

    /**
     * <p>
     *     This returns the identifier of the backing provider
     *     for this bean, for example some UUID or
     *     /documents/content/myprojec/news/article or
     *     http://www.example.com/foo/bar, or a RDBMS id,
     *     etc It is not allowed for any implementation to
     *     return <code>null</code>
     * </p>
     * <p>
     *     Since the return value for this method is used as
     *     the index document identifier, it must be unique
     *     for every bean that must be indexed
     * </p>
     * @return the identifier for this {@link IdentifiableContentBean}
     */
    // the identifier is used as index id, hence add name="id"
    @IndexField(name="id", ignoreInCompound = true)
    String getIdentifier();

    /**
     * @param identifier sets the identifier for this
     *        {@link IdentifiableContentBean}
     * @see #getIdentifier()
     */
    void setIdentifier(String identifier);
}

ContentBean:

/**
 * The marker interface for all beans that can be indexed
 * (thus also compounds): This includes beans that are
 * completely independent of jcr, The beans implementing
 * this {@link ContentBean} don't need a
 * {@link IdentifiableContentBean#getIdentifier()} identifier
 * . Beans that should be possible to be indexed
 * in something like an inversed index, need to implement
 * {@link IdentifiableContentBean}. Typically classes that
 * implement this {@link ContentBean} but not
 * {@link IdentifiableContentBean} are compounds of
 * an {@link IdentifiableContentBean}
 *
 * For example:
 *
 * <pre>
 * <code>
 *     public class NewsBean implements IdentifiableContentBean {
 *
 *         public  String getPath() {
 *             // return path
 *         }
 *
 *        public  void setPath(String path) {
 *            // set path
 *        }
 *
 *        public Author getAuthor() {
 *            // return author
 *        }
 *
 *     }
 *
 *     public class Author implements ContentBean {
 *
 *         public String getName() {
 *             // return name
 *         }
 *
 *     }
 *
 * </code>
 * </pre>
 *
 */
public interface ContentBean {

}

Difference between IdentifiableContentBean and ContentBean

Any ContentBean implementation is suited for being indexed : This means, will have their methods with @IndexField used during indexing. However, only IdentifiableContentBean's will be suited to create a Solr document. This is because the IdentifiableContentBean contains

@IgnoreForCompoundBean
@IndexField(name="id")
String getIdentifier();

where the getIdentifier() return value is used as (solr|lucene) index identifier. In other words:

Objects that implement IdentifiableContentBean can be indexed as Solr index document. Objects that only implement ContentBean and do not have a getter annotated with @IndexField(name="id") can only be indexed as Compound

Note: An object that only implements ContentBean but adds the @IndexField(name="id") to a getter that contains its identifier could thus also be indexed as Solr document without implementing IdentifiableContentBean

 

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?