private InsertCommandImpl getCreateCommand()

in rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java [89:119]


    private InsertCommandImpl getCreateCommand(DataObject changedObject) {
    	InsertCommandImpl command = null;
        if (createCommand == null) {
            Table table = mapping.getTableByTypeName(changedObject.getType().getName());
            if (table == null) {
                if (changedObject.getType().getProperty("ID") != null) {
                    // If the table is not defined in the config, assume it has a primary key of "ID"
                    mapping.addPrimaryKey(changedObject.getType().getName() + ".ID");
                    table = mapping.getTableByTypeName(changedObject.getType().getName());
                } else {
                    throw new RuntimeException("Table " + changedObject.getType().getName()
                            + " was changed in the DataGraph but is not present in the Config");
                }
            }

            Create create = table.getCreate();

            if (create == null) {
                command = InsertGenerator.INSTANCE.getInsertCommand(mapping, changedObject, table);
            } else {
            	// command can be cached
                createCommand = new InsertCommandImpl(create);
                command = createCommand;
            }
            command.setConnection(connection);
            command.configWrapper = mapping;
        } else {
        	command = createCommand;
        }
        return command;
    }