Package org.apache.metamodel.data

Examples of org.apache.metamodel.data.DefaultRow


                    final Object value = inputRow.getValue(header.getSelectItem(i));
                    if (value != null) {
                        values[i] = value;
                    }
                }
                resultRows.add(new DefaultRow(header, values));
            }
        }
        dataSet.close();

        // Collect the aggregates
        Map<SelectItem, Object> functionResult = new HashMap<SelectItem, Object>();
        for (SelectItem item : functionItems) {
            AggregateBuilder<?> aggregateBuilder = aggregateBuilders.get(item);
            Object result = aggregateBuilder.getAggregate();
            functionResult.put(item, result);
        }

        // if there are no result rows (no matching records at all), we still
        // need to return a record with the aggregates
        final boolean noResultRows = resultRows.isEmpty();

        if (onlyAggregates || noResultRows) {
            // We will only create a single row with all the aggregates
            Object[] values = new Object[header.size()];
            for (int i = 0; i < header.size(); i++) {
                values[i] = functionResult.get(header.getSelectItem(i));
            }
            Row row = new DefaultRow(header, values);
            resultRows.add(row);
        } else {
            // We will create the aggregates as well as regular values
            for (int i = 0; i < resultRows.size(); i++) {
                Row row = resultRows.get(i);
                Object[] values = row.getValues();
                for (Entry<SelectItem, Object> entry : functionResult.entrySet()) {
                    SelectItem item = entry.getKey();
                    int itemIndex = row.indexOf(item);
                    if (itemIndex != -1) {
                        Object value = entry.getValue();
                        values[itemIndex] = value;
                    }
                }
                resultRows.set(i, new DefaultRow(header, values));
            }
        }

        return new InMemoryDataSet(header, resultRows);
    }
View Full Code Here


                resultRows.addAll(carthesianRows);
            } else {
                Object[] values = ds1row.getValues();
                Object[] row = new Object[selectItems.length];
                System.arraycopy(values, 0, row, 0, values.length);
                resultRows.add(new DefaultRow(header, row));
            }
        }
        ds1.close();

        if (resultRows.isEmpty()) {
View Full Code Here

            }

            @Override
            protected Row executePrimaryKeyLookupQuery(Table table, List<SelectItem> selectItems, Column primaryKeyColumn, Object keyValue) {
                assertEquals("foo", keyValue);
                return new DefaultRow(new SimpleDataSetHeader(selectItems), new Object[] { "hello world" });
            }

            @Override
            protected Schema getMainSchema() throws MetaModelException {
                MutableSchema schema = new MutableSchema(getMainSchemaName());
View Full Code Here

            final SelectItem selectItem = header.getSelectItem(i);
            final String key = selectItem.getColumn().getName();
            final Object value = dbObject.get(key);
            values[i] = toValue(selectItem.getColumn(), value);
        }
        return new DefaultRow(header, values);
    }
View Full Code Here

        SelectItem[] selectItems = new SelectItem[] { s1, s2 };
        SimpleDataSetHeader header = new SimpleDataSetHeader(selectItems);
        Row row;
        FilterItem c;

        row = new DefaultRow(header, new Object[] { "foo", "bar" });
        c = new FilterItem(s1, OperatorType.DIFFERENT_FROM, s2);
        assertTrue(c.evaluate(row));

        row = new DefaultRow(header, new Object[] { "aaa", "bbb" });
        c = new FilterItem(s1, OperatorType.GREATER_THAN, s2);
        assertFalse(c.evaluate(row));

        c = new FilterItem(s1, OperatorType.LESS_THAN, s2);
        assertTrue(c.evaluate(row));

        row = new DefaultRow(header, new Object[] { "aaa", "aaa" });
        c = new FilterItem(s1, OperatorType.EQUALS_TO, s2);
        assertTrue(c.evaluate(row));

        c = new FilterItem(s1, OperatorType.LIKE, s2);
        row = new DefaultRow(header, new Object[] { "foobar", "fo%b%r" });
        assertTrue(c.evaluate(row));

        row = new DefaultRow(header, new Object[] { "foobbdbafsdfr", "fo%b%r" });
        assertTrue(c.evaluate(row));
    }
