Skip to content

Commit

Permalink
debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
ayax79 committed Sep 2, 2009
1 parent 5c7ab3c commit 441c18d
Showing 1 changed file with 14 additions and 5 deletions.
Expand Up @@ -32,6 +32,7 @@
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.annotations.Indexed;

import java.io.File;
Expand Down Expand Up @@ -181,8 +182,6 @@ private FullTextSession processObjects(FullTextSession fullTextSession, Connecti
Session session = sessionFactory.openSession(con);
fullTextSession = Search.getFullTextSession(session);

Transaction tx = fullTextSession.beginTransaction();

Map<String, ClassMetadata> metadata = sessionFactory.getAllClassMetadata();

for (Map.Entry<String, ClassMetadata> entry : metadata.entrySet()) {
Expand All @@ -192,17 +191,24 @@ private FullTextSession processObjects(FullTextSession fullTextSession, Connecti
if (clazz.isAnnotationPresent(Indexed.class)) {
getLog().info("Indexing " + entry);

Criteria criteria = session.createCriteria(clazz);
Transaction tx = fullTextSession.beginTransaction();
Criteria criteria = fullTextSession.createCriteria(clazz);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

DirectoryProvider[] providers = fullTextSession.getSearchFactory().getDirectoryProviders(clazz);
for (DirectoryProvider provider : providers) {
getLog().info("Index directory: "+provider.getDirectory());
}

List<?> list = criteria.list();
for (Object o : list) {
fullTextSession.index(o);
}
fullTextSession.flushToIndexes();
tx.commit();
}
}

tx.commit();
return fullTextSession;
}

Expand All @@ -220,7 +226,10 @@ private void prepareIndexDir(Configuration configuration) throws IOException {
//noinspection ResultOfMethodCallIgnored
dir.mkdirs();
}
configuration.setProperty("hibernate.index.dir", indexDir);
if (!dir.exists()) {
throw new IOException("failed to create directory");
}
configuration.setProperty("hibernate.search.default.indexBase", indexDir);
}

/**
Expand Down

0 comments on commit 441c18d

Please sign in to comment.