Revision 43379

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.h2/src/main/java/org/gvsig/fmap/dal/store/h2/H2SpatialSQLBuilder.java
114 114
                }
115 115
                builder.append(identifier(column.getName()));
116 116
                builder.append(" ");
117
                builder.append(sqltype(column.getType(), column.getPrecision(), column.getSize()));
118 117
                if( column.isGeometry() ) {
119
                    int h2geomtype = getH2SpatialGeometryTypeFromGeometryType(
118
                    String h2geomtype = getH2SpatialGeometryTypeFromGeometryType(
120 119
                        column.getGeometryType(), 
121 120
                        column.getGeometrySubtype()
122 121
                    );
123
                    if( h2geomtype>0 ) {
124
                        String constaint;
125
                        if( this.table().has_schema() ) {
126
                            constaint = MessageFormat.format(
127
                                "CHECK ({0}.ST_GEOMETRYTYPECODE({1}) = {2})",
128
                                this.table().getSchema(),
129
                                column.getName(),
130
                                h2geomtype
131
                            );                            
132
                        } else {
133
                            constaint = MessageFormat.format(
134
                                "CHECK (ST_GEOMETRYTYPECODE({0}) = {1})",
135
                                column.getName(),
136
                                h2geomtype
137
                            );
138
                        }
139
                        builder.append(constaint);
140
                    }
122
                    builder.append(h2geomtype);
141 123
                } else {
124
                    builder.append(sqltype(column.getType(), column.getPrecision(), column.getSize()));
142 125
                    if (column.isPrimaryKey()) {
143 126
                        builder.append(" PRIMARY KEY");
144 127
                    }
......
171 154
            return sqls;
172 155
        }
173 156
        
174
        public int getH2SpatialGeometryTypeFromGeometryType(int geomtype, int geomsubtype) {
157
        public String getH2SpatialGeometryTypeFromGeometryType(int geomtype, int geomsubtype) {
175 158
            //
176 159
            // https://github.com/orbisgis/h2gis/wiki/1.-Spatial-data#geometry-columns-view
177 160
            //
178 161
            
179 162
            switch(geomtype) {
180 163
            case Geometry.TYPES.POINT:
181
                return 1;
164
                return "POINT";
182 165
            case Geometry.TYPES.MULTIPOINT:
183
                return 4;
166
                return "MULTIPOINT";
184 167
            case Geometry.TYPES.LINE:
185
                return 2;
168
                return "LINESTRING";
186 169
            case Geometry.TYPES.MULTILINE:
187
                return 5;
170
                return "MULTILINESTRING";
188 171
            case Geometry.TYPES.POLYGON:
189
                return 3;
172
                return "POLYGON";
190 173
            case Geometry.TYPES.MULTIPOLYGON:
191
                return 6;
174
                return "MULTIPOLYGON";
192 175
            default:
193
                return -1;
176
                return "GEOMETRY";
194 177
            }
195 178
        }
196 179
    }

Also available in: Unified diff