Package org.apache.metamodel.schema

Examples of org.apache.metamodel.schema.Table


        }
        return null;
    }

    private final Column getColumn(final Schema schema, final String tableAndColumnPath) {
        Table table = null;
        String columnPath = tableAndColumnPath;
        final String[] tableNames = schema.getTableNames();
        for (final String tableName : tableNames) {
            if (tableName != null) {
                // search case-sensitive
                if (isStartingToken(tableName, tableAndColumnPath)) {
                    table = schema.getTableByName(tableName);
                    columnPath = tableAndColumnPath.substring(tableName.length());

                    if (columnPath.charAt(0) == '.') {
                        columnPath = columnPath.substring(1);
                        break;
                    }
                }
            }
        }

        if (table == null) {
            final String tableAndColumnPathInLowerCase = tableAndColumnPath.toLowerCase();
            for (final String tableName : tableNames) {
                if (tableName != null) {
                    String tableNameInLowerCase = tableName.toLowerCase();
                    // search case-insensitive
                    if (isStartingToken(tableNameInLowerCase, tableAndColumnPathInLowerCase)) {
                        table = schema.getTableByName(tableName);
                        columnPath = tableAndColumnPath.substring(tableName.length());

                        if (columnPath.charAt(0) == '.') {
                            columnPath = columnPath.substring(1);
                            break;
                        }
                    }
                }
            }
        }

        if (table == null && tableNames.length == 1) {
            table = schema.getTables()[0];
        }

        if (table != null) {
            Column column = table.getColumnByName(columnPath);
            if (column != null) {
                return column;
            }
        }
View Full Code Here


        final String[] tokens = tokenizePath(tableName, 2);
        if (tokens != null) {
            Schema schema = getSchemaByToken(tokens[0]);
            if (schema != null) {
                Table table = schema.getTableByName(tokens[1]);
                if (table != null) {
                    return table;
                }
            }
        }

        Schema schema = null;
        String[] schemaNames = getSchemaNames();
        for (String schemaName : schemaNames) {
            if (schemaName == null) {
                // there's an unnamed schema present.
                schema = getSchemaByName(null);
                if (schema != null) {
                    Table table = schema.getTableByName(tableName);
                    return table;
                }
            } else {
                // case-sensitive search
                if (isStartingToken(schemaName, tableName)) {
View Full Code Here

        dataContext = new SugarCrmDataContext(BASE_URL, getUsername(), getPassword(), "Test");

        Schema schema = dataContext.getDefaultSchema();
        assertEquals("SugarCRM", schema.getName());

        Table table = schema.getTableByName("Accounts");

        String[] columnNames = table.getColumnNames();
        assertEquals(
                "[id, name, date_entered, date_modified, modified_user_id, modified_by_name, created_by, created_by_name, "
                        + "description, deleted, assigned_user_id, assigned_user_name, account_type, industry, annual_revenue, phone_fax, "
                        + "billing_address_street, billing_address_street_2, billing_address_street_3, billing_address_street_4, "
                        + "billing_address_city, billing_address_state, billing_address_postalcode, billing_address_country, rating, "
                        + "phone_office, phone_alternate, website, ownership, employees, ticker_symbol, shipping_address_street, "
                        + "shipping_address_street_2, shipping_address_street_3, shipping_address_street_4, shipping_address_city, "
                        + "shipping_address_state, shipping_address_postalcode, shipping_address_country, email1, parent_id, sic_code, parent_name, "
                        + "email_opt_out, invalid_email, email, campaign_id, campaign_name]",
                Arrays.toString(columnNames));

        Column nameColumn = table.getColumnByName("name");
        String nativeType = nameColumn.getNativeType();
        String remarks = nameColumn.getRemarks();
        ColumnType type = nameColumn.getType();
        assertEquals("name|Name:|VARCHAR", nativeType + "|" + remarks + "|" + type);

        Column[] columns = table.getColumns();
        for (Column column : columns) {
            type = column.getType();
            if (type == null || type == ColumnType.OTHER) {
                fail("No type mapping for native type: " + column.getNativeType() + " (found in column: " + column
                        + ")");
            }
        }

        table = schema.getTableByName("Contacts");

        columnNames = table.getColumnNames();
        assertEquals(
                "[id, name, date_entered, date_modified, modified_user_id, modified_by_name, created_by, created_by_name, description, deleted, "
                        + "assigned_user_id, assigned_user_name, salutation, first_name, last_name, full_name, title, department, do_not_call, phone_home, "
                        + "email, phone_mobile, phone_work, phone_other, phone_fax, email1, email2, invalid_email, email_opt_out, primary_address_street, "
                        + "primary_address_street_2, primary_address_street_3, primary_address_city, primary_address_state, primary_address_postalcode, "
                        + "primary_address_country, alt_address_street, alt_address_street_2, alt_address_street_3, alt_address_city, alt_address_state, "
                        + "alt_address_postalcode, alt_address_country, assistant, assistant_phone, email_and_name1, lead_source, account_name, account_id, "
                        + "opportunity_role_fields, opportunity_role_id, opportunity_role, reports_to_id, report_to_name, birthdate, campaign_id, campaign_name, "
                        + "c_accept_status_fields, m_accept_status_fields, accept_status_id, accept_status_name, sync_contact]",
                Arrays.toString(columnNames));

        columns = table.getColumns();
        for (Column column : columns) {
            type = column.getType();
            if (type == null || type == ColumnType.OTHER) {
                fail("No type mapping for native type: " + column.getNativeType() + " (found in column: " + column
                        + ")");
View Full Code Here

            System.err.println(getInvalidConfigurationMessage());
            return;
        }

        // test the schema exploration
        final Table table = _dataContext.getDefaultSchema().getTableByName(EXAMPLE_TABLE_NAME);
        assertNotNull(table);

        assertEquals("[_id, bar, foo]", Arrays.toString(table.getColumnNames()));
        assertEquals(ColumnType.MAP, table.getColumn(1).getType());

        // insert two records
        insertRecordsNatively();

        // query using regular configuration
View Full Code Here

        // Instantiate the actual data context
        final DataContext dataContext = new MongoDbDataContext(db);

        assertEquals("[" + getCollectionName() + ", system.indexes]", Arrays.toString(dataContext.getDefaultSchema().getTableNames()));
        Table table = dataContext.getDefaultSchema().getTableByName(getCollectionName());
        assertEquals("[_id, baz, foo, id, list, name]", Arrays.toString(table.getColumnNames()));

        assertEquals(ColumnType.MAP, table.getColumnByName("baz").getType());
        assertEquals(ColumnType.VARCHAR, table.getColumnByName("foo").getType());
        assertEquals(ColumnType.LIST, table.getColumnByName("list").getType());
        assertEquals(ColumnType.INTEGER, table.getColumnByName("id").getType());
        assertEquals(ColumnType.ROWID, table.getColumnByName("_id").getType());

        DataSet ds = dataContext.query().from(getCollectionName()).select("name").and("foo").and("baz").and("list")
                .where("id").greaterThan(800).or("foo").isEquals("bar").execute();
        assertEquals(MongoDbDataSet.class, ds.getClass());
        assertFalse(((MongoDbDataSet) ds).isQueryPostProcessed());
View Full Code Here

        dc.executeUpdate(new UpdateScript() {

            @Override
            public void run(UpdateCallback callback) {
                Table table = callback.createTable(defaultSchema, "some_entries").withColumn("foo").withColumn("bar")
                        .withColumn("baz").withColumn("list").execute();

                callback.insertInto(table).value("foo", 1).value("bar", "hello").execute();
                callback.insertInto(table).value("foo", 2).value("bar", "world").execute();
                callback.insertInto(table).value("foo", 3).value("bar", "hi").execute();
View Full Code Here

    super(columnName, columnType, table, columnNumber, nullable);
  }

  @Override
  public boolean isIndexed() {
    Table table = getTable();
    if (table instanceof JdbcTable) {
      ((JdbcTable) table).loadIndexes();
    }
    return super.isIndexed();
  }
View Full Code Here

    return super.isIndexed();
  }

  @Override
  public boolean isPrimaryKey() {
    Table table = getTable();
    if (table instanceof JdbcTable) {
      ((JdbcTable) table).loadPrimaryKeys();
    }
    return super.isPrimaryKey();
  }
View Full Code Here

        final MongoDbDataContext targetDataContext = new MongoDbDataContext(_mongoDb);
        targetDataContext.executeUpdate(new UpdateScript() {

            @Override
            public void run(UpdateCallback callback) {
                final Table sourceTable = getSourceTable();
                final Table targetTable = callback.createTable(targetDataContext.getDefaultSchema(), _collectionName)
                        .like(sourceTable).execute();
                final Column[] sourceColumns = sourceTable.getColumns();
                final DataSet dataSet = _sourceDataContext.query().from(sourceTable).select(sourceColumns).execute();
                while (dataSet.next()) {
                    final Row row = dataSet.getRow();
View Full Code Here

        final CsvDataContext copyDataContext = new CsvDataContext(tempFile, configuration);
        copyDataContext.executeUpdate(new UpdateScript() {

            @Override
            public void run(UpdateCallback callback) {
                final Table originalTable = getTable();
                final Table copyTable = callback.createTable(copyDataContext.getDefaultSchema(), originalTable.getName())
                        .like(originalTable).execute();

                if (isTruncateTableOperation()) {
                    // no need to iterate old records, they should all be
                    // removed
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.