Revision 44678 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/AppendOperation.java

View differences:

AppendOperation.java
4 4
import java.sql.Connection;
5 5
import java.sql.PreparedStatement;
6 6
import java.sql.SQLException;
7
import java.util.Collection;
8
import java.util.Collections;
9
import java.util.List;
7 10
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
8 11
import org.gvsig.fmap.dal.DataTypes;
9 12
import org.gvsig.fmap.dal.exception.DataException;
13
import org.gvsig.fmap.dal.feature.Feature;
10 14
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
11 15
import org.gvsig.fmap.dal.feature.FeatureType;
12 16
import org.gvsig.fmap.dal.feature.exception.AlreadyEditingException;
......
31 35
    protected GeometryExpressionBuilder expbuilder;
32 36

  
33 37
    protected PreparedStatement preparedStatement;
34
    protected String sql;
38
    protected String insertSQL;
35 39
    
36 40
    public AppendOperation(
37 41
            JDBCHelper helper, 
......
76 80
                }
77 81
            }
78 82

  
79
            this.sql = this.sqlbuilder.insert().toString();
80
            this.preparedStatement = this.connection.prepareStatement(sql);
81
            this.connection.setAutoCommit(false);
83
            this.insertSQL = this.sqlbuilder.insert().toString();
84
            if( this.connection != null ) { // Not in test mode ???
85
              this.preparedStatement = this.connection.prepareStatement(insertSQL);
86
              this.connection.setAutoCommit(false);
87
              for (String sql : this.getPreviousSQLs()) {
88
                JDBCUtils.execute(this.connection, sql);
89
              }
90
            }
82 91
            
83 92
        } catch (SQLException ex) {
84 93
            throw new JDBCPreparingSQLException(this.sqlbuilder.toString(),ex);
......
92 101
        this.connection = null;
93 102
        this.preparedStatement = null;
94 103
        this.sqlbuilder = null;
95
        this.sql = null;        
104
        this.insertSQL = null;        
96 105
    }
97 106
    
98 107
    public void end() {
99 108
        try {
109
            if( this.connection == null ) {
110
              return; // In test mode ???
111
            }
100 112
            this.connection.commit();
113
            for (String sql : this.getPostSQLs()) {
114
              JDBCUtils.execute(this.connection, sql);
115
            }
101 116
        } catch (SQLException ex) {
102 117
            try {
103 118
                this.connection.rollback();
......
111 126
    
112 127
    public void abort() {        
113 128
        try {
129
            if( this.connection == null ) {
130
              return; // In test mode ???
131
            }
114 132
            this.connection.rollback();
133
            for (String sql : this.getPostSQLs()) {
134
              JDBCUtils.execute(this.connection, sql);
135
            }
115 136
        } catch (SQLException ex) {
137
        } finally {
138
          clean();
116 139
        }
117
        clean();
118 140
    }
141

  
142
    public String getSQL() { // For test
143
      return this.insertSQL;
144
    }
119 145
    
146
    public List<String> getPreviousSQLs() {
147
      return Collections.EMPTY_LIST;
148
    }
149
    
150
    public List<String> getPostSQLs() {
151
      return Collections.EMPTY_LIST;
152
    }    
153
    
154
    public List<Object> getSQLParameters(FeatureProvider feature) {
155
      return this.sqlbuilder.getParameters(feature);
156
    }
157
    
120 158
    public void append(FeatureProvider feature) throws DataException {
121 159
        int n;
122 160
        Disposable paramsDisposer = null;
123 161
        try {
124 162
            paramsDisposer = this.sqlbuilder.setParameters(this.preparedStatement, feature);
125
            n = JDBCUtils.executeUpdate(this.preparedStatement,this.sql);
163
            n = JDBCUtils.executeUpdate(this.preparedStatement,this.insertSQL);
126 164
        } catch(Exception ex) {
127 165
            throw new RuntimeException("Can't insert feature.", ex);
128 166
        } finally {

Also available in: Unified diff