Revision 34767 branches/gvSIG_1.11.0_Mejoras_gvSIG-EIEL/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/db/utils/ConnectionWithParams.java

View differences:

ConnectionWithParams.java
4 4

  
5 5
import org.apache.log4j.Logger;
6 6

  
7
import com.hardcode.driverManager.Driver;
8
import com.hardcode.gdbms.engine.data.driver.AlphanumericDBDriver;
7 9
import com.iver.cit.gvsig.fmap.drivers.ConnectionFactory;
8 10
import com.iver.cit.gvsig.fmap.drivers.DBException;
9 11
import com.iver.cit.gvsig.fmap.drivers.IConnection;
12
import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver;
13
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
10 14

  
11 15
/**
12 16
 * Utility class to keep the connection parameters. It is used as a item in the
......
33 37
    private String port;
34 38
    private String db;
35 39

  
36
    private String schema;
40
    private String schema = "";
37 41

  
38 42
    private boolean isNull = false;
39 43

  
......
92 96
		}
93 97
	}
94 98

  
99
	
100
	/**
101
	 * Class Constructor.
102
	 *
103
	 * @param _conn_str connection string
104
	 * @param _c connection object
105
	 * @param _drvName driver name
106
	 * @param _user user name
107
	 * @param _pw password
108
	 * @param _name connection name (freely chosen by user)
109
	 * @param _host host's url
110
	 * @param _port port number as a string
111
	 * @param _db database name
112
	 * @param _schema schema name or null if not used
113
	 * @param _isConn whether the connection is open or not
114
	 */
115
	public ConnectionWithParams(
116
			String _conn_str,
117
			IConnection _c,
118
			String _drvName,
119
			String _user,
120
			String _pw,
121
			String _name,
122
			String _host,
123
			String _port,
124
			String _db,
125
			String _schema,
126
			boolean _isConn) {
127

  
128
		connectionStr = _conn_str;
129
		connected = _isConn;
130
		conn = _c;
131
		drvName = _drvName;
132
		user = _user;
133
		pw = _pw;
134
		name = _name;
135

  
136
		host = _host;
137
		port = _port;
138
		db = _db;
139
		schema = _schema;
140

  
141
		if (!connected) {
142
			pw = null;
143
			conn = null;
144
		}
145
	}
146
	
147
	
148
	
95 149
	public IConnection getConnection() {
96 150
		return conn;
97 151
	}
......
141 195
	public void connect(String _pw) throws DBException {
142 196

  
143 197
		try {
144
			conn = ConnectionFactory.createConnection(connectionStr, user, _pw);//DriverManager.getConnection(connectionStr, user, _pw);
145
		} catch (DBException e) {
198
			Driver _drv = LayerFactory.getDM().getDriver(drvName);
199
			
200
			if (_drv instanceof AlphanumericDBDriver) {
201
				conn = SingleDBConnectionManager.getConnectionForDriver(
202
						_drv, null, this.host, this.port, this.db, this.user, _pw);
203
			} else {
204
				if (_drv instanceof IVectorialDatabaseDriver) {
205
					conn = ConnectionFactory.createConnection(this.connectionStr, this.user, _pw);
206
				} else {
207
					logger.error("CONNECT: Unexpected driver type: " + _drv.getClass().getName());
208
					throw new DBException(new Exception("CONNECT: Unexpected driver type: " + _drv.getClass().getName()));
209
				}
210
			}
211
		} catch (Exception e) {
146 212

  
147 213
			pw = null;
148 214
			conn = null;
149 215
			connected = false;
150
			e.printStackTrace();
216
			// e.printStackTrace();
151 217
			throw new DBException(e);
152 218
		}
153 219

  
......
224 290
		return schema;
225 291
	}
226 292

  
227
	public void setSchema(String schema) {
228
		this.schema = schema;
293
	public void setSchema(String sch) {
294
		schema = sch;
229 295
	}
230 296

  
231 297
}
298

  
299
// [eiel-gestion-conexiones]

Also available in: Unified diff