Package org.apache.metamodel.data

Examples of org.apache.metamodel.data.CachingDataSetHeader


    @Override
    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {

        List<Row> rows = new ArrayList<Row>();
        SelectItem[] items = MetaModelHelper.createSelectItems(columns);
        CachingDataSetHeader header = new CachingDataSetHeader(items);

        for (final Object[] values : _values) {
            Object[] rowValues = new Object[columns.length];
            for (int i = 0; i < columns.length; i++) {
                int columnNumber = columns[i].getColumnNumber();
View Full Code Here


        });
    }

    private void delete(List<FilterItem> whereItems) {
        final SelectItem[] selectItems = MetaModelHelper.createSelectItems(_table.getColumns());
        final CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
        for (Iterator<Object[]> it = _values.iterator(); it.hasNext();) {
            Object[] values = (Object[]) it.next();
            DefaultRow row = new DefaultRow(header, values);
            boolean delete = true;
            for (FilterItem filterItem : whereItems) {
View Full Code Here

            throw new IllegalStateException("No such table name: '" + table.getName() + "'. Valid table names are: "
                    + _tableData.keySet());
        }

        final SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
        final DataSetHeader header = new CachingDataSetHeader(selectItems);

        final List<Row> resultData = new ArrayList<Row>();
        for (Object[] tableDataRow : tableData) {
            if (maxRows == 0) {
                break;
View Full Code Here

    @Override
    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
        final DocumentConverter documentConverter = _schemaBuilder.getDocumentConverter(table);
        final SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
        final DataSetHeader header = new CachingDataSetHeader(selectItems);
        final DocumentSource documentSource = getDocumentSourceForTable(table.getName());

        DataSet dataSet = new DocumentSourceDataSet(header, documentSource, documentConverter);

        if (maxRows > 0) {
View Full Code Here

            throw new IllegalStateException("No such table name: '" + table.getName() + "'. Valid table names are: "
                    + _tableData.keySet());
        }

        final SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
        final DataSetHeader header = new CachingDataSetHeader(selectItems);

        final List<Row> resultData = new ArrayList<Row>();
        for (Object[] tableDataRow : tableData) {
            if (maxRows == 0) {
                break;
View Full Code Here

        if (data.isEmpty()) {
            return new EmptyDataSet(selectItems);
        }

        final DataSetHeader header = new CachingDataSetHeader(selectItems);
        final List<Row> rows = new ArrayList<Row>(data.size());
        for (Object[] objects : data) {
            rows.add(new DefaultRow(header, objects, null));
        }
View Full Code Here

            final SelectItem[] groupBySelects = new SelectItem[groupByItems.length];
            for (int i = 0; i < groupBySelects.length; i++) {
                groupBySelects[i] = groupByItems[i].getSelectItem();
            }
            final DataSetHeader groupByHeader = new CachingDataSetHeader(groupBySelects);

            // Creates a list of SelectItems that have functions
            List<SelectItem> functionItems = getFunctionSelectItems(selectItems);

            // Loop through the dataset and identify groups
            while (dataSet.next()) {
                Row row = dataSet.getRow();

                // Subselect a row prototype with only the unique values that
                // define the group
                Row uniqueRow = row.getSubSelection(groupByHeader);

                // function input is the values used for calculating aggregate
                // functions in the group
                Map<SelectItem, List<Object>> functionInput;
                if (!uniqueRows.containsKey(uniqueRow)) {
                    // If this group already exist, use an existing function
                    // input
                    functionInput = new HashMap<SelectItem, List<Object>>();
                    for (SelectItem item : functionItems) {
                        functionInput.put(item, new ArrayList<Object>());
                    }
                    uniqueRows.put(uniqueRow, functionInput);
                } else {
                    // If this is a new group, create a new function input
                    functionInput = uniqueRows.get(uniqueRow);
                }

                // Loop through aggregate functions to check for validity
                for (SelectItem item : functionItems) {
                    List<Object> objects = functionInput.get(item);
                    Column column = item.getColumn();
                    if (column != null) {
                        Object value = row.getValue(new SelectItem(column));
                        objects.add(value);
                    } else if (SelectItem.isCountAllItem(item)) {
                        // Just use the empty string, since COUNT(*) don't
                        // evaluate values (but null values should be prevented)
                        objects.add("");
                    } else {
                        throw new IllegalArgumentException("Expression function not supported: " + item);
                    }
                }
            }

            dataSet.close();
            final List<Row> resultData = new ArrayList<Row>();
            final DataSetHeader resultHeader = new CachingDataSetHeader(selectItems);

            // Loop through the groups to generate aggregates
            for (Entry<Row, Map<SelectItem, List<Object>>> entry : uniqueRows.entrySet()) {
                Row row = entry.getKey();
                Map<SelectItem, List<Object>> functionInput = entry.getValue();
View Full Code Here

        final DataSetHeader header;
        final boolean onlyAggregates;
        if (functionItems.size() != workSelectItems.size()) {
            onlyAggregates = false;
            header = new CachingDataSetHeader(workSelectItems);
        } else {
            onlyAggregates = true;
            header = new SimpleDataSetHeader(workSelectItems);
        }
View Full Code Here

            // no need to join, simply return a new view (with null values) on
            // the previous dataset.
            return getSelection(selectItems, ds1);
        }

        final DataSetHeader header = new CachingDataSetHeader(selectItems);

        while (ds1.next()) {

            // Construct a single-row dataset for making a carthesian product
            // against ds2
            Row ds1row = ds1.getRow();
            List<Row> ds1rows = new ArrayList<Row>();
            ds1rows.add(ds1row);

            DataSet carthesianProduct = getCarthesianProduct(new DataSet[] {
                    new InMemoryDataSet(new CachingDataSetHeader(si1), ds1rows),
                    new InMemoryDataSet(new CachingDataSetHeader(si2), ds2data) }, onConditions);
            List<Row> carthesianRows = readDataSetFull(carthesianProduct);
            if (carthesianRows.size() > 0) {
                resultRows.addAll(carthesianRows);
            } else {
                Object[] values = ds1row.getValues();
View Full Code Here

    @Override
    protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
        if (_tableName.equals(table.getName())) {
            final SelectItem[] allSelectItems = MetaModelHelper.createSelectItems(table.getColumns());
            final DataSetHeader header = new CachingDataSetHeader(allSelectItems);
            final List<Row> data = new ArrayList<Row>();
            data.add(new DefaultRow(header, new Object[] { "1", "hello", "world" }, null));
            data.add(new DefaultRow(header, new Object[] { "2", _value, "world" }, null));
            data.add(new DefaultRow(header, new Object[] { "3", "hi", _value }, null));
            data.add(new DefaultRow(header, new Object[] { "4", "yo", "world" }, null));
View Full Code Here

TOP

Related Classes of org.apache.metamodel.data.CachingDataSetHeader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.