KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > PC_XenaVersion


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.PC_XenaVersion
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.store.access;
23
24 import org.apache.derby.iapi.reference.SQLState;
25 import org.apache.derby.iapi.reference.Property;
26 import org.apache.derby.iapi.reference.ClassName;
27 import org.apache.derby.iapi.services.io.FormatIdUtil;
28 import org.apache.derby.iapi.services.io.StoredFormatIds;
29 import org.apache.derby.iapi.services.io.Formatable;
30 import org.apache.derby.iapi.error.StandardException;
31 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
32 import org.apache.derby.iapi.store.access.TransactionController;
33 import org.apache.derby.iapi.services.property.PropertyUtil;
34 import org.apache.derby.catalog.UUID;
35 import java.io.IOException JavaDoc;
36 import java.io.ObjectInput JavaDoc;
37 import java.io.ObjectOutput JavaDoc;
38 import java.io.StreamCorruptedException JavaDoc;
39 import java.util.Enumeration JavaDoc;
40 import java.util.Properties JavaDoc;
41
42 public class PC_XenaVersion implements Formatable
43 {
44     private static final int XENA_MAJOR_VERSION = 1;
45     private static final int XENA_MINOR_VERSION_0 = 0;
46
47     //
48
//Persistent state. The default value defined here is
49
//over-ridden by readExternal when reading serialized
50
//versions.
51
private int minorVersion = XENA_MINOR_VERSION_0;
52     
53
54     private boolean isUpgradeNeeded(PC_XenaVersion fromVersion)
55     {
56         return
57             fromVersion == null ||
58             getMajorVersionNumber() != fromVersion.getMajorVersionNumber();
59     }
60
61     public void upgradeIfNeeded(TransactionController tc,
62                                 PropertyConglomerate pc,
63                                 Properties JavaDoc serviceProperties)
64          throws StandardException
65     {
66         PC_XenaVersion dbVersion =
67             (PC_XenaVersion)pc.getProperty(tc,DataDictionary.PROPERTY_CONGLOMERATE_VERSION);
68         if (isUpgradeNeeded(dbVersion))
69         {
70             throw StandardException.newException(SQLState.UPGRADE_UNSUPPORTED, dbVersion, this);
71         }
72     }
73
74     public int getMajorVersionNumber() {return XENA_MAJOR_VERSION;}
75     public int getMinorVersionNumber() {return minorVersion;}
76     
77     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
78     {
79         out.writeInt(getMajorVersionNumber());
80         out.writeInt(getMinorVersionNumber());
81     }
82
83     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc
84     {
85         int majorVersion = in.readInt();
86         minorVersion = in.readInt();
87     }
88
89     public int getTypeFormatId() {return StoredFormatIds.PC_XENA_VERSION_ID;}
90
91     public String JavaDoc toString() {return getMajorVersionNumber()+"."+getMinorVersionNumber();}
92 }
93
Popular Tags