My fork of airsonic with experimental fixes and improvements. See branch "custom"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
airsonic-custom/airsonic-main/src/main/java/org/airsonic/player/dao/LegacyHsqlDaoHelper.java

59 lines
1.9 KiB

package org.airsonic.player.dao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceUtils;
import javax.annotation.PreDestroy;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
/**
* Special Dao Helper with additional features for managing the legacy embedded HSQL database.
*/
public class LegacyHsqlDaoHelper extends GenericDaoHelper {
private static final Logger LOG = LoggerFactory.getLogger(LegacyHsqlDaoHelper.class);
public LegacyHsqlDaoHelper(DataSource dataSource) {
super(dataSource);
}
@Override
public void checkpoint() {
// HSQLDB (at least version 1) does not handle automatic checkpoints very well by default.
// This makes sure the temporary log is actually written to more persistent storage.
LOG.debug("Database checkpoint in progress...");
getJdbcTemplate().execute("CHECKPOINT DEFRAG");
LOG.debug("Database checkpoint complete.");
}
@PreDestroy
public void onDestroy() {
Connection conn = null;
try {
// Properly shutdown the embedded HSQLDB database.
LOG.debug("Database shutdown in progress...");
JdbcTemplate jdbcTemplate = getJdbcTemplate();
conn = DataSourceUtils.getConnection(jdbcTemplate.getDataSource());
conn.setAutoCommit(true);
jdbcTemplate.execute("SHUTDOWN");
LOG.debug("Database shutdown complete.");
} catch (SQLException e) {
LOG.error("Database shutdown failed: " + e);
e.printStackTrace();
} finally {
try {
if (conn != null)
conn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}