Revision 364 trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/operations/PostgreSQLAppendOperation.java

View differences:

PostgreSQLAppendOperation.java
4 4
import org.gvsig.fmap.dal.exception.DataException;
5 5
import org.gvsig.fmap.dal.feature.FeatureType;
6 6
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
7
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecuteSQLException;
8
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCTransactionRollbackException;
9 7
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
10 8
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
11 9
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.AppendOperation;
......
31 29

  
32 30
    @Override
33 31
    public void append(FeatureProvider feature) throws DataException {
32
        int n;
34 33
        try {
35
            this.connection.setAutoCommit(false);
36
            try {
37
                getHelper().setPreparedStatementParameters(preparedStatement, sqlbuilder, type, feature);
38
                int n = JDBCUtils.executeUpdate(this.preparedStatement,this.sql);
39
                if ( n > 0) {
40
                    this.connection.commit();
41
                    return;
42
                }              
43
                this.connection.rollback();
44
            } catch(Exception ex) {
45
                try {
46
                    this.connection.rollback();
47
                } catch (Exception e1) {
48
                    throw new JDBCTransactionRollbackException(e1, ex);
49
                }                
50
                throw new JDBCExecuteSQLException(this.sql,ex);
51
            } 
52
            throw new JDBCExecuteSQLException(this.sql,null);
53

  
54
        } catch (JDBCExecuteSQLException ex) {
55
            throw ex;
56
        } catch (Exception ex) {
57
            throw new JDBCExecuteSQLException(this.sql,ex);
34
            getHelper().setPreparedStatementParameters(preparedStatement, sqlbuilder, type, feature);
35
            n = JDBCUtils.executeUpdate(this.preparedStatement,this.sql);
36
        } catch(Exception ex) {
37
            throw new RuntimeException("Can't insert feature.", ex);
58 38
        }
39
        if( n<1 ) {
40
            throw new RuntimeException("Can't insert feature (n="+n+").");
41
        }
59 42
    }
43
    
60 44
}

Also available in: Unified diff