Revision 38285

View differences:

tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/resource/db/AbstractDBResourceNoBlocker.java
1
/* 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
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.resource.db;
29

  
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.exception.InitializeException;
32
import org.gvsig.fmap.dal.resource.ResourceParameters;
33
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
34
import org.gvsig.fmap.dal.resource.exception.ResourceException;
35
import org.gvsig.fmap.dal.resource.spi.AbstractNonBlockingResource;
36

  
37
/**
38
 * <p>
39
 * Abstract Data Base Resource implementation that allow the concurrent access.
40
 * </p>
41
 * 
42
 * <p>
43
 * Useful for Pooled Data Base Access.
44
 * </p>
45
 * 
46
 * @author jmvivo
47
 *
48
 */
49
public abstract class AbstractDBResourceNoBlocker extends AbstractNonBlockingResource {
50

  
51
	/**
52
	 * Default constructor
53
	 *
54
	 * @param parameters
55
	 * @throws InitializeException
56
	 */
57
	protected AbstractDBResourceNoBlocker(DBResourceParameters parameters)
58
			throws InitializeException {
59
		super(parameters);
60
	}
61

  
62
	/**
63
	 * Return a connection to the data base.<br>
64
	 * Connect to the Data Base if is needed
65
	 *
66
	 * @return connection to the data base
67
	 */
68
	public Object get() throws AccessResourceException {
69
		if (!isConnected()) {
70
			try {
71
				this.connect();
72
			} catch (DataException e) {
73
				throw new AccessResourceException(this, e);
74
			}
75
		}
76
		try {
77
			return getTheConnection();
78
		} catch (DataException e) {
79
			throw new AccessResourceException(this, e);
80
		}
81
	}
82

  
83
	/**
84
	 * Return a connection to the data base.<br>
85
	 * Connect to the Data Base if is needed
86
	 *
87
	 *
88
	 * @return connection to the data base
89
	 * @see #get()
90
	 */
91
	public Object getConnection() throws AccessResourceException {
92
		return get();
93
	}
94

  
95
	/**
96
	 * inform if connection to the data base is established
97
	 *
98
	 * @return
99
	 */
100
	public abstract boolean isConnected();
101

  
102
	/**
103
	 * Establish connection to data base
104
	 *
105
	 * @throws DataException
106
	 */
107
	public final void connect() throws DataException {
108
		if (this.isConnected()) {
109
			return;
110
		}
111
		prepare();
112
		connectToDB();
113
	}
114

  
115
	/**
116
	 * final implementation method to Establish connection to data base<br>
117
	 * Called from {@link #get()}<br>
118
	 * <br>
119
	 *
120
	 *
121
	 * @throws DataException
122
	 */
123
	protected abstract void connectToDB() throws DataException;
124

  
125
	/**
126
	 * final implementation method to get a connection to data base<br>
127
	 * Called from {@link #connect()}<br>
128
	 * <br>
129
	 * This method is called with the connection establish
130
	 *
131
	 * @throws DataException
132
	 */
133
	protected abstract Object getTheConnection() throws DataException;
134

  
135
	/**
136
	 * Check if parameters is the same for this resource.<br>
137
	 * <br>
138
	 *
139
	 * <strong>Note:</strong> override this method to add checks for specify
140
	 * final implementation parameters
141
	 *
142
	 *
143
	 * @see AbstractResource#isThis(ResourceParameters)
144
	 */
145
	public boolean isThis(ResourceParameters parameters)
146
			throws ResourceException {
147
		if (!(parameters instanceof DBResourceParameters)) {
148
			return false;
149
		}
150
		DBResourceParameters params = (DBResourceParameters) parameters
151
				.getCopy();
152
		prepare(params);
153
		DBResourceParameters myParams = (DBResourceParameters) this
154
				.getParameters();
155

  
156
		if (!equals(myParams.getHost(), params.getHost())) {
157
			return false;
158
		}
159
		if (!equals(myParams.getPort(), params.getPort())) {
160
			return false;
161
		}
162
		if (!equals(myParams.getUser(), params.getUser())) {
163
			return false;
164
		}
165

  
166
		return true;
167
	}
168

  
169
	@SuppressWarnings("unchecked")
170
	protected boolean equals(Comparable v1, Comparable v2) {
171
		if (v1 == v2) {
172
			return true;
173
		}
174
		if ((v1 != null) && (v2 != null)) {
175
			return v1.compareTo(v2) == 0;
176
		}
177
		return false;
178
	}
179

  
180

  
181
}
0 182

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/resource/db/DBResourceParameters.java
1
/* 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
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.resource.db;
29

  
30
import org.gvsig.fmap.dal.resource.spi.AbstractResourceParameters;
31
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
32
import org.gvsig.fmap.dal.store.db.DBHelper;
33
import org.gvsig.tools.dynobject.DelegatedDynObject;
34

  
35
/**
36
 * Base Abstract class to Data Base Resources Parameters
37
 *
38
 * @author jmvivo
39
 *
40
 */
