Revision 11935 branches/v10/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGISWriter.java

View differences:

PostGISWriter.java
9 9

  
10 10
import com.iver.cit.gvsig.fmap.core.FShape;
11 11
import com.iver.cit.gvsig.fmap.core.IFeature;
12
import com.iver.cit.gvsig.fmap.drivers.ConnectionJDBC;
12 13
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
13 14
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
15
import com.iver.cit.gvsig.fmap.drivers.IConnection;
14 16
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
15 17
import com.iver.cit.gvsig.fmap.edition.EditionException;
16 18
import com.iver.cit.gvsig.fmap.edition.IFieldManager;
......
30 32

  
31 33
	private DBLayerDefinition lyrDef;
32 34

  
33
	private Connection conex;
35
	private IConnection conex;
34 36

  
35 37
	private Statement st;
36 38

  
......
38 40

  
39 41
	private PostGIS postGisSQL = new PostGIS();
40 42
	// private double flatness;
41
	
43

  
42 44
	private JdbcFieldManager fieldManager;
43 45

  
44 46
	/**
45 47
	 * Useful to create a layer from scratch Call setFile before using this
46 48
	 * function
47
	 * 
49
	 *
48 50
	 * @param lyrDef
49 51
	 * @throws IOException
50 52
	 * @throws DriverException
......
55 57
		conex = lyrDef.getConnection();
56 58

  
57 59
		try {
58
			st = conex.createStatement();
60
			st = ((ConnectionJDBC)conex).getConnection().createStatement();
59 61

  
60 62
			if (bCreateTable) {
61 63
				try {
......
85 87
				 * VALUES (2,GeometryFromText('LINESTRING(189141 244158,189265
86 88
				 * 244817)',-1),'Geordie Rd'); COMMIT;
87 89
				 */
88
				conex.commit();
90
				((ConnectionJDBC)conex).getConnection().commit();
89 91
			}
90
			conex.setAutoCommit(false);
91
			fieldManager = new JdbcFieldManager(conex, lyrDef.getTableName());
92
			((ConnectionJDBC)conex).getConnection().setAutoCommit(false);
93
			fieldManager = new JdbcFieldManager(((ConnectionJDBC)conex).getConnection(), lyrDef.getTableName());
92 94

  
93 95
		} catch (SQLException e) {
94 96
			e.printStackTrace();
......
105 107
        // to its charset
106 108
        // Note: we have to translate to UTF-8 because
107 109
        // the server cannot manage UTF-16
108
		
110

  
109 111
        ResultSet rsAux;
110 112
		try {
111
			conex.rollback();			
113
			((ConnectionJDBC)conex).getConnection().rollback();
112 114
			alterTable();
113 115

  
114 116
			rsAux = st.executeQuery("SHOW server_encoding;");
......
176 178

  
177 179
	public void postProcess() throws EditionException {
178 180
		try {
179
			conex.setAutoCommit(true);
181
			((ConnectionJDBC)conex).getConnection().setAutoCommit(true);
180 182
		} catch (SQLException e) {
181 183
			e.printStackTrace();
182 184
			throw new EditionException(e);
......
222 224
		case Types.VARCHAR:
223 225
		case Types.CHAR:
224 226
		case Types.LONGVARCHAR:
225
			return true; 
227
			return true;
226 228

  
227 229
		}
228 230

  
......
250 252

  
251 253
	public void addField(FieldDescription fieldDesc) {
252 254
		fieldManager.addField(fieldDesc);
253
		
255

  
254 256
	}
255 257

  
256 258
	public FieldDescription removeField(String fieldName) {
257 259
		return fieldManager.removeField(fieldName);
258
		
260

  
259 261
	}
260 262

  
261 263
	public void renameField(String antName, String newName) {
262 264
		fieldManager.renameField(antName, newName);
263
		
265

  
264 266
	}
265 267

  
266 268
	public boolean alterTable() throws EditionException {
......
278 280
	public boolean canSaveEdits() {
279 281
		// TODO: Revisar los permisos de la tabla en cuesti?n.
280 282
		try {
281
			return !conex.isReadOnly();
283
			return !((ConnectionJDBC)conex).getConnection().isReadOnly();
282 284
		} catch (SQLException e) {
283 285
			// TODO Auto-generated catch block
284 286
			e.printStackTrace();

Also available in: Unified diff