MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / update

Method update

CodenameOne/src/com/codename1/properties/SQLMap.java:376–417  ·  view source on GitHub ↗
(PropertyBusinessObject cmp)

Source from the content-addressed store, hash-verified

374 ///
375 /// - `IOException`
376 public void update(PropertyBusinessObject cmp) throws IOException {
377 String pkName = (String) cmp.getPropertyIndex().getMetaDataOfClass("cn1$pk");
378 if (pkName == null) {
379 throw new IOException("Primary key required for update");
380 }
381 String tableName = getTableName(cmp);
382 StringBuilder createStatement = new StringBuilder("UPDATE ");
383 createStatement.append(tableName);
384 createStatement.append(" SET ");
385
386 int count = 0;
387 ArrayList<Object> values = new ArrayList<Object>();
388 for (PropertyBase p : cmp.getPropertyIndex()) {
389 SqlType tp = getSqlType(p);
390 if (tp == SqlType.SQL_EXCLUDE) {
391 continue;
392 }
393 if (count > 0) {
394 createStatement.append(",");
395 }
396 if (p instanceof Property) {
397 values.add(tp.asUpdateInsertValue(p.get(), (Property) p));
398 } else {
399 // TODO
400 values.add(null);
401 }
402 count++;
403 String columnName = getColumnName(p);
404 createStatement.append(columnName);
405 createStatement.append(" = ?");
406 }
407
408 createStatement.append(" WHERE ");
409
410 createStatement.append(pkName);
411 createStatement.append(" = ?");
412
413 Property p = (Property) cmp.getPropertyIndex().getIgnoreCase(pkName);
414 values.add(p.get());
415
416 execute(createStatement.toString(), values.toArray());
417 }
418
419 /// Deletes a table row matching the component
420 ///

Callers

nothing calls this directly

Calls 13

getTableNameMethod · 0.95
appendMethod · 0.95
getSqlTypeMethod · 0.95
addMethod · 0.95
asUpdateInsertValueMethod · 0.95
getMethod · 0.95
getColumnNameMethod · 0.95
executeMethod · 0.95
toStringMethod · 0.95
toArrayMethod · 0.95
getMetaDataOfClassMethod · 0.80
getIgnoreCaseMethod · 0.80

Tested by

no test coverage detected