简体   繁体   中英

QueryDsl Set Schema

Using a Spring DataSource and a QueryDsl SQLQueryImpl , how do you specify the schema or set the schema?

Test case is:

  1. Use querydsl-maven-plugin (2.9.0) to connect to DB2 database to generate Q-Classes specifying <schemaPattern>
  2. Spring creates a DataSource bean
  3. DataSource bean is populated by scripts ( CREATE SCHEMA FOO , CREATE TABLE FOO.BAR etc)
  4. JUnit test imports DataSource
  5. Query using new SQLQueryImpl(dataSource.getConnection(), Configuration.DEFAULT)

Error:

org.h2.jdbc.JdbcSQLException: Table "BAR" not found; SQL Statement: ...

Note that this test implementation is an H2 database, but the production database is DB2. So far I've tried specifying the schema in the JDBC connection strings to no avail.

com.mysema.query.sql.SQLTemplates has a builder method called printSchema() . Initialise SQLTemplates using the builder() method and call printSchema() before build() . Example to follow:

SQLTemplates templates = OracleTemplates.builder().printSchema().build();

The Schema is encoded in the Q-types. It is accessed in the SQL serialization via the RelationalPath interface http://www.querydsl.com/static/querydsl/2.9.0/apidocs/com/mysema/query/sql/RelationalPath.html

I was able to extend SQLTemplates with my own implementation that called the protected method setPrintSchema(true); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM