Examples of JdbcDataContext


Examples of org.apache.metamodel.jdbc.JdbcDataContext

    public void testQueryUsingExpressions() throws Exception {
        if (!isConfigured()) {
            return;
        }
       
        JdbcDataContext strategy = new JdbcDataContext(getConnection(),
                new TableType[] { TableType.TABLE, TableType.VIEW }, DATABASE_NAME);
        Query q = new Query().select("Name").from("Production.Product").where("COlor IS NOT NULL").setMaxRows(5);
        DataSet dataSet = strategy.executeQuery(q);
        assertEquals("[Name]", Arrays.toString(dataSet.getSelectItems()));
        assertTrue(dataSet.next());
        assertEquals("Row[values=[LL Crankarm]]", dataSet.getRow().toString());
        assertTrue(dataSet.next());
        assertTrue(dataSet.next());
View Full Code Here

Examples of org.apache.metamodel.jdbc.JdbcDataContext

    public void testGetSchemaNormalTableTypes() throws Exception {
        if (!isConfigured()) {
            return;
        }
       
        JdbcDataContext dc = new JdbcDataContext(getConnection(), new TableType[] { TableType.TABLE, TableType.VIEW },
                DATABASE_NAME);
        Schema[] schemas = dc.getSchemas();

        assertEquals(8, schemas.length);
        assertEquals("Schema[name=HumanResources]", schemas[0].toString());
        assertEquals(13, schemas[0].getTableCount());
        assertEquals("Schema[name=INFORMATION_SCHEMA]", schemas[1].toString());
View Full Code Here

Examples of org.apache.metamodel.jdbc.JdbcDataContext

    public void testGetSchemaAllTableTypes() throws Exception {
        if (!isConfigured()) {
            return;
        }
       
        JdbcDataContext strategy = new JdbcDataContext(getConnection(), new TableType[] { TableType.OTHER,
                TableType.GLOBAL_TEMPORARY }, DATABASE_NAME);

        assertEquals("[Sales, HumanResources, dbo, Purchasing, sys, Production, INFORMATION_SCHEMA, Person]",
                Arrays.toString(strategy.getSchemaNames()));

        assertEquals("Schema[name=dbo]", strategy.getDefaultSchema().toString());
    }
View Full Code Here

Examples of org.apache.metamodel.jdbc.JdbcDataContext

    public void testQueryRewriterQuoteAliases() throws Exception {
        if (!isConfigured()) {
            return;
        }
       
        JdbcDataContext strategy = new JdbcDataContext(getConnection(), TableType.DEFAULT_TABLE_TYPES, DATABASE_NAME);
        IQueryRewriter queryRewriter = strategy.getQueryRewriter();
        assertSame(SQLServerQueryRewriter.class, queryRewriter.getClass());

        Schema schema = strategy.getSchemaByName("Sales");
        Table customersTable = schema.getTableByName("CUSTOMER");

        Query q = new Query().from(customersTable, "cus-tomers").select(
                new SelectItem(customersTable.getColumnByName("AccountNumber")).setAlias("c|o|d|e"));
        q.setMaxRows(5);

        assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());

        String queryString = queryRewriter.rewriteQuery(q);
        assertEquals(
                "SELECT TOP 5 \"cus-tomers\".\"AccountNumber\" AS \"c|o|d|e\" FROM Sales.\"Customer\" \"cus-tomers\"",
                queryString);

        // We have to test that no additional quoting characters are added every
        // time we run the rewriting
        queryString = queryRewriter.rewriteQuery(q);
        queryString = queryRewriter.rewriteQuery(q);
        assertEquals(
                "SELECT TOP 5 \"cus-tomers\".\"AccountNumber\" AS \"c|o|d|e\" FROM Sales.\"Customer\" \"cus-tomers\"",
                queryString);

        // Test that the original query is still the same (ie. it has been
        // cloned for execution)
        assertEquals("SELECT cus-tomers.\"AccountNumber\" AS c|o|d|e FROM Sales.\"Customer\" cus-tomers", q.toString());

        DataSet data = strategy.executeQuery(q);
        assertNotNull(data);
        data.close();
    }
View Full Code Here

Examples of org.apache.metamodel.jdbc.JdbcDataContext

    public void testQuotedString() throws Exception {
        if (!isConfigured()) {
            return;
        }
       
        JdbcDataContext dc = new JdbcDataContext(getConnection(), TableType.DEFAULT_TABLE_TYPES, DATABASE_NAME);
        IQueryRewriter queryRewriter = dc.getQueryRewriter();
        assertSame(SQLServerQueryRewriter.class, queryRewriter.getClass());

        Query q = dc.query().from("Production", "Product").select("Name").where("Color").eq("R'ed").toQuery();

        assertEquals(
                "SELECT \"Product\".\"Name\" FROM Production.\"Product\" Product WHERE Product.\"Color\" = 'R''ed'",
                queryRewriter.rewriteQuery(q));
    }
View Full Code Here

Examples of org.apache.metamodel.jdbc.JdbcDataContext

            return;
        }
        final Connection connection = getConnection();
        assertFalse(connection.isReadOnly());

        JdbcDataContext dc = new JdbcDataContext(connection);
        final Schema schema = dc.getSchemaByName("Person");

        JdbcTestTemplates.createInsertAndUpdateDateTypes(dc, schema, "test_table");
    }
