Package org.apache.metamodel.schema

Examples of org.apache.metamodel.schema.Schema


        assertFalse(data.next());
    }

    public void testAutoflattenTicket229() throws Exception {
        DataContext dc = new XmlDomDataContext(new File("src/test/resources/xml_input_ticket_229.xml"));
        Schema schema = dc.getDefaultSchema();
        assertNotNull(schema);

        assertEquals("[VirtualBox, Machine, Machine_ExtraData_ExtraDataItem, Machine_Hardware_Boot_Order, "
                + "Machine_Hardware_Display, Machine_Hardware_RemoteDisplay, Machine_Hardware_BIOS_Logo, "
                + "Machine_Hardware_DVDDrive, Machine_Hardware_USBController, Machine_Hardware_SATAController, "
                + "Machine_Hardware_Network_Adapter, Machine_Hardware_UART_Port, Machine_Hardware_LPT_Port, "
                + "Machine_Hardware_AudioAdapter, Machine_Hardware_SharedFolders_SharedFolder, "
                + "Machine_Hardware_Guest, Machine_HardDiskAttachments_HardDiskAttachment]",
                Arrays.toString(schema.getTableNames()));
        assertEquals(
                "[id, OSType, lastStateChange, name, uuid, enabled, enabled, RAMSize, enabled, enabled, mode, value, "
                        + "enabled, type, enabled, mode]",
                Arrays.toString(schema.getTableByName("Machine").getColumnNames()));
    }
View Full Code Here


        }
        final ExcelDataContext dc = new ExcelDataContext(file);
        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback cb) {
                Schema schema = dc.getDefaultSchema();
                Table table1 = cb.createTable(schema, "my_table_1").withColumn("foo").withColumn("bar")
                        .withColumn("baz").execute();

                assertEquals(1, schema.getTableCount());
                assertSame(table1.getSchema(), schema);
                assertSame(table1, schema.getTables()[0]);

                Table table2 = cb.createTable(schema, "my_table_2").withColumn("foo").withColumn("bar")
                        .withColumn("baz").execute();

                assertSame(table2.getSchema(), schema);
                assertSame(table2, schema.getTables()[1]);
                assertEquals(2, schema.getTableCount());

                cb.insertInto(table1).value("foo", 123.0).value("bar", "str 1").value("baz", true).execute();
            }
        });

        dc.refreshSchemas();

        Schema schema = dc.getDefaultSchema();
        assertEquals(2, schema.getTableCount());
        assertEquals("[my_table_1, my_table_2]", Arrays.toString(schema.getTableNames()));

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback cb) {
                cb.insertInto(dc.getTableByQualifiedLabel("my_table_1")).value("foo", 456.2)
                        .value("bar", "парфюмерия +и косметика").value("baz", false).execute();
            }
        });

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback cb) {
                cb.insertInto("my_table_1").value("foo", 789).value("bar", DateUtils.get(2011, Month.JULY, 8))
                        .value("baz", false).execute();
            }
        });

        DataSet ds = dc.query().from("my_table_1").select("foo").and("bar").and("baz").execute();
        assertTrue(ds.next());
        assertEquals("Row[values=[123, str 1, true]]", ds.getRow().toString());
        assertTrue(ds.next());
        assertEquals("Row[values=[456.2, парфюмерия +и косметика, false]]", ds.getRow().toString());
        assertTrue(ds.next());
        assertEquals("Row[values=[789, 2011-07-08 00:00:00, false]]", ds.getRow().toString());
        assertFalse(ds.next());
        ds.close();

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.deleteFrom("my_table_1").where("foo").greaterThan("124").execute();
            }
        });

        assertEquals("1",
                MetaModelHelper.executeSingleRowQuery(dc, dc.query().from("my_table_1").selectCount().toQuery())
                        .getValue(0).toString());

        ds = dc.query().from("my_table_1").select("foo").and("bar").and("baz").execute();
        assertTrue(ds.next());
        assertEquals("Row[values=[123, str 1, true]]", ds.getRow().toString());
        assertFalse(ds.next());
        ds.close();

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.dropTable("my_table_1").execute();
            }
        });

        assertEquals("[my_table_2]", Arrays.toString(schema.getTableNames()));

        dc.refreshSchemas();

        assertEquals("[my_table_2]", Arrays.toString(schema.getTableNames()));

        assertEquals(1, dc.getDefaultSchema().getTableCount());
    }
View Full Code Here

        return schemaNames;
    }

    @Override
    public Schema getDefaultSchema() throws MetaModelException {
        Schema schema = _delegate.getDefaultSchema();
        schema = _schemaInterceptors.interceptAll(schema);
        return schema;
    }
View Full Code Here

        return schema;
    }

    @Override
    public Schema getSchemaByName(String name) throws MetaModelException {
        Schema schema = _delegate.getSchemaByName(name);
        schema = _schemaInterceptors.interceptAll(schema);
        return schema;
    }
View Full Code Here

     * schema has not yet been (explicitly) loaded.
     */
    public void testExecuteQueryBeforeLoadingSchema() throws Exception {
        // first use one DataContext to retreive the schema/table/column objects
        ExcelDataContext dc1 = new ExcelDataContext(new File("src/test/resources/Spreadsheet2007.xlsx"));
        Schema schema = dc1.getDefaultSchema();
        Table table = schema.getTable(0);
        Column column = table.getColumn(0);

        // query another DataContext using the schemas of the one above
        ExcelDataContext dc2 = new ExcelDataContext(new File("src/test/resources/Spreadsheet2007.xlsx"));
        DataSet ds = dc2.executeQuery(new Query().from(table).select(column));
View Full Code Here

    }

    @Override
    public TableCreationBuilder createTable(String schemaName, String tableName) throws IllegalArgumentException,
            IllegalStateException {
        Schema schema = getSchema(schemaName);
        return createTable(schema, tableName);
    }
View Full Code Here

            IllegalStateException, UnsupportedOperationException {
        return insertInto(getTable(schemaName, tableName));
    }

    private Table getTable(String schemaName, String tableName) {
        final Schema schema = getSchema(schemaName);
        final Table table = schema.getTableByName(tableName);
        if (table == null) {
            throw new IllegalArgumentException("Nu such table '" + tableName + "' found in schema: " + schema
                    + ". Available tables are: " + Arrays.toString(schema.getTableNames()));
        }
        return table;
    }
View Full Code Here

        }
        return table;
    }

    private Schema getSchema(String schemaName) {
        final Schema schema = _dataContext.getSchemaByName(schemaName);
        if (schema == null) {
            throw new IllegalArgumentException("No such schema: " + schemaName);
        }
        return schema;
    }
View Full Code Here

            File file = new File("src/test/resources/tickets.csv");
            FileInputStream inputStream = new FileInputStream(file);
            dc = new CsvDataContext(inputStream, new CsvConfiguration());
        }

        Schema schema = dc.getDefaultSchema();
        String name = schema.getTable(0).getName();
        assertTrue(name.startsWith("metamodel"));
        assertTrue(name.endsWith("csv"));

        // Test two seperate reads to ensure that the temp file is working
        // properly and persistent.
View Full Code Here

    }

    public void testMultilineExample() throws Exception {
        File file = new File("src/test/resources/tickets.csv");
        DataContext dc = new CsvDataContext(file);
        Schema schema = dc.getDefaultSchema();
        Table table = schema.getTableByName("tickets.csv");
        Column descColumn = table.getColumnByName("_description");

        assertNotNull(table);
        assertNotNull(descColumn);
View Full Code Here

TOP

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

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.