Revision 46315 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/AbstractConnectionOperation.java

View differences:

AbstractConnectionOperation.java
28 28
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
29 29
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCTransactionRollbackException;
30 30
import org.gvsig.fmap.dal.store.jdbc.exception.SQLRuntimeException;
31
import org.gvsig.fmap.dal.store.jdbc2.JDBCConnection;
31 32
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
32 33
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
33 34
import org.slf4j.Logger;
......
40 41

  
41 42
    final protected JDBCHelper helper;
42 43
    
43
    protected Connection conn = null;
44
    protected JDBCConnection conn = null;
44 45

  
45 46
    public AbstractConnectionOperation(JDBCHelper helper) {
46 47
        this.helper = helper;
......
48 49

  
49 50
    @Override
50 51
    public boolean continueTransactionAllowed() {
51
        return false;
52
        return this.helper.getTransaction()!=null;
52 53
    }
53 54

  
54 55
    @Override
......
76 77
        }
77 78
    }
78 79

  
79
    protected Connection getConnection() throws AccessResourceException {
80
    protected JDBCConnection getConnection() throws AccessResourceException {
80 81
        if( this.conn == null ) {
81 82
            this.conn = this.helper.getConnection();
82 83
        }
......
90 91
            try {
91 92
                if( this.helper.allowNestedOperations() ) {
92 93
                    boolean commitOnFinish = true;
93
                    if (!this.getConnection().getAutoCommit()) {
94
                        // Casi seguro que es una operacion anidada, asi que no
95
                        // terminamos la transaccion.
94
                    if (!this.getConnection().isInTransaction()) {
96 95
                        commitOnFinish = false;
97 96
                    } 
98
                    this.getConnection().setAutoCommit(false);
97
                    this.getConnection().begin();
99 98
                    try {
100 99
                        LOGGER.trace("Excuting operation {}.", this.getClass().getSimpleName());
101 100
                        result = perform(this.getConnection());
......
109 108
                    }
110 109
                    if( commitOnFinish ) {
111 110
                        this.getConnection().commit();
112
                        this.getConnection().setAutoCommit(true);
111
                        
113 112
                    }
114 113
                } else {
115
                    if (!this.getConnection().getAutoCommit()) {
116
                        // Casi seguro que es una transaccion anidada, si no
117
                        // esta permitido, petamos.
114
                    if (this.getConnection().isInTransaction()) {
118 115
                        if (!continueTransactionAllowed()) {
119 116
                            throw new SQLException("nested operations not allowed.");
120 117
                        }
121 118
                    }
122
                    this.getConnection().setAutoCommit(false);
119
                    this.getConnection().begin();
123 120
                    try {
124 121
                        LOGGER.trace("Excuting operation {}.", this.getClass().getSimpleName());
125 122
                        result = perform(this.getConnection());
......
164 161
     * @throws Exception
165 162
     */
166 163
    protected void closeConnection(Object result) throws Exception {
167
        helper.closeConnection(this.getConnection());
164
        this.getConnection().close();
168 165
        conn = null;
169 166
    }
170 167
}

Also available in: Unified diff