Revision 43355 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
SQLBuilderBase.java | ||
---|---|---|
63 | 63 |
private int geom_type; |
64 | 64 |
private int geom_subtype; |
65 | 65 |
private int geom_srsid; |
66 |
private boolean _isIndexed; |
|
66 | 67 |
|
67 | 68 |
public ColumnDescriptorBuilderBase(String name, int type, Object defaultValue) { |
68 | 69 |
this.name = name; |
... | ... | |
76 | 77 |
this.geom_type = Geometry.TYPES.GEOMETRY; |
77 | 78 |
this.geom_subtype = Geometry.SUBTYPES.GEOM2D; |
78 | 79 |
this.geom_srsid = -1; |
80 |
this._isIndexed = false; |
|
79 | 81 |
} |
80 | 82 |
|
81 |
public ColumnDescriptorBuilderBase(String name, int type, int type_p, int type_s, boolean isPk, boolean allowNulls, boolean isAutomatic, Object defaultValue) { |
|
83 |
public ColumnDescriptorBuilderBase(String name, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue) {
|
|
82 | 84 |
this.name = name; |
83 | 85 |
this.type = type; |
84 | 86 |
this.type_p = type_p; |
... | ... | |
90 | 92 |
this.geom_type = Geometry.TYPES.GEOMETRY; |
91 | 93 |
this.geom_subtype = Geometry.SUBTYPES.GEOM2D; |
92 | 94 |
this.geom_srsid = -1; |
95 |
this._isIndexed = isIndexed; |
|
93 | 96 |
} |
94 | 97 |
|
95 |
public ColumnDescriptorBuilderBase(String name, int geom_type, int geom_subtype, IProjection proj, boolean allowNulls) { |
|
98 |
public ColumnDescriptorBuilderBase(String name, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls) {
|
|
96 | 99 |
this.name = name; |
100 |
this.type = DataTypes.GEOMETRY; |
|
97 | 101 |
this.type_p = 0; |
98 | 102 |
this.type_s = 0; |
99 | 103 |
this.isPk = false; |
... | ... | |
103 | 107 |
this.geom_type = geom_type; |
104 | 108 |
this.geom_subtype = geom_subtype; |
105 | 109 |
this.geom_srsid = getSRSId(proj); |
110 |
this._isIndexed = isIndexed; |
|
106 | 111 |
} |
107 | 112 |
|
108 | 113 |
@Override |
... | ... | |
171 | 176 |
} |
172 | 177 |
|
173 | 178 |
@Override |
179 |
public boolean isIndexed() { |
|
180 |
return _isIndexed; |
|
181 |
} |
|
182 |
|
|
183 |
@Override |
|
174 | 184 |
public void setIsAutomatic(boolean isAutomatic) { |
175 | 185 |
this._isAutomatic = isAutomatic; |
176 | 186 |
} |
... | ... | |
247 | 257 |
|
248 | 258 |
@Override |
249 | 259 |
public TableNameBuilder schema(String name) { |
250 |
this.schemaName = name; |
|
260 |
if( supportSchemas() ) { |
|
261 |
this.schemaName = name; |
|
262 |
} |
|
251 | 263 |
return this; |
252 | 264 |
} |
253 | 265 |
|
... | ... | |
274 | 286 |
|
275 | 287 |
@Override |
276 | 288 |
public boolean has_schema() { |
289 |
if( !supportSchemas() ) { |
|
290 |
return false; |
|
291 |
} |
|
277 | 292 |
return !StringUtils.isEmpty(this.schemaName); |
278 | 293 |
} |
279 | 294 |
|
... | ... | |
1216 | 1231 |
} |
1217 | 1232 |
|
1218 | 1233 |
@Override |
1219 |
public AlterTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean allowNulls, boolean isAutomatic, Object defaultValue) { |
|
1234 |
public AlterTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue) {
|
|
1220 | 1235 |
if (isPk || isAutomatic) { |
1221 | 1236 |
allowNulls = false; |
1222 | 1237 |
} |
1223 |
this.adds.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, allowNulls, isAutomatic, defaultValue)); |
|
1238 |
this.adds.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, isIndexed, allowNulls, isAutomatic, defaultValue));
|
|
1224 | 1239 |
return this; |
1225 | 1240 |
} |
1226 | 1241 |
|
1227 | 1242 |
@Override |
1228 |
public AlterTableBuilder alter_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean allowNulls, boolean isAutomatic, Object defaultValue) { |
|
1243 |
public AlterTableBuilder alter_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue) {
|
|
1229 | 1244 |
if (isPk || isAutomatic) { |
1230 | 1245 |
allowNulls = false; |
1231 | 1246 |
} |
1232 |
this.alters.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, allowNulls, isAutomatic, defaultValue)); |
|
1247 |
this.alters.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, isIndexed, allowNulls, isAutomatic, defaultValue));
|
|
1233 | 1248 |
return this; |
1234 | 1249 |
} |
1235 | 1250 |
|
... | ... | |
1443 | 1458 |
} |
1444 | 1459 |
|
1445 | 1460 |
@Override |
1446 |
public CreateTableBuilderBase add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean allowNulls, boolean isAutomatic, Object defaultValue) { |
|
1461 |
public CreateTableBuilderBase add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue) {
|
|
1447 | 1462 |
if( StringUtils.isEmpty(columnName) ) { |
1448 | 1463 |
throw new IllegalArgumentException("Argument 'columnName' can't be empty."); |
1449 | 1464 |
} |
1450 | 1465 |
if (isPk || isAutomatic) { |
1451 | 1466 |
allowNulls = false; |
1452 | 1467 |
} |
1453 |
this.columns.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, allowNulls, isAutomatic, defaultValue)); |
|
1468 |
this.columns.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, isIndexed, allowNulls, isAutomatic, defaultValue));
|
|
1454 | 1469 |
return this; |
1455 | 1470 |
} |
1456 | 1471 |
|
1457 | 1472 |
@Override |
1458 |
public CreateTableBuilder add_geometry_column(String columnName, int type, int subtype, IProjection proj, boolean allowNulls) { |
|
1473 |
public CreateTableBuilder add_geometry_column(String columnName, int type, int subtype, IProjection proj, boolean isIndexed, boolean allowNulls) {
|
|
1459 | 1474 |
if( StringUtils.isEmpty(columnName) ) { |
1460 | 1475 |
throw new IllegalArgumentException("Argument 'columnName' can't be empty."); |
1461 | 1476 |
} |
1462 |
this.columns.add(new ColumnDescriptorBuilderBase(columnName, type, subtype, proj, allowNulls)); |
|
1477 |
this.columns.add(new ColumnDescriptorBuilderBase(columnName, type, subtype, proj, isIndexed, allowNulls));
|
|
1463 | 1478 |
return this; |
1464 | 1479 |
} |
1465 | 1480 |
|
... | ... | |
1563 | 1578 |
} |
1564 | 1579 |
builder.append(" )"); |
1565 | 1580 |
sqls.add(builder.toString()); |
1566 |
|
|
1581 |
for (ColumnDescriptorBuilderBase column : columns) { |
|
1582 |
if( column.isIndexed() ) { |
|
1583 |
String sql; |
|
1584 |
String name = "idx_" + this.table().getName() + column.getName(); |
|
1585 |
if( column.isGeometry() ) { |
|
1586 |
sql = MessageFormat.format( |
|
1587 |
config.getString(SQLConfig.CREATE_INDEX_name_ON_table_USING_GIST_column), |
|
1588 |
name, |
|
1589 |
this.table().toString(), |
|
1590 |
column.getName() |
|
1591 |
); |
|
1592 |
} else { |
|
1593 |
sql = MessageFormat.format( |
|
1594 |
config.getString(SQLConfig.CREATE_INDEX_name_ON_table_column), |
|
1595 |
name, |
|
1596 |
this.table().toString(), |
|
1597 |
column.getName() |
|
1598 |
); |
|
1599 |
} |
|
1600 |
sqls.add(sql); |
|
1601 |
} |
|
1602 |
} |
|
1567 | 1603 |
return sqls; |
1568 | 1604 |
} |
1569 | 1605 |
} |
... | ... | |
1789 | 1825 |
config.set(SQLConfig.UPDATE_TABLE_STATISTICS_table, "VACUUM ANALYZE {0}"); |
1790 | 1826 |
config.set(SQLConfig.DROP_TABLE_table, "DROP TABLE {0}"); |
1791 | 1827 |
config.set(SQLConfig.DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table, "DELETE FROM GEOMETRY_COLUMNS WHERE f_table_schema = {0} AND f_table_name = {1}"); |
1792 |
config.set(SQLConfig.DELETE_GEOMETRY_COLUMN_FROM_TABLE_table, "DELETE FROM GEOMETRY_COLUMNS WHERE f_table_name, {0}");
|
|
1828 |
config.set(SQLConfig.DELETE_GEOMETRY_COLUMN_FROM_TABLE_table, "DELETE FROM GEOMETRY_COLUMNS WHERE f_table_name = {0}");
|
|
1793 | 1829 |
config.set(SQLConfig.UPDATE_table_SET_columnsAndValues_WHERE_expresion, "UPDATE {0} SET {1} WHERE {2}"); |
1794 | 1830 |
config.set(SQLConfig.UPDATE_table_SET_columnsAndValues, "UPDATE {0} SET {1}"); |
1795 |
config.set(SQLConfig.GRANT_privileges_ON_table_TO_role, "GRANT {0} ON {1} TO {2}"); |
|
1831 |
config.set(SQLConfig.GRANT_privileges_ON_table_TO_role, "GRANT {0} ON {1} TO {2}"); |
|
1832 |
config.set(SQLConfig.CREATE_INDEX_name_ON_table_column, "CREATE INDEX {0} ON {1} ({2})"); |
|
1833 |
config.set(SQLConfig.CREATE_INDEX_name_ON_table_USING_GIST_column, "CREATE INDEX {0} ON {1} USING GIST ({2})"); |
|
1796 | 1834 |
} |
1797 | 1835 |
|
1798 | 1836 |
@Override |
1799 | 1837 |
public String default_schema() { |
1800 | 1838 |
return config.getString(SQLConfig.default_schema); |
1801 | 1839 |
} |
1840 |
|
|
1841 |
@Override |
|
1842 |
public boolean supportSchemas() { |
|
1843 |
return config.getBoolean(Config.support_schemas); |
|
1844 |
} |
|
1802 | 1845 |
|
1803 | 1846 |
@Override |
1804 | 1847 |
public String sqltype(int type, int p, int s) { |
... | ... | |
1904 | 1947 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM2DM), "MULTILINESTRINGM"); |
1905 | 1948 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTILINE,Geometry.SUBTYPES.GEOM3DM), "MULTILINESTRINGZM"); |
1906 | 1949 |
|
1950 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTICURVE,Geometry.SUBTYPES.GEOM2D), "MULTILINESTRING"); |
|
1951 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTICURVE,Geometry.SUBTYPES.GEOM3D), "MULTILINESTRINGZ"); |
|
1952 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTICURVE,Geometry.SUBTYPES.GEOM2DM), "MULTILINESTRINGM"); |
|
1953 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTICURVE,Geometry.SUBTYPES.GEOM3DM), "MULTILINESTRINGZM"); |
|
1954 |
|
|
1907 | 1955 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM2D), "MULTIPOLYGON"); |
1908 | 1956 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM3D), "MULTIPOLYGONZ"); |
1909 | 1957 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM2DM), "MULTIPOLYGONM"); |
1910 | 1958 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTIPOLYGON,Geometry.SUBTYPES.GEOM3DM), "MULTIPOLYGONZM"); |
1911 | 1959 |
|
1960 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTISURFACE,Geometry.SUBTYPES.GEOM2D), "MULTIPOLYGON"); |
|
1961 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTISURFACE,Geometry.SUBTYPES.GEOM3D), "MULTIPOLYGONZ"); |
|
1962 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTISURFACE,Geometry.SUBTYPES.GEOM2DM), "MULTIPOLYGONM"); |
|
1963 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.MULTISURFACE,Geometry.SUBTYPES.GEOM3DM), "MULTIPOLYGONZM"); |
|
1964 |
|
|
1912 | 1965 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM2D), "GEOMETRY"); |
1913 | 1966 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM3D), "GEOMETRYZ"); |
1914 | 1967 |
sqlgeometrytypes.put( new ImmutablePair<>(Geometry.TYPES.GEOMETRY,Geometry.SUBTYPES.GEOM2DM), "GEOMETRYM"); |
Also available in: Unified diff