Package org.apache.metamodel.jdbc

Examples of org.apache.metamodel.jdbc.JdbcDataContext


            } catch (Exception e) {
                logger.error("Failed to get JDBC connection using URL: " + url, e);
                throw new IllegalStateException("Failed to get JDBC connection", e);
            }

            return new JdbcDataContext(connection, tableTypes, params.getCatalogName());
        }

        return new JdbcDataContext(dataSource, tableTypes, params.getCatalogName());
    }
View Full Code Here


      String url = "jdbc:hsqldb:file:" + tempDir.getAbsolutePath() + "/"
          + databaseName;
      logger.info("Using database URL: " + url);
      _connection = DriverManager.getConnection(url, "SA", "");
      _connection.setReadOnly(true);
      _dataContextDelegate = new JdbcDataContext(_connection,
          TableType.DEFAULT_TABLE_TYPES, null);
    } catch (Exception e) {
      throw new MetaModelException(e);
    }
  }
View Full Code Here

                + ")derby_testdb;territory=en");
        connection.setReadOnly(true);

        DB db = new Mongo().getDB("orderdb_copy");

        DataContext sourceDataContext = new JdbcDataContext(connection);

        new MongoDbDataCopyer(db, "orders", sourceDataContext, "APP", "orders").copy();
        new MongoDbDataCopyer(db, "offices", sourceDataContext, "APP", "offices").copy();
        new MongoDbDataCopyer(db, "payments", sourceDataContext, "APP", "payments").copy();
        new MongoDbDataCopyer(db, "orderfact", sourceDataContext, "APP", "orderfact").copy();
View Full Code Here

  public void testFilmQuery() throws Exception {
      if (!isConfigured()) {
            return;
        }
       
    DataContext dc = new JdbcDataContext(getConnection());
    Table table = dc.getDefaultSchema().getTableByName("film");
    Query q = new Query().select(table.getColumns()).from(table).setMaxRows(400);
    dc.executeQuery(q);
  }
