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.log4j.db;
19  
20  import org.apache.log4j.spi.Component;
21  import org.apache.log4j.spi.OptionHandler;
22  
23  import java.sql.Connection;
24  import java.sql.SQLException;
25  
26  
27  /**
28   * The {@code ConnectionSource} interface provides a pluggable means of
29   * transparently obtaining JDBC {@link java.sql.Connection}s for log4j classes
30   * that require the use of a {@link java.sql.Connection}.
31   *
32   * @author <a href="mailto:rdecampo@twcny.rr.com">Ray DeCampo</a>
33   */
34  public interface ConnectionSource extends Component, OptionHandler {
35  
36      int UNKNOWN_DIALECT = 0;
37      int POSTGRES_DIALECT = 1;
38      int MYSQL_DIALECT = 2;
39      int ORACLE_DIALECT = 3;
40      int MSSQL_DIALECT = 4;
41      int HSQL_DIALECT = 5;
42  
43      /**
44       * Obtain a {@link java.sql.Connection} for use.  The client is
45       * responsible for closing the {@link java.sql.Connection} when it is no
46       * longer required.
47       *
48       * @throws SQLException if a {@link java.sql.Connection} could not be
49       *                      obtained
50       */
51      Connection getConnection() throws SQLException;
52  
53      /**
54       * Get the SQL dialect that should be used for this connection. Note that the
55       * dialect is not needed if the JDBC driver supports the getGeneratedKeys
56       * method.
57       */
58      int getSQLDialectCode();
59  
60      /**
61       * If the connection supports the JDBC 3.0 getGeneratedKeys method, then
62       * we do not need any specific dialect support.
63       */
64      boolean supportsGetGeneratedKeys();
65  
66      /**
67       * If the connection does not support batch updates, we will avoid using them.
68       */
69      boolean supportsBatchUpdates();
70  }