KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > db > Factory


1 /*
2
3    Derby - Class org.apache.derby.iapi.db.Factory
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (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 JavaDoc;
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
64     /**
65     <P>
66     Returns the Database object associated with the current connection.
67         @exception SQLException Not in a connection context.
68     **/

69     public static org.apache.derby.database.Database getDatabaseOfConnection()
70         throws SQLException JavaDoc
71     {
72         // Get the current language connection context. This is associated
73
// with the current database.
74
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
75         return lcc.getDatabase();
76     }
77
78     /**
79      * Get the TriggerExecutionContext for the current connection
80      * of the connection.
81      *
82      * @return the TriggerExecutionContext if called from the context
83      * of a trigger; otherwise, null.
84
85         @exception SQLException Not in a connection or trigger context.
86      */

87     public static TriggerExecutionContext getTriggerExecutionContext()
88         throws SQLException JavaDoc
89     {
90         LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
91         return lcc.getTriggerExecutionContext();
92     }
93 }
94
Popular Tags