Skip to main content
summaryrefslogtreecommitdiffstats
blob: a82da6616101d6d2f536257e9e7924dad89917c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*******************************************************************************
 * Copyright (c) 2013 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.database.internal.core;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
import org.eclipse.osee.framework.database.core.OseeConnection;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;

/**
 * @author Roberto E. Escobar
 */
public class BaseOseeConnection extends OseeConnection {

   private static final int timeout = 60000;
   private final Connection conn;

   public BaseOseeConnection(Connection conn) {
      super();
      this.conn = conn;
   }

   @Override
   public boolean isStale() {
      boolean result = true;
      try {
         result = !conn.isValid(timeout);
      } catch (SQLException ex) {
         // do nothing
      }
      return result;
   }

   @Override
   public void close() throws OseeCoreException {
      destroy();
   }

   @Override
   public boolean isClosed() throws OseeCoreException {
      try {
         return conn.isClosed();
      } catch (SQLException ex) {
         OseeExceptions.wrapAndThrow(ex);
         return false; // unreachable since wrapAndThrow() always throws an exception
      }
   }

   @Override
   public DatabaseMetaData getMetaData() throws OseeCoreException {
      try {
         return conn.getMetaData();
      } catch (SQLException ex) {
         OseeExceptions.wrapAndThrow(ex);
         return null; // unreachable since wrapAndThrow() always throws an exception
      }
   }

   PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
      return conn.prepareStatement(sql, resultSetType, resultSetConcurrency);
   }

   PreparedStatement prepareStatement(String sql) throws SQLException {
      return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
   }

   CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
      return conn.prepareCall(sql, resultSetType, resultSetConcurrency);
   }

   @Override
   protected void destroy() throws OseeCoreException {
      try {
         conn.close();
      } catch (SQLException ex) {
         // Do Nothing - OseeExceptions.wrapAndThrow(ex);
      }
   }

   @Override
   protected void setAutoCommit(boolean autoCommit) throws OseeCoreException {
      try {
         conn.setAutoCommit(autoCommit);
      } catch (SQLException ex) {
         OseeExceptions.wrapAndThrow(ex);
      }
   }

   @Override
   protected boolean getAutoCommit() throws OseeCoreException {
      try {
         return conn.getAutoCommit();
      } catch (SQLException ex) {
         OseeExceptions.wrapAndThrow(ex);
         return false; // unreachable since wrapAndThrow() always throws an exception
      }
   }

   @Override
   protected void commit() throws OseeCoreException {
      try {
         conn.commit();
      } catch (SQLException ex) {
         OseeExceptions.wrapAndThrow(ex);
      }
   }

   @Override
   protected void rollback() throws OseeCoreException {
      try {
         conn.rollback();
      } catch (SQLException ex) {
         OseeExceptions.wrapAndThrow(ex);
      }
   }

}

Back to the top