01: package org.jbpm.ant;
02:
03: import java.sql.Connection;
04: import java.sql.SQLException;
05: import java.sql.Statement;
06:
07: import org.apache.tools.ant.BuildException;
08: import org.apache.tools.ant.Task;
09: import org.hibernate.connection.ConnectionProvider;
10: import org.hibernate.impl.SessionFactoryImpl;
11: import org.jbpm.JbpmConfiguration;
12: import org.jbpm.JbpmContext;
13: import org.jbpm.persistence.db.DbPersistenceServiceFactory;
14: import org.jbpm.svc.Services;
15:
16: public class ShutDownHsqldb extends Task {
17:
18: public void execute() throws BuildException {
19: Connection connection = null;
20: JbpmConfiguration jbpmConfiguration = AntHelper
21: .getJbpmConfiguration(null);
22: JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
23: try {
24: DbPersistenceServiceFactory dbPersistenceServiceFactory = (DbPersistenceServiceFactory) jbpmContext
25: .getServiceFactory(Services.SERVICENAME_PERSISTENCE);
26: SessionFactoryImpl sessionFactory = (SessionFactoryImpl) dbPersistenceServiceFactory
27: .getSessionFactory();
28: ConnectionProvider connectionProvider = sessionFactory
29: .getConnectionProvider();
30: connection = connectionProvider.getConnection();
31: Statement statement = connection.createStatement();
32: log("shutting down database");
33: statement.executeUpdate("SHUTDOWN");
34: connection.close();
35:
36: } catch (SQLException e) {
37: e.printStackTrace();
38: } finally {
39: jbpmContext.close();
40: }
41: }
42:
43: }
|