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