01: /*
02:
03: Derby - Class org.apache.derby.impl.store.access.PC_XenaVersion
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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;
36: import java.io.ObjectInput;
37: import java.io.ObjectOutput;
38: import java.io.StreamCorruptedException;
39: import java.util.Enumeration;
40: import java.util.Properties;
41:
42: public class PC_XenaVersion implements Formatable {
43: private static final int XENA_MAJOR_VERSION = 1;
44: private static final int XENA_MINOR_VERSION_0 = 0;
45:
46: //
47: //Persistent state. The default value defined here is
48: //over-ridden by readExternal when reading serialized
49: //versions.
50: private int minorVersion = XENA_MINOR_VERSION_0;
51:
52: private boolean isUpgradeNeeded(PC_XenaVersion fromVersion) {
53: return fromVersion == null
54: || getMajorVersionNumber() != fromVersion
55: .getMajorVersionNumber();
56: }
57:
58: public void upgradeIfNeeded(TransactionController tc,
59: PropertyConglomerate pc, Properties serviceProperties)
60: throws StandardException {
61: PC_XenaVersion dbVersion = (PC_XenaVersion) pc.getProperty(tc,
62: DataDictionary.PROPERTY_CONGLOMERATE_VERSION);
63: if (isUpgradeNeeded(dbVersion)) {
64: throw StandardException.newException(
65: SQLState.UPGRADE_UNSUPPORTED, dbVersion, this );
66: }
67: }
68:
69: public int getMajorVersionNumber() {
70: return XENA_MAJOR_VERSION;
71: }
72:
73: public int getMinorVersionNumber() {
74: return minorVersion;
75: }
76:
77: public void writeExternal(ObjectOutput out) throws IOException {
78: out.writeInt(getMajorVersionNumber());
79: out.writeInt(getMinorVersionNumber());
80: }
81:
82: public void readExternal(ObjectInput in) throws IOException {
83: int majorVersion = in.readInt();
84: minorVersion = in.readInt();
85: }
86:
87: public int getTypeFormatId() {
88: return StoredFormatIds.PC_XENA_VERSION_ID;
89: }
90:
91: public String toString() {
92: return getMajorVersionNumber() + "." + getMinorVersionNumber();
93: }
94: }
|