View Full Code Here

Examples of org.apache.metamodel.jdbc.JdbcDataContext

            // do nothing
        }

        assertFalse(connection.isReadOnly());

        JdbcDataContext dc = new JdbcDataContext(connection);
        final Schema schema = dc.getSchemaByName("Person");
        assertEquals("Person", schema.getName());

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback cb) {
                Table table = cb.createTable(schema, "test_table").withColumn("id").asPrimaryKey()
                        .ofType(ColumnType.INTEGER).withColumn("birthdate").ofType(ColumnType.DATE).execute();

                cb.insertInto(table).value("id", "1").execute();
                cb.insertInto(table).value("id", 2).value("birthdate", "2011-12-21").execute();
            }
        });

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

        assertTrue(table.getColumnByName("id").isPrimaryKey());
        assertFalse(table.getColumnByName("birthdate").isPrimaryKey());

        // the jdbc driver represents the date as a VARCHAR
        assertEquals("[Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=int,columnSize=10], "
                + "Column[name=birthdate,columnNumber=1,type=VARCHAR,nullable=true,nativeType=date,columnSize=10]]",
                Arrays.toString(table.getColumns()));

        DataSet ds = dc.query().from(table).select("id").and("birthdate").execute();
        assertTrue(ds.next());
        assertEquals("Row[values=[1, null]]", ds.getRow().toString());
        assertEquals("java.lang.Integer", ds.getRow().getValue(0).getClass().getName());
        assertTrue(ds.next());
        assertEquals("Row[values=[2, 2011-12-21]]", ds.getRow().toString());
View Full Code Here

Examples of org.apache.metamodel.jdbc.JdbcDataContext

    public void testQueryUsingExpressions() throws Exception {
        if (!isConfigured()) {
            return;
        }
        JdbcDataContext strategy = new JdbcDataContext(getConnection(), new TableType[] { TableType.TABLE,
                TableType.VIEW }, DATABASE_NAME);
        Query q = new Query().select("Name").from("Production.Product").where("COlor IS NOT NULL").setMaxRows(5);
        DataSet dataSet = strategy.executeQuery(q);
        assertEquals("[Name]", Arrays.toString(dataSet.getSelectItems()));
        assertTrue(dataSet.next());
        assertEquals("Row[values=[LL Crankarm]]", dataSet.getRow().toString());
        assertTrue(dataSet.next());
        assertTrue(dataSet.next());
View Full Code Here

Examples of org.apache.metamodel.jdbc.JdbcDataContext

    public void testGetSchemaNormalTableTypes() throws Exception {
        if (!isConfigured()) {
            return;
        }
        JdbcDataContext dc = new JdbcDataContext(getConnection(), new TableType[] { TableType.TABLE, TableType.VIEW },
                DATABASE_NAME);
        Schema[] schemas = dc.getSchemas();

        assertEquals(8, schemas.length);
        assertEquals("Schema[name=HumanResources]", schemas[0].toString());
        assertEquals(13, schemas[0].getTableCount());
        assertEquals("Schema[name=INFORMATION_SCHEMA]", schemas[1].toString());
View Full Code Here

Examples of org.apache.metamodel.jdbc.JdbcDataContext

    public void testGetSchemaAllTableTypes() throws Exception {
        if (!isConfigured()) {
            return;
        }
        JdbcDataContext strategy = new JdbcDataContext(getConnection(), new TableType[] { TableType.OTHER,
                TableType.GLOBAL_TEMPORARY }, DATABASE_NAME);
        Schema schema = strategy.getDefaultSchema();
        assertEquals("dbo", schema.getName());

        assertEquals("[Sales, HumanResources, dbo, Purchasing, sys, Production, INFORMATION_SCHEMA, Person]",
                Arrays.toString(strategy.getSchemaNames()));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.