CCM NG: Basic integration for Hibernate Search
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4487 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: 60661478fd
pull/2/head
parent
a38485014b
commit
c4662f4274
|
|
@ -64,7 +64,7 @@
|
|||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-search</artifactId>
|
||||
<artifactId>hibernate-search-orm</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import javax.validation.constraints.NotNull;
|
|||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -50,6 +51,8 @@ import java.util.Objects;
|
|||
import static org.libreccm.core.CoreConstants.CORE_XML_NS;
|
||||
import static org.libreccm.core.CoreConstants.DB_SCHEMA;
|
||||
|
||||
import org.hibernate.search.annotations.Field;
|
||||
|
||||
/**
|
||||
* Root class of all entities in LibreCCM which need categorisation and
|
||||
* permission services.
|
||||
|
|
@ -92,6 +95,7 @@ public class CcmObject implements Identifiable, Serializable {
|
|||
@Id
|
||||
@Column(name = "OBJECT_ID")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Field
|
||||
@XmlElement(name = "object-id", namespace = CORE_XML_NS)
|
||||
private long objectId;
|
||||
|
||||
|
|
@ -100,6 +104,7 @@ public class CcmObject implements Identifiable, Serializable {
|
|||
*/
|
||||
@Column(name = "UUID", unique = true)
|
||||
@NotNull
|
||||
@Field
|
||||
@XmlElement(name = "uuid")
|
||||
private String uuid;
|
||||
|
||||
|
|
@ -108,6 +113,7 @@ public class CcmObject implements Identifiable, Serializable {
|
|||
*/
|
||||
@Column(name = "DISPLAY_NAME")
|
||||
@Audited
|
||||
@Field
|
||||
@XmlElement(name = "display-name", namespace = CORE_XML_NS)
|
||||
private String displayName;
|
||||
|
||||
|
|
|
|||
|
|
@ -453,6 +453,18 @@ public class CcmIntegrator implements Integrator {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper method for getting a setting from the configuration database.
|
||||
* We can't use JPA/Hibernate in this class because the JPA subsystem is
|
||||
* not initialised when this class runs. Therefore we have the fallback to
|
||||
* JDBC here.
|
||||
*
|
||||
* @param connection Connection to the database.
|
||||
* @param settingClass Setting class used to represent the setting.
|
||||
* @param settingName The name of the setting to retrieve.
|
||||
* @return The value of the setting.
|
||||
* @throws SQLException
|
||||
*/
|
||||
private Optional<String> getSetting(final Connection connection,
|
||||
final String settingClass,
|
||||
final String settingName)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (C) 2016 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.search;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.hibernate.search.MassIndexer;
|
||||
import org.hibernate.search.SearchFactory;
|
||||
import org.hibernate.search.jpa.FullTextEntityManager;
|
||||
import org.hibernate.search.jpa.Search;
|
||||
import org.hibernate.search.query.dsl.QueryBuilder;
|
||||
import org.libreccm.core.CoreConstants;
|
||||
import org.libreccm.security.AuthorizationRequired;
|
||||
import org.libreccm.security.RequiresPrivilege;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SearchManager {
|
||||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
private FullTextEntityManager fullTextEntityManager;
|
||||
|
||||
public SearchManager() {
|
||||
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
|
||||
}
|
||||
|
||||
@AuthorizationRequired
|
||||
@RequiresPrivilege(CoreConstants.PRIVILEGE_ADMIN)
|
||||
public Future<?> rebuildIndex() {
|
||||
final MassIndexer indexer = fullTextEntityManager.createIndexer();
|
||||
return indexer.start();
|
||||
}
|
||||
|
||||
public QueryBuilder createQueryBuilder(final Class<?> entityClass) {
|
||||
final SearchFactory searchFactory = fullTextEntityManager.getSearchFactory();
|
||||
return searchFactory.buildQueryBuilder().forEntity(entityClass).get();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<?> executeQuery(final Query query) {
|
||||
final javax.persistence.Query jpaQuery = fullTextEntityManager
|
||||
.createFullTextQuery(query);
|
||||
|
||||
return jpaQuery.getResultList();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue