Package org.apache.metamodel.data

Examples of org.apache.metamodel.data.DataSet


                "[Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=Auto-generated primary key,columnSize=null], "
                        + "Column[name=inceptionYear,columnNumber=1,type=STRING,nullable=true,nativeType=XML Text,columnSize=null]]",
                Arrays.toString(table.getColumns()));

        // first read
        DataSet data = dc.executeQuery(new Query().select(table.getColumnByName("inceptionYear")).from(table)
                .setMaxRows(1));
        assertTrue(data.next());
        assertEquals("2007", data.getRow().getValue(0));
        assertFalse(data.next());

        // repeated read
        data = dc.query().from(table).select("inceptionYear").execute();
        assertTrue(data.next());
        assertEquals("2007", data.getRow().getValue(0));
        assertFalse(data.next());
    }
View Full Code Here


    public void testGetStyles() throws Exception {
        DataContext dc = new ExcelDataContext(new File("src/test/resources/styles.xlsx"));
        Table table = dc.getDefaultSchema().getTables()[0];
        assertEquals("[style name, example]", Arrays.toString(table.getColumnNames()));

        DataSet ds = dc.query().from(table).select(table.getColumns()).execute();
        assertTrue(ds.next());
        assertEquals("Row[values=[bold, foo]]", ds.getRow().toString());
        assertEquals("", ds.getRow().getStyle(0).toCSS());
        assertEquals("font-weight: bold;", ds.getRow().getStyle(1).toCSS());

        assertTrue(ds.next());
        assertEquals("Row[values=[italic, foo]]", ds.getRow().toString());
        assertEquals("", ds.getRow().getStyle(0).toCSS());
        assertEquals("font-style: italic;", ds.getRow().getStyle(1).toCSS());

        assertTrue(ds.next());
        assertEquals("Row[values=[underline, foo]]", ds.getRow().toString());
        assertEquals("", ds.getRow().getStyle(0).toCSS());
        assertEquals("text-decoration: underline;", ds.getRow().getStyle(1).toCSS());

        assertTrue(ds.next());
        assertEquals("Row[values=[custom text col, foo]]", ds.getRow().toString());
        assertEquals("", ds.getRow().getStyle(0).toCSS());
        assertEquals("color: rgb(138,67,143);", ds.getRow().getStyle(1).toCSS());

        assertTrue(ds.next());
        assertEquals("Row[values=[yellow text col, foo]]", ds.getRow().toString());
        assertEquals("", ds.getRow().getStyle(0).toCSS());
        assertEquals("color: rgb(255,255,0);", ds.getRow().getStyle(1).toCSS());

        assertTrue(ds.next());
        assertEquals("Row[values=[custom bg, foo]]", ds.getRow().toString());
        assertEquals("", ds.getRow().getStyle(0).toCSS());
        assertEquals("background-color: rgb(136,228,171);", ds.getRow().getStyle(1).toCSS());

        assertTrue(ds.next());
        assertEquals("Row[values=[yellow bg, foo]]", ds.getRow().toString());
        assertEquals("", ds.getRow().getStyle(0).toCSS());
        assertEquals("background-color: rgb(255,255,0);", ds.getRow().getStyle(1).toCSS());

        assertTrue(ds.next());
        assertEquals("Row[values=[center align, foo]]", ds.getRow().toString());
        assertEquals("", ds.getRow().getStyle(0).toCSS());
        assertEquals("text-align: center;", ds.getRow().getStyle(1).toCSS());

        assertTrue(ds.next());
        assertEquals("Row[values=[font size 8, foo]]", ds.getRow().toString());
        assertEquals("", ds.getRow().getStyle(0).toCSS());
        assertEquals("font-size: 8pt;", ds.getRow().getStyle(1).toCSS());

        assertTrue(ds.next());
        assertEquals("Row[values=[font size 16, foo]]", ds.getRow().toString());
        assertEquals("", ds.getRow().getStyle(0).toCSS());
        assertEquals("font-size: 16pt;", ds.getRow().getStyle(1).toCSS());

        assertFalse(ds.next());
    }
