001: /*
002:
003: Derby - Class org.apache.derby.client.am.ProductLevel
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021: package org.apache.derby.client.am;
022:
023: public class ProductLevel {
024: public String databaseProductName_;
025: public int versionLevel_;
026: public int releaseLevel_;
027: public int modificationLevel_;
028:
029: // The following value is sent in the srvrlslv level
030: public String databaseProductVersion_;
031:
032: // The productID is set by the constructors.
033: // dabaseProductVersion added by derby to include srvrlslv
034: public ProductLevel(String productID, String databaseProductName,
035: String srvrlslv) {
036: // this.productID has the following format
037: // CSS for Derby
038: // vv = version id
039: // rr = release id
040: // m = modification level
041: versionLevel_ = Integer.parseInt(productID.substring(3, 5));
042: releaseLevel_ = Integer.parseInt(productID.substring(5, 7));
043: modificationLevel_ = Integer
044: .parseInt(productID.substring(7, 8));
045: databaseProductName_ = (databaseProductName == null) ? "Derby"
046: : databaseProductName; // This is the srvclsnm in PROTOCOL.
047:
048: // databaseProductVersion - extracted from the srvrlslv.
049: // srvrlslv has the format <PRDID>/<ALTERNATE VERSION FORMAT>
050: // for example Derby has a four part verison number so might send
051: // CSS10000/10.0.1.1 beta. If the alternate version format is not
052: // specified,
053: // databaseProductVersion_ will just be set to the srvrlslvl.
054: // final fallback will be the product id.
055: // this is the value returned with the getDatabaseProductVersion()
056: // metadata call
057: int dbVersionOffset = 0;
058: if (srvrlslv != null) {
059: dbVersionOffset = srvrlslv.indexOf('/') + 1;
060: // if there was no '/' dbVersionOffset will just be 0
061: databaseProductVersion_ = srvrlslv
062: .substring(dbVersionOffset);
063: }
064: if (databaseProductVersion_ == null) {
065: databaseProductVersion_ = productID;
066: }
067: }
068:
069: public boolean greaterThanOrEqualTo(int versionLevel,
070: int releaseLevel, int modificationLevel) {
071: if (versionLevel_ > versionLevel) {
072: return true;
073: } else if (versionLevel_ == versionLevel) {
074: if (releaseLevel_ > releaseLevel) {
075: return true;
076: } else if (releaseLevel_ == releaseLevel) {
077: if (modificationLevel_ >= modificationLevel) {
078: return true;
079: }
080: }
081: }
082: return false;
083: }
084:
085: public boolean lessThan(int versionLevel, int releaseLevel,
086: int modificationLevel) {
087: if (versionLevel_ < versionLevel) {
088: return true;
089: } else if (versionLevel_ == versionLevel) {
090: if (releaseLevel_ < releaseLevel) {
091: return true;
092: } else if (releaseLevel_ == releaseLevel) {
093: if (modificationLevel_ < modificationLevel) {
094: return true;
095: }
096: }
097: }
098: return false;
099: }
100: }
|