41
public abstract class DBResourceParameters extends AbstractResourceParameters
42
		implements DBParameters {
43

  
44
    public static final String PARAMETERS_DEFINITION_NAME = "DBResourceParameters";
45
	private DelegatedDynObject parameters;
46

  
47
    public DBResourceParameters(String parametersDefinitionName, String typeName) {
48
    	this.parameters = (DelegatedDynObject) DBHelper.newParameters(parametersDefinitionName);
49
    	this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, typeName);
50
	}
51

  
52
	protected DelegatedDynObject getDelegatedDynObject() {
53
		return parameters;
54
	}
55

  
56
	public String getTypeName() {
57
    	return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
58
    }
59
    
60
    public String getHost() {
61
		return (String) this.getDynValue(HOST_PARAMTER_NAME);
62
	}
63

  
64
	public Integer getPort() {
65
		return (Integer) this.getDynValue(PORT_PARAMTER_NAME);
66
	}
67

  
68
	public String getDBName() {
69
		return (String) this.getDynValue(DBNAME_PARAMTER_NAME);
70
	}
71

  
72
	public String getUser() {
73
		return (String) this.getDynValue(USER_PARAMTER_NAME);
74
	}
75

  
76
	public String getPassword() {
77
		return (String) this.getDynValue(PASSWORD_PARAMTER_NAME);
78
	}
79

  
80
	/**
81
	 * Set <code>host</code> parameter value
82
	 *
83
	 * @param host
84
	 */
85
	public void setHost(String host) {
86
		this.setDynValue(HOST_PARAMTER_NAME, host);
87
	}
88

  
89
	/**
90
	 * Set <code>port</code> parameter value
91
	 *
92
	 * @param port
93
	 */
94
	public void setPort(int port) {
95
		this.setDynValue(PORT_PARAMTER_NAME, new Integer(port));
96
	}
97

  
98
	/**
99
	 * Set <code>port</code> parameter value
100
	 *
101
	 * @param port
102
	 */
103
	public void setPort(Integer port) {
104
		this.setDynValue(PORT_PARAMTER_NAME, port);
105
	}
106

  
107
	/**
108
	 * Set <code>data base name</code> parameter value
109
	 *
110
	 * @param data
111
	 *            base name
112
	 */
113
	public void setDBName(String dbName) {
114
		this.setDynValue(DBNAME_PARAMTER_NAME, dbName);
115
	}
116

  
117
	/**
118
	 * Set <code>user</code> parameter value
119
	 * 
120
	 * @param user
121
	 */
122
	public void setUser(String user) {
123
		this.setDynValue(USER_PARAMTER_NAME, user);
124
	}
125

  
126
	/**
127
	 * Set <code>password</code> parameter value
128
	 * 
129
	 * @param password
130
	 */
131
	public void setPassword(String password) {
132
		this.setDynValue(PASSWORD_PARAMTER_NAME, password);
133
	}
134

  
135
}
0 136

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/resource/db/DBResourceLibrary.java
1
/* 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
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.resource.db;
32

  
33
import org.gvsig.fmap.dal.DALDbLibrary;
34
import org.gvsig.fmap.dal.DALLibrary;
35
import org.gvsig.fmap.dal.store.db.DBHelper;
36
import org.gvsig.tools.library.AbstractLibrary;
37
import org.gvsig.tools.library.LibraryException;
38

  
39
/**
40
 * Library to initialize Data Base Resources
41
 *
42
 * @author jmvivo
43
 *
44
 */
