Package org.apache.metamodel.schema

Examples of org.apache.metamodel.schema.MutableTable


    public MutableTable toTable() {
        String name = getName();
        String[] columnNames = getColumnNames();
        ColumnType[] columnTypes = getColumnTypes();

        MutableTable table = new MutableTable(name, TableType.TABLE);

        for (int i = 0; i < columnNames.length; i++) {
            table.addColumn(new MutableColumn(columnNames[i], columnTypes[i], table, i, true));
        }
        return table;
    }
View Full Code Here


        final MutableSchema schema = new MutableSchema(schemaName);
        final Workbook wb = ExcelUtils.readWorkbook(inputStream);

        for (int i = 0; i < wb.getNumberOfSheets(); i++) {
            final Sheet currentSheet = wb.getSheetAt(i);
            final MutableTable table = createTable(wb, currentSheet);
            table.setSchema(schema);
            schema.addTable(table);
        }

        return schema;
    }
View Full Code Here

    public void notifyTablesModified(Ref<InputStream> inputStreamRef) {
        // do nothing
    }

    private MutableTable createTable(final Workbook wb, final Sheet sheet) {
        final MutableTable table = new MutableTable(sheet.getSheetName());

        if (sheet.getPhysicalNumberOfRows() <= 0) {
            // no physical rows in sheet
            return table;
        }

        final Iterator<Row> rowIterator = ExcelUtils.getRowIterator(sheet, _configuration, false);

        if (!rowIterator.hasNext()) {
            // no physical rows in sheet
            return table;
        }


        Row row = null;

        if (_configuration.isSkipEmptyLines()) {
            while (row == null && rowIterator.hasNext()) {
                row = rowIterator.next();
            }
        } else {
            row = rowIterator.next();
        }

        final int columnNameLineNumber = _configuration.getColumnNameLineNumber();
        if (columnNameLineNumber == ExcelConfiguration.NO_COLUMN_NAME_LINE) {

            // get to the first non-empty line (no matter if lines are skipped
            // or not we need to read ahead to figure out how many columns there
            // are!)
            while (row == null && rowIterator.hasNext()) {
                row = rowIterator.next();
            }

            // build columns by using alphabetic sequences
            // (A,B,C...)
            AlphabeticSequence sequence = new AlphabeticSequence();

            final int offset = getColumnOffset(row);
            for (int i = 0; i < offset; i++) {
                sequence.next();
            }

            for (int j = offset; j < row.getLastCellNum(); j++) {
                Column column = new MutableColumn(sequence.next(), ColumnType.VARCHAR, table, j, true);
                table.addColumn(column);
            }
        } else {

            boolean hasColumns = true;
View Full Code Here

    protected Schema getMainSchema() throws MetaModelException {
        final MutableSchema schema = new MutableSchema(getMainSchemaName());

        for (XmlSaxTableDef tableDef : _tableDefs) {
            final String rowXpath = tableDef.getRowXpath();
            final MutableTable table = new MutableTable(getTableName(tableDef)).setSchema(schema)
                    .setRemarks("XPath: " + rowXpath);

            final MutableColumn rowIndexColumn = new MutableColumn(COLUMN_NAME_ROW_ID, ColumnType.INTEGER).setColumnNumber(0)
                    .setNullable(false).setTable(table).setRemarks("Row/tag index (0-based)");
            table.addColumn(rowIndexColumn);

            for (String valueXpath : tableDef.getValueXpaths()) {
                final MutableColumn column = new MutableColumn(getName(tableDef, valueXpath)).setRemarks("XPath: " + valueXpath);
                if (valueXpath.startsWith("index(") && valueXpath.endsWith(")")) {
                    column.setType(ColumnType.INTEGER);
                } else {
                    column.setType(ColumnType.VARCHAR);
                }
                column.setTable(table);
                table.addColumn(column);
            }
            schema.addTable(table);
        }

        return new ImmutableSchema(schema);
View Full Code Here

    protected Schema getMainSchema() throws MetaModelException {
        if (_schema == null) {
            MutableSchema schema = new MutableSchema(getMainSchemaName());
            for (SimpleTableDef tableDef : _tableDefs) {

                MutableTable table = tableDef.toTable().setSchema(schema);
                Column[] rowIdColumns = table.getColumnsOfType(ColumnType.ROWID);
                for (Column column : rowIdColumns) {
                    if (column instanceof MutableColumn) {
                        ((MutableColumn) column).setPrimaryKey(true);
                    }
                }
View Full Code Here

    @Override
    protected Schema getMainSchema() throws MetaModelException {
        final MutableSchema schema = new MutableSchema(SCHEMA_NAME);
        for (final SimpleTableDef tableDef : _tableDefs) {
            final MutableTable table = tableDef.toTable().setSchema(schema);
            CouchDbTableCreationBuilder.addMandatoryColumns(table);
            schema.addTable(table);
        }
        return schema;
    }
View Full Code Here

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        schema = new MutableSchema("sch");
        table = new MutableTable("foo").setSchema(schema);
        schema.addTable(table);
        col = new MutableColumn("bar").setTable(table);
        table.addColumn(col);
    }
View Full Code Here

                queryString);
    }

    public void testFullyQualifiedColumnNames() throws Exception {
        final MutableSchema schema = new MutableSchema("sch");
        final MutableTable table = new MutableTable("tab", TableType.TABLE, schema);
        final MutableColumn nameColumn = new MutableColumn("name", ColumnType.VARCHAR).setTable(table);
        final MutableColumn ageColumn = new MutableColumn("age", ColumnType.INTEGER).setTable(table);
        schema.addTable(table);
        table.addColumn(nameColumn);
        table.addColumn(ageColumn);

        final Query q = new Query();
        q.select(ageColumn).selectCount();
        q.from(table);
        q.where(ageColumn, OperatorType.GREATER_THAN, 18);
View Full Code Here

                + "GROUP BY sch.tab.age HAVING COUNT(sch.tab.name) < 100 ORDER BY sch.tab.age ASC", sql);
    }

    public void testFullyQualifiedColumnNamesWithFilterItemContainingTimestamp() throws Exception {
        final MutableSchema schema = new MutableSchema("sch");
        final MutableTable table = new MutableTable("tab", TableType.TABLE, schema);
        final MutableColumn nameColumn = new MutableColumn("name", ColumnType.VARCHAR).setTable(table);
        final MutableColumn dateColumn = new MutableColumn("age", ColumnType.TIMESTAMP).setTable(table);
        schema.addTable(table);
        table.addColumn(nameColumn);
        table.addColumn(dateColumn);

        final Query q = new Query();
        q.select(dateColumn).selectCount();
        q.from(table);
        q.where(dateColumn, OperatorType.GREATER_THAN, "2012-10-31 08:09:54");
View Full Code Here

        final MutableSchema schema = new MutableSchema(schemaName);
        final Workbook wb = ExcelUtils.readWorkbook(inputStream);

        for (int i = 0; i < wb.getNumberOfSheets(); i++) {
            final Sheet currentSheet = wb.getSheetAt(i);
            final MutableTable table = createTable(wb, currentSheet);
            table.setSchema(schema);
            schema.addTable(table);
        }

        return schema;
    }
View Full Code Here

TOP

Related Classes of org.apache.metamodel.schema.MutableTable

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.