Revision 44191 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
AbstractConnectionOperation.java | ||
---|---|---|
9 | 9 |
import org.slf4j.Logger; |
10 | 10 |
import org.slf4j.LoggerFactory; |
11 | 11 |
|
12 |
@SuppressWarnings("UseSpecificCatch") |
|
12 | 13 |
public abstract class AbstractConnectionOperation implements ConnectionOperation { |
13 | 14 |
|
14 | 15 |
final static protected Logger LOGGER = LoggerFactory.getLogger(AbstractConnectionOperation.class); |
... | ... | |
58 | 59 |
LOGGER.debug("preparing execution of "+this.getClass().getSimpleName()+"."); |
59 | 60 |
if( needTransaction() ) { |
60 | 61 |
try { |
61 |
// XXX OJO esta condicion NO ES FIABLE |
|
62 |
if (!this.getConnection().getAutoCommit()) { |
|
63 |
if (!continueTransactionAllowed()) { |
|
64 |
throw new SQLException("nested operations not allowed."); |
|
62 |
if( this.helper.allowNestedOperations() ) { |
|
63 |
boolean commitOnFinish = true; |
|
64 |
if (!this.getConnection().getAutoCommit()) { |
|
65 |
// Casi seguro que es una operacion anidada, asi que no |
|
66 |
// terminamos la transaccion. |
|
67 |
commitOnFinish = false; |
|
68 |
} |
|
69 |
this.getConnection().setAutoCommit(false); |
|
70 |
try { |
|
71 |
LOGGER.debug("Excuting operation {}.", this.getClass().getSimpleName()); |
|
72 |
result = perform(this.getConnection()); |
|
73 |
} catch (Exception ex) { |
|
74 |
try { |
|
75 |
this.getConnection().rollback(); |
|
76 |
} catch (Exception e1) { |
|
77 |
throw new JDBCTransactionRollbackException(e1, ex); |
|
78 |
} |
|
79 |
throw new RuntimeException("Can't perform operation '"+this.getClass().getSimpleName()+"'.",ex); |
|
65 | 80 |
} |
66 |
} |
|
67 |
this.getConnection().setAutoCommit(false); |
|
68 |
try { |
|
69 |
LOGGER.debug("Excuting operation {}.", this.getClass().getSimpleName()); |
|
70 |
result = perform(this.getConnection()); |
|
71 |
} catch (Exception ex) { |
|
81 |
if( commitOnFinish ) { |
|
82 |
this.getConnection().commit(); |
|
83 |
this.getConnection().setAutoCommit(true); |
|
84 |
} |
|
85 |
} else { |
|
86 |
if (!this.getConnection().getAutoCommit()) { |
|
87 |
// Casi seguro que es una transaccion anidada, si no |
|
88 |
// esta permitido, petamos. |
|
89 |
if (!continueTransactionAllowed()) { |
|
90 |
throw new SQLException("nested operations not allowed."); |
|
91 |
} |
|
92 |
} |
|
93 |
this.getConnection().setAutoCommit(false); |
|
72 | 94 |
try { |
73 |
this.getConnection().rollback(); |
|
74 |
} catch (Exception e1) { |
|
75 |
throw new JDBCTransactionRollbackException(e1, ex); |
|
95 |
LOGGER.debug("Excuting operation {}.", this.getClass().getSimpleName()); |
|
96 |
result = perform(this.getConnection()); |
|
97 |
} catch (Exception ex) { |
|
98 |
try { |
|
99 |
this.getConnection().rollback(); |
|
100 |
} catch (Exception e1) { |
|
101 |
throw new JDBCTransactionRollbackException(e1, ex); |
|
102 |
} |
|
103 |
throw new RuntimeException("Can't perform operation '"+this.getClass().getSimpleName()+"'.",ex); |
|
76 | 104 |
} |
77 |
throw new RuntimeException("Can't perform operation '"+this.getClass().getSimpleName()+"'.",ex);
|
|
105 |
this.getConnection().commit();
|
|
78 | 106 |
} |
79 |
this.getConnection().commit(); |
|
80 | 107 |
} finally { |
81 | 108 |
helper.closeConnection(this.getConnection()); |
82 | 109 |
conn = null; |
Also available in: Unified diff