KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > SecondaryConfig


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: SecondaryConfig.java,v 1.19 2006/11/20 15:46:58 cwl Exp $
7  */

8
9 package com.sleepycat.je;
10
11 import com.sleepycat.je.utilint.DatabaseUtil;
12
13 /**
14  * Javadoc for this public class is generated via
15  * the doc templates in the doc_src directory.
16  */

17 public class SecondaryConfig extends DatabaseConfig {
18
19     /*
20      * For internal use, to allow null as a valid value for
21      * the config parameter.
22      */

23     public static final SecondaryConfig DEFAULT = new SecondaryConfig();
24
25     private boolean allowPopulate;
26     private SecondaryKeyCreator keyCreator;
27     private SecondaryMultiKeyCreator multiKeyCreator;
28     private Database foreignKeyDatabase;
29     private ForeignKeyDeleteAction foreignKeyDeleteAction =
30             ForeignKeyDeleteAction.ABORT;
31     private ForeignKeyNullifier foreignKeyNullifier;
32     private ForeignMultiKeyNullifier foreignMultiKeyNullifier;
33     private boolean immutableSecondaryKey;
34
35     /**
36      * Javadoc for this public method is generated via
37      * the doc templates in the doc_src directory.
38      */

39     public SecondaryConfig() {
40     }
41
42     /**
43      * Javadoc for this public method is generated via
44      * the doc templates in the doc_src directory.
45      */

46     public void setKeyCreator(SecondaryKeyCreator keyCreator) {
47         this.keyCreator = keyCreator;
48     }
49
50     /**
51      * Javadoc for this public method is generated via
52      * the doc templates in the doc_src directory.
53      */

54     public SecondaryKeyCreator getKeyCreator() {
55         return keyCreator;
56     }
57
58     /**
59      * Javadoc for this public method is generated via
60      * the doc templates in the doc_src directory.
61      */

62     public void setMultiKeyCreator(SecondaryMultiKeyCreator multiKeyCreator) {
63         this.multiKeyCreator = multiKeyCreator;
64     }
65
66     /**
67      * Javadoc for this public method is generated via
68      * the doc templates in the doc_src directory.
69      */

70     public SecondaryMultiKeyCreator getMultiKeyCreator() {
71         return multiKeyCreator;
72     }
73
74     /**
75      * Javadoc for this public method is generated via
76      * the doc templates in the doc_src directory.
77      */

78     public void setAllowPopulate(boolean allowPopulate) {
79         this.allowPopulate = allowPopulate;
80     }
81
82     /**
83      * Javadoc for this public method is generated via
84      * the doc templates in the doc_src directory.
85      */

86     public boolean getAllowPopulate() {
87         return allowPopulate;
88     }
89
90     /**
91      * Javadoc for this public method is generated via
92      * the doc templates in the doc_src directory.
93      */

94     public void setForeignKeyDatabase(Database foreignKeyDatabase) {
95         this.foreignKeyDatabase = foreignKeyDatabase;
96     }
97
98     /**
99      * Javadoc for this public method is generated via
100      * the doc templates in the doc_src directory.
101      */

102     public Database getForeignKeyDatabase() {
103         return foreignKeyDatabase;
104     }
105
106     /**
107      * Javadoc for this public method is generated via
108      * the doc templates in the doc_src directory.
109      */

110     public void setForeignKeyDeleteAction(ForeignKeyDeleteAction
111                                           foreignKeyDeleteAction) {
112         DatabaseUtil.checkForNullParam(foreignKeyDeleteAction,
113                                        "foreignKeyDeleteAction");
114         this.foreignKeyDeleteAction = foreignKeyDeleteAction;
115     }
116
117     /**
118      * Javadoc for this public method is generated via
119      * the doc templates in the doc_src directory.
120      */

121     public ForeignKeyDeleteAction getForeignKeyDeleteAction() {
122         return foreignKeyDeleteAction;
123     }
124
125     /**
126      * Javadoc for this public method is generated via
127      * the doc templates in the doc_src directory.
128      */

129     public void setForeignKeyNullifier(ForeignKeyNullifier
130                                        foreignKeyNullifier) {
131         this.foreignKeyNullifier = foreignKeyNullifier;
132     }
133
134     /**
135      * Javadoc for this public method is generated via
136      * the doc templates in the doc_src directory.
137      */

138     public ForeignKeyNullifier getForeignKeyNullifier() {
139         return foreignKeyNullifier;
140     }
141
142     /**
143      * Javadoc for this public method is generated via
144      * the doc templates in the doc_src directory.
145      */

146     public void setForeignMultiKeyNullifier(ForeignMultiKeyNullifier
147                                             foreignMultiKeyNullifier) {
148         this.foreignMultiKeyNullifier = foreignMultiKeyNullifier;
149     }
150
151     /**
152      * Javadoc for this public method is generated via
153      * the doc templates in the doc_src directory.
154      */

155     public ForeignMultiKeyNullifier getForeignMultiKeyNullifier() {
156         return foreignMultiKeyNullifier;
157     }
158
159     /**
160      * Javadoc for this public method is generated via
161      * the doc templates in the doc_src directory.
162      */

163     public void setImmutableSecondaryKey(boolean immutableSecondaryKey) {
164         this.immutableSecondaryKey = immutableSecondaryKey;
165     }
166
167     /**
168      * Javadoc for this public method is generated via
169      * the doc templates in the doc_src directory.
170      */

171     public boolean getImmutableSecondaryKey() {
172         return immutableSecondaryKey;
173     }
174
175     /*
176      * For JCA Database handle caching.
177      */

178     void validate(DatabaseConfig configArg)
179     throws DatabaseException {
180
181     super.validate(configArg);
182
183     if (configArg == null ||
184         !(configArg instanceof SecondaryConfig)) {
185         throw new DatabaseException
186         ("The SecondaryConfig argument is null.");
187     }
188
189     SecondaryConfig config = (SecondaryConfig) configArg;
190
191     boolean kcMatch = equalOrBothNull
192             (config.getKeyCreator(), keyCreator);
193     boolean mkcMatch = equalOrBothNull
194             (config.getMultiKeyCreator(), multiKeyCreator);
195     boolean fkdMatch =
196         (config.getForeignKeyDatabase() == foreignKeyDatabase);
197     boolean fkdaMatch =
198         (config.getForeignKeyDeleteAction() == foreignKeyDeleteAction);
199     boolean fknMatch = equalOrBothNull
200         (config.getForeignKeyNullifier(), foreignKeyNullifier);
201     boolean fmknMatch = equalOrBothNull
202         (config.getForeignMultiKeyNullifier(), foreignMultiKeyNullifier);
203     boolean imskMatch =
204         (config.getImmutableSecondaryKey() == immutableSecondaryKey);
205     if (kcMatch &&
206             mkcMatch &&
207         fkdMatch &&
208         fkdaMatch &&
209         fknMatch &&
210         fmknMatch &&
211         imskMatch) {
212         return;
213     }
214
215     String JavaDoc message =
216         genSecondaryConfigMismatchMessage(
217                 config, kcMatch, mkcMatch, fkdMatch, fkdaMatch,
218                 fknMatch, fmknMatch, imskMatch);
219     throw new DatabaseException(message);
220     }
221
222     private boolean equalOrBothNull(Object JavaDoc o1, Object JavaDoc o2) {
223         return (o1 != null) ? o1.equals(o2) : (o2 == null);
224     }
225
226     String JavaDoc genSecondaryConfigMismatchMessage(DatabaseConfig config,
227                          boolean kcMatch,
228                          boolean mkcMatch,
229                          boolean fkdMatch,
230                          boolean fkdaMatch,
231                          boolean fknMatch,
232                          boolean fmknMatch,
233                          boolean imskMatch) {
234     StringBuffer JavaDoc ret = new StringBuffer JavaDoc
235         ("The following SecondaryConfig parameters for the\n" +
236          "cached Database do not match the parameters for the\n" +
237          "requested Database:\n");
238     if (!kcMatch) {
239         ret.append(" SecondaryKeyCreator\n");
240     }
241         
242     if (!mkcMatch) {
243         ret.append(" SecondaryMultiKeyCreator\n");
244     }
245         
246     if (!fkdMatch) {
247         ret.append(" ForeignKeyDelete\n");
248     }
249         
250     if (!fkdaMatch) {
251         ret.append(" ForeignKeyDeleteAction\n");
252     }
253         
254     if (!fknMatch) {
255         ret.append(" ForeignKeyNullifier\n");
256     }
257         
258     if (!fknMatch) {
259         ret.append(" ForeignMultiKeyNullifier\n");
260     }
261         
262     if (!imskMatch) {
263         ret.append(" ImmutableSecondaryKey\n");
264     }
265
266     return ret.toString();
267     }
268 }
269
Popular Tags