Revision 41485
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/jdbc/JDBCHelper.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.sql.Connection; |
27 | 27 |
import java.sql.DatabaseMetaData; |
28 |
import java.sql.PreparedStatement; |
|
28 | 29 |
import java.sql.ResultSet; |
29 | 30 |
import java.sql.ResultSetMetaData; |
30 | 31 |
import java.sql.SQLException; |
31 | 32 |
import java.sql.Statement; |
32 |
import java.sql.Time; |
|
33 | 33 |
import java.util.ArrayList; |
34 | 34 |
import java.util.Arrays; |
35 | 35 |
import java.util.Date; |
36 | 36 |
import java.util.List; |
37 |
import java.util.logging.Level; |
|
38 | 37 |
|
39 | 38 |
import org.cresques.cts.IProjection; |
40 | 39 |
import org.gvsig.fmap.dal.DALLocator; |
... | ... | |
65 | 64 |
import org.gvsig.fmap.geom.Geometry; |
66 | 65 |
import org.gvsig.fmap.geom.GeometryLocator; |
67 | 66 |
import org.gvsig.fmap.geom.GeometryManager; |
68 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
|
69 | 67 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
70 | 68 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
71 | 69 |
/* |
... | ... | |
114 | 112 |
|
115 | 113 |
} |
116 | 114 |
|
115 |
public static ResultSet executeQuery(Statement st, String sql) throws SQLException { |
|
116 |
logger.debug("execute SQL: "+sql); |
|
117 |
ResultSet rs = st.executeQuery(sql); |
|
118 |
return rs; |
|
119 |
} |
|
120 |
|
|
121 |
public static void execute(Statement st, String sql) throws SQLException { |
|
122 |
logger.debug("execute SQL: "+sql); |
|
123 |
st.execute(sql); |
|
124 |
} |
|
125 |
|
|
126 |
public static ResultSet executeQuery(PreparedStatement st, String sql) throws SQLException { |
|
127 |
logger.debug("execute SQL: "+sql); |
|
128 |
ResultSet rs = st.executeQuery(); |
|
129 |
return rs; |
|
130 |
} |
|
131 |
|
|
132 |
public static void execute(PreparedStatement st, String sql) throws SQLException { |
|
133 |
logger.debug("execute SQL: "+sql); |
|
134 |
st.execute(); |
|
135 |
} |
|
136 |
|
|
137 |
public static int executeUpdate(PreparedStatement st) throws SQLException { |
|
138 |
return st.executeUpdate(); |
|
139 |
} |
|
140 |
|
|
141 |
|
|
117 | 142 |
protected void initializeResource() throws InitializeException { |
118 | 143 |
ResourceManagerProviderServices manager = (ResourceManagerProviderServices) DALLocator |
119 | 144 |
.getResourceManager(); |
... | ... | |
650 | 675 |
try { |
651 | 676 |
st = conn.createStatement(); |
652 | 677 |
try { |
653 |
rs = st.executeQuery(sql.toString());
|
|
678 |
rs = JDBCHelper.executeQuery(st, sql.toString());
|
|
654 | 679 |
} catch (java.sql.SQLException e) { |
655 | 680 |
throw new JDBCExecuteSQLException(sql.toString(), e); |
656 | 681 |
} |
... | ... | |
671 | 696 |
|
672 | 697 |
} |
673 | 698 |
|
674 |
protected void loadFeatureType(Connection conn,
|
|
675 |
EditableFeatureType featureType, String sql, String[] pks,
|
|
676 |
String defGeomName, String schema, String table)
|
|
677 |
throws DataException {
|
|
699 |
protected void loadFeatureType(Connection conn,
|
|
700 |
EditableFeatureType featureType, String sql, String[] pks,
|
|
701 |
String defGeomName, String schema, String table)
|
|
702 |
throws DataException {
|
|
678 | 703 |
|
679 |
Statement stAux = null;
|
|
680 |
ResultSet rs = null;
|
|
681 |
try {
|
|
704 |
Statement stAux = null;
|
|
705 |
ResultSet rs = null;
|
|
706 |
try {
|
|
682 | 707 |
|
683 |
stAux = conn.createStatement();
|
|
684 |
stAux.setFetchSize(1);
|
|
708 |
stAux = conn.createStatement();
|
|
709 |
stAux.setFetchSize(1);
|
|
685 | 710 |
|
686 |
try {
|
|
687 |
rs = stAux.executeQuery(sql);
|
|
688 |
} catch (SQLException e) {
|
|
689 |
throw new JDBCExecuteSQLException(sql, e);
|
|
690 |
}
|
|
691 |
ResultSetMetaData rsMetadata = rs.getMetaData();
|
|
711 |
try {
|
|
712 |
rs = JDBCHelper.executeQuery(stAux, sql);
|
|
713 |
} catch (SQLException e) {
|
|
714 |
throw new JDBCExecuteSQLException(sql, e);
|
|
715 |
}
|
|
716 |
ResultSetMetaData rsMetadata = rs.getMetaData();
|
|
692 | 717 |
|
693 |
List pksList = null;
|
|
694 |
if (pks != null) {
|
|
695 |
pksList = Arrays.asList(pks);
|
|
718 |
List pksList = null;
|
|
719 |
if (pks != null) {
|
|
720 |
pksList = Arrays.asList(pks);
|
|
696 | 721 |
|
697 |
}
|
|
722 |
}
|
|
698 | 723 |
|
699 |
int i;
|
|
700 |
int geometriesColumns = 0;
|
|
701 |
String lastGeometry = null;
|
|
724 |
int i;
|
|
725 |
int geometriesColumns = 0;
|
|
726 |
String lastGeometry = null;
|
|
702 | 727 |
|
703 |
EditableFeatureAttributeDescriptor attr;
|
|
728 |
EditableFeatureAttributeDescriptor attr;
|
|
704 | 729 |
boolean firstGeometryAttrFound = false; |
705 |
for (i = 1; i <= rsMetadata.getColumnCount(); i++) {
|
|
706 |
attr = getAttributeFromJDBC(featureType, conn, rsMetadata, i);
|
|
707 |
if (pksList != null && pksList.contains(attr.getName())) {
|
|
708 |
attr.setIsPrimaryKey(true);
|
|
709 |
}
|
|
710 |
if (attr.getType() == DataTypes.GEOMETRY) {
|
|
730 |
for (i = 1; i <= rsMetadata.getColumnCount(); i++) {
|
|
731 |
attr = getAttributeFromJDBC(featureType, conn, rsMetadata, i);
|
|
732 |
if (pksList != null && pksList.contains(attr.getName())) {
|
|
733 |
attr.setIsPrimaryKey(true);
|
|
734 |
}
|
|
735 |
if (attr.getType() == DataTypes.GEOMETRY) {
|
|
711 | 736 |
geometriesColumns++; |
712 | 737 |
lastGeometry = attr.getName(); |
713 | 738 |
// Set the default geometry attribute if it is the one |
714 | 739 |
// given as parameter or it is the first one, just in case. |
715 | 740 |
if (!firstGeometryAttrFound |
716 |
|| lastGeometry.equals(defGeomName)) { |
|
741 |
|| lastGeometry.equals(defGeomName)) {
|
|
717 | 742 |
firstGeometryAttrFound = true; |
718 | 743 |
featureType |
719 |
.setDefaultGeometryAttributeName(lastGeometry); |
|
744 |
.setDefaultGeometryAttributeName(lastGeometry);
|
|
720 | 745 |
} |
721 |
}
|
|
746 |
}
|
|
722 | 747 |
|
723 |
}
|
|
748 |
}
|
|
724 | 749 |
|
725 |
if (geometriesColumns > 0) {
|
|
726 |
loadSRS_and_shapeType(conn, rsMetadata, featureType, schema,
|
|
727 |
table);
|
|
728 |
}
|
|
750 |
if (geometriesColumns > 0) {
|
|
751 |
loadSRS_and_shapeType(conn, rsMetadata, featureType, schema,
|
|
752 |
table);
|
|
753 |
}
|
|
729 | 754 |
|
730 |
if (defGeomName == null && geometriesColumns == 1) {
|
|
731 |
featureType.setDefaultGeometryAttributeName(lastGeometry);
|
|
732 |
defGeomName = lastGeometry;
|
|
733 |
}
|
|
755 |
if (defGeomName == null && geometriesColumns == 1) {
|
|
756 |
featureType.setDefaultGeometryAttributeName(lastGeometry);
|
|
757 |
defGeomName = lastGeometry;
|
|
758 |
}
|
|
734 | 759 |
|
735 |
} catch (java.sql.SQLException e) {
|
|
736 |
throw new JDBCSQLException(e); // FIXME exception
|
|
737 |
} finally {
|
|
738 |
try {
|
|
739 |
rs.close();
|
|
740 |
} catch (Exception e) {
|
|
741 |
}
|
|
742 |
try {
|
|
743 |
stAux.close();
|
|
744 |
} catch (Exception e) {
|
|
745 |
}
|
|
760 |
} catch (java.sql.SQLException e) {
|
|
761 |
throw new JDBCSQLException(e); // FIXME exception
|
|
762 |
} finally {
|
|
763 |
try {
|
|
764 |
rs.close();
|
|
765 |
} catch (Exception e) {
|
|
766 |
}
|
|
767 |
try {
|
|
768 |
stAux.close();
|
|
769 |
} catch (Exception e) {
|
|
770 |
}
|
|
746 | 771 |
|
747 |
}
|
|
772 |
}
|
|
748 | 773 |
|
749 |
}
|
|
774 |
}
|
|
750 | 775 |
|
751 | 776 |
/** |
752 | 777 |
* Override if provider has geometry support |
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/jdbc/JDBCServerExplorer.java | ||
---|---|---|
168 | 168 |
|
169 | 169 |
try{ |
170 | 170 |
try{ |
171 |
LOG.debug("execute: "+sqlDrop); |
|
172 |
st.execute(sqlDrop); |
|
171 |
JDBCHelper.execute(st, sqlDrop); |
|
173 | 172 |
} catch (SQLException e) { |
174 | 173 |
throw new JDBCExecuteSQLException(sqlDrop, e); |
175 | 174 |
} |
... | ... | |
520 | 519 |
|
521 | 520 |
try { |
522 | 521 |
sql = sqlCreate; |
523 |
LOG.debug("execute: "+sql); |
|
524 |
st.execute(sql); |
|
522 |
JDBCHelper.execute(st, sql); |
|
525 | 523 |
if (sqlAdditional != null) { |
526 | 524 |
Iterator iter = sqlAdditional.iterator(); |
527 | 525 |
while (iter.hasNext()) { |
528 | 526 |
sql = (String) iter.next(); |
529 |
LOG.debug("execute: "+sql); |
|
530 |
st.execute(sql); |
|
527 |
JDBCHelper.execute(st, sql); |
|
531 | 528 |
} |
532 | 529 |
} |
533 | 530 |
|
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/jdbc/JDBCStoreProviderWriter.java | ||
---|---|---|
153 | 153 |
st.setObject(i + 1, values.get(i)); |
154 | 154 |
} |
155 | 155 |
try { |
156 |
int nAffected =st.executeUpdate();
|
|
156 |
int nAffected =JDBCHelper.executeUpdate(st);
|
|
157 | 157 |
if (nAffected == 0) { |
158 | 158 |
throw new JDBCUpdateWithoutChangesException(sql, values); |
159 | 159 |
} |
... | ... | |
195 | 195 |
st.setObject(i + 1, values.get(i)); |
196 | 196 |
} |
197 | 197 |
try { |
198 |
if (st.executeUpdate() == 0) {
|
|
198 |
if ( JDBCHelper.executeUpdate(st) == 0) {
|
|
199 | 199 |
throw new JDBCUpdateWithoutChangesException(sql, values); |
200 | 200 |
} |
201 | 201 |
} catch (SQLException e) { |
... | ... | |
391 | 391 |
throw new JDBCSQLException(e1); |
392 | 392 |
} |
393 | 393 |
try { |
394 |
st.execute(sql);
|
|
394 |
JDBCHelper.execute(st, sql);
|
|
395 | 395 |
Iterator<String> iter = additionalStatement.iterator(); |
396 | 396 |
while (iter.hasNext()) { |
397 | 397 |
sql = (String) iter.next(); |
398 |
st.execute(sql);
|
|
398 |
JDBCHelper.execute(st, sql);
|
|
399 | 399 |
} |
400 | 400 |
} catch (SQLException e1) { |
401 | 401 |
throw new JDBCExecuteSQLException(sql, e1); |
... | ... | |
430 | 430 |
sql, values }); |
431 | 431 |
} |
432 | 432 |
try { |
433 |
insertSt.execute();
|
|
433 |
JDBCHelper.execute(insertSt, sql);
|
|
434 | 434 |
} catch (SQLException e) { |
435 | 435 |
throw new JDBCExecutePreparedSQLException(sql, values, e); |
436 | 436 |
} |
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/jdbc/JDBCStoreProvider.java | ||
---|---|---|
253 | 253 |
public final int createResultSet(final String sql, final Object[] values, |
254 | 254 |
final int fetchSize) |
255 | 255 |
throws DataException { |
256 |
logger.debug("Creating resultSet with sql: {}", sql); |
|
257 | 256 |
synchronized (this) { |
258 | 257 |
checksResulsets(); |
259 | 258 |
return ((Integer) getResource().execute(new ResourceAction() { |
... | ... | |
642 | 641 |
if (fetchSize > 0) { |
643 | 642 |
st.setFetchSize(fetchSize); |
644 | 643 |
} |
645 |
rs = st.executeQuery();
|
|
644 |
rs = JDBCHelper.executeQuery(st, sql);
|
|
646 | 645 |
if (fetchSize > 0) { |
647 | 646 |
rs.setFetchSize(fetchSize); |
648 | 647 |
} |
Also available in: Unified diff