/** * @param entity */ protected void index(E entity) { getFullTextSession().index(entity); }
/** * @param entity */ protected void index(E entity) { getFullTextSession().index(entity); }
/** * @see org.openmrs.api.db.ContextDAO#updateSearchIndexForObject(java.lang.Object) */ @Override @Transactional public void updateSearchIndexForObject(Object object) { FullTextSession session = Search.getFullTextSession(sessionFactory.getCurrentSession()); session.index(object); session.flushToIndexes(); }
public static void index(FullTextSession fullTextSession, Object dbObj) { fullTextSession.index(dbObj); }
index++; session.index(results.get(0)); if (index % 1000 == 0) {
@Override void go(FullTextSession session) { session.index(obj); session.flushToIndexes(); }
@SuppressWarnings("unchecked") private void indexAllClasses(Class... entityTypes) { FullTextSession fullTextSession = getFullTextSession(); for (Class entityType : entityTypes) { for (Object obj : fullTextSession.createCriteria(entityType).list()) { fullTextSession.index(obj); } } }
FullTextSession fullTextSession = Search.getFullTextSession(session); fullTextSession.openSession() Object customer = fullTextSession.load( Datasheet.class, datasheetDocument.getDatasheet.getId() ); fullTextSession.index(customer); fullTextSession.flushIndex();
@SuppressWarnings("unchecked") private void indexProducts() { FullTextSession fullTextSession = getFullTextSession(); List results = fullTextSession.createCriteria(Product.class) .setFetchMode("actors", FetchMode.JOIN) .setFetchMode("categories", FetchMode.JOIN) .list(); for (Object obj : results) { fullTextSession.index(obj); } }
/** * Calls {@link Session#delete(Object)} * * @param obj * @throws Exception */ public void persist(Object obj) throws Exception { try { if(TransactionStatus.NOT_ACTIVE.equals(session.getTransaction().getStatus())) session.getTransaction().begin(); session.delete(obj); if(isIndexed(obj)) Search.getFullTextSession(session).index(obj); } catch (Exception e) { rollback(); throw e; } }
FullTextSession session = Search.getFullTextSession(getSessionFactory().openSession()); session.setFlushMode(FlushMode.MANUAL); session.setCacheMode(CacheMode.IGNORE); Transaction transaction = session.beginTransaction(); ScrollableResults items = session.createQuery("from Item i ") .scroll(ScrollMode.FORWARD_ONLY); while(items.next()) { Object nextToIndex = items.get(0); session.index(nextToIndex); session.flushToIndexes(); session.clear(); } transaction.commit();
@Test public void testExplicitIndexingIgnoresInterceptor() throws Exception { indexTestData(); Transaction tx = fullTextSession.beginTransaction(); for ( Foo foo : testEntities ) { Foo attachedFoo = (Foo) fullTextSession.merge( foo ); fullTextSession.index( attachedFoo ); } tx.commit(); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( new MatchAllDocsQuery() ); assertEquals( "All test entities should be indexed", testEntities.size(), fullTextQuery.list().size() ); }
/** * Calls {@link Session#refresh(Object)} * * @param obj * @throws Exception */ public void refresh(Object obj) throws Exception { try { if(TransactionStatus.NOT_ACTIVE.equals(session.getTransaction().getStatus())) session.getTransaction().begin(); session.refresh(obj); if(isIndexed(obj)) Search.getFullTextSession(session).index(obj); } catch (Exception e) { rollback(); throw e; } }
/** * Calls {@link Session#saveOrUpdate(Object)} * * @param obj * @throws Exception */ public void saveOrUpdate(Object obj) throws Exception { try { if(TransactionStatus.NOT_ACTIVE.equals(session.getTransaction().getStatus())) session.getTransaction().begin(); session.saveOrUpdate(obj); if(isIndexed(obj)) Search.getFullTextSession(session).index(obj); } catch (Exception e) { rollback(); throw e; } }
/** * Calls {@link Session#update(Object)} * * @param obj * @throws Exception */ public void update(Object obj) throws Exception { try { if(TransactionStatus.NOT_ACTIVE.equals(session.getTransaction().getStatus())) session.getTransaction().begin(); session.update(obj); if(isIndexed(obj)) Search.getFullTextSession(session).index(obj); } catch (Exception e) { rollback(); throw e; } }
/** * Calls {@link Session#save(Object)} * * @param obj * @throws Exception */ public void save(Object obj) throws Exception { try { if(TransactionStatus.NOT_ACTIVE.equals(session.getTransaction().getStatus())) session.getTransaction().begin(); session.persist(obj); if(isIndexed(obj)) Search.getFullTextSession(session).index(obj); } catch (Exception e) { rollback(); throw e; } }
/** * Calls {@link Session#merge(Object)} * * @param obj * @throws Exception */ @SuppressWarnings("unchecked") public <T> T merge(T obj) throws Exception { try { if(TransactionStatus.NOT_ACTIVE.equals(session.getTransaction().getStatus())) session.getTransaction().begin(); T t = (T) session.merge(obj); if(isIndexed(t)) Search.getFullTextSession(session).index(t); return t; } catch (Exception e) { rollback(); throw e; } }
public Object doInJpa(EntityManager em) throws PersistenceException { FullTextSession fullTextSession = getFullTextSession(getHibernateSession(em)); fullTextSession.purgeAll(Webbis.class); // Do not update the second level cache. It will just slow things down. fullTextSession.setCacheMode(CacheMode.GET); // Read 5000 entries at a time. final int BATCH_SIZE = 5000; // Due to a bug in Hibernate (HHH-1283) a join does not work here. // See http://opensource.atlassian.com/projects/hibernate/browse/HHH-1283 ScrollableResults results = fullTextSession.createQuery("from Webbis w").scroll(); int index = 0; while (results.next()) { index++; fullTextSession.index(results.get(0)); // index each element if (index % BATCH_SIZE == 0) { fullTextSession.flushToIndexes(); // apply changes to indexes fullTextSession.clear(); // clear since the queue is processed } } return null; } });
@Test public void writeThenPurge() throws Exception { flush(); List<Level1> all = getAll(); assertEquals( "Wrong total number of entries", 3, all.size() ); // Expect 0 failure in the backend threads logged.expectLevelMissing( Level.ERROR ); Transaction tx = fullTextSession.beginTransaction(); fullTextSession.index( fullTextSession.get( Level1.class, 1L ) ); tx.commit(); tx = fullTextSession.beginTransaction(); fullTextSession.purgeAll( Level1.class ); tx.commit(); flush(); all = getAll(); assertEquals( "Wrong total number of entries. Index should be empty after purge.", 0, all.size() ); tx = fullTextSession.beginTransaction(); fullTextSession.createIndexer() .batchSizeToLoadObjects( 25 ) .threadsToLoadObjects( 1 ) .optimizeOnFinish( true ) .startAndWait(); tx.commit(); flush(); all = getAll(); assertEquals( "Wrong total number of entries.", 3, all.size() ); }
while ( results.next() ) { index++; s.index( results.get( 0 ) ); if ( index % 5 == 0 ) { s.clear();