45
public class DBResourceLibrary extends AbstractLibrary {
46

  
47
    @Override
48
    public void doRegistration() {
49
        registerAsServiceOf(DALLibrary.class);
50
        require(DALDbLibrary.class);
51
    }
52

  
53
	@Override
54
	protected void doInitialize() throws LibraryException {
55
	}
56

  
57
	@Override
58
	protected void doPostInitialize() throws LibraryException {
59
		DBHelper.registerParametersDefinition(
60
				DBResourceParameters.PARAMETERS_DEFINITION_NAME, 
61
				DBResourceParameters.class, 
62
				"DBParameters.xml"
63
		);
64
	}
65
}
0 66

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/resource/db/AbstractDBResourceBlocker.java
1
/* 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
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.resource.db;
29

  
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.exception.InitializeException;
32
import org.gvsig.fmap.dal.resource.ResourceParameters;
33
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
34
import org.gvsig.fmap.dal.resource.exception.ResourceException;
35
import org.gvsig.fmap.dal.resource.spi.AbstractResource;
36

  
37
/**
38
 * Abstract Data Base Resource implementation that prevents the concurrent
39
 * access.
40
 *
41
 * @author jmvivo
42
 * 
43
 */
44
public abstract class AbstractDBResourceBlocker extends AbstractResource
45
		implements
46
		DBResource {
47

  
48
	/**
49
	 * Default constructor
50
	 *
51
	 * @param parameters
52
	 * @throws InitializeException
53
	 */
54
	protected AbstractDBResourceBlocker(DBResourceParameters parameters)
55
			throws InitializeException {
56
		super(parameters);
57
	}
58

  
59

  
60
	/**
61
	 * Return a connection to the data base.<br>
62
	 * Connect to the Data Base if is needed
63
	 *
64
	 * @return connection to the data base
65
	 */
66
	public Object get() throws AccessResourceException {
67
		if (!isConnected()) {
68
			try {
69
				this.connect();
70
			} catch (DataException e) {
71
				throw new AccessResourceException(this, e);
72
			}
73
		}
74
		try {
75
			return getTheConnection();
76
		} catch (DataException e) {
77
			throw new AccessResourceException(this, e);
78
		}
79
	}
80

  
81
	/**
82
	 * Return a connection to the data base.<br>
83
	 * Connect to the Data Base if is needed
84
	 *
85
	 *
86
	 * @return connection to the data base
87
	 * @see #get()
88
	 */
89
	public Object getConnection() throws AccessResourceException {
90
		return get();
91
	}
92

  
93
	/**
94
	 * Establish connection to data base
95
	 *
96
	 * @throws DataException
97
	 */
98
	public final void connect() throws DataException {
99
		if (this.isConnected()) {
100
			return;
101
		}
102
		prepare();
103
		connectToDB();
104
	}
105

  
106
	/**
107
	 * Check if parameters is the same for this resource.<br>
108
	 * <br>
109
	 *
110
	 * <strong>Note:</strong> override this method to add checks for specify
111
	 * final implementation parameters
112
	 *
113
	 *
114
	 * @see AbstractResource#isThis(ResourceParameters)
115
	 */
116
	public boolean isThis(ResourceParameters parameters)
117
			throws ResourceException {
118
		if (!(parameters instanceof DBResourceParameters)) {
119
			return false;
120
		}
121
		DBResourceParameters params = (DBResourceParameters) parameters
122
				.getCopy();
123
		prepare(params);
124
		DBResourceParameters myParams = (DBResourceParameters) this
125
				.getParameters();
126

  
127
		if (!equals(myParams.getHost(), params.getHost())) {
128
			return false;
129
		}
130
		if (!equals(myParams.getPort(), params.getPort())) {
131
			return false;
132
		}
133
		if (!equals(myParams.getUser(), params.getUser())) {
134
			return false;
135
		}
136

  
137
		return true;
138
	}
139

  
140
	@SuppressWarnings("unchecked")
141
	protected boolean equals(Comparable v1, Comparable v2) {
142
		if (v1 == v2) {
143
			return true;
144
		}
145
		if ((v1 != null) && (v2 != null)) {
146
			return v1.compareTo(v2) == 0;
147
		}
148
		return false;
149
	}
150

  
151
	/**
152
	 * final implementation method to Establish connection to data base<br>
153
	 * Called from {@link #get()}<br>
154
	 * <br>
155
	 *
156
	 *
157
	 * @throws DataException
158
	 */
159
	protected abstract void connectToDB() throws DataException;
160

  
161
	/**
162
	 * final implementation method to get a connection to data base<br>
163
	 * Called from {@link #connect()}<br>
164
	 * <br>
165
	 * This method is called with the connection establish
166
	 *
167
	 * @throws DataException
168
	 */
169
	protected abstract Object getTheConnection() throws DataException;
170

  
171
}
0 172

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/resource/db/DBParameters.java
1
/* 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
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.resource.db;
29

  
30
/**
31
 * Interface for describe parameters of a Data Base
32
 *
33
 *
34
 * @author jmvivo
35
 *
36
 */
