KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * com.mckoi.database.SystemQueryContext 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  * A QueryContext that only wraps around a TransactionSystem and does not
29  * provide implementations for the 'getTable', and 'getDatabase' methods.
30  *
31  * @author Tobias Downer
32  */

33
34 final class SystemQueryContext extends AbstractQueryContext {
35
36   /**
37    * The wrapped TransactionSystem object.
38    */

39   private TransactionSystem system;
40
41   /**
42    * The Transaction this is a part of.
43    */

44   private SimpleTransaction transaction;
45
46   /**
47    * The context schema of this context.
48    */

49   private String JavaDoc current_schema;
50
51
52
53   /**
54    * Constructs the QueryContext.
55    */

56   SystemQueryContext(SimpleTransaction transaction,
57                      String JavaDoc current_schema) {
58     this.transaction = transaction;
59     this.system = transaction.getSystem();
60     this.current_schema = current_schema;
61   }
62
63   /**
64    * Returns a TransactionSystem object that is used to determine information
65    * about the transactional system.
66    */

67   public TransactionSystem getSystem() {
68     return system;
69   }
70
71   /**
72    * Returns the system FunctionLookup object.
73    */

74   public FunctionLookup getFunctionLookup() {
75     return getSystem().getFunctionLookup();
76   }
77   
78   /**
79    * Increments the sequence generator and returns the next unique key.
80    */

81   public long nextSequenceValue(String JavaDoc name) {
82     TableName tn = transaction.resolveToTableName(current_schema, name,
83                                                 system.ignoreIdentifierCase());
84     return transaction.nextSequenceValue(tn);
85   }
86
87   /**
88    * Returns the current sequence value returned for the given sequence
89    * generator within the connection defined by this context. If a value was
90    * not returned for this connection then a statement exception is generated.
91    */

92   public long currentSequenceValue(String JavaDoc name) {
93     TableName tn = transaction.resolveToTableName(current_schema, name,
94                                                 system.ignoreIdentifierCase());
95     return transaction.lastSequenceValue(tn);
96   }
97
98   /**
99    * Sets the current sequence value for the given sequence generator.
100    */

101   public void setSequenceValue(String JavaDoc name, long value) {
102     TableName tn = transaction.resolveToTableName(current_schema, name,
103                                                 system.ignoreIdentifierCase());
104     transaction.setSequenceValue(tn, value);
105   }
106   
107   /**
108    * Returns a unique key for the given table source in the database.
109    */

110   public long nextUniqueID(String JavaDoc table_name) {
111     TableName tname = TableName.resolve(current_schema, table_name);
112     return transaction.nextUniqueID(tname);
113   }
114
115   /**
116    * Returns the user name of the connection.
117    */

118   public String JavaDoc getUserName() {
119     return "@SYSTEM";
120   }
121
122 }
123
Popular Tags