Statistics
| Revision:

root / trunk / org.gvsig.postgresql / org.gvsig.postgresql.provider / src / main / java / org / gvsig / postgresql / dal / operations / PostgreSQLAppendOperation.java @ 362

History | View | Annotate | Download (2.06 KB)

1

    
2
package org.gvsig.postgresql.dal.operations;
3

    
4
import org.gvsig.fmap.dal.exception.DataException;
5
import org.gvsig.fmap.dal.feature.FeatureType;
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
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
10
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
11
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.AppendOperation;
12
import org.gvsig.postgresql.dal.PostgreSQLHelper;
13

    
14

    
15
public class PostgreSQLAppendOperation extends AppendOperation {
16

    
17
    public PostgreSQLAppendOperation(
18
            JDBCHelper helper, 
19
            String database,
20
            String schema, 
21
            String table, 
22
            FeatureType type
23
        ) {
24
        super(helper, database, schema, table, type);
25
    }
26
    
27
    
28
    private PostgreSQLHelper getHelper() {
29
        return (PostgreSQLHelper) this.helper;
30
    }
31

    
32
    @Override
33
    public void append(FeatureProvider feature) throws DataException {
34
        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);
58
        }
59
    }
60
}