I am new to Java EE 6, so I apologize if the answer to this question is obvious. I have a task that needs to be done hourly to restore the Solr index from the database. I also want the rebuild to happen when the application is deployed. My gut instinct is that this should work:
@Singleton
@Startup
public class Rebuilder {
@Inject private ProposalDao proposalDao;
@Inject private SolrServer solrServer;
@Schedule(hour="*", minute="0", second="0")
public void rebuildIndex() {
}
}
Since I use myBatis, I wrote this producer:
public class ProposalSessionProvider {
private static final String CONFIGURATION_FILE = "...";
static {
try {
sessFactory = new SqlSessionFactoryBuilder().build(
Resources.getResourceAsReader(CONFIGURATION_FILE));
}
catch (IOException ex) {
throw new RuntimeException("Error configuring MyBatis: " + ex.getMessage(), ex);
}
}
@Produces
public ProposalsDao openSession() {
log.info("Connecting to the database");
session = sessFactory.openSession();
return session.getMapper(ProposalsDao.class);
}
}
So, I have three problems:
- What is the way to start rebuilding during deployment? A
@PostConstructmethod? - ? myBatis, , , Java EE. ,
@Singleton, , @Startup @Stateless bean? - Rebuilder ? ,
@PostConstruct .
, . .