// Path: src/main/java/com/raibledesigns/dao/GenericDao.java
// public interface GenericDao <T, PK extends Serializable> {
// 
//     /**
//      * Generic method used to get all objects of a particular type. This
//      * is the same as lookup up all rows in a table.
//      * @return List of populated objects
//      */
//     List<T> getAll();
// 
//     /**
//      * Gets all records without duplicates.
//      * <p>Note that if you use this method, it is imperative that your model
//      * classes correctly implement the hashcode/equals methods</p>
//      * @return List of populated objects
//      */
//     List<T> getAllDistinct();
// 
//     /**
//      * Gets all records that match a search term. "*" will get them all.
//      * @param searchTerm the term to search for
//      * @return the mathing records
//      * @throws SearchException
//      */
//     List<T> search(String searchTerm) throws SearchException;
// 
//     /**
//      * Generic method to get an object based on class and identifier. An
//      * ObjectRetrievalFailureException Runtime Exception is thrown if
//      * nothing is found.
//      *
//      * @param id the identifier (primary key) of the object to get
//      * @return a populated object
//      * @see org.springframework.orm.ObjectRetrievalFailureException
//      */
//     T get(PK id);
// 
//     /**
//      * Checks for existence of an object of type T using the id arg.
//      * @param id the id of the entity
//      * @return - true if it exists, false if it doesn't
//      */
//     boolean exists(PK id);
// 
//     /**
//      * Generic method to save an object - handles both update and insert.
//      * @param object the object to save
//      * @return the persisted object
//      */
//     T save(T object);
// 
//     /**
//      * Generic method to delete an object
//      * @param object the object to remove
//      */
//     void remove(T object);
// 
//     /**
//      * Generic method to delete an object
//      * @param id the identifier (primary key) of the object to remove
//      */
//     void remove(PK id);
// 
//     /**
//      * Generic method to regenerate full text index of the persistent class T
//      */
//     void reindex();
// 
//     /**
//      * Generic method to regenerate full text index of all indexed classes
//      * @param async true to perform the reindexing asynchronously
//      */
//     void reindexAll(boolean async);
// }
// 
// Path: src/main/java/com/raibledesigns/dao/SearchException.java
// public class SearchException extends RuntimeException {
// 
//     public SearchException(Throwable ex) {
//         super(ex);
//     }
// 
// }


import com.raibledesigns.dao.GenericDao;
import com.raibledesigns.dao.SearchException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.util.Version;
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.PersistenceContext;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
        return entity != null;
    }

    /**
     * {@inheritDoc}
     */
    public T save(T object) {
        return this.entityManager.merge(object);
    }

    /**
     * {@inheritDoc}
     */
    public void remove(T object) {
        entityManager.remove(entityManager.contains(object) ? object : entityManager.merge(object));
    }

    /**
     * {@inheritDoc}
     */
    public void remove(PK id) {
        this.entityManager.remove(this.get(id));
    }

    public List<T> search(String searchTerm) throws SearchException {
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
        org.apache.lucene.search.Query qry;
        try {
            qry = HibernateSearchJpaTools.generateQuery(searchTerm, this.persistentClass, entityManager, defaultAnalyzer);
        } catch (ParseException ex) {
// Path: src/main/java/com/raibledesigns/dao/GenericDao.java
// public interface GenericDao <T, PK extends Serializable> {
// 
//     /**
//      * Generic method used to get all objects of a particular type. This
//      * is the same as lookup up all rows in a table.
//      * @return List of populated objects
//      */
//     List<T> getAll();
// 
//     /**
//      * Gets all records without duplicates.
//      * <p>Note that if you use this method, it is imperative that your model
//      * classes correctly implement the hashcode/equals methods</p>
//      * @return List of populated objects
//      */
//     List<T> getAllDistinct();
// 
//     /**
//      * Gets all records that match a search term. "*" will get them all.
//      * @param searchTerm the term to search for
//      * @return the mathing records
//      * @throws SearchException
//      */
//     List<T> search(String searchTerm) throws SearchException;
// 
//     /**
//      * Generic method to get an object based on class and identifier. An
//      * ObjectRetrievalFailureException Runtime Exception is thrown if
//      * nothing is found.
//      *
//      * @param id the identifier (primary key) of the object to get
//      * @return a populated object
//      * @see org.springframework.orm.ObjectRetrievalFailureException
//      */
//     T get(PK id);
// 
//     /**
//      * Checks for existence of an object of type T using the id arg.
//      * @param id the id of the entity
//      * @return - true if it exists, false if it doesn't
//      */
//     boolean exists(PK id);
// 
//     /**
//      * Generic method to save an object - handles both update and insert.
//      * @param object the object to save
//      * @return the persisted object
//      */
//     T save(T object);
// 
//     /**
//      * Generic method to delete an object
//      * @param object the object to remove
//      */
//     void remove(T object);
// 
//     /**
//      * Generic method to delete an object
//      * @param id the identifier (primary key) of the object to remove
//      */
//     void remove(PK id);
// 
//     /**
//      * Generic method to regenerate full text index of the persistent class T
//      */
//     void reindex();
// 
//     /**
//      * Generic method to regenerate full text index of all indexed classes
//      * @param async true to perform the reindexing asynchronously
//      */
//     void reindexAll(boolean async);
// }
// 
// Path: src/main/java/com/raibledesigns/dao/SearchException.java
// public class SearchException extends RuntimeException {
// 
//     public SearchException(Throwable ex) {
//         super(ex);
//     }
// 
// }


// Path: src/main/java/com/raibledesigns/dao/jpa/GenericDaoJpa.java
import com.raibledesigns.dao.GenericDao;
import com.raibledesigns.dao.SearchException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.util.Version;
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.PersistenceContext;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;

        return entity != null;
    }

    /**
     * {@inheritDoc}
     */
    public T save(T object) {
        return this.entityManager.merge(object);
    }

    /**
     * {@inheritDoc}
     */
    public void remove(T object) {
        entityManager.remove(entityManager.contains(object) ? object : entityManager.merge(object));
    }

    /**
     * {@inheritDoc}
     */
    public void remove(PK id) {
        this.entityManager.remove(this.get(id));
    }

    public List<T> search(String searchTerm) throws SearchException {
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
        org.apache.lucene.search.Query qry;
        try {
            qry = HibernateSearchJpaTools.generateQuery(searchTerm, this.persistentClass, entityManager, defaultAnalyzer);
        } catch (ParseException ex) {
            throw new SearchException(ex);