View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, see
18   * <http://www.gnu.org/licenses/>.
19   */
20  
21  package org.jumpmind.symmetric.service.impl;
22  
23  import java.sql.SQLException;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.apache.commons.lang.exception.ExceptionUtils;
28  import org.jumpmind.symmetric.service.IParameterService;
29  import org.springframework.jdbc.core.JdbcTemplate;
30  import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
31  
32  abstract class AbstractService {
33  
34      protected IParameterService parameterService;
35  
36      protected JdbcTemplate jdbcTemplate;
37  
38      private Map<String, String> sql;
39  
40      public void setJdbcTemplate(JdbcTemplate jdbc) {
41          this.jdbcTemplate = jdbc;
42      }
43      
44      protected SimpleJdbcTemplate getSimpleTemplate() {
45          return new SimpleJdbcTemplate(jdbcTemplate);
46      }
47      
48      @SuppressWarnings("unchecked")
49      protected SQLException unwrapSqlException(Throwable e) {
50          List<Throwable> exs = ExceptionUtils.getThrowableList(e);
51          for (Throwable throwable : exs) {
52              if (throwable instanceof SQLException) {
53                  return (SQLException) throwable;
54              }
55          }
56          return null;
57      }    
58  
59      public void setSql(Map<String, String> sql) {
60          this.sql = sql;
61      }
62  
63      public String getSql(String key) {
64          return sql.get(key);
65      }
66  
67      public void setParameterService(IParameterService parameterService) {
68          this.parameterService = parameterService;
69      }
70  
71  }