KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > catalog > DD_Version


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.catalog.DD_Version
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.impl.sql.catalog;
23
24 import org.apache.derby.iapi.services.monitor.Monitor;
25 import org.apache.derby.iapi.services.sanity.SanityManager;
26 import org.apache.derby.iapi.services.io.Formatable;
27 import org.apache.derby.iapi.error.StandardException;
28 import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;
29 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
30 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
31 import org.apache.derby.iapi.sql.dictionary.SPSDescriptor;
32 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
33 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
34 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
35 import org.apache.derby.iapi.types.DataValueFactory;
36 import org.apache.derby.iapi.types.RowLocation;
37 import org.apache.derby.iapi.reference.SQLState;
38 import org.apache.derby.iapi.store.access.ConglomerateController;
39 import org.apache.derby.iapi.store.access.TransactionController;
40 import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;
41 import org.apache.derby.iapi.store.access.ScanController;
42 import org.apache.derby.iapi.sql.execute.ExecRow;
43 import org.apache.derby.iapi.sql.execute.ExecIndexRow;
44 import org.apache.derby.iapi.services.io.StoredFormatIds;
45
46 import org.apache.derby.iapi.services.io.FormatableBitSet;
47 import org.apache.derby.iapi.services.info.ProductGenusNames;
48 import org.apache.derby.iapi.services.info.ProductVersionHolder;
49 import org.apache.derby.iapi.reference.JDBC30Translation;
50 import org.apache.derby.iapi.reference.Limits;
51 import org.apache.derby.iapi.util.IdUtil;
52
53 import org.apache.derby.iapi.services.uuid.UUIDFactory;
54 import org.apache.derby.catalog.UUID;
55 import org.apache.derby.catalog.types.RoutineAliasInfo;
56 import org.apache.derby.catalog.AliasInfo;
57 import org.apache.derby.catalog.TypeDescriptor;
58 import org.apache.derby.iapi.types.DataTypeDescriptor;
59 import java.io.IOException JavaDoc;
60 import java.io.ObjectInput JavaDoc;
61 import java.io.ObjectOutput JavaDoc;
62 import java.sql.Types JavaDoc;
63 import java.util.Enumeration JavaDoc;
64 import java.util.Properties JavaDoc;
65
66 /**
67  * Generic code for upgrading data dictionaries.
68  * Currently has all minor version upgrade logic.
69  * <p>
70  * A word about minor vs. major upgraded. Minor
71  * upgrades must be backwards/forwards compatible.
72  * So they cannot version classes or introduce new
73  * classes. Major releases are only backwards compatible;
74  * they will run against an old database, but not the
75  * other way around. So they can introduce new classes,
76  * etc.
77  *
78  * @author Rick
79  */

