View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.driver.state.circuit.connection;
19  
20  import org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedOperationConnection;
21  import org.apache.shardingsphere.driver.state.circuit.metadata.CircuitBreakerDatabaseMetaData;
22  import org.apache.shardingsphere.driver.state.circuit.statement.CircuitBreakerPreparedStatement;
23  import org.apache.shardingsphere.driver.state.circuit.statement.CircuitBreakerStatement;
24  
25  import java.sql.Array;
26  import java.sql.CallableStatement;
27  import java.sql.Connection;
28  import java.sql.DatabaseMetaData;
29  import java.sql.PreparedStatement;
30  import java.sql.SQLException;
31  import java.sql.SQLFeatureNotSupportedException;
32  import java.sql.SQLWarning;
33  import java.sql.Savepoint;
34  import java.sql.Statement;
35  
36  /**
37   * Circuit breaker connection.
38   */
39  public final class CircuitBreakerConnection extends AbstractUnsupportedOperationConnection {
40      
41      @Override
42      public DatabaseMetaData getMetaData() {
43          return new CircuitBreakerDatabaseMetaData();
44      }
45      
46      @Override
47      public void setReadOnly(final boolean readOnly) {
48      }
49      
50      @Override
51      public boolean isReadOnly() {
52          return false;
53      }
54      
55      @Override
56      public void setCatalog(final String catalog) {
57      }
58      
59      @Override
60      public String getCatalog() {
61          return "";
62      }
63      
64      @Override
65      public void setTransactionIsolation(final int level) {
66      }
67      
68      @Override
69      public int getTransactionIsolation() {
70          return Connection.TRANSACTION_NONE;
71      }
72      
73      @Override
74      public SQLWarning getWarnings() {
75          return null;
76      }
77      
78      @Override
79      public void clearWarnings() {
80      }
81      
82      @Override
83      public void setAutoCommit(final boolean autoCommit) {
84      }
85      
86      @Override
87      public boolean getAutoCommit() {
88          return false;
89      }
90      
91      @Override
92      public void commit() {
93      }
94      
95      @Override
96      public void rollback() {
97      }
98      
99      @Override
100     public void rollback(final Savepoint savepoint) throws SQLException {
101         throw new SQLFeatureNotSupportedException("rollback savepoint");
102     }
103     
104     @Override
105     public Savepoint setSavepoint() throws SQLException {
106         throw new SQLFeatureNotSupportedException("setSavepoint");
107     }
108     
109     @Override
110     public Savepoint setSavepoint(final String name) throws SQLException {
111         throw new SQLFeatureNotSupportedException("setSavepoint name");
112     }
113     
114     @Override
115     public void releaseSavepoint(final Savepoint savepoint) throws SQLException {
116         throw new SQLFeatureNotSupportedException("releaseSavepoint");
117     }
118     
119     @Override
120     public void setHoldability(final int holdability) {
121     }
122     
123     @Override
124     public int getHoldability() {
125         return 0;
126     }
127     
128     @Override
129     public PreparedStatement prepareStatement(final String sql) {
130         return new CircuitBreakerPreparedStatement();
131     }
132     
133     @Override
134     public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency) {
135         return new CircuitBreakerPreparedStatement();
136     }
137     
138     @Override
139     public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) {
140         return new CircuitBreakerPreparedStatement();
141     }
142     
143     @Override
144     public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) {
145         return new CircuitBreakerPreparedStatement();
146     }
147     
148     @Override
149     public PreparedStatement prepareStatement(final String sql, final int[] columnIndexes) {
150         return new CircuitBreakerPreparedStatement();
151     }
152     
153     @Override
154     public PreparedStatement prepareStatement(final String sql, final String[] columnNames) {
155         return new CircuitBreakerPreparedStatement();
156     }
157     
158     @Override
159     public CallableStatement prepareCall(final String sql) throws SQLException {
160         throw new SQLFeatureNotSupportedException("prepareCall");
161     }
162     
163     @Override
164     public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException {
165         throw new SQLFeatureNotSupportedException("prepareCall");
166     }
167     
168     @Override
169     public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) throws SQLException {
170         throw new SQLFeatureNotSupportedException("prepareCall");
171     }
172     
173     @Override
174     public boolean isValid(final int timeout) {
175         return true;
176     }
177     
178     @Override
179     public Array createArrayOf(final String typeName, final Object[] elements) {
180         return null;
181     }
182     
183     @Override
184     public void setSchema(final String schema) {
185     }
186     
187     @Override
188     public String getSchema() {
189         return "";
190     }
191     
192     @Override
193     public Statement createStatement() {
194         return new CircuitBreakerStatement();
195     }
196     
197     @Override
198     public Statement createStatement(final int resultSetType, final int resultSetConcurrency) {
199         return new CircuitBreakerStatement();
200     }
201     
202     @Override
203     public Statement createStatement(final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) {
204         return new CircuitBreakerStatement();
205     }
206     
207     @Override
208     public void close() {
209     }
210     
211     @Override
212     public boolean isClosed() {
213         return false;
214     }
215 }