Package org.apache.metamodel.data

Examples of org.apache.metamodel.data.Row


     * @return
     */
    protected static <RB extends RowBuilder<?>> RB convertRow(RB rowBuilder, Map<Column, TypeConverter<?, ?>> converters) {
        Table table = rowBuilder.getTable();
        Column[] columns = table.getColumns();
        Row row = rowBuilder.toRow();
        for (Column column : columns) {
            @SuppressWarnings("unchecked")
            TypeConverter<?, Object> converter = (TypeConverter<?, Object>) converters.get(column);
            if (converter != null) {
                final int indexInRow = row.indexOf(column);
                final Object value = row.getValue(indexInRow);
                final Object physicalValue = converter.toPhysicalValue(value);
                logger.debug("Converted virtual value {} to {}", value, physicalValue);
                if (value == null && physicalValue == null && !rowBuilder.isSet(column)) {
                    logger.debug("Omitting implicit null value for column: {}", column);
                } else {
                    final Style style = row.getStyle(indexInRow);
                    rowBuilder.value(column, physicalValue, style);
                }
            }
        }
        return rowBuilder;
View Full Code Here


        assertEquals(1, dc.getFetchSizeCalculator().getFetchSize(q));

        DataSet ds = dc.executeQuery(q);
        assertTrue(ds.next());
        Row row = ds.getRow();
        assertFalse(ds.next());

        assertEquals(10000, ((Number) row.getValue(0)).intValue());
        int maxAge = ((Number) row.getValue(1)).intValue();
        assertTrue("Maximum age was: " + maxAge, maxAge > 90 && maxAge <= 100);
        int minAge = ((Number) row.getValue(2)).intValue();
        assertTrue("Minimum age was: " + minAge, minAge < 10 && minAge >= 0);

        q = dc.query().from(table).as("t").select(ageColumn).selectCount().where(ageColumn).greaterThan(50).groupBy(ageColumn)
                .toQuery();
        assertEquals("SELECT t.\"AGE\", COUNT(*) FROM PUBLIC.\"TEST_TABLE\" t WHERE t.\"AGE\" > 50 GROUP BY t.\"AGE\"", q.toSql());
View Full Code Here

        assertEquals(3, map.size());
    }

    private static int getCount(DataSet ds) {
        assertTrue(ds.next());
        Row row = ds.getRow();
        assertFalse(ds.next());
        ds.close();

        Number count = (Number) row.getValue(0);
        return count.intValue();
    }
View Full Code Here

        try {
            ds.next();
            fail("Exception expected");
        } catch (InconsistentRowLengthException e) {
            assertEquals("Inconsistent length of row no. 3. Expected 2 columns but found 3.", e.getMessage());
            Row proposedRow = e.getProposedRow();
            assertEquals("[5, 6]", Arrays.toString(proposedRow.getValues()));

            String[] sourceLine = e.getSourceLine();
            assertEquals("[5, 6, 7]", Arrays.toString(sourceLine));
        }

        assertTrue(ds.next());

        try {
            ds.next();
            fail("Exception expected");
        } catch (InconsistentRowLengthException e) {
            assertEquals("Inconsistent length of row no. 5. Expected 2 columns but found 1.", e.getMessage());
            Row proposedRow = e.getProposedRow();
            assertEquals("[10, null]", Arrays.toString(proposedRow.getValues()));

            String[] sourceLine = e.getSourceLine();
            assertEquals("[10]", Arrays.toString(sourceLine));
        }
View Full Code Here

        assertEquals(3, map.size());
    }

    private static int getCount(DataSet ds) {
        assertTrue(ds.next());
        Row row = ds.getRow();
        assertFalse(ds.next());
        ds.close();

        Number count = (Number) row.getValue(0);
        return count.intValue();
    }
View Full Code Here

            dc.executeUpdate(new InsertInto(table).value("id", 1).value("foo", exampleMap).value("bar", exampleList));

            DataSet ds = dc.query().from(table).select("id", "foo", "bar").execute();
            assertTrue(ds.next());
            Row row = ds.getRow();
            assertFalse(ds.next());
            ds.close();

            assertEquals("Row[values=[1, {hello=[world, welt, verden], foo=bar}, [{}, {meta=model, couch=db}]]]",
                    row.toString());
            assertTrue(row.getValue(0) instanceof Integer);
            assertTrue(row.getValue(1) instanceof Map);
            assertTrue(row.getValue(2) instanceof List);

        } finally {
            dc.executeUpdate(new DropTable(table));
        }
View Full Code Here

        assertTrue("Class: " + ds2.getClass().getName(), ds2 instanceof CouchDbDataSet);

        assertTrue(ds1.next());
        assertTrue(ds2.next());

        final Row row1 = ds1.getRow();
        final Row row2 = ds2.getRow();

        assertFalse(ds1.next());
        assertFalse(ds2.next());

        assertEquals("Row[values=[Jane Doe, null]]", row1.toString());
        assertEquals("Row[values=[John Doe, 30]]", row2.toString());

        ds1.close();
        ds2.close();
    }
View Full Code Here

        final DBObject query = createMongoDbQuery(table, whereItems);
        final DBObject resultDBObject = collection.findOne(query);

        DataSetHeader header = new SimpleDataSetHeader(selectItems);

        Row row = MongoDBUtils.toRow(resultDBObject, header);

        return row;
    }
View Full Code Here

                        if (!whereItem.isCompoundFilter() && selectItem != null && selectItem.getColumn() != null) {
                            final Column column = selectItem.getColumn();
                            if (column.isPrimaryKey() && whereItem.getOperator() == OperatorType.EQUALS_TO) {
                                logger.debug("Query is a primary key lookup query. Trying executePrimaryKeyLookupQuery(...)");
                                final Object operand = whereItem.getOperand();
                                final Row row = executePrimaryKeyLookupQuery(table, selectItems, column, operand);
                                if (row == null) {
                                    logger.debug("DataContext did not return any primary key lookup query results. Proceeding with manual lookup.");
                                } else {
                                    final DataSetHeader header = new SimpleDataSetHeader(selectItems);
                                    return new InMemoryDataSet(header, row);
View Full Code Here

            // 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();
                Object[] resultRow = new Object[selectItems.size()];
                // Loop through select items to generate a row
                int i = 0;
                for (SelectItem item : selectItems) {
                    int uniqueRowIndex = row.indexOf(item);
                    if (uniqueRowIndex != -1) {
                        // If there's already a value for the select item in the
                        // row, keep it (it's one of the grouped by columns)
                        resultRow[i] = row.getValue(uniqueRowIndex);
                    } else {
                        // Use the function input to calculate the aggregate
                        // value
                        List<Object> objects = functionInput.get(item);
                        if (objects != null) {
View Full Code Here

TOP

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

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.