Revision 45507 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
45 45

  
46 46

  
47 47
public class AppendOperation {
48

  
48
    
49 49
    protected Connection connection = null;
50 50
    protected final JDBCHelper helper;
51 51
    protected final TableReference table;
......
56 56

  
57 57
    protected PreparedStatement preparedStatement;
58 58
    protected String insertSQL;
59
    protected int batchCount;
60
    private final int batchSize;
59 61
    
60 62
    public AppendOperation(
61 63
            JDBCHelper helper, 
......
65 67
        this.helper = helper;
66 68
        this.table = table;
67 69
        this.type = type;
70
        this.batchSize = this.helper.getConnectionParameters().getBatchSize();
68 71
    }
69 72
    
70 73
    public void begin() throws DataException {
......
129 132
            if( this.connection == null ) {
130 133
              return; // In test mode ???
131 134
            }
135
            if( this.batchCount > 0 ) {
136
                this.batchCount = 0;
137
                JDBCUtils.executeBatch(this.preparedStatement,this.insertSQL);
138
            }
139

  
132 140
            this.connection.commit();
133 141
            for (String sql : this.getPostSQLs()) {
134 142
              JDBCUtils.execute(this.connection, sql);
......
175 183
      return this.sqlbuilder.getParameters(feature);
176 184
    }
177 185
    
186
    @SuppressWarnings("UseSpecificCatch")
178 187
    public void append(FeatureProvider feature) throws DataException {
179
        int n;
188
        int status[] = null;
180 189
        Disposable paramsDisposer = null;
181 190
        try {
182 191
            paramsDisposer = this.sqlbuilder.setParameters(this.preparedStatement, feature);
183
            n = JDBCUtils.executeUpdate(this.preparedStatement,this.insertSQL);
192
            JDBCUtils.addBatch(this.preparedStatement,this.insertSQL);
193
            if( ++this.batchCount >= this.batchSize ) {
194
                this.batchCount = 0;
195
                status = JDBCUtils.executeBatch(this.preparedStatement,this.insertSQL);
196
            }
184 197
        } catch(Exception ex) {
185 198
            throw new RuntimeException("Can't insert feature.", ex);
186 199
        } finally {
187 200
            DisposeUtils.disposeQuietly(paramsDisposer);
188 201
        }
189
        if( n<1 ) {
190
            throw new RuntimeException("Can't insert feature (n="+n+").");
202
        if( status!=null ) {
203
            for (int n : status) {
204
                if( n<1 ) {
205
                    throw new RuntimeException("Can't insert feature (n="+n+").");
206
                }
207
            }
191 208
        }
192 209
    }
193 210
}

Also available in: Unified diff