37
public interface DBParameters {
38

  
39
	/**
40
	 * Parameter name for <code>host</code>
41
	 */
42
	public static final String HOST_PARAMTER_NAME = "host";
43

  
44
	/**
45
	 * Parameter name for <code>port</code> 
46
	 */
47
	public static final String PORT_PARAMTER_NAME = "port";
48

  
49
	/**
50
	 * Parameter name for <code>data base name</code> 
51
	 */
52
	public static final String DBNAME_PARAMTER_NAME = "dbname";
53

  
54
	/**
55
	 * Parameter name for <code>user</code>
56
	 */
57
	public static final String USER_PARAMTER_NAME = "dbuser";
58

  
59
	/**
60
	 * Parameter name for <code>password</code>
61
	 */
62
	public static final String PASSWORD_PARAMTER_NAME = "password";
63

  
64
	/**
65
	 * Return the value of <code>host</code> parameter
66
	 *
67
	 * @return
68
	 */
69
	public String getHost();
70

  
71
	/**
72
	 * Return the value of <code>port</code> parameter
73
	 *
74
	 * @return
75
	 */
76
	public Integer getPort();
77

  
78
	/**
79
	 * Return the value of <code>data base name</code> parameter
80
	 *
81
	 * @return
82
	 */
83
	public String getDBName();
84

  
85
	/**
86
	 * Return the value of <code>password</code> parameter
87
	 *
88
	 * @return
89
	 */
90
	public String getPassword();
91

  
92
	/**
93
	 * Return the value of <code>user</code> parameter
94
	 *
95
	 * @return
96
	 */
97
	public String getUser();
98

  
99
}
0 100

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/resource/db/DBResource.java
1
/* 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
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.resource.db;
29

  
30
import org.gvsig.fmap.dal.resource.Resource;
31

  
32
/**
33
 * Interface for Resources of a Data Base
34
 *
35
 * @author jmvivo
36
 *
37
 */
38
public interface DBResource extends Resource {
39

  
40
	/**
41
	 * inform if connection to the data base is established
42
	 *
43
	 * @return
44
	 */
45
	public boolean isConnected();
46

  
47
}
0 48

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/serverexplorer/db/DBConnectionParameter.java
1
/* 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
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.serverexplorer.db;
32

  
33
import org.gvsig.fmap.dal.resource.db.DBParameters;
34

  
35
/**
36
 * Interface for describe parameters of a Data Base connection
37
 *
38
 *
39
 * @author jmvivo
40
 *
41
 */
42

  
43
public interface DBConnectionParameter extends DBParameters {
44

  
45
}
0 46

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/serverexplorer/db/spi/AbstractDBServerExplorer.java
1
/* 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
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.serverexplorer.db.spi;
32

  
33
import org.gvsig.fmap.dal.DataServerExplorerParameters;
34
import org.gvsig.fmap.dal.NewDataStoreParameters;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer;
37
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
38
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
39
import org.gvsig.fmap.dal.spi.DataStoreProvider;
40
import org.gvsig.tools.dispose.impl.AbstractDisposable;
41

  
42
/**
43
 * Abstract class for {@link DBServerExplorer} implementation
44
 *
45
 * @author jmvivo
46
 *
47
 */
