View Javadoc
1   package org.synchronoss.cpo.jdbc;
2   
3   /*-
4    * [[
5    * jdbc
6    * ==
7    * Copyright (C) 2003 - 2026 Exaxis LLC, Synchronoss Technologies Inc
8    * ==
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * ]]
23   */
24  
25  import java.io.Serializable;
26  import java.sql.Connection;
27  import org.synchronoss.cpo.core.CpoException;
28  
29  /**
30   * Strategy for how a {@link JdbcCpoAdapter} obtains and releases its JDBC connections. The plain
31   * adapter uses a pooled per-call strategy ({@link JdbcPooledConnectionStrategy}); a {@link
32   * JdbcCpoTrxAdapter} pins a single connection for the life of the transaction ({@link
33   * JdbcPinnedConnectionStrategy}).
34   *
35   * @author david berry
36   */
37  interface JdbcConnectionStrategy extends Serializable {
38  
39    /**
40     * Gets a connection for a read-only operation.
41     *
42     * @return A read connection
43     * @throws CpoException An error has occurred.
44     */
45    Connection getReadConnection() throws CpoException;
46  
47    /**
48     * Gets a connection for a write operation.
49     *
50     * @return A write connection
51     * @throws CpoException An error has occurred.
52     */
53    Connection getWriteConnection() throws CpoException;
54  
55    /**
56     * Releases a connection at the end of a call-local unit of work. A transaction-scoped strategy
57     * keeps the connection open instead.
58     *
59     * @param connection The connection to close
60     */
61    void closeLocalConnection(Connection connection);
62  
63    /**
64     * Commits a call-local unit of work. A transaction-scoped strategy leaves the commit to the
65     * transaction owner instead.
66     *
67     * @param connection The connection to commit
68     */
69    void commitLocalConnection(Connection connection);
70  
71    /**
72     * Rolls back a call-local unit of work. A transaction-scoped strategy leaves the rollback to the
73     * transaction owner instead.
74     *
75     * @param connection The connection to rollback
76     */
77    void rollbackLocalConnection(Connection connection);
78  }