Revision 1086
Added by Jing Tao over 22 years ago
src/edu/ucsb/nceas/metacat/DBConnection.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Purpose: A class represent a connection object, it includes connction |
|
4 |
* itself, index, status, age and usageCount. |
|
5 |
* Copyright: 2000 Regents of the University of California and the |
|
6 |
* National Center for Ecological Analysis and Synthesis |
|
7 |
* Authors: Jing Tao |
|
8 |
* Release: @release@ |
|
9 |
* |
|
10 |
* '$Author$' |
|
11 |
* '$Date$' |
|
12 |
* '$Revision$' |
|
13 |
* |
|
14 |
* This program is free software; you can redistribute it and/or modify |
|
15 |
* it under the terms of the GNU General Public License as published by |
|
16 |
* the Free Software Foundation; either version 2 of the License, or |
|
17 |
* (at your option) any later version. |
|
18 |
* |
|
19 |
* This program is distributed in the hope that it will be useful, |
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
* GNU General Public License for more details. |
|
23 |
* |
|
24 |
* You should have received a copy of the GNU General Public License |
|
25 |
* along with this program; if not, write to the Free Software |
|
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
27 |
*/ |
|
28 |
|
|
29 |
package edu.ucsb.nceas.metacat; |
|
30 |
|
|
31 |
import java.io.*; |
|
32 |
import java.sql.*; |
|
33 |
|
|
34 |
/** |
|
35 |
* A class represent a connection object, it includes connection itself, |
|
36 |
* index, status, age, usageCount, warning message |
|
37 |
*/ |
|
38 |
|
|
39 |
public class DBConnection |
|
40 |
{ |
|
41 |
private Connection conn; |
|
42 |
private int status; |
|
43 |
private long age; |
|
44 |
private int usageCount; |
|
45 |
private SQLWarning warningMessage; |
|
46 |
|
|
47 |
/** |
|
48 |
* default constructor of the DBConnection class |
|
49 |
* |
|
50 |
*/ |
|
51 |
public DBConnection() |
|
52 |
{ |
|
53 |
conn = null; |
|
54 |
status = 0; |
|
55 |
age = 0; |
|
56 |
usageCount= 0; |
|
57 |
warningMessage = null; |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* construct an instance of the DBQConnection class |
|
63 |
* |
|
64 |
* @param conn, the JDBC connection itself. |
|
65 |
* @param status, the status of this connection, free or using |
|
66 |
* @param age,the age of the connection |
|
67 |
* @param usageCount of the connection |
|
68 |
*/ |
|
69 |
public DBConnection (Connection conn, int status, int myAge, |
|
70 |
int usageCount) |
|
71 |
throws SQLException |
|
72 |
{ |
|
73 |
this.conn = conn; |
|
74 |
this.status = status; |
|
75 |
this.age = age; |
|
76 |
this.usageCount = usageCount; |
|
77 |
try |
|
78 |
{ |
|
79 |
this.warningMessage = conn.getWarnings(); |
|
80 |
} |
|
81 |
catch (SQLException e) |
|
82 |
{ |
|
83 |
throw e; |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* get the db connetion from the object |
|
89 |
*/ |
|
90 |
public Connection getDBConnection() |
|
91 |
{ |
|
92 |
return conn; |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* Set a connection to this object |
|
97 |
* @param myDBConnection, the connection which will be assign to this object |
|
98 |
*/ |
|
99 |
public void setDBConnection( Connection myDBConnection) |
|
100 |
{ |
|
101 |
this.conn = myDBConnection; |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* get the db connetion status from the object |
|
106 |
*/ |
|
107 |
public int getStatus() |
|
108 |
{ |
|
109 |
return status; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Set a connection status to this object |
|
114 |
* @param myStatus, the status which will be assign to this object |
|
115 |
* 0 is free, 1 is using |
|
116 |
*/ |
|
117 |
public void setStatus(int myStatus) |
|
118 |
{ |
|
119 |
this.status = myStatus; |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* get the db connetion age from the object |
|
124 |
*/ |
|
125 |
public long getAge() |
|
126 |
{ |
|
127 |
return age; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Set a connection age to this object |
|
132 |
* @param myAge, the Age which will be assign to this object |
|
133 |
*/ |
|
134 |
public void setAge(long myAge) |
|
135 |
{ |
|
136 |
this.age = myAge; |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
/** |
|
141 |
* get the db connetion usage times from the object |
|
142 |
*/ |
|
143 |
public int getUsageCount() |
|
144 |
{ |
|
145 |
return usageCount; |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Set a usage number to this object |
|
150 |
* @param myUsageCount, number of usage which will be assign to this object |
|
151 |
*/ |
|
152 |
public void setUsageCount(int myUsageCount) |
|
153 |
{ |
|
154 |
this.usageCount = myUsageCount; |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* get the db connetion waring message from the object |
|
159 |
*/ |
|
160 |
public SQLWarning getWarningMessage() |
|
161 |
{ |
|
162 |
return warningMessage; |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Set a warning message to this object |
|
167 |
* @param myWarningMessage, the waring which will be assign to this object |
|
168 |
*/ |
|
169 |
public void setWarningMessage(SQLWarning myWarningMessage) |
|
170 |
{ |
|
171 |
this.warningMessage = myWarningMessage; |
|
172 |
} |
|
173 |
|
|
174 |
|
|
175 |
}//DBConnection class |
|
0 | 176 |
Also available in: Unified diff
Add this new class into meta package. DBConnection class repsent a conncetion and its information.