1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.db.Factory |
4 | |
5 | Copyright 1998, 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.services.monitor.Monitor; |
24 | import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; |
25 | import org.apache.derby.iapi.sql.conn.ConnectionUtil; |
26 | import java.sql.SQLException; |
27 | |
28 | /** |
29 | * <P> |
30 | * Callers of these methods must be within the context of a |
31 | * Cloudscape statement execution otherwise a SQLException will be thrown. |
32 | * <BR> |
33 | * There are two basic ways to call these methods. |
34 | * <OL> |
35 | * <LI> |
36 | * Within a SQL statement. |
37 | * <PRE> |
38 | * -- checkpoint the database |
39 | * CALL org.apache.derby.iapi.db.Factory:: |
40 | * getDatabaseOfConnection().checkpoint(); |
41 | * </PRE> |
42 | * <LI> |
43 | * In a server-side JDBC method. |
44 | * <PRE> |
45 | * import org.apache.derby.iapi.db.*; |
46 | * |
47 | * ... |
48 | * |
49 | * // checkpoint the database |
50 | * Database db = Factory.getDatabaseOfConnection(); |
51 | * db.checkpoint(); |
52 | * |
53 | * </PRE> |
54 | * </OL> |
55 | This class can only be used within an SQL-J statement, a Java procedure or a server side Java method. |
56 | <p>This class can be accessed using the class alias <code> FACTORY </code> in SQL-J statements. |
57 | */ |
58 | |
59 | public class Factory |
60 | { |
61 | |
62 | |
63 | /** |
64 | <P> |
65 | Returns the Database object associated with the current connection. |
66 | @exception SQLException Not in a connection context. |
67 | **/ |
68 | public static org.apache.derby.database.Database getDatabaseOfConnection() |
69 | throws SQLException |
70 | { |
71 | // Get the current language connection context. This is associated |
72 | // with the current database. |
73 | LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); |
74 | return lcc.getDatabase(); |
75 | } |
76 | |
77 | /** |
78 | * Get the TriggerExecutionContext for the current connection |
79 | * of the connection. |
80 | * |
81 | * @return the TriggerExecutionContext if called from the context |
82 | * of a trigger; otherwise, null. |
83 | |
84 | @exception SQLException Not in a connection or trigger context. |
85 | */ |
86 | public static TriggerExecutionContext getTriggerExecutionContext() |
87 | throws SQLException |
88 | { |
89 | LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); |
90 | return lcc.getTriggerExecutionContext(); |
91 | } |
92 | } |