48
public abstract class AbstractDBServerExplorer extends AbstractDisposable
49
		implements DBServerExplorer, DataServerExplorerProvider {
50

  
51
	private DataServerExplorerProviderServices dataServerExplorerProviderServices;
52
	private DataServerExplorerParameters dataServerParameters;
53

  
54
	protected AbstractDBServerExplorer(DataServerExplorerParameters parameters,
55
			DataServerExplorerProviderServices services) {
56
		this.dataServerParameters = parameters;
57
		this.dataServerExplorerProviderServices = services;
58
	}
59

  
60
	/**
61
	 * Return the name of {@link DataStoreProvider} returned by this
62
	 * ServerExplorer
63
	 *
64
	 * @return
65
	 */
66
	protected abstract String getStoreName();
67

  
68
	/* (non-Javadoc)
69
	 * @see org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer#canAdd(java.lang.String)
70
	 */
71
	public boolean canAdd(String storeName) throws DataException {
72
		return getStoreName().equals(storeName);
73
	}
74

  
75

  
76
	/* (non-Javadoc)
77
	 * @see org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer#getAddParameters(java.lang.String)
78
	 */
79
	public NewDataStoreParameters getAddParameters(String storeName)
80
			throws DataException {
81
		if (!getStoreName().equals(storeName)) {
82
			// FIXME exception
83
			throw new IllegalArgumentException();
84
		}
85
		return getAddParameters();
86
	}
87

  
88
	/**
89
	 * Return instance of {@link DataServerExplorerProviderServices}
90
	 *
91
	 */
92
	public DataServerExplorerProviderServices getServerExplorerProviderServices() {
93
		return dataServerExplorerProviderServices;
94
	}
95

  
96
	/*
97
	 * (non-Javadoc)
98
	 * 
99
	 * @see
100
	 * org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer#getParameters()
101
	 */
102
	public DataServerExplorerParameters getParameters() {
103
		return dataServerParameters;
104
	}
105

  
106
}
0 107

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/serverexplorer/db/DBServerExplorer.java
1
/* 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
package org.gvsig.fmap.dal.serverexplorer.db;
29

  
30
import org.gvsig.fmap.dal.DataServerExplorer;
31
import org.gvsig.fmap.dal.DataStore;
32
import org.gvsig.fmap.dal.DataStoreParameters;
33
import org.gvsig.fmap.dal.NewDataStoreParameters;
34
import org.gvsig.fmap.dal.exception.CloseException;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.exception.OpenException;
37
import org.gvsig.fmap.dal.feature.FeatureType;
38

  
39
/**
40
 * Base interface of {@link DataServerExplorer} for Data Base type server
41
 *
42
 * @author jmvivo
43
 *
44
 */
45
public interface DBServerExplorer extends DataServerExplorer {
46

  
47
	/**
48
	 * Return a instance of {@link NewDataStoreParameters} to fill
49
	 *
50
	 * @return
51
	 * @throws DataException
52
	 */
53
	public NewDataStoreParameters getAddParameters()
54
			throws DataException;
55

  
56
	/**
57
	 * Return the {@link FeatureType} of the store of <code>dsp</code> store
58
	 *
59
	 * @param dsp
60
	 * @return
61
	 * @throws DataException
62
	 */
63
	public FeatureType getFeatureType(DataStoreParameters dsp)
64
			throws DataException;
65
	/**
66
	 * Open a store defined by <code>dsp</code>
67
	 *
68
	 * @param dsp
69
	 * @return
70
	 * @throws DataException
71
	 */
72
	public DataStore open(DataStoreParameters dsp)
73
			throws DataException;
74

  
75
	/**
76
	 * Open connection to the server
77
	 *
78
	 * @throws OpenException
79
	 */
80
	public void open() throws OpenException;
81

  
82

  
83
	/**
84
	 * Close connection to the server
85
	 *
86
	 * @throws OpenException
87
	 */
88
	public void close() throws CloseException;
89
}
0 90

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/serverexplorer/db/DBServerExplorerParameters.java
1
/* 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
package org.gvsig.fmap.dal.serverexplorer.db;
28

  
29
import org.gvsig.fmap.dal.DataServerExplorerParameters;
30
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
31
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
32
import org.gvsig.fmap.dal.store.db.DBHelper;
33
import org.gvsig.tools.dynobject.DelegatedDynObject;
34

  
35
/**
36
 * Abstract class of {@link DataServerExplorerParameters} for Data Base type
37
 * server
38
 *
39
 * @author jmvivo
40
 *
41
 */
42
public abstract class DBServerExplorerParameters extends AbstractDataParameters
43
		implements DataServerExplorerParameters, DBConnectionParameter {
44

  
45
    public static final String PARAMETERS_DEFINITION_NAME = "DBServerExplorerParameters";
46

  
47
    private DelegatedDynObject parameters;
48

  
49
	public DBServerExplorerParameters(String parametersDefinitionName, String explorerName) {
50
		this.parameters = (DelegatedDynObject) DBHelper.newParameters(parametersDefinitionName);
51
		this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, explorerName);
52
	}
53

  
54
	public String getExplorerName() {
55
		return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
56
	}
