Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libDataSourceDBBaseDrivers / src / org / gvsig / data / datastores / vectorial / db / jdbc / JDBCFeaturesWriter.java @ 20376

History | View | Annotate | Download (1.58 KB)

1
package org.gvsig.data.datastores.vectorial.db.jdbc;
2

    
3
import java.sql.Connection;
4
import java.sql.SQLException;
5
import java.sql.Statement;
6

    
7
import org.gvsig.data.datastores.vectorial.ISelectiveWriter;
8
import org.gvsig.data.datastores.vectorial.db.DBFeatureType;
9
import org.gvsig.data.datastores.vectorial.db.jdbc.h2.H2StoreParameters;
10
import org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostgresqlStore;
11
import org.gvsig.data.exception.OpenException;
12
import org.gvsig.data.exception.ReadException;
13
import org.gvsig.data.exception.WriteException;
14
import org.gvsig.data.vectorial.IFeatureStore;
15

    
16
public abstract class JDBCFeaturesWriter implements ISelectiveWriter{
17

    
18
        protected Connection conex;
19
        protected JDBCStore store;
20
        protected boolean previousAutocommit;
21

    
22

    
23
        public void init(IFeatureStore store) {
24
                this.store = (JDBCStore)store;
25
                this.conex = this.store.getConnection();
26
        }
27

    
28

    
29
        public void preProcess() throws WriteException, ReadException {
30
                try {
31
                        previousAutocommit = conex.getAutoCommit();
32
                        conex.setAutoCommit(false);
33
                } catch (SQLException e) {
34
                        throw new WriteException(this.store.getName(),e);
35
                }
36

    
37
        }
38

    
39
        public void postProcess() throws OpenException, WriteException {
40
                try {
41
                        conex.commit();
42
                        if (previousAutocommit){
43
                                conex.setAutoCommit(true);
44
                        }
45
                } catch (SQLException e) {
46
                        throw new WriteException(this.store.getName(),e);
47
                }
48
        }
49

    
50
        public void cancelProcess() throws WriteException {
51
                try {
52
                        conex.rollback();
53
                        if (previousAutocommit){
54
                                conex.setAutoCommit(true);
55
                        }
56
                } catch (SQLException e) {
57
                        throw new WriteException(this.store.getName(),e);
58
                }
59
        }
60

    
61
}