Revision 43362 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/PerformChangesOperation.java
PerformChangesOperation.java | ||
---|---|---|
65 | 65 |
public final Object perform(Connection conn) throws DataException { |
66 | 66 |
if (featureTypesChanged.hasNext()) { |
67 | 67 |
FeatureStoreProvider.FeatureTypeChanged item = featureTypesChanged.next(); |
68 |
this.performUpdateTable(conn, tableName, item.getSource(), item.getTarget()); |
|
68 |
this.performUpdateTable(conn, dbName, schemaName, tableName, item.getSource(), item.getTarget());
|
|
69 | 69 |
typeChanged = true; |
70 | 70 |
} else { |
71 | 71 |
typeChanged = false; |
... | ... | |
82 | 82 |
return true; |
83 | 83 |
} |
84 | 84 |
|
85 |
public void performDeletes(Connection conn,
|
|
85 |
protected JDBCSQLBuilderBase buildDeleteSQL(
|
|
86 | 86 |
String database, |
87 | 87 |
String schema, |
88 | 88 |
String table, |
89 |
FeatureType type, |
|
90 |
Iterator<FeatureReferenceProviderServices> deleteds) throws DataException { |
|
91 |
|
|
92 |
JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder(); |
|
89 |
FeatureType type |
|
90 |
) { |
|
91 |
JDBCSQLBuilderBase sqlbuilder = createSQLBuilder(); |
|
93 | 92 |
sqlbuilder.delete().table().database(database).schema(schema).name(table); |
94 | 93 |
for (FeatureAttributeDescriptor attr : type) { |
95 | 94 |
if (attr.isPrimaryKey()) { |
... | ... | |
104 | 103 |
if (!sqlbuilder.delete().has_where() ) { |
105 | 104 |
throw new RuntimeException("Operation requires missing pk"); |
106 | 105 |
} |
106 |
return sqlbuilder; |
|
107 |
} |
|
107 | 108 |
|
109 |
public void performDeletes(Connection conn, |
|
110 |
String database, |
|
111 |
String schema, |
|
112 |
String table, |
|
113 |
FeatureType type, |
|
114 |
Iterator<FeatureReferenceProviderServices> deleteds) throws DataException { |
|
115 |
|
|
116 |
JDBCSQLBuilderBase sqlbuilder = buildDeleteSQL(database, schema, table, type); |
|
117 |
|
|
108 | 118 |
PreparedStatement st = null; |
109 | 119 |
String sql = sqlbuilder.delete().toString(); |
110 | 120 |
try { |
... | ... | |
131 | 141 |
JDBCUtils.closeQuietly(st); |
132 | 142 |
} |
133 | 143 |
} |
134 |
|
|
135 |
public void performInserts(Connection conn,
|
|
144 |
|
|
145 |
protected JDBCSQLBuilderBase buildInsertSQL(
|
|
136 | 146 |
String database, |
137 | 147 |
String schema, |
138 | 148 |
String table, |
139 |
FeatureType type,
|
|
140 |
Iterator<FeatureProvider> inserteds) throws DataException {
|
|
149 |
FeatureType type |
|
150 |
) {
|
|
141 | 151 |
JDBCSQLBuilderBase sqlbuilder = createSQLBuilder(); |
142 | 152 |
|
143 | 153 |
sqlbuilder.insert().table().database(database).schema(schema).name(table); |
144 | 154 |
for (FeatureAttributeDescriptor attr : type) { |
155 |
if( attr.isAutomatic() ) { |
|
156 |
continue; |
|
157 |
} |
|
145 | 158 |
if (attr.getType() == DataTypes.GEOMETRY) { |
146 | 159 |
sqlbuilder.insert().column().name(attr.getName()).with_value( |
147 | 160 |
sqlbuilder.parameter(attr.getName()).as_geometry_variable().srs( |
... | ... | |
154 | 167 |
); |
155 | 168 |
} |
156 | 169 |
} |
170 |
return sqlbuilder; |
|
171 |
} |
|
157 | 172 |
|
173 |
public void performInserts(Connection conn, |
|
174 |
String database, |
|
175 |
String schema, |
|
176 |
String table, |
|
177 |
FeatureType type, |
|
178 |
Iterator<FeatureProvider> inserteds) throws DataException { |
|
179 |
JDBCSQLBuilderBase sqlbuilder = buildInsertSQL(database, schema, table, type); |
|
180 |
|
|
158 | 181 |
PreparedStatement st; |
159 | 182 |
String sql = sqlbuilder.insert().toString(); |
160 | 183 |
try { |
... | ... | |
177 | 200 |
} |
178 | 201 |
} |
179 | 202 |
|
180 |
public void performUpdates(Connection conn,
|
|
203 |
protected JDBCSQLBuilderBase buildUpdateSQL(
|
|
181 | 204 |
String database, |
182 | 205 |
String schema, |
183 | 206 |
String table, |
184 |
FeatureType type, |
|
185 |
Iterator<FeatureProvider> updateds) throws DataException { |
|
207 |
FeatureType type |
|
208 |
) { |
|
209 |
JDBCSQLBuilderBase sqlbuilder = createSQLBuilder(); |
|
186 | 210 |
|
187 |
JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder(); |
|
188 | 211 |
sqlbuilder.update().table().database(database).schema(schema).name(table); |
189 | 212 |
for (FeatureAttributeDescriptor attr : type) { |
190 | 213 |
if (attr.isPrimaryKey()) { |
... | ... | |
211 | 234 |
if (!sqlbuilder.update().has_where() ) { |
212 | 235 |
throw new RuntimeException("Operation requires missing pk"); |
213 | 236 |
} |
237 |
return sqlbuilder; |
|
238 |
} |
|
239 |
|
|
240 |
public void performUpdates(Connection conn, |
|
241 |
String database, |
|
242 |
String schema, |
|
243 |
String table, |
|
244 |
FeatureType type, |
|
245 |
Iterator<FeatureProvider> updateds) throws DataException { |
|
214 | 246 |
|
247 |
JDBCSQLBuilderBase sqlbuilder = buildUpdateSQL(database, schema, table, type); |
|
248 |
|
|
215 | 249 |
PreparedStatement st = null; |
216 | 250 |
String sql = sqlbuilder.update().toString(); |
217 | 251 |
try { |
... | ... | |
230 | 264 |
} |
231 | 265 |
} |
232 | 266 |
|
233 |
public void performUpdateTable(Connection conn, |
|
267 |
protected JDBCSQLBuilderBase buildUpdateTableSQL( |
|
268 |
String database, |
|
269 |
String schema, |
|
234 | 270 |
String table, |
235 | 271 |
FeatureType original, |
236 |
FeatureType target) throws DataException { |
|
272 |
FeatureType target |
|
273 |
) { |
|
274 |
JDBCSQLBuilderBase sqlbuilder = createSQLBuilder(); |
|
275 |
sqlbuilder.update().table().database(database).schema(schema).name(table); |
|
237 | 276 |
|
238 |
SQLBuilderBase sqlbuilder = createSQLBuilder(); |
|
239 |
sqlbuilder.update().table().name(table); |
|
240 |
|
|
241 | 277 |
for (FeatureAttributeDescriptor attrOrgiginal : original) { |
242 | 278 |
FeatureAttributeDescriptor attrTarget = target.getAttributeDescriptor( |
243 | 279 |
attrOrgiginal.getName() |
... | ... | |
273 | 309 |
); |
274 | 310 |
} |
275 | 311 |
} |
312 |
return sqlbuilder; |
|
313 |
} |
|
314 |
|
|
315 |
public void performUpdateTable(Connection conn, |
|
316 |
String database, |
|
317 |
String schema, |
|
318 |
String table, |
|
319 |
FeatureType original, |
|
320 |
FeatureType target) throws DataException { |
|
321 |
|
|
322 |
SQLBuilderBase sqlbuilder = buildUpdateTableSQL(null, null, table, original, target); |
|
276 | 323 |
Statement st = null; |
277 | 324 |
try { |
278 | 325 |
st = conn.createStatement(); |
Also available in: Unified diff