001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.internal.databaseaccess;
038:
039: import java.util.Vector;
040: import oracle.toplink.essentials.exceptions.DatabaseException;
041: import oracle.toplink.essentials.internal.sessions.AbstractSession;
042: import oracle.toplink.essentials.internal.sessions.AbstractRecord;
043: import oracle.toplink.essentials.sessions.Login;
044: import oracle.toplink.essentials.queryframework.Call;
045:
046: /**
047: * INTERNAL:
048: * Accessor defines the interface used primarily by the assorted
049: * TopLink Sessions to interact with a data store. In "normal"
050: * TopLink this data store is a relational database. But this interface
051: * also allows developers using the TopLink SDK to develop Accessors
052: * to other, non-relational, data stores.<p>
053: *
054: * Accessors must implement the following behavior: <ul>
055: * <li>connect to and disconnect from the data store
056: * <li>handle transaction contexts
057: * <li>execute calls that read, insert, update, and delete data
058: * <li>keep track of concurrently executing calls
059: * <li>supply metadata about the data store
060: * </ul>
061: *
062: * @see oracle.toplink.essentials.publicinterface.Session
063: * @see Call
064: *
065: * @author Big Country
066: * @since TOPLink/Java 3.0
067: */
068: public interface Accessor extends Cloneable {
069:
070: /**
071: * To be called after JTS transaction has been completed (committed or rolled back)
072: */
073: public void afterJTSTransaction();
074:
075: /**
076: * Begin a transaction on the data store.
077: */
078: void beginTransaction(AbstractSession session)
079: throws DatabaseException;
080:
081: /**
082: * Return a clone of the accessor.
083: */
084: Object clone();
085:
086: /**
087: * Close the accessor's connection.
088: * This is used only for external connection pooling
089: * when it is intended for the connection to be reconnected in the future.
090: */
091: void closeConnection();
092:
093: /**
094: * Commit a transaction on the data store.
095: */
096: void commitTransaction(AbstractSession session)
097: throws DatabaseException;
098:
099: /**
100: * Connect to the data store using the configuration
101: * information in the login.
102: */
103: void connect(Login login, AbstractSession session)
104: throws DatabaseException;
105:
106: /**
107: * Decrement the number of calls in progress.
108: * Used for external pooling.
109: */
110: void decrementCallCount();
111:
112: /**
113: * Disconnect from the data store.
114: */
115: void disconnect(AbstractSession session) throws DatabaseException;
116:
117: /**
118: * Execute the call.
119: * The actual behavior of the execution depends on the type of call.
120: * The call may be parameterized where the arguments are in the translation row.
121: * The row will be empty if there are no parameters.
122: * @return a row, a collection of rows, a row count, or a cursor
123: */
124: Object executeCall(Call call, AbstractRecord translationRow,
125: AbstractSession session) throws DatabaseException;
126:
127: /**
128: * Execute any deferred select calls. This method will generally be called
129: * after one or more select calls have been collected in a LOBValueWriter (to be
130: * executed after all insert calls are executed).
131: * Bug 2804663.
132: *
133: * @see oracle.toplink.essentials.internal.helper.LOBValueWriter#buildAndExecuteCallForLocator(DatabaseCall,Session,Accessor)
134: */
135: void flushSelectCalls(AbstractSession session);
136:
137: /**
138: * Return the number of calls currently in progress.
139: * Used for load balancing and external pooling.
140: */
141: int getCallCount();
142:
143: /**
144: * Return the column metadata for the specified
145: * selection criteria.
146: */
147: Vector getColumnInfo(String catalog, String schema,
148: String tableName, String columnName, AbstractSession session)
149: throws DatabaseException;
150:
151: /**
152: * Return the JDBC connection for relational accessors.
153: * This will fail for non-relational accessors.
154: */
155: java.sql.Connection getConnection();
156:
157: /**
158: * Return the driver level connection,
159: * this will need to be cast to the implementation class for the data access type being used.
160: */
161: Object getDatasourceConnection();
162:
163: /**
164: * Return the table metadata for the specified
165: * selection criteria.
166: */
167: Vector getTableInfo(String catalog, String schema,
168: String tableName, String[] types, AbstractSession session)
169: throws DatabaseException;
170:
171: /**
172: * Increment the number of calls in progress.
173: * Used for external pooling.
174: */
175: void incrementCallCount(AbstractSession session);
176:
177: /**
178: * Return whether the accessor is connected to the data store.
179: */
180: boolean isConnected();
181:
182: /**
183: * Reconnect to the database. This can be used if the connection was
184: * temporarily disconnected or if it timed out.
185: */
186: void reestablishConnection(AbstractSession session)
187: throws DatabaseException;
188:
189: /**
190: * Roll back a transaction on the data store.
191: */
192: void rollbackTransaction(AbstractSession session)
193: throws DatabaseException;
194:
195: /**
196: * Return whether the accessor uses an external
197: * transaction controller (e.g. JTS).
198: */
199: boolean usesExternalTransactionController();
200:
201: /**
202: * This method will be called after a series of writes have been issued to
203: * mark where a particular set of writes has completed. It will be called
204: * from commitTransaction and may be called from writeChanges. Its main
205: * purpose is to ensure that the batched statements have been executed
206: */
207: public void writesCompleted(AbstractSession session);
208: }
|