57
	
58
	protected DelegatedDynObject getDelegatedDynObject() {
59
		return parameters;
60
	}
61

  
62
	public String getHost() {
63
		return (String) this.getDynValue(HOST_PARAMTER_NAME);
64
	}
65

  
66
	public Integer getPort() {
67
		return (Integer) this.getDynValue(PORT_PARAMTER_NAME);
68
	}
69

  
70
	public String getDBName() {
71
		return (String) this.getDynValue(DBNAME_PARAMTER_NAME);
72
	}
73

  
74
	public String getUser() {
75
		return (String) this.getDynValue(USER_PARAMTER_NAME);
76
	}
77

  
78
	public String getPassword() {
79
		return (String) this.getDynValue(PASSWORD_PARAMTER_NAME);
80
	}
81

  
82
	/**
83
	 * Set <code>host</code> parameter value
84
	 *
85
	 * @param host
86
	 */
87
	public void setHost(String host) {
88
		this.setDynValue(HOST_PARAMTER_NAME, host);
89
	}
90

  
91
	/**
92
	 * Set <code>port/code> parameter value
93
	 *
94
	 * @param port
95
	 */
96
	public void setPort(int port) {
97
		this.setDynValue(PORT_PARAMTER_NAME, new Integer(port));
98
	}
99

  
100
	/**
101
	 * Set <code>port/code> parameter value
102
	 *
103
	 * @param port
104
	 */
105
	public void setPort(Integer port) {
106
		this.setDynValue(PORT_PARAMTER_NAME, port);
107
	}
108

  
109
	/**
110
	 * Set <code>data base name/code> parameter value
111
	 *
112
	 * @param data
113
	 *            base name
114
	 */
115
	public void setDBName(String dbName) {
116
		this.setDynValue(DBNAME_PARAMTER_NAME, dbName);
117
	}
118

  
119
	/**
120
	 * Set <code>user/code> parameter value
121
	 *
122
	 * @param user
123
	 */
124
	public void setUser(String user) {
125
		this.setDynValue(USER_PARAMTER_NAME, user);
126
	}
127

  
128
	/**
129
	 * Set <code>password/code> parameter value
130
	 * 
131
	 * @param password
132
	 */
133
	public void setPassword(String password) {
134
		this.setDynValue(PASSWORD_PARAMTER_NAME, password);
135
	}
136

  
137
}
0 138

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/DALDbLibrary.java
1
/* 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.dal;
32

  
33
import org.gvsig.tools.library.AbstractLibrary;
34
import org.gvsig.tools.library.LibraryException;
35

  
36
/**
37
 * Initialize DAL data base basic support
38
 *
39
 * @author jmvivo
40
 * 
41
 */
42
public class DALDbLibrary extends AbstractLibrary {
43

  
44
    @Override
45
    public void doRegistration() {
46
        registerAsServiceOf(DALLibrary.class);
47
    }
48

  
49
	@Override
50
	protected void doInitialize() throws LibraryException {
51
	}
52

  
53
	@Override
54
	protected void doPostInitialize() throws LibraryException {
55
	}
56
}
0 57

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/store/db/DBStoreLibrary.java
1
/* 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
package org.gvsig.fmap.dal.store.db;
29

  
30
import org.gvsig.fmap.dal.DALLibrary;
31
import org.gvsig.fmap.dal.resource.db.DBResourceLibrary;
32
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters;
33
import org.gvsig.tools.library.AbstractLibrary;
34
import org.gvsig.tools.library.LibraryException;
35

  
36
/**
37
 * Data Base Store Library intialization
38
 * 
39
 *
40
 */
