* @param config The {@link Configuration} to save
* @throws OutOfSyncException If the {@link Configuration} is <code>null</code> or out of
* synchronization with database
*/
public void saveConfig(Configuration config) throws OutOfSyncException {
ScanConfigOutOfSyncException exception = null;
if (config == null) {
exception = new ScanConfigOutOfSyncException("Can't save a null configuration");
}
else {
Configuration configuration = getConfigById(config.getId());
boolean newConfig = configuration == null;
// Checking if the configuration is out of synchronization
if (!newConfig && !config.getTimestamp().equals(configuration.getTimestamp())) {
exception = new ScanConfigOutOfSyncException();
}
else {
// Checking if the configuration directory has been deleted
IDirectory directory = getDirectoryById(config.getDirectoryId(), false);
if (directory == null
|| !directory.getTimestamp().equals(config.getDirectory().getTimestamp())) {
exception = new ScanConfigOutOfSyncException();
}
else {
StringBuilder queryBuilder = new StringBuilder();
if (newConfig) {
queryBuilder.append("INSERT INTO config (name, type, data, directoryid) ");