Revision 45008
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.lib/org.gvsig.exportto.lib.impl/src/main/java/org/gvsig/export/impl/service/DefaultExportAttributes.java | ||
---|---|---|
7 | 7 |
import org.apache.commons.lang3.StringUtils; |
8 | 8 |
import org.gvsig.export.ExportAttributes; |
9 | 9 |
import org.gvsig.fmap.dal.DALLocator; |
10 |
import org.gvsig.fmap.dal.DataTypes; |
|
10 | 11 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
11 | 12 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
12 | 13 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
... | ... | |
14 | 15 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
15 | 16 |
import org.gvsig.fmap.dal.feature.FeatureType; |
16 | 17 |
import org.gvsig.tools.ToolsLocator; |
17 |
import org.gvsig.tools.dataTypes.DataTypes;
|
|
18 |
import org.gvsig.tools.dataTypes.DataType; |
|
18 | 19 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
19 | 20 |
import org.gvsig.tools.dynobject.DynStruct; |
20 | 21 |
import org.gvsig.tools.namestranslator.NamesTranslator; |
... | ... | |
47 | 48 |
exportAttribute.setNewType(fad.getDataType().getType()); |
48 | 49 |
exportAttribute.setSize(fad.getSize()); |
49 | 50 |
if (query == null || (query != null && query.getGroupByColumns().isEmpty())) { |
50 |
exportAttribute.setExported(isShowableDataType(fad.getDataType().getType()));
|
|
51 |
exportAttribute.setExported(isShowableDataType(fad.getDataType())); |
|
51 | 52 |
} else { |
52 | 53 |
if (query.getAggregate(fad.getName()) != null || query.getGroupByColumns().contains(fad.getName())) { |
53 |
exportAttribute.setExported(isShowableDataType(fad.getDataType().getType()));
|
|
54 |
exportAttribute.setExported(isShowableDataType(fad.getDataType())); |
|
54 | 55 |
} else { |
55 | 56 |
exportAttribute.setExported(false); |
56 | 57 |
} |
... | ... | |
65 | 66 |
this.getNamesTranslator().addSource(fad.getName()); |
66 | 67 |
exportAttribute.setNewType(fad.getDataType().getType()); |
67 | 68 |
exportAttribute.setSize(fad.getSize()); |
68 |
exportAttribute.setExported(isShowableDataType(fad.getDataType().getType()));
|
|
69 |
exportAttribute.setExported(isShowableDataType(fad.getDataType())); |
|
69 | 70 |
attrs.add(exportAttribute); |
70 | 71 |
} |
71 | 72 |
} |
... | ... | |
73 | 74 |
|
74 | 75 |
} |
75 | 76 |
|
76 |
protected boolean isShowableDataType(int dataType) {
|
|
77 |
DataTypesManager dataTypemanager = ToolsLocator.getDataTypesManager();
|
|
78 |
if (dataTypemanager.isContainer(dataType)
|
|
79 |
|| dataTypemanager.isObject(dataType)
|
|
80 |
|| dataType == DataTypes.ARRAY) {
|
|
77 |
protected boolean isShowableDataType(DataType dataType) {
|
|
78 |
if ( dataType.getType() != DataTypes.GEOMETRY && (
|
|
79 |
dataType.isContainer()
|
|
80 |
|| dataType.isObject()
|
|
81 |
|| dataType.getType() == DataTypes.ARRAY)) {
|
|
81 | 82 |
return false; |
82 | 83 |
|
83 | 84 |
} else { |
84 | 85 |
return true; |
85 | 86 |
} |
86 | 87 |
} |
88 |
|
|
87 | 89 |
|
88 | 90 |
@Override |
89 | 91 |
public void setNamesTranslator(NamesTranslator namesTranslator) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/SQLBuilder.java | ||
---|---|---|
9 | 9 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
10 | 10 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType; |
11 | 11 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
12 |
import org.gvsig.fmap.geom.Geometry; |
|
12 | 13 |
|
13 | 14 |
public interface SQLBuilder { |
14 | 15 |
|
... | ... | |
142 | 143 |
public String getAlias(); |
143 | 144 |
|
144 | 145 |
public String getValue(); |
146 |
|
|
147 |
public boolean isGeometry(); |
|
148 |
|
|
149 |
public TableNameBuilder getTable(); |
|
145 | 150 |
} |
146 | 151 |
|
147 | 152 |
public interface InsertColumnBuilder extends StatementPart { |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/feature/FeatureStoreProviderFactory.java | ||
---|---|---|
104 | 104 |
public Function<String,Integer> allowFunction(); |
105 | 105 |
|
106 | 106 |
public int allowGroupBy(); |
107 |
|
|
108 |
public boolean allowSpatialIndexSupport(); |
|
107 | 109 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/AbstractFeatureStoreProviderFactory.java | ||
---|---|---|
123 | 123 |
public int allowGroupBy() { |
124 | 124 |
return UNKNOWN; |
125 | 125 |
} |
126 |
|
|
127 |
@Override |
|
128 |
public boolean allowSpatialIndexSupport() { |
|
129 |
return false; |
|
130 |
} |
|
126 | 131 |
|
127 | 132 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.spi/src/main/java/org/gvsig/fmap/dal/feature/spi/SQLBuilderBase.java | ||
---|---|---|
13 | 13 |
import org.apache.commons.lang3.tuple.ImmutablePair; |
14 | 14 |
import org.apache.commons.lang3.tuple.Pair; |
15 | 15 |
import org.cresques.cts.IProjection; |
16 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
17 | 16 |
import org.gvsig.expressionevaluator.ExpressionBuilder.AbstractValue; |
18 | 17 |
import org.gvsig.expressionevaluator.ExpressionBuilder.ClassVisitorFilter; |
19 | 18 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_CONSTANT; |
... | ... | |
815 | 814 |
} |
816 | 815 |
return builder.toString(); |
817 | 816 |
} |
817 |
public boolean isGeometry() { |
|
818 |
return this.asGeometry; |
|
819 |
} |
|
820 |
|
|
821 |
public TableNameBuilder getTable() { |
|
822 |
return this.table; |
|
823 |
} |
|
818 | 824 |
} |
819 | 825 |
|
820 | 826 |
public class OrderByBuilderBase |
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/JDBCHelperBase.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.store.jdbc2.spi; |
2 | 2 |
|
3 | 3 |
import java.sql.Blob; |
4 |
import java.sql.Clob; |
|
4 | 5 |
import org.gvsig.fmap.dal.store.jdbc2.impl.ResulSetControlerBase; |
5 | 6 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase; |
6 | 7 |
import java.sql.Connection; |
7 | 8 |
import java.sql.ResultSet; |
8 | 9 |
import java.util.ArrayList; |
9 | 10 |
import java.util.List; |
11 |
import org.apache.commons.io.IOUtils; |
|
10 | 12 |
import org.apache.commons.lang3.ArrayUtils; |
11 | 13 |
import org.apache.commons.lang3.StringUtils; |
12 | 14 |
import org.apache.commons.lang3.mutable.MutableBoolean; |
... | ... | |
19 | 21 |
import org.gvsig.expressionevaluator.SymbolTable; |
20 | 22 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_EXISTS; |
21 | 23 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_FOREING_VALUE; |
22 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_SELECT; |
|
23 | 24 |
import org.gvsig.fmap.dal.DataTypes; |
24 | 25 |
import org.gvsig.fmap.dal.SQLBuilder; |
25 | 26 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
430 | 431 |
Blob blob = (Blob) value; |
431 | 432 |
value = blob.getBytes(0, (int) blob.length()); |
432 | 433 |
blob.free(); |
433 |
} |
|
434 |
} else if(value instanceof Clob) { |
|
435 |
Clob clob = (Clob) value; |
|
436 |
value = new String(IOUtils.toCharArray(clob.getCharacterStream())); |
|
437 |
clob.free(); |
|
438 |
} |
|
434 | 439 |
} |
435 | 440 |
feature.set(column.getIndex(), value); |
436 | 441 |
} |
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/AppendOperation.java | ||
---|---|---|
4 | 4 |
import java.sql.Connection; |
5 | 5 |
import java.sql.PreparedStatement; |
6 | 6 |
import java.sql.SQLException; |
7 |
import java.util.Collection; |
|
8 | 7 |
import java.util.Collections; |
9 | 8 |
import java.util.List; |
10 | 9 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
11 | 10 |
import org.gvsig.fmap.dal.DataTypes; |
12 | 11 |
import org.gvsig.fmap.dal.exception.DataException; |
13 |
import org.gvsig.fmap.dal.feature.Feature; |
|
14 | 12 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
15 | 13 |
import org.gvsig.fmap.dal.feature.FeatureType; |
16 | 14 |
import org.gvsig.fmap.dal.feature.exception.AlreadyEditingException; |
... | ... | |
68 | 66 |
continue; |
69 | 67 |
} |
70 | 68 |
if (attr.getType() == DataTypes.GEOMETRY) { |
71 |
this.sqlbuilder.insert().column().name(attr.getName()).with_value( |
|
72 |
expbuilder.parameter(attr.getName()).as_geometry_variable().srs( |
|
73 |
expbuilder.parameter().value(attr.getSRS()) |
|
74 |
) |
|
75 |
); |
|
76 |
} else { |
|
77 |
this.sqlbuilder.insert().column().name(attr.getName()).with_value( |
|
69 |
this.sqlbuilder.insert().column().name(attr.getName()).with_value(
|
|
70 |
expbuilder.parameter(attr.getName()).as_geometry_variable().srs(
|
|
71 |
expbuilder.parameter().value(attr.getSRS())
|
|
72 |
)
|
|
73 |
);
|
|
74 |
} else {
|
|
75 |
this.sqlbuilder.insert().column().name(attr.getName()).with_value(
|
|
78 | 76 |
expbuilder.parameter(attr.getName()).as_variable() |
79 | 77 |
); |
80 | 78 |
} |
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/CalculateEnvelopeOfColumnOperation.java | ||
---|---|---|
4 | 4 |
import java.sql.ResultSet; |
5 | 5 |
import java.sql.SQLException; |
6 | 6 |
import java.sql.Statement; |
7 |
import java.util.List; |
|
8 | 7 |
import org.apache.commons.lang3.StringUtils; |
9 | 8 |
import org.cresques.cts.IProjection; |
10 | 9 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Variable; |
... | ... | |
18 | 17 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
19 | 18 |
import static org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase.PROP_TABLE; |
20 | 19 |
import org.gvsig.fmap.geom.Geometry; |
20 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
21 | 21 |
import org.gvsig.fmap.geom.primitive.Envelope; |
22 | 22 |
|
23 | 23 |
public class CalculateEnvelopeOfColumnOperation extends AbstractConnectionOperation { |
... | ... | |
54 | 54 |
} |
55 | 55 |
|
56 | 56 |
public String getSQL() { |
57 |
if (this.helper.hasSpatialFunctions()) { |
|
58 |
return getSQLWithAggregate(); |
|
59 |
} else { |
|
60 |
return getSQLWihoutAggregate(); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
public String getSQLWihoutAggregate() { |
|
65 |
//Crear un select que devuelve todas las lineas |
|
66 |
JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder(); |
|
67 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
68 |
|
|
69 |
sqlbuilder.select().column().name(columnName).as_geometry(); |
|
70 |
sqlbuilder.select().from().table() |
|
71 |
.database(this.table.getDatabase()) |
|
72 |
.schema(this.table.getSchema()) |
|
73 |
.name(this.table.getTable()); |
|
74 |
|
|
75 |
sqlbuilder.select().from().subquery(this.table.getSubquery()); |
|
76 |
if (!StringUtils.isEmpty(baseFilter)) { |
|
77 |
sqlbuilder.select().where().set(expbuilder.custom(baseFilter)); |
|
78 |
} |
|
79 |
// todo ? |
|
80 |
sqlbuilder.select().where().and(expbuilder.not_is_null(expbuilder.column(columnName))); |
|
81 |
String sql = sqlbuilder.select().toString(); |
|
82 |
return sql; |
|
83 |
} |
|
84 |
|
|
85 |
public String getSQLWithAggregate() { |
|
57 | 86 |
// |
58 | 87 |
// Parece ser que en versiones anteriores a SQL Server 2012 no esta |
59 | 88 |
// disponible la funcion ST_ExtentAggregate. |
... | ... | |
64 | 93 |
// |
65 | 94 |
JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder(); |
66 | 95 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
67 |
|
|
96 |
|
|
68 | 97 |
sqlbuilder.select().column().value( |
69 |
// expbuilder.ifnull( |
|
70 |
// expbuilder.column(columnName), |
|
71 |
// expbuilder.constant(null), |
|
98 |
// expbuilder.ifnull(
|
|
99 |
// expbuilder.column(columnName),
|
|
100 |
// expbuilder.constant(null),
|
|
72 | 101 |
expbuilder.as_geometry( |
73 |
expbuilder.ST_ExtentAggregate( |
|
74 |
expbuilder.column(columnName) |
|
75 |
) |
|
102 |
expbuilder.ST_ExtentAggregate(
|
|
103 |
expbuilder.column(columnName)
|
|
104 |
)
|
|
76 | 105 |
) |
77 |
// ) |
|
106 |
// )
|
|
78 | 107 |
); |
79 | 108 |
// sqlbuilder.select().group_by(expbuilder.column(columnName)); |
80 | 109 |
sqlbuilder.select().from().table() |
... | ... | |
97 | 126 |
); |
98 | 127 |
} |
99 | 128 |
} else { |
100 |
sqlbuilder.select().where().set( expbuilder.custom(baseFilter) );
|
|
129 |
sqlbuilder.select().where().set(expbuilder.custom(baseFilter));
|
|
101 | 130 |
if (limit != null) { |
102 | 131 |
sqlbuilder.select().where().and( |
103 | 132 |
expbuilder.ST_Intersects( |
104 |
expbuilder.ST_Envelope( |
|
105 |
expbuilder.column(columnName) |
|
106 |
), |
|
107 |
expbuilder.ST_Envelope( |
|
108 |
expbuilder.geometry(limit.getGeometry(), crs) |
|
109 |
) |
|
133 |
expbuilder.ST_Envelope(
|
|
134 |
expbuilder.column(columnName)
|
|
135 |
),
|
|
136 |
expbuilder.ST_Envelope(
|
|
137 |
expbuilder.geometry(limit.getGeometry(), crs)
|
|
138 |
)
|
|
110 | 139 |
) |
111 | 140 |
); |
112 | 141 |
} |
113 | 142 |
} |
114 |
sqlbuilder.select().where().and(
|
|
115 |
expbuilder.not_is_null(expbuilder.column(columnName)) |
|
143 |
sqlbuilder.select().where().and( |
|
144 |
expbuilder.not_is_null(expbuilder.column(columnName))
|
|
116 | 145 |
); |
117 | 146 |
this.helper.processSpecialFunctions(sqlbuilder, featureType, null); |
118 | 147 |
sqlbuilder.setProperties( |
119 |
Variable.class,
|
|
148 |
Variable.class, |
|
120 | 149 |
PROP_TABLE, table |
121 | 150 |
); |
122 | 151 |
String sql = sqlbuilder.select().toString(); |
123 | 152 |
return sql; |
124 | 153 |
} |
125 |
|
|
154 |
|
|
126 | 155 |
public Envelope calculateEnvelopeOfColumn(Connection conn) throws DataException { |
156 |
if (this.helper.hasSpatialFunctions()) { |
|
157 |
return calculateEnvelopeOfColumnWithAggregate(conn); |
|
158 |
} else { |
|
159 |
return calculateEnvelopeOfColumnWithoutAggregate(conn); |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
private Envelope calculateEnvelopeOfColumnWithAggregate(Connection conn) throws DataException { |
|
127 | 164 |
String sql = this.getSQL(); |
128 |
|
|
165 |
|
|
129 | 166 |
Statement st = null; |
130 | 167 |
ResultSet rs = null; |
131 | 168 |
try { |
132 | 169 |
st = conn.createStatement(); |
133 | 170 |
try { |
134 |
LOGGER.debug("execute query SQL:"+sql);
|
|
171 |
LOGGER.debug("execute query SQL:" + sql);
|
|
135 | 172 |
rs = st.executeQuery(sql); |
136 | 173 |
// No llamo al de JDBC utils para que no meta el error |
137 | 174 |
// en el log. |
138 | 175 |
// rs = JDBCUtils.executeQuery(st, sql); |
139 |
} catch(SQLException ex) { |
|
176 |
} catch (SQLException ex) {
|
|
140 | 177 |
// Para calcular el envelope se esta lanzando una colsulta como: |
141 | 178 |
// SELECT ST_AsBinary(ST_Extent("geometry")) |
142 | 179 |
// FROM "gis_osm_roads_free_1" |
... | ... | |
165 | 202 |
} |
166 | 203 |
} |
167 | 204 |
|
205 |
private Envelope calculateEnvelopeOfColumnWithoutAggregate(Connection conn) throws DataException { |
|
206 |
// crear una sql que devuelva un resultarSet |
|
207 |
//bucle |
|
208 |
// iif instacia de string: cast string |
|
209 |
// GeometryLocator.getGeometryManager().createFrom("") |
|
210 |
// elif instance de bytearray con cast a bytearray: |
|
211 |
// GeometryLocator.getGeometryManager().createFrom("") |
|
212 |
// else: |
|
213 |
// coerceToGeometry |
|
214 |
// |
|
215 |
// |
|
216 |
// Notas: atrapar error, y si se produce error hago un coerceToGeometry |
|
217 |
String sql = this.getSQL(); |
|
218 |
|
|
219 |
Statement st = null; |
|
220 |
ResultSet rs = null; |
|
221 |
try { |
|
222 |
st = conn.createStatement(); |
|
223 |
try { |
|
224 |
LOGGER.debug("execute query SQL:" + sql); |
|
225 |
rs = st.executeQuery(sql); |
|
226 |
// No llamo al de JDBC utils para que no meta el error |
|
227 |
// en el log. |
|
228 |
// rs = JDBCUtils.executeQuery(st, sql); |
|
229 |
} catch (SQLException ex) { |
|
230 |
// Para calcular el envelope se esta lanzando una colsulta como: |
|
231 |
// SELECT ST_AsBinary(ST_Extent("geometry")) |
|
232 |
// FROM "gis_osm_roads_free_1" |
|
233 |
// WHERE ( ("geometry") IS NOT NULL ) |
|
234 |
// Que falla cuando no hay registros al recibir un NULL en el |
|
235 |
// ST_AsBinary. |
|
236 |
// A falta de una forma mejor de detectar eso, si peta en este |
|
237 |
// punto asumiremos que no hay registros en la consulta y devolveremos |
|
238 |
// null como envelope. |
|
239 |
return null; |
|
240 |
} |
|
241 |
Envelope finalEnvelope = GeometryUtils.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
|
242 |
while (rs.next()) { |
|
243 |
String geometryString = rs.getString("geometry"); |
|
244 |
Geometry geometry = GeometryUtils.createFrom(geometryString); |
|
245 |
finalEnvelope.add(geometry); |
|
246 |
} |
|
247 |
// Geometry geom = this.helper.getGeometryFromColumn(rs, 1); |
|
248 |
// if (geom == null) { |
|
249 |
// return null; |
|
250 |
// } |
|
251 |
// return geom.getEnvelope(); |
|
252 |
return finalEnvelope; |
|
253 |
} catch (SQLException ex) { |
|
254 |
throw new JDBCSQLException(ex); |
|
255 |
} finally { |
|
256 |
JDBCUtils.closeQuietly(st); |
|
257 |
JDBCUtils.closeQuietly(rs); |
|
258 |
} |
|
259 |
|
|
260 |
} |
|
261 |
|
|
168 | 262 |
} |
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/JDBCStoreProviderBase.java | ||
---|---|---|
470 | 470 |
); |
471 | 471 |
fetchFeatureType.perform(); |
472 | 472 |
|
473 |
if( !StringUtils.isBlank(params.getDefaultGeometryField()) ) { |
|
474 |
if( !params.getDefaultGeometryField().equalsIgnoreCase(type.getDefaultGeometryAttributeName()) ) { |
|
475 |
type.setDefaultGeometryAttributeName(params.getDefaultGeometryField()); |
|
476 |
EditableFeatureAttributeDescriptor attr = (EditableFeatureAttributeDescriptor) type.getDefaultGeometryAttribute(); |
|
477 |
attr.setGeometryType(Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM2D); |
|
473 |
if (!StringUtils.isBlank(params.getDefaultGeometryField())) { |
|
474 |
if (!params.getDefaultGeometryField().equalsIgnoreCase(type.getDefaultGeometryAttributeName())) { |
|
475 |
if (type.getAttributeDescriptor(params.getDefaultGeometryField()) != null) { |
|
476 |
type.setDefaultGeometryAttributeName(params.getDefaultGeometryField()); |
|
477 |
} else { |
|
478 |
type.setDefaultGeometryAttributeName(null); |
|
479 |
} |
|
480 |
if (type.getDefaultGeometryAttribute() != null) { |
|
481 |
EditableFeatureAttributeDescriptor attr = (EditableFeatureAttributeDescriptor) type.getDefaultGeometryAttribute(); |
|
482 |
attr.setGeometryType(Geometry.TYPES.GEOMETRY, Geometry.SUBTYPES.GEOM2D); |
|
483 |
} |
|
484 |
} else { |
|
485 |
type.setDefaultGeometryAttributeName(null); |
|
478 | 486 |
} |
479 | 487 |
} |
488 |
|
|
480 | 489 |
FeatureType defaultType = type.getNotEditableCopy(); |
481 | 490 |
List<FeatureType> types = Collections.singletonList(defaultType); |
482 | 491 |
this.getStoreServices().setFeatureTypes(types, defaultType); |
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/impl/JDBCStoreProviderFactory.java | ||
---|---|---|
96 | 96 |
return NO; |
97 | 97 |
} |
98 | 98 |
|
99 |
@Override |
|
100 |
public boolean allowSpatialIndexSupport() { |
|
101 |
if (this.hasVectorialSupport() == YES) { |
|
102 |
return true; |
|
103 |
} |
|
104 |
return false; |
|
105 |
} |
|
99 | 106 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/main/java/org/gvsig/fmap/dal/store/mdb/operations/CoercionGeometryToString.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.mdb.operations; |
|
2 |
|
|
3 |
import org.apache.commons.codec.binary.Hex; |
|
4 |
import org.gvsig.fmap.geom.Geometry; |
|
5 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
6 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
7 |
import org.gvsig.tools.dataTypes.AbstractCoercion; |
|
8 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
9 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
10 |
|
|
11 |
/** |
|
12 |
* |
|
13 |
* @author omartinez |
|
14 |
*/ |
|
15 |
public class CoercionGeometryToString extends AbstractCoercion { |
|
16 |
|
|
17 |
// private final FieldFormatter formater; |
|
18 |
|
|
19 |
public CoercionGeometryToString() { |
|
20 |
// this.formater = new FieldFormatter(); |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
|
25 |
if( value instanceof Geometry ) { |
|
26 |
Geometry geom = (Geometry) value; |
|
27 |
byte[] wkb; |
|
28 |
try { |
|
29 |
wkb = geom.convertToWKB(); |
|
30 |
} catch (GeometryOperationException ex) { |
|
31 |
throw new CoercionException("Not able to convert geometry to WKB format"); |
|
32 |
} catch (GeometryOperationNotSupportedException ex) { |
|
33 |
throw new CoercionException("Not able to convert geometry to WKB format"); |
|
34 |
} |
|
35 |
String hexString = Hex.encodeHexString(wkb); |
|
36 |
return hexString; |
|
37 |
} |
|
38 |
|
|
39 |
return null; |
|
40 |
} |
|
41 |
|
|
42 |
} |
|
43 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/main/java/org/gvsig/fmap/dal/store/mdb/operations/MDBFetchFeatureTypeOperation.java | ||
---|---|---|
12 | 12 |
import java.util.List; |
13 | 13 |
import java.util.Map; |
14 | 14 |
import org.cresques.cts.IProjection; |
15 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
16 | 15 |
import org.gvsig.fmap.dal.DataTypes; |
17 | 16 |
import org.gvsig.fmap.dal.exception.DataException; |
18 | 17 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
... | ... | |
28 | 27 |
import org.gvsig.fmap.geom.GeometryLocator; |
29 | 28 |
import org.gvsig.fmap.geom.GeometryManager; |
30 | 29 |
import org.gvsig.fmap.geom.type.GeometryType; |
30 |
import org.gvsig.tools.ToolsLocator; |
|
31 | 31 |
import org.gvsig.tools.dataTypes.DataType; |
32 | 32 |
|
33 | 33 |
@SuppressWarnings("UseSpecificCatch") |
... | ... | |
308 | 308 |
attr.setAllowNull(false); |
309 | 309 |
break; |
310 | 310 |
case DataTypes.STRING: |
311 |
DataType myDataType = null; |
|
312 |
try { |
|
313 |
myDataType = ToolsLocator.getDataTypesManager().get(DataTypes.STRING).clone(); |
|
314 |
} catch (CloneNotSupportedException ex) { |
|
315 |
throw new RuntimeException(ex); |
|
316 |
} |
|
317 |
myDataType.addCoercion(new CoercionGeometryToString()); |
|
318 |
attr.setDataType(myDataType); |
|
311 | 319 |
attr.setSize(rsMetadata.getPrecision(colIndex)); |
312 | 320 |
attr.setPrecision(DataType.PRECISION_NONE); |
313 | 321 |
attr.setScale(DataType.SCALE_NONE); |
314 | 322 |
break; |
323 |
|
|
315 | 324 |
case DataTypes.BYTE: |
316 | 325 |
attr.setDisplaySize(rsMetadata.getColumnDisplaySize(colIndex)); |
317 | 326 |
attr.setPrecision(DataType.BYTE_DEFAULT_PRECISION); |
... | ... | |
366 | 375 |
) throws SQLException { |
367 | 376 |
|
368 | 377 |
switch (rsMetadata.getColumnType(colIndex)) { |
369 |
|
|
378 |
case java.sql.Types.CLOB: |
|
379 |
return DataTypes.STRING; |
|
370 | 380 |
case java.sql.Types.NUMERIC: |
371 | 381 |
case java.sql.Types.DECIMAL: |
372 | 382 |
if (rsMetadata.getPrecision(colIndex)==19 && rsMetadata.getScale(colIndex)== 0) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/main/java/org/gvsig/fmap/dal/store/mdb/operations/MDBOperationsFactory.java | ||
---|---|---|
5 | 5 |
import org.cresques.cts.IProjection; |
6 | 6 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
7 | 7 |
import org.gvsig.fmap.dal.feature.FeatureType; |
8 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
9 | 8 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
10 | 9 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.AppendOperation; |
11 | 10 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation; |
12 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ListTablesOperation; |
|
13 | 11 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase; |
14 | 12 |
|
15 | 13 |
|
... | ... | |
26 | 24 |
defaultGeometryField, crs |
27 | 25 |
); |
28 | 26 |
} |
27 |
// |
|
28 |
// @Override |
|
29 |
// public ListTablesOperation createListTables(int mode, JDBCStoreParameters baseParameters, boolean informationTables) { |
|
30 |
// return new MDBListTablesOperation(helper, mode, baseParameters, informationTables); |
|
31 |
// } |
|
29 | 32 |
|
30 | 33 |
@Override |
31 |
public ListTablesOperation createListTables(int mode, JDBCStoreParameters baseParameters, boolean informationTables) { |
|
32 |
return new MDBListTablesOperation(helper, mode, baseParameters, informationTables); |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 | 34 |
public AppendOperation createAppend(TableReference table, FeatureType type) { |
37 | 35 |
return new MDBAppendOperation(helper, table, type); |
38 | 36 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/main/java/org/gvsig/fmap/dal/store/mdb/MDBSQLBuilder.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.store.mdb; |
2 | 2 |
|
3 |
import java.sql.Clob; |
|
3 | 4 |
import java.sql.PreparedStatement; |
4 | 5 |
import java.sql.SQLException; |
5 | 6 |
import java.sql.Timestamp; |
... | ... | |
8 | 9 |
import java.util.Date; |
9 | 10 |
import java.util.List; |
10 | 11 |
import java.util.Objects; |
12 |
import org.apache.commons.codec.binary.Hex; |
|
13 |
import org.apache.commons.lang3.mutable.MutableBoolean; |
|
11 | 14 |
import org.apache.commons.lang3.tuple.Pair; |
12 | 15 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
13 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_CONSTANT; |
|
14 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_VARIABLE; |
|
15 | 16 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter; |
16 | 17 |
import org.gvsig.expressionevaluator.Formatter; |
17 | 18 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper; |
18 |
import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.PARAMETER_TYPE_GEOMETRY;
|
|
19 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometryParameter;
|
|
19 | 20 |
import org.gvsig.fmap.dal.DataTypes; |
20 | 21 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
21 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
22 | 22 |
import org.gvsig.fmap.dal.feature.FeatureType; |
23 | 23 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
24 | 24 |
import org.gvsig.fmap.dal.store.mdb.expressionbuilderformatter.MDBFormatter; |
25 | 25 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
26 |
import org.gvsig.fmap.dal.store.mdb.MDBHelper; |
|
27 | 26 |
import org.gvsig.fmap.geom.Geometry; |
28 | 27 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
29 | 28 |
import org.gvsig.tools.dispose.Disposable; |
29 |
import org.hsqldb.jdbc.JDBCClob; |
|
30 | 30 |
|
31 | 31 |
public class MDBSQLBuilder extends JDBCSQLBuilderBase { |
32 | 32 |
|
... | ... | |
44 | 44 |
this.STMT_DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table = null; |
45 | 45 |
this.STMT_DELETE_GEOMETRY_COLUMN_FROM_TABLE_table = null; |
46 | 46 |
|
47 |
this.STMT_UPDATE_TABLE_STATISTICS_table = "ANALYZE SAMPLE_SIZE 0";
|
|
47 |
this.STMT_UPDATE_TABLE_STATISTICS_table = ""; |
|
48 | 48 |
|
49 | 49 |
this.type_boolean = "BOOLEAN"; |
50 | 50 |
this.type_byte = "TINYINT"; |
51 | 51 |
this.type_bytearray = "BLOB"; |
52 |
this.type_geometry = "GEOMETRY";
|
|
52 |
this.type_geometry = "CLOB";
|
|
53 | 53 |
this.type_char = "CHAR"; |
54 | 54 |
this.type_date = "DATETIME"; |
55 | 55 |
this.type_double = "FLOAT"; |
... | ... | |
66 | 66 |
this.type_URI = "VARCHAR"; |
67 | 67 |
this.type_URL = "VARCHAR"; |
68 | 68 |
this.type_FILE = "VARCHAR"; |
69 |
this.type_FOLDER = "VARCHAR"; |
|
69 |
this.type_FOLDER = "VARCHAR";
|
|
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
@Override |
... | ... | |
280 | 280 |
builder.append(" ("); |
281 | 281 |
boolean first = true; |
282 | 282 |
for (ColumnDescriptor column : columns) { |
283 |
if( column.isGeometry() ) { |
|
284 |
continue; |
|
285 |
} |
|
286 | 283 |
|
287 | 284 |
if (first) { |
288 | 285 |
first = false; |
... | ... | |
291 | 288 |
} |
292 | 289 |
builder.append(as_identifier(column.getName())); |
293 | 290 |
builder.append(" "); |
294 |
builder.append( |
|
295 |
sqltype( |
|
296 |
column.getType(), |
|
297 |
column.getSize(), |
|
298 |
column.getPrecision(), |
|
299 |
column.getScale(), |
|
300 |
column.getGeometryType(), |
|
301 |
column.getGeometrySubtype() |
|
302 |
) |
|
303 |
); |
|
304 | 291 |
if( column.isGeometry() ) { |
305 |
// // |
|
306 |
// // https://github.com/orbisgis/h2gis/wiki/1.-Spatial-data#geometry-columns-view |
|
307 |
// // https://github.com/orbisgis/h2gis/blob/master/h2gis-functions/src/main/java/org/h2gis/functions/spatial/type/GeometryTypeFromConstraint.java |
|
308 |
// // |
|
309 |
// if( column.getGeometrySRSId()==null ) { |
|
310 |
// builder.append( |
|
311 |
// MessageFormat.format( |
|
312 |
// " CHECK NVL2(\"{0}\", ST_GeometryTypeCode(\"{0}\") = {1} AND ST_CoordDim(\"{0}\") = {2}, TRUE)", |
|
313 |
// column.getName(), |
|
314 |
// sqlgeometrytype(column.getGeometryType(),column.getGeometrySubtype()), |
|
315 |
// sqlgeometrynumdimension(column.getGeometryType(),column.getGeometrySubtype()) ) |
|
316 |
// ); |
|
317 |
// } else { |
|
318 |
// builder.append( |
|
319 |
// MessageFormat.format( |
|
320 |
// " CHECK NVL2(\"{0}\", ST_GeometryTypeCode(\"{0}\") = {1,number,###} AND ST_CoordDim(\"{0}\") = {2,number,###} AND ST_SRID(\"{0}\") = {3,number,#####}, TRUE)", |
|
321 |
// column.getName(), |
|
322 |
// sqlgeometrytype(column.getGeometryType(),column.getGeometrySubtype()), |
|
323 |
// sqlgeometrynumdimension(column.getGeometryType(),column.getGeometrySubtype()), |
|
324 |
// column.getGeometrySRSId() |
|
325 |
// ) |
|
326 |
// ); |
|
327 |
// } |
|
328 |
|
|
292 |
builder.append(type_geometry); |
|
329 | 293 |
} else { |
330 |
if (column.isPrimaryKey()) { |
|
331 |
builder.append(" PRIMARY KEY"); |
|
332 |
if( column.isAutomatic() ) { |
|
333 |
builder.append(" AUTO_INCREMENT"); |
|
294 |
builder.append( |
|
295 |
sqltype( |
|
296 |
column.getType(), |
|
297 |
column.getSize(), |
|
298 |
column.getPrecision(), |
|
299 |
column.getScale(), |
|
300 |
column.getGeometryType(), |
|
301 |
column.getGeometrySubtype() |
|
302 |
) |
|
303 |
); |
|
304 |
} |
|
305 |
if (column.isPrimaryKey()) { |
|
306 |
builder.append(" PRIMARY KEY"); |
|
307 |
if( column.isAutomatic() ) { |
|
308 |
builder.append(" AUTO_INCREMENT"); |
|
309 |
} |
|
310 |
} else { |
|
311 |
if( column.isAutomatic() ) { |
|
312 |
builder.append(" AUTO_INCREMENT"); |
|
313 |
} |
|
314 |
if (column.getDefaultValue() == null) { |
|
315 |
if (column.allowNulls()) { |
|
316 |
builder.append(" DEFAULT NULL"); |
|
334 | 317 |
} |
335 | 318 |
} else { |
336 |
if( column.isAutomatic() ) { |
|
337 |
builder.append(" AUTO_INCREMENT"); |
|
338 |
} |
|
339 |
if (column.getDefaultValue() == null) { |
|
340 |
if (column.allowNulls()) { |
|
341 |
builder.append(" DEFAULT NULL"); |
|
342 |
} |
|
319 |
if( column.getType() == DataTypes.DATE ) { |
|
320 |
builder.append(" DEFAULT ( TIMESTAMP '"); |
|
321 |
Date d = (Date) column.getDefaultValue(); |
|
322 |
builder.append(MessageFormat.format( "{0,date,yyyy-MM-dd HH:mm:ss.S}",d)); |
|
323 |
builder.append("' )"); |
|
343 | 324 |
} else { |
344 |
if( column.getType() == DataTypes.DATE ) { |
|
345 |
builder.append(" DEFAULT ( TIMESTAMP '"); |
|
346 |
Date d = (Date) column.getDefaultValue(); |
|
347 |
builder.append(MessageFormat.format( "{0,date,yyyy-MM-dd HH:mm:ss.S}",d)); |
|
348 |
builder.append("' )"); |
|
349 |
} else { |
|
350 |
builder.append(" DEFAULT '"); |
|
351 |
builder.append(Objects.toString(column.getDefaultValue(),"")); |
|
352 |
builder.append("'"); |
|
353 |
} |
|
325 |
builder.append(" DEFAULT '"); |
|
326 |
builder.append(Objects.toString(column.getDefaultValue(),"")); |
|
327 |
builder.append("'"); |
|
354 | 328 |
} |
355 |
} |
|
329 |
}
|
|
356 | 330 |
} |
357 | 331 |
if (!column.allowNulls()) { |
358 | 332 |
builder.append(" NOT NULL"); |
... | ... | |
381 | 355 |
} |
382 | 356 |
} |
383 | 357 |
|
358 |
public class MDBSelectColumnBuilderBase extends SelectColumnBuilderBase { |
|
359 |
@Override |
|
360 |
public String toString(Formatter formatter) { |
|
361 |
return super.toString(formatter); |
|
362 |
} |
|
363 |
} |
|
364 |
|
|
384 | 365 |
public class MDBSelectBuilderBase extends SelectBuilderBase { |
385 | 366 |
|
386 | 367 |
@Override |
... | ... | |
400 | 381 |
} else { |
401 | 382 |
builder.append(", "); |
402 | 383 |
} |
384 |
|
|
403 | 385 |
builder.append(column.toString(formatter)); |
404 | 386 |
} |
405 | 387 |
|
... | ... | |
475 | 457 |
if( type!=DataTypes.GEOMETRY ) { |
476 | 458 |
return super.sqltype(type, size, precision, scale, geomtype, geomSubtype); |
477 | 459 |
} |
478 |
return "GEOMETRY(1)";
|
|
460 |
return this.type_geometry;
|
|
479 | 461 |
} |
480 | 462 |
|
481 | 463 |
@Override |
... | ... | |
531 | 513 |
try { |
532 | 514 |
FeatureType featureType = feature.getType(); |
533 | 515 |
List<Object> values = new ArrayList<>(); |
534 |
for (Parameter parameter : this.parameters()) { |
|
516 |
List<Parameter> parameters = this.parametersWithoutSRS(); |
|
517 |
for (Parameter parameter : parameters) { |
|
535 | 518 |
if (parameter.is_constant()) { |
536 | 519 |
values.add(parameter.value()); |
537 | 520 |
} else { |
... | ... | |
571 | 554 |
} |
572 | 555 |
} |
573 | 556 |
|
557 |
public List<Parameter> parametersWithoutSRS() { |
|
558 |
final List<Parameter> params = new ArrayList<>(); |
|
559 |
MutableBoolean skipNextParameter = new MutableBoolean(false); |
|
560 |
this.accept((ExpressionBuilder.Visitable value1) -> { |
|
561 |
if (skipNextParameter.isTrue()) { |
|
562 |
skipNextParameter.setFalse(); |
|
563 |
return; |
|
564 |
} |
|
565 |
if (value1 instanceof GeometryExpressionBuilderHelper.GeometryParameter) { |
|
566 |
GeometryParameter g = (GeometryParameter) value1; |
|
567 |
if (g.srs()!= null) { |
|
568 |
skipNextParameter.setTrue(); |
|
569 |
} |
|
570 |
|
|
571 |
} |
|
572 |
params.add((Parameter) value1); |
|
573 |
}, new ExpressionBuilder.ClassVisitorFilter(Parameter.class)); |
|
574 |
return params; |
|
575 |
} |
|
576 |
//. |
|
577 |
// public List<Parameter> parametersWithoutSRS() { // aqui hay que eliminar el srs. Visitor de tipo GeometryParameterBase, si ese tiene srs. si lo tiene y es de tipo Parametro debe saltarselo |
|
578 |
// final List<Parameter> params = new ArrayList<>(); |
|
579 |
// this.accept(new ExpressionBuilder.Visitor() { |
|
580 |
// @Override |
|
581 |
// public void visit(ExpressionBuilder.Visitable value) { |
|
582 |
// params.add((Parameter) value); |
|
583 |
// } |
|
584 |
// }, new ExpressionBuilder.ClassVisitorFilter(Parameter.class)); |
|
585 |
// return params; |
|
586 |
// } |
|
587 |
|
|
574 | 588 |
@Override |
575 | 589 |
public InsertColumnBuilderBase createInsertColumnBuilder() { |
576 | 590 |
return new MDBInsertColumnBuilderBase(); |
... | ... | |
602 | 616 |
} |
603 | 617 |
|
604 | 618 |
@Override |
619 |
protected SelectColumnBuilder createSelectColumnBuilder() { |
|
620 |
|
|
621 |
return new MDBSelectColumnBuilderBase(); //super.createSelectColumnBuilder().; // SelectColumnBuilderBase, override el metodo toString |
|
622 |
} |
|
623 |
|
|
624 |
@Override |
|
605 | 625 |
protected CreateIndexBuilder createCreateIndexBuilder() { |
606 | 626 |
return new MDBCreateIndexBuilder(); |
607 | 627 |
} |
... | ... | |
620 | 640 |
List values, |
621 | 641 |
GeometryExpressionBuilderHelper.GeometrySupportType geometrySupportType) throws SQLException { |
622 | 642 |
|
643 |
// |
|
644 |
DisposableClobs disposableClobs = new DisposableClobs(); |
|
645 |
// |
|
623 | 646 |
if (values == null) { |
624 |
return new Disposable() { |
|
625 |
@Override |
|
626 |
public void dispose() { |
|
627 |
} |
|
628 |
}; |
|
647 |
return disposableClobs; |
|
629 | 648 |
} |
630 | 649 |
if (true || LOGGER.isDebugEnabled()) { |
631 | 650 |
StringBuilder debug = new StringBuilder(); |
... | ... | |
683 | 702 |
} |
684 | 703 |
} |
685 | 704 |
byte[] bytes; |
705 |
char[] hexGeomEwkb; |
|
686 | 706 |
int columnIndex = 1; |
687 | 707 |
Object theValue; |
708 |
Clob cl; |
|
688 | 709 |
try { |
689 | 710 |
for (Object value : values) { |
690 | 711 |
theValue = value; |
... | ... | |
698 | 719 |
case NATIVE: |
699 | 720 |
case WKB: |
700 | 721 |
bytes = ((Geometry) value).convertToWKB(); |
701 |
st.setBytes(columnIndex, bytes); |
|
722 |
cl = disposableClobs.add(bytes); |
|
723 |
st.setClob(columnIndex, cl); |
|
702 | 724 |
break; |
725 |
|
|
703 | 726 |
case EWKB: |
704 | 727 |
bytes = ((Geometry) value).convertToEWKB(); |
705 |
st.setBytes(columnIndex, bytes); |
|
728 |
cl = disposableClobs.add(bytes); |
|
729 |
st.setClob(columnIndex, cl); |
|
706 | 730 |
break; |
731 |
|
|
732 |
|
|
707 | 733 |
} |
708 | 734 |
} else if (value instanceof Date) { |
709 | 735 |
// Access solo soporta timestamp |
... | ... | |
718 | 744 |
} |
719 | 745 |
columnIndex++; |
720 | 746 |
} |
721 |
return new Disposable() { |
|
722 |
@Override |
|
723 |
public void dispose() { |
|
724 |
} |
|
725 |
}; |
|
747 |
return disposableClobs; |
|
726 | 748 |
} catch (Exception ex) { |
727 | 749 |
throw new SQLException("Can't set values for the prepared statement.", ex); |
728 | 750 |
} |
... | ... | |
782 | 804 |
} |
783 | 805 |
|
784 | 806 |
|
785 |
|
|
786 |
|
|
787 |
|
|
807 |
public class DisposableClobs implements Disposable { |
|
788 | 808 |
|
809 |
private final List<Clob> clobList = new ArrayList<>(); |
|
810 |
|
|
811 |
public Clob add(byte[] bytes) throws SQLException { |
|
812 |
char[] hexGeom = Hex.encodeHex(bytes); |
|
813 |
String strHexGeo = new String(hexGeom); |
|
814 |
JDBCClob clob = new JDBCClob(strHexGeo); |
|
815 |
clobList.add(clob); |
|
816 |
return clob; |
|
817 |
} |
|
818 |
|
|
819 |
@Override |
|
820 |
public void dispose() { |
|
821 |
clobList.forEach((Clob clob) -> { |
|
822 |
try { |
|
823 |
clob.free(); |
|
824 |
} catch (SQLException ex) { |
|
825 |
} |
|
826 |
}); |
|
827 |
} |
|
828 |
|
|
829 |
} |
|
789 | 830 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/main/java/org/gvsig/fmap/dal/store/mdb/expressionbuilderformatter/GeometryParameterMDB.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.mdb.expressionbuilderformatter; |
|
2 |
|
|
3 |
import java.text.MessageFormat; |
|
4 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
5 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_CONSTANT; |
|
6 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_VARIABLE; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Variable; |
|
9 |
import org.gvsig.expressionevaluator.Formatter; |
|
10 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
11 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometryParameter; |
|
12 |
import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType.EWKB; |
|
13 |
import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType.WKB; |
|
14 |
import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType.WKT; |
|
15 |
import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.PARAMETER_TYPE_GEOMETRY; |
|
16 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
17 |
import org.gvsig.fmap.geom.Geometry; |
|
18 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
19 |
|
|
20 |
/** |
|
21 |
* |
|
22 |
* @author jjdelcerro |
|
23 |
*/ |
|
24 |
public class GeometryParameterMDB implements Formatter<Value> { |
|
25 |
|
|
26 |
private final SQLBuilder sqlbuilder; |
|
27 |
private final Formatter<Value> formatter; |
|
28 |
|
|
29 |
public GeometryParameterMDB(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
|
30 |
this.sqlbuilder = sqlbuilder; |
|
31 |
this.formatter = formatter; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public boolean canApply(ExpressionBuilder.Value value) { |
|
36 |
if (value instanceof GeometryParameter) { |
|
37 |
Object x = ((GeometryParameter) value); |
|
38 |
return true; |
|
39 |
} |
|
40 |
return false; |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public String format(Value variable) { |
|
45 |
// GeometryParameter x = ((GeometryParameter) variable); |
|
46 |
return "?"; |
|
47 |
} |
|
48 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/main/java/org/gvsig/fmap/dal/store/mdb/expressionbuilderformatter/VariableBaseMDB.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.store.mdb.expressionbuilderformatter; |
2 | 2 |
|
3 |
import java.text.MessageFormat; |
|
4 | 3 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
5 | 4 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
6 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Variable; |
|
7 | 5 |
import org.gvsig.expressionevaluator.Formatter; |
8 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
9 |
import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType.EWKB; |
|
10 |
import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType.WKB; |
|
11 |
import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType.WKT; |
|
12 | 6 |
import org.gvsig.fmap.dal.SQLBuilder; |
13 |
import org.gvsig.fmap.geom.Geometry; |
|
14 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
15 | 7 |
|
16 | 8 |
/** |
17 | 9 |
* |
... | ... | |
31 | 23 |
public boolean canApply(ExpressionBuilder.Value value) { |
32 | 24 |
if (value instanceof ExpressionBuilder.Variable) { |
33 | 25 |
Object x = ((ExpressionBuilder.Variable)value); |
34 |
// if( x instanceof byte[] ) { |
|
35 |
// return true; |
|
36 |
// } |
|
37 |
// if( x instanceof Geometry ) { |
|
38 |
// return true; |
|
39 |
// } |
|
40 | 26 |
return true; |
41 | 27 |
} |
42 | 28 |
return false; |
... | ... | |
44 | 30 |
|
45 | 31 |
@Override |
46 | 32 |
public String format(Value variable) { |
47 |
ExpressionBuilder.Variable x = ((ExpressionBuilder.Variable)variable); |
|
48 |
// GeometryExpressionBuilder builder = this.sqlbuilder.expression(); |
|
49 |
|
|
33 |
ExpressionBuilder.Variable x = ((ExpressionBuilder.Variable)variable); |
|
50 | 34 |
return "["+x.name()+"]"; |
51 | 35 |
} |
52 | 36 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/main/java/org/gvsig/fmap/dal/store/mdb/expressionbuilderformatter/SelectColumnBuilder.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.mdb.expressionbuilderformatter; |
|
2 |
|
|
3 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
4 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
5 |
import org.gvsig.expressionevaluator.Formatter; |
|
6 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
* @author jjdelcerro |
|
11 |
*/ |
|
12 |
public class SelectColumnBuilder implements Formatter<Value> { |
|
13 |
|
|
14 |
private final SQLBuilder sqlbuilder; |
|
15 |
private final Formatter<Value> formatter; |
|
16 |
|
|
17 |
public SelectColumnBuilder(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
|
18 |
this.sqlbuilder = sqlbuilder; |
|
19 |
this.formatter = formatter; |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
public boolean canApply(ExpressionBuilder.Value value) { |
|
24 |
if (value instanceof SQLBuilder.SelectColumnBuilder) { |
|
25 |
SQLBuilder.SelectColumnBuilder x = (SQLBuilder.SelectColumnBuilder) value; |
|
26 |
return x.isGeometry(); |
|
27 |
} |
|
28 |
|
|
29 |
return false; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public String format(Value constant) { |
|
34 |
SQLBuilder.SelectColumnBuilder x = (SQLBuilder.SelectColumnBuilder) constant; |
|
35 |
return "[" + x.getName() + "]"; |
|
36 |
|
|
37 |
} |
|
38 |
|
|
39 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/main/java/org/gvsig/fmap/dal/store/mdb/expressionbuilderformatter/MDBFormatter.java | ||
---|---|---|
27 | 27 |
new Constant(this.builder, this), |
28 | 28 |
new Exists(this.builder, this), |
29 | 29 |
new Getattr(this.builder, this), |
30 |
new GeometryParameterMDB(this.builder, this), |
|
30 | 31 |
new VariableBaseMDB(this.builder, this), |
31 | 32 |
new DateFunction(this.builder, this), |
32 | 33 |
new TimeFunction(this.builder, this), |
33 | 34 |
new TimestampFunction(this.builder, this), |
35 |
new SelectColumnBuilder(this.builder, this), |
|
34 | 36 |
DALLocator.getDataManager().createDALExpressionBuilder().formatter(this), |
35 | 37 |
}; |
36 | 38 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/main/java/org/gvsig/fmap/dal/store/mdb/MDBHelper.java | ||
---|---|---|
22 | 22 |
package org.gvsig.fmap.dal.store.mdb; |
23 | 23 |
|
24 | 24 |
import java.io.File; |
25 |
import java.sql.Clob; |
|
25 | 26 |
import java.sql.Connection; |
27 |
import java.sql.ResultSet; |
|
26 | 28 |
import java.sql.SQLException; |
27 | 29 |
import java.text.MessageFormat; |
28 | 30 |
import org.apache.commons.dbcp.BasicDataSource; |
29 |
import org.apache.commons.io.FilenameUtils;
|
|
31 |
import org.apache.commons.io.IOUtils;
|
|
30 | 32 |
import org.apache.commons.lang3.StringUtils; |
31 | 33 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType; |
34 |
import org.gvsig.fmap.dal.exception.DataException; |
|
32 | 35 |
import org.gvsig.fmap.dal.exception.InitializeException; |
33 | 36 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
34 | 37 |
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices; |
... | ... | |
37 | 40 |
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters; |
38 | 41 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
39 | 42 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
43 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCCantFetchValueException; |
|
40 | 44 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCDriverClassNotFoundException; |
41 | 45 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
42 | 46 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
43 | 47 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase; |
44 | 48 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
45 | 49 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCServerExplorerBase; |
46 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverBase; |
|
47 | 50 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverDumb; |
51 |
import org.gvsig.fmap.geom.Geometry; |
|
48 | 52 |
//import org.h2.tools.Server; |
49 | 53 |
//import org.h2gis.ext.H2GISExtension; |
50 | 54 |
import org.slf4j.Logger; |
... | ... | |
388 | 392 |
this.initialize(explorer, parameters, null); |
389 | 393 |
return explorer; |
390 | 394 |
} |
395 |
|
|
396 |
@Override |
|
397 |
public Geometry getGeometryFromColumn(ResultSet rs, int index) throws DataException { |
|
398 |
try { |
|
399 |
Object value; |
|
400 |
Clob clob; |
|
401 |
String strGeom; |
|
402 |
switch (this.getGeometrySupportType()) { |
|
403 |
case NATIVE: |
|
404 |
case WKB: |
|
405 |
clob = rs.getClob(index); |
|
406 |
if (clob ==null) { |
|
407 |
return null; |
|
408 |
} |
|
409 |
strGeom = new String(IOUtils.toCharArray(clob.getCharacterStream())); |
|
410 |
clob.free(); |
|
411 |
return this.getGeometryManager().createFrom(strGeom); |
|
412 |
case EWKB: |
|
413 |
clob = rs.getClob(index); |
|
414 |
if (clob ==null) { |
|
415 |
return null; |
|
416 |
} |
|
417 |
strGeom = new String(IOUtils.toCharArray(clob.getCharacterStream())); |
|
418 |
return this.getGeometryManager().createFrom(strGeom); |
|
419 |
case WKT: |
|
420 |
default: |
|
421 |
value = rs.getString(index); |
|
422 |
if (value == null) { |
|
423 |
return null; |
|
424 |
} |
|
425 |
return this.getGeometryManager().createFrom((String) value); |
|
426 |
|
|
427 |
} |
|
428 |
} catch (Exception ex) { |
|
429 |
throw new JDBCCantFetchValueException(ex); |
|
430 |
} |
|
431 |
} |
|
391 | 432 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/main/java/org/gvsig/fmap/dal/store/mdb/MDBStoreProviderFactory.java | ||
---|---|---|
94 | 94 |
public int allowGroupBy() { |
95 | 95 |
return YES; |
96 | 96 |
} |
97 |
|
|
98 |
@Override |
|
99 |
public boolean allowSpatialIndexSupport() { |
|
100 |
return false; |
|
101 |
} |
|
97 | 102 |
|
98 |
|
|
99 | 103 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/test/resources/org/gvsig/fmap/dal/store/mdb/testCreateSource1_1.csv | ||
---|---|---|
1 |
ID/Integer/set/pk=true;Byte/Byte;Bool1/Boolean;Long/Long;Timestamp/TimeStamp;Date/Date;Time/Time;Bool2/Boolean;String/String/set/size=30;Bool3/Boolean;Double/Double;Bool4/Boolean;Float/Float;Bool5/Boolean;Decimal/Decimal/set/precision=6/set/scale=3;Geometry/String/set/size=50 |
|
2 |
0; ; ; ; ; ; ; ; ; ; ; ; ;T; ; |
|
3 |
1;10;T;1000;20191229121314;20191229;121314;T;Yo yo1;F;12345.54321;T;123.21;T;456.123;POINT (-3.8945156972987958 42.01053743584765) |
|
4 |
2;20;T;2000;20191129121314;20191129;131314;T;Yo yo2;F;12100.54321;T;100.21;T;456.123;POINT (-2.1079618220646115 41.983079082675474) |
|
5 |
3;30;T;3000;20191029121314;20191029;141314;T;Yo yo3;F;12101.54321;T;101.21;T;456.123;POINT (-2.57249737803327 41.35372113353277) |
|
6 |
4;40;T;4000;20190929121314;20190929;151314;T;Yo yo4;F;12102.54321;T;102.21;T;456.123;POINT (-4.061822048036304 41.35877680235475) |
|
7 |
5;50;T;5000;20190829121314;20190829;161314;T;Yo yo5;F;12103.54321;T;103.21;T;456.123;POINT (-3.974317066986988 40.78701209315094) |
|
8 |
6;60;T;6000;20190729121314;20190729;171314;T;Yo yo6;F;12104.54321;T;104.21;T;456.123;POINT (-2.510509736717547 40.69847453392384) |
|
9 |
7;70;T;7000;20190629121314;20190629;181314;T;Yo yo7;F;12105.54321;T;105.21;T;456.123;POINT (-0.5317736981843011 40.66396082637622) |
|
10 |
8;80;T;8000;20190529121314;20190529;191314;T;Yo yo8;F;12106.54321;T;106.21;T;456.123;POINT (-0.3626917259170671 41.13652386601604) |
|
11 |
9;90;T;9000;20190429121314;20190429;201314;T;Yo yo9;F;12107.54321;T;107.21;T;456.123;POINT (-1.2461823078608523 41.84950010180092) |
|
12 |
10;;T;1001;20191229121314;20191229;121314;T;Yo yo1;F;12345.54321;T;123.21;T;456.123;POINT (-1.2145405488596532 41.22158511004416) |
|
13 |
11;22; ;2002;20191129121314;20191129;131314;T;Yo yo2;F;12100.54321;T;100.21;T;456.123;POINT (-0.7699089544899235 41.630581204431756) |
|
14 |
12;33;T; ;20190929121314;20191029;141314;T;Yo yo3;F;12101.54321;T;101.21;T;456.123;POINT (0.4821915816701051 41.75970939133133) |
|
15 |
13;41;T;4001; ;20190929;151314;T;Yo yo4;F;12102.54321;T;102.21;T;456.123;POINT (0.7912661147227479 41.919324620992036) |
|
16 |
14;52;T;5002;20190829121314; ;161314;T;Yo yo5;F;12103.54321;T;103.21;T;456.123;POINT (1.052534629531243 41.493736996249545) |
|
17 |
15;63;T;6003;20190729121314;20190729; ;T;Yo yo6;F;12104.54321;T;104.21;T;456.123;POINT (0.8097002367335026 41.0899480235613) |
|
18 |
16;74;T;7004;20190629121314;20190629;181314;T; ;F;12105.54321;T;105.21;T;456.123;POINT (-0.4883960310112362 41.17597288081971) |
|
19 |
17;85;T;8005;20190529121314;20190529;191314;T;Yo yo8;F; ;T;106.21;T;456.123;POINT (-0.6439030698437881 40.89530766155764) |
|
20 |
18;96;T;9006;20190429121314;20190429;201314;T;Yo yo9;F;12107.54321;T; ;T; ;POINT (-1.3061826868199504 40.72372835570524) |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/test/resources/org/gvsig/fmap/dal/store/mdb/calculateEnvelope.sql | ||
---|---|---|
1 | 1 |
|
2 | 2 |
-- Count SQL |
3 | 3 |
SELECT |
4 |
NVL2(ST_Extent("Geometry"),ST_AsBinary(ST_Extent("Geometry")),NULL) |
|
5 |
FROM "PUBLIC"."test" |
|
6 |
WHERE ( ("Geometry") IS NOT NULL ); |
|
4 |
[Geometry] |
|
5 |
FROM [test] |
|
6 |
WHERE ( ([Geometry]) IS NOT NULL ); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/test/resources/org/gvsig/fmap/dal/store/mdb/createTable.sql | ||
---|---|---|
18 | 18 |
[Float] REAL DEFAULT NULL, |
19 | 19 |
[Bool5] BOOLEAN DEFAULT NULL, |
20 | 20 |
[Decimal] DECIMAL(6,3) DEFAULT NULL, |
21 |
[Geometry] VARCHAR(50) DEFAULT NULL,
|
|
21 |
[Geometry] CLOB DEFAULT NULL,
|
|
22 | 22 |
[Decimal19_0] DECIMAL(19) DEFAULT NULL ); |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/test/resources/org/gvsig/fmap/dal/store/mdb/testCreateSource1.csv | ||
---|---|---|
1 |
ID/Integer/set/pk=true;Byte/Byte;Bool1/Boolean;Long/Long;Timestamp/TimeStamp;Date/Date;Time/Time;Bool2/Boolean;String/String/set/size=30;Bool3/Boolean;Double/Double;Bool4/Boolean;Float/Float;Bool5/Boolean;Decimal/Decimal/set/precision=6/set/scale=3;Geometry/String/set/size=50;Decimal19_0/Decimal/set/precision=19/set/scale=0
|
|
1 |
ID/Integer/set/pk=true;Byte/Byte;Bool1/Boolean;Long/Long;Timestamp/TimeStamp;Date/Date;Time/Time;Bool2/Boolean;String/String/set/size=30;Bool3/Boolean;Double/Double;Bool4/Boolean;Float/Float;Bool5/Boolean;Decimal/Decimal/set/precision=6/set/scale=3;Geometry/Geometry/set/geomtype=Point:2D/set/srs=EPSG:4326;Decimal19_0/Decimal/set/precision=19/set/scale=0
|
|
2 | 2 |
0; ; ; ; ; ; ; ; ; ; ; ; ;T; ;; |
3 | 3 |
1;10;T;1000;20191229121314;20191229;121314;T;Yo yo1;F;12345.54321;T;123.21;T;456.123;POINT (-3.8945156972987958 42.01053743584765);12345678901234567 |
4 | 4 |
2;20;T;2000;20191129121314;20191129;131314;T;Yo yo2;F;12100.54321;T;100.21;T;456.123;POINT (-2.1079618220646115 41.983079082675474);12345678901234567 |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/test/resources/org/gvsig/fmap/dal/store/mdb/performChanges.sql | ||
---|---|---|
48 | 48 |
ALTER TABLE [test] ADD COLUMN [Float] REAL DEFAULT NULL NULL; |
49 | 49 |
ALTER TABLE [test] ADD COLUMN [Bool5] BOOLEAN DEFAULT NULL NULL; |
50 | 50 |
ALTER TABLE [test] ADD COLUMN [Decimal] DECIMAL(6,3) DEFAULT NULL NULL; |
51 |
ALTER TABLE [test] ADD COLUMN [Geometry] VARCHAR(50) DEFAULT NULL NULL;
|
|
51 |
ALTER TABLE [test] ADD COLUMN [Geometry] CLOB DEFAULT NULL NULL;
|
|
52 | 52 |
ALTER TABLE [test] ADD COLUMN [Decimal19_0] DECIMAL(19) DEFAULT NULL NULL; |
53 | 53 |
|
54 | 54 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.mdb/src/test/java/org/gvsig/fmap/dal/store/mdb/TestCreate.java | ||
---|---|---|
6 | 6 |
import java.util.List; |
7 | 7 |
import junit.framework.TestCase; |
8 | 8 |
import static junit.framework.TestCase.assertEquals; |
9 |
import org.apache.commons.codec.binary.Hex; |
|
9 | 10 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
10 | 11 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
11 | 12 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
... | ... | |
25 | 26 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
26 | 27 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
27 | 28 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
29 |
import org.gvsig.fmap.geom.Geometry; |
|
28 | 30 |
import org.gvsig.tools.ToolsLocator; |
29 | 31 |
import org.gvsig.tools.dataTypes.DataType; |
30 | 32 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
... | ... | |
237 | 239 |
); |
238 | 240 |
assertEquals( |
239 | 241 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
240 |
sourceAttr.getDataTypeName(),
|
|
242 |
ToolsLocator.getDataTypesManager().get(DataTypes.STRING).getName(),
|
|
241 | 243 |
targetAttr.getDataTypeName() |
242 | 244 |
); |
243 |
assertEquals( |
|
244 |
String.format("Field %s geometry type mismatch", sourceAttr.getName()), |
|
245 |
sourceAttr.getGeomType().getName(), |
|
246 |
targetAttr.getGeomType().getName() |
|
247 |
); |
|
248 |
assertEquals( |
|
249 |
String.format("Field %s geometry SRS mismatch", sourceAttr.getName()), |
|
250 |
sourceAttr.getSRS().toString(), |
|
251 |
targetAttr.getSRS().toString() |
|
252 |
); |
|
253 |
assertEquals( |
|
254 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
255 |
sourceAttr.getSize(), |
|
256 |
targetAttr.getSize() |
|
257 |
); |
|
258 |
assertEquals( |
|
259 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
260 |
sourceAttr.getPrecision(), |
|
261 |
targetAttr.getPrecision() |
|
262 |
); |
|
245 |
// assertEquals(
|
|
246 |
// String.format("Field %s geometry type mismatch", sourceAttr.getName()),
|
|
247 |
// sourceAttr.getGeomType().getName(),
|
|
248 |
// targetAttr.getGeomType().getName()
|
|
249 |
// );
|
|
250 |
// assertEquals(
|
|
251 |
// String.format("Field %s geometry SRS mismatch", sourceAttr.getName()),
|
|
252 |
// sourceAttr.getSRS().toString(),
|
|
253 |
// targetAttr.getSRS().toString()
|
|
254 |
// );
|
|
255 |
// assertEquals(
|
|
256 |
// String.format("Field %s size mismatch", sourceAttr.getName()),
|
|
257 |
// sourceAttr.getSize(),
|
|
258 |
// targetAttr.getSize()
|
|
259 |
// );
|
|
260 |
// assertEquals(
|
|
261 |
// String.format("Field %s precision mismatch", sourceAttr.getName()),
|
|
262 |
// sourceAttr.getPrecision(),
|
|
263 |
// targetAttr.getPrecision()
|
|
264 |
// );
|
|
263 | 265 |
break; |
264 | 266 |
default: |
265 | 267 |
fail( |
... | ... | |
333 | 335 |
); |
334 | 336 |
break; |
335 | 337 |
case DataTypes.GEOMETRY: |
336 |
assertEquals( |
|
337 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
338 |
sourceFeature.get(sourceAttr.getName()), |
|
339 |
targetFeature.get(sourceAttr.getName()) |
|
340 |
); |
|
338 |
Geometry sourceGeom = sourceFeature.getDefaultGeometry(); |
|
339 |
if (sourceGeom != null) { |
|
340 |
byte[] wkb = sourceGeom.convertToWKB(); |
|
341 |
String sourceGeomHex = Hex.encodeHexString(wkb); |
|
342 |
|
|
343 |
assertEquals( |
|
344 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
345 |
sourceGeomHex, |
|
346 |
targetFeature.get(sourceAttr.getName()) |
|
347 |
); |
|
348 |
} else { |
|
349 |
assertEquals( |
|
350 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
351 |
sourceGeom, |
|
352 |
targetFeature.get(sourceAttr.getName()) |
|
353 |
); |
|
354 |
} |
|
341 | 355 |
break; |
356 |
|
|
342 | 357 |
case DataTypes.LONG: |
343 | 358 |
Object expectedLong = sourceFeature.get(sourceAttr.getName()); |
344 | 359 |
if (expectedLong != null) { |
... | ... | |
355 | 370 |
); |
356 | 371 |
break; |
357 | 372 |
|
358 |
case DataTypes.FLOAT: |
|
373 |
case DataTypes.FLOAT: // Access float |
|
374 |
Object expectedFloat = sourceFeature.get(sourceAttr.getName()); |
|
375 |
if (expectedFloat != null) { |
|
376 |
expectedFloat = sourceFeature.get(sourceAttr.getName()); |
|
377 |
} |
|
378 |
Object targetFloat = targetFeature.get(sourceAttr.getName()); |
|
379 |
if (targetFloat!=null) { |
|
380 |
targetFloat = targetFeature.getFloat(sourceAttr.getName()); |
|
381 |
} |
|
382 |
assertEquals( |
|
383 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
384 |
expectedFloat, |
|
385 |
targetFloat |
|
386 |
); |
|
387 |
break; |
|
388 |
case DataTypes.DECIMAL: |
|
389 |
if (sourceAttr.getPrecision() == 19 && sourceAttr.getScale() == 0) { // en acces es un decimal, lo tratamos como long |
|
390 |
Object expectedDecimalAsLong = sourceFeature.get(sourceAttr.getName()); |
|
391 |
if (expectedDecimalAsLong != null) { |
|
392 |
expectedDecimalAsLong = sourceFeature.getLong(sourceAttr.getName()); |
|
393 |
} |
|
394 |
Object targetDecimalasLong= targetFeature.get(sourceAttr.getName()); |
|
395 |
if (targetDecimalasLong!=null) { |
|
396 |
targetDecimalasLong = targetFeature.getLong(sourceAttr.getName()); |
|
397 |
} |
|
398 |
assertEquals( |
|
399 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
400 |
expectedDecimalAsLong, |
|
401 |
targetDecimalasLong |
|
402 |
); |
|
403 |
break; |
|
404 |
} |
|
359 | 405 |
case DataTypes.DOUBLE: |
360 | 406 |
default: |
361 | 407 |
Object sourceValue = sourceFeature.get(sourceAttr.getName()); |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geodb.app/org.gvsig.geodb.app.mainplugin/src/main/java/org/gvsig/geodb/AbstractWizardDB.java | ||
---|---|---|
427 | 427 |
protected abstract boolean requireGeometry(); |
428 | 428 |
|
429 | 429 |
protected Collection<TableInfo> getTablesInformation() { |
430 |
this.updateTableInfoFromUI(); |
|
430 | 431 |
if( this.tablesInfo == null ) { |
431 | 432 |
this.tablesInfo = new HashMap<>(); |
432 | 433 |
} |
... | ... | |
572 | 573 |
this.setEditableTableConfig(false); |
573 | 574 |
return; |
574 | 575 |
} |
575 |
String previousTableName = this.view.txtName.getText(); |
|
576 |
TableInfo previousInfo = this.tablesInfo.get(previousTableName); |
|
577 |
if (previousInfo != null) { |
|
578 |
this.fetch(previousInfo); |
|
579 |
} |
|
576 |
this.updateTableInfoFromUI(); |
|
580 | 577 |
this.put(tableInfo); |
581 | 578 |
this.checkFinishable(); |
582 | 579 |
} |
580 |
|
|
581 |
private void updateTableInfoFromUI() { |
|
582 |
String previousTableName = this.view.txtName.getText(); |
|
583 |
if (this.tablesInfo!=null && !this.tablesInfo.isEmpty()) { |
|
584 |
TableInfo previousInfo = this.tablesInfo.get(previousTableName); |
|
585 |
if (previousInfo != null) { |
|
586 |
this.fetch(previousInfo); |
|
587 |
} |
|
588 |
} |
|
589 |
} |
|
583 | 590 |
|
584 | 591 |
private void put(TableInfo tableInfo) { |
585 | 592 |
this.lwcColumns.setModel(tableInfo.getColumnsListModel()); |
Also available in: Unified diff