Package org.apache.metamodel.schema

Examples of org.apache.metamodel.schema.Table


            return;
        }
       
    DataContext dc = new JdbcDataContext(getConnection(), TableType.DEFAULT_TABLE_TYPES, "sakila");
    Schema schema = dc.getSchemaByName("sakila");
    Table staffListTable = schema.getTableByName("staff_list");
    assertNotNull(staffListTable);
    Table paymentTable = schema.getTableByName("payment");
    assertNotNull(paymentTable);
    Column countryColumn = staffListTable.getColumnByName("country");
    assertNotNull(countryColumn);
    Column paymentColumn = paymentTable.getColumns()[0];
    assertNotNull(paymentColumn);
    Query q = new Query().from(staffListTable, "sl").from(paymentTable, "e").select(countryColumn, paymentColumn);
    assertEquals("SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e",
        q.toString());
View Full Code Here


      return createSqlStatement(_inlineValues);
  }

  private String createSqlStatement(boolean inlineValues) {
    final Object[] values = getValues();
    final Table table = getTable();
    final StringBuilder sb = new StringBuilder();

    final String tableLabel = _queryRewriter.rewriteFromItem(new FromItem(table));

    sb.append("INSERT INTO ");
View Full Code Here

    });

    dc.executeUpdate(new UpdateScript() {
      @Override
      public void run(UpdateCallback callback) {
        Table table = callback
            .createTable(dc.getDefaultSchema(), "table")
            .withColumn("col1").withColumn("col2").execute();

        callback.insertInto(table).value("col1", "hello")
            .value("col2", "world").execute();
        callback.insertInto(table).value("col1", "123")
            .value("col2", "567").execute();
      }
    });

    assertEquals("[table]",
        Arrays.toString(dc.getDefaultSchema().getTableNames()));
    Table table = dc.getDefaultSchema().getTables()[0];
    assertEquals("[col1, col2, foobar]",
        Arrays.toString(table.getColumnNames()));

    DataSet ds = dc.query().from(table).select(table.getColumns())
        .execute();
    assertTrue(ds.next());
    assertEquals("Row[values=[hello, world, elite!]]", ds.getRow()
        .toString());
    assertTrue(ds.next());
View Full Code Here

        String[] tableNames = schema.getTableNames();

        System.out.println("All tables:\n" + Arrays.toString(tableNames));

        Table accountTable = schema.getTableByName("Account");
        assertNotNull(accountTable);

        String[] columnNames = accountTable.getColumnNames();
        System.out.println("Account table columns: " + Arrays.toString(columnNames));

        Column idColumn = accountTable.getColumnByName("Id");
        Column nameColumn = accountTable.getColumnByName("Name");

        assertNotNull(idColumn);
        assertNotNull(nameColumn);

        assertEquals("Column[name=Id,columnNumber=0,type=VARCHAR,nullable=false,nativeType=id,columnSize=18]",
View Full Code Here

        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        final Date dateValue = dateFormat.parse(dateString);
        assertEquals("1980-08-08 05:10:22", dateFormat.format(dateValue));

        final Table table = dc.getTableByQualifiedLabel(tableName);

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.insertInto(table).value("FirstName", firstName).value("LastName", lastName)
View Full Code Here

        return createSqlStatement(_inlineValues);
    }

    private String createSqlStatement(boolean inlineValues) {
        final Object[] values = getValues();
        final Table table = getTable();
        final StringBuilder sb = new StringBuilder();

        final String tableLabel = _queryRewriter.rewriteFromItem(new FromItem(table));

        sb.append("UPDATE ");
View Full Code Here

        _updateCallback = updateCallback;
    }

    @Override
    public void execute() throws MetaModelException {
        final Table table = getTable();
        _updateCallback.removeSheet(table.getName());
        final MutableSchema schema = (MutableSchema) table.getSchema();
        schema.removeTable(table);
    }
View Full Code Here

        // find all datacontexts involved, by investigating FROM items
        List<FromItem> items = query.getFromClause().getItems();
        for (FromItem item : items) {
            List<FromItem> tableFromItems = MetaModelHelper.getTableFromItems(item);
            for (FromItem fromItem : tableFromItems) {
                Table table = fromItem.getTable();

                DataContext dc = getDataContext(table);
                if (dc == null) {
                    throw new MetaModelException("Could not resolve child-datacontext for table: " + table);
                }
View Full Code Here

        }
        JdbcDataContext dc = new JdbcDataContext(getConnection());
        Schema schema = dc.getDefaultSchema();
        assertEquals(getUsername().toUpperCase(), schema.getName());

        Table countryTable = schema.getTableByName("COUNTRY");
        assertNotNull(countryTable);

        DataSet ds = dc.query().from(countryTable).selectCount().execute();
        assertTrue(ds.next());
        assertEquals("Row[values=[1008]]", ds.getRow().toString());
View Full Code Here

        JdbcDataContext dc = new JdbcDataContext(getConnection());
        Schema schema = dc.getDefaultSchema();
        String[] tableNames = schema.getTableNames();
        System.out.println("Tables: " + Arrays.toString(tableNames));

        Table countryTable = schema.getTableByName("COUNTRY");
        assertNotNull(countryTable);

        Query query = dc.query().from(countryTable).select("COUNTRYCODE").limit(200).toQuery();
        assertEquals("SELECT DB2INST1.\"COUNTRY\".\"COUNTRYCODE\" FROM DB2INST1.\"COUNTRY\" "
                + "FETCH FIRST 200 ROWS ONLY", dc.getQueryRewriter().rewriteQuery(query));
View Full Code Here

TOP

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

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.