// get a connection to the proxy database
Connection source;
try {
source = _dataSource.getConnection();
} catch (SQLException exception) {
throw new PersistenceException(
"Failed to get connection to source database",
exception);
}
_database.start();
// init master stores
MasterDestinationStore masterDestinations
= new MasterDestinationStore(_database);
MasterMessageStore masterMessages = new MasterMessageStore(_database);
MasterConsumerStore masterConsumers
= new MasterConsumerStore(_database);
MasterUserStore masterUsers = new MasterUserStore(_database);
// init proxy stores
PropertyStore properties = new PropertyStore(source);
VersionInfo info = new VersionInfo(properties);
String schemaVersion = info.getProxySchemaVersion();
if (schemaVersion == null || !schemaVersion.equals("1.0")) {
throw new PersistenceException("Cannot import data: unsupported schema version: "
+ schemaVersion);
}
Date created = new Date(info.getCreationTimestamp());
_log.info("Importing data created on " + created + " by OpenJMS "
+ info.getOpenJMSVersion());
DestinationStore destinations = new DestinationStore(source);
ConsumerStore consumers = new ConsumerStore(destinations, source);
MessageStore messages = new MessageStore(destinations, source);
UserStore users = new UserStore(source);
// import data from the proxy database to the master database
_log.info("Importing destinations...");
apply(destinations, masterDestinations);
_log.info("Imported " + masterDestinations.size() + " destinations");
_log.info("Importing messages...");
apply(messages, masterMessages);
_log.info("Imported " + masterMessages.size() + " messages");
_log.info("Importing consumers...");
apply(consumers, new MasterConsumerStore(_database));
_log.info("Imported " + masterConsumers.size() + " consumers");
_log.info("Importing users...");
apply(users, new MasterUserStore(_database));
_log.info("Imported " + masterUsers.size() + " users");
try {
source.close();
} catch (SQLException exception) {
throw new PersistenceException("Failed to close source",
exception);
}
_database.stop();
_dataSource.setShutdownDatabase("shutdown");