Search in sources :

Example 1 with OEntity

use of org.odata4j.core.OEntity in project teiid by teiid.

the class ODataUpdateExecution method addAutoGeneretedKeys.

private void addAutoGeneretedKeys() {
    OEntity entity = this.response.getResultsIter().next().getEntity();
    Table table = this.visitor.getEnityTable();
    int cols = table.getPrimaryKey().getColumns().size();
    Class<?>[] columnDataTypes = new Class<?>[cols];
    String[] columnNames = new String[cols];
    // this is typically expected to be an int/long, but we'll be general here.  we may eventual need the type logic off of the metadata importer
    for (int i = 0; i < cols; i++) {
        columnDataTypes[i] = table.getPrimaryKey().getColumns().get(i).getJavaType();
        columnNames[i] = table.getPrimaryKey().getColumns().get(i).getName();
    }
    GeneratedKeys generatedKeys = this.executionContext.getCommandContext().returnGeneratedKeys(columnNames, columnDataTypes);
    List<Object> vals = new ArrayList<Object>(columnDataTypes.length);
    for (int i = 0; i < columnDataTypes.length; i++) {
        OProperty<?> prop = entity.getProperty(columnNames[i]);
        Object value = this.translator.retrieveValue(prop.getValue(), columnDataTypes[i]);
        vals.add(value);
    }
    generatedKeys.addKey(vals);
}
Also used : Table(org.teiid.metadata.Table) ArrayList(java.util.ArrayList) GeneratedKeys(org.teiid.GeneratedKeys) OEntity(org.odata4j.core.OEntity)

Aggregations

ArrayList (java.util.ArrayList)1 OEntity (org.odata4j.core.OEntity)1 GeneratedKeys (org.teiid.GeneratedKeys)1 Table (org.teiid.metadata.Table)1