41
public class DBStoreLibrary extends AbstractLibrary {
42
	
43
    @Override
44
    public void doRegistration() {
45
        registerAsServiceOf(DALLibrary.class);
46
        require(DBResourceLibrary.class);
47
    }
48

  
49
	@Override
50
	protected void doInitialize() throws LibraryException {
51
	}
52

  
53
	@Override
54
	protected void doPostInitialize() throws LibraryException {
55
		DBHelper.registerParametersDefinition(
56
				DBStoreParameters.PARAMETERS_DEFINITION_NAME,
57
				DBStoreParameters.class,
58
				"DBParameters.xml"
59
		);
60
		DBHelper.registerParametersDefinition(
61
				DBServerExplorerParameters.PARAMETERS_DEFINITION_NAME, 
62
				DBServerExplorerParameters.class, 
63
				"DBParameters.xml"
64
		);
65
	}
66
	
67
}
0 68

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/store/db/FeatureTypeHelper.java
1
package org.gvsig.fmap.dal.store.db;
2

  
3
import java.util.Iterator;
4

  
5
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
6
import org.gvsig.fmap.dal.feature.FeatureType;
7

  
8
public final class FeatureTypeHelper {
9
	@SuppressWarnings("unchecked")
10
	public static  Iterator<FeatureAttributeDescriptor> iterator(FeatureType type) {
11
		return type.iterator();
12
	}
13
	
14
}
15

  
0 16

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/store/db/DBHelper.java
1
package org.gvsig.fmap.dal.store.db;
2

  
3
import java.io.InputStream;
4

  
5
import org.gvsig.metadata.MetadataLocator;
6
import org.gvsig.metadata.MetadataManager;
7
import org.gvsig.metadata.exceptions.MetadataException;
8
import org.gvsig.tools.ToolsLocator;
9
import org.gvsig.tools.dynobject.DynObject;
10
import org.gvsig.tools.persistence.PersistenceManager;
11

  
12
public final class DBHelper {
13

  
14
	private DBHelper() {
15
		// Do nothing
16
	}
17
	
18
	@SuppressWarnings("unchecked")
19
	public static void registerParametersDefinition(String name, Class theClass, String filename) {
20
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
21
		if (manager.getDefinition(name) == null) {
22
			InputStream resource = theClass.getResourceAsStream(filename);
23
			if( resource==null ) {
24
				throw new IllegalArgumentException("File '"+ filename + "' not found as a resource of '"+theClass.getName()+"'.");
25
			}
26
			manager.addDefinition(
27
					theClass,
28
					name, 
29
					resource,
30
					theClass.getClassLoader(), 
31
					null, 
32
					null
33
			);
34
		}
35
	}
36
	
37
	@SuppressWarnings("unchecked")
38
	public static void registerMetadataDefinition(String name, Class theClass, String filename) throws MetadataException {
39
		MetadataManager manager = MetadataLocator.getMetadataManager();
40
		if( manager.getDefinition(name)==null ) {
41
			InputStream resource = theClass.getResourceAsStream(filename);
42
			if( resource==null ) {
43
				throw new IllegalArgumentException("File '"+ filename + "' not found as a resource of '"+theClass.getName()+"'.");
44
			}
45
			manager.addDefinition(
46
					name, 
47
					theClass.getResourceAsStream(filename),
48
					theClass.getClassLoader()
49
			);
50
		}
51
	}
52

  
53
	public static DynObject newParameters(String name) {
54
    	return ToolsLocator.getDynObjectManager()
55
			.createDynObject(
56
				ToolsLocator.getPersistenceManager().getDefinition(name)
57
			);
58
	}
59
	
60
	public static DynObject newMetadataContainer(String name) {
61
    	return ToolsLocator.getDynObjectManager()
62
			.createDynObject(
63
				MetadataLocator.getMetadataManager().getDefinition(name)
64
			);
65
	}
66

  
67
}
0 68

  
tags/v2_0_0_Build_2047/libraries/libFMap_daldb/src/org/gvsig/fmap/dal/store/db/DBStoreParameters.java
1
/* 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
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.store.db;
29

  
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.dal.DataStoreParameters;
32
import org.gvsig.fmap.dal.feature.Feature;
33
import org.gvsig.fmap.dal.serverexplorer.db.DBConnectionParameter;
34
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
35
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
36
import org.gvsig.fmap.geom.primitive.Envelope;
37
import org.gvsig.tools.dynobject.DelegatedDynObject;
38

  
39
/**
40
 * Abstract Data base Store Parameters
41
 *
42
 * @author jmvivo
43
 *
44
 */
45
public abstract class DBStoreParameters extends AbstractDataParameters
46
		implements
47
		DataStoreParameters, DBConnectionParameter {
48

  
49
	public static final String PARAMETERS_DEFINITION_NAME = "DBStoreParameters";
50

  
51
	/**
52
	 * Parameter name for specify the feature type in the creacion of
53
	 * news stores.
54
	 * 
55
	 * Is defined only in "new" paramaters.
56
	 *
57
	 */
58
	public static final String FEATURETYPE_PARAMTER_NAME = "FeatureType";
59
    
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff