KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > DatabaseQueryContext


1 /**
2  * com.mckoi.database.DatabaseQueryContext 25 Mar 2002
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database;
26
27 /**
28  * An implementation of a QueryContext based on a DatabaseConnection object.
29  *
30  * @author Tobias Downer
31  */

32
33 public class DatabaseQueryContext extends AbstractQueryContext {
34
35   /**
36    * The DatabaseConnection.
37    */

38   private DatabaseConnection database;
39
40   /**
41    * Constructs the QueryContext.
42    */

43   public DatabaseQueryContext(DatabaseConnection database) {
44     this.database = database;
45   }
46
47   /**
48    * Returns the Database object that this context is a child of.
49    */

50   public Database getDatabase() {
51     return database.getDatabase();
52   }
53
54   /**
55    * Returns a TransactionSystem object that is used to determine information
56    * about the transactional system.
57    */

58   public TransactionSystem getSystem() {
59     return getDatabase().getSystem();
60   }
61
62   /**
63    * Returns the system FunctionLookup object.
64    */

65   public FunctionLookup getFunctionLookup() {
66     return getSystem().getFunctionLookup();
67   }
68   
69   /**
70    * Returns the GrantManager object that is used to determine grant information
71    * for the database.
72    */

73   public GrantManager getGrantManager() {
74     return database.getGrantManager();
75   }
76   
77   /**
78    * Returns a DataTable from the database with the given table name.
79    */

80   public DataTable getTable(TableName name) {
81     database.addSelectedFromTable(name);
82     return database.getTable(name);
83   }
84
85   /**
86    * Returns a DataTableDef for the given table name.
87    */

88   public DataTableDef getDataTableDef(TableName name) {
89     return database.getDataTableDef(name);
90   }
91   
92   /**
93    * Creates a QueryPlanNode for the view with the given name.
94    */

95   public QueryPlanNode createViewQueryPlanNode(TableName name) {
96     return database.createViewQueryPlanNode(name);
97   }
98   
99   /**
100    * Increments the sequence generator and returns the next unique key.
101    */

102   public long nextSequenceValue(String JavaDoc name) {
103     return database.nextSequenceValue(name);
104   }
105
106   /**
107    * Returns the current sequence value returned for the given sequence
108    * generator within the connection defined by this context. If a value was
109    * not returned for this connection then a statement exception is generated.
110    */

111   public long currentSequenceValue(String JavaDoc name) {
112     return database.lastSequenceValue(name);
113   }
114
115   /**
116    * Sets the current sequence value for the given sequence generator.
117    */

118   public void setSequenceValue(String JavaDoc name, long value) {
119     database.setSequenceValue(name, value);
120   }
121   
122   /**
123    * Returns the user name of the connection.
124    */

125   public String JavaDoc getUserName() {
126     return database.getUser().getUserName();
127   }
128
129 }
130
Popular Tags