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

Method insert

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

Source from the content-addressed store, hash-verified

327 ///
328 /// - `cmp`: the business component
329 public void insert(PropertyBusinessObject cmp) throws IOException {
330 String tableName = getTableName(cmp);
331 StringBuilder createStatement = new StringBuilder("INSERT INTO ");
332 createStatement.append(tableName);
333 createStatement.append(" (");
334
335 int count = 0;
336 ArrayList<Object> values = new ArrayList<Object>();
337 for (PropertyBase p : cmp.getPropertyIndex()) {
338 SqlType tp = getSqlType(p);
339 if (tp == SqlType.SQL_EXCLUDE) {
340 continue;
341 }
342 if (count > 0) {
343 createStatement.append(",");
344 }
345 if (p instanceof Property) {
346 values.add(tp.asUpdateInsertValue(p.get(), (Property) p));
347 } else {
348 // TODO
349 values.add(null);
350 }
351 count++;
352 String columnName = getColumnName(p);
353 createStatement.append(columnName);
354 }
355
356 createStatement.append(") VALUES (?");
357
358 for (int iter = 1; iter < values.size(); iter++) {
359 createStatement.append(",?");
360 }
361
362 createStatement.append(")");
363
364 execute(createStatement.toString(), values.toArray());
365 }
366
367 /// The equivalent of an SQL update assumes that the object is already in the database
368 ///

Callers 1

testInsertMethod · 0.95

Calls 12

getTableNameMethod · 0.95
appendMethod · 0.95
getSqlTypeMethod · 0.95
addMethod · 0.95
asUpdateInsertValueMethod · 0.95
getColumnNameMethod · 0.95
sizeMethod · 0.95
executeMethod · 0.95
toStringMethod · 0.95
toArrayMethod · 0.95
getPropertyIndexMethod · 0.65
getMethod · 0.65

Tested by 1

testInsertMethod · 0.76