private void initValues(final RecordDefinition recordDefinition) { if (recordDefinition == null) { this.values = new Object[0]; } else { final int fieldCount = recordDefinition.getFieldCount(); this.values = new Object[fieldCount]; final Map<String, Object> defaultValues = recordDefinition.getDefaultValues(); setValuesByPath(defaultValues); } }
private String getInsertSql(final RecordDefinition type, final boolean generatePrimaryKey) { final PathName typePath = type.getPathName(); final String tableName = this.recordStore.getDatabaseQualifiedTableName(typePath); String sql; if (generatePrimaryKey) { sql = this.typeInsertSequenceSqlMap.get(typePath); } else { sql = this.typeInsertSqlMap.get(typePath); } if (sql == null) { final StringBuilder sqlBuffer = new StringBuilder(); if (this.sqlPrefix != null) { sqlBuffer.append(this.sqlPrefix); } sqlBuffer.append("insert "); if (this.hints != null) { sqlBuffer.append(this.hints); } sqlBuffer.append(" into "); sqlBuffer.append(tableName); sqlBuffer.append(" ("); if (generatePrimaryKey) { final String idFieldName = type.getIdFieldName(); if (this.quoteColumnNames) { sqlBuffer.append('"').append(idFieldName).append('"'); } else { sqlBuffer.append(idFieldName); } sqlBuffer.append(","); } for (int i = 0; i < type.getFieldCount(); i++) { if (!generatePrimaryKey || i != type.getIdFieldIndex()) { final String fieldName = type.getFieldName(i); if (this.quoteColumnNames) { sqlBuffer.append('"').append(fieldName).append('"'); } else { sqlBuffer.append(fieldName); } if (i < type.getFieldCount() - 1) { sqlBuffer.append(", "); } } } sqlBuffer.append(") VALUES ("); if (generatePrimaryKey) { sqlBuffer.append(getGeneratePrimaryKeySql(type)); sqlBuffer.append(","); } for (int i = 0; i < type.getFieldCount(); i++) { if (!generatePrimaryKey || i != type.getIdFieldIndex()) { final JdbcFieldDefinition attribute = (JdbcFieldDefinition) type.getField(i); attribute.addInsertStatementPlaceHolder(sqlBuffer, generatePrimaryKey); if (i < type.getFieldCount() - 1) { sqlBuffer.append(", "); } } } sqlBuffer.append(")"); if (this.sqlSuffix != null) { sqlBuffer.append(this.sqlSuffix); } sql = sqlBuffer.toString(); if (generatePrimaryKey) { this.typeInsertSequenceSqlMap.put(typePath, sql); } else { this.typeInsertSqlMap.put(typePath, sql); } } return sql; }