Revision 43739 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 | ||
---|---|---|
31 | 31 |
import org.gvsig.fmap.dal.SQLBuilder.UpdateBuilder; |
32 | 32 |
import org.gvsig.fmap.dal.SQLBuilder.UpdateColumnBuilder; |
33 | 33 |
import org.gvsig.fmap.dal.SQLBuilder.UpdateTableStatisticsBuilder; |
34 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
34 | 35 |
import org.gvsig.fmap.dal.feature.spi.ExpressionBuilderBase.AbstractValue; |
35 | 36 |
import org.gvsig.fmap.geom.Geometry; |
36 | 37 |
import org.slf4j.Logger; |
... | ... | |
52 | 53 |
protected CreateIndexBuilder create_index; |
53 | 54 |
protected List<Parameter> parameters; |
54 | 55 |
|
55 |
protected class ColumnDescriptorBuilderBase implements ColumnDescriptorBuilder { |
|
56 |
|
|
57 |
private String name; |
|
58 |
private int type; |
|
59 |
private int type_p; |
|
60 |
private int type_s; |
|
61 |
private boolean isPk; |
|
62 |
private boolean _allowNulls; |
|
63 |
private boolean _isAutomatic; |
|
64 |
private Object defaultValue; |
|
65 |
private int geom_type; |
|
66 |
private int geom_subtype; |
|
67 |
private Object geom_srsdbcode; |
|
68 |
private boolean _isIndexed; |
|
69 |
|
|
70 |
public ColumnDescriptorBuilderBase(String name, int type, Object defaultValue) { |
|
71 |
this.name = name; |
|
72 |
this.type = type; |
|
73 |
this.type_p = -1; |
|
74 |
this.type_s = -1; |
|
75 |
this.isPk = false; |
|
76 |
this._allowNulls = true; |
|
77 |
this._isAutomatic = false; |
|
78 |
this.defaultValue = defaultValue; |
|
79 |
this.geom_type = Geometry.TYPES.GEOMETRY; |
|
80 |
this.geom_subtype = Geometry.SUBTYPES.GEOM2D; |
|
81 |
this.geom_srsdbcode = null; |
|
82 |
this._isIndexed = false; |
|
83 |
} |
|
84 |
|
|
85 |
public ColumnDescriptorBuilderBase(String name, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue) { |
|
86 |
this.name = name; |
|
87 |
this.type = type; |
|
88 |
this.type_p = type_p; |
|
89 |
this.type_s = type_s; |
|
90 |
this.isPk = isPk; |
|
91 |
this._allowNulls = allowNulls; |
|
92 |
this._isAutomatic = isAutomatic; |
|
93 |
this.defaultValue = defaultValue; |
|
94 |
this.geom_type = Geometry.TYPES.GEOMETRY; |
|
95 |
this.geom_subtype = Geometry.SUBTYPES.GEOM2D; |
|
96 |
this.geom_srsdbcode = null; |
|
97 |
this._isIndexed = isIndexed; |
|
98 |
} |
|
99 |
|
|
100 |
public ColumnDescriptorBuilderBase(String name, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls) { |
|
101 |
this.name = name; |
|
102 |
this.type = DataTypes.GEOMETRY; |
|
103 |
this.type_p = 0; |
|
104 |
this.type_s = 0; |
|
105 |
this.isPk = false; |
|
106 |
this._allowNulls = allowNulls; |
|
107 |
this._isAutomatic = false; |
|
108 |
this.defaultValue = null; |
|
109 |
this.geom_type = geom_type; |
|
110 |
this.geom_subtype = geom_subtype; |
|
111 |
this.geom_srsdbcode = getSRSId(proj); |
|
112 |
this._isIndexed = isIndexed; |
|
113 |
} |
|
114 |
|
|
115 |
public ColumnDescriptorBuilderBase(String name, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls) { |
|
116 |
this.name = name; |
|
117 |
this.type = DataTypes.GEOMETRY; |
|
118 |
this.type_p = 0; |
|
119 |
this.type_s = 0; |
|
120 |
this.isPk = false; |
|
121 |
this._allowNulls = allowNulls; |
|
122 |
this._isAutomatic = false; |
|
123 |
this.defaultValue = null; |
|
124 |
this.geom_type = geom_type; |
|
125 |
this.geom_subtype = geom_subtype; |
|
126 |
this.geom_srsdbcode = srsdbcode; |
|
127 |
this._isIndexed = isIndexed; |
|
128 |
} |
|
129 |
|
|
130 |
@Override |
|
131 |
public String getName() { |
|
132 |
return this.name; |
|
133 |
} |
|
134 |
|
|
135 |
@Override |
|
136 |
public void setName(String name) { |
|
137 |
this.name = name; |
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 |
public int getType() { |
|
142 |
return this.type; |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public void setType(int type) { |
|
147 |
this.type = type; |
|
148 |
} |
|
149 |
|
|
150 |
@Override |
|
151 |
public int getPrecision() { |
|
152 |
return type_p; |
|
153 |
} |
|
154 |
|
|
155 |
@Override |
|
156 |
public void setPrecision(int precision) { |
|
157 |
this.type_p = precision; |
|
158 |
} |
|
159 |
|
|
160 |
@Override |
|
161 |
public int getSize() { |
|
162 |
return type_s; |
|
163 |
} |
|
164 |
|
|
165 |
@Override |
|
166 |
public void setSize(int size) { |
|
167 |
this.type_s = size; |
|
168 |
} |
|
169 |
|
|
170 |
@Override |
|
171 |
public boolean isPrimaryKey() { |
|
172 |
return isPk; |
|
173 |
} |
|
174 |
|
|
175 |
@Override |
|
176 |
public void setIsPrimaryKey(boolean isPk) { |
|
177 |
this.isPk = isPk; |
|
178 |
} |
|
179 |
|
|
180 |
@Override |
|
181 |
public boolean allowNulls() { |
|
182 |
return _allowNulls; |
|
183 |
} |
|
184 |
|
|
185 |
@Override |
|
186 |
public void setAllowNulls(boolean allowNulls) { |
|
187 |
this._allowNulls = allowNulls; |
|
188 |
} |
|
189 |
|
|
190 |
@Override |
|
191 |
public boolean isAutomatic() { |
|
192 |
return _isAutomatic; |
|
193 |
} |
|
194 |
|
|
195 |
@Override |
|
196 |
public boolean isIndexed() { |
|
197 |
return _isIndexed; |
|
198 |
} |
|
199 |
|
|
200 |
@Override |
|
201 |
public void setIsAutomatic(boolean isAutomatic) { |
|
202 |
this._isAutomatic = isAutomatic; |
|
203 |
} |
|
204 |
|
|
205 |
@Override |
|
206 |
public Object getDefaultValue() { |
|
207 |
return defaultValue; |
|
208 |
} |
|
209 |
|
|
210 |
@Override |
|
211 |
public void setDefaultValue(Object defaultValue) { |
|
212 |
this.defaultValue = defaultValue; |
|
213 |
} |
|
214 |
|
|
215 |
@Override |
|
216 |
public int getGeometryType() { |
|
217 |
return geom_type; |
|
218 |
} |
|
219 |
|
|
220 |
@Override |
|
221 |
public void setGeometryType(int geom_type) { |
|
222 |
this.geom_type = geom_type; |
|
223 |
} |
|
224 |
|
|
225 |
@Override |
|
226 |
public int getGeometrySubtype() { |
|
227 |
return geom_subtype; |
|
228 |
} |
|
229 |
|
|
230 |
@Override |
|
231 |
public void setGeometrySubtype(int geom_subtype) { |
|
232 |
this.geom_subtype = geom_subtype; |
|
233 |
} |
|
234 |
|
|
235 |
@Override |
|
236 |
public Object getGeometrySRSId() { |
|
237 |
return geom_srsdbcode; |
|
238 |
} |
|
239 |
|
|
240 |
@Override |
|
241 |
public void setGeometrySRSId(Object geom_srsid) { |
|
242 |
this.geom_srsdbcode = geom_srsid; |
|
243 |
} |
|
244 |
|
|
245 |
@Override |
|
246 |
public boolean isGeometry() { |
|
247 |
return this.type == DataTypes.GEOMETRY; |
|
248 |
} |
|
249 |
|
|
250 |
} |
|
251 |
|
|
252 |
|
|
253 | 56 |
public class TableNameBuilderBase implements TableNameBuilder { |
254 | 57 |
|
255 | 58 |
public String tableName; |
... | ... | |
1309 | 1112 |
|
1310 | 1113 |
protected TableNameBuilder table; |
1311 | 1114 |
protected List<String> drops; |
1312 |
protected List<ColumnDescriptorBuilderBase> adds;
|
|
1313 |
protected List<ColumnDescriptorBuilderBase> alters;
|
|
1115 |
protected List<ColumnDescriptor> adds; |
|
1116 |
protected List<ColumnDescriptor> alters; |
|
1314 | 1117 |
protected List<Pair<String,String>> renames; |
1315 | 1118 |
|
1316 | 1119 |
public AlterTableBuilderBase() { |
... | ... | |
1351 | 1154 |
this.drops.add(columnName); |
1352 | 1155 |
return this; |
1353 | 1156 |
} |
1157 |
|
|
1158 |
@Override |
|
1159 |
public AlterTableBuilder add_column(FeatureAttributeDescriptor fad) { |
|
1160 |
this.adds.add(column(fad).getDescriptor()); |
|
1161 |
return this; |
|
1162 |
} |
|
1354 | 1163 |
|
1355 | 1164 |
@Override |
1356 | 1165 |
public AlterTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue) { |
1357 | 1166 |
if (isPk || isAutomatic) { |
1358 | 1167 |
allowNulls = false; |
1359 | 1168 |
} |
1360 |
this.adds.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, isIndexed, allowNulls, isAutomatic, defaultValue));
|
|
1169 |
this.adds.add(new ColumnDescriptorBase(columnName, type, type_p, type_s, isPk, isIndexed, allowNulls, isAutomatic, defaultValue)); |
|
1361 | 1170 |
return this; |
1362 | 1171 |
} |
1363 | 1172 |
|
... | ... | |
1366 | 1175 |
if( StringUtils.isEmpty(columnName) ) { |
1367 | 1176 |
throw new IllegalArgumentException("Argument 'columnName' can't be empty."); |
1368 | 1177 |
} |
1369 |
this.adds.add(new ColumnDescriptorBuilderBase(columnName, type, subtype, proj, isIndexed, allowNulls));
|
|
1178 |
this.adds.add(new ColumnDescriptorBase(columnName, type, subtype, proj, isIndexed, allowNulls)); |
|
1370 | 1179 |
return this; |
1371 | 1180 |
} |
1372 | 1181 |
|
... | ... | |
1375 | 1184 |
if( StringUtils.isEmpty(columnName) ) { |
1376 | 1185 |
throw new IllegalArgumentException("Argument 'columnName' can't be empty."); |
1377 | 1186 |
} |
1378 |
this.adds.add(new ColumnDescriptorBuilderBase(columnName, type, subtype, srsdbcode, isIndexed, allowNulls));
|
|
1187 |
this.adds.add(new ColumnDescriptorBase(columnName, type, subtype, srsdbcode, isIndexed, allowNulls)); |
|
1379 | 1188 |
return this; |
1380 | 1189 |
} |
1381 |
|
|
1190 |
|
|
1382 | 1191 |
@Override |
1192 |
public AlterTableBuilder alter_column(FeatureAttributeDescriptor fad) { |
|
1193 |
this.alters.add(column(fad).getDescriptor()); |
|
1194 |
return this; |
|
1195 |
} |
|
1196 |
|
|
1197 |
@Override |
|
1383 | 1198 |
public AlterTableBuilder alter_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue) { |
1384 | 1199 |
if (isPk || isAutomatic) { |
1385 | 1200 |
allowNulls = false; |
1386 | 1201 |
} |
1387 |
this.alters.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, isIndexed, allowNulls, isAutomatic, defaultValue));
|
|
1202 |
this.alters.add(new ColumnDescriptorBase(columnName, type, type_p, type_s, isPk, isIndexed, allowNulls, isAutomatic, defaultValue)); |
|
1388 | 1203 |
return this; |
1389 | 1204 |
} |
1390 | 1205 |
|
... | ... | |
1393 | 1208 |
if( StringUtils.isEmpty(columnName) ) { |
1394 | 1209 |
throw new IllegalArgumentException("Argument 'columnName' can't be empty."); |
1395 | 1210 |
} |
1396 |
this.alters.add(new ColumnDescriptorBuilderBase(columnName, type, subtype, proj, isIndexed, allowNulls));
|
|
1211 |
this.alters.add(new ColumnDescriptorBase(columnName, type, subtype, proj, isIndexed, allowNulls)); |
|
1397 | 1212 |
return this; |
1398 | 1213 |
} |
1399 | 1214 |
|
... | ... | |
1402 | 1217 |
if( StringUtils.isEmpty(columnName) ) { |
1403 | 1218 |
throw new IllegalArgumentException("Argument 'columnName' can't be empty."); |
1404 | 1219 |
} |
1405 |
this.alters.add(new ColumnDescriptorBuilderBase(columnName, type, subtype, srsdbcode, isIndexed, allowNulls));
|
|
1220 |
this.alters.add(new ColumnDescriptorBase(columnName, type, subtype, srsdbcode, isIndexed, allowNulls)); |
|
1406 | 1221 |
return this; |
1407 | 1222 |
} |
1408 | 1223 |
|
... | ... | |
1444 | 1259 |
builder.append(identifier(column)); |
1445 | 1260 |
sqls.add(builder.toString()); |
1446 | 1261 |
} |
1447 |
for (ColumnDescriptorBuilderBase column : adds) {
|
|
1262 |
for (ColumnDescriptor column : adds) { |
|
1448 | 1263 |
StringBuilder builder = new StringBuilder(); |
1449 | 1264 |
builder.append("ALTER TABLE "); |
1450 | 1265 |
builder.append(this.table.toString()); |
... | ... | |
1483 | 1298 |
} |
1484 | 1299 |
sqls.add(builder.toString()); |
1485 | 1300 |
} |
1486 |
for (ColumnDescriptorBuilderBase column : alters) {
|
|
1301 |
for (ColumnDescriptor column : alters) { |
|
1487 | 1302 |
StringBuilder builder = new StringBuilder(); |
1488 | 1303 |
builder.append("ALTER TABLE "); |
1489 | 1304 |
builder.append(this.table.toString()); |
... | ... | |
1534 | 1349 |
public class CreateTableBuilderBase implements CreateTableBuilder { |
1535 | 1350 |
|
1536 | 1351 |
protected TableNameBuilder table; |
1537 |
protected List<ColumnDescriptorBuilderBase> columns;
|
|
1352 |
protected List<ColumnDescriptor> columns; |
|
1538 | 1353 |
|
1539 | 1354 |
public CreateTableBuilderBase() { |
1540 | 1355 |
this.columns = new ArrayList<>(); |
... | ... | |
1559 | 1374 |
} |
1560 | 1375 |
|
1561 | 1376 |
@Override |
1377 |
public CreateTableBuilderBase add_column(FeatureAttributeDescriptor fad) { |
|
1378 |
this.columns.add(column(fad).getDescriptor()); |
|
1379 |
return this; |
|
1380 |
} |
|
1381 |
|
|
1382 |
@Override |
|
1562 | 1383 |
public CreateTableBuilderBase add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue) { |
1563 | 1384 |
if( StringUtils.isEmpty(columnName) ) { |
1564 | 1385 |
throw new IllegalArgumentException("Argument 'columnName' can't be empty."); |
... | ... | |
1566 | 1387 |
if (isPk || isAutomatic) { |
1567 | 1388 |
allowNulls = false; |
1568 | 1389 |
} |
1569 |
this.columns.add(new ColumnDescriptorBuilderBase(columnName, type, type_p, type_s, isPk, isIndexed, allowNulls, isAutomatic, defaultValue));
|
|
1390 |
this.columns.add(new ColumnDescriptorBase(columnName, type, type_p, type_s, isPk, isIndexed, allowNulls, isAutomatic, defaultValue)); |
|
1570 | 1391 |
return this; |
1571 | 1392 |
} |
1572 | 1393 |
|
... | ... | |
1575 | 1396 |
if( StringUtils.isEmpty(columnName) ) { |
1576 | 1397 |
throw new IllegalArgumentException("Argument 'columnName' can't be empty."); |
1577 | 1398 |
} |
1578 |
this.columns.add(new ColumnDescriptorBuilderBase(columnName, type, subtype, proj, isIndexed, allowNulls));
|
|
1399 |
this.columns.add(new ColumnDescriptorBase(columnName, type, subtype, proj, isIndexed, allowNulls)); |
|
1579 | 1400 |
return this; |
1580 | 1401 |
} |
1581 | 1402 |
|
... | ... | |
1584 | 1405 |
if( StringUtils.isEmpty(columnName) ) { |
1585 | 1406 |
throw new IllegalArgumentException("Argument 'columnName' can't be empty."); |
1586 | 1407 |
} |
1587 |
this.columns.add(new ColumnDescriptorBuilderBase(columnName, type, subtype, srsdbcode, isIndexed, allowNulls));
|
|
1408 |
this.columns.add(new ColumnDescriptorBase(columnName, type, subtype, srsdbcode, isIndexed, allowNulls)); |
|
1588 | 1409 |
return this; |
1589 | 1410 |
} |
1590 | 1411 |
|
1591 | 1412 |
@Override |
1592 |
public ColumnDescriptorBuilder getColumnDescriptor(String columnName) {
|
|
1413 |
public ColumnDescriptor getColumnDescriptor(String columnName) { |
|
1593 | 1414 |
if( StringUtils.isEmpty(columnName) ) { |
1594 | 1415 |
return null; |
1595 | 1416 |
} |
1596 |
for (ColumnDescriptorBuilderBase column : columns) {
|
|
1417 |
for (ColumnDescriptor column : columns) { |
|
1597 | 1418 |
if( columnName.equals(column.getName()) ) { |
1598 | 1419 |
return column; |
1599 | 1420 |
} |
... | ... | |
1653 | 1474 |
builder.append(this.table.toString()); |
1654 | 1475 |
builder.append(" ("); |
1655 | 1476 |
boolean first = true; |
1656 |
for (ColumnDescriptorBuilderBase column : columns) {
|
|
1477 |
for (ColumnDescriptor column : columns) { |
|
1657 | 1478 |
if (first) { |
1658 | 1479 |
first = false; |
1659 | 1480 |
} else { |
Also available in: Unified diff