1 package com.atlassian.activeobjects.backup;
2
3 import com.atlassian.activeobjects.spi.ActiveObjectsImportExportException;
4 import com.atlassian.activeobjects.spi.ImportExportException;
5 import com.atlassian.activeobjects.spi.PluginInformation;
6 import com.atlassian.dbexporter.ImportExportErrorService;
7
8 import java.sql.SQLException;
9
10 import static com.google.common.base.Preconditions.checkNotNull;
11
12 public final class ImportExportErrorServiceImpl implements ImportExportErrorService {
13 private final PluginInformationFactory pluginInformationFactory;
14
15 public ImportExportErrorServiceImpl(PluginInformationFactory pluginInformationFactory) {
16 this.pluginInformationFactory = checkNotNull(pluginInformationFactory);
17 }
18
19 @Override
20 public ImportExportException newImportExportException(String tableName, String message) {
21 return new ActiveObjectsImportExportException(tableName, getPluginInformation(tableName), message);
22 }
23
24 @Override
25 public ImportExportException newImportExportSqlException(String tableName, String message, SQLException e) {
26 return new ActiveObjectsImportExportException(tableName, getPluginInformation(tableName), message, e);
27 }
28
29 @Override
30 public ImportExportException newRowImportSqlException(String tableName, long rowNum, SQLException e) {
31 return new ActiveObjectsImportExportException(tableName,
32 getPluginInformation(tableName),
33 "There has been a SQL exception importing row #"
34 + rowNum + " for table '" + tableName +
35 "' see the cause of this exception for more detail about it.", e);
36 }
37
38 @Override
39 public ImportExportException newParseException(Throwable t) {
40 return new ActiveObjectsImportExportException(null, getPluginInformation(null), t);
41 }
42
43 @Override
44 public ImportExportException newParseException(String message) {
45 return new ActiveObjectsImportExportException(null, getPluginInformation(null), message);
46 }
47
48 @Override
49 public ImportExportException newParseException(String message, Throwable t) {
50 return new ActiveObjectsImportExportException(null, getPluginInformation(null), message, t);
51 }
52
53 private PluginInformation getPluginInformation(String tableName) {
54 return pluginInformationFactory.getPluginInformation(tableName);
55 }
56 }