View Full Code Here

  public void testGetSchema() throws Exception {
      if (!isConfigured()) {
            return;
        }
       
    DataContext dc = new JdbcDataContext(getConnection());
    Schema[] schemas = dc.getSchemas();
    assertEquals(5, schemas.length);
    Schema schema = dc.getDefaultSchema();

    assertEquals("[Table[name=actor,type=TABLE,remarks=], " + "Table[name=address,type=TABLE,remarks=], "
        + "Table[name=category,type=TABLE,remarks=], " + "Table[name=city,type=TABLE,remarks=], "
        + "Table[name=country,type=TABLE,remarks=], " + "Table[name=customer,type=TABLE,remarks=], "
        + "Table[name=film,type=TABLE,remarks=], " + "Table[name=film_actor,type=TABLE,remarks=], "
        + "Table[name=film_category,type=TABLE,remarks=], " + "Table[name=film_text,type=TABLE,remarks=], "
        + "Table[name=inventory,type=TABLE,remarks=], " + "Table[name=language,type=TABLE,remarks=], "
        + "Table[name=payment,type=TABLE,remarks=], " + "Table[name=rental,type=TABLE,remarks=], "
        + "Table[name=staff,type=TABLE,remarks=], " + "Table[name=store,type=TABLE,remarks=], "
        + "Table[name=actor_info,type=VIEW,remarks=], " + "Table[name=customer_list,type=VIEW,remarks=], "
        + "Table[name=film_list,type=VIEW,remarks=], "
        + "Table[name=nicer_but_slower_film_list,type=VIEW,remarks=], "
        + "Table[name=sales_by_film_category,type=VIEW,remarks=], "
        + "Table[name=sales_by_store,type=VIEW,remarks=], " + "Table[name=staff_list,type=VIEW,remarks=]]",
        Arrays.toString(schema.getTables()));

    Table filmTable = schema.getTableByName("film");
    assertEquals(
        "[Column[name=film_id,columnNumber=0,type=SMALLINT,nullable=false,nativeType=SMALLINT UNSIGNED,columnSize=5], "
            + "Column[name=title,columnNumber=1,type=VARCHAR,nullable=false,nativeType=VARCHAR,columnSize=255], "
            + "Column[name=description,columnNumber=2,type=LONGVARCHAR,nullable=true,nativeType=TEXT,columnSize=65535], "
            + "Column[name=release_year,columnNumber=3,type=DATE,nullable=true,nativeType=YEAR,columnSize=0], "
            + "Column[name=language_id,columnNumber=4,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], "
            + "Column[name=original_language_id,columnNumber=5,type=TINYINT,nullable=true,nativeType=TINYINT UNSIGNED,columnSize=3], "
            + "Column[name=rental_duration,columnNumber=6,type=TINYINT,nullable=false,nativeType=TINYINT UNSIGNED,columnSize=3], "
            + "Column[name=rental_rate,columnNumber=7,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=4], "
            + "Column[name=length,columnNumber=8,type=SMALLINT,nullable=true,nativeType=SMALLINT UNSIGNED,columnSize=5], "
            + "Column[name=replacement_cost,columnNumber=9,type=DECIMAL,nullable=false,nativeType=DECIMAL,columnSize=5], "
            + "Column[name=rating,columnNumber=10,type=CHAR,nullable=true,nativeType=ENUM,columnSize=5], "
            + "Column[name=special_features,columnNumber=11,type=CHAR,nullable=true,nativeType=SET,columnSize=54], "
            + "Column[name=last_update,columnNumber=12,type=TIMESTAMP,nullable=false,nativeType=TIMESTAMP,columnSize=19]]",
        Arrays.toString(filmTable.getColumns()));
    assertEquals(
        "[Relationship[primaryTable=language,primaryColumns=[language_id],foreignTable=film,foreignColumns=[language_id]], Relationship[primaryTable=language,primaryColumns=[language_id],foreignTable=film,foreignColumns=[original_language_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=film_actor,foreignColumns=[film_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=film_category,foreignColumns=[film_id]], Relationship[primaryTable=film,primaryColumns=[film_id],foreignTable=inventory,foreignColumns=[film_id]]]",
        Arrays.toString(filmTable.getRelationships()));

    dc = new JdbcDataContext(getConnection(), TableType.DEFAULT_TABLE_TYPES, "sakila");
    schemas = dc.getSchemas();
    assertEquals(6, schemas.length);
    assertEquals("[Table[name=actor,type=TABLE,remarks=], " + "Table[name=address,type=TABLE,remarks=], "
        + "Table[name=category,type=TABLE,remarks=], " + "Table[name=city,type=TABLE,remarks=], "
        + "Table[name=country,type=TABLE,remarks=], " + "Table[name=customer,type=TABLE,remarks=], "
        + "Table[name=film,type=TABLE,remarks=], " + "Table[name=film_actor,type=TABLE,remarks=], "
View Full Code Here

  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");
View Full Code Here

  public void testQueryWithSingleQuote() throws Exception {
      if (!isConfigured()) {
            return;
        }
       
    DataContext dc = new JdbcDataContext(getConnection(), TableType.DEFAULT_TABLE_TYPES, "sakila");
    Query q = dc.query().from("category").selectCount().where("name").eq("kasper's horror movies").toQuery();
    DataSet ds = dc.executeQuery(q);
    assertTrue(ds.next());
    assertEquals(0, ((Number) ds.getRow().getValue(0)).intValue());
    assertFalse(ds.next());
  }
View Full Code Here

    public void testDefaultSchema() throws Exception {
        if (!isConfigured()) {
            return;
        }
        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());
        assertFalse(ds.next());
        ds.close();
    }
View Full Code Here

    public void testMaxRowsOnly() throws Exception {
        if (!isConfigured()) {
            return;
        }
        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));

        DataSet ds = dc.executeQuery(query);
        for (int i = 0; i < 200; i++) {
            assertTrue(ds.next());
            assertEquals(1, ds.getRow().getValues().length);
        }
        assertFalse(ds.next());
View Full Code Here

    public void testMaxRowsAndOffset() throws Exception {
        if (!isConfigured()) {
            return;
        }
        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).offset(200).toQuery();
        assertEquals(
                "SELECT metamodel_subquery.\"COUNTRYCODE\" FROM ("
                        + "SELECT DB2INST1.\"COUNTRY\".\"COUNTRYCODE\", ROW_NUMBER() OVER() AS metamodel_row_number FROM DB2INST1.\"COUNTRY\""
                        + ") metamodel_subquery WHERE metamodel_row_number BETWEEN 201 AND 400", dc.getQueryRewriter()
                        .rewriteQuery(query));

        DataSet ds = dc.executeQuery(query);
        for (int i = 0; i < 200; i++) {
            assertTrue(ds.next());
            assertEquals(1, ds.getRow().getValues().length);
        }
        assertFalse(ds.next());
View Full Code Here

TOP

Related Classes of org.apache.metamodel.jdbc.JdbcDataContext

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.