Skip to content

Commit

Permalink
change hibernate search method index() into async mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mincong-h committed May 1, 2016
1 parent 322c58a commit 2b2ac86
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
Expand Up @@ -25,10 +25,9 @@ public class IndexServlet extends HttpServlet {

@EJB
private AddressSession addressSession;

protected void service(HttpServletRequest request,
HttpServletResponse response) {

try {
addressSession.index();
} catch (InterruptedException e) {
Expand Down
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import javax.ejb.Asynchronous;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
Expand Down Expand Up @@ -34,22 +35,17 @@ public AddressSession() {

@SuppressWarnings("unchecked")
public List<Address> getAddresses() {
List<Address> addresses = null;
if (entityManager == null) {
logger.warn("entityManager is NULL");
return null;
}
addresses = entityManager
return entityManager
.createQuery("SELECT a FROM Address a WHERE a.type = :type")
.setParameter("type", "Rd")
.setMaxResults(1000)
.getResultList();
if (addresses.isEmpty()) {
logger.warn("No result found.");
}
return addresses;
}

// @Asynchronous Used to mark a session bean method as an asynchronous
// method or to designate all business methods of a session bean class
// as asynchronous.
@Asynchronous
public void index() throws InterruptedException {
fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
fullTextEntityManager
Expand Down
1 change: 0 additions & 1 deletion us-address/src/main/resources/META-INF/persistence.xml
Expand Up @@ -14,7 +14,6 @@
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/MySqlDS-addresses</jta-data-source>
<class>io.github.mincongh.entity.Address</class>
<!-- <class>io.github.mincongh.entity.AddressPK</class> -->
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.show_sql" value="false" />
Expand Down

0 comments on commit 2b2ac86

Please sign in to comment.