Revision 45437
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 | ||
---|---|---|
133 | 133 |
this.getConnection().commit(); |
134 | 134 |
} |
135 | 135 |
} finally { |
136 |
helper.closeConnection(this.getConnection()); |
|
137 |
conn = null; |
|
136 |
closeConnection(result); |
|
138 | 137 |
} |
139 | 138 |
} else { |
140 | 139 |
try { |
... | ... | |
143 | 142 |
} catch (Exception ex) { |
144 | 143 |
throw new RuntimeException("Can't perform operation '"+this.getClass().getSimpleName()+"'.",ex); |
145 | 144 |
} finally { |
146 |
helper.closeConnection(this.getConnection()); |
|
147 |
conn = null; |
|
145 |
closeConnection(result); |
|
148 | 146 |
} |
149 | 147 |
} |
150 | 148 |
return result; |
151 | 149 |
} |
150 |
|
|
151 |
/** |
|
152 |
* |
|
153 |
* @param result the result of the operation recently executed |
|
154 |
* @throws Exception |
|
155 |
*/ |
|
156 |
protected void closeConnection(Object result) throws Exception { |
|
157 |
helper.closeConnection(this.getConnection()); |
|
158 |
conn = null; |
|
159 |
} |
|
152 | 160 |
} |
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/ExecuteOperation.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.sql.Connection; |
27 | 27 |
import java.sql.ResultSet; |
28 |
import java.sql.SQLException; |
|
28 | 29 |
import java.sql.Statement; |
29 |
import org.apache.commons.lang3.StringUtils; |
|
30 | 30 |
import org.gvsig.fmap.dal.exception.DataException; |
31 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCTransactionRollbackException; |
|
31 | 32 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
32 | 33 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
34 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.AbstractConnectionOperation.LOGGER; |
|
33 | 35 |
|
34 | 36 |
public class ExecuteOperation extends AbstractConnectionOperation { |
35 | 37 |
|
... | ... | |
50 | 52 |
|
51 | 53 |
public Object execute(String sql) { |
52 | 54 |
Statement st = null; |
55 |
ResultSet rs = null; |
|
53 | 56 |
try { |
54 | 57 |
st = this.getConnection().createStatement(); |
55 |
ResultSet rs = null; |
|
56 | 58 |
String mode = "select"; |
57 | 59 |
try { |
58 | 60 |
mode = sql.trim().substring(0, sql.trim().indexOf(' ')).toLowerCase(); |
... | ... | |
71 | 73 |
JDBCUtils.execute(st, sql); |
72 | 74 |
break; |
73 | 75 |
} |
74 |
if(rs != null) { |
|
75 |
if(rs.next()){ |
|
76 |
if(rs.getMetaData().getColumnCount() == 1 && rs.isFirst() && rs.isLast()) { |
|
77 |
Object res = rs.getObject(1); |
|
78 |
rs.close(); |
|
79 |
return res; |
|
80 |
} |
|
81 |
return rs; |
|
82 |
} |
|
83 |
rs.close(); |
|
76 |
if(rs == null) { |
|
77 |
JDBCUtils.closeQuietly(st); |
|
78 |
return null; |
|
84 | 79 |
} |
85 |
return null; |
|
80 |
if(rs.getMetaData().getColumnCount() > 0) { |
|
81 |
return rs; |
|
82 |
} |
|
83 |
if(!rs.next()){ |
|
84 |
rs.close(); |
|
85 |
JDBCUtils.closeQuietly(st); |
|
86 |
return null; |
|
87 |
} |
|
88 |
if(rs.isFirst() && rs.isLast()) { |
|
89 |
Object res = rs.getObject(1); |
|
90 |
rs.close(); |
|
91 |
JDBCUtils.closeQuietly(st); |
|
92 |
return res; |
|
93 |
} |
|
94 |
rs.first(); |
|
95 |
return rs; |
|
86 | 96 |
} catch (Exception ex) { |
87 |
throw new RuntimeException("Can't execute query ["+sql+"].",ex); |
|
88 |
|
|
89 |
} finally { |
|
97 |
JDBCUtils.closeQuietly(rs); |
|
90 | 98 |
JDBCUtils.closeQuietly(st); |
99 |
throw new RuntimeException("Can't execute query ["+sql+"].",ex); |
|
91 | 100 |
} |
92 | 101 |
} |
93 | 102 |
|
94 |
// |
|
95 |
// |
|
96 |
// public void execute( |
|
97 |
// Connection conn, |
|
98 |
// String sql |
|
99 |
// ) { |
|
100 |
// Statement st = null; |
|
101 |
// try { |
|
102 |
// st = conn.createStatement(); |
|
103 |
// JDBCUtils.execute(st, sql); |
|
104 |
// } catch (SQLException ex) { |
|
105 |
// throw new RuntimeException("Can't execute query ["+sql+"].",ex); |
|
106 |
// |
|
107 |
// } finally { |
|
108 |
// JDBCUtils.closeQuietly(st); |
|
109 |
// } |
|
110 |
// |
|
111 |
// } |
|
103 |
protected void closeConnection(Object result) throws Exception { |
|
104 |
if (!(result instanceof ResultSet)) { |
|
105 |
helper.closeConnection(this.getConnection()); |
|
106 |
conn = null; |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
|
|
112 | 111 |
} |
trunk/org.gvsig.desktop/pom.xml | ||
---|---|---|
2740 | 2740 |
|
2741 | 2741 |
<jython.artifactId>jython-standalone</jython.artifactId> |
2742 | 2742 |
<!-- External project versions --> |
2743 |
<gvsig.tools.version>3.0.261</gvsig.tools.version>
|
|
2743 |
<gvsig.tools.version>3.0.262-SNAPSHOT</gvsig.tools.version>
|
|
2744 | 2744 |
<gvsig.proj.version>1.0.30</gvsig.proj.version> |
2745 | 2745 |
<gvsig.projection.api.version>2.0.54</gvsig.projection.api.version> |
2746 | 2746 |
</properties> |
Also available in: Unified diff