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