View Full Code Here

        SelectItem[] selectItems = new SelectItem[] { s1, s2 };
        CachingDataSetHeader header = new CachingDataSetHeader(selectItems);

        FilterItem c = new FilterItem(s1, OperatorType.EQUALS_TO, null);

        Row row = new DefaultRow(header, new Object[] { 1, 1 });
        assertFalse(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { null, 1 });
        assertTrue(c.evaluate(row));

        c = new FilterItem(s1, OperatorType.EQUALS_TO, 1);

        row = new DefaultRow(header, new Object[] { 1, 1 });
        assertTrue(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { null, 1 });
        assertFalse(c.evaluate(row));

        c = new FilterItem(s1, OperatorType.DIFFERENT_FROM, 5);

        row = new DefaultRow(header, new Object[] { 1, 1 });
        assertTrue(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { null, 1 });
        assertTrue(c.evaluate(row));

        c = new FilterItem(s1, OperatorType.GREATER_THAN, s2);

        row = new DefaultRow(header, new Object[] { 5, 1 });
        assertTrue(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { null, 1 });
        assertFalse(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { 1, null });
        assertFalse(c.evaluate(row));

        c = new FilterItem(s1, OperatorType.EQUALS_TO, s2);
        row = new DefaultRow(header, new Object[] { 1, null });
        assertFalse(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { null, null });
        assertTrue(c.evaluate(row));
    }
View Full Code Here

        CachingDataSetHeader header = new CachingDataSetHeader(selectItems);

        long currentTimeMillis = System.currentTimeMillis();
        FilterItem c = new FilterItem(s1, OperatorType.LESS_THAN, new java.sql.Date(currentTimeMillis));

        Row row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis) });
        assertFalse(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis + 10000000) });
        assertFalse(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis - 10000000) });
        assertTrue(c.evaluate(row));
    }
View Full Code Here

        SelectItem[] selectItems = new SelectItem[] { s1 };
        DataSetHeader header = new SimpleDataSetHeader(selectItems);

        FilterItem c = new FilterItem(s1, OperatorType.EQUALS_TO, true);

        Row row = new DefaultRow(header, new Object[] { true });
        assertTrue(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { false });
        assertFalse(c.evaluate(row));

        c = new FilterItem(s1, OperatorType.EQUALS_TO, false);
        row = new DefaultRow(header, new Object[] { true });
        assertFalse(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { false });
        assertTrue(c.evaluate(row));

        c = new FilterItem(s1, OperatorType.GREATER_THAN, false);
        row = new DefaultRow(header, new Object[] { true });
        assertTrue(c.evaluate(row));
        row = new DefaultRow(header, new Object[] { false });
        assertFalse(c.evaluate(row));
    }
View Full Code Here

        FilterItem filter = new FilterItem(c1, c2, c3);
        assertEquals("(Col1 = 'foo' OR Col1 = 'bar' OR Col1 = 'foobar')", filter.toString());

        DataSetHeader header = new SimpleDataSetHeader(new SelectItem[] { s1 });

        assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foo" })));
        assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "bar" })));
        assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foobar" })));

        assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foob" })));
    }
View Full Code Here

        FilterItem filter = new FilterItem(LogicalOperator.AND, c1, c2, c3);
        assertEquals("(Col1 LIKE 'foo%' AND Col1 LIKE '%bar' AND Col1 <> 'foobar')", filter.toString());

        SelectItem[] items = new SelectItem[] { s1 };
        CachingDataSetHeader header = new CachingDataSetHeader(items);
        assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foo bar" })));
        assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foosenbar" })));
        assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foo" })));
        assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "hello world" })));
        assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foobar" })));
    }
View Full Code Here

TOP

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

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.