root / branches / v2_0_0_prep / libraries / libFMap_daldb / src / org / gvsig / fmap / data / feature / db / DBResource.java @ 24491
History | View | Annotate | Download (3.19 KB)
1 | 23340 | jmvivo | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2008 IVER T.I. S.A. {{Task}}
|
||
26 | */
|
||
27 | |||
28 | /**
|
||
29 | *
|
||
30 | */
|
||
31 | package org.gvsig.fmap.data.feature.db; |
||
32 | |||
33 | 24491 | jmvivo | import org.gvsig.fmap.dal.DataParameters; |
34 | import org.gvsig.fmap.dal.exceptions.InitializeException; |
||
35 | import org.gvsig.fmap.dal.exceptions.OpenException; |
||
36 | import org.gvsig.fmap.dal.resource.spi.AbstractResource; |
||
37 | 23340 | jmvivo | |
38 | /**
|
||
39 | * @author jmvivo
|
||
40 | *
|
||
41 | */
|
||
42 | 23754 | jjdelcerro | public abstract class DBResource extends AbstractResource { |
43 | 23615 | jmvivo | protected DBParameters dbparameters;
|
44 | 23340 | jmvivo | protected String user; |
45 | protected String password; |
||
46 | |||
47 | |||
48 | 23615 | jmvivo | protected DBResource(DataParameters parameters) {
|
49 | super(parameters);
|
||
50 | this.dbparameters = (DBParameters) parameters;
|
||
51 | this.user = this.dbparameters.getUser(); |
||
52 | this.password = this.dbparameters.getPassw(); |
||
53 | 23340 | jmvivo | } |
54 | |||
55 | /**
|
||
56 | * @return the password
|
||
57 | */
|
||
58 | public String getPassword() { |
||
59 | return password;
|
||
60 | } |
||
61 | |||
62 | /**
|
||
63 | * @param password the password to set
|
||
64 | * @throws InitializeException
|
||
65 | */
|
||
66 | public void setPassword(String password) throws InitializeException { |
||
67 | if (inUse()){
|
||
68 | 23754 | jjdelcerro | throw new InitializeException("Resource in use",this.getDescription()); |
69 | 23340 | jmvivo | } |
70 | this.password = password;
|
||
71 | } |
||
72 | |||
73 | /**
|
||
74 | * @return the user
|
||
75 | */
|
||
76 | public String getUser() { |
||
77 | return user;
|
||
78 | } |
||
79 | |||
80 | /**
|
||
81 | * @param user the user to set
|
||
82 | * @throws InitializeException
|
||
83 | */
|
||
84 | public void setUser(String user) throws InitializeException { |
||
85 | if (this.getRefencesCount() > 0){ |
||
86 | 23754 | jjdelcerro | throw new InitializeException("Resource in use",this.getDescription()); |
87 | 23340 | jmvivo | } |
88 | this.user = user;
|
||
89 | } |
||
90 | |||
91 | public boolean testConnection() { |
||
92 | try{
|
||
93 | this.open();
|
||
94 | } catch (OpenException e) {
|
||
95 | return false; |
||
96 | } |
||
97 | return true; |
||
98 | } |
||
99 | |||
100 | public abstract boolean inUse(); |
||
101 | |||
102 | // protected boolean equalsValues(String v1, String v2){
|
||
103 | // if (v1 == null || v1.length()== 0){
|
||
104 | // return v2 == null || v2.length() == 0;
|
||
105 | // } else if (v2 == null || v2.length() == 0){
|
||
106 | // return false;
|
||
107 | // }
|
||
108 | // return v1.equals(v2);
|
||
109 | //
|
||
110 | // }
|
||
111 | //
|
||
112 | |||
113 | // public String getCatalog() {
|
||
114 | // return this.parameters.getCatalog();
|
||
115 | // }
|
||
116 | //
|
||
117 | // public String getDb() {
|
||
118 | // return this.parameters.getDb();
|
||
119 | // }
|
||
120 | //
|
||
121 | // public String getHost() {
|
||
122 | // return this.parameters.getHost();
|
||
123 | // }
|
||
124 | //
|
||
125 | // public String getPassw() {
|
||
126 | // return this.parameters.getHost();
|
||
127 | // }
|
||
128 | //
|
||
129 | // public String getPort() {
|
||
130 | // return this.parameters.getPort();
|
||
131 | // }
|
||
132 | //
|
||
133 | // public String getSchema() {
|
||
134 | // return this.parameters.getSchema();
|
||
135 | // }
|
||
136 | |||
137 | } |