View Full Code Here

                    if (item.getFunction() != null || item.getExpression() != null) {
                        break previewTable;
                    }
                }

                DataSet dataSet = materializeTable(table, selectItems, firstRow, maxRows);
                dataSet = MetaModelHelper.getSelection(selectItems, dataSet);
                return dataSet;
            }
        }

        // Creates a list for all select items that are needed to execute query
        // (some may only be used as part of a filter, but not shown in result)
        List<SelectItem> workSelectItems = CollectionUtils.concat(true, selectItems, whereSelectItems,
                groupBySelectItems, havingSelectItems, orderBySelectItems);

        // Materialize the tables in the from clause
        final DataSet[] fromDataSets = new DataSet[fromItems.size()];
        for (int i = 0; i < fromDataSets.length; i++) {
            FromItem fromItem = fromItems.get(i);
            fromDataSets[i] = materializeFromItem(fromItem, workSelectItems);
        }

        // Execute the query using the raw data
        DataSet dataSet = MetaModelHelper.getCarthesianProduct(fromDataSets, whereItems);

        // we can now exclude the select items imposed by the WHERE clause (and
        // should, to make the aggregation process faster)
        workSelectItems = CollectionUtils.concat(true, selectItems, groupBySelectItems, havingSelectItems,
                orderBySelectItems);
View Full Code Here

    protected Row executePrimaryKeyLookupQuery(Table table, List<SelectItem> selectItems, Column primaryKeyColumn, Object keyValue) {
        return null;
    }

    protected DataSet materializeFromItem(final FromItem fromItem, final List<SelectItem> selectItems) {
        DataSet dataSet;
        JoinType joinType = fromItem.getJoin();
        if (fromItem.getTable() != null) {
            // We need to materialize a single table
            final Table table = fromItem.getTable();
            final List<SelectItem> selectItemsToMaterialize = new ArrayList<SelectItem>();
View Full Code Here

            schemaName = null;
        } else {
            schemaName = schema.getName();
        }

        final DataSet dataSet;
        if (INFORMATION_SCHEMA_NAME.equals(schemaName)) {
            final DataSet informationDataSet = materializeInformationSchemaTable(table, selectItems, maxRows);
            if (firstRow > 1) {
                @SuppressWarnings("resource")
                final DataSet firstRowDataSet = new FirstRowDataSet(informationDataSet, firstRow);
                dataSet = firstRowDataSet;
            } else {
                dataSet = informationDataSet;
            }
        } else {
            final DataSet tableDataSet = materializeMainSchemaTable(table, selectItems, firstRow, maxRows);

            // conversion is done at materialization time, since it enables
            // the refined types to be used also in eg. where clauses.
            dataSet = new ConvertedDataSetInterceptor(_converters).intercept(tableDataSet);
        }
View Full Code Here

            }
        } else {
            throw new IllegalArgumentException("Cannot materialize non information_schema table: " + table);
        }

        DataSet dataSet;
        if (data.isEmpty()) {
            dataSet = new EmptyDataSet(selectItems);
        } else {
            dataSet = new InMemoryDataSet(header, data);
        }

        // Handle column subset
        DataSet selectionDataSet = MetaModelHelper.getSelection(selectItems, dataSet);
        dataSet = selectionDataSet;

        // Handle maxRows
        if (maxRows != -1) {
            dataSet = new MaxRowsDataSet(dataSet, maxRows);
View Full Code Here

    protected DataSet materializeMainSchemaTable(Table table, List<SelectItem> selectItems, int firstRow, int maxRows) {
        Column[] columns = new Column[selectItems.size()];
        for (int i = 0; i < columns.length; i++) {
            columns[i] = selectItems.get(i).getColumn();
        }
        DataSet dataSet = materializeMainSchemaTable(table, columns, firstRow, maxRows);

        dataSet = MetaModelHelper.getSelection(selectItems, dataSet);

        return dataSet;
    }
View Full Code Here

        if (firstRow == 1) {
            rowsToMaterialize = maxRows;
        } else {
            rowsToMaterialize = maxRows + (firstRow - 1);
        }
        DataSet dataSet = materializeMainSchemaTable(table, columns, rowsToMaterialize);
        if (firstRow > 1) {
            dataSet = new FirstRowDataSet(dataSet, firstRow);
        }
        return dataSet;
    }
View Full Code Here

       
        Table table = tables[0];
        assertEquals("testEmptyFileNoColumnHeaderLine.csv", table.getName());
        assertEquals(2, table.getColumnCount());
       
        DataSet ds = dc1.query().from(table).selectAll().execute();
        assertTrue(ds.next());
        assertEquals("Row[values=[1, 2]]", ds.getRow().toString());
        assertFalse(ds.next());
        ds.close();
    }
View Full Code Here

            UnsupportedOperationException {
        return new AbstractRowDeletionBuilder(table) {

            @Override
            public void execute() throws MetaModelException {
                final DataSet dataSet = _dataContext.query().from(getTable()).select(getTable().getColumns()).execute();
                final PojoDataSet<?> pojoDataSet = (PojoDataSet<?>) dataSet;
                final List<FilterItem> whereItems = getWhereItems();
                while (pojoDataSet.next()) {
                    boolean delete = true;
                    final Row row = pojoDataSet.getRow();
View Full Code Here

TOP

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

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.