| 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 | /// |