01: /*
02:
03: Derby - Class org.apache.derby.iapi.db.ConnectionInfo
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derby.iapi.db;
23:
24: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
25: import org.apache.derby.iapi.sql.conn.ConnectionUtil;
26: import org.apache.derby.iapi.error.StandardException;
27: import org.apache.derby.iapi.error.PublicAPI;
28: import java.sql.SQLException;
29:
30: /**
31: *
32: * ConnectionInfo class provides static methods for getting information
33: * related to a JDBC connection.
34: *
35: * When called from within the query language,
36: * each method returns information about the connection from which it was called.
37: * <p>
38: * Use the methods of this class only within an SQL-J statement; do not call
39: * them directly.
40: */
41:
42: public abstract class ConnectionInfo {
43:
44: /** no requirement for a constructor */
45: private ConnectionInfo() {
46: }
47:
48: /**
49: * Get the last autoincrement value inserted into the column by
50: * a statement in this connection.
51:
52: <BR><B> In JDBC 3.0 an application should use the standard methods provided by
53: JDBC 3.0 to obtain generated key values. See java.sql.Statement.getGeneratedKeys().</B>
54: *
55: * @param schemaName Name of the schema.
56: * @param tableName Name of the table.
57: * @param columnName Name of the column.
58: *
59: * @return the last value to be inserted into the named autoincrement
60: * column by this connection. Returns null if this connection has never
61: * inserted into this column.
62: *
63: * @exception SQLException if the current connection could not be
64: * established properly.
65: */
66: public static Long lastAutoincrementValue(String schemaName,
67: String tableName, String columnName) throws SQLException {
68: // a static method can manipulate lcc?
69: LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
70: return lcc.lastAutoincrementValue(schemaName, tableName,
71: columnName);
72: }
73:
74: /**
75: * <B>INTERNAL USE ONLY</B>
76: * (<B>THIS METHOD MAY BE REMOVED IN A FUTURE RELEASE</B>.)
77: * @throws SQLException on error
78: **/
79: public static long nextAutoincrementValue(String schemaName,
80: String tableName, String columnName) throws SQLException {
81: LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
82: try {
83: return lcc.nextAutoincrementValue(schemaName, tableName,
84: columnName);
85: } catch (StandardException se) {
86: throw PublicAPI.wrapStandardException(se);
87: }
88: }
89: }
|