当前位置: 首页>>代码示例>>Java>>正文


Java DataContext.getSchemaByName方法代码示例

本文整理汇总了Java中org.apache.metamodel.DataContext.getSchemaByName方法的典型用法代码示例。如果您正苦于以下问题:Java DataContext.getSchemaByName方法的具体用法?Java DataContext.getSchemaByName怎么用?Java DataContext.getSchemaByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.metamodel.DataContext的用法示例。


在下文中一共展示了DataContext.getSchemaByName方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveForeignColumn

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public Column resolveForeignColumn(final DatastoreCatalog datastoreCatalog) {
    final Datastore datastore = datastoreCatalog.getDatastore(getForeignDatastoreName());
    if (datastore == null) {
        return null;
    }
    try (DatastoreConnection connection = datastore.openConnection()) {
        final DataContext dataContext = connection.getDataContext();
        final Schema schema = dataContext.getSchemaByName(getForeignSchemaName());
        if (schema == null) {
            return null;
        }
        final Table table = schema.getTableByName(getForeignTableName());
        if (table == null) {
            return null;
        }
        return table.getColumnByName(getForeignColumnName());
    }
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:19,代码来源:ForeignKey.java

示例2: resolveForeignColumn

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public Column resolveForeignColumn(DatastoreCatalog datastoreCatalog) {
    Datastore datastore = datastoreCatalog.getDatastore(getForeignDatastoreName());
    if (datastore == null) {
        return null;
    }
    try (DatastoreConnection connection = datastore.openConnection()) {
        DataContext dataContext = connection.getDataContext();
        Schema schema = dataContext.getSchemaByName(getForeignSchemaName());
        if (schema == null) {
            return null;
        }
        Table table = schema.getTableByName(getForeignTableName());
        if (table == null) {
            return null;
        }
        Column column = table.getColumnByName(getForeignColumnName());
        return column;
    }
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:20,代码来源:ForeignKey.java

示例3: testAlternativeConnectionString

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testAlternativeConnectionString() throws Exception {
    if (!isConfigured()) {
        return;
    }

    DataContext dc = new JdbcDataContext(getConnection(), TableType.DEFAULT_TABLE_TYPES, "sakila");
    final Schema sakila = dc.getSchemaByName("sakila");
    assertNotNull(sakila);

    Table table = sakila.getTableByName("film");
    Query q = new Query().from(table).select(table.getColumns());
    DataSet data = dc.executeQuery(q);
    TableModel tableModel = new DataSetTableModel(data);
    assertEquals(13, tableModel.getColumnCount());
    assertEquals(1000, tableModel.getRowCount());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:17,代码来源:MysqlTest.java

示例4: printTables

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
private void printTables(final DataCleanerConfiguration configuration) {
    final String datastoreName = _arguments.getDatastoreName();
    final String schemaName = _arguments.getSchemaName();

    if (datastoreName == null) {
        System.err.println("You need to specify the datastore name!");
    } else {
        final Datastore ds = configuration.getDatastoreCatalog().getDatastore(datastoreName);
        if (ds == null) {
            System.err.println("No such datastore: " + datastoreName);
        } else {
            final DatastoreConnection con = ds.openConnection();
            final DataContext dc = con.getDataContext();
            final Schema schema;
            if (schemaName == null) {
                schema = dc.getDefaultSchema();
            } else {
                schema = dc.getSchemaByName(schemaName);
            }
            if (schema == null) {
                System.err.println("No such schema: " + schemaName);
            } else {
                final List<String> tableNames = schema.getTableNames();
                if (tableNames == null || tableNames.isEmpty()) {
                    System.err.println("No tables in schema!");
                } else {
                    write("Tables:");
                    write("-------");
                    for (final String tableName : tableNames) {
                        write(tableName);
                    }
                }
            }
            con.close();
        }
    }
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:38,代码来源:CliRunner.java

示例5: printTables

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
private void printTables(AnalyzerBeansConfiguration configuration) {
    String datastoreName = _arguments.getDatastoreName();
    String schemaName = _arguments.getSchemaName();

    if (datastoreName == null) {
        System.err.println("You need to specify the datastore name!");
    } else {
        Datastore ds = configuration.getDatastoreCatalog().getDatastore(datastoreName);
        if (ds == null) {
            System.err.println("No such datastore: " + datastoreName);
        } else {
            DatastoreConnection con = ds.openConnection();
            DataContext dc = con.getDataContext();
            Schema schema;
            if (schemaName == null) {
                schema = dc.getDefaultSchema();
            } else {
                schema = dc.getSchemaByName(schemaName);
            }
            if (schema == null) {
                System.err.println("No such schema: " + schemaName);
            } else {
                String[] tableNames = schema.getTableNames();
                if (tableNames == null || tableNames.length == 0) {
                    System.err.println("No tables in schema!");
                } else {
                    write("Tables:");
                    write("-------");
                    for (String tableName : tableNames) {
                        write(tableName);
                    }
                }
            }
            con.close();
        }
    }
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:38,代码来源:CliRunner.java

示例6: testSplitQuery

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testSplitQuery() throws Exception {
    if (!isConfigured()) {
        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().get(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());

    QuerySplitter qs = new QuerySplitter(dc, q);
    assertEquals(32098, qs.getRowCount());
    List<Query> splitQueries = qs.setMaxRows(8000).splitQuery();
    assertEquals(7, splitQueries.size());
    assertEquals(
            "[SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` < 4013 OR e.`rental_id` IS NULL) AND (e.`customer_id` < 300 OR e.`customer_id` IS NULL), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` < 4013 OR e.`rental_id` IS NULL) AND (e.`customer_id` > 300 OR e.`customer_id` = 300), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 4013 OR e.`rental_id` = 4013) AND (e.`rental_id` < 8025 OR e.`rental_id` = 4013) AND (e.`payment_id` < 8025 OR e.`payment_id` IS NULL), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 4013 OR e.`rental_id` = 4013) AND (e.`rental_id` < 8025 OR e.`rental_id` = 4013) AND (e.`payment_id` > 8025 OR e.`payment_id` = 8025), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 8025 OR e.`rental_id` = 8025) AND (e.`rental_id` < 12037 OR e.`rental_id` = 8025) AND (e.`amount` < 6 OR e.`amount` IS NULL), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 8025 OR e.`rental_id` = 8025) AND (e.`rental_id` < 12037 OR e.`rental_id` = 8025) AND (e.`amount` > 6 OR e.`amount` = 6), SELECT sl.`country`, e.`payment_id` FROM sakila.`staff_list` sl, sakila.`payment` e WHERE (e.`rental_id` > 12037 OR e.`rental_id` = 12037)]",
            Arrays.toString(splitQueries.toArray()));

    DataSet data = qs.executeQueries();
    int count = 0;
    while (data.next()) {
        count++;
    }
    data.close();
    assertEquals(32098, count);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:36,代码来源:MysqlTest.java

示例7: testSimpleQuerySplit

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testSimpleQuerySplit() throws Exception {
	Connection con = getTestDbConnection();
	DataContext dc = new JdbcDataContext(con);
	Schema schema = dc.getSchemaByName("PUBLIC");
	Table employeesTable = schema.getTableByName("EMPLOYEES");
	Table customersTable = schema.getTableByName("CUSTOMERS");
	Query q = new Query().from(employeesTable, "e").from(customersTable,
			"c");
	q.select(employeesTable.getColumns().get(0), customersTable.getColumns().get(0));
	assertEquals(
			"SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c",
			q.toString().replace('\"', '_'));

	QuerySplitter qs = new QuerySplitter(dc, q);
	long rowCount = qs.getRowCount();
	assertEquals(2806, rowCount);

	qs.setMaxRows(1000);
	List<Query> splitQueries = qs.splitQuery();

	assertEquals("[793, 610, 366, 714, 323]",
			Arrays.toString(getCounts(dc, splitQueries)));

	assertEquals(
			"[SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c WHERE (c._CUSTOMERNUMBER_ < 299 OR c._CUSTOMERNUMBER_ IS NULL) AND (e._EMPLOYEENUMBER_ < 1352 OR e._EMPLOYEENUMBER_ IS NULL), SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c WHERE (c._CUSTOMERNUMBER_ < 299 OR c._CUSTOMERNUMBER_ IS NULL) AND (e._EMPLOYEENUMBER_ > 1352 OR e._EMPLOYEENUMBER_ = 1352), SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c WHERE (c._CUSTOMERNUMBER_ > 299 OR c._CUSTOMERNUMBER_ = 299) AND (e._REPORTSTO_ < 1072 OR e._REPORTSTO_ IS NULL), SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c WHERE (c._CUSTOMERNUMBER_ > 299 OR c._CUSTOMERNUMBER_ = 299) AND (e._REPORTSTO_ > 1072 OR e._REPORTSTO_ = 1072) AND (c._SALESREPEMPLOYEENUMBER_ < 1433 OR c._SALESREPEMPLOYEENUMBER_ IS NULL), SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c WHERE (c._CUSTOMERNUMBER_ > 299 OR c._CUSTOMERNUMBER_ = 299) AND (e._REPORTSTO_ > 1072 OR e._REPORTSTO_ = 1072) AND (c._SALESREPEMPLOYEENUMBER_ > 1433 OR c._SALESREPEMPLOYEENUMBER_ = 1433)]",
			Arrays.toString(splitQueries.toArray()).replace('\"', '_'));
	assertSameCount(dc, qs, splitQueries);
	assertEquals(5, splitQueries.size());

	splitQueries = qs.setMaxRows(300).splitQuery();
	assertSameCount(dc, qs, splitQueries);
	assertEquals(
			"[299, 221, 170, 299, 276, 253, 102, 289, 253, 138, 368, 138]",
			Arrays.toString(getCounts(dc, splitQueries)));

	splitQueries = qs.setMaxRows(5000).splitQuery();
	assertEquals(1, splitQueries.size());
	assertSame(q, splitQueries.get(0));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:40,代码来源:QuerySplitterTest.java

示例8: printColumns

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
private void printColumns(final DataCleanerConfiguration configuration) {
    final String datastoreName = _arguments.getDatastoreName();
    final String tableName = _arguments.getTableName();
    final String schemaName = _arguments.getSchemaName();

    if (datastoreName == null) {
        System.err.println("You need to specify the datastore name!");
    } else if (tableName == null) {
        System.err.println("You need to specify a table name!");
    } else {
        final Datastore ds = configuration.getDatastoreCatalog().getDatastore(datastoreName);
        if (ds == null) {
            System.err.println("No such datastore: " + datastoreName);
        } else {
            final DatastoreConnection con = ds.openConnection();
            final DataContext dc = con.getDataContext();
            final Schema schema;
            if (schemaName == null) {
                schema = dc.getDefaultSchema();
            } else {
                schema = dc.getSchemaByName(schemaName);
            }
            if (schema == null) {
                System.err.println("No such schema: " + schemaName);
            } else {
                final Table table = schema.getTableByName(tableName);
                if (table == null) {
                    write("No such table: " + tableName);
                } else {
                    final List<String> columnNames = table.getColumnNames();
                    write("Columns:");
                    write("--------");
                    for (final String columnName : columnNames) {
                        write(columnName);
                    }
                }
            }
            con.close();
        }
    }
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:42,代码来源:CliRunner.java

示例9: printColumns

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
private void printColumns(AnalyzerBeansConfiguration configuration) {
    String datastoreName = _arguments.getDatastoreName();
    String tableName = _arguments.getTableName();
    String schemaName = _arguments.getSchemaName();

    if (datastoreName == null) {
        System.err.println("You need to specify the datastore name!");
    } else if (tableName == null) {
        System.err.println("You need to specify a table name!");
    } else {
        Datastore ds = configuration.getDatastoreCatalog().getDatastore(datastoreName);
        if (ds == null) {
            System.err.println("No such datastore: " + datastoreName);
        } else {
            DatastoreConnection con = ds.openConnection();
            DataContext dc = con.getDataContext();
            Schema schema;
            if (schemaName == null) {
                schema = dc.getDefaultSchema();
            } else {
                schema = dc.getSchemaByName(schemaName);
            }
            if (schema == null) {
                System.err.println("No such schema: " + schemaName);
            } else {
                Table table = schema.getTableByName(tableName);
                if (table == null) {
                    write("No such table: " + tableName);
                } else {
                    String[] columnNames = table.getColumnNames();
                    write("Columns:");
                    write("--------");
                    for (String columnName : columnNames) {
                        write(columnName);
                    }
                }
            }
            con.close();
        }
    }
}
 
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:42,代码来源:CliRunner.java

示例10: testGetNonExistingSchema

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testGetNonExistingSchema() throws Exception {
    Connection con = getTestDbConnection();
    DataContext dc = new JdbcDataContext(con);
    Schema schema = dc.getSchemaByName("foobar");
    assertNull("found schema: " + schema, schema);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:7,代码来源:JdbcDataContextTest.java

示例11: testGetSchema

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
public void testGetSchema() throws Exception {
    if (!isConfigured()) {
        return;
    }

    DataContext dc = new JdbcDataContext(getConnection());
    List<Schema> schemas = dc.getSchemas();
    assertTrue(schemas.size() >= 3);

    assertNotNull(dc.getSchemaByName("information_schema"));
    assertNotNull(dc.getSchemaByName("pg_catalog"));
    assertNotNull(dc.getSchemaByName("public"));

    Schema schema = dc.getSchemaByName("public");

    assertEquals("[Table[name=categories,type=TABLE,remarks=null], "
            + "Table[name=cust_hist,type=TABLE,remarks=null], " + "Table[name=customers,type=TABLE,remarks=null], "
            + "Table[name=inventory,type=TABLE,remarks=null], " + "Table[name=orderlines,type=TABLE,remarks=null], "
            + "Table[name=orders,type=TABLE,remarks=null], " + "Table[name=products,type=TABLE,remarks=null], "
            + "Table[name=reorder,type=TABLE,remarks=null]]", Arrays.toString(schema.getTables().toArray()));

    Table productsTable = schema.getTableByName("products");
    assertEquals(
            "[Column[name=prod_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10], "
                    + "Column[name=category,columnNumber=1,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
                    + "Column[name=title,columnNumber=2,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=actor,columnNumber=3,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=price,columnNumber=4,type=NUMERIC,nullable=false,nativeType=numeric,columnSize=12], "
                    + "Column[name=special,columnNumber=5,type=SMALLINT,nullable=true,nativeType=int2,columnSize=5], "
                    + "Column[name=common_prod_id,columnNumber=6,type=INTEGER,nullable=false,nativeType=int4,columnSize=10]]",
            Arrays.toString(productsTable.getColumns().toArray()));
    Table customersTable = schema.getTableByName("customers");
    assertEquals(
            "[Column[name=customerid,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10], "
                    + "Column[name=firstname,columnNumber=1,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=lastname,columnNumber=2,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=address1,columnNumber=3,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=address2,columnNumber=4,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
                    + "Column[name=city,columnNumber=5,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=state,columnNumber=6,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
                    + "Column[name=zip,columnNumber=7,type=INTEGER,nullable=true,nativeType=int4,columnSize=10], "
                    + "Column[name=country,columnNumber=8,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=region,columnNumber=9,type=SMALLINT,nullable=false,nativeType=int2,columnSize=5], "
                    + "Column[name=email,columnNumber=10,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
                    + "Column[name=phone,columnNumber=11,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=50], "
                    + "Column[name=creditcardtype,columnNumber=12,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
                    + "Column[name=creditcard,columnNumber=13,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=creditcardexpiration,columnNumber=14,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=username,columnNumber=15,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=password,columnNumber=16,type=VARCHAR,nullable=false,nativeType=varchar,columnSize=50], "
                    + "Column[name=age,columnNumber=17,type=SMALLINT,nullable=true,nativeType=int2,columnSize=5], "
                    + "Column[name=income,columnNumber=18,type=INTEGER,nullable=true,nativeType=int4,columnSize=10], "
                    + "Column[name=gender,columnNumber=19,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=1]]",
            Arrays.toString(customersTable.getColumns().toArray()));
    List<Relationship> relations = new ArrayList<>(customersTable.getRelationships());
    // bit o a hack to ensure ordering
    Collections.sort(relations, (rel1,rel2) -> rel1.getForeignTable().getName().compareTo(rel2.getForeignTable().getName()));
    assertEquals(2, relations.size());
    assertEquals(
            "[Relationship[primaryTable=customers,primaryColumns=[customerid],foreignTable=cust_hist,foreignColumns=[customerid]], "
                    + "Relationship[primaryTable=customers,primaryColumns=[customerid],foreignTable=orders,foreignColumns=[customerid]]]",
            Arrays.toString(relations.toArray()));
    assertEquals("Table[name=customers,type=TABLE,remarks=null]", relations.get(0).getPrimaryTable().toString());
    assertEquals("Table[name=cust_hist,type=TABLE,remarks=null]", relations.get(0).getForeignTable().toString());
    assertEquals("Table[name=customers,type=TABLE,remarks=null]", relations.get(1).getPrimaryTable().toString());
    assertEquals("Table[name=orders,type=TABLE,remarks=null]", relations.get(1).getForeignTable().toString());

    Table ordersTable = schema.getTableByName("orderlines");
    assertEquals(
            "[Column[name=orderlineid,columnNumber=0,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
                    + "Column[name=orderid,columnNumber=1,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
                    + "Column[name=prod_id,columnNumber=2,type=INTEGER,nullable=false,nativeType=int4,columnSize=10], "
                    + "Column[name=quantity,columnNumber=3,type=SMALLINT,nullable=false,nativeType=int2,columnSize=5], "
                    + "Column[name=orderdate,columnNumber=4,type=DATE,nullable=false,nativeType=date,columnSize=13]]",
            Arrays.toString(ordersTable.getColumns().toArray()));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:77,代码来源:PostgresqlTest.java

示例12: testSplitHugeQueryExecute146

import org.apache.metamodel.DataContext; //导入方法依赖的package包/类
/**
 * Splits a huge query into 146 pieces and executes them to test that the
 * collective result are equal to the original one in size
 */
@Ignore
public void testSplitHugeQueryExecute146() throws Exception {
    if (!isConfigured()) {
        return;
    }

    if (!"true".equalsIgnoreCase(getProperties().getProperty(PROPERTY_LONGRUNNINGTESTS))) {
        return;
    }

    DataContext dc = new JdbcDataContext(getConnection());
    Query q = new Query();
    Schema schema = dc.getSchemaByName("public");
    Table productsTable = schema.getTableByName("products");
    Table customerTable = schema.getTableByName("customers");
    q.from(productsTable, "p").from(customerTable, "c");

    Column titleColumn = productsTable.getColumnByName("title");
    Column priceColumn = productsTable.getColumnByName("price");
    Column cityColumn = customerTable.getColumnByName("city");
    Column ageColumn = customerTable.getColumnByName("age");
    q.select(titleColumn, priceColumn, cityColumn);

    q.where(new FilterItem(new SelectItem(priceColumn), OperatorType.GREATER_THAN, 27));
    q.where(new FilterItem(new SelectItem(ageColumn), OperatorType.GREATER_THAN, 55));

    assertEquals(
            "SELECT p.\"title\", p.\"price\", c.\"city\" FROM public.\"products\" p, public.\"customers\" c WHERE p.\"price\" > 27 AND c.\"age\" > 55",
            q.toString());

    QuerySplitter qs = new QuerySplitter(dc, q);
    qs.setMaxRows(100000);
    assertEquals(14072278, qs.getRowCount());

    List<Query> splitQueries = qs.splitQuery();
    assertEquals(146, splitQueries.size());
    assertEquals(
            "SELECT p.\"title\", p.\"price\", c.\"city\" FROM public.\"products\" p, public.\"customers\" c WHERE p.\"price\" > 27 AND c.\"age\" > 55 AND (c.\"customerid\" < 143 OR c.\"customerid\" IS NULL) AND (p.\"category\" < 8 OR p.\"category\" IS NULL)",
            splitQueries.get(0).toString());
    assertEquals(
            "SELECT p.\"title\", p.\"price\", c.\"city\" FROM public.\"products\" p, public.\"customers\" c WHERE p.\"price\" > 27 AND c.\"age\" > 55 AND (c.\"customerid\" > 19739 OR c.\"customerid\" = 19739)",
            splitQueries.get(145).toString());

    assertEquals(
            "[45954, 55752, 52122, 55480, 49770, 53410, 60434, 51590, 97284, 94336, 86966, 76648, 98758, 84018, 98758, 95810, 92862, 91388, 39798, 79596, "
                    + "91388, 48642, 60434, 106128, 94336, 94336, 86966, 79596, 85492, 94336, 104654, 97284, 84018, 101706, 109076, 89914, 110550, 107602, 98758, "
                    + "112024, 100232, 101706, 95810, 92862, 107602, 100232, 86966, 98758, 106128, 91388, 107602, 104654, 107602, 81070, 114972, 79596, 100232, 97284, "
                    + "103180, 98758, 113498, 103180, 89914, 104654, 97284, 109076, 114972, 103180, 86966, 106128, 101706, 95810, 103180, 88440, 112024, 91388, 106128, "
                    + "82544, 122342, 98758, 104654, 103180, 104654, 89914, 106128, 88440, 103180, 100232, 98758, 100232, 89914, 101706, 100232, 107602, 88440, 89914, "
                    + "91388, 103180, 100232, 104654, 120868, 106128, 100232, 107602, 97284, 103180, 106128, 91388, 100232, 106128, 100232, 109076, 94336, 106128, 94336, "
                    + "106128, 104654, 116446, 98758, 113498, 107602, 104654, 107602, 88440, 100232, 92862, 89914, 110550, 109076, 100232, 92862, 100232, 104654, 103180, "
                    + "89914, 103180, 103180, 107602, 85492, 112024, 85492, 101706, 92862, 86966, 104654, 201938]",
            Arrays.toString(getCounts(dc, splitQueries)));
    assertSameCount(dc, qs, splitQueries);

    DataSet data = qs.executeQueries(splitQueries);
    int count = 0;
    while (data.next()) {
        count++;
    }
    data.close();
    assertEquals(14072278, count);
    System.out.println("Successfully iterated 14072278 rows! :)");
}
 
开发者ID:apache,项目名称:metamodel,代码行数:69,代码来源:PostgresqlTest.java


注:本文中的org.apache.metamodel.DataContext.getSchemaByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。