80
81 public class DD_Version implements Formatable
82 {
83     ////////////////////////////////////////////////////////////////////////
84
//
85
// STATE
86
//
87
////////////////////////////////////////////////////////////////////////
88

89     private transient DataDictionaryImpl bootingDictionary;
90
91     int majorVersionNumber;
92     private int minorVersionNumber;
93
94     ////////////////////////////////////////////////////////////////////////
95
//
96
// CONSTRUCTORS
97
//
98
////////////////////////////////////////////////////////////////////////
99

100     /**
101       * Public niladic constructor needed for Formatable interface.
102       */

103     public DD_Version() {}
104
105
106     /**
107      * Construct a Version for the currently booting data dictionary.
108      * The minor version is set by the subclass.
109      *
110      * @param bootingDictionary The booting dictionary that needs to be upgraded.
111      */

112     DD_Version( DataDictionaryImpl bootingDictionary, int majorVersionNumber)
113     {
114         this.majorVersionNumber = majorVersionNumber;
115         this.minorVersionNumber = getJBMSMinorVersionNumber();
116         this.bootingDictionary = bootingDictionary;
117     }
118
119     ////////////////////////////////////////////////////////////////////////
120
//
121
// OVERRIDE OBJECT METHODS
122
//
123
////////////////////////////////////////////////////////////////////////
124

125     /**
126       * Stringify this Version.
127       *
128       * @return String representation of this Version.
129       */

130     public String JavaDoc toString()
131     {
132         return DD_Version.majorToString(majorVersionNumber);
133     }
134
135     private static String JavaDoc majorToString(int majorVersionNumber) {
136         switch (majorVersionNumber) {
137         case DataDictionary.DD_VERSION_CS_5_0:
138             return "5.0";
139         case DataDictionary.DD_VERSION_CS_5_1:
140             return "5.1";
141         case DataDictionary.DD_VERSION_CS_5_2:
142             return "5.2";
143         case DataDictionary.DD_VERSION_CS_8_1:
144             return "8.1";
145         case DataDictionary.DD_VERSION_CS_10_0:
146             return "10.0";
147         case DataDictionary.DD_VERSION_DERBY_10_1:
148             return "10.1";
149         case DataDictionary.DD_VERSION_DERBY_10_2:
150             return "10.2";
151         default:
152             return null;
153         }
154     }
155
156     ////////////////////////////////////////////////////////////////////////
157
//
158
// DataDictionary SPECIFIC
159
//
160
////////////////////////////////////////////////////////////////////////
161

162     /**
163      * Upgrade the data dictionary catalogs to the version represented by this
164      * DD_Version.
165      *
166      * @param dictionaryVersion the version of the data dictionary tables.
167      * @exception StandardException Ooops
168      */

169     void upgradeIfNeeded(DD_Version dictionaryVersion,
170                                 TransactionController tc, Properties JavaDoc startParams)
171          throws StandardException
172     {
173         // database has been upgrade with a later engine version than this?
174
if (dictionaryVersion.majorVersionNumber > majorVersionNumber) {
175             throw StandardException.newException(SQLState.LANG_CANT_UPGRADE_CATALOGS,
176                 dictionaryVersion, this);
177         }
178
179
180         boolean minorOnly = false;
181         boolean performMajorUpgrade = false;
182         boolean softUpgradeRun = false;
183         boolean isReadOnly = bootingDictionary.af.isReadOnly();
184
185         if (dictionaryVersion.majorVersionNumber == majorVersionNumber) {
186
187             // exact match of engine to database, do nothing.
188
if (dictionaryVersion.minorVersionNumber == minorVersionNumber)
189                 return;
190
191             // database and engine at same major level
192
minorOnly = true;
193
194         } else {
195            
196             if (Monitor.isFullUpgrade(startParams, dictionaryVersion.toString())) {
197                 performMajorUpgrade = true;
198             } else {
199                 softUpgradeRun = true;
200             }
201         }
202
203         // make sure we have a clean transaction for the upgrade
204
tc.commit();
205
206         if (performMajorUpgrade) {
207             // real upgrade changes. Get user name of current user.
208
String JavaDoc userName = IdUtil.getUserNameFromURLProps(startParams);
209             doFullUpgrade(tc, dictionaryVersion.majorVersionNumber,IdUtil.getUserAuthorizationId(userName));
210         }
211
212         if (!minorOnly && !isReadOnly) {
213             // apply changes that can be made and will continue to work
214
// against previous version.
215

216             // See if we have already applied these changes.
217
DD_Version softUpgradeVersion = (DD_Version) tc.getProperty(
218                                             DataDictionary.SOFT_DATA_DICTIONARY_VERSION);
219
220             // need to apply them if we have never performed a soft upgrade
221
// or only a soft upgrade using a previous version.
222
int softUpgradeMajorVersion = 0;
223             if (softUpgradeVersion != null)
224                 softUpgradeMajorVersion = softUpgradeVersion.majorVersionNumber;
225
226             if (softUpgradeMajorVersion < majorVersionNumber) {
227                 applySafeChanges( tc, dictionaryVersion.majorVersionNumber, softUpgradeMajorVersion);
228             }
229         }
230
231         // changes such as invalidating SPS so they will recompile against
232
// the new internal classes.
233
// this method also changes the on-disk format version on the disk and in-memory as well.
234
handleMinorRevisionChange(tc, dictionaryVersion, softUpgradeRun);
235
236         // commit any upgrade
237
tc.commit();
238     }
239
240     /**
241         Apply changes that can safely be made in soft upgrade.
242         Any changes must not prevent the database from being re-booted
243         by the a Derby engine at the older version fromMajorVersionNumber.
244         <BR>
245         Examples are fixes to catalog meta data, e.g. fix nullability of
246         a system column.
247
248         <BR>
249         <B>Upgrade items for 10.1</B>
250         <UL>
251         <LI> None.
252         </UL>
253       *
254       * @param tc transaction controller
255       * @param fromMajorVersionNumber version of the on-disk database
256         @param lastSoftUpgradeVersion last engine to perform a soft upgrade that made changes.
257       *
258       * @exception StandardException Standard Cloudscape error policy.
259       */

260     private void applySafeChanges(TransactionController tc, int fromMajorVersionNumber, int lastSoftUpgradeVersion)
261         throws StandardException
262     {
263
264         /*
265          * OLD Cloudscape 5.1 upgrade code, Derby does not support
266          * upgrade from Cloudscape 5.x databases. If it ever is changed
267          * to do so, this code would be useful.
268          *
269          *
270         if (lastSoftUpgradeVersion <= DataDictionary.DD_VERSION_CS_5_1)
271         {
272
273             // All these soft upgrade actions are new in 5.2 (first ever soft upgrade)
274             if (fromMajorVersionNumber <= DataDictionary.DD_VERSION_CS_5_0)
275                 modifySysTableNullability(tc,
276                     DataDictionaryImpl.SYSALIASES_CATALOG_NUM);
277
278             if (fromMajorVersionNumber <= DataDictionary.DD_VERSION_CS_5_1)
279                 modifySysTableNullability(tc,
280                     DataDictionaryImpl.SYSSTATEMENTS_CATALOG_NUM);
281
282         }
283         */

284
285         tc.setProperty(DataDictionary.SOFT_DATA_DICTIONARY_VERSION, this, true);
286     }
287
288     /**
289         Do full upgrade. Apply changes that can NOT be safely made in soft upgrade.
290         
291         <BR>
292         <B>Upgrade items for every new release</B>
293         <UL>
294         <LI> Drop and recreate the stored versions of the JDBC database metadata queries
295         </UL>
296         
297         <BR>
298         <B>Upgrade items for 10.1</B>
299         <UL>
300         <LI> None.
301         </UL>
302         
303       *
304       * @param tc transaction controller
305       * @param fromMajorVersionNumber version of the on-disk database
306       * @param aid AuthorizationID of current user to be made Database Owner
307       *
308       * @exception StandardException Standard Cloudscape error policy.
309       */

310     private void doFullUpgrade(TransactionController tc, int fromMajorVersionNumber, String JavaDoc aid)
311         throws StandardException
312     {
313         // Only supports upgrade from Derby 10.0 releases onwards
314
if (fromMajorVersionNumber < DataDictionary.DD_VERSION_CS_10_0)
315         {
316             throw StandardException.newException(SQLState.UPGRADE_UNSUPPORTED,
317                     DD_Version.majorToString(fromMajorVersionNumber), this);
318         }
319
320         //Drop and recreate the stored versions of the JDBC database metadata queries
321
//This is to make sure that we have the stored versions of JDBC database
322
//metadata queries matching with this release of the engine.
323
dropJDBCMetadataSPSes(tc, false);
324         bootingDictionary.createSystemSps(tc);
325
326         /*
327          * OLD Cloudscape 5.1 upgrade code, Derby does not support
328          * upgrade from Cloudscape 5.x databases. If it ever is changed
329          * to do so, this code would be useful.
330     
331         if (fromMajorVersionNumber <= DataDictionary.DD_VERSION_CS_5_1)
332         {
333             // drop sps in SYSIBM, SYSIBM, recreate SYSIBM, SYSDUMMY1, populate SYSDUMMY1, create procs
334             dropJDBCMetadataSPSes(tc, true);
335             SchemaDescriptor sd = bootingDictionary.getSchemaDescriptor("SYSIBM", null, false);
336             if (sd != null)
337                 bootingDictionary.dropSchemaDescriptor("SYSIBM", tc);
338             sd = bootingDictionary.getSysIBMSchemaDescriptor();
339             bootingDictionary.addDescriptor(sd, null, DataDictionary.SYSSCHEMAS_CATALOG_NUM, false, tc);
340             bootingDictionary.upgradeMakeCatalog(tc, DataDictionary.SYSDUMMY1_CATALOG_NUM);
341             bootingDictionary.populateSYSDUMMY1(tc);
342             bootingDictionary.create_SYSIBM_procedures(tc);
343             bootingDictionary.createSystemSps(tc);
344         }
345         
346         */

347
348         if (fromMajorVersionNumber == DataDictionary.DD_VERSION_CS_10_0)
349         {
350             // This upgrade depends on the SYSUTIL schema, which only exists
351
// since 10.0. Will not work to upgrade any db previous to 10.0,
352
// thus only checks for 10.0 rather than <= 10.0.
353
bootingDictionary.create_10_1_system_procedures(
354                 tc,
355                 bootingDictionary.getSystemUtilSchemaDescriptor().getUUID());
356         }
357
358         if (fromMajorVersionNumber <= DataDictionary.DD_VERSION_DERBY_10_1)
359         {
360             // On ugrade from versions before 10.2, create system procedures
361
// added in 10.2.
362
bootingDictionary.create_10_2_system_procedures(
363                 tc,
364                 bootingDictionary.getSystemUtilSchemaDescriptor().getUUID());
365
366             if (SanityManager.DEBUG)
367                 SanityManager.ASSERT((aid != null), "Failed to get new Database Owner authorization");
368
369             // Add new system catalogs created for grant and revoke
370
bootingDictionary.upgradeMakeCatalog(tc, DataDictionary.SYSTABLEPERMS_CATALOG_NUM);
371             bootingDictionary.upgradeMakeCatalog(tc, DataDictionary.SYSCOLPERMS_CATALOG_NUM);
372             bootingDictionary.upgradeMakeCatalog(tc, DataDictionary.SYSROUTINEPERMS_CATALOG_NUM);
373
374             // Change system schemas to be owned by aid
375
bootingDictionary.updateSystemSchemaAuthorization(aid, tc);
376             
377             // Grant PUBLIC access to some system routines
378
bootingDictionary.grantPublicAccessToSystemRoutines(tc, aid);
379         }
380         
381     }
382
383     /**
384      * Do any work needed for a minor revision change.
385      * For the data dictionary this is always invalidating
386      * stored prepared statements. When we are done
387      * with the upgrade, we always recompile all SPSes
388      * so the customer doesn't have to (and isn't going
389      * to get deadlocks because of the recomp).
390      *
391      * @param tc the xact
392      *
393      * @exception StandardException Standard Cloudscape error policy.
394      */

395     private void handleMinorRevisionChange(TransactionController tc, DD_Version fromVersion, boolean softUpgradeRun)
396         throws StandardException
397     {
398         boolean isReadOnly = bootingDictionary.af.isReadOnly();
399
400         if (!isReadOnly) {
401             bootingDictionary.clearSPSPlans();
402
403             DD_Version lastRun;
404             
405             if (softUpgradeRun)
406             {
407                 // log a version that will cause a minor revision change
408
// for any subsequent re-boot, including an old Cloudscape version
409
fromVersion.minorVersionNumber = 1; // see getJBMSMinorVersionNumber
410
lastRun = fromVersion;
411             }
412             else
413             {
414                 // log the new version
415
lastRun = this;
416             
417                 // and change the in-memory version.
418
fromVersion.majorVersionNumber = majorVersionNumber;
419                 fromVersion.minorVersionNumber = minorVersionNumber;
420             }
421
422             tc.setProperty(DataDictionary.CORE_DATA_DICTIONARY_VERSION, fromVersion, true);
423         }
424         else
425         {
426             // For a readonly database where we need some kind of upgrade
427
// (either minor release or soft upgrade) then since we cannot
428
// invalidate all the procedures we need to indicate that
429
// any procedure we read off disk is automatically invalid,
430
// so we do not try to load the generated class.
431
bootingDictionary.readOnlyUpgrade = true;
432         }
433
434         bootingDictionary.clearCaches();
435     }
436
437     /**
438      * Drop all jdbc metadata spses. This
439      * it to ensure that we don't have any problems
440      * with old metadata queries that have outdated
441      * query text (the plans are always cleared out
442      * on upgrade time).
443      *
444      * @param tc the xact
445      * @param removeSYSIBMonly if <code>true</code>, remove stored
446      * prepared statements in the SYSIBM schema only; otherwise,
447      * remove stored prepared statements in all system schemas
448      * (including SYSIBM)
449      *
450      * @exception StandardException Standard Cloudscape error policy.
451      */

452     protected void dropJDBCMetadataSPSes(TransactionController tc, boolean removeSYSIBMonly)
453         throws StandardException
454     {
455         for (java.util.Iterator JavaDoc it = bootingDictionary.getAllSPSDescriptors().iterator(); it.hasNext(); )
456         {
457             SPSDescriptor spsd = (SPSDescriptor) it.next();
458             SchemaDescriptor sd = spsd.getSchemaDescriptor();
459             // need to compare the name, old SYSIBM is not built-in
460
boolean isSYSIBM = sd.getSchemaName().equals(SchemaDescriptor.IBM_SYSTEM_SCHEMA_NAME);
461
462             // don't drop statements in non-system schemas
463
if (!sd.isSystemSchema() && !isSYSIBM) {
464                 continue;
465             }
466
467             // don't drop statements outside the SYSIBM schema if
468
// we're told not to
469
if (removeSYSIBMonly && !isSYSIBM) {
470                 continue;
471             }
472
473             bootingDictionary.dropSPSDescriptor(spsd, tc);
474             bootingDictionary.dropDependentsStoredDependencies(spsd.getUUID(),
475                                                                tc);
476         }
477     }
478
479     /**
480      * Make a catalog.
481      * @param tc TransactionController
482      * @exception StandardException Standard Cloudscape error policy.
483      */

484     protected void makeSystemCatalog(TransactionController tc,
485                                      TabInfoImpl ti)
486         throws StandardException
487     {
488         SchemaDescriptor sd = bootingDictionary.getSystemSchemaDescriptor();
489         bootingDictionary.makeCatalog(ti,sd,tc);
490     }
491
492     /**
493       Remove the description of a System table from the data dictionary.
494       This does not delete the conglomerates that hold the catalog or
495       its indexes.
496       @param tc TransactionController
497       @param td Table descriptor for the catalog to drop.
498       @exception StandardException Standard Cloudscape error policy.
499       */

500     protected void
501     dropSystemCatalogDescription(TransactionController tc, TableDescriptor td)
502         throws StandardException
503     {
504         /* Drop the columns */
505         bootingDictionary.dropAllColumnDescriptors(td.getUUID(), tc);
506
507         /* Drop the conglomerate descriptors */
508         bootingDictionary.dropAllConglomerateDescriptors(td, tc);
509
510         /* Drop table descriptor */
511         bootingDictionary.dropTableDescriptor( td, td.getSchemaDescriptor(), tc );
512         bootingDictionary.clearCaches();
513     }
514
515     /**
516      * Drop a System catalog.
517      * @param tc TransactionController
518      * @param crf CatalogRowFactory for the catalog to drop.
519      * @exception StandardException Standard Cloudscape error policy.
520      */

521     protected void dropSystemCatalog(TransactionController tc,
522                              CatalogRowFactory crf)
523         throws StandardException
524     {
525         SchemaDescriptor sd = bootingDictionary.getSystemSchemaDescriptor();
526         TableDescriptor td = bootingDictionary.getTableDescriptor(
527                                             crf.getCatalogName(),
528                                             sd);
529         ConglomerateDescriptor[] cds = td.getConglomerateDescriptors();
530         for (int index = 0; index < cds.length; index++)
531         {
532             tc.dropConglomerate(cds[index].getConglomerateNumber());
533         }
534         dropSystemCatalogDescription(tc,td);
535     }
536
537
538     /**
539      * Populates a new system index from the base system table.
540      *
541      * @param tc transaction controller
542      * @param heapConglomerateNumber identifies system table to Store
543      * @param tabInfo describes base system table
544      * @param indexNumber index to populate
545      *
546      *
547      * @exception StandardException Thrown on failure
548      */

549     protected void fillIndex
550     (
551         TransactionController tc,
552         long heapConglomerateNumber,
553         TabInfoImpl tabInfo,
554         int indexNumber
555     )
556         throws StandardException
557     {
558         long indexConglomerateNumber = tabInfo.getIndexConglomerate( indexNumber );
559         IndexRowGenerator indexRowGenerator = tabInfo.getIndexRowGenerator( indexNumber );
560         CatalogRowFactory rowFactory = tabInfo.getCatalogRowFactory();
561         ExecRow heapRow = rowFactory.makeEmptyRow();
562         ExecIndexRow indexableRow = indexRowGenerator.getIndexRowTemplate();
563
564         ScanController heapScan =
565             tc.openScan(
566                 heapConglomerateNumber, // conglomerate to open
567
false, // don't hold open across commit
568
0, // for read
569
TransactionController.MODE_TABLE,
570                 TransactionController.ISOLATION_REPEATABLE_READ,
571                 (FormatableBitSet) null, // all fields as objects
572
null, // start position - first row
573
ScanController.GE, // startSearchOperation
574
null, //scanQualifier,
575
null, //stop position-through last row
576
ScanController.GT); // stopSearchOperation
577

578         RowLocation heapLocation =
579             heapScan.newRowLocationTemplate();
580
581         ConglomerateController indexController =
582             tc.openConglomerate(
583                 indexConglomerateNumber,
584                 false,
585                 TransactionController.OPENMODE_FORUPDATE,
586                 TransactionController.MODE_TABLE,
587                 TransactionController.ISOLATION_REPEATABLE_READ);
588
589         while ( heapScan.fetchNext(heapRow.getRowArray()) )
590         {
591             heapScan.fetchLocation( heapLocation );
592
593             indexRowGenerator.getIndexRow( heapRow, heapLocation, indexableRow, (FormatableBitSet) null );
594
595             indexController.insert(indexableRow.getRowArray());
596         }
597
598         indexController.close();
599         heapScan.close();
600     }
601
602     ////////////////////////////////////////////////////////////////////////
603
//
604
// FORMATABLE INTERFACE
605
//
606
////////////////////////////////////////////////////////////////////////
607
/**
608      * Get the formatID which corresponds to this class.
609        Map to the 5.0 version identifier so that 5.0 will understand
610        this object when we write it out in soft upgrade mode.
611        CS 5.0 will de-serialize it correctly.
612        When we are writing out a 5.1 version number we write out
613        the 5.1 version just to ensure no problems.
614        
615      *
616      * @return the formatID of this class
617      */

618     public int getTypeFormatId() {
619         return majorVersionNumber == DataDictionary.DD_VERSION_CS_5_1 ?
620             StoredFormatIds.DD_ARWEN_VERSION_ID : StoredFormatIds.DD_DB2J72_VERSION_ID;
621     }
622     /**
623      * Read this object from a stream of stored objects. Set
624      * the minor version. Ignore the major version.
625      *
626      * @param in read this.
627      *
628      * @exception IOException on error
629      */

630     public final void readExternal( ObjectInput JavaDoc in ) throws IOException JavaDoc
631     {
632         majorVersionNumber = in.readInt();
633         minorVersionNumber = in.readInt();
634     }
635
636     /**
637      * Write this object to a stream of stored objects. Write
638      * out the minor version which is bumped across minor release.
639      * Just to be safe, write out the major version too. This
640      * will allow us to do versioning of a specific Version impl
641      * in the future.
642      *
643      * @param out write bytes here.
644      *
645      * @exception IOException on error
646      */

647     public final void writeExternal( ObjectOutput JavaDoc out ) throws IOException JavaDoc
648     {
649         out.writeInt(majorVersionNumber);
650         out.writeInt(minorVersionNumber);
651     }
652     /**
653      * Get the minor version from the JBMS product minor version/maint version.
654      * Bumps it up by 1 if production, or 0 if beta to ensure
655      * minor upgrade across beta. Starts at 2 because of an
656      * old convention. We use this starting at 2 to allow soft upgrade to
657      * write a version of 1 with the old major number to ensure a minor upgrade
658        when reverting to an old version afer a soft upgrade. E.g run with 5.0.2,
659        then 5.2.1.1, then 5.0.2. Want to ensure 5.0.2 does the minor upgrade.
660      *
661      * @return the minor version
662
663         For 5.0 and 5.1 the minor number was calculated as
664
665         jbmsVersion.getMinorVersion()*100 +jbmsVersion.getMaintVersion() + (jbmsVersion.isBeta() ? 0 : 1) + 2
666
667         5.0.22 => (0*100) + 22 + 2 = 24 - (5.0 has a unique major number)
668         5.1.2 => (1*100) + 2 + 2 = 104 - (5.1 has a unique major number)
669
670
671         With the switch to the four part scheme in 5.2, the maint number now is in increments of one million,
672         thus the above scheme could lead to duplicate numbers. Note that the major number may not change
673         when the minor external release changes, e.g. 5.2 and 5.3 could share a DD_Version major number.
674
675         5.2.1.100 => (2*100) + 1000100 + 2 = 1000302
676         5.3.1.0 => (3*100) + 1000000 + 2 = 1000302
677
678         
679
680      */

681     private int getJBMSMinorVersionNumber()
682     {
683         ProductVersionHolder jbmsVersion = Monitor.getMonitor().getEngineVersion();
684
685         return jbmsVersion.getMinorVersion()*100 +jbmsVersion.getMaintVersion() + (jbmsVersion.isBeta() ? 0 : 1) + 2;
686     }
687     
688     /**
689      *
690      * Modifies the nullability of the system table corresponding
691      * to the received catalog number.
692      * OLD Cloudscape 5.1 upgrade code
693      * @param tc TransactionController.
694      * @param catalogNum The catalog number corresponding
695      * to the table for which we will modify the nullability.
696      * If this corresponds to SYSALIASES, then the nullability of
697      * the SYSALIASES.ALIASINFO column will be changed to true
698      * (Beetle 4430). If this corresponds to SYSSTATEMENTS,
699      * the nullability of the SYSSTATEMENTS.LASTCOMPILED
700      * column will be changed to true.
701      *
702      * @exception StandardException
703      */

704
705     /* OLD Cloudscape 5.1 upgrade code. See applySafeChanges().
706
707     private void modifySysTableNullability(TransactionController tc, int catalogNum)
708     throws StandardException
709     {
710
711         TabInfo ti = bootingDictionary.getNonCoreTIByNumber(catalogNum);
712         CatalogRowFactory rowFactory = ti.getCatalogRowFactory();
713         if (catalogNum == DataDictionaryImpl.SYSALIASES_CATALOG_NUM) {
714         // SYSALIASES table ==> ALIASINFO needs to be modified.
715             bootingDictionary.upgrade_setNullability(rowFactory,
716                 SYSALIASESRowFactory.SYSALIASES_ALIASINFO, true, tc);
717         }
718         else if (catalogNum == DataDictionaryImpl.SYSSTATEMENTS_CATALOG_NUM) {
719         // SYSSTATEMENTS table ==> LASTCOMPILED needs to be modified.
720             bootingDictionary.upgrade_setNullability(rowFactory,
721                 SYSSTATEMENTSRowFactory.SYSSTATEMENTS_LASTCOMPILED, true, tc);
722         }
723     }
724 */

725     /**
726         Check to see if a database has been upgraded to the required
727         level in order to use a language feature.
728
729         @param requiredMajorVersion Data Dictionary major version
730         @param feature Non-null to throw an error, null to return the state of the version match.
731
732         @return True if the database has been upgraded to the required level, false otherwise.
733     */

734     boolean checkVersion(int requiredMajorVersion, String JavaDoc feature) throws StandardException {
735
736         if (majorVersionNumber < requiredMajorVersion) {
737
738             if (feature != null)
739                 throw StandardException.newException(SQLState.LANG_STATEMENT_UPGRADE_REQUIRED, feature,
740                     DD_Version.majorToString(majorVersionNumber),
741                     DD_Version.majorToString(requiredMajorVersion));
742
743             return false;
744         }
745
746         return true;
747     }
748
749 }
750
Popular Tags