Revision 41346
Added by Alessia Bardi over 8 years ago
DatabaseServiceImpl.java | ||
---|---|---|
3 | 3 |
import java.util.Date; |
4 | 4 |
import java.util.concurrent.ExecutorService; |
5 | 5 |
import java.util.concurrent.Executors; |
6 |
|
|
7 | 6 |
import javax.xml.ws.wsaddressing.W3CEndpointReference; |
8 | 7 |
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
import org.springframework.beans.factory.annotation.Required; |
|
12 |
|
|
13 | 8 |
import eu.dnetlib.enabling.database.rmi.DatabaseException; |
14 | 9 |
import eu.dnetlib.enabling.database.rmi.DatabaseService; |
15 | 10 |
import eu.dnetlib.enabling.resultset.XSLTMappedResultSetFactory; |
16 | 11 |
import eu.dnetlib.enabling.tools.AbstractBaseService; |
12 |
import org.apache.commons.logging.Log; |
|
13 |
import org.apache.commons.logging.LogFactory; |
|
14 |
import org.springframework.beans.factory.annotation.Required; |
|
17 | 15 |
|
18 | 16 |
public class DatabaseServiceImpl extends AbstractBaseService implements DatabaseService { |
19 | 17 |
|
... | ... | |
28 | 26 |
private ExecutorService threadPool = Executors.newCachedThreadPool(); |
29 | 27 |
|
30 | 28 |
@Override |
31 |
public W3CEndpointReference dumpTable(final String db, final String table) { |
|
32 |
return core.generateResultSet(db, table, null); |
|
29 |
public W3CEndpointReference dumpTable(final String db, final String table) throws DatabaseException { |
|
30 |
try { |
|
31 |
return core.generateResultSet(db, table, null); |
|
32 |
} catch (Throwable e) { |
|
33 |
throw new DatabaseException(e); |
|
34 |
} |
|
33 | 35 |
} |
34 | 36 |
|
35 | 37 |
@Override |
36 |
public W3CEndpointReference dumpTableAndLogs(final String db, final String table, final Date from, final Date until) { |
|
37 |
return core.generateResultSet(db, table, from, until); |
|
38 |
public W3CEndpointReference dumpTableAndLogs(final String db, final String table, final Date from, final Date until) throws DatabaseException { |
|
39 |
try { |
|
40 |
return core.generateResultSet(db, table, from, until); |
|
41 |
} catch (Throwable e) { |
|
42 |
throw new DatabaseException(e); |
|
43 |
} |
|
38 | 44 |
} |
39 | 45 |
|
40 | 46 |
@Override |
... | ... | |
48 | 54 |
} |
49 | 55 |
|
50 | 56 |
@Override |
51 |
public boolean importFromEPR(final String db, final W3CEndpointReference epr, final String xslt) {
|
|
57 |
public void importFromEPR(final String db, final W3CEndpointReference epr, final String xslt) throws DatabaseException {
|
|
52 | 58 |
|
53 | 59 |
final W3CEndpointReference mappedEpr = (xslt == null || xslt.isEmpty()) ? |
54 | 60 |
epr : xsltResultsetFactory.createMappedResultSet(epr, xslt) ; |
55 |
|
|
56 |
|
|
57 |
threadPool.execute(new Runnable() { |
|
58 |
@Override |
|
59 |
public void run() { |
|
60 |
try { |
|
61 |
core.importFromResultset(db, mappedEpr); |
|
62 |
} catch (final Exception e) { |
|
63 |
log.error("Error in thread when importing from epr", e); |
|
61 |
|
|
62 |
try { |
|
63 |
threadPool.execute(new Runnable() { |
|
64 |
@Override |
|
65 |
public void run() { |
|
66 |
try { |
|
67 |
core.importFromResultset(db, mappedEpr); |
|
68 |
} catch (final Exception e) { |
|
69 |
log.error("Error in thread when importing from epr", e); |
|
70 |
throw new RuntimeException(e); |
|
71 |
} |
|
64 | 72 |
} |
65 |
} |
|
66 |
});
|
|
67 |
|
|
68 |
return true;
|
|
73 |
});
|
|
74 |
} catch (RuntimeException e) {
|
|
75 |
throw new DatabaseException(e); |
|
76 |
}
|
|
69 | 77 |
} |
70 | 78 |
|
71 | 79 |
@Required |
... | ... | |
74 | 82 |
} |
75 | 83 |
|
76 | 84 |
@Override |
77 |
public W3CEndpointReference searchSQL(final String db, final String sql) { |
|
85 |
public W3CEndpointReference searchSQL(final String db, final String sql) throws DatabaseException { |
|
86 |
try { |
|
78 | 87 |
return core.generateResultSet(db, sql); |
88 |
} catch (Throwable e) { |
|
89 |
throw new DatabaseException(e); |
|
90 |
} |
|
79 | 91 |
} |
80 | 92 |
|
81 | 93 |
@Override |
82 |
public W3CEndpointReference alternativeSearchSQL(String db, String sql, String sqlForSize) { |
|
83 |
return core.generateResultsetWithSize(db, sql, sqlForSize); |
|
94 |
public W3CEndpointReference alternativeSearchSQL(String db, String sql, String sqlForSize) throws DatabaseException { |
|
95 |
try { |
|
96 |
return core.generateResultsetWithSize(db, sql, sqlForSize); |
|
97 |
} catch (Throwable e) { |
|
98 |
throw new DatabaseException(e); |
|
99 |
} |
|
84 | 100 |
} |
85 | 101 |
|
86 | 102 |
@Override |
87 |
public boolean updateSQL(final String db, final String sql) { |
|
88 |
try { |
|
89 |
core.getDbUtils().executeSql(db, sql); |
|
90 |
return true; |
|
91 |
} catch (DatabaseException e) { |
|
92 |
log.error("error updating db: " + db + " sql: " + sql, e); |
|
93 |
return false; |
|
94 |
} |
|
103 |
public void updateSQL(final String db, final String sql) throws DatabaseException { |
|
104 |
core.getDbUtils().executeSql(db, sql); |
|
95 | 105 |
} |
96 | 106 |
|
97 | 107 |
@Override |
98 |
public W3CEndpointReference xsltSearchSQL(final String db, final String sql, final String xslt) { |
|
108 |
public W3CEndpointReference xsltSearchSQL(final String db, final String sql, final String xslt) throws DatabaseException {
|
|
99 | 109 |
try { |
100 | 110 |
return xsltResultsetFactory.createMappedResultSet(searchSQL(db, sql), xslt); |
101 |
} catch (Exception e) {
|
|
102 |
throw new RuntimeException("Error returning a transformed resultSet", e);
|
|
111 |
} catch (Throwable e) {
|
|
112 |
throw new DatabaseException("Error returning a transformed resultSet", e);
|
|
103 | 113 |
} |
104 | 114 |
} |
105 | 115 |
|
106 | 116 |
@Override |
107 |
public W3CEndpointReference alternativeXsltSearchSQL(String db, String sql, String sqlForSize, String xslt) { |
|
117 |
public W3CEndpointReference alternativeXsltSearchSQL(String db, String sql, String sqlForSize, String xslt) throws DatabaseException {
|
|
108 | 118 |
try { |
109 | 119 |
return xsltResultsetFactory.createMappedResultSet(alternativeSearchSQL(db, sql, sqlForSize), xslt); |
110 |
} catch (Exception e) {
|
|
111 |
throw new RuntimeException("Error returning a transformed resultSet", e);
|
|
120 |
} catch (Throwable e) {
|
|
121 |
throw new DatabaseException("Error returning a transformed resultSet", e);
|
|
112 | 122 |
} |
113 | 123 |
} |
114 | 124 |
|
115 | 125 |
|
116 | 126 |
@Override |
117 |
public boolean contains(final String db, final String table, final String column, final String value) { |
|
127 |
public boolean contains(final String db, final String table, final String column, final String value) throws DatabaseException {
|
|
118 | 128 |
return core.getDbUtils().contains(db, table, column, value); |
119 | 129 |
} |
120 | 130 |
|
Also available in: Unified diff
throwing DatabaseException whenever we need to. Updated signatures to the latest changes in the service interface.