KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > ProductLevel


1 /*
2
3    Derby - Class org.apache.derby.client.am.ProductLevel
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 package org.apache.derby.client.am;
22
23 public class ProductLevel {
24     public String JavaDoc databaseProductName_;
25     public int versionLevel_;
26     public int releaseLevel_;
27     public int modificationLevel_;
28
29     // The following value is sent in the srvrlslv level
30
public String JavaDoc databaseProductVersion_;
31
32     // The productID is set by the constructors.
33
// dabaseProductVersion added by derby to include srvrlslv
34
public ProductLevel(String JavaDoc productID, String JavaDoc databaseProductName,
35                         String JavaDoc srvrlslv) {
36         // this.productID has the following format
37
// CSS for Derby
38
// vv = version id
39
// rr = release id
40
// m = modification level
41
versionLevel_ = Integer.parseInt(productID.substring(3, 5));
42         releaseLevel_ = Integer.parseInt(productID.substring(5, 7));
43         modificationLevel_ = Integer.parseInt(productID.substring(7, 8));
44         databaseProductName_ = (databaseProductName == null) ?
45                 "Derby" : databaseProductName; // This is the srvclsnm in PROTOCOL.
46

47         // databaseProductVersion - extracted from the srvrlslv.
48
// srvrlslv has the format <PRDID>/<ALTERNATE VERSION FORMAT>
49
// for example Derby has a four part verison number so might send
50
// CSS10000/10.0.1.1 beta. If the alternate version format is not
51
// specified,
52
// databaseProductVersion_ will just be set to the srvrlslvl.
53
// final fallback will be the product id.
54
// this is the value returned with the getDatabaseProductVersion()
55
// metadata call
56
int dbVersionOffset = 0;
57         if (srvrlslv != null) {
58             dbVersionOffset = srvrlslv.indexOf('/') + 1;
59             // if there was no '/' dbVersionOffset will just be 0
60
databaseProductVersion_ = srvrlslv.substring(dbVersionOffset);
61         }
62         if (databaseProductVersion_ == null) {
63             databaseProductVersion_ = productID;
64         }
65     }
66
67     public boolean greaterThanOrEqualTo(int versionLevel, int releaseLevel, int modificationLevel) {
68         if (versionLevel_ > versionLevel) {
69             return true;
70         } else if (versionLevel_ == versionLevel) {
71             if (releaseLevel_ > releaseLevel) {
72                 return true;
73             } else if (releaseLevel_ == releaseLevel) {
74                 if (modificationLevel_ >= modificationLevel) {
75                     return true;
76                 }
77             }
78         }
79         return false;
80     }
81
82     public boolean lessThan(int versionLevel, int releaseLevel, int modificationLevel) {
83         if (versionLevel_ < versionLevel) {
84             return true;
85         } else if (versionLevel_ == versionLevel) {
86             if (releaseLevel_ < releaseLevel) {
87                 return true;
88             } else if (releaseLevel_ == releaseLevel) {
89                 if (modificationLevel_ < modificationLevel) {
90                     return true;
91                 }
92             }
93         }
94         return false;
95     }
96 }
97
Popular Tags